diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 106dee84..1975fa11 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -1121,6 +1121,224 @@ void runTechValidationReport(int argc, char** argv) { } } + +void ShowINISettings(int argc, char **argv,Config &config,Config &configKeys) { + 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 properties 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("\nMain settings report\n"); + printf("====================\n"); + vector > mergedMainSettings = config.getMergedProperties(); + vector > mergedKeySettings = configKeys.getMergedProperties(); + + // Figure out the max # of tabs we need to format display nicely + int tabCount = 1; + 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) { + int requredTabs = (nameValue.first.length() / 8)+1; + if(nameValue.first.length() % 8) { + requredTabs++; + } + if(requredTabs > tabCount) { + tabCount = requredTabs; + } + } + } + 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) { + int requredTabs = (nameValue.first.length() / 8)+1; + if(nameValue.first.length() % 8) { + requredTabs++; + } + if(requredTabs > tabCount) { + tabCount = requredTabs; + } + } + } + + // Output the properties + 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]",nameValue.first.c_str()); + + int tabs = (nameValue.first.length() / 8) + 1; + for(int j = 0; j < (tabCount - tabs); ++j) { + printf("\t"); + } + + printf("Value [%s]\n",nameValue.second.c_str()); + } + } + + printf("\n\nMain key binding settings report\n"); + printf("====================================\n"); + + 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]",nameValue.first.c_str()); + + int tabs = (nameValue.first.length() / 8) + 1; + for(int j = 0; j < (tabCount - tabs); ++j) { + printf("\t"); + } + + printf("Value [%s]\n",nameValue.second.c_str()); + } + } + } +} + +void CheckForDuplicateData() { + Config &config = Config::getInstance(); + + vector maps; + std::vector results; + vector mapPaths = config.getPathListForType(ptMaps); + + findAll(mapPaths, "*.gbm", results, false, false, true); + copy(results.begin(), results.end(), std::back_inserter(maps)); + + results.clear(); + findAll(mapPaths, "*.mgm", results, false, false, true); + copy(results.begin(), results.end(), std::back_inserter(maps)); + + results.clear(); + std::sort(maps.begin(),maps.end()); + + if(maps.empty()) { + throw runtime_error("No maps were found!"); + } + + for(int i = 0; i < maps.size(); ++i) { + string map1 = maps[i]; + for(int j = 0; j < maps.size(); ++j) { + if(i != j) { + string map2 = maps[j]; + + //printf("i = %d map1 [%s] j = %d map2 [%s]\n",i,map1.c_str(),j,map2.c_str()); + + if(map1 == map2) { + char szBuf[4096]=""; + sprintf(szBuf,"You have duplicate maps for map [%s] in [%s] and [%s]",map1.c_str(),mapPaths[0].c_str(),mapPaths[1].c_str()); + throw runtime_error(szBuf); + } + } + } + } + + //tilesets + std::vector tileSets; + vector tilesetPaths = config.getPathListForType(ptTilesets); + findDirs(tilesetPaths, tileSets, false, true); + + if (tileSets.empty()) { + throw runtime_error("No tilesets were found!"); + } + + for(int i = 0; i < tileSets.size(); ++i) { + string tileset1 = tileSets[i]; + for(int j = 0; j < tileSets.size(); ++j) { + if(i != j) { + string tileset2 = tileSets[j]; + if(tileset1 == tileset2) { + char szBuf[4096]=""; + sprintf(szBuf,"You have duplicate tilesets for tileset [%s] in [%s] and [%s]",tileset1.c_str(),tilesetPaths[0].c_str(),tilesetPaths[1].c_str()); + throw runtime_error(szBuf); + + } + } + } + } + + vector techPaths = config.getPathListForType(ptTechs); + vector techTrees; + findDirs(techPaths, techTrees, false, true); + if(techTrees.empty()) { + throw runtime_error("No tech-trees were found!"); + } + + for(int i = 0; i < techTrees.size(); ++i) { + string techtree1 = techTrees[i]; + for(int j = 0; j < techTrees.size(); ++j) { + if(i != j) { + string techtree2 = techTrees[j]; + if(techtree1 == techtree2) { + char szBuf[4096]=""; + sprintf(szBuf,"You have duplicate techtrees for techtree [%s] in [%s] and [%s]",techtree1.c_str(),techTrees[0].c_str(),techTrees[1].c_str()); + throw runtime_error(szBuf); + + } + } + } + } +} int glestMain(int argc, char** argv) { #ifdef SL_LEAK_DUMP @@ -1278,136 +1496,7 @@ 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 properties 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("\nMain settings report\n"); - printf("====================\n"); - vector > mergedMainSettings = config.getMergedProperties(); - vector > mergedKeySettings = configKeys.getMergedProperties(); - - // Figure out the max # of tabs we need to format display nicely - int tabCount = 1; - 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) { - int requredTabs = (nameValue.first.length() / 8)+1; - if(nameValue.first.length() % 8) { - requredTabs++; - } - if(requredTabs > tabCount) { - tabCount = requredTabs; - } - } - } - 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) { - int requredTabs = (nameValue.first.length() / 8)+1; - if(nameValue.first.length() % 8) { - requredTabs++; - } - if(requredTabs > tabCount) { - tabCount = requredTabs; - } - } - } - - // Output the properties - 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]",nameValue.first.c_str()); - - int tabs = (nameValue.first.length() / 8) + 1; - for(int j = 0; j < (tabCount - tabs); ++j) { - printf("\t"); - } - - printf("Value [%s]\n",nameValue.second.c_str()); - } - } - - printf("\n\nMain key binding settings report\n"); - printf("====================================\n"); - - 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]",nameValue.first.c_str()); - - int tabs = (nameValue.first.length() / 8) + 1; - for(int j = 0; j < (tabCount - tabs); ++j) { - printf("\t"); - } - - printf("Value [%s]\n",nameValue.second.c_str()); - } - } - + ShowINISettings(argc,argv,config,configKeys); return -1; } @@ -1430,8 +1519,8 @@ int glestMain(int argc, char** argv) { mainWindow= new MainWindow(program); mainWindow->setUseDefaultCursorOnly(config.getBool("No2DMouseRendering","false")); - - SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //parse command line if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SERVER]) == true) { @@ -1537,6 +1626,12 @@ int glestMain(int argc, char** argv) { } } // Cache Player textures - END + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + + CheckForDuplicateData(); + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); //throw "BLAH!"; diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index 0da4f011..e97fc18b 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -108,8 +108,8 @@ public: // ===================================================== void Tokenize(const string& str,vector& tokens,const string& delimiters = " "); bool isdir(const char *path); -void findDirs(const vector &paths, vector &results, bool errorOnNotFound=false); -void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension=false, bool errorOnNotFound=true); +void findDirs(const vector &paths, vector &results, bool errorOnNotFound=false,bool keepDuplicates=false); +void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension=false, bool errorOnNotFound=true,bool keepDuplicates=false); void findAll(const string &path, vector &results, bool cutExtension=false, bool errorOnNotFound=true); int32 getFolderTreeContentsCheckSumRecursively(vector paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 244cf405..dc8a814d 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -204,7 +204,7 @@ void Tokenize(const string& str,vector& tokens,const string& delimiters) } } -void findDirs(const vector &paths, vector &results, bool errorOnNotFound) { +void findDirs(const vector &paths, vector &results, bool errorOnNotFound,bool keepDuplicates) { results.clear(); size_t pathCount = paths.size(); for(unsigned int idx = 0; idx < pathCount; idx++) { @@ -217,7 +217,7 @@ void findDirs(const vector &paths, vector &results, bool errorOn const string current_folder_path = paths[idx] + "/" + current_folder; if(isdir(current_folder_path.c_str()) == true) { - if(std::find(results.begin(),results.end(),current_folder) == results.end()) { + if(keepDuplicates == true || std::find(results.begin(),results.end(),current_folder) == results.end()) { results.push_back(current_folder); } } @@ -228,7 +228,7 @@ void findDirs(const vector &paths, vector &results, bool errorOn std::sort(results.begin(),results.end()); } -void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension, bool errorOnNotFound) { +void findAll(const vector &paths, const string &fileFilter, vector &results, bool cutExtension, bool errorOnNotFound, bool keepDuplicates) { results.clear(); size_t pathCount = paths.size(); for(unsigned int idx = 0; idx < pathCount; idx++) { @@ -238,7 +238,7 @@ void findAll(const vector &paths, const string &fileFilter, vector 0) { for(unsigned int folder_index = 0; folder_index < current_results.size(); folder_index++) { string ¤t_file = current_results[folder_index]; - if(std::find(results.begin(),results.end(),current_file) == results.end()) { + if(keepDuplicates == true || std::find(results.begin(),results.end(),current_file) == results.end()) { results.push_back(current_file); } }