diff --git a/source/glest_game/game/game_settings.h b/source/glest_game/game/game_settings.h index 8d71f970..61e8db03 100644 --- a/source/glest_game/game/game_settings.h +++ b/source/glest_game/game/game_settings.h @@ -16,6 +16,8 @@ #include "conversion.h" #include #include "xml_parser.h" +#include "config.h" +#include "util.h" #include "leak_dumper.h" using namespace Shared::Util; @@ -424,6 +426,10 @@ public: scenario = gameSettingsNode->getAttribute("scenario")->getValue(); // string scenarioDir; scenarioDir = gameSettingsNode->getAttribute("scenarioDir")->getValue(); + if(fileExists(scenarioDir) == false) { + scenarioDir = Config::findValidLocalFileFromPath(scenarioDir); + } + // string factionTypeNames[GameConstants::maxPlayers]; //faction names for(int idx =0; idx < GameConstants::maxPlayers; idx++) { const XmlNode *factionTypeNamesNode = gameSettingsNode->getChild("factionTypeNames",idx); diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index d215eb3c..75719280 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -1005,24 +1005,56 @@ vector Config::getPathListForType(PathType type, string scenarioDir) { return pathList; } +bool Config::replaceFileWithLocalFile(const vector &dirList, string fileNamePart, string &resultToReplace) { + bool found = false; + for(unsigned int i = 0; i < dirList.size(); ++i) { + string path = dirList[i]; + endPathWithSlash(path); + string newFileName = path + fileNamePart; + if(fileExists(newFileName) == true) { + resultToReplace = newFileName; + found = true; + break; + } + } + return found; +} + + + string Config::findValidLocalFileFromPath(string fileName) { string result = fileName; // /home/user1/SCM/megaglest-trunk/mk/linux//techs/megapack/factions/tech/units/blacksmith/images/particle.bmp + // /home/user1/SCM/megaglest-trunk/mk/linux//tutorials/3_advanced_tutorial/3_advanced_tutorial.xml size_t pos = fileName.find("techs/"); if(pos != fileName.npos ) { string fileNamePart = fileName.substr(pos+6); Config &config = Config::getInstance(); vector dirList = config.getPathListForType(ptTechs); - for(unsigned int i = 0; i < dirList.size(); ++i) { - string path = dirList[i]; - endPathWithSlash(path); - string newFileName = path + fileNamePart; - if(fileExists(newFileName) == true) { - result = newFileName; - break; - } - } + replaceFileWithLocalFile(dirList, fileNamePart, result); + + printf("Found file [%s] @ %lu [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); + } + else if(fileName.find("scenarios/") != fileName.npos) { + pos = fileName.find("scenarios/"); + + string fileNamePart = fileName.substr(pos+10); + + Config &config = Config::getInstance(); + vector dirList = config.getPathListForType(ptScenarios); + replaceFileWithLocalFile(dirList, fileNamePart, result); + + printf("Found file [%s] @ %lu [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); + } + else if(fileName.find("tutorials/") != fileName.npos) { + pos = fileName.find("tutorials/"); + + string fileNamePart = fileName.substr(pos+10); + + Config &config = Config::getInstance(); + vector dirList = config.getPathListForType(ptTutorials); + replaceFileWithLocalFile(dirList, fileNamePart, result); printf("Found file [%s] @ %lu [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str()); } diff --git a/source/glest_game/global/config.h b/source/glest_game/global/config.h index 194bcda8..d93091f2 100644 --- a/source/glest_game/global/config.h +++ b/source/glest_game/global/config.h @@ -65,6 +65,7 @@ protected: bool tryCustomPath(std::pair &type, std::pair &file, string custom_path); static void CopyAll(Config *src,Config *dest); vector > getPropertiesFromContainer(const Properties &propertiesObj) const; + static bool replaceFileWithLocalFile(const vector &dirList, string fileNamePart, string &resultToReplace); public: diff --git a/source/glest_game/world/scenario.cpp b/source/glest_game/world/scenario.cpp index 50eb5d67..75848b05 100644 --- a/source/glest_game/world/scenario.cpp +++ b/source/glest_game/world/scenario.cpp @@ -70,9 +70,13 @@ Checksum Scenario::load(const string &path) { } } //Exception handling (conversions and so on); - catch(const exception &e) { - SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what()); - throw runtime_error("Error: " + path + "\n" + e.what()); + catch(const exception &ex) { + char szBuf[8096]=""; + sprintf(szBuf,"In [%s::%s %d]\nError loading scenario [%s]:\n%s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),ex.what()); + SystemFlags::OutputDebug(SystemFlags::debugError,szBuf); + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + + throw runtime_error(szBuf); } return scenarioChecksum;