Skip to content
Permalink
Browse files

Change filename of screenshots to something more human readable

  • Loading branch information
Zeno- committed Mar 24, 2015
1 parent 2641fcc commit 4fbcfac6cf5f7404df62e94133388c601386d687
Showing with 15 additions and 6 deletions.
  1. +15 −6 src/client.cpp
@@ -1710,13 +1710,22 @@ void Client::makeScreenshot(IrrlichtDevice *device)

if (image) {
raw_image->copyTo(image);
irr::c8 filename[256];
snprintf(filename, sizeof(filename),
(std::string("%s") + DIR_DELIM + "screenshot_%u.png").c_str(),
g_settings->get("screenshot_path").c_str(),
device->getTimer()->getRealTime());

std::string filename;

time_t t = time(NULL);
struct tm *tm = localtime(&t);
char timetstamp_c[16]; // YYYYMMDD_HHMMSS + '\0'
strftime(timetstamp_c, sizeof(timetstamp_c), "%Y%m%d_%H%M%S", tm);

filename = g_settings->get("screenshot_path")
+ DIR_DELIM
+ std::string("screenshot_")
+ std::string(timetstamp_c)
+ ".png";

std::ostringstream sstr;
if (driver->writeImageToFile(image, filename)) {
if (driver->writeImageToFile(image, filename.c_str())) {
sstr << "Saved screenshot to '" << filename << "'";
} else {
sstr << "Failed to save screenshot '" << filename << "'";

3 comments on commit 4fbcfac

@ShadowNinja

This comment has been minimized.

Copy link
Member

@ShadowNinja ShadowNinja replied Mar 27, 2015

This should include miliseconds or a serial value (imagine trying to grab a bunch of shots of TNT going off hoping for a good one).

I'd also prefer if this used ISO 8601 format ("%FT%T" without miliseconds).

@Zeno-

This comment has been minimized.

Copy link
Contributor Author

@Zeno- Zeno- replied Mar 28, 2015

Well, the T is easy enough. I don't like the '-' in filenames but that should not stop them being used (we discussed this on IRC briefly) so %FT%F is ok with me. The ms or serial is the more problematic issue. Do you have any ideas? I suppose getRealTime() can be appended as well (or some division of... maybe %1000 for a 'serial number' in the range 0-999 (I doubt many computers will be able to take 999 screenshots a second)?

@ShadowNinja

This comment has been minimized.

Copy link
Member

@ShadowNinja ShadowNinja replied Mar 31, 2015

By "serial" I meant screanshot_foo.png, screenshot_foo-1.png, etc --- like the player saving code does. Dashes should not be an issue at all. In ISO 8601 format the miliseconds are appended seperated by a dot. It could be a colon instead if dumb file managers cause issues though. Milisecond resolution should be plenty, although something inside me prefers the serial version because you probably could take two screenshots in a millisecond and it should still work.

Please sign in to comment.