Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #8333 from CookiePLMonster/screenshot-timestamp
Core: Generate screenshot name with timestamps
  • Loading branch information
JMC47 committed Sep 30, 2019
2 parents 06ab51b + 37ef5a5 commit bec433c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
22 changes: 14 additions & 8 deletions Source/Core/Core/Core.cpp
Expand Up @@ -13,6 +13,7 @@
#include <variant>

#include <fmt/format.h>
#include <fmt/time.h>

#ifdef _WIN32
#include <windows.h>
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoCommon/RenderBase.cpp
Expand Up @@ -369,12 +369,12 @@ Renderer::ConvertStereoRectangle(const MathUtil::Rectangle<int>& 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<std::mutex> lk(m_screenshot_lock);
m_screenshot_name = filename;
m_screenshot_name = std::move(filename);
m_screenshot_request.Set();
}

Expand Down
2 changes: 1 addition & 1 deletion Source/Core/VideoCommon/RenderBase.h
Expand Up @@ -196,7 +196,7 @@ class Renderer
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.
Expand Down

0 comments on commit bec433c

Please sign in to comment.