Browse Source

revised for date/time stamps instead.

pull/4561/head
DakkJaniels 4 years ago committed by Anders Jenbo
parent
commit
3f9b385a1d
  1. 20
      Source/capture.cpp

20
Source/capture.cpp

@ -5,6 +5,9 @@
*/
#include <cstdint>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <fmt/chrono.h>
#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<uint32_t>::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);
}
/**

Loading…
Cancel
Save