GSdx: Improve captured screenshots naming

Previously, when F8 was triggered multiple times in a single second, the latest captured image would replace the previous captured one as it has the same name as the previous image.

The following patch detects such cases and adds a number along with the filename when new image capture is requested under the same time as the previous capture.
This commit is contained in:
Akash 2017-01-14 19:25:19 +05:30 committed by Jonathan Li
parent 21612cafc1
commit 0d659a1b46
1 changed files with 19 additions and 5 deletions

View File

@ -556,13 +556,27 @@ bool GSRenderer::MakeSnapshot(const string& path)
{
if(m_snapshot.empty())
{
time_t t = time(NULL);
time_t cur_time = time(nullptr);
static time_t prev_snap;
// The variable 'n' is used for labelling the screenshots when multiple screenshots are taken in
// a single second, we'll start using this variable for naming when a second screenshot request is detected
// at the same time as the first one. Hence, we're initially setting this counter to 2 to imply that
// the captured image is the 2nd image captured at this specific time.
static int n = 2;
char local_time[16];
char buff[16];
if(strftime(buff, sizeof(buff), "%Y%m%d%H%M%S", localtime(&t)))
if (strftime(local_time, sizeof(local_time), "%Y%m%d%H%M%S", localtime(&cur_time)))
{
m_snapshot = format("%s_%s", path.c_str(), buff);
if (cur_time == prev_snap)
{
m_snapshot = format("%s_%s_(%d)", path.c_str(), local_time, n++);
}
else
{
n = 2;
m_snapshot = format("%s_%s", path.c_str(), local_time);
}
prev_snap = cur_time;
}
}