Skip to content

Commit

Permalink
Change filename of screenshots to something more human readable
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeno- committed Mar 24, 2015
1 parent 2641fcc commit 4fbcfac
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/client.cpp
Expand Up @@ -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 << "'";
Expand Down

3 comments on commit 4fbcfac

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-
Copy link
Contributor Author

@Zeno- Zeno- commented on 4fbcfac Mar 28, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.