From d13118ecf84db17c9dfb9b79ab55fe6852b8ce70 Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Tue, 30 Dec 2014 15:05:24 -0800 Subject: [PATCH] - attempt to make updates work for windows --- source/glest_game/facilities/game_util.cpp | 34 ++++++++++++++++++++++ source/glest_game/facilities/game_util.h | 2 ++ source/glest_game/menu/menu_state_root.cpp | 18 +++++++----- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 7f201f93..ba4eba8f 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -370,4 +370,38 @@ void initSpecialStrings() { getCompileDateTime(); } +bool upgradeFilesInTemp() { + // Get path to temp files + string tempFilePath = "temp/"; + if(getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) != "") { + tempFilePath = getGameReadWritePath(GameConstants::path_logs_CacheLookupKey) + tempFilePath; + } + else { + Config &config = Config::getInstance(); + string userData = config.getString("UserData_Root",""); + if(userData != "") { + endPathWithSlash(userData); + } + tempFilePath = userData + tempFilePath; + } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Temp files path [%s]\n",tempFilePath.c_str()); + + // Move all files into binary folder + bool anyFailures = false; + vector fileList = getFolderTreeContentsListRecursively(tempFilePath, "", false, NULL); + for(unsigned int index = 0; index < fileList.size(); ++index) { + string fileName = fileList[index]; + string newFileName = Properties::getApplicationPath() + extractFileFromDirectoryPath(fileName); + bool result = renameFile(fileName,newFileName); + if(result == false) { + anyFailures = true; + } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",fileName.c_str(),newFileName.c_str(),result); + } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Successfully updated!\n"); + + return (fileList.size() > 0 && anyFailures == false); +} + }}//end namespace diff --git a/source/glest_game/facilities/game_util.h b/source/glest_game/facilities/game_util.h index 81f0b4cc..aab72efc 100644 --- a/source/glest_game/facilities/game_util.h +++ b/source/glest_game/facilities/game_util.h @@ -54,6 +54,8 @@ string formatString(string str); string getGameReadWritePath(string lookupKey=""); string getGameCustomCoreDataPath(string originalBasePath, string uniqueFilePath); +bool upgradeFilesInTemp(); + }}//end namespace #endif diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index bf7baf2b..c446430d 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -446,17 +446,19 @@ void MenuStateRoot::FTPClient_CallbackEvent(string itemName, removeFile(tempFilePath + itemName); } - // Move all files into binary folder - vector fileList = getFolderTreeContentsListRecursively(tempFilePath, "", false, NULL); - for(unsigned int index = 0; index < fileList.size(); ++index) { - string fileName = fileList[index]; - string newFileName = Properties::getApplicationPath() + extractFileFromDirectoryPath(fileName); - bool result = renameFile(fileName,newFileName); + bool result = upgradeFilesInTemp(); + if(result == false) { + string binaryName = Properties::getApplicationPath() + extractFileFromDirectoryPath(PlatformExceptionHandler::application_binary); + string binaryNameOld = Properties::getApplicationPath() + extractFileFromDirectoryPath(PlatformExceptionHandler::application_binary) + "__REMOVE"; + bool resultRename = renameFile(binaryName,binaryNameOld); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",binaryName.c_str(),binaryNameOld.c_str(),resultRename); + printf("#1 Rename: [%s] to [%s] result = %d\n",binaryName.c_str(),binaryNameOld.c_str(),resultRename); - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",fileName.c_str(),newFileName.c_str(),result); + result = upgradeFilesInTemp(); + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Rename: [%s] to [%s] result = %d\n",binaryName.c_str(),binaryNameOld.c_str(),resultRename); + printf("#2 Rename: [%s] to [%s] result = %d\n",binaryName.c_str(),binaryNameOld.c_str(),resultRename); } - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Successfully updated!\n"); console.addLine("Successfully updated, please restart!",true); } else {