mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-06-25 03:21:36 +02:00
Merge pull request #13727 from JoshuaVandaele/fmt-11.2.0-localtime-deprec
fmt: Replace deprecated `fmt::localtime` usage with `Common::LocalTime`
This commit is contained in:
@ -16,6 +16,7 @@
|
|||||||
#include "AudioCommon/WASAPIStream.h"
|
#include "AudioCommon/WASAPIStream.h"
|
||||||
#include "Common/FileUtil.h"
|
#include "Common/FileUtil.h"
|
||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
|
#include "Common/TimeUtil.h"
|
||||||
#include "Core/Config/MainSettings.h"
|
#include "Core/Config/MainSettings.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
#include "Core/System.h"
|
#include "Core/System.h"
|
||||||
@ -219,8 +220,11 @@ void StartAudioDump(Core::System& system)
|
|||||||
|
|
||||||
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 =
|
const auto local_time = Common::LocalTime(start_time);
|
||||||
fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, fmt::localtime(start_time));
|
if (!local_time)
|
||||||
|
return;
|
||||||
|
|
||||||
|
std::string base_name = fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, *local_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);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#include "Common/Logging/Log.h"
|
#include "Common/Logging/Log.h"
|
||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
|
#include "Common/TimeUtil.h"
|
||||||
|
|
||||||
#include "Core/Config/MainSettings.h"
|
#include "Core/Config/MainSettings.h"
|
||||||
|
|
||||||
@ -95,12 +96,7 @@ int SDCardDiskIOCtl(File::IOFile* image, u8 pdrv, u8 cmd, void* buff)
|
|||||||
u32 GetSystemTimeFAT()
|
u32 GetSystemTimeFAT()
|
||||||
{
|
{
|
||||||
const std::time_t time = std::time(nullptr);
|
const std::time_t time = std::time(nullptr);
|
||||||
std::tm tm;
|
std::tm tm = *Common::LocalTime(time);
|
||||||
#ifdef _WIN32
|
|
||||||
localtime_s(&tm, &time);
|
|
||||||
#else
|
|
||||||
localtime_r(&time, &tm);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
DWORD fattime = 0;
|
DWORD fattime = 0;
|
||||||
fattime |= (tm.tm_year - 80) << 25;
|
fattime |= (tm.tm_year - 80) << 25;
|
||||||
|
@ -122,7 +122,6 @@ std::string SettingsWriter::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.
|
return fmt::format("{:09}", t % 1000000000);
|
||||||
return fmt::format("{:%j%H%M%S}", fmt::localtime(t));
|
|
||||||
}
|
}
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
@ -2,23 +2,25 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "Common/TimeUtil.h"
|
#include "Common/TimeUtil.h"
|
||||||
|
#include "Common/Logging/Log.h"
|
||||||
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
std::optional<std::tm> Localtime(std::time_t time)
|
std::optional<std::tm> LocalTime(std::time_t time)
|
||||||
{
|
{
|
||||||
std::tm local_time;
|
std::tm local_time;
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
if (localtime_s(&local_time, &time) != 0)
|
if (localtime_s(&local_time, &time) != 0)
|
||||||
return std::nullopt;
|
|
||||||
#else
|
#else
|
||||||
std::tm* result = localtime_r(&time, &local_time);
|
if (localtime_r(&time, &local_time) == NULL)
|
||||||
if (result != &local_time)
|
|
||||||
return std::nullopt;
|
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
ERROR_LOG_FMT(COMMON, "Failed to convert time to local time: {}", std::strerror(errno));
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
return local_time;
|
return local_time;
|
||||||
}
|
}
|
||||||
} // Namespace Common
|
} // Namespace Common
|
||||||
|
@ -9,5 +9,5 @@
|
|||||||
namespace Common
|
namespace Common
|
||||||
{
|
{
|
||||||
// Threadsafe and error-checking variant of std::localtime()
|
// Threadsafe and error-checking variant of std::localtime()
|
||||||
std::optional<std::tm> Localtime(std::time_t time);
|
std::optional<std::tm> LocalTime(std::time_t time);
|
||||||
} // Namespace Common
|
} // Namespace Common
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
@ -34,6 +35,7 @@
|
|||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "Common/Thread.h"
|
#include "Common/Thread.h"
|
||||||
|
#include "Common/TimeUtil.h"
|
||||||
#include "Common/Version.h"
|
#include "Common/Version.h"
|
||||||
|
|
||||||
#include "Core/AchievementManager.h"
|
#include "Core/AchievementManager.h"
|
||||||
@ -733,15 +735,17 @@ static std::string GenerateScreenshotFolderPath()
|
|||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string GenerateScreenshotName()
|
static std::optional<std::string> GenerateScreenshotName()
|
||||||
{
|
{
|
||||||
// append gameId, path only contains the folder here.
|
// append gameId, path only contains the folder here.
|
||||||
const std::string path_prefix =
|
const std::string path_prefix =
|
||||||
GenerateScreenshotFolderPath() + SConfig::GetInstance().GetGameID();
|
GenerateScreenshotFolderPath() + SConfig::GetInstance().GetGameID();
|
||||||
|
|
||||||
const std::time_t cur_time = std::time(nullptr);
|
const std::time_t cur_time = std::time(nullptr);
|
||||||
const std::string base_name =
|
const auto local_time = Common::LocalTime(cur_time);
|
||||||
fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, fmt::localtime(cur_time));
|
if (!local_time)
|
||||||
|
return std::nullopt;
|
||||||
|
const std::string base_name = fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, *local_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);
|
||||||
@ -757,7 +761,9 @@ static std::string GenerateScreenshotName()
|
|||||||
void SaveScreenShot()
|
void SaveScreenShot()
|
||||||
{
|
{
|
||||||
const Core::CPUThreadGuard guard(Core::System::GetInstance());
|
const Core::CPUThreadGuard guard(Core::System::GetInstance());
|
||||||
g_frame_dumper->SaveScreenshot(GenerateScreenshotName());
|
std::optional<std::string> name = GenerateScreenshotName();
|
||||||
|
if (name)
|
||||||
|
g_frame_dumper->SaveScreenshot(*name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveScreenShot(std::string_view name)
|
void SaveScreenShot(std::string_view name)
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "Common/Network.h"
|
#include "Common/Network.h"
|
||||||
#include "Common/PcapFile.h"
|
#include "Common/PcapFile.h"
|
||||||
#include "Common/ScopeGuard.h"
|
#include "Common/ScopeGuard.h"
|
||||||
|
#include "Common/TimeUtil.h"
|
||||||
#include "Core/Config/MainSettings.h"
|
#include "Core/Config/MainSettings.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ PCAPSSLCaptureLogger::PCAPSSLCaptureLogger()
|
|||||||
{
|
{
|
||||||
const std::string filepath =
|
const std::string filepath =
|
||||||
fmt::format("{}{} {:%Y-%m-%d %Hh%Mm%Ss}.pcap", File::GetUserPath(D_DUMPSSL_IDX),
|
fmt::format("{}{} {:%Y-%m-%d %Hh%Mm%Ss}.pcap", File::GetUserPath(D_DUMPSSL_IDX),
|
||||||
SConfig::GetInstance().GetGameID(), fmt::localtime(std::time(nullptr)));
|
SConfig::GetInstance().GetGameID(), *Common::LocalTime(std::time(nullptr)));
|
||||||
m_file = std::make_unique<Common::PCAP>(
|
m_file = std::make_unique<Common::PCAP>(
|
||||||
new File::IOFile(filepath, "wb", File::SharedAccess::Read), Common::PCAP::LinkType::Ethernet);
|
new File::IOFile(filepath, "wb", File::SharedAccess::Read), Common::PCAP::LinkType::Ethernet);
|
||||||
}
|
}
|
||||||
|
@ -281,7 +281,7 @@ static std::string SystemTimeAsDoubleToString(double time)
|
|||||||
{
|
{
|
||||||
// revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again
|
// revert adjustments from GetSystemTimeAsDouble() to get a normal Unix timestamp again
|
||||||
const time_t seconds = static_cast<time_t>(time) + DOUBLE_TIME_OFFSET;
|
const time_t seconds = static_cast<time_t>(time) + DOUBLE_TIME_OFFSET;
|
||||||
const auto local_time = Common::Localtime(seconds);
|
const auto local_time = Common::LocalTime(seconds);
|
||||||
if (!local_time)
|
if (!local_time)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#include "VideoCommon/FrameDumpFFMpeg.h"
|
#include "VideoCommon/FrameDumpFFMpeg.h"
|
||||||
|
#include "Common/TimeUtil.h"
|
||||||
|
|
||||||
#if defined(__FreeBSD__)
|
#if defined(__FreeBSD__)
|
||||||
#define __STDC_CONSTANT_MACROS 1
|
#define __STDC_CONSTANT_MACROS 1
|
||||||
@ -124,11 +125,15 @@ std::string GetDumpPath(const std::string& extension, std::time_t time, u32 inde
|
|||||||
if (!dump_path.empty())
|
if (!dump_path.empty())
|
||||||
return dump_path;
|
return dump_path;
|
||||||
|
|
||||||
|
const auto local_time = Common::LocalTime(time);
|
||||||
|
if (!local_time)
|
||||||
|
return "";
|
||||||
|
|
||||||
const std::string path_prefix =
|
const std::string path_prefix =
|
||||||
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, fmt::localtime(time), index);
|
fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}_{}", path_prefix, *local_time, index);
|
||||||
|
|
||||||
const std::string path = fmt::format("{}.{}", base_name, extension);
|
const std::string path = fmt::format("{}.{}", base_name, extension);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user