Use fmt::localtime instead of thread-unsafe std::localtime

fmt::localtime is also less awkward to use compared to std::localtime.
This commit is contained in:
Léo Lam 2021-10-15 22:49:13 +02:00
parent 2187f11b08
commit fd7df2ccae
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
4 changed files with 4 additions and 4 deletions

View File

@ -210,7 +210,7 @@ void StartAudioDump()
std::string path_prefix = File::GetUserPath(D_DUMPAUDIO_IDX) + SConfig::GetInstance().GetGameID(); std::string path_prefix = File::GetUserPath(D_DUMPAUDIO_IDX) + SConfig::GetInstance().GetGameID();
std::string base_name = std::string base_name =
fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, *std::localtime(&start_time)); fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, fmt::localtime(start_time));
const std::string audio_file_name_dtk = fmt::format("{}_dtkdump.wav", base_name); const std::string audio_file_name_dtk = fmt::format("{}_dtkdump.wav", base_name);
const std::string audio_file_name_dsp = fmt::format("{}_dspdump.wav", base_name); const std::string audio_file_name_dsp = fmt::format("{}_dspdump.wav", base_name);

View File

@ -140,6 +140,6 @@ std::string SettingsHandler::GenerateSerialNumber()
// Must be 9 characters at most; otherwise the serial number will be rejected by SDK libraries, // 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. // 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. // 3 for %j, 2 for %H, 2 for %M, 2 for %S.
return fmt::format("{:%j%H%M%S}", *std::localtime(&t)); return fmt::format("{:%j%H%M%S}", fmt::localtime(t));
} }
} // namespace Common } // namespace Common

View File

@ -739,7 +739,7 @@ static std::string GenerateScreenshotName()
const std::time_t cur_time = std::time(nullptr); const std::time_t cur_time = std::time(nullptr);
const std::string base_name = const std::string base_name =
fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, *std::localtime(&cur_time)); fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, fmt::localtime(cur_time));
// First try a filename without any suffixes, if already exists then append increasing numbers // First try a filename without any suffixes, if already exists then append increasing numbers
std::string name = fmt::format("{}.png", base_name); std::string name = fmt::format("{}.png", base_name);

View File

@ -86,7 +86,7 @@ std::string GetDumpPath(const std::string& extension, std::time_t time, u32 inde
File::GetUserPath(D_DUMPFRAMES_IDX) + SConfig::GetInstance().GetGameID(); File::GetUserPath(D_DUMPFRAMES_IDX) + SConfig::GetInstance().GetGameID();
const std::string base_name = const std::string base_name =
fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}_{}", path_prefix, *std::localtime(&time), index); fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}_{}", path_prefix, fmt::localtime(time), index);
const std::string path = fmt::format("{}.{}", base_name, extension); const std::string path = fmt::format("{}.{}", base_name, extension);