@@ -1704,25 +1704,42 @@ void Client::makeScreenshot(IrrlichtDevice *device)
1704
1704
{
1705
1705
irr::video::IVideoDriver *driver = device->getVideoDriver ();
1706
1706
irr::video::IImage* const raw_image = driver->createScreenShot ();
1707
- if (raw_image) {
1708
- irr::video::IImage* const image = driver->createImage (video::ECF_R8G8B8,
1709
- raw_image->getDimension ());
1710
1707
1711
- if (image) {
1712
- raw_image-> copyTo (image) ;
1708
+ if (!raw_image)
1709
+ return ;
1713
1710
1714
- std::string filename;
1711
+ time_t t = time (NULL );
1712
+ struct tm *tm = localtime (&t);
1715
1713
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 );
1714
+ char timetstamp_c[64 ];
1715
+ strftime (timetstamp_c, sizeof (timetstamp_c), " %FT%T" , tm );
1720
1716
1721
- filename = g_settings->get (" screenshot_path" )
1722
- + DIR_DELIM
1723
- + std::string (" screenshot_" )
1724
- + std::string (timetstamp_c)
1725
- + " .png" ;
1717
+ std::string filename_base = g_settings->get (" screenshot_path" )
1718
+ + DIR_DELIM
1719
+ + std::string (" screenshot_" )
1720
+ + std::string (timetstamp_c);
1721
+ std::string filename_ext = " .png" ;
1722
+ std::string filename;
1723
+
1724
+ // Try to find a unique filename
1725
+ unsigned serial = 0 ;
1726
+
1727
+ while (serial < SCREENSHOT_MAX_SERIAL_TRIES) {
1728
+ filename = filename_base + (serial > 0 ? (" -" + itos (serial)) : " " ) + filename_ext;
1729
+ std::ifstream tmp (filename.c_str ());
1730
+ if (!tmp.good ())
1731
+ break ; // File did not apparently exist, we'll go with it
1732
+ serial++;
1733
+ }
1734
+
1735
+ if (serial == SCREENSHOT_MAX_SERIAL_TRIES) {
1736
+ infostream << " Could not find suitable filename for screenshot" << std::endl;
1737
+ } else {
1738
+ irr::video::IImage* const image =
1739
+ driver->createImage (video::ECF_R8G8B8, raw_image->getDimension ());
1740
+
1741
+ if (image) {
1742
+ raw_image->copyTo (image);
1726
1743
1727
1744
std::ostringstream sstr;
1728
1745
if (driver->writeImageToFile (image, filename.c_str ())) {
@@ -1734,8 +1751,9 @@ void Client::makeScreenshot(IrrlichtDevice *device)
1734
1751
infostream << sstr.str () << std::endl;
1735
1752
image->drop ();
1736
1753
}
1737
- raw_image->drop ();
1738
1754
}
1755
+
1756
+ raw_image->drop ();
1739
1757
}
1740
1758
1741
1759
// IGameDef interface
0 commit comments