From 68a1b883eb50c4698b0d0f433d10c76747bf2463 Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:43:44 +0200 Subject: [PATCH] autosave folders --- Global.h | 4 ++++ client/CPlayerInterface.cpp | 8 +++++--- lib/StartInfo.h | 4 +++- lib/serializer/CSerializer.h | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Global.h b/Global.h index 3c308f54c..e0c22dfae 100644 --- a/Global.h +++ b/Global.h @@ -121,6 +121,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size."); #include #include #include +#include #include #include #include @@ -166,6 +167,9 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size."); #include #include #include +#include +#include +#include #ifndef M_PI # define M_PI 3.14159265358979323846 diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 3a407a796..d1dd2fb8b 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -193,6 +193,8 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player) void CPlayerInterface::performAutosave() { + std::string id = cb->getStartInfo()->uuid.substr(0, 8); + int frequency = static_cast(settings["general"]["saveFrequency"].Integer()); if(frequency > 0 && cb->getDate() % frequency == 0) { @@ -204,7 +206,7 @@ void CPlayerInterface::performAutosave() prefix = settings["general"]["savePrefix"].String(); if(prefix.empty()) { - prefix = cb->getMapHeader()->name.substr(0, 5) + "_"; + prefix = cb->getMapHeader()->name.substr(0, 18) + "_" + id + "/"; } } @@ -213,7 +215,7 @@ void CPlayerInterface::performAutosave() int autosaveCountLimit = settings["general"]["autosaveCountLimit"].Integer(); if(autosaveCountLimit > 0) { - cb->save("Saves/" + prefix + "Autosave_" + std::to_string(autosaveCount)); + cb->save("Saves/Autosave/" + prefix + "Autosave_" + std::to_string(autosaveCount)); autosaveCount %= autosaveCountLimit; } else @@ -222,7 +224,7 @@ void CPlayerInterface::performAutosave() + std::to_string(cb->getDate(Date::WEEK)) + std::to_string(cb->getDate(Date::DAY_OF_WEEK)); - cb->save("Saves/" + prefix + "Autosave_" + stringifiedDate); + cb->save("Saves/Autosave/" + prefix + "Autosave_" + stringifiedDate); } } } diff --git a/lib/StartInfo.h b/lib/StartInfo.h index 779f9c9e0..6a672a2da 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -80,6 +80,7 @@ struct DLL_LINKAGE StartInfo ui32 seedToBeUsed; //0 if not sure (client requests server to decide, will be send in reply pack) ui32 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet ui32 mapfileChecksum; //0 if not relevant + std::string uuid; ui8 turnTime; //in minutes, 0=unlimited std::string mapname; // empty for random map, otherwise name of the map or savegame bool createRandomMap() const { return mapGenOptions != nullptr; } @@ -103,6 +104,7 @@ struct DLL_LINKAGE StartInfo h & seedToBeUsed; h & seedPostInit; h & mapfileChecksum; + h & uuid; h & turnTime; h & mapname; h & mapGenOptions; @@ -110,7 +112,7 @@ struct DLL_LINKAGE StartInfo } StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0), - mapfileChecksum(0), turnTime(0) + mapfileChecksum(0), turnTime(0), uuid(boost::uuids::to_string(boost::uuids::random_generator()())) { } diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index 926d73b6c..086eb0d04 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -14,8 +14,8 @@ VCMI_LIB_NAMESPACE_BEGIN -const ui32 SERIALIZATION_VERSION = 825; -const ui32 MINIMAL_SERIALIZATION_VERSION = 824; +const ui32 SERIALIZATION_VERSION = 826; +const ui32 MINIMAL_SERIALIZATION_VERSION = 826; const std::string SAVEGAME_MAGIC = "VCMISVG"; class CHero;