[10081] Use ACE config library instead dotconfpp

NOTE: all config versions update because in old state
      it's not compatible with new way loading.
      Look for *.conf.dist.in chnages in commit for update configs.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Astellar 2010-06-20 01:50:19 +04:00 committed by VladimirMangos
parent e63dc32f4d
commit 41d178ca7b
7 changed files with 54 additions and 52 deletions

View file

@ -1,7 +1,9 @@
##################################### #####################################
# MaNGOS Configuration file # # MaNGOS Configuration file #
##################################### #####################################
ConfVersion=2010051901
[MangosdConf]
ConfVersion=2010062001
################################################################################################################### ###################################################################################################################
# CONNECTIONS AND DIRECTORIES # CONNECTIONS AND DIRECTORIES

View file

@ -1,7 +1,9 @@
############################################ ############################################
# MaNGOS realmd configuration file # # MaNGOS realmd configuration file #
############################################ ############################################
ConfVersion=2007062001
[RealmdConf]
ConfVersion=2010062001
################################################################################################################### ###################################################################################################################
# REALMD SETTINGS # REALMD SETTINGS

View file

@ -17,12 +17,35 @@
*/ */
#include "ConfigEnv.h" #include "ConfigEnv.h"
#include "ace/Configuration_Import_Export.h"
#include "Policies/SingletonImp.h" #include "Policies/SingletonImp.h"
INSTANTIATE_SINGLETON_1(Config); INSTANTIATE_SINGLETON_1(Config);
static bool GetValueHelper(ACE_Configuration_Heap *mConf, const char *name, ACE_TString &result)
{
if (!mConf)
return false;
ACE_TString section_name;
ACE_Configuration_Section_Key section_key;
ACE_Configuration_Section_Key root_key = mConf->root_section();
int i = 0;
while (mConf->enumerate_sections(root_key, i, section_name) == 0)
{
mConf->open_section(root_key, section_name.c_str(), 0, section_key);
if (mConf->get_string_value(section_key, name, result) == 0)
return true;
++i;
}
return false;
}
Config::Config() Config::Config()
: mIgnoreCase(true), mConf(NULL) : mConf(NULL)
{ {
} }
@ -31,9 +54,8 @@ Config::~Config()
delete mConf; delete mConf;
} }
bool Config::SetSource(const char *file, bool ignorecase) bool Config::SetSource(const char *file)
{ {
mIgnoreCase = ignorecase;
mFilename = file; mFilename = file;
return Reload(); return Reload();
@ -42,43 +64,33 @@ bool Config::SetSource(const char *file, bool ignorecase)
bool Config::Reload() bool Config::Reload()
{ {
delete mConf; delete mConf;
mConf = new ACE_Configuration_Heap;
mConf = new DOTCONFDocument(mIgnoreCase ? if (mConf->open() == 0)
DOTCONFDocument::CASEINSENSETIVE :
DOTCONFDocument::CASESENSITIVE);
if (mConf->setContent(mFilename.c_str()) == -1)
{ {
delete mConf; ACE_Ini_ImpExp config_importer(*mConf);
mConf = NULL; if (config_importer.import_config(mFilename.c_str()) == 0)
return false; return true;
} }
return true; delete mConf;
mConf = NULL;
return false;
} }
std::string Config::GetStringDefault(const char* name, const char* def) std::string Config::GetStringDefault(const char* name, const char* def)
{ {
if (!mConf) ACE_TString val;
return std::string(def); return GetValueHelper(mConf, name, val) ? val.c_str() : def;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return std::string(def);
return std::string(node->getValue());
} }
bool Config::GetBoolDefault(const char* name, bool def) bool Config::GetBoolDefault(const char* name, bool def)
{ {
if (!mConf) ACE_TString val;
if (!GetValueHelper(mConf, name, val))
return def; return def;
DOTCONFDocumentNode const *node = mConf->findNode(name); const char* str = val.c_str();
if (!node || !node->getValue())
return def;
const char* str = node->getValue();
if (strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 || if (strcmp(str, "true") == 0 || strcmp(str, "TRUE") == 0 ||
strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 || strcmp(str, "yes") == 0 || strcmp(str, "YES") == 0 ||
strcmp(str, "1") == 0) strcmp(str, "1") == 0)
@ -90,25 +102,13 @@ bool Config::GetBoolDefault(const char* name, bool def)
int32 Config::GetIntDefault(const char* name, int32 def) int32 Config::GetIntDefault(const char* name, int32 def)
{ {
if (!mConf) ACE_TString val;
return def; return GetValueHelper(mConf, name, val) ? atoi(val.c_str()) : def;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return def;
return atoi(node->getValue());
} }
float Config::GetFloatDefault(const char* name, float def) float Config::GetFloatDefault(const char* name, float def)
{ {
if (!mConf) ACE_TString val;
return def; return GetValueHelper(mConf, name, val) ? (float)atof(val.c_str()) : def;
DOTCONFDocumentNode const *node = mConf->findNode(name);
if (!node || !node->getValue())
return def;
return (float)atof(node->getValue());
} }

View file

@ -22,7 +22,7 @@
#include <Policies/Singleton.h> #include <Policies/Singleton.h>
#include "Platform/Define.h" #include "Platform/Define.h"
class DOTCONFDocument; class ACE_Configuration_Heap;
class MANGOS_DLL_SPEC Config class MANGOS_DLL_SPEC Config
{ {
@ -31,7 +31,7 @@ class MANGOS_DLL_SPEC Config
Config(); Config();
~Config(); ~Config();
bool SetSource(const char *file, bool ignorecase = true); bool SetSource(const char *file);
bool Reload(); bool Reload();
std::string GetStringDefault(const char* name, const char* def); std::string GetStringDefault(const char* name, const char* def);
@ -44,8 +44,7 @@ class MANGOS_DLL_SPEC Config
private: private:
std::string mFilename; std::string mFilename;
bool mIgnoreCase; ACE_Configuration_Heap *mConf;
DOTCONFDocument *mConf;
}; };
#define sConfig MaNGOS::Singleton<Config>::Instance() #define sConfig MaNGOS::Singleton<Config>::Instance()

View file

@ -21,7 +21,6 @@
#define CONFIGENVIRONMENT_H #define CONFIGENVIRONMENT_H
#include "Common.h" #include "Common.h"
#include "dotconfpp/dotconfpp.h"
#include "Config.h" #include "Config.h"
#endif #endif

View file

@ -36,10 +36,10 @@
// Format is YYYYMMDDRR where RR is the change in the conf file // Format is YYYYMMDDRR where RR is the change in the conf file
// for that day. // for that day.
#ifndef _MANGOSDCONFVERSION #ifndef _MANGOSDCONFVERSION
# define _MANGOSDCONFVERSION 2010051901 # define _MANGOSDCONFVERSION 2010062001
#endif #endif
#ifndef _REALMDCONFVERSION #ifndef _REALMDCONFVERSION
# define _REALMDCONFVERSION 2007062001 # define _REALMDCONFVERSION 2010062001
#endif #endif
#if MANGOS_ENDIAN == MANGOS_BIGENDIAN #if MANGOS_ENDIAN == MANGOS_BIGENDIAN

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__ #ifndef __REVISION_NR_H__
#define __REVISION_NR_H__ #define __REVISION_NR_H__
#define REVISION_NR "10080" #define REVISION_NR "10081"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__