From 1134ad399d23fbe6617498fb91a544d8978c85a8 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Mon, 4 Nov 2013 07:21:04 +0000 Subject: [PATCH] - added a more graceful way to handle more serious errors during data validation commands in order to offer more detailed error analysis --- source/glest_game/main/main.cpp | 966 +++++++++--------- source/glest_game/types/faction_type.cpp | 101 +- source/glest_game/types/faction_type.h | 4 +- source/glest_game/types/tech_tree.cpp | 39 +- source/glest_game/types/tech_tree.h | 9 +- source/glest_game/types/unit_type.cpp | 110 +- source/glest_game/types/unit_type.h | 7 +- source/glest_game/types/upgrade_type.cpp | 39 +- source/glest_game/types/upgrade_type.h | 4 +- source/glest_game/world/world.cpp | 6 +- source/glest_game/world/world.h | 4 +- source/shared_lib/include/graphics/vec.h | 1 + .../sources/platform/sdl/platform_util.cpp | 6 +- 13 files changed, 703 insertions(+), 593 deletions(-) diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 75b60685..6549b5fd 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2022,488 +2022,495 @@ void runTechValidationForPath(string techPath, string techName, Config &config = Config::getInstance(); vector otherTechPaths = config.getPathListForType(ptTechs,""); pathList.insert(pathList.end(), otherTechPaths.begin(), otherTechPaths.end()); - world.loadTech(pathList, techName, factions, &checksum, loadedFileList); - // Fixup paths with .. - { - std::map > > newLoadedFileList; - for( std::map > >::iterator iterMap = loadedFileList.begin(); - iterMap != loadedFileList.end(); ++iterMap) { - string loadedFile = iterMap->first; + try { + world.loadTech(pathList, techName, factions, &checksum, loadedFileList, true); - replaceAll(loadedFile,"//","/"); - replaceAll(loadedFile,"\\\\","\\"); - updatePathClimbingParts(loadedFile); + // Fixup paths with .. + { + std::map > > newLoadedFileList; + for( std::map > >::iterator iterMap = loadedFileList.begin(); + iterMap != loadedFileList.end(); ++iterMap) { + string loadedFile = iterMap->first; - if(newLoadedFileList.find(loadedFile) != newLoadedFileList.end()) { - for(unsigned int xx1 = 0; xx1 < iterMap->second.size(); ++xx1) { - pair &newVal = iterMap->second[xx1]; - replaceAll(newVal.first,"//","/"); - replaceAll(newVal.first,"\\\\","\\"); - updatePathClimbingParts(newVal.first); - replaceAll(newVal.second,"//","/"); - replaceAll(newVal.second,"\\\\","\\"); - updatePathClimbingParts(newVal.second); + replaceAll(loadedFile,"//","/"); + replaceAll(loadedFile,"\\\\","\\"); + updatePathClimbingParts(loadedFile); - newLoadedFileList[loadedFile].push_back(newVal); - } - } - else { - for(unsigned int xx1 = 0; xx1 < iterMap->second.size(); ++xx1) { - pair &newVal = iterMap->second[xx1]; - replaceAll(newVal.first,"//","/"); - replaceAll(newVal.first,"\\\\","\\"); - updatePathClimbingParts(newVal.first); - replaceAll(newVal.second,"//","/"); - replaceAll(newVal.second,"\\\\","\\"); - updatePathClimbingParts(newVal.second); - } + if(newLoadedFileList.find(loadedFile) != newLoadedFileList.end()) { + for(unsigned int xx1 = 0; xx1 < iterMap->second.size(); ++xx1) { + pair &newVal = iterMap->second[xx1]; + replaceAll(newVal.first,"//","/"); + replaceAll(newVal.first,"\\\\","\\"); + updatePathClimbingParts(newVal.first); + replaceAll(newVal.second,"//","/"); + replaceAll(newVal.second,"\\\\","\\"); + updatePathClimbingParts(newVal.second); - newLoadedFileList[loadedFile] = iterMap->second; - } - } - loadedFileList = newLoadedFileList; - } - - // Validate the faction setup to ensure we don't have any bad associations - std::vector resultErrors = world.validateFactionTypes(); - if(resultErrors.empty() == false) { - techtree_errors = true; - // Display the validation errors - string errorText = "\nErrors were detected:\n=====================\n"; - for(int i = 0; i < resultErrors.size(); ++i) { - if(i > 0) { - errorText += "\n"; - } - errorText = errorText + resultErrors[i]; - } - errorText += "\n=====================\n"; - //throw megaglest_runtime_error(errorText); - printf("%s",errorText.c_str()); - } - - // Validate the faction resource setup to ensure we don't have any bad associations - printf("\nChecking resources, count = %d\n",world.getTechTree()->getResourceTypeCount()); - - for(int i = 0; i < world.getTechTree()->getResourceTypeCount(); ++i) { - printf("Found techtree resource [%s]\n",world.getTechTree()->getResourceType(i)->getName().c_str()); - } - - resultErrors = world.validateResourceTypes(); - if(resultErrors.empty() == false) { - techtree_errors = true; - // Display the validation errors - string errorText = "\nErrors were detected:\n=====================\n"; - for(int i = 0; i < resultErrors.size(); ++i) { - if(i > 0) { - errorText += "\n"; - } - errorText = errorText + resultErrors[i]; - } - errorText += "\n=====================\n"; - //throw megaglest_runtime_error(errorText); - printf("%s",errorText.c_str()); - } - - // Now check for unused files in the techtree - std::map > > foundFileList; - for(unsigned int i = 0; i < pathList.size(); ++i) { - string path = pathList[i]; - endPathWithSlash(path); - path = path + techName + "/"; - - replaceAll(path, "//", "/"); - replaceAll(path, "\\\\", "\\"); - - vector foundFiles = getFolderTreeContentsListRecursively(path + "*.", ""); - for(unsigned int j = 0; j < foundFiles.size(); ++j) { - string file = foundFiles[j]; - replaceAll(file, "//", "/"); - replaceAll(file, "\\\\", "\\"); - - if( file.find(GameConstants::LOADING_SCREEN_FILE) != string::npos || - file.find(GameConstants::PREVIEW_SCREEN_FILE) != string::npos || - file.find(GameConstants::HUD_SCREEN_FILE) != string::npos) { - continue; - } - if(file.find("/factions/") != string::npos) { - bool includeFaction = false; - for ( set::iterator it = factions.begin(); it != factions.end(); ++it ) { - string currentFaction = *it; - if(file.find("/factions/" + currentFaction) != string::npos) { - includeFaction = true; - break; - } - } - if(includeFaction == false) { - continue; - } - } - - replaceAll(file,"//","/"); - replaceAll(file,"\\\\","\\"); - - foundFileList[file].push_back(make_pair(path,path)); - } - } - - printf("Found techtree filecount = " MG_SIZE_T_SPECIFIER ", used = " MG_SIZE_T_SPECIFIER "\n",foundFileList.size(),loadedFileList.size()); - -// for( std::map >::iterator iterMap = loadedFileList.begin(); -// iterMap != loadedFileList.end(); ++iterMap) { -// string foundFile = iterMap->first; -// -// if(foundFile.find("golem_ack1.wav") != string::npos) { -// printf("FOUND file [%s]\n",foundFile.c_str()); -// } -// } - - int purgeCount = 0; - bool foundUnusedFile = false; - for( std::map > >::iterator iterMap = foundFileList.begin(); - iterMap != foundFileList.end(); ++iterMap) { - string foundFile = iterMap->first; - replaceAll(foundFile, "//", "/"); - replaceAll(foundFile, "\\\\", "\\"); - - if(loadedFileList.find(foundFile) == loadedFileList.end() && - foundFile.find("lang/") == foundFile.npos) { - if(foundUnusedFile == false) { - printf("\nLine ref: %d, Warning, unused files were detected - START:\n=====================\n",__LINE__); - } - foundUnusedFile = true; - - printf("[%s]\n",foundFile.c_str()); - - string fileName = extractFileFromDirectoryPath(foundFile); - if(loadedFileList.find(fileName) != loadedFileList.end()) { - printf("possible match on [%s] ?\n",loadedFileList.find(fileName)->first.c_str()); - } - else if(purgeUnusedFiles == true) { - off_t fileSize = getFileSize(foundFile); - // convert to MB - purgedMegaBytes += ((double)fileSize / 1048576.0); - purgeCount++; - - if(svnPurgeFiles == true) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"svn delete \"%s\"",foundFile.c_str()); - bool svnOk = executeShellCommand(szBuf,0); - if(svnOk == false) { - throw megaglest_runtime_error("Call to command failed [" + string(szBuf) + "]"); + newLoadedFileList[loadedFile].push_back(newVal); } } else { - removeFile(foundFile); + for(unsigned int xx1 = 0; xx1 < iterMap->second.size(); ++xx1) { + pair &newVal = iterMap->second[xx1]; + replaceAll(newVal.first,"//","/"); + replaceAll(newVal.first,"\\\\","\\"); + updatePathClimbingParts(newVal.first); + replaceAll(newVal.second,"//","/"); + replaceAll(newVal.second,"\\\\","\\"); + updatePathClimbingParts(newVal.second); + } + + newLoadedFileList[loadedFile] = iterMap->second; } } + loadedFileList = newLoadedFileList; } - } - if(foundUnusedFile == true) { - if(purgedMegaBytes > 0) { - printf("Purged %.2f MB (%d) in files\n",purgedMegaBytes,purgeCount); - } - printf("\nLine ref: %d, Warning, unused files were detected - END:\n",__LINE__); - } - if(showDuplicateFiles == true) { - std::map > mapDuplicateFiles; - // Now check for duplicate data content - for(std::map > >::iterator iterMap = loadedFileList.begin(); - iterMap != loadedFileList.end(); ++iterMap) { - string fileName = iterMap->first; - Checksum checksum; - checksum.addFile(fileName); - uint32 crcValue = checksum.getSum(); - if(crcValue == 0) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"Error calculating CRC for file [%s]",fileName.c_str()); - throw megaglest_runtime_error(szBuf); + // Validate the faction setup to ensure we don't have any bad associations + std::vector resultErrors = world.validateFactionTypes(); + if(resultErrors.empty() == false) { + techtree_errors = true; + // Display the validation errors + string errorText = "\nErrors were detected:\n=====================\n"; + for(int i = 0; i < resultErrors.size(); ++i) { + if(i > 0) { + errorText += "\n"; + } + errorText = errorText + resultErrors[i]; } - // else { - // printf("** CRC for file [%s] is [%d] and has %d parents\n",fileName.c_str(),crcValue,(int)iterMap->second.size()); - // } - mapDuplicateFiles[crcValue].push_back(fileName); + errorText += "\n=====================\n"; + //throw megaglest_runtime_error(errorText); + printf("%s",errorText.c_str()); } - double duplicateMegaBytesPurged=0; - int duplicateCountPurged=0; + // Validate the faction resource setup to ensure we don't have any bad associations + printf("\nChecking resources, count = %d\n",world.getTechTree()->getResourceTypeCount()); - double duplicateMegaBytes=0; - int duplicateCount=0; + for(int i = 0; i < world.getTechTree()->getResourceTypeCount(); ++i) { + printf("Found techtree resource [%s]\n",world.getTechTree()->getResourceType(i)->getName().c_str()); + } - bool foundDuplicates = false; - for(std::map >::iterator iterMap = mapDuplicateFiles.begin(); - iterMap != mapDuplicateFiles.end(); ++iterMap) { - vector &fileList = iterMap->second; - if(fileList.size() > 1) { - if(foundDuplicates == false) { - foundDuplicates = true; - printf("\nWarning, duplicate files were detected - START:\n=====================\n"); + resultErrors = world.validateResourceTypes(); + if(resultErrors.empty() == false) { + techtree_errors = true; + // Display the validation errors + string errorText = "\nErrors were detected:\n=====================\n"; + for(int i = 0; i < resultErrors.size(); ++i) { + if(i > 0) { + errorText += "\n"; + } + errorText = errorText + resultErrors[i]; + } + errorText += "\n=====================\n"; + //throw megaglest_runtime_error(errorText); + printf("%s",errorText.c_str()); + } + + // Now check for unused files in the techtree + std::map > > foundFileList; + for(unsigned int i = 0; i < pathList.size(); ++i) { + string path = pathList[i]; + endPathWithSlash(path); + path = path + techName + "/"; + + replaceAll(path, "//", "/"); + replaceAll(path, "\\\\", "\\"); + + vector foundFiles = getFolderTreeContentsListRecursively(path + "*.", ""); + for(unsigned int j = 0; j < foundFiles.size(); ++j) { + string file = foundFiles[j]; + replaceAll(file, "//", "/"); + replaceAll(file, "\\\\", "\\"); + + if( file.find(GameConstants::LOADING_SCREEN_FILE) != string::npos || + file.find(GameConstants::PREVIEW_SCREEN_FILE) != string::npos || + file.find(GameConstants::HUD_SCREEN_FILE) != string::npos) { + continue; + } + if(file.find("/factions/") != string::npos) { + bool includeFaction = false; + for ( set::iterator it = factions.begin(); it != factions.end(); ++it ) { + string currentFaction = *it; + if(file.find("/factions/" + currentFaction) != string::npos) { + includeFaction = true; + break; + } + } + if(includeFaction == false) { + continue; + } } - printf("----- START duplicate files for CRC [%u] count [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",iterMap->first,fileList.size(),fileList[0].c_str()); + replaceAll(file,"//","/"); + replaceAll(file,"\\\\","\\"); - map parentList; - for(unsigned int idx = 0; idx < fileList.size(); ++idx) { - string duplicateFile = fileList[idx]; - if(idx > 0) { - off_t fileSize = getFileSize(duplicateFile); - // convert to MB - duplicateMegaBytes += ((double)fileSize / 1048576.0); - duplicateCount++; + foundFileList[file].push_back(make_pair(path,path)); + } + } + + printf("Found techtree filecount = " MG_SIZE_T_SPECIFIER ", used = " MG_SIZE_T_SPECIFIER "\n",foundFileList.size(),loadedFileList.size()); + + // for( std::map >::iterator iterMap = loadedFileList.begin(); + // iterMap != loadedFileList.end(); ++iterMap) { + // string foundFile = iterMap->first; + // + // if(foundFile.find("golem_ack1.wav") != string::npos) { + // printf("FOUND file [%s]\n",foundFile.c_str()); + // } + // } + + int purgeCount = 0; + bool foundUnusedFile = false; + for( std::map > >::iterator iterMap = foundFileList.begin(); + iterMap != foundFileList.end(); ++iterMap) { + string foundFile = iterMap->first; + replaceAll(foundFile, "//", "/"); + replaceAll(foundFile, "\\\\", "\\"); + + if(loadedFileList.find(foundFile) == loadedFileList.end() && + foundFile.find("lang/") == foundFile.npos) { + if(foundUnusedFile == false) { + printf("\nLine ref: %d, Warning, unused files were detected - START:\n=====================\n",__LINE__); + } + foundUnusedFile = true; + + printf("[%s]\n",foundFile.c_str()); + + string fileName = extractFileFromDirectoryPath(foundFile); + if(loadedFileList.find(fileName) != loadedFileList.end()) { + printf("possible match on [%s] ?\n",loadedFileList.find(fileName)->first.c_str()); + } + else if(purgeUnusedFiles == true) { + off_t fileSize = getFileSize(foundFile); + // convert to MB + purgedMegaBytes += ((double)fileSize / 1048576.0); + purgeCount++; + + if(svnPurgeFiles == true) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"svn delete \"%s\"",foundFile.c_str()); + bool svnOk = executeShellCommand(szBuf,0); + if(svnOk == false) { + throw megaglest_runtime_error("Call to command failed [" + string(szBuf) + "]"); + } } else { - printf("\n"); + removeFile(foundFile); } - - printf("[%s]\n",duplicateFile.c_str()); - std::map > >::iterator iterFind = loadedFileList.find(duplicateFile); - if(iterFind != loadedFileList.end()) { - for(unsigned int jdx = 0; jdx < iterFind->second.size(); jdx++) { - parentList[iterFind->second[jdx].first]++; - } - } - - //!!! - string newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); - string expandedNewCommonFileName = newCommonFileName; - std::map mapExtraTagReplacementValues; - string techCommonData = techPath + techName + "/commondata/"; - replaceAll(techCommonData, "//", "/"); - mapExtraTagReplacementValues["$COMMONDATAPATH"] = techCommonData; - mapExtraTagReplacementValues = Properties::getTagReplacementValues(&mapExtraTagReplacementValues); - Properties::applyTagsToValue(expandedNewCommonFileName,&mapExtraTagReplacementValues); - replaceAll(expandedNewCommonFileName, "//", "/"); - - //printf("**** Checking for partial commondata scenario [%s] [%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); - //if(StartsWith(duplicateFile, expandedNewCommonFileName) == true) { - // throw megaglest_runtime_error("ERROR, this configuration has partial common data and duplicates, aborting.."); - //} } + } + } + if(foundUnusedFile == true) { + if(purgedMegaBytes > 0) { + printf("Purged %.2f MB (%d) in files\n",purgedMegaBytes,purgeCount); + } + printf("\nLine ref: %d, Warning, unused files were detected - END:\n",__LINE__); + } - printf("----- Finding parents for duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); - - for(map::iterator iterMap1 = parentList.begin(); - iterMap1 != parentList.end(); ++iterMap1) { - - if(iterMap1 == parentList.begin()) { - printf("\tParents:\n"); - } - printf("\t[%s]\n",iterMap1->first.c_str()); + if(showDuplicateFiles == true) { + std::map > mapDuplicateFiles; + // Now check for duplicate data content + for(std::map > >::iterator iterMap = loadedFileList.begin(); + iterMap != loadedFileList.end(); ++iterMap) { + string fileName = iterMap->first; + Checksum checksum; + checksum.addFile(fileName); + uint32 crcValue = checksum.getSum(); + if(crcValue == 0) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"Error calculating CRC for file [%s]",fileName.c_str()); + throw megaglest_runtime_error(szBuf); } + // else { + // printf("** CRC for file [%s] is [%d] and has %d parents\n",fileName.c_str(),crcValue,(int)iterMap->second.size()); + // } + mapDuplicateFiles[crcValue].push_back(fileName); + } - if(purgeDuplicateFiles == true) { - //printf("\nPurge Duplicate Files detected - START:\n=====================\n"); + double duplicateMegaBytesPurged=0; + int duplicateCountPurged=0; - printf("----- move / remove duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); - // First move first duplicate to commondata and delete all other copies - string newCommonFileName = ""; + double duplicateMegaBytes=0; + int duplicateCount=0; + + bool foundDuplicates = false; + for(std::map >::iterator iterMap = mapDuplicateFiles.begin(); + iterMap != mapDuplicateFiles.end(); ++iterMap) { + vector &fileList = iterMap->second; + if(fileList.size() > 1) { + if(foundDuplicates == false) { + foundDuplicates = true; + printf("\nWarning, duplicate files were detected - START:\n=====================\n"); + } + + printf("----- START duplicate files for CRC [%u] count [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",iterMap->first,fileList.size(),fileList[0].c_str()); + + map parentList; for(unsigned int idx = 0; idx < fileList.size(); ++idx) { string duplicateFile = fileList[idx]; - string fileExt = extractExtension(duplicateFile); - if(fileExt == "wav" || fileExt == "ogg") { + if(idx > 0) { off_t fileSize = getFileSize(duplicateFile); + // convert to MB + duplicateMegaBytes += ((double)fileSize / 1048576.0); + duplicateCount++; + } + else { + printf("\n"); + } - printf("#1 [%u / " MG_SIZE_T_SPECIFIER "] removing duplicate [%s]\n",idx,fileList.size(),duplicateFile.c_str()); + printf("[%s]\n",duplicateFile.c_str()); + std::map > >::iterator iterFind = loadedFileList.find(duplicateFile); + if(iterFind != loadedFileList.end()) { + for(unsigned int jdx = 0; jdx < iterFind->second.size(); jdx++) { + parentList[iterFind->second[jdx].first]++; + } + } - if(idx == 0) { - newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); + //!!! + string newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); + string expandedNewCommonFileName = newCommonFileName; + std::map mapExtraTagReplacementValues; + string techCommonData = techPath + techName + "/commondata/"; + replaceAll(techCommonData, "//", "/"); + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techCommonData; + mapExtraTagReplacementValues = Properties::getTagReplacementValues(&mapExtraTagReplacementValues); + Properties::applyTagsToValue(expandedNewCommonFileName,&mapExtraTagReplacementValues); + replaceAll(expandedNewCommonFileName, "//", "/"); - string expandedNewCommonFileName = newCommonFileName; + //printf("**** Checking for partial commondata scenario [%s] [%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + //if(StartsWith(duplicateFile, expandedNewCommonFileName) == true) { + // throw megaglest_runtime_error("ERROR, this configuration has partial common data and duplicates, aborting.."); + //} + } - std::map mapExtraTagReplacementValues; + printf("----- Finding parents for duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); - string techCommonData = techPath + techName + "/commondata/"; - replaceAll(techCommonData, "//", "/"); + for(map::iterator iterMap1 = parentList.begin(); + iterMap1 != parentList.end(); ++iterMap1) { - mapExtraTagReplacementValues["$COMMONDATAPATH"] = techCommonData; - mapExtraTagReplacementValues = Properties::getTagReplacementValues(&mapExtraTagReplacementValues); - Properties::applyTagsToValue(expandedNewCommonFileName,&mapExtraTagReplacementValues); - replaceAll(expandedNewCommonFileName, "//", "/"); - createDirectoryPaths(extractDirectoryPathFromFile(expandedNewCommonFileName)); + if(iterMap1 == parentList.begin()) { + printf("\tParents:\n"); + } + printf("\t[%s]\n",iterMap1->first.c_str()); + } - if(svnPurgeFiles == true) { - copyFileTo(duplicateFile, expandedNewCommonFileName); + if(purgeDuplicateFiles == true) { + //printf("\nPurge Duplicate Files detected - START:\n=====================\n"); - char szBuf[8096]=""; - snprintf(szBuf,8096,"svn delete \"%s\"",duplicateFile.c_str()); - bool svnOk = executeShellCommand(szBuf,0); - if(svnOk == false) { - throw megaglest_runtime_error("Call to command failed [" + string(szBuf) + "]"); - } - printf("*** Duplicate file:\n[%s]\nwas svn deleted and copied to:\n[%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); - } - else { - //int result = 0; - printf("moving duplicate [%s] to common data [%s] expanded to [%s]\n",duplicateFile.c_str(),newCommonFileName.c_str(),expandedNewCommonFileName.c_str()); + printf("----- move / remove duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); + // First move first duplicate to commondata and delete all other copies + string newCommonFileName = ""; + for(unsigned int idx = 0; idx < fileList.size(); ++idx) { + string duplicateFile = fileList[idx]; + string fileExt = extractExtension(duplicateFile); + if(fileExt == "wav" || fileExt == "ogg") { + off_t fileSize = getFileSize(duplicateFile); + + printf("#1 [%u / " MG_SIZE_T_SPECIFIER "] removing duplicate [%s]\n",idx,fileList.size(),duplicateFile.c_str()); + + if(idx == 0) { + newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); + + string expandedNewCommonFileName = newCommonFileName; + + std::map mapExtraTagReplacementValues; + + string techCommonData = techPath + techName + "/commondata/"; + replaceAll(techCommonData, "//", "/"); + + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techCommonData; + mapExtraTagReplacementValues = Properties::getTagReplacementValues(&mapExtraTagReplacementValues); + Properties::applyTagsToValue(expandedNewCommonFileName,&mapExtraTagReplacementValues); + replaceAll(expandedNewCommonFileName, "//", "/"); + createDirectoryPaths(extractDirectoryPathFromFile(expandedNewCommonFileName)); + + if(svnPurgeFiles == true) { + copyFileTo(duplicateFile, expandedNewCommonFileName); - int result = rename(duplicateFile.c_str(),expandedNewCommonFileName.c_str()); - if(result != 0) { char szBuf[8096]=""; - char *errmsg = strerror(errno); - snprintf(szBuf,8096,"!!! Error [%s] Could not rename [%s] to [%s]!",errmsg,duplicateFile.c_str(),expandedNewCommonFileName.c_str()); - throw megaglest_runtime_error(szBuf); + snprintf(szBuf,8096,"svn delete \"%s\"",duplicateFile.c_str()); + bool svnOk = executeShellCommand(szBuf,0); + if(svnOk == false) { + throw megaglest_runtime_error("Call to command failed [" + string(szBuf) + "]"); + } + printf("*** Duplicate file:\n[%s]\nwas svn deleted and copied to:\n[%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); } else { - printf("*** Duplicate file:\n[%s]\nwas renamed to:\n[%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + //int result = 0; + printf("moving duplicate [%s] to common data [%s] expanded to [%s]\n",duplicateFile.c_str(),newCommonFileName.c_str(),expandedNewCommonFileName.c_str()); + + int result = rename(duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + if(result != 0) { + char szBuf[8096]=""; + char *errmsg = strerror(errno); + snprintf(szBuf,8096,"!!! Error [%s] Could not rename [%s] to [%s]!",errmsg,duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + throw megaglest_runtime_error(szBuf); + } + else { + printf("*** Duplicate file:\n[%s]\nwas renamed to:\n[%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + } } } - } - else { - if(svnPurgeFiles == true) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"svn delete \"%s\"",duplicateFile.c_str()); - bool svnOk = executeShellCommand(szBuf,0); - if(svnOk == false) { - throw megaglest_runtime_error("Call to command failed [" + string(szBuf) + "]"); - } - printf("*** Duplicate file:\n[%s]\nwas svn deleted\n",duplicateFile.c_str()); - } else { - printf("removing duplicate [%s]\n",duplicateFile.c_str()); - removeFile(duplicateFile); - } - printf("*** Duplicate file:\n[%s]\nwas removed\n",duplicateFile.c_str()); + if(svnPurgeFiles == true) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"svn delete \"%s\"",duplicateFile.c_str()); + bool svnOk = executeShellCommand(szBuf,0); + if(svnOk == false) { + throw megaglest_runtime_error("Call to command failed [" + string(szBuf) + "]"); + } + printf("*** Duplicate file:\n[%s]\nwas svn deleted\n",duplicateFile.c_str()); + } + else { + printf("removing duplicate [%s]\n",duplicateFile.c_str()); + removeFile(duplicateFile); + } + printf("*** Duplicate file:\n[%s]\nwas removed\n",duplicateFile.c_str()); - // convert to MB - duplicateMegaBytesPurged += ((double)fileSize / 1048576.0); - duplicateCountPurged++; + // convert to MB + duplicateMegaBytesPurged += ((double)fileSize / 1048576.0); + duplicateCountPurged++; + } } } + + printf("----- update XML files for duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); + std::map mapUniqueParentList; + + // Update the XML files to point to the new single copy in commondata + for(unsigned int idx = 0; idx < fileList.size(); ++idx) { + string duplicateFile = fileList[idx]; + string fileExt = extractExtension(duplicateFile); + if(fileExt == "wav" || fileExt == "ogg") { + std::map > >::iterator iterFind2 = loadedFileList.find(duplicateFile); + if(iterFind2 != loadedFileList.end()) { + for(unsigned int jdx1 = 0; jdx1 < iterFind2->second.size(); jdx1++) { + string parentFile = iterFind2->second[jdx1].first; + string searchText = iterFind2->second[jdx1].second; + + if(mapUniqueParentList.find(parentFile) == mapUniqueParentList.end()) { + printf("*** Searching parent file:\n[%s]\nfor duplicate file reference:\n[%s]\nto replace with newname:\n[%s]\n",parentFile.c_str(),searchText.c_str(),newCommonFileName.c_str()); + bool foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, false); + printf("foundText = %d\n",foundText); + if(foundText == false) { + + string techCommonData = techPath + techName + "/commondata/"; + replaceAll(techCommonData, "//", "/"); + + //printf("WARNING #1 techCommonData check\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str()); + + if(StartsWith(searchText, techCommonData) == true) { + printf("WARNING #1 [%d] techCommonData check\n[%s]\n[%s]\n[%s]\n[%s]\n", + foundText,parentFile.c_str(),techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str()); + + replaceAll(searchText, techCommonData, "$COMMONDATAPATH/"); + foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, false); + + printf("WARNING #2 [%d] techCommonData check\n[%s]\n[%s]\n[%s]\n[%s]\n", + foundText,parentFile.c_str(),techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str()); + } + if(foundText == false) { + //printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str()); + + char szBuf[8096]=""; + snprintf(szBuf,8096,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str()); + printf("\n\n=================================================\n%s",szBuf); + + throw megaglest_runtime_error(szBuf); + } + } + mapUniqueParentList[parentFile]++; + } + } + } + } + } + + //printf("\nPurge Duplicate Files detected - END:\n=====================\n"); } + else { + //printf("\nPurge Duplicate Files DISABLED - START:\n=====================\n"); - printf("----- update XML files for duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); - std::map mapUniqueParentList; + string newCommonFileName = ""; + for(unsigned int idx = 0; idx < fileList.size(); ++idx) { + string duplicateFile = fileList[idx]; + string fileExt = extractExtension(duplicateFile); + if(fileExt == "wav" || fileExt == "ogg") { + off_t fileSize = getFileSize(duplicateFile); + if(idx == 0) { + newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); + break; + } + } + } - // Update the XML files to point to the new single copy in commondata - for(unsigned int idx = 0; idx < fileList.size(); ++idx) { - string duplicateFile = fileList[idx]; - string fileExt = extractExtension(duplicateFile); - if(fileExt == "wav" || fileExt == "ogg") { - std::map > >::iterator iterFind2 = loadedFileList.find(duplicateFile); - if(iterFind2 != loadedFileList.end()) { - for(unsigned int jdx1 = 0; jdx1 < iterFind2->second.size(); jdx1++) { - string parentFile = iterFind2->second[jdx1].first; - string searchText = iterFind2->second[jdx1].second; + //printf("\nPurge Duplicate Files #2 DISABLED [" MG_SIZE_T_SPECIFIER "] - START:\n=====================\n",fileList.size()); - if(mapUniqueParentList.find(parentFile) == mapUniqueParentList.end()) { - printf("*** Searching parent file:\n[%s]\nfor duplicate file reference:\n[%s]\nto replace with newname:\n[%s]\n",parentFile.c_str(),searchText.c_str(),newCommonFileName.c_str()); - bool foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, false); - printf("foundText = %d\n",foundText); + for(unsigned int idx = 0; idx < fileList.size(); ++idx) { + string duplicateFile = fileList[idx]; + string fileExt = extractExtension(duplicateFile); + if(fileExt == "wav" || fileExt == "ogg") { + std::map > >::iterator iterFind4 = loadedFileList.find(duplicateFile); + if(iterFind4 != loadedFileList.end()) { + for(unsigned int jdx = 0; jdx < iterFind4->second.size(); jdx++) { + string parentFile = iterFind4->second[jdx].first; + string searchText = iterFind4->second[jdx].second; + //replaceAll(parentFile, "//", "/"); + //replaceAll(parentFile, "\\\\", "\\"); + + //printf("*** Searching parent file:\n[%s]\nfor duplicate file reference:\n[%s]\nto replace with newname:\n[%s]\n",parentFile.c_str(),searchText.c_str(),newCommonFileName.c_str()); + bool foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, true); + //printf("foundText = %d\n",foundText); if(foundText == false) { - string techCommonData = techPath + techName + "/commondata/"; replaceAll(techCommonData, "//", "/"); //printf("WARNING #1 techCommonData check\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str()); if(StartsWith(searchText, techCommonData) == true) { - printf("WARNING #1 [%d] techCommonData check\n[%s]\n[%s]\n[%s]\n[%s]\n", - foundText,parentFile.c_str(),techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str()); - replaceAll(searchText, techCommonData, "$COMMONDATAPATH/"); - foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, false); + foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, true); - printf("WARNING #2 [%d] techCommonData check\n[%s]\n[%s]\n[%s]\n[%s]\n", - foundText,parentFile.c_str(),techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str()); + //printf("WARNING #2 techCommonData check\n[%s]\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str()); } if(foundText == false) { //printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str()); - char szBuf[8096]=""; - snprintf(szBuf,8096,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str()); - printf("\n\n=================================================\n%s",szBuf); + // Check if the sound file already references commandata + foundText = searchAndReplaceTextInFile(parentFile, newCommonFileName, newCommonFileName, true); + if(foundText == false) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str()); + printf("\n\n=================================================\n%s",szBuf); - throw megaglest_runtime_error(szBuf); - } - } - mapUniqueParentList[parentFile]++; - } - } - } - } - } - - //printf("\nPurge Duplicate Files detected - END:\n=====================\n"); - } - else { - //printf("\nPurge Duplicate Files DISABLED - START:\n=====================\n"); - - string newCommonFileName = ""; - for(unsigned int idx = 0; idx < fileList.size(); ++idx) { - string duplicateFile = fileList[idx]; - string fileExt = extractExtension(duplicateFile); - if(fileExt == "wav" || fileExt == "ogg") { - off_t fileSize = getFileSize(duplicateFile); - if(idx == 0) { - newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); - break; - } - } - } - - //printf("\nPurge Duplicate Files #2 DISABLED [" MG_SIZE_T_SPECIFIER "] - START:\n=====================\n",fileList.size()); - - for(unsigned int idx = 0; idx < fileList.size(); ++idx) { - string duplicateFile = fileList[idx]; - string fileExt = extractExtension(duplicateFile); - if(fileExt == "wav" || fileExt == "ogg") { - std::map > >::iterator iterFind4 = loadedFileList.find(duplicateFile); - if(iterFind4 != loadedFileList.end()) { - for(unsigned int jdx = 0; jdx < iterFind4->second.size(); jdx++) { - string parentFile = iterFind4->second[jdx].first; - string searchText = iterFind4->second[jdx].second; - //replaceAll(parentFile, "//", "/"); - //replaceAll(parentFile, "\\\\", "\\"); - - //printf("*** Searching parent file:\n[%s]\nfor duplicate file reference:\n[%s]\nto replace with newname:\n[%s]\n",parentFile.c_str(),searchText.c_str(),newCommonFileName.c_str()); - bool foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, true); - //printf("foundText = %d\n",foundText); - if(foundText == false) { - string techCommonData = techPath + techName + "/commondata/"; - replaceAll(techCommonData, "//", "/"); - - //printf("WARNING #1 techCommonData check\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str()); - - if(StartsWith(searchText, techCommonData) == true) { - replaceAll(searchText, techCommonData, "$COMMONDATAPATH/"); - foundText = searchAndReplaceTextInFile(parentFile, searchText, newCommonFileName, true); - - //printf("WARNING #2 techCommonData check\n[%s]\n[%s]\n[%s]\n",techCommonData.c_str(),searchText.c_str(),newCommonFileName.c_str()); - } - if(foundText == false) { - //printf("Error finding text [%s] in file [%s]",searchText.c_str(),parentFile.c_str()); - - // Check if the sound file already references commandata - foundText = searchAndReplaceTextInFile(parentFile, newCommonFileName, newCommonFileName, true); - if(foundText == false) { - char szBuf[8096]=""; - snprintf(szBuf,8096,"Line ref = %d, Error finding text\n[%s]\nin file\n[%s]\nnew Common File [%s]\n",__LINE__,searchText.c_str(),parentFile.c_str(),newCommonFileName.c_str()); - printf("\n\n=================================================\n%s",szBuf); - - throw megaglest_runtime_error(szBuf); + throw megaglest_runtime_error(szBuf); + } } } } } } } + + //printf("\nPurge Duplicate Files DISABLED - END:\n=====================\n"); } - //printf("\nPurge Duplicate Files DISABLED - END:\n=====================\n"); + + printf("----- END duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); } + } + if(foundDuplicates == true) { + printf("Duplicates %.2f MB (%d) in files\n",duplicateMegaBytes,duplicateCount); + printf("Duplicates purged %.2f MB (%d) in files\n",duplicateMegaBytesPurged,duplicateCountPurged); - - printf("----- END duplicate files [" MG_SIZE_T_SPECIFIER "] first file is [%s]\n",fileList.size(),fileList[0].c_str()); + printf("\nWarning, duplicate files were detected - END:\n"); } } - if(foundDuplicates == true) { - printf("Duplicates %.2f MB (%d) in files\n",duplicateMegaBytes,duplicateCount); - printf("Duplicates purged %.2f MB (%d) in files\n",duplicateMegaBytesPurged,duplicateCountPurged); - - printf("\nWarning, duplicate files were detected - END:\n"); - } + } + catch(const megaglest_runtime_error &ex) { + techtree_errors = true; + printf("\n\n****ERROR**** detected while validating the techName: %s\nMESSAGE: %s\n",techName.c_str(),ex.what()); } if(techtree_errors == false) { @@ -2554,98 +2561,105 @@ void runTechTranslationExtractionForPath(string techPath, string techName, Config &config = Config::getInstance(); vector otherTechPaths = config.getPathListForType(ptTechs,""); pathList.insert(pathList.end(), otherTechPaths.begin(), otherTechPaths.end()); - world.loadTech(pathList, techName, factions, &checksum, loadedFileList); - const TechTree *techtree = world.getTechTree(); - string translationFile = techtree->getPath(); - endPathWithSlash(translationFile); - translationFile += "lang/" + techName + "_default.lng"; - if(fileExists(translationFile) == false) { - string txFilePath = extractDirectoryPathFromFile(translationFile); - createDirectoryPaths(txFilePath); + try { + world.loadTech(pathList, techName, factions, &checksum, loadedFileList, true); + + const TechTree *techtree = world.getTechTree(); + string translationFile = techtree->getPath(); + endPathWithSlash(translationFile); + translationFile += "lang/" + techName + "_default.lng"; + if(fileExists(translationFile) == false) { + string txFilePath = extractDirectoryPathFromFile(translationFile); + createDirectoryPaths(txFilePath); #if defined(WIN32) && !defined(__MINGW32__) - FILE *fp = _wfopen(utf8_decode(translationFile).c_str(), L"w"); - std::ofstream txFile(fp); + FILE *fp = _wfopen(utf8_decode(translationFile).c_str(), L"w"); + std::ofstream txFile(fp); #else - std::ofstream txFile; - txFile.open(translationFile.c_str(), ios_base::out | ios_base::trunc); + std::ofstream txFile; + txFile.open(translationFile.c_str(), ios_base::out | ios_base::trunc); #endif - if(txFile.is_open() == true) { - txFile << "TechTreeName=" << techName << std::endl; + if(txFile.is_open() == true) { + txFile << "TechTreeName=" << techName << std::endl; - txFile << "; --------------" << std::endl; - txFile << "; Types of Armor" << std::endl; - for(unsigned int index = 0; index < techtree->getArmorTypeCount(); ++index) { - const ArmorType *at = techtree->getArmorTypeByIndex(index); - txFile << "ArmorTypeName_" << at->getName(false) << "=" << at->getName(false) << std::endl; - } - - txFile << "; -------------- " << std::endl; - txFile << "; Types of Attack" << std::endl; - for(unsigned int index = 0; index < techtree->getAttackTypeCount(); ++index) { - const AttackType *at = techtree->getAttackTypeByIndex(index); - txFile << "AttackTypeName_" << at->getName(false) << "=" << at->getName(false) << std::endl; - } - - txFile << "; ------------------" << std::endl; - txFile << "; Types of Resources" << std::endl; - for(unsigned int index = 0; index < techtree->getResourceTypeCount(); ++index) { - const ResourceType *rt = techtree->getResourceType(index); - txFile << "ResourceTypeName_" << rt->getName(false) << "=" << rt->getName(false) << std::endl; - } - - txFile << "; -----------------" << std::endl; - txFile << "; Types of Factions" << std::endl; - txFile << "FactionName_" << GameConstants::OBSERVER_SLOTNAME << "=" << GameConstants::OBSERVER_SLOTNAME << std::endl; - txFile << "FactionName_" << GameConstants::RANDOMFACTION_SLOTNAME << "=" << GameConstants::RANDOMFACTION_SLOTNAME << std::endl; - - for(unsigned int index = 0; index < techtree->getTypeCount(); ++index) { - const FactionType *ft = techtree->getType(index); - txFile << "FactionName_" << ft->getName(false) << "=" << ft->getName(false) << std::endl; - - txFile << "; ----------------------------------" << std::endl; - txFile << "; Types of Upgrades for this Faction" << std::endl; - for(unsigned int upgradeIndex = 0; upgradeIndex < ft->getUpgradeTypeCount(); ++upgradeIndex) { - const UpgradeType *upt = ft->getUpgradeType(upgradeIndex); - txFile << "UpgradeTypeName_" << upt->getName(false) << "=" << upt->getName(false) << std::endl; + txFile << "; --------------" << std::endl; + txFile << "; Types of Armor" << std::endl; + for(unsigned int index = 0; index < techtree->getArmorTypeCount(); ++index) { + const ArmorType *at = techtree->getArmorTypeByIndex(index); + txFile << "ArmorTypeName_" << at->getName(false) << "=" << at->getName(false) << std::endl; } - txFile << "; -------------------------------" << std::endl; - txFile << "; Types of Units for this Faction" << std::endl; - for(unsigned int unitIndex = 0; unitIndex < ft->getUnitTypeCount(); ++unitIndex) { - const UnitType *ut = ft->getUnitType(unitIndex); - txFile << "UnitTypeName_" << ut->getName(false) << "=" << ut->getName(false) << std::endl; + txFile << "; -------------- " << std::endl; + txFile << "; Types of Attack" << std::endl; + for(unsigned int index = 0; index < techtree->getAttackTypeCount(); ++index) { + const AttackType *at = techtree->getAttackTypeByIndex(index); + txFile << "AttackTypeName_" << at->getName(false) << "=" << at->getName(false) << std::endl; + } - txFile << "; --------------------" << std::endl; - txFile << "; Levels for this Unit" << std::endl; - for(unsigned int levelIndex = 0; levelIndex < ut->getLevelCount(); ++levelIndex) { - const Level *level = ut->getLevel(levelIndex); - txFile << "LevelName_" << level->getName(false) << "=" << level->getName(false) << std::endl; + txFile << "; ------------------" << std::endl; + txFile << "; Types of Resources" << std::endl; + for(unsigned int index = 0; index < techtree->getResourceTypeCount(); ++index) { + const ResourceType *rt = techtree->getResourceType(index); + txFile << "ResourceTypeName_" << rt->getName(false) << "=" << rt->getName(false) << std::endl; + } + + txFile << "; -----------------" << std::endl; + txFile << "; Types of Factions" << std::endl; + txFile << "FactionName_" << GameConstants::OBSERVER_SLOTNAME << "=" << GameConstants::OBSERVER_SLOTNAME << std::endl; + txFile << "FactionName_" << GameConstants::RANDOMFACTION_SLOTNAME << "=" << GameConstants::RANDOMFACTION_SLOTNAME << std::endl; + + for(unsigned int index = 0; index < techtree->getTypeCount(); ++index) { + const FactionType *ft = techtree->getType(index); + txFile << "FactionName_" << ft->getName(false) << "=" << ft->getName(false) << std::endl; + + txFile << "; ----------------------------------" << std::endl; + txFile << "; Types of Upgrades for this Faction" << std::endl; + for(unsigned int upgradeIndex = 0; upgradeIndex < ft->getUpgradeTypeCount(); ++upgradeIndex) { + const UpgradeType *upt = ft->getUpgradeType(upgradeIndex); + txFile << "UpgradeTypeName_" << upt->getName(false) << "=" << upt->getName(false) << std::endl; } txFile << "; -------------------------------" << std::endl; - txFile << "; Types of Commands for this Unit" << std::endl; - for(unsigned int commandIndex = 0; commandIndex < ut->getCommandTypeCount(); ++commandIndex) { - const CommandType *ct = ut->getCommandType(commandIndex); - txFile << "CommandName_" << ct->getName(false) << "=" << ct->getName(false) << std::endl; + txFile << "; Types of Units for this Faction" << std::endl; + for(unsigned int unitIndex = 0; unitIndex < ft->getUnitTypeCount(); ++unitIndex) { + const UnitType *ut = ft->getUnitType(unitIndex); + txFile << "UnitTypeName_" << ut->getName(false) << "=" << ut->getName(false) << std::endl; + + txFile << "; --------------------" << std::endl; + txFile << "; Levels for this Unit" << std::endl; + for(unsigned int levelIndex = 0; levelIndex < ut->getLevelCount(); ++levelIndex) { + const Level *level = ut->getLevel(levelIndex); + txFile << "LevelName_" << level->getName(false) << "=" << level->getName(false) << std::endl; + } + + txFile << "; -------------------------------" << std::endl; + txFile << "; Types of Commands for this Unit" << std::endl; + for(unsigned int commandIndex = 0; commandIndex < ut->getCommandTypeCount(); ++commandIndex) { + const CommandType *ct = ut->getCommandType(commandIndex); + txFile << "CommandName_" << ct->getName(false) << "=" << ct->getName(false) << std::endl; + } } } } - } - txFile.close(); + txFile.close(); #if defined(WIN32) && !defined(__MINGW32__) - if(fp) { - fclose(fp); - } + if(fp) { + fclose(fp); + } #endif + } + else { + printf("\n** Cannot product techtree translation file [%s] for techPath [%s] techName [%s] because the file already exists!\n",translationFile.c_str(),techPath.c_str(), techName.c_str()); + } } - else { - printf("\n** Cannot product techtree translation file [%s] for techPath [%s] techName [%s] because the file already exists!\n",translationFile.c_str(),techPath.c_str(), techName.c_str()); + catch(const megaglest_runtime_error &ex) { + printf("\n\n****ERROR**** detected while loading the techName: %s\nMESSAGE: %s\n",techName.c_str(),ex.what()); } + } printf("----------------------------------------------------------------"); } @@ -5434,6 +5448,8 @@ int glestMain(int argc, char** argv) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } catch(const megaglest_runtime_error &e) { + //printf("\n\nMAIN ERROR [%s]\n\n",e.what()); + if(GlobalStaticFlags::getIsNonGraphicalModeEnabled() == false) { soundThreadManager = (program != NULL ? program->getSoundThreadManager(true) : NULL); if(soundThreadManager) { @@ -5444,6 +5460,8 @@ int glestMain(int argc, char** argv) { if(program != NULL && program->getTryingRendererInit() == true && program->getRendererInitOk() == false) { + //printf("#2 MAIN ERROR \n"); + message(e.what(),GlobalStaticFlags::getIsNonGraphicalModeEnabled()); } } @@ -5451,6 +5469,8 @@ int glestMain(int argc, char** argv) { if(program == NULL || program->getTryingRendererInit() == false || (program->getTryingRendererInit() == true && program->getRendererInitOk() == true)) { + //printf("#3 MAIN ERROR \n"); + ExceptionHandler::handleRuntimeError(e); } } diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 02627039..87c33e19 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -38,7 +38,9 @@ FactionType::FactionType() { //load a faction, given a directory void FactionType::load(const string &factionName, const TechTree *techTree, Checksum* checksum, - Checksum *techtreeChecksum, std::map > > &loadedFileList) { + Checksum *techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -162,29 +164,49 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec int progressBaseValue=logger.getProgress(); for(int i = 0; i < unitTypes.size(); ++i) { string str= currentPath + "units/" + unitTypes[i].getName(); - unitTypes[i].loaddd(i, str, techTree,techTreePath, this, checksum,techtreeChecksum, - loadedFileList); - logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount())); - SDL_PumpEvents(); + + try { + unitTypes[i].loaddd(i, str, techTree,techTreePath, this, checksum,techtreeChecksum, + loadedFileList,validationMode); + logger.setProgress(progressBaseValue+(int)((((double)i + 1.0) / (double)unitTypes.size()) * 100.0/techTree->getTypeCount())); + SDL_PumpEvents(); + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + } + } } } catch(megaglest_runtime_error& ex) { - //printf("1111111b ex.wantStackTrace() = %d\n",ex.wantStackTrace()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); - //printf("222222b\n"); - throw megaglest_runtime_error("Error loading units: "+ currentPath + "\n" + ex.what(),!ex.wantStackTrace()); + throw megaglest_runtime_error("Error loading units: "+ currentPath + "\nMessage: " + ex.what(),!ex.wantStackTrace()); } catch(const exception &e) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what()); - throw megaglest_runtime_error("Error loading units: "+ currentPath + "\n" + e.what()); + throw megaglest_runtime_error("Error loading units: "+ currentPath + "\nMessage: " + e.what()); } // b2) load upgrades try{ for(int i = 0; i < upgradeTypes.size(); ++i) { string str= currentPath + "upgrades/" + upgradeTypes[i].getName(); - upgradeTypes[i].load(str, techTree, this, checksum,techtreeChecksum, - loadedFileList); + + try { + upgradeTypes[i].load(str, techTree, this, checksum, + techtreeChecksum,loadedFileList,validationMode); + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); + } + } SDL_PumpEvents(); } @@ -214,7 +236,18 @@ void FactionType::load(const string &factionName, const TechTree *techTree, Chec const XmlNode *resourceNode= startingResourcesNode->getChild("resource", i); string name= resourceNode->getAttribute("name")->getRestrictedValue(); int amount= resourceNode->getAttribute("amount")->getIntValue(); - startingResources[i].init(techTree->getResourceType(name), amount); + + try { + startingResources[i].init(techTree->getResourceType(name), amount); + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\nFor FactionType: %s for StartResource: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what(),this->name.c_str(),name.c_str()); + } + } SDL_PumpEvents(); } @@ -858,29 +891,32 @@ void FactionType::deletePixels() { bool FactionType::factionUsesResourceType(const ResourceType *rt) const { bool factionUsesResourceType = false; - for(unsigned int j = 0; factionUsesResourceType == false && j < this->getUnitTypeCount(); ++j) { - const UnitType *ut= this->getUnitType(j); - for(int k = 0; factionUsesResourceType == false && k < ut->getCostCount(); ++k) { - const Resource *costResource = ut->getCost(k); - //printf("#1 factionUsesResourceType, unit [%s] resource [%s] cost [%s]\n",ut->getName().c_str(),rt->getName().c_str(),costResource->getType()->getName().c_str()); + if(rt != NULL) { + for(unsigned int j = 0; factionUsesResourceType == false && j < this->getUnitTypeCount(); ++j) { + const UnitType *ut= this->getUnitType(j); + for(int k = 0; factionUsesResourceType == false && k < ut->getCostCount(); ++k) { + const Resource *costResource = ut->getCost(k); + //printf("#1 factionUsesResourceType, unit [%s] resource [%s] cost [%s]\n",ut->getName().c_str(),rt->getName().c_str(),costResource->getType()->getName().c_str()); - if(costResource != NULL && costResource->getType()->getName() == rt->getName()) { - factionUsesResourceType = true; - break; + if(costResource != NULL && costResource->getType() != NULL && + costResource->getType()->getName() == rt->getName()) { + factionUsesResourceType = true; + break; + } } - } - if(factionUsesResourceType == false) { - for(unsigned int k = 0; factionUsesResourceType == false && k < ut->getCommandTypeCount(); ++k) { - const CommandType *commandType = ut->getCommandType(k); - if(commandType != NULL && commandType->getClass() == ccHarvest) { - const HarvestCommandType *hct = dynamic_cast(commandType); - if(hct != NULL && hct->getHarvestedResourceCount() > 0) { - for(unsigned int l = 0; factionUsesResourceType == false && l < hct->getHarvestedResourceCount(); ++l) { - //printf("#2 factionUsesResourceType, unit [%s] resource [%s] harvest [%s]\n",ut->getName().c_str(),rt->getName().c_str(),hct->getHarvestedResource(l)->getName().c_str()); + if(factionUsesResourceType == false) { + for(unsigned int k = 0; factionUsesResourceType == false && k < ut->getCommandTypeCount(); ++k) { + const CommandType *commandType = ut->getCommandType(k); + if(commandType != NULL && commandType->getClass() == ccHarvest) { + const HarvestCommandType *hct = dynamic_cast(commandType); + if(hct != NULL && hct->getHarvestedResourceCount() > 0) { + for(unsigned int l = 0; factionUsesResourceType == false && l < hct->getHarvestedResourceCount(); ++l) { + //printf("#2 factionUsesResourceType, unit [%s] resource [%s] harvest [%s]\n",ut->getName().c_str(),rt->getName().c_str(),hct->getHarvestedResource(l)->getName().c_str()); - if(hct->getHarvestedResource(l)->getName() == rt->getName()) { - factionUsesResourceType = true; - break; + if(hct->getHarvestedResource(l)->getName() == rt->getName()) { + factionUsesResourceType = true; + break; + } } } } @@ -888,7 +924,6 @@ bool FactionType::factionUsesResourceType(const ResourceType *rt) const { } } } - return factionUsesResourceType; } diff --git a/source/glest_game/types/faction_type.h b/source/glest_game/types/faction_type.h index e111cb72..47641598 100644 --- a/source/glest_game/types/faction_type.h +++ b/source/glest_game/types/faction_type.h @@ -100,7 +100,9 @@ public: //init FactionType(); void load(const string &factionName, const TechTree *techTree, Checksum* checksum, - Checksum *techtreeChecksum, std::map > > &loadedFileList); + Checksum *techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode=false); virtual ~FactionType(); const std::vector getAIBehaviorUnits(AIBehaviorUnitCategory category) const; diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index b33071b3..75d57195 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -46,6 +46,7 @@ TechTree::TechTree(const vector pathList) { translatedTechNames.clear(); translatedTechFactionNames.clear(); languageUsedForCache = ""; + isValidationModeEnabled = false; } string TechTree::getNameUntranslated() const { @@ -155,13 +156,17 @@ string TechTree::getTranslatedFactionName(string techName, string factionName) { } Checksum TechTree::loadTech(const string &techName, - set &factions, Checksum* checksum, std::map > > &loadedFileList) { + set &factions, Checksum* checksum, + std::map > > &loadedFileList, + bool validationMode) { name = ""; + isValidationModeEnabled = validationMode; Checksum techtreeChecksum; string path=findPath(techName); if(path!="") { //printf(">>> path=%s\n",path.c_str()); - load(path, factions, checksum, &techtreeChecksum, loadedFileList); + load(path, factions, checksum, &techtreeChecksum, loadedFileList, + validationMode); } else { printf(">>> techtree [%s] path not found.\n",techName.c_str()); @@ -191,7 +196,9 @@ string TechTree::findPath(const string &techName, const vector &pathTech void TechTree::load(const string &dir, set &factions, Checksum* checksum, - Checksum *techtreeChecksum, std::map > > &loadedFileList) { + Checksum *techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); string currentPath = dir; @@ -230,7 +237,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what()); - throw megaglest_runtime_error("Error loading Resource Types in: [" + currentPath + "]\n" + e.what()); + throw megaglest_runtime_error("Error loading Resource Types in: [" + currentPath + "]\n" + e.what(),isValidationModeEnabled); } // give CPU time to update other things to avoid apperance of hanging @@ -302,7 +309,7 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what()); - throw megaglest_runtime_error("Error loading Tech Tree: "+ currentPath + "\n" + e.what()); + throw megaglest_runtime_error("Error loading Tech Tree: "+ currentPath + "\n" + e.what(),isValidationModeEnabled); } // give CPU time to update other things to avoid apperance of hanging @@ -327,7 +334,8 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum logger.setState(szBuf); logger.setProgress((int)((((double)i) / (double)factions.size()) * 100.0)); - factionTypes[i++].load(factionName, this, checksum,&checksumValue,loadedFileList); + factionTypes[i++].load(factionName, this, checksum,&checksumValue, + loadedFileList,validationMode); // give CPU time to update other things to avoid apperance of hanging sleep(0); @@ -336,14 +344,12 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum } } catch(megaglest_runtime_error& ex) { - //printf("1111111b ex.wantStackTrace() = %d\n",ex.wantStackTrace()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); - //printf("222222b\n"); - throw megaglest_runtime_error("Error loading Faction Types: "+ currentPath + "\n" + ex.what(),!ex.wantStackTrace()); + throw megaglest_runtime_error("Error loading Faction Types: "+ currentPath + "\nMessage: " + ex.what(),!ex.wantStackTrace() || isValidationModeEnabled); } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what()); - throw megaglest_runtime_error("Error loading Faction Types: "+ currentPath + "\n" + e.what()); + throw megaglest_runtime_error("Error loading Faction Types: "+ currentPath + "\nMessage: " + e.what(),isValidationModeEnabled); } if(techtreeChecksum != NULL) { @@ -429,7 +435,7 @@ FactionType *TechTree::getTypeByName(const string &name) { } } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - throw megaglest_runtime_error("Faction not found: "+name); + throw megaglest_runtime_error("Faction not found: " + name,isValidationModeEnabled); } const FactionType *TechTree::getType(const string &name) const { @@ -439,7 +445,7 @@ const FactionType *TechTree::getType(const string &name) const { } } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); - throw megaglest_runtime_error("Faction not found: "+name); + throw megaglest_runtime_error("Faction not found: " + name,isValidationModeEnabled); } const ResourceType *TechTree::getTechResourceType(int i) const{ @@ -466,8 +472,7 @@ const ResourceType *TechTree::getFirstTechResourceType() const{ char szBuf[8096]=""; snprintf(szBuf,8096,"The referenced tech tree [%s] is either missing or has no resources defined but at least one resource is required.",this->name.c_str()); - //throw megaglest_runtime_error("This tech tree has no resources defined, at least one is required"); - throw megaglest_runtime_error(szBuf); + throw megaglest_runtime_error(szBuf,isValidationModeEnabled); } const ResourceType *TechTree::getResourceType(const string &name) const{ @@ -478,7 +483,7 @@ const ResourceType *TechTree::getResourceType(const string &name) const{ } } - throw megaglest_runtime_error("Resource Type not found: "+name); + throw megaglest_runtime_error("Resource Type not found: " + name,isValidationModeEnabled); } const ArmorType *TechTree::getArmorType(const string &name) const{ @@ -488,7 +493,7 @@ const ArmorType *TechTree::getArmorType(const string &name) const{ } } - throw megaglest_runtime_error("Armor Type not found: "+name); + throw megaglest_runtime_error("Armor Type not found: " + name,isValidationModeEnabled); } const AttackType *TechTree::getAttackType(const string &name) const{ @@ -498,7 +503,7 @@ const AttackType *TechTree::getAttackType(const string &name) const{ } } - throw megaglest_runtime_error("Attack Type not found: "+name); + throw megaglest_runtime_error("Attack Type not found: " + name,isValidationModeEnabled); } double TechTree::getDamageMultiplier(const AttackType *att, const ArmorType *art) const { diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index 586e0e27..5e8bcacf 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -56,12 +56,17 @@ private: string languageUsedForCache; std::map translatedTechNames; std::map > translatedTechFactionNames; + bool isValidationModeEnabled; public: Checksum loadTech(const string &techName, - set &factions, Checksum* checksum, std::map > > &loadedFileList); + set &factions, Checksum* checksum, + std::map > > &loadedFileList, + bool validationMode=false); void load(const string &dir, set &factions, Checksum* checksum, - Checksum *techtreeChecksum, std::map > > &loadedFileList); + Checksum *techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode=false); string findPath(const string &techName) const; static string findPath(const string &techName, const vector &pathTechList); diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 629656f4..a3c7ee9c 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -164,9 +164,11 @@ void UnitType::preLoad(const string &dir) { name= lastDir(dir); } -void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const string &techTreePath, - const FactionType *factionType, Checksum* checksum, - Checksum* techtreeChecksum, std::map > > &loadedFileList) { +void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, + const string &techTreePath, const FactionType *factionType, + Checksum* checksum, Checksum* techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -281,7 +283,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const const XmlNode *rowNode= cellMapNode->getChild("row", i); string row= rowNode->getAttribute("value")->getRestrictedValue(); if(row.size()!=size){ - throw megaglest_runtime_error("Cellmap row has not the same length as unit size"); + throw megaglest_runtime_error("Cellmap row has not the same length as unit size",validationMode); } for(int j=0; jgetChildCount()); for(int i=0; igetChild("level", i); + levels[i].init( levelNode->getAttribute("name")->getRestrictedValue(), levelNode->getAttribute("kills")->getIntValue()); @@ -311,7 +314,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const fields[fAir]= true; } else{ - throw megaglest_runtime_error("Not a valid field: "+fieldName+": "+ path); + throw megaglest_runtime_error("Not a valid field: "+fieldName+": "+ path, validationMode); } } @@ -322,7 +325,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const field = fAir; } else { - throw megaglest_runtime_error("Unit has no field: " + path); + throw megaglest_runtime_error("Unit has no field: " + path, validationMode); } //properties @@ -339,7 +342,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const } } if(!found) { - throw megaglest_runtime_error("Unknown property: " + propertyName); + throw megaglest_runtime_error("Unknown property: " + propertyName, validationMode); } } //damage-particles @@ -353,18 +356,11 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const string path= particleFileNode->getAttribute("path")->getRestrictedValue(); UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); - //Texture2D *newTexture = Renderer::getInstance().newTexture2D(rsGame); - //Texture2D *newTexture = NULL; - unitParticleSystemType->load(particleFileNode, dir, currentPath + path, &Renderer::getInstance(),loadedFileList, sourceXMLFile, techTree->getPath()); loadedFileList[currentPath + path].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue())); - //if(unitParticleSystemType->hasTexture() == false) { - //Renderer::getInstance().endLastTexture(rsGame,true); - //} - if(particleFileNode->getAttribute("minHp",false) != NULL && particleFileNode->getAttribute("maxHp",false) != NULL) { unitParticleSystemType->setMinmaxEnabled(true); unitParticleSystemType->setMinHp(particleFileNode->getAttribute("minHp")->getIntValue()); @@ -374,7 +370,6 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const unitParticleSystemType->setMinmaxIsPercent(particleFileNode->getAttribute("ispercentbased")->getBoolValue()); } - //printf("Found customized particle trigger by HP [%d to %d]\n",unitParticleSystemType->getMinHp(),unitParticleSystemType->getMaxHp()); } damageParticleSystemTypes.push_back(unitParticleSystemType); @@ -476,8 +471,18 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const int index = 0; for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { - costs[index].init(techTree->getResourceType(iterMap->first), iterMap->second); - index++; + try { + costs[index].init(techTree->getResourceType(iterMap->first), iterMap->second); + index++; + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\nFor UnitType: %s Cost: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what(),name.c_str(),iterMap->second); + } + } } sortedItems.clear(); hasDup = false; @@ -508,8 +513,18 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const index = 0; for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { - storedResources[index].init(techTree->getResourceType(iterMap->first), iterMap->second); - index++; + try { + storedResources[index].init(techTree->getResourceType(iterMap->first), iterMap->second); + index++; + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\nFor UnitType: %s Store: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what(),name.c_str(),iterMap->second); + } + } } sortedItems.clear(); @@ -544,21 +559,24 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const if(parametersNode->hasChild("count-unit-death-in-stats")){ const XmlNode *countUnitDeathInStatsNode= parametersNode->getChild("count-unit-death-in-stats"); countUnitDeathInStats= countUnitDeathInStatsNode->getAttribute("value")->getBoolValue(); - } else { + } + else { countUnitDeathInStats=true; } //countUnitProductionInStats if(parametersNode->hasChild("count-unit-production-in-stats")){ const XmlNode *countUnitProductionInStatsNode= parametersNode->getChild("count-unit-production-in-stats"); countUnitProductionInStats= countUnitProductionInStatsNode->getAttribute("value")->getBoolValue(); - } else { + } + else { countUnitProductionInStats=true; } //countUnitKillInStats if(parametersNode->hasChild("count-unit-kill-in-stats")){ const XmlNode *countUnitKillInStatsNode= parametersNode->getChild("count-unit-kill-in-stats"); countUnitKillInStats= countUnitKillInStatsNode->getAttribute("value")->getBoolValue(); - } else { + } + else { countUnitKillInStats=true; } @@ -622,9 +640,19 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const string classId= typeNode->getAttribute("value")->getRestrictedValue(); SkillType *skillType= SkillTypeFactory::getInstance().newInstance(classId); - skillType->load(sn, attackBoostsNode, dir, techTree, factionType, loadedFileList,sourceXMLFile); - skillTypes[i]= skillType; - + skillTypes[i]=NULL; + try { + skillType->load(sn, attackBoostsNode, dir, techTree, factionType, loadedFileList,sourceXMLFile); + skillTypes[i]= skillType; + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\nFor UnitType: %s SkillType: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what(),name.c_str(),classId.c_str()); + } + } } //commands @@ -635,32 +663,42 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const const XmlNode *typeNode= commandNode->getChild("type"); string classId= typeNode->getAttribute("value")->getRestrictedValue(); CommandType *commandType= CommandTypeFactory::getInstance().newInstance(classId); - commandType->load(i, commandNode, dir, techTree, factionType, *this, - loadedFileList,sourceXMLFile); - commandTypes[i]= commandType; + + commandTypes[i]=NULL; + try { + commandType->load(i, commandNode, dir, techTree, factionType, *this, + loadedFileList,sourceXMLFile); + commandTypes[i]= commandType; + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\nFor UnitType: %s CommandType:%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what(),name.c_str(),classId.c_str()); + } + } } computeFirstStOfClass(); computeFirstCtOfClass(); if(getFirstStOfClass(scStop)==NULL){ - throw megaglest_runtime_error("Every unit must have at least one stop skill: "+ path); + throw megaglest_runtime_error("Every unit must have at least one stop skill: "+ path,validationMode); } if(getFirstStOfClass(scDie)==NULL){ - throw megaglest_runtime_error("Every unit must have at least one die skill: "+ path); + throw megaglest_runtime_error("Every unit must have at least one die skill: "+ path,validationMode); } } //Exception handling (conversions and so on); catch(megaglest_runtime_error& ex) { - //printf("1111111a ex.wantStackTrace() = %d\n",ex.wantStackTrace()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what()); - //printf("222222a\n"); - throw megaglest_runtime_error("Error loading UnitType: " + path + "\n" + ex.what(),!ex.wantStackTrace()); + throw megaglest_runtime_error("Error loading UnitType: " + path + "\nMessage: " + ex.what(),!ex.wantStackTrace()); } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,e.what()); - throw megaglest_runtime_error("Error loading UnitType: " + path + "\n" + e.what()); + throw megaglest_runtime_error("Error loading UnitType: " + path + "\nMessage: " + e.what()); } if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -976,7 +1014,7 @@ void UnitType::computeFirstStOfClass() { for(int j= 0; j < scCount; ++j) { firstSkillTypeOfClass[j]= NULL; for(int i= 0; i < skillTypes.size(); ++i) { - if(skillTypes[i]->getClass()== SkillClass(j)) { + if(skillTypes[i] != NULL && skillTypes[i]->getClass()== SkillClass(j)) { firstSkillTypeOfClass[j]= skillTypes[i]; break; } @@ -988,7 +1026,7 @@ void UnitType::computeFirstCtOfClass() { for(int j = 0; j < ccCount; ++j) { firstCommandTypeOfClass[j]= NULL; for(int i = 0; i < commandTypes.size(); ++i) { - if(commandTypes[i]->getClass() == CommandClass(j)) { + if(commandTypes[i] != NULL && commandTypes[i]->getClass() == CommandClass(j)) { firstCommandTypeOfClass[j] = commandTypes[i]; break; } diff --git a/source/glest_game/types/unit_type.h b/source/glest_game/types/unit_type.h index 93b2d802..7d3b8035 100644 --- a/source/glest_game/types/unit_type.h +++ b/source/glest_game/types/unit_type.h @@ -163,9 +163,12 @@ public: UnitType(); virtual ~UnitType(); void preLoad(const string &dir); - void loaddd(int id, const string &dir, const TechTree *techTree,const string &techTreePath, + void loaddd(int id, const string &dir, const TechTree *techTree, + const string &techTreePath, const FactionType *factionType, Checksum* checksum, - Checksum* techtreeChecksum, std::map > > &loadedFileList); + Checksum* techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode=false); virtual string getName(bool translatedValue=false) const; diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 816d5b2b..b0ed3292 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -585,7 +585,9 @@ void UpgradeType::preLoad(const string &dir){ void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, - Checksum* techtreeChecksum, std::map > > &loadedFileList) { + Checksum* techtreeChecksum, std::map > > &loadedFileList, + bool validationMode) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); char szBuf[8096]=""; @@ -610,29 +612,9 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, //image image = NULL; // Not used for upgrade types -// const XmlNode *imageNode= upgradeNode->getChild("image"); -// image= Renderer::getInstance().newTexture2D(rsGame); -// if(image) { -// image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath,true)); -// } -// loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath,true)].push_back(make_pair(sourceXMLFile,imageNode->getAttribute("path")->getRestrictedValue())); - - //if(fileExists(imageNode->getAttribute("path")->getRestrictedValue(currentPath,true)) == false) { - // printf("\n***ERROR MISSING FILE [%s]\n",imageNode->getAttribute("path")->getRestrictedValue(currentPath,true).c_str()); - //} //image cancel cancelImage = NULL; // Not used for upgrade types -// const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel"); -// cancelImage= Renderer::getInstance().newTexture2D(rsGame); -// if(cancelImage) { -// cancelImage->load(imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath,true)); -// } -// loadedFileList[imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath,true)].push_back(make_pair(sourceXMLFile,imageCancelNode->getAttribute("path")->getRestrictedValue())); - - //if(fileExists(imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath,true)) == false) { - // printf("\n***ERROR MISSING FILE [%s]\n",imageCancelNode->getAttribute("path")->getRestrictedValue(currentPath,true).c_str()); - //} //upgrade time const XmlNode *upgradeTimeNode= upgradeNode->getChild("time"); @@ -719,8 +701,19 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, index = 0; for(std::map::iterator iterMap = sortedItems.begin(); iterMap != sortedItems.end(); ++iterMap) { - costs[index].init(techTree->getResourceType(iterMap->first), iterMap->second); - index++; + try { + costs[index].init(techTree->getResourceType(iterMap->first), iterMap->second); + index++; + } + catch(megaglest_runtime_error& ex) { + if(validationMode == false) { + throw ex; + } + else { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\nFor UpgradeType: %s Cost: %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what(),name.c_str(),iterMap->second); + } + } + } sortedItems.clear(); hasDup = false; diff --git a/source/glest_game/types/upgrade_type.h b/source/glest_game/types/upgrade_type.h index f75f304f..4a9937d8 100644 --- a/source/glest_game/types/upgrade_type.h +++ b/source/glest_game/types/upgrade_type.h @@ -204,7 +204,9 @@ public: void preLoad(const string &dir); void load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum, - Checksum* techtreeChecksum, std::map > > &loadedFileList); + Checksum* techtreeChecksum, + std::map > > &loadedFileList, + bool validationMode=false); virtual string getName(bool translatedValue=false) const; diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index e29bfac2..66c2b8d4 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -454,14 +454,16 @@ Checksum World::loadTileset(const string &dir, Checksum *checksum, std::map pathList, const string &techName, - set &factions, Checksum *checksum, std::map > > &loadedFileList) { + set &factions, Checksum *checksum, + std::map > > &loadedFileList, + bool validationMode) { Checksum techtreeChecksum; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); techTree = new TechTree(pathList); techtreeChecksum = techTree->loadTech( techName, factions, - checksum,loadedFileList); + checksum,loadedFileList,validationMode); return techtreeChecksum; } diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index 4771ec6f..b81b73ab 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -205,7 +205,9 @@ public: std::map > > &loadedFileList); void clearTileset(); Checksum loadTech(const vector pathList, const string &techName, - set &factions, Checksum* checksum,std::map > > &loadedFileList); + set &factions, Checksum* checksum, + std::map > > &loadedFileList, + bool validationMode=false); Checksum loadMap(const string &path, Checksum* checksum); Checksum loadScenario(const string &path, Checksum* checksum,bool resetCurrentScenario=false,const XmlNode *rootNode=NULL); void setQueuedScenario(string scenarioName,bool keepFactions); diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index 7d5535a7..a46454d7 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -70,6 +70,7 @@ inline T truncateDecimal(const T &value, int precision=6) { if((T)value * (T)precNum <= MAX_INT_VALUE) { int resultInt = (T)value * (T)precNum; T result = (T)resultInt / precNum; + //printf("=======================\nvalue = %.10f\nresultInt: %d\nprecision: %d\nbecame: %.10f\n----------\n",value,resultInt,precision,result); return result; } diff --git a/source/shared_lib/sources/platform/sdl/platform_util.cpp b/source/shared_lib/sources/platform/sdl/platform_util.cpp index 742c0fd6..bef0dcfe 100644 --- a/source/shared_lib/sources/platform/sdl/platform_util.cpp +++ b/source/shared_lib/sources/platform/sdl/platform_util.cpp @@ -60,12 +60,12 @@ const char * getDialogCommand() { return NULL; } -bool showMessage(const std::string & warning) { +bool showMessage(std::string warning) { bool guiMessage = false; const char * dialogCommand = getDialogCommand(); if (dialogCommand) { std::string command = dialogCommand; - command += " --title \"Error\" --msgbox \"`printf \"" + warning + "\"`\""; + command += " --title \"Error\" --msgbox \"`printf \"" + warning.erase(4096,std::string::npos) + "\"`\""; //printf("\n\n\nzenity command [%s]\n\n\n",command.c_str()); @@ -79,9 +79,11 @@ bool showMessage(const std::string & warning) { } void message(string message, bool isNonGraphicalModeEnabled) { + std::cerr << "\n\n\n"; std::cerr << "******************************************************\n"; std::cerr << " " << message << "\n"; std::cerr << "******************************************************\n"; + std::cerr << "\n\n\n"; if(isNonGraphicalModeEnabled == false) { showMessage(message);