From 23ed5c2be4141cee9d988729d507db09597ed0db Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 11 Mar 2016 09:44:21 +0100 Subject: [PATCH] Changed: Create new client.cfg --- .../tools/client/client_config_qt/config.cpp | 53 ++++++++++++++++--- .../tools/client/client_config_qt/config.h | 10 +++- 2 files changed, 54 insertions(+), 9 deletions(-) diff --git a/code/ryzom/tools/client/client_config_qt/config.cpp b/code/ryzom/tools/client/client_config_qt/config.cpp index 0d41db0cd..15cd4fb9d 100644 --- a/code/ryzom/tools/client/client_config_qt/config.cpp +++ b/code/ryzom/tools/client/client_config_qt/config.cpp @@ -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 &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 ); + cf.load(fileName); - std::string def = getString( "RootConfigFilename" ); - if( def.compare( "" ) != 0 ) - dcf.load( def ); + std::string def = getString("RootConfigFilename"); + 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; diff --git a/code/ryzom/tools/client/client_config_qt/config.h b/code/ryzom/tools/client/client_config_qt/config.h index d9ddb536e..05f82c83a 100644 --- a/code/ryzom/tools/client/client_config_qt/config.h +++ b/code/ryzom/tools/client/client_config_qt/config.h @@ -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