From ea243051edbb7a7882b37d967b4f87149e1f9ff8 Mon Sep 17 00:00:00 2001 From: BearOso Date: Wed, 11 Sep 2024 19:22:45 -0500 Subject: [PATCH] Save screenshot files with date for easier sorting. --- screenshot.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/screenshot.cpp b/screenshot.cpp index 1572edf5..a76b8a0c 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -7,6 +7,11 @@ #ifdef HAVE_LIBPNG #include #endif + +#include +#include +#include + #include "snes9x.h" #include "memmap.h" #include "display.h" @@ -24,7 +29,27 @@ bool8 S9xDoScreenshot (int width, int height) png_color_8 sig_bit; int imgwidth, imgheight; - std::string fname = S9xGetFilenameInc(".png", SCREENSHOT_DIR); + std::tm current_time; + std::time_t current_timet = time(nullptr); + localtime_r(¤t_timet, ¤t_time); + + auto screenshot_dir = S9xGetDirectory(SCREENSHOT_DIR); + std::stringstream ss; + ss << screenshot_dir + << S9xBasenameNoExt(Memory.ROMFilename) << "-" + << std::put_time(¤t_time, "%Y-%m-%d-%H:%M:%S"); + std::string fname = ss.str() + ".png"; + + for (int i = 0; i < 1000; i++) + { + FILE *fp = fopen(fname.c_str(), "r"); + + if (!fp) + break; + + fclose(fp); + fname = ss.str() + "-" + std::to_string(i) + ".png"; + } fp = fopen(fname.c_str(), "wb"); if (!fp)