diff --git a/Adventures in Lestoria/SaveFile.cpp b/Adventures in Lestoria/SaveFile.cpp index 5d271381..e5f61f48 100644 --- a/Adventures in Lestoria/SaveFile.cpp +++ b/Adventures in Lestoria/SaveFile.cpp @@ -204,13 +204,16 @@ const void SaveFile::SaveGame(){ bool fileHashWrittenSuccessfully{false}; while(!fileNoHashWrittenSuccessfully||!fileHashWrittenSuccessfully){ saveFile["Hash"].SetString(""); - fileNoHashWrittenSuccessfully=utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); + fileNoHashWrittenSuccessfully=utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)+".tmp"); - std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID)); + std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID)+".tmp"); saveFile["Hash"].SetString(fileHash); fileHashWrittenSuccessfully=utils::datafile::Write(saveFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); //Once the hash has been computed and added, save the file a second time. } + std::error_code result; + std::filesystem::remove("save_file_path"_S+std::format("save.{:04}",saveFileID)+".tmp",result); + if(!result)LOG(std::format("WARNING! Could not delete temporary save file. Error: {}",result.message())); #pragma endregion //WARNING! DO NOT WRITE ANY CODE BELOW HERE!!!!! THE HASH HAS ALREADY BEEN WRITTEN. //FILES BECOME CORRUPTED IF THE SAVE FILE IS MODIFIED FROM HERE ONWARDS. @@ -335,7 +338,7 @@ void SaveFile::LoadFile(){ fileNoHashWrittenSuccessfully=false; fileHashWrittenSuccessfully=false; loadFile["Hash"].SetString(""); - fileNoHashWrittenSuccessfully=utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); + fileNoHashWrittenSuccessfully=utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)+".tmp"); auto trim = [](std::string& s) { @@ -343,7 +346,7 @@ void SaveFile::LoadFile(){ s.erase(s.find_last_not_of(" \t\n\r\f\v") + 1); }; - std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID)); + std::string fileHash=util::GetHash("save_file_path"_S+std::format("save.{:04}",saveFileID)+".tmp"); trim(fileHash); //It's possible the expected file hash has a space at the end/beginning that gets stripped out. We want to trim and match that string. if(!ADMIN_MODE&&expectedFileHash!=fileHash){ @@ -354,6 +357,10 @@ void SaveFile::LoadFile(){ loadFile["Hash"].SetString(expectedFileHash); //Now write the hash back into the file since we tampered with it. fileHashWrittenSuccessfully=utils::datafile::Write(loadFile,"save_file_path"_S+std::format("save.{:04}",saveFileID)); } + + std::error_code result; + std::filesystem::remove("save_file_path"_S+std::format("save.{:04}",saveFileID)+".tmp",result); + if(!result)LOG(std::format("WARNING! Could not delete temporary save file. Error: {}",result.message())); } } game->ResetGame(); diff --git a/Adventures in Lestoria/Version.h b/Adventures in Lestoria/Version.h index 587f2263..9c928cbb 100644 --- a/Adventures in Lestoria/Version.h +++ b/Adventures in Lestoria/Version.h @@ -39,7 +39,7 @@ All rights reserved. #define VERSION_MAJOR 1 #define VERSION_MINOR 2 #define VERSION_PATCH 5 -#define VERSION_BUILD 11200 +#define VERSION_BUILD 11201 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/x64/Release/Adventures in Lestoria.exe b/x64/Release/Adventures in Lestoria.exe index 488512f4..000e8720 100644 Binary files a/x64/Release/Adventures in Lestoria.exe and b/x64/Release/Adventures in Lestoria.exe differ