From 01f8f518b3a5002bfb46f227bafd2873d0b24eed Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 15 Mar 2012 22:09:11 +0000 Subject: [PATCH] - saved games now go into saved folder --- source/glest_game/game/game.cpp | 2 +- source/glest_game/main/main.cpp | 15 ++++++- source/shared_lib/sources/xml/xml_parser.cpp | 44 ++++++++++---------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index c9e8d7cab..d0827b3fa 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -3606,7 +3606,7 @@ string Game::saveGame(string name) { gameNode->addAttribute("lastMasterServerGameStatsDump",intToStr(lastMasterServerGameStatsDump), mapTagReplacements); // Save the file now - string saveGameFile = name; + string saveGameFile = "saved/" + name; if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { saveGameFile = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + saveGameFile; } diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 9fe3b7a20..d0ace0b24 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2706,9 +2706,14 @@ int glestMain(int argc, char** argv) { shutdownFadeSoundMilliseconds = config.getInt("ShutdownFadeSoundMilliseconds",intToStr(shutdownFadeSoundMilliseconds).c_str()); string userData = config.getString("UserData_Root",""); - if(userData != "") { - endPathWithSlash(userData); + if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { + userData = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey); + } + if(userData != "") { + endPathWithSlash(userData); + } + if(userData != "") { if(isdir(userData.c_str()) == false) { createDirectoryPaths(userData); } @@ -2719,6 +2724,12 @@ int glestMain(int argc, char** argv) { } setCRCCacheFilePath(crcCachePath); + string savedGamePath = userData + "saved/"; + if(isdir(savedGamePath.c_str()) == false) { + createDirectoryPaths(savedGamePath); + //printf("savedGamePath = [%s]\n",savedGamePath.c_str()); + } + string tempDataPath = userData + "temp/"; if(isdir(tempDataPath.c_str()) == true) { removeFolder(tempDataPath); diff --git a/source/shared_lib/sources/xml/xml_parser.cpp b/source/shared_lib/sources/xml/xml_parser.cpp index f8f94d895..1fc96c246 100644 --- a/source/shared_lib/sources/xml/xml_parser.cpp +++ b/source/shared_lib/sources/xml/xml_parser.cpp @@ -267,6 +267,7 @@ XmlNode *XmlIoRapid::load(const string &path, std::map mapTagRepl Chrono chrono; chrono.start(); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using RapidXml to load file [%s]\n",path.c_str()); + //printf("Using RapidXml to load file [%s]\n",path.c_str()); XmlNode *rootNode = NULL; try { @@ -280,29 +281,25 @@ XmlNode *XmlIoRapid::load(const string &path, std::map mapTagRepl throw runtime_error("Can not open file: [" + path + "]"); } - // read file into input_xml - string inputXml = ""; - const int bufsize = 32 * 1024; - char buff[bufsize]=""; - while(xmlFile) { - xmlFile.read(buff,bufsize); - if(buff[0] != '\0') { - inputXml += buff; - } - } + xmlFile.unsetf(ios::skipws); - // make a safe-to-modify copy of input_xml - // (you should never modify the contents of an std::string directly) - vector buffer(inputXml.begin(), inputXml.end()); - buffer.push_back('\0'); + // Determine stream size + xmlFile.seekg(0, ios::end); + size_t size = xmlFile.tellg(); + xmlFile.seekg(0); - /* "Read file into vector" See linked thread above*/ - //vector buffer((istreambuf_iterator(xmlFile)), istreambuf_iterator( )); - //buffer.push_back('\0'); - doc->parse(&buffer[0]); + // Load data and add terminating 0 + vector buffer; + buffer.resize(size + 1); + xmlFile.read(&buffer.front(), static_cast(size)); + buffer[size] = 0; + + //doc->parse(&buffer[0]); + //doc->parse(&buffer.front()); + //doc->parse(&buffer[0]); + doc->parse(&buffer.front()); rootNode= new XmlNode(doc->first_node(),mapTagReplacementValues); - //parser->release(); #if defined(WIN32) && !defined(__MINGW32__) if(fp) { @@ -310,15 +307,16 @@ XmlNode *XmlIoRapid::load(const string &path, std::map mapTagRepl } #endif } - catch(const DOMException &ex) { + catch(const exception &ex) { char szBuf[8096]=""; - sprintf(szBuf,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(ex.msg)); + sprintf(szBuf,"In [%s::%s Line: %d] Exception while loading: [%s], msg:\n%s",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),ex.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"%s\n",szBuf); throw runtime_error(szBuf); } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] took msecs: %ld\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis()); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] took msecs: %ld for file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),path.c_str()); + printf("In [%s::%s Line: %d] took msecs: %ld for file [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,chrono.getMillis(),path.c_str()); return rootNode; } @@ -371,7 +369,7 @@ void XmlIoRapid::save(const string &path, const XmlNode *node){ } //xmlFile << xml_no_indent; -// xmlFile << xml_as_string << '\0'; +// xmlFile << xml_as_string; xmlFile << doc; #if defined(WIN32) && !defined(__MINGW32__)