mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- 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 <algorithm>
|
||||
#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);
|
||||
|
@ -1005,24 +1005,56 @@ vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
||||
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 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<string> 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<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());
|
||||
}
|
||||
|
@ -65,6 +65,7 @@ protected:
|
||||
bool tryCustomPath(std::pair<ConfigType,ConfigType> &type, std::pair<string,string> &file, string custom_path);
|
||||
static void CopyAll(Config *src,Config *dest);
|
||||
vector<pair<string,string> > getPropertiesFromContainer(const Properties &propertiesObj) const;
|
||||
static bool replaceFileWithLocalFile(const vector<string> &dirList, string fileNamePart, string &resultToReplace);
|
||||
|
||||
public:
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user