Selaa lähdekoodia

avoid destroing utf-8; no extra Autosave text

Michael 2 vuotta sitten
vanhempi
sitoutus
9f68a0bf49
2 muutettua tiedostoa jossa 8 lisäystä ja 3 poistoa
  1. 1 0
      Global.h
  2. 7 3
      client/CPlayerInterface.cpp

+ 1 - 0
Global.h

@@ -108,6 +108,7 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
 #include <cassert>
 #include <climits>
 #include <cmath>
+#include <codecvt>
 #include <cstdlib>
 #include <cstdio>
 #include <fstream>

+ 7 - 3
client/CPlayerInterface.cpp

@@ -212,7 +212,11 @@ void CPlayerInterface::performAutosave()
 			prefix = settings["general"]["savePrefix"].String();
 			if(prefix.empty())
 			{
-				std::string name = cb->getMapHeader()->name.substr(0, 15);
+				std::string name = cb->getMapHeader()->name;
+				std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> conv;
+				int txtlen = conv.from_bytes(name).size(); 
+
+				TextOperations::trimRightUnicode(name, std::max(0, txtlen - 15));
 				std::string forbiddenChars("\\/:?\"<>| ");
 				std::replace_if(name.begin(), name.end(), [&](char c) { return std::string::npos != forbiddenChars.find(c); }, '_' );
 
@@ -225,7 +229,7 @@ void CPlayerInterface::performAutosave()
 		int autosaveCountLimit = settings["general"]["autosaveCountLimit"].Integer();
 		if(autosaveCountLimit > 0)
 		{
-			cb->save("Saves/Autosave/" + prefix + "Autosave_" + std::to_string(autosaveCount));
+			cb->save("Saves/Autosave/" + prefix + std::to_string(autosaveCount));
 			autosaveCount %= autosaveCountLimit;
 		}
 		else
@@ -234,7 +238,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 + stringifiedDate);
 		}
 	}
 }