summaryrefslogtreecommitdiff
path: root/Source/Core/Common/SettingsHandler.cpp
diff options
context:
space:
mode:
authorLéo Lam <leo@innovatetechnologi.es>2017-08-08 23:23:46 +0800
committerLéo Lam <leo@innovatetechnologi.es>2017-08-08 23:25:40 +0800
commit58b7350562aceb7f76b8fbf490dfb88ee572b4d8 (patch)
treefc879c62bc4068b66e00882dd506b36ac720f3c4 /Source/Core/Common/SettingsHandler.cpp
parenta25f7b9b4cba292ae6230cafe2497f73086e161b (diff)
SettingsHandler: Fix generated serial numbers
Must be 9 characters at most; otherwise the serial number will be rejected by SDK libraries, as there is a check to ensure the string length is strictly lower than 10.
Diffstat (limited to 'Source/Core/Common/SettingsHandler.cpp')
-rw-r--r--Source/Core/Common/SettingsHandler.cpp22
1 files changed, 10 insertions, 12 deletions
diff --git a/Source/Core/Common/SettingsHandler.cpp b/Source/Core/Common/SettingsHandler.cpp
index 1629a017cf..8a0240939b 100644
--- a/Source/Core/Common/SettingsHandler.cpp
+++ b/Source/Core/Common/SettingsHandler.cpp
@@ -8,6 +8,8 @@
#include <cstdio>
#include <cstring>
#include <ctime>
+#include <iomanip>
+#include <sstream>
#include <string>
#ifdef _WIN32
@@ -134,16 +136,12 @@ void SettingsHandler::WriteByte(u8 b)
std::string SettingsHandler::GenerateSerialNumber()
{
- time_t rawtime;
- tm* timeinfo;
- char buffer[12];
- char serialNumber[12];
-
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- strftime(buffer, 11, "%j%H%M%S", timeinfo);
-
- snprintf(serialNumber, 11, "%s%i", buffer, (Common::Timer::GetTimeMs() >> 1) & 0xF);
- serialNumber[10] = 0;
- return std::string(serialNumber);
+ const std::time_t t = std::time(nullptr);
+
+ // Must be 9 characters at most; otherwise the serial number will be rejected by SDK libraries,
+ // as there is a check to ensure the string length is strictly lower than 10.
+ // 3 for %j, 2 for %H, 2 for %M, 2 for %S.
+ std::stringstream stream;
+ stream << std::put_time(std::localtime(&t), "%j%H%M%S");
+ return stream.str();
}