From d2bbe0f35a88ac82b7efd624aa69e19c4d58b77c Mon Sep 17 00:00:00 2001 From: Michael <13953785+Laserlicht@users.noreply.github.com> Date: Wed, 23 Aug 2023 01:47:55 +0200 Subject: [PATCH] starttime in foldername --- client/CPlayerInterface.cpp | 10 +++++----- include/vstd/DateUtils.h | 1 + lib/StartInfo.h | 6 +++++- lib/vstd/DateUtils.cpp | 9 +++++++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index b6498d6b4..fcf684593 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -169,7 +169,7 @@ void CPlayerInterface::initGameInterface(std::shared_ptr ENV, std:: void CPlayerInterface::playerStartsTurn(PlayerColor player) { EVENT_HANDLER_CALLED_BY_CLIENT; - + makingTurn = false; stillMoveHero.setn(STOP_MOVE); @@ -180,7 +180,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player) GH.windows().pushWindow(adventureInt); } - //close window from another player +//close window from another player if(auto w = GH.windows().topWindow()) if(w->ID == -1 && player != playerID) w->close(); @@ -201,7 +201,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player) void CPlayerInterface::performAutosave() { - std::string id = cb->getStartInfo()->gameUuid.substr(0, 8); + std::string id = cb->getStartInfo()->gameUuid.substr(0, 4); int frequency = static_cast(settings["general"]["saveFrequency"].Integer()); if(frequency > 0 && cb->getDate() % frequency == 0) @@ -214,7 +214,7 @@ void CPlayerInterface::performAutosave() prefix = settings["general"]["savePrefix"].String(); if(prefix.empty()) { - prefix = cb->getMapHeader()->name.substr(0, 18) + "_" + id + "/"; + prefix = cb->getMapHeader()->name.substr(0, 15) + "_" + cb->getStartInfo()->startTimeIso8601 + "/"; } } @@ -232,7 +232,7 @@ void CPlayerInterface::performAutosave() + std::to_string(cb->getDate(Date::WEEK)) + std::to_string(cb->getDate(Date::DAY_OF_WEEK)); - cb->save("Saves/Autosave/" + prefix + "Autosave_" + stringifiedDate); + cb->save("Saves/Autosave/" + prefix + "Autosave_" + id + "_" + stringifiedDate); } } } diff --git a/include/vstd/DateUtils.h b/include/vstd/DateUtils.h index 9f3a9cc43..d080e96b1 100644 --- a/include/vstd/DateUtils.h +++ b/include/vstd/DateUtils.h @@ -6,6 +6,7 @@ namespace vstd { DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt); + DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt); } diff --git a/lib/StartInfo.h b/lib/StartInfo.h index fec4fb7af..afcaade81 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -9,6 +9,8 @@ */ #pragma once +#include "vstd/DateUtils.h" + #include "GameConstants.h" #include "TurnTimerInfo.h" #include "campaign/CampaignConstants.h" @@ -82,6 +84,7 @@ struct DLL_LINKAGE StartInfo 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 gameUuid; + std::string startTimeIso8601; TurnTimerInfo turnTimerInfo; std::string mapname; // empty for random map, otherwise name of the map or savegame bool createRandomMap() const { return mapGenOptions != nullptr; } @@ -106,6 +109,7 @@ struct DLL_LINKAGE StartInfo h & seedPostInit; h & mapfileChecksum; h & gameUuid; + h & startTimeIso8601; h & turnTimerInfo; h & mapname; h & mapGenOptions; @@ -113,7 +117,7 @@ struct DLL_LINKAGE StartInfo } StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0), - mapfileChecksum(0), gameUuid(boost::uuids::to_string(boost::uuids::random_generator()())) + mapfileChecksum(0), gameUuid(boost::uuids::to_string(boost::uuids::random_generator()())), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(0))) { } diff --git a/lib/vstd/DateUtils.cpp b/lib/vstd/DateUtils.cpp index 41f2d59c7..f494f3e66 100644 --- a/lib/vstd/DateUtils.cpp +++ b/lib/vstd/DateUtils.cpp @@ -15,6 +15,15 @@ namespace vstd return s.str(); } + DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt) + { + std::tm tm = *std::localtime(&dt); + std::stringstream s; + s.imbue(std::locale("")); + s << std::put_time(&tm, "%Y%m%dT%H%M%S"); + return s.str(); + } + } VCMI_LIB_NAMESPACE_END