diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index c78dfe009..5c4202d93 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -1819,6 +1819,9 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client fileFTPProgressList.erase(itemName); safeMutexFTPProgress.ReleaseLock(); + // Clear the CRC file Cache + Checksum::clearFileCache(); + NetworkManager &networkManager= NetworkManager::getInstance(); ClientInterface* clientInterface= networkManager.getClientInterface(); const GameSettings *gameSettings = clientInterface->getGameSettings(); @@ -1889,6 +1892,9 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client } // END + // Clear the CRC file Cache + Checksum::clearFileCache(); + // Reload tilesets for the UI findDirs(Config::getInstance().getPathListForType(ptTilesets), tileSets); } diff --git a/source/shared_lib/include/util/checksum.h b/source/shared_lib/include/util/checksum.h index 60508895c..6257b282d 100644 --- a/source/shared_lib/include/util/checksum.h +++ b/source/shared_lib/include/util/checksum.h @@ -37,7 +37,7 @@ private: static std::map fileListCache; void addSum(int32 value); - void addFileToSum(const string &path); + bool addFileToSum(const string &path); public: Checksum(); @@ -49,6 +49,9 @@ public: void addByte(int8 value); void addString(const string &value); void addFile(const string &path); + + static void removeFileFromCache(const string file); + static void clearFileCache(); }; }}//end namespace diff --git a/source/shared_lib/sources/util/checksum.cpp b/source/shared_lib/sources/util/checksum.cpp index 22e802eec..75f601a54 100644 --- a/source/shared_lib/sources/util/checksum.cpp +++ b/source/shared_lib/sources/util/checksum.cpp @@ -66,7 +66,7 @@ void Checksum::addFile(const string &path){ } } -void Checksum::addFileToSum(const string &path){ +bool Checksum::addFileToSum(const string &path){ // OLD SLOW FILE I/O /* @@ -115,10 +115,10 @@ void Checksum::addFileToSum(const string &path){ free(data); */ - + bool fileExists = false; FILE* file= fopen(path.c_str(), "rb"); - if(file!=NULL) { - + if(file != NULL) { + fileExists = true; addString(lastFile(path)); bool isXMLFile = (EndsWith(path, ".xml") == true); @@ -162,12 +162,11 @@ void Checksum::addFileToSum(const string &path){ } } } - else - { + else { throw runtime_error("Can not open file: " + path); } fclose(file); - + return fileExists; } int32 Checksum::getSum() { @@ -200,4 +199,14 @@ int32 Checksum::getFileCount() { return (int32)fileList.size(); } +void Checksum::removeFileFromCache(const string file) { + if(Checksum::fileListCache.find(file) != Checksum::fileListCache.end()) { + Checksum::fileListCache.erase(file); + } +} + +void Checksum::clearFileCache() { + Checksum::fileListCache.clear(); +} + }}//end namespace