1
0
Fork 0

Change screenshot filename to have date time

Format fgfs-YYYYMMDDHHMMSS[-#] where the # is for the rare case when there are multiple screenshots per second.

The change makes the filenames sortable based on date and slightly improves run time performance when there are a lot of screenshots in a particular directory
This commit is contained in:
Richard Harrison 2019-01-20 23:24:38 +01:00
parent 88f43a33a3
commit 58314f359a

View file

@ -441,16 +441,20 @@ namespace
SGPath nextScreenshotPath(const SGPath& screenshotDir)
{
char filename[32];
static int count = 1;
while (count < 0x7fff) {
if (count < 1000) {
// zero-pad for backwards compatability
snprintf(filename, 32, "fgfs-screen-%03d.png", count++);
} else {
snprintf(filename, 32, "fgfs-screen-%d.png", count++);
}
char filename[60];
int count = 0;
while (count < 100) { // 100 per second should be more than enough.
char time_str[20];
time_t calendar_time = time(NULL);
struct tm *tmUTC;
tmUTC = gmtime(&calendar_time);
strftime(time_str, sizeof(time_str), "%Y%m%d%H%M%S", tmUTC);
if (count)
snprintf(filename, 32, "fgfs-%s-%d.png", time_str, count++);
else
snprintf(filename, 32, "fgfs-%s.png", time_str);
SGPath p = screenshotDir / filename;
if (!p.exists()) {
return p;