From 3f9b385a1d64d150a11dd1a52d0d3e81341ef189 Mon Sep 17 00:00:00 2001 From: DakkJaniels <6080734+DakkJaniels@users.noreply.github.com> Date: Mon, 9 May 2022 20:34:28 -0400 Subject: [PATCH] revised for date/time stamps instead. --- Source/capture.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Source/capture.cpp b/Source/capture.cpp index 7d41033cb..a95fd22e9 100644 --- a/Source/capture.cpp +++ b/Source/capture.cpp @@ -5,6 +5,9 @@ */ #include #include +#include +#include +#include #include "DiabloUI/diabloui.h" #include "dx.h" @@ -130,15 +133,16 @@ bool CapturePix(const Surface &buf, std::ofstream *out) std::ofstream CaptureFile(std::string *dstPath) { - char filename[sizeof("screen0000000000.PCX") / sizeof(char)]; - for (uint32_t i = 0; i <= std::numeric_limits::max(); ++i) { - snprintf(filename, sizeof(filename) / sizeof(char), "screen%d.PCX", i); - *dstPath = paths::PrefPath() + filename; - if (!FileExists(dstPath->c_str())) { - return std::ofstream(*dstPath, std::ios::binary | std::ios::trunc); - } + std::time_t tt = std::time(nullptr); + std::tm *tm = std::localtime(&tt); + std::string filename = fmt::format("Screenshot from {:%Y-%m-%d %H-%M-%S}", *tm); + *dstPath = paths::PrefPath() + filename + ".PCX"; + int i = 0; + while (FileExists(dstPath->c_str())) { + i++; + *dstPath = paths::PrefPath() + filename + "-" + std::to_string(i) + ".PCX"; } - return {}; + return std::ofstream(*dstPath, std::ios::binary | std::ios::trunc); } /**