summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorSilent <zdanio95@gmail.com>2019-08-26 19:31:12 +0200
committerSilent <zdanio95@gmail.com>2019-08-28 19:52:35 +0200
commitff8f978eafb3a45959280a7a0c61bf11766dd040 (patch)
treef70098c3e6149f6d6c853415f47c83d03b6697f6 /Source/Core
parent71ff97cf1cf6ccaed34826a8f8d14cad0e292d7c (diff)
Core: Generate screenshot name with timestamps instead of only increasing numbers
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/Core/Core.cpp22
1 files 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 <variant>
#include <fmt/format.h>
+#include <fmt/time.h>
#ifdef _WIN32
#include <windows.h>
@@ -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();
+
+ 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));
- std::string name;
- for (int i = 1; File::Exists(name = fmt::format("{}-{}.png", path, i)); ++i)
+ // 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);