mirror of
https://github.com/EQEmu/Server.git
synced 2026-08-28 15:57:58 +00:00
Headless client work
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
#include "json_config.h"
|
||||
#include <fstream>
|
||||
|
||||
EQ::JsonConfigFile::JsonConfigFile()
|
||||
{
|
||||
}
|
||||
|
||||
EQ::JsonConfigFile::JsonConfigFile(const Json::Value &value)
|
||||
{
|
||||
m_root = value;
|
||||
}
|
||||
|
||||
EQ::JsonConfigFile::~JsonConfigFile()
|
||||
{
|
||||
}
|
||||
|
||||
EQ::JsonConfigFile EQ::JsonConfigFile::Load(const std::string &filename)
|
||||
{
|
||||
JsonConfigFile ret;
|
||||
ret.m_root = Json::Value();
|
||||
|
||||
std::ifstream ifs;
|
||||
ifs.open(filename, std::ifstream::in);
|
||||
|
||||
if (!ifs.good()) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
try {
|
||||
ifs >> ret.m_root;
|
||||
}
|
||||
catch (std::exception) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string EQ::JsonConfigFile::GetVariableString(const std::string &title, const std::string ¶meter, const std::string &default_value) {
|
||||
try {
|
||||
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
|
||||
return m_root[title][parameter].asString();
|
||||
}
|
||||
}
|
||||
catch (std::exception) {
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
int EQ::JsonConfigFile::GetVariableInt(const std::string &title, const std::string ¶meter, const int default_value) {
|
||||
try {
|
||||
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
|
||||
return m_root[title][parameter].asInt();
|
||||
}
|
||||
}
|
||||
catch (std::exception) {
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
bool EQ::JsonConfigFile::GetVariableBool(const std::string &title, const std::string ¶meter, const bool default_value) {
|
||||
try {
|
||||
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
|
||||
return m_root[title][parameter].asBool();
|
||||
}
|
||||
}
|
||||
catch (std::exception) {
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
|
||||
double EQ::JsonConfigFile::GetVariableDouble(const std::string &title, const std::string ¶meter, const double default_value) {
|
||||
try {
|
||||
if (m_root.isMember(title) && m_root[title].isMember(parameter)) {
|
||||
return m_root[title][parameter].asDouble();
|
||||
}
|
||||
}
|
||||
catch (std::exception) {
|
||||
return default_value;
|
||||
}
|
||||
|
||||
return default_value;
|
||||
}
|
||||
Reference in New Issue
Block a user