- updated loading games to translate tutorials and scenario paths
This commit is contained in:
parent
74910ea0b2
commit
3d386936dc
|
@ -16,6 +16,8 @@
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include "xml_parser.h"
|
#include "xml_parser.h"
|
||||||
|
#include "config.h"
|
||||||
|
#include "util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
|
@ -424,6 +426,10 @@ public:
|
||||||
scenario = gameSettingsNode->getAttribute("scenario")->getValue();
|
scenario = gameSettingsNode->getAttribute("scenario")->getValue();
|
||||||
// string scenarioDir;
|
// string scenarioDir;
|
||||||
scenarioDir = gameSettingsNode->getAttribute("scenarioDir")->getValue();
|
scenarioDir = gameSettingsNode->getAttribute("scenarioDir")->getValue();
|
||||||
|
if(fileExists(scenarioDir) == false) {
|
||||||
|
scenarioDir = Config::findValidLocalFileFromPath(scenarioDir);
|
||||||
|
}
|
||||||
|
|
||||||
// string factionTypeNames[GameConstants::maxPlayers]; //faction names
|
// string factionTypeNames[GameConstants::maxPlayers]; //faction names
|
||||||
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
|
for(int idx =0; idx < GameConstants::maxPlayers; idx++) {
|
||||||
const XmlNode *factionTypeNamesNode = gameSettingsNode->getChild("factionTypeNames",idx);
|
const XmlNode *factionTypeNamesNode = gameSettingsNode->getChild("factionTypeNames",idx);
|
||||||
|
|
|
@ -1005,24 +1005,56 @@ vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
||||||
return pathList;
|
return pathList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Config::replaceFileWithLocalFile(const vector<string> &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 Config::findValidLocalFileFromPath(string fileName) {
|
||||||
string result = 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//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/");
|
size_t pos = fileName.find("techs/");
|
||||||
if(pos != fileName.npos ) {
|
if(pos != fileName.npos ) {
|
||||||
string fileNamePart = fileName.substr(pos+6);
|
string fileNamePart = fileName.substr(pos+6);
|
||||||
|
|
||||||
Config &config = Config::getInstance();
|
Config &config = Config::getInstance();
|
||||||
vector<string> dirList = config.getPathListForType(ptTechs);
|
vector<string> dirList = config.getPathListForType(ptTechs);
|
||||||
for(unsigned int i = 0; i < dirList.size(); ++i) {
|
replaceFileWithLocalFile(dirList, fileNamePart, result);
|
||||||
string path = dirList[i];
|
|
||||||
endPathWithSlash(path);
|
printf("Found file [%s] @ %lu [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str());
|
||||||
string newFileName = path + fileNamePart;
|
|
||||||
if(fileExists(newFileName) == true) {
|
|
||||||
result = newFileName;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else if(fileName.find("scenarios/") != fileName.npos) {
|
||||||
|
pos = fileName.find("scenarios/");
|
||||||
|
|
||||||
|
string fileNamePart = fileName.substr(pos+10);
|
||||||
|
|
||||||
|
Config &config = Config::getInstance();
|
||||||
|
vector<string> 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<string> 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());
|
printf("Found file [%s] @ %lu [%s]\nNew File [%s]\n",fileName.c_str(),pos,fileNamePart.c_str(),result.c_str());
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,7 @@ protected:
|
||||||
bool tryCustomPath(std::pair<ConfigType,ConfigType> &type, std::pair<string,string> &file, string custom_path);
|
bool tryCustomPath(std::pair<ConfigType,ConfigType> &type, std::pair<string,string> &file, string custom_path);
|
||||||
static void CopyAll(Config *src,Config *dest);
|
static void CopyAll(Config *src,Config *dest);
|
||||||
vector<pair<string,string> > getPropertiesFromContainer(const Properties &propertiesObj) const;
|
vector<pair<string,string> > getPropertiesFromContainer(const Properties &propertiesObj) const;
|
||||||
|
static bool replaceFileWithLocalFile(const vector<string> &dirList, string fileNamePart, string &resultToReplace);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
@ -70,9 +70,13 @@ Checksum Scenario::load(const string &path) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Exception handling (conversions and so on);
|
//Exception handling (conversions and so on);
|
||||||
catch(const exception &e) {
|
catch(const exception &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
|
char szBuf[8096]="";
|
||||||
throw runtime_error("Error: " + path + "\n" + e.what());
|
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;
|
return scenarioChecksum;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user