From ff8f978eafb3a45959280a7a0c61bf11766dd040 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 26 Aug 2019 19:31:12 +0200 Subject: [PATCH 1/2] Core: Generate screenshot name with timestamps instead of only increasing numbers --- Source/Core/Core/Core.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index 5f35ddbb11..5908cc1347 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -13,6 +13,7 @@ #include #include +#include #ifdef _WIN32 #include @@ -677,15 +678,20 @@ static std::string GenerateScreenshotFolderPath() static std::string GenerateScreenshotName() { - std::string path = GenerateScreenshotFolderPath(); - // append gameId, path only contains the folder here. - path += SConfig::GetInstance().GetGameID(); + const std::string path_prefix = + GenerateScreenshotFolderPath() + SConfig::GetInstance().GetGameID(); - std::string name; - for (int i = 1; File::Exists(name = fmt::format("{}-{}.png", path, i)); ++i) + const std::time_t cur_time = std::time(nullptr); + const std::string base_name = + fmt::format("{}_{:%Y-%m-%d_%H-%M-%S}", path_prefix, *std::localtime(&cur_time)); + + // First try a filename without any suffixes, if already exists then append increasing numbers + std::string name = fmt::format("{}.png", base_name); + if (File::Exists(name)) { - // TODO? + for (u32 i = 1; File::Exists(name = fmt::format("{}_{}.png", base_name, i)); ++i) + ; } return name; @@ -709,8 +715,8 @@ void SaveScreenShot(std::string_view name, bool wait_for_completion) SetState(State::Paused); - const std::string path = fmt::format("{}{}.png", GenerateScreenshotFolderPath(), name); - g_renderer->SaveScreenshot(path, wait_for_completion); + g_renderer->SaveScreenshot(fmt::format("{}{}.png", GenerateScreenshotFolderPath(), name), + wait_for_completion); if (!bPaused) SetState(State::Running); From 37ef5a54c906ae697c76e2724f85f0beab4a3435 Mon Sep 17 00:00:00 2001 From: Silent Date: Mon, 26 Aug 2019 19:31:29 +0200 Subject: [PATCH 2/2] Core: Use move semantics for Renderer::SaveScreenshot --- Source/Core/VideoCommon/RenderBase.cpp | 4 ++-- Source/Core/VideoCommon/RenderBase.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Core/VideoCommon/RenderBase.cpp b/Source/Core/VideoCommon/RenderBase.cpp index 972b0e15fc..31d3192933 100644 --- a/Source/Core/VideoCommon/RenderBase.cpp +++ b/Source/Core/VideoCommon/RenderBase.cpp @@ -369,12 +369,12 @@ Renderer::ConvertStereoRectangle(const MathUtil::Rectangle& rc) const return std::make_tuple(left_rc, right_rc); } -void Renderer::SaveScreenshot(const std::string& filename, bool wait_for_completion) +void Renderer::SaveScreenshot(std::string filename, bool wait_for_completion) { // We must not hold the lock while waiting for the screenshot to complete. { std::lock_guard lk(m_screenshot_lock); - m_screenshot_name = filename; + m_screenshot_name = std::move(filename); m_screenshot_request.Set(); } diff --git a/Source/Core/VideoCommon/RenderBase.h b/Source/Core/VideoCommon/RenderBase.h index 6ff7f410dd..16ce52aaa4 100644 --- a/Source/Core/VideoCommon/RenderBase.h +++ b/Source/Core/VideoCommon/RenderBase.h @@ -196,7 +196,7 @@ public: float EFBToScaledYf(float y) const; // Random utilities - void SaveScreenshot(const std::string& filename, bool wait_for_completion); + void SaveScreenshot(std::string filename, bool wait_for_completion); void DrawDebugText(); // ImGui initialization depends on being able to create textures and pipelines, so do it last.