From 21c1da2e1858af8d76f5858fafd99ba288f2fba5 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 3 Jan 2011 20:59:18 +0000 Subject: [PATCH] - added a new commandline parameter to display merged ini settings and also to filter on a specific ini setting --- source/glest_game/global/config.cpp | 44 +++++++++++ source/glest_game/global/config.h | 5 ++ source/glest_game/main/main.cpp | 82 ++++++++++++++++++++- source/shared_lib/include/util/properties.h | 6 +- 4 files changed, 130 insertions(+), 7 deletions(-) diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index d659450f..4d760e5f 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -389,6 +389,50 @@ void Config::setString(const string &key, const string &value){ properties.first.setString(key, value); } +vector > Config::getPropertiesFromContainer(const Properties &propertiesObj) const { + vector > result; + + int count = propertiesObj.getPropertyCount(); + for(int i = 0; i < count; ++i) { + pair property; + property.first = propertiesObj.getKey(i); + property.second = propertiesObj.getString(i); + result.push_back(property); + } + + return result; +} + +vector > Config::getMergedProperties() const { + vector > result = getMasterProperties(); + vector > resultUser = getUserProperties(); + for(int i = 0; i < resultUser.size(); ++i) { + const pair &propertyUser = resultUser[i]; + bool overrideProperty = false; + for(int j = 0; j < result.size(); ++j) { + pair &property = result[j]; + // Take the user property and override the original value + if(property.first == propertyUser.first) { + property.second = propertyUser.second; + break; + } + } + if(overrideProperty == false) { + result.push_back(propertyUser); + } + } + + return result; +} + +vector > Config::getMasterProperties() const { + return getPropertiesFromContainer(properties.first); +} + +vector > Config::getUserProperties() const { + return getPropertiesFromContainer(properties.second); +} + string Config::toString(){ return properties.first.toString(); } diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index 093ae956..167b5ae9 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -53,6 +53,7 @@ protected: char translateStringToCharKey(const string &value) const; static void CopyAll(Config *src,Config *dest); + vector > getPropertiesFromContainer(const Properties &propertiesObj) const; public: static Config &getInstance(std::pair type = std::make_pair(cfgMainGame,cfgUserGame) , @@ -79,6 +80,10 @@ public: vector getPathListForType(PathType type, string scenarioDir = ""); + vector > getMergedProperties() const; + vector > getMasterProperties() const; + vector > getUserProperties() const; + string toString(); }; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index d7daa617..d8033a8f 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -95,6 +95,7 @@ const char *GAME_ARGS[] = { "--data-path", "--ini-path", "--log-path", + "--show-ini-settings", "--verbose" }; @@ -115,6 +116,7 @@ enum GAME_ARG_TYPE { GAME_ARG_DATA_PATH, GAME_ARG_INI_PATH, GAME_ARG_LOG_PATH, + GAME_ARG_SHOW_INI_SETTINGS, GAME_ARG_VERBOSE_MODE }; @@ -799,6 +801,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\texample: %s %s=~/game_config/",argv0,GAME_ARGS[GAME_ARG_INI_PATH]); printf("\n%s=x\t\t\tSets the game logs path to x",GAME_ARGS[GAME_ARG_LOG_PATH]); printf("\n \t\texample: %s %s=~/game_logs/",argv0,GAME_ARGS[GAME_ARG_LOG_PATH]); + printf("\n%s=x\t\t\tdisplays merged ini settings information.",GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]); + printf("\n \t\tWhere x is an optional property name to filter (default shows all)."); + printf("\n \t\texample: %s %s=DebugMode",argv0,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]); printf("\n%s\t\t\tdisplays verbose information in the console.",GAME_ARGS[GAME_ARG_VERBOSE_MODE]); printf("\n\n"); @@ -1151,7 +1156,8 @@ int glestMain(int argc, char** argv) { hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CURL_INFO]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) { haveSpecialOutputCommandLineOption = true; @@ -1214,9 +1220,6 @@ int glestMain(int argc, char** argv) { return setupResult; } - // Setup the file crc thread - std::auto_ptr preCacheThread; - // Attempt to read ini files Config &config = Config::getInstance(); @@ -1273,6 +1276,77 @@ int glestMain(int argc, char** argv) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) == true) { + + vector filteredPropertyList; + if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) + string("=")) == true) { + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) + string("="),&foundParamIndIndex); + string filterList = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(filterList,paramPartTokens,"="); + if(paramPartTokens.size() >= 2) { + string tokenList = paramPartTokens[1]; + Tokenize(tokenList,filteredPropertyList,","); + + if(filteredPropertyList.size() > 0) { + printf("Filtering techtrees and only looking for the following:\n"); + for(int idx = 0; idx < filteredPropertyList.size(); ++idx) { + filteredPropertyList[idx] = trim(filteredPropertyList[idx]); + printf("%s\n",filteredPropertyList[idx].c_str()); + } + } + } + } + + printf("Main settings report\n"); + printf("====================\n"); + vector > mergedMainSettings = config.getMergedProperties(); + for(int i = 0; i < mergedMainSettings.size(); ++i) { + const pair &nameValue = mergedMainSettings[i]; + + bool displayProperty = false; + if(filteredPropertyList.size() > 0) { + if(find(filteredPropertyList.begin(),filteredPropertyList.end(),nameValue.first) != filteredPropertyList.end()) { + displayProperty = true; + } + } + else { + displayProperty = true; + } + + if(displayProperty == true) { + printf("Property Name [%s]\t\t\t\tValue[%s]\n",nameValue.first.c_str(),nameValue.second.c_str()); + } + } + + printf("\n\nMain key binding settings report\n"); + printf("====================================\n"); + vector > mergedKeySettings = configKeys.getMergedProperties(); + for(int i = 0; i < mergedKeySettings.size(); ++i) { + const pair &nameValue = mergedKeySettings[i]; + + bool displayProperty = false; + if(filteredPropertyList.size() > 0) { + if(find(filteredPropertyList.begin(),filteredPropertyList.end(),nameValue.first) != filteredPropertyList.end()) { + displayProperty = true; + } + } + else { + displayProperty = true; + } + + if(displayProperty == true) { + printf("Property Name [%s]\t\t\t\tValue[%s]\n",nameValue.first.c_str(),nameValue.second.c_str()); + } + } + + return -1; + } + + // Setup the file crc thread + std::auto_ptr preCacheThread; + //float pingTime = Socket::getAveragePingMS("soft-haus.com"); //printf("Ping time = %f\n",pingTime); diff --git a/source/shared_lib/include/util/properties.h b/source/shared_lib/include/util/properties.h index 64224c4e..4251b657 100644 --- a/source/shared_lib/include/util/properties.h +++ b/source/shared_lib/include/util/properties.h @@ -49,9 +49,9 @@ public: void load(const string &path); void save(const string &path); - int getPropertyCount() {return (int)propertyVector.size();} - string getKey(int i) {return propertyVector[i].first;} - string getString(int i) {return propertyVector[i].second;} + int getPropertyCount() const {return (int)propertyVector.size();} + string getKey(int i) const {return propertyVector[i].first;} + string getString(int i) const {return propertyVector[i].second;} bool getBool(const string &key, const char *defaultValueIfNotFound=NULL) const; int getInt(const string &key, const char *defaultValueIfNotFound=NULL) const;