1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-08 23:36:33 +02:00

starttime in foldername

This commit is contained in:
Michael 2023-08-23 01:47:55 +02:00 committed by GitHub
parent 538acfe3c0
commit d2bbe0f35a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 6 deletions

View File

@ -201,7 +201,7 @@ void CPlayerInterface::playerStartsTurn(PlayerColor player)
void CPlayerInterface::performAutosave() 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<int>(settings["general"]["saveFrequency"].Integer()); int frequency = static_cast<int>(settings["general"]["saveFrequency"].Integer());
if(frequency > 0 && cb->getDate() % frequency == 0) if(frequency > 0 && cb->getDate() % frequency == 0)
@ -214,7 +214,7 @@ void CPlayerInterface::performAutosave()
prefix = settings["general"]["savePrefix"].String(); prefix = settings["general"]["savePrefix"].String();
if(prefix.empty()) 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::WEEK))
+ std::to_string(cb->getDate(Date::DAY_OF_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);
} }
} }
} }

View File

@ -6,6 +6,7 @@ namespace vstd
{ {
DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt); DLL_LINKAGE std::string getFormattedDateTime(std::time_t dt);
DLL_LINKAGE std::string getDateTimeISO8601Basic(std::time_t dt);
} }

View File

@ -9,6 +9,8 @@
*/ */
#pragma once #pragma once
#include "vstd/DateUtils.h"
#include "GameConstants.h" #include "GameConstants.h"
#include "TurnTimerInfo.h" #include "TurnTimerInfo.h"
#include "campaign/CampaignConstants.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 seedPostInit; //so we know that game is correctly synced at the start; 0 if not known yet
ui32 mapfileChecksum; //0 if not relevant ui32 mapfileChecksum; //0 if not relevant
std::string gameUuid; std::string gameUuid;
std::string startTimeIso8601;
TurnTimerInfo turnTimerInfo; TurnTimerInfo turnTimerInfo;
std::string mapname; // empty for random map, otherwise name of the map or savegame std::string mapname; // empty for random map, otherwise name of the map or savegame
bool createRandomMap() const { return mapGenOptions != nullptr; } bool createRandomMap() const { return mapGenOptions != nullptr; }
@ -106,6 +109,7 @@ struct DLL_LINKAGE StartInfo
h & seedPostInit; h & seedPostInit;
h & mapfileChecksum; h & mapfileChecksum;
h & gameUuid; h & gameUuid;
h & startTimeIso8601;
h & turnTimerInfo; h & turnTimerInfo;
h & mapname; h & mapname;
h & mapGenOptions; h & mapGenOptions;
@ -113,7 +117,7 @@ struct DLL_LINKAGE StartInfo
} }
StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0), 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)))
{ {
} }

View File

@ -15,6 +15,15 @@ namespace vstd
return s.str(); 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 VCMI_LIB_NAMESPACE_END