From 27b5d40bf8a97984ec908d0fb6b8bb2312ab81e6 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 6 Jul 2012 16:29:49 +0000 Subject: [PATCH] - commandline override options now stored in a different buffer so that they will not be saved in ini files --- source/glest_game/global/config.cpp | 361 +++++----------------------- source/glest_game/global/config.h | 13 +- source/glest_game/main/main.cpp | 24 +- 3 files changed, 74 insertions(+), 324 deletions(-) diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index b49e0912..ff97b82f 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -310,6 +310,9 @@ void Config::save(const string &path){ } int Config::getInt(const char *key,const char *defaultValueIfNotFound) const { + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getInt(key,defaultValueIfNotFound); + } if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getInt(key,defaultValueIfNotFound); @@ -318,6 +321,10 @@ int Config::getInt(const char *key,const char *defaultValueIfNotFound) const { } bool Config::getBool(const char *key,const char *defaultValueIfNotFound) const { + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getBool(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getBool(key,defaultValueIfNotFound); @@ -327,6 +334,10 @@ bool Config::getBool(const char *key,const char *defaultValueIfNotFound) const { } float Config::getFloat(const char *key,const char *defaultValueIfNotFound) const { + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getFloat(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getFloat(key,defaultValueIfNotFound); @@ -336,6 +347,10 @@ float Config::getFloat(const char *key,const char *defaultValueIfNotFound) const } const string Config::getString(const char *key,const char *defaultValueIfNotFound) const { + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getString(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getString(key,defaultValueIfNotFound); @@ -345,6 +360,10 @@ const string Config::getString(const char *key,const char *defaultValueIfNotFoun } int Config::getInt(const string &key,const char *defaultValueIfNotFound) const{ + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getInt(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getInt(key,defaultValueIfNotFound); @@ -354,6 +373,10 @@ int Config::getInt(const string &key,const char *defaultValueIfNotFound) const{ } bool Config::getBool(const string &key,const char *defaultValueIfNotFound) const{ + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getBool(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getBool(key,defaultValueIfNotFound); @@ -363,6 +386,10 @@ bool Config::getBool(const string &key,const char *defaultValueIfNotFound) const } float Config::getFloat(const string &key,const char *defaultValueIfNotFound) const{ + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getFloat(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getFloat(key,defaultValueIfNotFound); @@ -372,6 +399,10 @@ float Config::getFloat(const string &key,const char *defaultValueIfNotFound) con } const string Config::getString(const string &key,const char *defaultValueIfNotFound) const{ + if(tempProperties.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + return tempProperties.getString(key,defaultValueIfNotFound); + } + if(fileLoaded.second == true && properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) { return properties.second.getString(key,defaultValueIfNotFound); @@ -380,309 +411,6 @@ const string Config::getString(const string &key,const char *defaultValueIfNotFo return properties.first.getString(key,defaultValueIfNotFound); } -/* -SDLKey Config::translateSpecialStringToSDLKey(char c) const { - SDLKey result = SDLK_UNKNOWN; - if(c < 0) { - switch(c) { - case vkAdd: - result = SDLK_PLUS; - break; - case vkSubtract: - result = SDLK_MINUS; - break; - - case vkAlt: - result = SDLK_RALT; - break; - - case vkControl: - result = SDLK_RCTRL; - break; - - case vkShift: - result = SDLK_RSHIFT; - break; - - case vkEscape: - result = SDLK_ESCAPE; - break; - - case vkUp: - result = SDLK_UP; - break; - - case vkLeft: - result = SDLK_LEFT; - break; - - case vkRight: - result = SDLK_RIGHT; - break; - - case vkDown: - result = SDLK_DOWN; - break; - - case vkReturn: - result = SDLK_RETURN; - break; - - case vkBack: - result = SDLK_BACKSPACE; - break; - - case vkTab: - result = SDLK_TAB; - break; - - case vkF1: - result = SDLK_F1; - break; - - case vkF2: - result = SDLK_F2; - break; - - case vkF3: - result = SDLK_F3; - break; - - case vkF4: - result = SDLK_F4; - break; - - case vkF5: - result = SDLK_F5; - break; - - case vkF6: - result = SDLK_F6; - break; - - case vkF7: - result = SDLK_F7; - break; - - case vkF8: - result = SDLK_F8; - break; - - case vkF9: - result = SDLK_F9; - break; - - case vkF10: - result = SDLK_F10; - break; - - case vkF11: - result = SDLK_F11; - break; - - case vkF12: - result = SDLK_F12; - break; - - case vkDelete: - result = SDLK_DELETE; - break; - - case vkPrint: - result = SDLK_PRINT; - break; - - case vkPause: - result = SDLK_PAUSE; - break; - } - } - else { - result = static_cast(c); - } - - return result; -} - -char Config::translateStringToCharKey(const string &value) const { - char result = 0; - - if(IsNumeric(value.c_str()) == true) { - result = strToInt(value); - } - else if(value.substr(0,2) == "vk") { - if(value == "vkLeft") { - result = vkLeft; - } - else if(value == "vkRight") { - result = vkRight; - } - else if(value == "vkUp") { - result = vkUp; - } - else if(value == "vkDown") { - result = vkDown; - } - else if(value == "vkAdd") { - result = vkAdd; - } - else if(value == "vkSubtract") { - result = vkSubtract; - } - else if(value == "vkEscape") { - result = vkEscape; - } - else if(value == "vkF1") { - result = vkF1; - } - else if(value == "vkF2") { - result = vkF2; - } - else if(value == "vkF3") { - result = vkF3; - } - else if(value == "vkF4") { - result = vkF4; - } - else if(value == "vkF5") { - result = vkF5; - } - else if(value == "vkF6") { - result = vkF6; - } - else if(value == "vkF7") { - result = vkF7; - } - else if(value == "vkF8") { - result = vkF8; - } - else if(value == "vkF9") { - result = vkF9; - } - else if(value == "vkF10") { - result = vkF10; - } - else if(value == "vkF11") { - result = vkF11; - } - else if(value == "vkF12") { - result = vkF12; - } - else if(value == "vkPrint") { - result = vkPrint; - } - else if(value == "vkPause") { - result = vkPause; - } - else { - string sError = "Unsupported key translation [" + value + "]"; - throw megaglest_runtime_error(sError.c_str()); - } - } - else if(value.length() >= 1) { - if(value.length() == 3 && value[0] == '\'' && value[2] == '\'') { - result = value[1]; - } - else { - bool foundKey = false; - if(value.length() > 1) { - for(int i = SDLK_UNKNOWN; i < SDLK_LAST; ++i) { - SDLKey key = static_cast(i); - string keyName = SDL_GetKeyName(key); - if(value == keyName) { - if(key > 255) { - if(value == "left") { - result = vkLeft; - } - else if(value == "right") { - result = vkRight; - } - else if(value == "up") { - result = vkUp; - } - else if(value == "down") { - result = vkDown; - } - else if(value == "add") { - result = vkAdd; - } - else if(value == "subtract") { - result = vkSubtract; - } - else if(value == "escape") { - result = vkEscape; - } - else if(value == "f1") { - result = vkF1; - } - else if(value == "f2") { - result = vkF2; - } - else if(value == "f3") { - result = vkF3; - } - else if(value == "f4") { - result = vkF4; - } - else if(value == "f5") { - result = vkF5; - } - else if(value == "f6") { - result = vkF6; - } - else if(value == "f7") { - result = vkF7; - } - else if(value == "f8") { - result = vkF8; - } - else if(value == "f9") { - result = vkF9; - } - else if(value == "f10") { - result = vkF10; - } - else if(value == "f11") { - result = vkF11; - } - else if(value == "f12") { - result = vkF12; - } - else if(value == "print-screen") { - result = vkPrint; - } - else if(value == "pause") { - result = vkPause; - } - else { - result = -key; - } - } - else { - result = key; - } - foundKey = true; - break; - } - } - } - - if(foundKey == false) { - result = value[0]; - } - } - } - else { - string sError = "Unsupported key translation" + value; - throw megaglest_runtime_error(sError.c_str()); - } - - // Because SDL is based on lower Ascii - result = tolower(result); - return result; -} -*/ - SDLKey Config::translateStringToSDLKey(const string &value) const { SDLKey result = SDLK_UNKNOWN; @@ -813,7 +541,11 @@ SDLKey Config::getSDLKey(const char *key) const { // return translateStringToCharKey(value); //} -void Config::setInt(const string &key, int value){ +void Config::setInt(const string &key, int value, bool tempBuffer) { + if(tempBuffer == true) { + tempProperties.setInt(key, value); + return; + } if(fileLoaded.second == true) { properties.second.setInt(key, value); return; @@ -821,7 +553,12 @@ void Config::setInt(const string &key, int value){ properties.first.setInt(key, value); } -void Config::setBool(const string &key, bool value){ +void Config::setBool(const string &key, bool value, bool tempBuffer) { + if(tempBuffer == true) { + tempProperties.setBool(key, value); + return; + } + if(fileLoaded.second == true) { properties.second.setBool(key, value); return; @@ -830,7 +567,12 @@ void Config::setBool(const string &key, bool value){ properties.first.setBool(key, value); } -void Config::setFloat(const string &key, float value){ +void Config::setFloat(const string &key, float value, bool tempBuffer) { + if(tempBuffer == true) { + tempProperties.setFloat(key, value); + return; + } + if(fileLoaded.second == true) { properties.second.setFloat(key, value); return; @@ -839,7 +581,12 @@ void Config::setFloat(const string &key, float value){ properties.first.setFloat(key, value); } -void Config::setString(const string &key, const string &value){ +void Config::setString(const string &key, const string &value, bool tempBuffer) { + if(tempBuffer == true) { + tempProperties.setString(key, value); + return; + } + if(fileLoaded.second == true) { properties.second.setString(key, value); return; diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index e856d82e..3902d837 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -36,14 +36,17 @@ using Shared::Util::Properties; enum ConfigType { cfgMainGame, cfgUserGame, + cfgTempGame, cfgMainKeys, - cfgUserKeys + cfgUserKeys, + cfgTempKeys }; class Config { private: std::pair properties; + Properties tempProperties; std::pair cfgType; std::pair fileNameParameter; std::pair fileName; @@ -92,10 +95,10 @@ public: //char getCharKey(const char *key) const; SDLKey getSDLKey(const char *key) const; - void setInt(const string &key, int value); - void setBool(const string &key, bool value); - void setFloat(const string &key, float value); - void setString(const string &key, const string &value); + void setInt(const string &key, int value, bool tempBuffer=false); + void setBool(const string &key, bool value, bool tempBuffer=false); + void setFloat(const string &key, float value, bool tempBuffer=false); + void setString(const string &key, const string &value, bool tempBuffer=false); vector getPathListForType(PathType type, string scenarioDir = ""); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 77957272..89ff0e44 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -3262,16 +3262,16 @@ int glestMain(int argc, char** argv) { printf("Forcing internal port# %d, external port# %d\n",internalPort,externalPort); - config.setInt("ServerPort",internalPort); - config.setInt("MasterServerExternalPort",externalPort); - config.setInt("FTPServerPort",internalPort+1); + config.setInt("ServerPort",internalPort,true); + config.setInt("MasterServerExternalPort",externalPort,true); + config.setInt("FTPServerPort",internalPort+1,true); if(paramPartPortsTokens.size() >= 3 && paramPartPortsTokens[2].length() > 0) { int statusPort = strToInt(paramPartPortsTokens[2]); printf("Forcing status port# %d\n",statusPort); - config.setInt("ServerAdminPort",statusPort); + config.setInt("ServerAdminPort",statusPort,true); } } else { @@ -3306,7 +3306,7 @@ int glestMain(int argc, char** argv) { if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_DISABLE_SOUND]) == true || hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) { - config.setString("FactorySound","None"); + config.setString("FactorySound","None",true); if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_MASTERSERVER_MODE])) == true) { //Logger::getInstance().setMasterserverMode(true); //Model::setMasterserverMode(true); @@ -3356,10 +3356,10 @@ int glestMain(int argc, char** argv) { Tokenize(settings,paramPartTokens,"x"); if(paramPartTokens.size() >= 2) { int newScreenWidth = strToInt(paramPartTokens[0]); - config.setInt("ScreenWidth",newScreenWidth); + config.setInt("ScreenWidth",newScreenWidth,true); int newScreenHeight = strToInt(paramPartTokens[1]); - config.setInt("ScreenHeight",newScreenHeight); + config.setInt("ScreenHeight",newScreenHeight,true); } else { printf("\nInvalid missing resolution settings specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); @@ -3388,7 +3388,7 @@ int glestMain(int argc, char** argv) { printf("Forcing colorbits [%s]\n",settings.c_str()); int newColorBits = strToInt(settings); - config.setInt("ColorBits",newColorBits); + config.setInt("ColorBits",newColorBits,true); } else { printf("\nInvalid missing colorbits settings specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); @@ -3411,7 +3411,7 @@ int glestMain(int argc, char** argv) { printf("Forcing depthbits [%s]\n",settings.c_str()); int newDepthBits = strToInt(settings); - config.setInt("DepthBits",newDepthBits); + config.setInt("DepthBits",newDepthBits,true); } else { printf("\nInvalid missing depthbits setting specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); @@ -3434,7 +3434,7 @@ int glestMain(int argc, char** argv) { printf("Forcing fullscreen [%s]\n",settings.c_str()); bool newFullScreenMode = strToBool(settings); - config.setBool("Windowed",!newFullScreenMode); + config.setBool("Windowed",!newFullScreenMode,true); } else { printf("\nInvalid missing fullscreen setting specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); @@ -3457,7 +3457,7 @@ int glestMain(int argc, char** argv) { printf("Forcing gamma [%s]\n",settings.c_str()); float newGammaValue = strToFloat(settings); - config.setFloat("GammaValue",newGammaValue); + config.setFloat("GammaValue",newGammaValue,true); } else { printf("\nInvalid missing gamma setting specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); @@ -3614,7 +3614,7 @@ int glestMain(int argc, char** argv) { printf("Running in auto test mode\n"); } if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_AUTO_TEST])) == true) { - Config::getInstance().setBool("AutoTest","true"); + Config::getInstance().setBool("AutoTest","true",true); int foundParamIndIndex = -1; hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_AUTO_TEST]) + string("="),&foundParamIndIndex);