瀏覽代碼

starttime in foldername

Michael 2 年之前
父節點
當前提交
d2bbe0f35a
共有 4 個文件被更改,包括 20 次插入6 次删除
  1. 5 5
      client/CPlayerInterface.cpp
  2. 1 0
      include/vstd/DateUtils.h
  3. 5 1
      lib/StartInfo.h
  4. 9 0
      lib/vstd/DateUtils.cpp

+ 5 - 5
client/CPlayerInterface.cpp

@@ -169,7 +169,7 @@ void CPlayerInterface::initGameInterface(std::shared_ptr<Environment> 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<CInfoWindow>())
 		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<int>(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);
 		}
 	}
 }

+ 1 - 0
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);
 
 }
 

+ 5 - 1
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)))
 	{
 
 	}

+ 9 - 0
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