mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-14 11:19:07 +00:00
Changed: #1153 automaticaly update RootConfigFilename in client.cfg
This commit is contained in:
parent
ebc2101c1f
commit
0d7bc590b1
2 changed files with 85 additions and 54 deletions
|
@ -1885,43 +1885,16 @@ void CClientConfig::serial(class NLMISC::IStream &f) throw(NLMISC::EStream)
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
void CClientConfig::init(const string &configFileName)
|
void CClientConfig::init(const string &configFileName)
|
||||||
{
|
{
|
||||||
|
// if the users client config does not exist
|
||||||
if(!CFile::fileExists(configFileName))
|
if(!CFile::fileExists(configFileName))
|
||||||
{
|
{
|
||||||
std::string defaultConfigFileName = "client_default.cfg";
|
// create the basic .cfg
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
if (CFile::isExists(defaultConfigFileName)) found = true;
|
|
||||||
|
|
||||||
#ifdef NL_OS_MAC
|
|
||||||
if (!found)
|
|
||||||
{
|
|
||||||
defaultConfigFileName =
|
|
||||||
getAppBundlePath() + "/Contents/Resources/" + defaultConfigFileName;
|
|
||||||
if(CFile::isExists(defaultConfigFileName)) found = true;
|
|
||||||
}
|
|
||||||
#elif defined(RYZOM_ETC_PREFIX)
|
|
||||||
if (!found)
|
|
||||||
{
|
|
||||||
defaultConfigFileName = CPath::standardizePath(RYZOM_ETC_PREFIX) + defaultConfigFileName;
|
|
||||||
if (CFile::isExists(defaultConfigFileName)) found = true;
|
|
||||||
}
|
|
||||||
#endif // RYZOM_ETC_PREFIX
|
|
||||||
|
|
||||||
if (found)
|
|
||||||
{
|
|
||||||
// create the basic .cfg that link the default one
|
|
||||||
FILE *fp = fopen(configFileName.c_str(), "w");
|
FILE *fp = fopen(configFileName.c_str(), "w");
|
||||||
|
|
||||||
if (fp == NULL)
|
if (fp == NULL)
|
||||||
{
|
|
||||||
nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str());
|
nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str());
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
nlwarning("CFG::init: creating '%s' with default values", configFileName.c_str ());
|
nlwarning("CFG::init: creating '%s' with default values", configFileName.c_str ());
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(fp, "RootConfigFilename = \"%s\";\n", defaultConfigFileName.c_str());
|
|
||||||
|
|
||||||
// get current locale
|
// get current locale
|
||||||
std::string lang = toLower(std::string(setlocale(LC_CTYPE, "")));
|
std::string lang = toLower(std::string(setlocale(LC_CTYPE, "")));
|
||||||
|
@ -1934,6 +1907,7 @@ void CClientConfig::init(const string &configFileName)
|
||||||
{
|
{
|
||||||
if (lang == languages[i])
|
if (lang == languages[i])
|
||||||
{
|
{
|
||||||
|
// store the language code in the config file
|
||||||
fprintf(fp, "LanguageCode = \"%s\";\n", lang.c_str());
|
fprintf(fp, "LanguageCode = \"%s\";\n", lang.c_str());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1941,12 +1915,37 @@ void CClientConfig::init(const string &configFileName)
|
||||||
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
// read the exising config file (don't parse it yet!)
|
||||||
|
ucstring content;
|
||||||
|
NLMISC::CI18N::readTextFile(configFileName, content);
|
||||||
|
std::string contentUtf8 = content.toUtf8();
|
||||||
|
|
||||||
|
// while there are "RootConfigFilename" values, remove them
|
||||||
|
size_t pos = 0;
|
||||||
|
while((pos = contentUtf8.find("RootConfigFilename")) != configFileName.npos)
|
||||||
{
|
{
|
||||||
nlwarning("CFG::init: '%s' Not Found !!!", defaultConfigFileName.c_str());
|
size_t endOfLine = contentUtf8.find("\n", pos);
|
||||||
}
|
contentUtf8.erase(pos, (endOfLine - pos) + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get current location of the root config file (client_default.cfg)
|
||||||
|
std::string defaultConfigLocation;
|
||||||
|
if(!getDefaultConfigLocation(defaultConfigLocation))
|
||||||
|
nlerror("cannot find client_default.cfg");
|
||||||
|
|
||||||
|
// and store it in the RootConfigFilename value in the very first line
|
||||||
|
contentUtf8.insert(0, std::string("RootConfigFilename = \"") +
|
||||||
|
defaultConfigLocation + "\";\n");
|
||||||
|
|
||||||
|
// save the updated config file
|
||||||
|
NLMISC::COFile configFile(configFileName, false, true, false);
|
||||||
|
configFile.serialBuffer((uint8*)contentUtf8.c_str(), contentUtf8.size());
|
||||||
|
configFile.close();
|
||||||
|
|
||||||
|
// now we can continue loading and parsing the config file
|
||||||
|
|
||||||
|
|
||||||
// if the config file will be modified, it calls automatically the function setValuesOnFileChange()
|
// if the config file will be modified, it calls automatically the function setValuesOnFileChange()
|
||||||
ClientCfg.ConfigFile.setCallback (CClientConfig::setValuesOnFileChange);
|
ClientCfg.ConfigFile.setCallback (CClientConfig::setValuesOnFileChange);
|
||||||
|
|
||||||
|
@ -2164,3 +2163,32 @@ ucstring CClientConfig::buildLoadingString( const ucstring& ucstr ) const
|
||||||
else
|
else
|
||||||
return ucstr;
|
return ucstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ***************************************************************************
|
||||||
|
bool CClientConfig::getDefaultConfigLocation(std::string& p_name) const
|
||||||
|
{
|
||||||
|
std::string defaultConfigFileName = "client_default.cfg";
|
||||||
|
|
||||||
|
#ifdef NL_OS_MAC
|
||||||
|
// on mac, client_default.cfg is located in the .app/Contents/Resources/
|
||||||
|
defaultConfigFileName =
|
||||||
|
CPath::standardizePath(getAppBundlePath() + "/Contents/Resources/") +
|
||||||
|
defaultConfigFileName;
|
||||||
|
|
||||||
|
#elif defined(RYZOM_ETC_PREFIX)
|
||||||
|
// if RYZOM_ETC_PREFIX is defined, look for client_default.cfg over there
|
||||||
|
defaultConfigFileName = CPath::standardizePath(RYZOM_ETC_PREFIX) +
|
||||||
|
defaultConfigFileName;
|
||||||
|
|
||||||
|
#endif // RYZOM_ETC_PREFIX
|
||||||
|
|
||||||
|
// else, client_default.cfg has to be in the working path
|
||||||
|
|
||||||
|
if (CFile::isExists(defaultConfigFileName))
|
||||||
|
{
|
||||||
|
p_name = defaultConfigFileName;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -836,6 +836,9 @@ public:
|
||||||
// return a random loading tip or, if there are not, return the string in argument
|
// return a random loading tip or, if there are not, return the string in argument
|
||||||
ucstring buildLoadingString( const ucstring& ucstr ) const;
|
ucstring buildLoadingString( const ucstring& ucstr ) const;
|
||||||
|
|
||||||
|
/// get the path to client_default.cfg including the filename itself.
|
||||||
|
bool getDefaultConfigLocation(std::string& fileLocation) const;
|
||||||
|
|
||||||
};// CClientConfig //
|
};// CClientConfig //
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue