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); } /**