Skip to content

Commit 4fbcfac

Browse files
committedMar 24, 2015
Change filename of screenshots to something more human readable
1 parent 2641fcc commit 4fbcfac

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed
 

Diff for: ‎src/client.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -1710,13 +1710,22 @@ void Client::makeScreenshot(IrrlichtDevice *device)
17101710

17111711
if (image) {
17121712
raw_image->copyTo(image);
1713-
irr::c8 filename[256];
1714-
snprintf(filename, sizeof(filename),
1715-
(std::string("%s") + DIR_DELIM + "screenshot_%u.png").c_str(),
1716-
g_settings->get("screenshot_path").c_str(),
1717-
device->getTimer()->getRealTime());
1713+
1714+
std::string filename;
1715+
1716+
time_t t = time(NULL);
1717+
struct tm *tm = localtime(&t);
1718+
char timetstamp_c[16]; // YYYYMMDD_HHMMSS + '\0'
1719+
strftime(timetstamp_c, sizeof(timetstamp_c), "%Y%m%d_%H%M%S", tm);
1720+
1721+
filename = g_settings->get("screenshot_path")
1722+
+ DIR_DELIM
1723+
+ std::string("screenshot_")
1724+
+ std::string(timetstamp_c)
1725+
+ ".png";
1726+
17181727
std::ostringstream sstr;
1719-
if (driver->writeImageToFile(image, filename)) {
1728+
if (driver->writeImageToFile(image, filename.c_str())) {
17201729
sstr << "Saved screenshot to '" << filename << "'";
17211730
} else {
17221731
sstr << "Failed to save screenshot '" << filename << "'";

3 commit comments

Comments
 (3)

ShadowNinja commented on Mar 27, 2015

@ShadowNinja
Contributor

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- commented on Mar 28, 2015

@Zeno-
ContributorAuthor

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 commented on Mar 31, 2015

@ShadowNinja
Contributor

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.