From 449e3f25c8dbd2f62ee7074d9e01734652f91b1a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 6 May 2011 22:12:16 +0000 Subject: [PATCH] - updates to commondata handling. From now on commondata tag specified the commondata folder under a techtree making it easier to share data and portable since you just need to copy the techtree and its contents, this means no sharing data between techtrees (which is good since we don't want such dependencies) --- mk/linux/makedata.sh | 1 - mk/windoze/Installer/MegaGlestInstaller.nsi | 3 - source/configurator/configuration.cpp | 2 +- source/g3d_viewer/main.cpp | 18 ++-- source/glest_game/graphics/particle_type.cpp | 20 ++-- source/glest_game/graphics/particle_type.h | 6 +- .../graphics/unit_particle_type.cpp | 14 ++- .../glest_game/graphics/unit_particle_type.h | 5 +- source/glest_game/main/main.cpp | 99 +++++++++++++++---- source/glest_game/menu/main_menu.cpp | 2 +- source/glest_game/menu/menu_background.cpp | 4 +- .../glest_game/menu/menu_state_scenario.cpp | 2 +- source/glest_game/types/faction_type.cpp | 4 +- source/glest_game/types/resource_type.cpp | 9 +- source/glest_game/types/resource_type.h | 3 +- source/glest_game/types/skill_type.cpp | 8 +- source/glest_game/types/tech_tree.cpp | 12 ++- source/glest_game/types/tech_tree.h | 12 ++- source/glest_game/types/unit_type.cpp | 10 +- source/glest_game/types/upgrade_type.cpp | 6 +- source/glest_game/world/scenario.cpp | 3 +- source/glest_game/world/tileset.cpp | 5 +- .../include/platform/common/platform_common.h | 1 + source/shared_lib/include/util/properties.h | 3 +- source/shared_lib/include/xml/xml_parser.h | 21 ++-- .../platform/common/platform_common.cpp | 36 +++++-- source/shared_lib/sources/util/properties.cpp | 91 ++++++++++++++++- source/shared_lib/sources/xml/xml_parser.cpp | 43 ++++---- 28 files changed, 324 insertions(+), 119 deletions(-) diff --git a/mk/linux/makedata.sh b/mk/linux/makedata.sh index 4bdcf194..6deaa156 100755 --- a/mk/linux/makedata.sh +++ b/mk/linux/makedata.sh @@ -32,7 +32,6 @@ find glest.ini \( -name "*" \) -exec cp -p "{}" $RELEASEDIR/glest_linux.ini ';' find glestkeys.ini \( -name "*" \) -exec cp -p --parents "{}" $RELEASEDIR ';' find configuration.xml \( -name "*" \) -exec cp -p --parents "{}" $RELEASEDIR ';' -find commondata/ \( -name "*" \) -not \( -name .svn -prune \) -not \( -name "*~" -prune \) -not \( -name "*.bak" -prune \) -exec cp -p --parents "{}" $RELEASEDIR ';' find data/ \( -name "*" \) -not \( -name .svn -prune \) -not \( -name "*~" -prune \) -not \( -name "*.bak" -prune \) -exec cp -p --parents "{}" $RELEASEDIR ';' find docs/ \( -name "*" \) -not \( -name .svn -prune \) -not \( -name "*~" -prune \) -not \( -name "*.bak" -prune \) -exec cp -p --parents "{}" $RELEASEDIR ';' find maps/ \( -name "*" \) -not \( -name .svn -prune \) -not \( -name "*~" -prune \) -not \( -name "*.bak" -prune \) -exec cp -p --parents "{}" $RELEASEDIR ';' diff --git a/mk/windoze/Installer/MegaGlestInstaller.nsi b/mk/windoze/Installer/MegaGlestInstaller.nsi index 288905bd..c14213ff 100644 --- a/mk/windoze/Installer/MegaGlestInstaller.nsi +++ b/mk/windoze/Installer/MegaGlestInstaller.nsi @@ -201,7 +201,6 @@ Section "${APNAME} (required)" File "..\..\..\source\tools\glexemel\g3d_logo.png" SetOutPath $INSTDIR - File /r /x .svn /x mydata "..\..\..\data\glest_game\commondata" File /r /x .svn /x mydata "..\..\..\data\glest_game\data" File /r /x .svn /x mydata "..\..\..\data\glest_game\docs" File /r /x .svn /x mydata "..\..\..\data\glest_game\maps" @@ -279,7 +278,6 @@ Section "Uninstall" Delete $INSTDIR\xerces-c_3_0.dll Delete $INSTDIR\*.log - Delete $INSTDIR\commondata\*.* Delete $INSTDIR\data\*.* Delete $INSTDIR\docs\*.* Delete $INSTDIR\maps\*.* @@ -289,7 +287,6 @@ Section "Uninstall" Delete $INSTDIR\tilesets\*.* Delete $INSTDIR\tutorials\*.* - RMDir /r $INSTDIR\commondata RMDir /r $INSTDIR\data RMDir /r $INSTDIR\docs RMDir /r $INSTDIR\maps diff --git a/source/configurator/configuration.cpp b/source/configurator/configuration.cpp index 4ffe9f37..3559b751 100644 --- a/source/configurator/configuration.cpp +++ b/source/configurator/configuration.cpp @@ -43,7 +43,7 @@ void Configuration::load(const string &path){ void Configuration::loadStructure(const string &path){ XmlTree xmlTree; - xmlTree.load(path); + xmlTree.load(path,Properties::getTagReplacementValues()); const XmlNode *configurationNode= xmlTree.getRootNode(); diff --git a/source/g3d_viewer/main.cpp b/source/g3d_viewer/main.cpp index 0fddaddf..0eb7d4a8 100644 --- a/source/g3d_viewer/main.cpp +++ b/source/g3d_viewer/main.cpp @@ -931,7 +931,7 @@ void MainWindow::loadUnit(string path, string skillName) { if(fileExists(unitXML) == true) { XmlTree xmlTree; - xmlTree.load(unitXML); + xmlTree.load(unitXML,Properties::getTagReplacementValues()); const XmlNode *unitNode= xmlTree.getRootNode(); bool foundSkillName = false; @@ -1102,7 +1102,7 @@ void MainWindow::loadParticle(string path) { if(fileExists(unitXML) == true) { XmlTree xmlTree; - xmlTree.load(unitXML); + xmlTree.load(unitXML,Properties::getTagReplacementValues()); const XmlNode *unitNode= xmlTree.getRootNode(); const XmlNode *parametersNode= unitNode->getChild("parameters"); //size @@ -1116,7 +1116,7 @@ void MainWindow::loadParticle(string path) { std::map > > loadedFileList; UnitParticleSystemType *unitParticleSystemType = new UnitParticleSystemType(); unitParticleSystemType->load(dir, dir + folderDelimiter + particlePath, - renderer,loadedFileList,"g3dviewer"); + renderer,loadedFileList,"g3dviewer",""); unitParticleSystemTypes.push_back(unitParticleSystemType); for(std::vector::const_iterator it= unitParticleSystemTypes.begin(); it != unitParticleSystemTypes.end(); ++it) { @@ -1193,7 +1193,7 @@ void MainWindow::loadProjectileParticle(string path) { if(fileExists(unitXML) == true) { XmlTree xmlTree; - xmlTree.load(unitXML); + xmlTree.load(unitXML,Properties::getTagReplacementValues()); const XmlNode *unitNode= xmlTree.getRootNode(); const XmlNode *parametersNode= unitNode->getChild("parameters"); //size @@ -1205,7 +1205,7 @@ void MainWindow::loadProjectileParticle(string path) { // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; XmlTree xmlTree; - xmlTree.load(dir + folderDelimiter + particlePath); + xmlTree.load(dir + folderDelimiter + particlePath,Properties::getTagReplacementValues()); const XmlNode *particleSystemNode= xmlTree.getRootNode(); // std::cout << "Loaded successfully, loading values..." << std::endl; @@ -1214,7 +1214,7 @@ void MainWindow::loadProjectileParticle(string path) { ParticleSystemTypeProjectile *projectileParticleSystemType= new ParticleSystemTypeProjectile(); projectileParticleSystemType->load(dir, dir + folderDelimiter + particlePath,renderer, loadedFileList, - "g3dviewer"); + "g3dviewer",""); // std::cout << "Values loaded, about to read..." << std::endl; @@ -1296,7 +1296,7 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp if(fileExists(unitXML) == true) { XmlTree xmlTree; - xmlTree.load(unitXML); + xmlTree.load(unitXML,Properties::getTagReplacementValues()); const XmlNode *unitNode= xmlTree.getRootNode(); const XmlNode *parametersNode= unitNode->getChild("parameters"); //size @@ -1308,7 +1308,7 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp // std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl; XmlTree xmlTree; - xmlTree.load(dir + folderDelimiter + particlePath); + xmlTree.load(dir + folderDelimiter + particlePath,Properties::getTagReplacementValues()); const XmlNode *particleSystemNode= xmlTree.getRootNode(); // std::cout << "Loaded successfully, loading values..." << std::endl; @@ -1316,7 +1316,7 @@ void MainWindow::loadSplashParticle(string path) { // uses ParticleSystemTypeSp std::map > > loadedFileList; ParticleSystemTypeSplash *splashParticleSystemType= new ParticleSystemTypeSplash(); splashParticleSystemType->load(dir, dir + folderDelimiter + particlePath,renderer, - loadedFileList,"g3dviewer"); // <---- only that must be splash... + loadedFileList,"g3dviewer",""); // <---- only that must be splash... // std::cout << "Values loaded, about to read..." << std::endl; diff --git a/source/glest_game/graphics/particle_type.cpp b/source/glest_game/graphics/particle_type.cpp index 29e40dcf..14dac232 100644 --- a/source/glest_game/graphics/particle_type.cpp +++ b/source/glest_game/graphics/particle_type.cpp @@ -42,7 +42,7 @@ ParticleSystemType::ParticleSystemType() { void ParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader) { + string parentLoader, string techtreePath) { //texture const XmlNode *textureNode= particleSystemNode->getChild("texture"); bool textureEnabled= textureNode->getAttribute("value")->getBoolValue(); @@ -188,16 +188,19 @@ void ParticleSystemType::setValues(AttackParticleSystem *ats){ void ParticleSystemTypeProjectile::load(const string &dir, const string &path, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader) { + string parentLoader, string techtreePath) { try{ XmlTree xmlTree; - xmlTree.load(path); + + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techtreePath + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(parentLoader,parentLoader)); const XmlNode *particleSystemNode= xmlTree.getRootNode(); - ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList,parentLoader); + ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList,parentLoader, techtreePath); //trajectory values const XmlNode *tajectoryNode= particleSystemNode->getChild("trajectory"); @@ -250,16 +253,19 @@ ProjectileParticleSystem *ParticleSystemTypeProjectile::create() { void ParticleSystemTypeSplash::load(const string &dir, const string &path, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader) { + string parentLoader, string techtreePath) { try{ XmlTree xmlTree; - xmlTree.load(path); + + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techtreePath + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(parentLoader,parentLoader)); const XmlNode *particleSystemNode= xmlTree.getRootNode(); - ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList, parentLoader); + ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList, parentLoader, techtreePath); //emission rate fade const XmlNode *emissionRateFadeNode= particleSystemNode->getChild("emission-rate-fade"); diff --git a/source/glest_game/graphics/particle_type.h b/source/glest_game/graphics/particle_type.h index e3d6d116..a67b9e8f 100644 --- a/source/glest_game/graphics/particle_type.h +++ b/source/glest_game/graphics/particle_type.h @@ -69,7 +69,7 @@ public: ParticleSystemType(); void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader); + string parentLoader, string techtreePath); void setValues(AttackParticleSystem *ats); bool hasTexture() const { return(texture != NULL); } bool hasModel() const { return(model != NULL); } @@ -92,7 +92,7 @@ private: public: void load(const string &dir, const string &path, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader); + string parentLoader, string techtreePath); ProjectileParticleSystem *create(); }; @@ -105,7 +105,7 @@ class ParticleSystemTypeSplash: public ParticleSystemType { public: void load(const string &dir, const string &path, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader); + string parentLoader, string techtreePath); SplashParticleSystem *create(); private: diff --git a/source/glest_game/graphics/unit_particle_type.cpp b/source/glest_game/graphics/unit_particle_type.cpp index 69e8371e..77bfa3d5 100644 --- a/source/glest_game/graphics/unit_particle_type.cpp +++ b/source/glest_game/graphics/unit_particle_type.cpp @@ -31,8 +31,9 @@ namespace Glest{ namespace Game{ void UnitParticleSystemType::load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader) { - ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList, parentLoader); + string parentLoader, string techtreePath) { + ParticleSystemType::load(particleSystemNode, dir, renderer, loadedFileList, + parentLoader,techtreePath); //radius const XmlNode *radiusNode= particleSystemNode->getChild("radius"); radius= radiusNode->getAttribute("value")->getFloatValue(); @@ -138,16 +139,19 @@ const void UnitParticleSystemType::setValues(UnitParticleSystem *ups){ void UnitParticleSystemType::load(const string &dir, const string &path, RendererInterface *renderer, std::map > > &loadedFileList, - string parentLoader) { + string parentLoader, string techtreePath) { try{ XmlTree xmlTree; - xmlTree.load(path); + + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techtreePath + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(parentLoader,parentLoader)); const XmlNode *particleSystemNode= xmlTree.getRootNode(); UnitParticleSystemType::load(particleSystemNode, dir, renderer, - loadedFileList, parentLoader); + loadedFileList, parentLoader, techtreePath); } catch(const exception &e){ SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); diff --git a/source/glest_game/graphics/unit_particle_type.h b/source/glest_game/graphics/unit_particle_type.h index 5a74dce5..22f03602 100644 --- a/source/glest_game/graphics/unit_particle_type.h +++ b/source/glest_game/graphics/unit_particle_type.h @@ -58,9 +58,10 @@ protected: public: void load(const XmlNode *particleSystemNode, const string &dir, RendererInterface *newTexture, std::map > > &loadedFileList, - string parentLoader); + string parentLoader, string techtreePath); void load(const string &dir, const string &path, RendererInterface *newTexture, - std::map > > &loadedFileList,string parentLoader); + std::map > > &loadedFileList,string parentLoader, + string techtreePath); const void setValues (UnitParticleSystem *uts); bool hasTexture() const { return(texture != NULL); } }; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 7d28504e..0a3778e1 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -969,11 +969,13 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n%s\t\t\tdisplays your SDL version information.",GAME_ARGS[GAME_ARG_SDL_INFO]); printf("\n%s\t\t\tdisplays your LUA version information.",GAME_ARGS[GAME_ARG_LUA_INFO]); printf("\n%s\t\t\tdisplays your CURL version information.",GAME_ARGS[GAME_ARG_CURL_INFO]); - printf("\n%s=x=purgeunused=purgeduplicates\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); + printf("\n%s=x=purgeunused=purgeduplicates=svndelete\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); printf("\n \t\tto your selected techtrees game data."); printf("\n \t\tWhere x is a comma-delimited list of techtrees to validate."); printf("\n \t\tWhere purgeunused is an optional parameter telling the validation to delete extra files in the techtree that are not used."); printf("\n \t\tWhere purgeduplicates is an optional parameter telling the validation to merge duplicate files in the techtree."); + printf("\n \t\tWhere svndelete is an optional parameter telling the validation to call svn delete on duplicate / unused files in the techtree."); + printf("\n \t\t*NOTE: This only applies when files are purged due to the above flags being set."); printf("\n \t\texample: %s %s=megapack,vbros_pack_5",argv0,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); printf("\n%s=x=purgeunused=purgeduplicates\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]); printf("\n \t\tto your selected factions game data."); @@ -984,7 +986,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n \t\t%s",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]); printf("\n \t\texample: %s %s=tech,egypt",argv0,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]); - printf("\n%s=x=purgeunused\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]); + printf("\n%s=x=purgeunused=svndelete\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]); printf("\n \t\tto your selected scenario game data."); printf("\n \t\tWhere x is a single scenario to validate."); printf("\n \t\tWhere purgeunused is an optional parameter telling the validation to delete extra files in the scenario that are not used."); @@ -1271,7 +1273,8 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) { void runTechValidationForPath(string techPath, string techName, const std::vector filteredFactionList, World &world, - bool purgeUnusedFiles,bool purgeDuplicateFiles, double &purgedMegaBytes) { + bool purgeUnusedFiles,bool purgeDuplicateFiles, bool svnPurgeFiles, + double &purgedMegaBytes) { Config &config = Config::getInstance(); vector factionsList; findDirs(techPath + techName + "/factions/", factionsList, false, false); @@ -1437,7 +1440,17 @@ void runTechValidationForPath(string techPath, string techName, purgedMegaBytes += ((double)fileSize / 1048576.0); purgeCount++; - removeFile(foundFile); + if(svnPurgeFiles == true) { + char szBuf[4096]=""; + sprintf(szBuf,"svn delete \"%s\"",foundFile.c_str()); + bool svnOk = executeShellCommand(szBuf,0); + if(svnOk == false) { + throw runtime_error("Call to command failed [" + string(szBuf) + "]"); + } + } + else { + removeFile(foundFile); + } } } } @@ -1525,22 +1538,51 @@ void runTechValidationForPath(string techPath, string techName, newCommonFileName = "$COMMONDATAPATH/sounds/" + extractFileFromDirectoryPath(duplicateFile); string expandedNewCommonFileName = newCommonFileName; - Properties::applyTagsToValue(expandedNewCommonFileName); - //int result = 0; - int result = rename(duplicateFile.c_str(),expandedNewCommonFileName.c_str()); - if(result != 0) { + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techPath + techName + "/commondata/"; + mapExtraTagReplacementValues = Properties::getTagReplacementValues(&mapExtraTagReplacementValues); + Properties::applyTagsToValue(expandedNewCommonFileName,&mapExtraTagReplacementValues); + createDirectoryPaths(extractDirectoryPathFromFile(expandedNewCommonFileName)); + + if(svnPurgeFiles == true) { + copyFileTo(duplicateFile, expandedNewCommonFileName); + char szBuf[4096]=""; - char *errmsg = strerror(errno); - sprintf(szBuf,"!!! Error [%s] Could not rename [%s] to [%s]!",errmsg,duplicateFile.c_str(),expandedNewCommonFileName.c_str()); - throw runtime_error(szBuf); + sprintf(szBuf,"svn delete \"%s\"",duplicateFile.c_str()); + bool svnOk = executeShellCommand(szBuf,0); + if(svnOk == false) { + throw 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; + int result = rename(duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + if(result != 0) { + char szBuf[4096]=""; + char *errmsg = strerror(errno); + sprintf(szBuf,"!!! Error [%s] Could not rename [%s] to [%s]!",errmsg,duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + throw runtime_error(szBuf); + } + else { + printf("*** Duplicate file:\n[%s]\nwas renamed to:\n[%s]\n",duplicateFile.c_str(),expandedNewCommonFileName.c_str()); + } } } else { - removeFile(duplicateFile); + if(svnPurgeFiles == true) { + char szBuf[4096]=""; + sprintf(szBuf,"svn delete \"%s\"",duplicateFile.c_str()); + bool svnOk = executeShellCommand(szBuf,0); + if(svnOk == false) { + throw runtime_error("Call to command failed [" + string(szBuf) + "]"); + } + printf("*** Duplicate file:\n[%s]\nwas svn deleted\n",duplicateFile.c_str()); + } + else { + removeFile(duplicateFile); + } printf("*** Duplicate file:\n[%s]\nwas removed\n",duplicateFile.c_str()); // convert to MB @@ -1640,6 +1682,8 @@ void runTechValidationReport(int argc, char** argv) { bool purgeDuplicateFiles = false; bool purgeUnusedFiles = false; + bool svnPurgeFiles = false; + double purgedMegaBytes=0; Config &config = Config::getInstance(); @@ -1691,7 +1735,7 @@ void runTechValidationReport(int argc, char** argv) { string file = scenarioPath + scenarioName + "/" + scenarioName + ".xml"; XmlTree xmlTree; - xmlTree.load(file); + xmlTree.load(file,Properties::getTagReplacementValues()); const XmlNode *scenarioNode= xmlTree.getRootNode(); string techName = scenarioNode->getChild("tech-tree")->getAttribute("value")->getValue(); @@ -1702,7 +1746,7 @@ void runTechValidationReport(int argc, char** argv) { printf("Found Scenario [%s] with custom techtree [%s] validating...\n",scenarioName.c_str(),techName.c_str()); runTechValidationForPath(techPath, techName, filteredFactionList, - world, purgeUnusedFiles, false, purgedMegaBytes); + world, purgeUnusedFiles, false, false, purgedMegaBytes); } // // @@ -1785,6 +1829,10 @@ void runTechValidationReport(int argc, char** argv) { purgeDuplicateFiles = true; printf("*NOTE All duplicate techtree files will be merged!\n"); } + else if(paramPartTokens[2] == "svndelete") { + svnPurgeFiles = true; + printf("*NOTE All unused / duplicate techtree files will be removed from svn!\n"); + } } if(paramPartTokens.size() >= 4) { if(paramPartTokens[3] == "purgeunused") { @@ -1795,12 +1843,29 @@ void runTechValidationReport(int argc, char** argv) { purgeDuplicateFiles = true; printf("*NOTE All duplicate techtree files will be merged!\n"); } + else if(paramPartTokens[3] == "svndelete") { + svnPurgeFiles = true; + printf("*NOTE All unused / duplicate techtree files will be removed from svn!\n"); + } + } + if(paramPartTokens.size() >= 5) { + if(paramPartTokens[4] == "purgeunused") { + purgeUnusedFiles = true; + printf("*NOTE All unused techtree files will be deleted!\n"); + } + else if(paramPartTokens[4] == "purgeduplicates") { + purgeDuplicateFiles = true; + printf("*NOTE All duplicate techtree files will be merged!\n"); + } + else if(paramPartTokens[4] == "svndelete") { + svnPurgeFiles = true; + printf("*NOTE All unused / duplicate techtree files will be removed from svn!\n"); + } } } } - { printf("\n---------------- Loading factions inside world ----------------"); World world; @@ -1819,7 +1884,7 @@ void runTechValidationReport(int argc, char** argv) { std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) { runTechValidationForPath(techPath, techName, filteredFactionList, - world, purgeUnusedFiles,purgeDuplicateFiles,purgedMegaBytes); + world, purgeUnusedFiles,purgeDuplicateFiles,svnPurgeFiles,purgedMegaBytes); } } } diff --git a/source/glest_game/menu/main_menu.cpp b/source/glest_game/menu/main_menu.cpp index a1c18325..05ededf0 100644 --- a/source/glest_game/menu/main_menu.cpp +++ b/source/glest_game/menu/main_menu.cpp @@ -221,7 +221,7 @@ MenuState::MenuState(Program *program, MainMenu *mainMenu, const string &stateNa //camera XmlTree xmlTree; - xmlTree.load(data_path + "data/core/menu/menu.xml"); + xmlTree.load(data_path + "data/core/menu/menu.xml",Properties::getTagReplacementValues()); const XmlNode *menuNode= xmlTree.getRootNode(); const XmlNode *cameraNode= menuNode->getChild("camera"); diff --git a/source/glest_game/menu/menu_background.cpp b/source/glest_game/menu/menu_background.cpp index 94cc22d5..99646598 100644 --- a/source/glest_game/menu/menu_background.cpp +++ b/source/glest_game/menu/menu_background.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Martiño Figueroa +// Copyright (C) 2001-2008 Marti�o Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -40,7 +40,7 @@ MenuBackground::MenuBackground(){ string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey); XmlTree xmlTree; - xmlTree.load(data_path + "data/core/menu/menu.xml"); + xmlTree.load(data_path + "data/core/menu/menu.xml",Properties::getTagReplacementValues()); const XmlNode *menuNode= xmlTree.getRootNode(); //water diff --git a/source/glest_game/menu/menu_state_scenario.cpp b/source/glest_game/menu/menu_state_scenario.cpp index 2b80b5e0..e4113157 100644 --- a/source/glest_game/menu/menu_state_scenario.cpp +++ b/source/glest_game/menu/menu_state_scenario.cpp @@ -245,7 +245,7 @@ void MenuStateScenario::loadScenarioInfo(string file, ScenarioInfo *scenarioInfo Lang &lang= Lang::getInstance(); XmlTree xmlTree; - xmlTree.load(file); + xmlTree.load(file,Properties::getTagReplacementValues()); const XmlNode *scenarioNode= xmlTree.getRootNode(); const XmlNode *difficultyNode= scenarioNode->getChild("difficulty"); diff --git a/source/glest_game/types/faction_type.cpp b/source/glest_game/types/faction_type.cpp index 7789ab3e..69f6db1a 100644 --- a/source/glest_game/types/faction_type.cpp +++ b/source/glest_game/types/faction_type.cpp @@ -118,7 +118,9 @@ void FactionType::load(const string &dir, const TechTree *techTree, Checksum* ch techtreeChecksum->addFile(path); XmlTree xmlTree; - xmlTree.load(path); + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(currentPath,currentPath)); const XmlNode *factionNode= xmlTree.getRootNode(); diff --git a/source/glest_game/types/resource_type.cpp b/source/glest_game/types/resource_type.cpp index f15d0876..2f738179 100644 --- a/source/glest_game/types/resource_type.cpp +++ b/source/glest_game/types/resource_type.cpp @@ -17,6 +17,7 @@ #include "renderer.h" #include "xml_parser.h" #include "game_util.h" +#include "properties.h" #include "leak_dumper.h" using namespace Shared::Util; @@ -46,7 +47,7 @@ ResourceType::~ResourceType(){ } void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtreeChecksum, - std::map > > &loadedFileList) { + std::map > > &loadedFileList, string techtreePath) { string path, str; Renderer &renderer= Renderer::getInstance(); @@ -67,7 +68,9 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre //tree XmlTree xmlTree; - xmlTree.load(path); + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techtreePath + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(currentPath,currentPath)); const XmlNode *resourceNode= xmlTree.getRootNode(); @@ -104,7 +107,7 @@ void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtre ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); objectParticleSystemType->load(dir, currentPath + particlePath, - &Renderer::getInstance(), loadedFileList, sourceXMLFile); + &Renderer::getInstance(), loadedFileList, sourceXMLFile, techtreePath); loadedFileList[currentPath + particlePath].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue())); particleTypes.push_back(objectParticleSystemType); diff --git a/source/glest_game/types/resource_type.h b/source/glest_game/types/resource_type.h index b35caf43..57d12fa9 100644 --- a/source/glest_game/types/resource_type.h +++ b/source/glest_game/types/resource_type.h @@ -54,7 +54,8 @@ public: ResourceType(); ~ResourceType(); void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum, - std::map > > &loadedFileList); + std::map > > &loadedFileList, + string techtreePath); //get int getClass() const {return resourceClass;} diff --git a/source/glest_game/types/skill_type.cpp b/source/glest_game/types/skill_type.cpp index 5b935439..635104ce 100644 --- a/source/glest_game/types/skill_type.cpp +++ b/source/glest_game/types/skill_type.cpp @@ -81,7 +81,7 @@ void SkillType::load(const XmlNode *sn, const string &dir, const TechTree *tt, string path= particleFileNode->getAttribute("path")->getRestrictedValue(); UnitParticleSystemType *unitParticleSystemType= new UnitParticleSystemType(); unitParticleSystemType->load(dir, currentPath + path, &Renderer::getInstance(), - loadedFileList,parentLoader); + loadedFileList,parentLoader,tt->getPath()); loadedFileList[currentPath + path].push_back(make_pair(parentLoader,particleFileNode->getAttribute("path")->getRestrictedValue())); unitParticleSystemTypes.push_back(unitParticleSystemType); } @@ -251,7 +251,8 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree string path= particleNode->getAttribute("path")->getRestrictedValue(); projectileParticleSystemType= new ParticleSystemTypeProjectile(); projectileParticleSystemType->load(dir, currentPath + path, - &Renderer::getInstance(), loadedFileList, parentLoader); + &Renderer::getInstance(), loadedFileList, parentLoader, + tt->getPath()); } //proj sounds @@ -286,7 +287,8 @@ void AttackSkillType::load(const XmlNode *sn, const string &dir, const TechTree string path= particleNode->getAttribute("path")->getRestrictedValue(); splashParticleSystemType= new ParticleSystemTypeSplash(); splashParticleSystemType->load(dir, currentPath + path, - &Renderer::getInstance(),loadedFileList, parentLoader); + &Renderer::getInstance(),loadedFileList, parentLoader, + tt->getPath()); } } } diff --git a/source/glest_game/types/tech_tree.cpp b/source/glest_game/types/tech_tree.cpp index b324d307..9dd117ae 100644 --- a/source/glest_game/types/tech_tree.cpp +++ b/source/glest_game/types/tech_tree.cpp @@ -34,6 +34,7 @@ namespace Glest{ namespace Game{ Checksum TechTree::loadTech(const vector pathList, const string &techName, set &factions, Checksum* checksum, std::map > > &loadedFileList) { + name = ""; Checksum techtreeChecksum; for(int idx = 0; idx < pathList.size(); idx++) { string currentPath = pathList[idx]; @@ -54,10 +55,10 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum string currentPath = dir; endPathWithSlash(currentPath); + treePath = currentPath; + name= lastDir(currentPath); vector filenames; - string name= lastDir(currentPath); - Logger::getInstance().add("TechTree: "+ formatString(name), true); //load resources @@ -69,7 +70,8 @@ void TechTree::load(const string &dir, set &factions, Checksum* checksum for(int i=0; i &factions, Checksum* checksum checksum->addFile(path); checksumValue.addFile(path); - xmlTree.load(path); + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = currentPath + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(currentPath,currentPath)); const XmlNode *techTreeNode= xmlTree.getRootNode(); diff --git a/source/glest_game/types/tech_tree.h b/source/glest_game/types/tech_tree.h index 2c514954..2d893a9f 100644 --- a/source/glest_game/types/tech_tree.h +++ b/source/glest_game/types/tech_tree.h @@ -36,7 +36,11 @@ private: typedef vector AttackTypes; private: - string desc; + + string name; + //string desc; + string treePath; + ResourceTypes resourceTypes; FactionTypes factionTypes; ArmorTypes armorTypes; @@ -57,7 +61,11 @@ public: int getTypeCount() const {return factionTypes.size();} const FactionType *getType(int i) const {return &factionTypes[i];} const ResourceType *getResourceType(int i) const {return &resourceTypes[i];} - const string &getDesc() const {return desc;} + const string getName() const {return name;} + //const string &getDesc() const {return desc;} + + const string getPath() const {return treePath;} + const FactionType *getType(const string &name) const; FactionType *getTypeByName(const string &name); const ResourceType *getResourceType(const string &name) const; diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index fce64519..c96ac59b 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -130,8 +130,7 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, this->id= id; - try{ - + try { Logger::getInstance().add("Unit type: " + formatString(name), true); //file load @@ -139,7 +138,9 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, techtreeChecksum->addFile(path); XmlTree xmlTree; - xmlTree.load(path); + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(dir,dir)); const XmlNode *unitNode= xmlTree.getRootNode(); @@ -295,7 +296,8 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, Texture2D *newTexture = NULL; unitParticleSystemType->load(dir, currentPath + path, - &Renderer::getInstance(),loadedFileList, sourceXMLFile); + &Renderer::getInstance(),loadedFileList, sourceXMLFile, + techTree->getPath()); loadedFileList[currentPath + path].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue())); //if(unitParticleSystemType->hasTexture() == false) { diff --git a/source/glest_game/types/upgrade_type.cpp b/source/glest_game/types/upgrade_type.cpp index 4bacb680..1ead348c 100644 --- a/source/glest_game/types/upgrade_type.cpp +++ b/source/glest_game/types/upgrade_type.cpp @@ -59,12 +59,14 @@ void UpgradeType::load(const string &dir, const TechTree *techTree, string path = currentPath + name + ".xml"; string sourceXMLFile = path; - try{ + try { checksum->addFile(path); techtreeChecksum->addFile(path); XmlTree xmlTree; - xmlTree.load(path); + std::map mapExtraTagReplacementValues; + mapExtraTagReplacementValues["$COMMONDATAPATH"] = techTree->getPath() + "/commondata/"; + xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues)); loadedFileList[path].push_back(make_pair(currentPath,currentPath)); const XmlNode *upgradeNode= xmlTree.getRootNode(); diff --git a/source/glest_game/world/scenario.cpp b/source/glest_game/world/scenario.cpp index ead28012..8956a803 100644 --- a/source/glest_game/world/scenario.cpp +++ b/source/glest_game/world/scenario.cpp @@ -19,6 +19,7 @@ #include "game_util.h" #include #include "platform_common.h" +#include "properties.h" #include "leak_dumper.h" using namespace Shared::Xml; @@ -47,7 +48,7 @@ Checksum Scenario::load(const string &path) { //parse xml XmlTree xmlTree; - xmlTree.load(path); + xmlTree.load(path,Properties::getTagReplacementValues()); const XmlNode *scenarioNode= xmlTree.getRootNode(); const XmlNode *scriptsNode= scenarioNode->getChild("scripts"); diff --git a/source/glest_game/world/tileset.cpp b/source/glest_game/world/tileset.cpp index e774c57c..14d63233 100644 --- a/source/glest_game/world/tileset.cpp +++ b/source/glest_game/world/tileset.cpp @@ -19,6 +19,7 @@ #include "renderer.h" #include "game_util.h" #include "leak_dumper.h" +#include "properties.h" #include "platform_util.h" using namespace Shared::Util; @@ -158,7 +159,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck //parse xml XmlTree xmlTree; - xmlTree.load(path); + xmlTree.load(path,Properties::getTagReplacementValues()); loadedFileList[path].push_back(make_pair(currentPath,currentPath)); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -226,7 +227,7 @@ void Tileset::load(const string &dir, Checksum *checksum, Checksum *tilesetCheck string path= particleFileNode->getAttribute("path")->getRestrictedValue(); ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType(); objectParticleSystemType->load(dir, currentPath + path, - &Renderer::getInstance(), loadedFileList, sourceXMLFile); + &Renderer::getInstance(), loadedFileList, sourceXMLFile,""); loadedFileList[currentPath + path].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue())); objectTypes[i].addParticleSystem((objectParticleSystemType)); diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index 6c4a96ab..a269958a 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -175,6 +175,7 @@ bool renameFile(string oldFile, string newFile); void removeFolder(const string path); off_t getFileSize(string filename); bool searchAndReplaceTextInFile(string fileName, string findText, string replaceText, bool simulateOnly); +void copyFileTo(string fromFileName, string toFileName); int getScreenW(); int getScreenH(); diff --git a/source/shared_lib/include/util/properties.h b/source/shared_lib/include/util/properties.h index e2ba7874..eb84d4fd 100644 --- a/source/shared_lib/include/util/properties.h +++ b/source/shared_lib/include/util/properties.h @@ -75,7 +75,8 @@ public: void setFloat(const string &key, float value); void setString(const string &key, const string &value); - static bool applyTagsToValue(string &value); + static bool applyTagsToValue(string &value, std::map *mapTagReplacementValues=NULL); + static std::map getTagReplacementValues(std::map *mapExtraTagReplacementValues=NULL); string getpath() const { return path;} diff --git a/source/shared_lib/include/xml/xml_parser.h b/source/shared_lib/include/xml/xml_parser.h index 844fefa2..3ac4e517 100644 --- a/source/shared_lib/include/xml/xml_parser.h +++ b/source/shared_lib/include/xml/xml_parser.h @@ -15,10 +15,10 @@ #include #include #include +#include #include "leak_dumper.h" -using std::string; -using std::vector; +using namespace std; namespace XERCES_CPP_NAMESPACE{ class DOMImplementation; @@ -29,7 +29,7 @@ namespace XERCES_CPP_NAMESPACE{ namespace Shared{ namespace Xml{ -const int strSize= 256; +const int strSize= 4096; class XmlIo; class XmlTree; @@ -53,7 +53,7 @@ private: public: static XmlIo &getInstance(); ~XmlIo(); - XmlNode *load(const string &path); + XmlNode *load(const string &path, std::map mapTagReplacementValues); void save(const string &path, const XmlNode *node); }; @@ -74,7 +74,7 @@ public: ~XmlTree(); void init(const string &name); - void load(const string &path); + void load(const string &path, std::map mapTagReplacementValues); void save(const string &path); XmlNode *getRootNode() const {return rootNode;} @@ -84,7 +84,7 @@ public: // class XmlNode // ===================================================== -class XmlNode{ +class XmlNode { private: string name; string text; @@ -96,7 +96,7 @@ private: void operator =(XmlNode&); public: - XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node); + XmlNode(XERCES_CPP_NAMESPACE::DOMNode *node, std::map mapTagReplacementValues); XmlNode(const string &name); ~XmlNode(); @@ -115,7 +115,7 @@ public: XmlNode *addChild(const string &name); - XmlAttribute *addAttribute(const string &name, const string &value); + XmlAttribute *addAttribute(const string &name, const string &value, std::map mapTagReplacementValues); XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const; @@ -133,14 +133,15 @@ private: string name; bool skipRestrictionCheck; bool usesCommondata; + std::map mapTagReplacementValues; private: XmlAttribute(XmlAttribute&); void operator =(XmlAttribute&); public: - XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute); - XmlAttribute(const string &name, const string &value); + XmlAttribute(XERCES_CPP_NAMESPACE::DOMNode *attribute, std::map mapTagReplacementValues); + XmlAttribute(const string &name, const string &value, std::map mapTagReplacementValues); public: const string getName() const {return name;} diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index a137cd43..f43ce762 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -1807,16 +1807,18 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) { buff_ptr = buffer; - while ((find_ptr = strstr(buff_ptr,findText.c_str()))) { - //printf("Replacing text [%s] with [%s] in file [%s]\n",findText.c_str(),replaceText.c_str(),fileName.c_str()); + if(findText != "") { + while ((find_ptr = strstr(buff_ptr,findText.c_str()))) { + //printf("Replacing text [%s] with [%s] in file [%s]\n",findText.c_str(),replaceText.c_str(),fileName.c_str()); - while(buff_ptr < find_ptr) { - fputc((int)*buff_ptr++,fp2); + while(buff_ptr < find_ptr) { + fputc((int)*buff_ptr++,fp2); + } + fputs(replaceText.c_str(),fp2); + + buff_ptr += find_len; + replacedText = true; } - fputs(replaceText.c_str(),fp2); - - buff_ptr += find_len; - replacedText = true; } fputs(buff_ptr,fp2); } @@ -1835,6 +1837,24 @@ bool searchAndReplaceTextInFile(string fileName, string findText, string replace return replacedText; } +void copyFileTo(string fromFileName, string toFileName) { + const int MAX_LEN_SINGLE_LINE = 4096; + char buffer[MAX_LEN_SINGLE_LINE+2]; + char *buff_ptr, *find_ptr; + FILE *fp1, *fp2; + + fp1 = fopen(fromFileName.c_str(),"r"); + fp2 = fopen(toFileName.c_str(),"w"); + + while(fgets(buffer,MAX_LEN_SINGLE_LINE + 2,fp1)) { + buff_ptr = buffer; + fputs(buff_ptr,fp2); + } + + fclose(fp2); + fclose(fp1); +} + // ===================================== // ModeInfo // ===================================== diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index d8ae5673..ecf53198 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -104,8 +104,87 @@ void Properties::load(const string &path, bool clearCurrentProperties) { fileStream.close(); } -bool Properties::applyTagsToValue(string &value) { +std::map Properties::getTagReplacementValues(std::map *mapExtraTagReplacementValues) { + std::map mapTagReplacementValues; + + // + // #1 + // First add the standard tags + // + char *homeDir = NULL; +#ifdef WIN32 + homeDir = getenv("USERPROFILE"); +#else + homeDir = getenv("HOME"); +#endif + + mapTagReplacementValues["~/"] = (homeDir != NULL ? homeDir : ""); + mapTagReplacementValues["$HOME"] = (homeDir != NULL ? homeDir : ""); + mapTagReplacementValues["%%HOME%%"] = (homeDir != NULL ? homeDir : ""); + mapTagReplacementValues["%%USERPROFILE%%"] = (homeDir != NULL ? homeDir : ""); + mapTagReplacementValues["%%HOMEPATH%%"] = (homeDir != NULL ? homeDir : ""); + + // For win32 we allow use of the appdata variable since that is the recommended + // place for application data in windows platform +#ifdef WIN32 + TCHAR szPath[MAX_PATH]=""; + // Get path for each computer, non-user specific and non-roaming data. + if ( SUCCEEDED( SHGetFolderPath( NULL, CSIDL_APPDATA, + NULL, 0, szPath))) { + string appPath = szPath; + mapTagReplacementValues["$APPDATA"] = appPath; + mapTagReplacementValues["%%APPDATA%%"] = appPath; + } +#endif + + char *username = NULL; + username = getenv("USERNAME"); + + mapTagReplacementValues["$USERNAME"] = (username != NULL ? username : ""); + mapTagReplacementValues["%%USERNAME%%"] = (username != NULL ? username : ""); + + mapTagReplacementValues["$APPLICATIONPATH"] = Properties::applicationPath; + mapTagReplacementValues["%%APPLICATIONPATH%%"] = Properties::applicationPath; + +#if defined(CUSTOM_DATA_INSTALL_PATH) + mapTagReplacementValues["$APPLICATIONDATAPATH"] = CUSTOM_DATA_INSTALL_PATH; + mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = CUSTOM_DATA_INSTALL_PATH; + + //mapTagReplacementValues["$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); + //mapTagReplacementValues["%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); + +#else + mapTagReplacementValues["$APPLICATIONDATAPATH"] = Properties::applicationPath; + mapTagReplacementValues["%%APPLICATIONDATAPATH%%"] = Properties::applicationPath; + + //mapTagReplacementValues["$COMMONDATAPATH", Properties::applicationPath + "/commondata/"); + //mapTagReplacementValues["%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/"); +#endif + + // + // #2 + // Next add the extra tags if passed in + // + if(mapExtraTagReplacementValues != NULL) { + for(std::map::iterator iterMap = mapExtraTagReplacementValues->begin(); + iterMap != mapExtraTagReplacementValues->end(); ++iterMap) { + mapTagReplacementValues[iterMap->first] = iterMap->second; + } + } + + return mapTagReplacementValues; +} + +bool Properties::applyTagsToValue(string &value, std::map *mapTagReplacementValues) { string originalValue = value; + + if(mapTagReplacementValues != NULL) { + for(std::map::iterator iterMap = mapTagReplacementValues->begin(); + iterMap != mapTagReplacementValues->end(); ++iterMap) { + replaceAll(value, iterMap->first, iterMap->second); + } + } + else { char *homeDir = NULL; #ifdef WIN32 homeDir = getenv("USERPROFILE"); @@ -144,17 +223,19 @@ bool Properties::applyTagsToValue(string &value) { replaceAll(value, "$APPLICATIONDATAPATH", CUSTOM_DATA_INSTALL_PATH); replaceAll(value, "%%APPLICATIONDATAPATH%%", CUSTOM_DATA_INSTALL_PATH); - replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); - replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); + //replaceAll(value, "$COMMONDATAPATH", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); + //replaceAll(value, "%%COMMONDATAPATH%%", string(CUSTOM_DATA_INSTALL_PATH) + "/commondata/"); #else replaceAll(value, "$APPLICATIONDATAPATH", Properties::applicationPath); replaceAll(value, "%%APPLICATIONDATAPATH%%", Properties::applicationPath); - replaceAll(value, "$COMMONDATAPATH", Properties::applicationPath + "/commondata/"); - replaceAll(value, "%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/"); + //replaceAll(value, "$COMMONDATAPATH", Properties::applicationPath + "/commondata/"); + //replaceAll(value, "%%COMMONDATAPATH%%", Properties::applicationPath + "/commondata/"); #endif + } + //printf("\nBEFORE SUBSTITUTE [%s] AFTER [%s]\n",originalValue.c_str(),value.c_str()); return (originalValue != value); } diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index 4e0a9ef0..33bbd437 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -88,7 +88,7 @@ XmlIo::~XmlIo(){ XMLPlatformUtils::Terminate(); } -XmlNode *XmlIo::load(const string &path){ +XmlNode *XmlIo::load(const string &path, std::map mapTagReplacementValues) { try{ ErrorHandler errorHandler; @@ -111,7 +111,7 @@ XmlNode *XmlIo::load(const string &path){ throw runtime_error("Can not parse URL: " + path); } - XmlNode *rootNode= new XmlNode(document->getDocumentElement()); + XmlNode *rootNode= new XmlNode(document->getDocumentElement(),mapTagReplacementValues); parser->release(); return rootNode; } @@ -167,8 +167,8 @@ void XmlTree::init(const string &name){ this->rootNode= new XmlNode(name); } -void XmlTree::load(const string &path){ - this->rootNode= XmlIo::getInstance().load(path); +void XmlTree::load(const string &path, std::map mapTagReplacementValues) { + this->rootNode= XmlIo::getInstance().load(path, mapTagReplacementValues); } void XmlTree::save(const string &path){ @@ -183,7 +183,7 @@ XmlTree::~XmlTree(){ // class XmlNode // ===================================================== -XmlNode::XmlNode(DOMNode *node) { +XmlNode::XmlNode(DOMNode *node, std::map mapTagReplacementValues) { if(node == NULL || node->getNodeName() == NULL) { throw runtime_error("XML structure seems to be corrupt!"); } @@ -203,7 +203,7 @@ XmlNode::XmlNode(DOMNode *node) { for(unsigned int i = 0; i < node->getChildNodes()->getLength(); ++i) { DOMNode *currentNode= node->getChildNodes()->item(i); if(currentNode != NULL && currentNode->getNodeType()==DOMNode::ELEMENT_NODE){ - XmlNode *xmlNode= new XmlNode(currentNode); + XmlNode *xmlNode= new XmlNode(currentNode, mapTagReplacementValues); children.push_back(xmlNode); } } @@ -215,7 +215,7 @@ XmlNode::XmlNode(DOMNode *node) { for(unsigned int i = 0; i < domAttributes->getLength(); ++i) { DOMNode *currentNode= domAttributes->item(i); if(currentNode->getNodeType() == DOMNode::ATTRIBUTE_NODE) { - XmlAttribute *xmlAttribute= new XmlAttribute(domAttributes->item(i)); + XmlAttribute *xmlAttribute= new XmlAttribute(domAttributes->item(i), mapTagReplacementValues); attributes.push_back(xmlAttribute); } } @@ -321,8 +321,8 @@ XmlNode *XmlNode::addChild(const string &name){ return node; } -XmlAttribute *XmlNode::addAttribute(const string &name, const string &value) { - XmlAttribute *attr= new XmlAttribute(name, value); +XmlAttribute *XmlNode::addAttribute(const string &name, const string &value, std::map mapTagReplacementValues) { + XmlAttribute *attr= new XmlAttribute(name, value, mapTagReplacementValues); attributes.push_back(attr); return attr; } @@ -371,27 +371,30 @@ string XmlNode::getTreeString() const { // class XmlAttribute // ===================================================== -XmlAttribute::XmlAttribute(DOMNode *attribute) { - skipRestrictionCheck = false; - usesCommondata = false; - char str[strSize]=""; +XmlAttribute::XmlAttribute(DOMNode *attribute, std::map mapTagReplacementValues) { + skipRestrictionCheck = false; + usesCommondata = false; + this->mapTagReplacementValues = mapTagReplacementValues; + char str[strSize] = ""; XMLString::transcode(attribute->getNodeValue(), str, strSize-1); value= str; usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos)); - skipRestrictionCheck = Properties::applyTagsToValue(this->value); + skipRestrictionCheck = Properties::applyTagsToValue(this->value,&this->mapTagReplacementValues); XMLString::transcode(attribute->getNodeName(), str, strSize-1); name= str; } -XmlAttribute::XmlAttribute(const string &name, const string &value) { - skipRestrictionCheck = false; - usesCommondata = false; - this->name= name; - this->value= value; +XmlAttribute::XmlAttribute(const string &name, const string &value, std::map mapTagReplacementValues) { + skipRestrictionCheck = false; + usesCommondata = false; + this->mapTagReplacementValues = mapTagReplacementValues; + this->name = name; + this->value = value; + usesCommondata = ((value.find("$COMMONDATAPATH") != string::npos) || (value.find("%%COMMONDATAPATH%%") != string::npos)); - skipRestrictionCheck = Properties::applyTagsToValue(this->value); + skipRestrictionCheck = Properties::applyTagsToValue(this->value,&this->mapTagReplacementValues); } bool XmlAttribute::getBoolValue() const {