Changed: Create new client.cfg
--HG-- branch : develop
This commit is contained in:
parent
4762b33ac0
commit
e0be334456
2 changed files with 54 additions and 9 deletions
|
@ -17,6 +17,10 @@
|
|||
#include "stdpch.h"
|
||||
#include "config.h"
|
||||
|
||||
#include "nel/misc/common.h"
|
||||
#include "nel/misc/i18n.h"
|
||||
#include "nel/misc/path.h"
|
||||
|
||||
CConfig::CConfig()
|
||||
{
|
||||
}
|
||||
|
@ -25,17 +29,50 @@ CConfig::~CConfig()
|
|||
{
|
||||
}
|
||||
|
||||
bool CConfig::load( const char *fileName )
|
||||
bool CConfig::create(const std::string &configFileName, const std::string &defaultFileName)
|
||||
{
|
||||
NLMISC::CFile::createDirectoryTree(NLMISC::CFile::getPath(configFileName));
|
||||
|
||||
// create the basic .cfg
|
||||
FILE *fp = NLMISC::nlfopen(configFileName, "w");
|
||||
|
||||
if (fp == NULL) return false;
|
||||
|
||||
// store full path to default config file
|
||||
fprintf(fp, "RootConfigFilename = \"%s\";\n", defaultFileName.c_str());
|
||||
|
||||
// get current locale
|
||||
std::string lang = NLMISC::CI18N::getSystemLanguageCode();
|
||||
|
||||
const std::vector<std::string> &languages = NLMISC::CI18N::getLanguageCodes();
|
||||
|
||||
// search if current locale is defined in language codes
|
||||
for(uint i = 0; i < languages.size(); ++i)
|
||||
{
|
||||
if (lang == languages[i])
|
||||
{
|
||||
// store the language code in the config file
|
||||
fprintf(fp, "LanguageCode = \"%s\";\n", lang.c_str());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CConfig::load(const std::string &fileName)
|
||||
{
|
||||
try
|
||||
{
|
||||
cf.load(fileName);
|
||||
|
||||
std::string def = getString("RootConfigFilename");
|
||||
if( def.compare( "" ) != 0 )
|
||||
if (!def.empty())
|
||||
dcf.load(def);
|
||||
}
|
||||
catch( NLMISC::Exception &e )
|
||||
catch (const NLMISC::Exception &e)
|
||||
{
|
||||
nlwarning( "%s", e.what() );
|
||||
return false;
|
||||
|
@ -51,7 +88,7 @@ bool CConfig::reload()
|
|||
cf.clear();
|
||||
cf.reparse();
|
||||
}
|
||||
catch( NLMISC::Exception &e )
|
||||
catch (const NLMISC::Exception &e)
|
||||
{
|
||||
nlwarning( "%s", e.what() );
|
||||
return false;
|
||||
|
@ -112,7 +149,7 @@ bool CConfig::save()
|
|||
{
|
||||
cf.save();
|
||||
}
|
||||
catch( NLMISC::Exception &e )
|
||||
catch (const NLMISC::Exception &e)
|
||||
{
|
||||
nlwarning( "%s", e.what() );
|
||||
return false;
|
||||
|
|
|
@ -28,12 +28,20 @@ public:
|
|||
CConfig();
|
||||
~CConfig();
|
||||
|
||||
/**
|
||||
@brief Create a config file.
|
||||
@param fileName - The config file to create
|
||||
@param defaultFileName - The default config file to use
|
||||
@return Returns true on success, returns false on failure.
|
||||
*/
|
||||
bool create(const std::string &fileName, const std::string &defaultFileName);
|
||||
|
||||
/**
|
||||
@brief Loads a config file.
|
||||
@param fileName - The file to load
|
||||
@return Returns true on success, returns false on failure.
|
||||
*/
|
||||
bool load( const char *fileName );
|
||||
bool load(const std::string &fileName);
|
||||
|
||||
/**
|
||||
@brief Reloads the contents of the config file
|
||||
|
|
Loading…
Reference in a new issue