Merge pull request #5905 from leoetlino/serial-number

SettingsHandler: Fix generated serial numbers
This commit is contained in:
Pierre Bourdon 2017-08-08 18:07:57 +02:00 committed by GitHub
commit 8b5ae7b0c7
1 changed files with 9 additions and 11 deletions

View File

@ -8,6 +8,8 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <iomanip>
#include <sstream>
#include <string> #include <string>
#ifdef _WIN32 #ifdef _WIN32
@ -134,16 +136,12 @@ void SettingsHandler::WriteByte(u8 b)
std::string SettingsHandler::GenerateSerialNumber() std::string SettingsHandler::GenerateSerialNumber()
{ {
time_t rawtime; const std::time_t t = std::time(nullptr);
tm* timeinfo;
char buffer[12];
char serialNumber[12];
time(&rawtime); // Must be 9 characters at most; otherwise the serial number will be rejected by SDK libraries,
timeinfo = localtime(&rawtime); // as there is a check to ensure the string length is strictly lower than 10.
strftime(buffer, 11, "%j%H%M%S", timeinfo); // 3 for %j, 2 for %H, 2 for %M, 2 for %S.
std::stringstream stream;
snprintf(serialNumber, 11, "%s%i", buffer, (Common::Timer::GetTimeMs() >> 1) & 0xF); stream << std::put_time(std::localtime(&t), "%j%H%M%S");
serialNumber[10] = 0; return stream.str();
return std::string(serialNumber);
} }