clean up screenshot saving
use a unique name for every screenshot in case image files are moved off the memory card
This commit is contained in:
@@ -1253,12 +1253,8 @@ void Profile::LoadScreenshotDataFromNode( const XNode* pNode )
|
||||
if( !(*screenshot)->GetChildValue("MD5",ss.sMD5) )
|
||||
WARN_AND_CONTINUE;
|
||||
|
||||
XNode *pHighScoreNode = (*screenshot)->GetChild("HighScore");
|
||||
if( pHighScoreNode == NULL )
|
||||
if( !(*screenshot)->GetChildValue("Time",(int&)ss.time) ) // time_t is a signed long on Win32. Is this ok on other platforms?
|
||||
WARN_AND_CONTINUE;
|
||||
|
||||
HighScore &hs = ss.highScore;
|
||||
hs.LoadFromNode( pHighScoreNode );
|
||||
|
||||
m_vScreenshots.push_back( ss );
|
||||
}
|
||||
@@ -1282,7 +1278,7 @@ XNode* Profile::SaveScreenshotDataCreateNode() const
|
||||
|
||||
pScreenshotNode->AppendChild( "FileName", ss.sFileName );
|
||||
pScreenshotNode->AppendChild( "MD5", ss.sMD5);
|
||||
pScreenshotNode->AppendChild( ss.highScore.CreateNode() );
|
||||
pScreenshotNode->AppendChild( "Time", ss.time);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
|
||||
@@ -147,10 +147,11 @@ public:
|
||||
{
|
||||
CString sFileName; // no directory part - just the file name
|
||||
CString sMD5; // MD5 hash of the screenshot file
|
||||
HighScore highScore; // high score that the screenshot is taken of
|
||||
time_t time; // return value of time() when screenshot was taken
|
||||
};
|
||||
vector<Screenshot> m_vScreenshots;
|
||||
void AddScreenshot( Screenshot screenshot );
|
||||
int GetNextScreenshotIndex() { return m_vScreenshots.size(); }
|
||||
|
||||
|
||||
//
|
||||
|
||||
@@ -828,15 +828,26 @@ void PrintBookkeeping( RageFile &f, const Profile *pProfile, CString sTitle, vec
|
||||
|
||||
void PrintScreenshot( RageFile &f, const Profile::Screenshot &ss )
|
||||
{
|
||||
CString sHtmlPath = "Screenshots/"+ss.sFileName;
|
||||
CString sImgTag = ssprintf("<a href='%s' target='_new'><img class='screenshot' src='%s' width='160' height='120'></a>", sHtmlPath.c_str(), sHtmlPath.c_str() );
|
||||
CString sDetails = "<p>This is a screenshot</p>\n<p>We have no idea where it came from</p>";
|
||||
CString sImagePath = SCREENSHOTS_SUBDIR+ss.sFileName;
|
||||
CString sImgHtml = ssprintf("<a href='%s' target='_new'><img class='screenshot' src='%s' width='160' height='120'></a>", sImagePath.c_str(), sImagePath.c_str() );
|
||||
|
||||
|
||||
f.Write("<table>\n");
|
||||
f.Write("<tr>\n");
|
||||
f.Write("<td>"+sImgHtml+"</td>\n");
|
||||
f.Write("<td>\n");
|
||||
|
||||
BEGIN_TABLE(1);
|
||||
|
||||
TABLE_LINE2( sImgTag, sDetails );
|
||||
TABLE_LINE2( "File", ss.sFileName );
|
||||
TABLE_LINE2( "MD5", ss.sMD5 );
|
||||
TABLE_LINE2( "Time", (CString)ctime(&ss.time) );
|
||||
|
||||
END_TABLE;
|
||||
|
||||
f.Write("</td>\n");
|
||||
|
||||
f.Write("</table>\n");
|
||||
}
|
||||
|
||||
void PrintScreenshots( RageFile &f, const Profile *pProfile, CString sTitle, CString sProfileDir )
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "RageDisplay.h"
|
||||
#include "StepMania.h"
|
||||
#include "CryptManager.h"
|
||||
#include <time.h>
|
||||
|
||||
const int NUM_SCORE_DIGITS = 9;
|
||||
|
||||
@@ -1298,17 +1299,18 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t
|
||||
if( !m_bSavedScreenshot[pn] && // only allow one screenshot
|
||||
PROFILEMAN->IsUsingProfile(pn) )
|
||||
{
|
||||
Profile* pProfile = PROFILEMAN->GetProfile(pn);
|
||||
CString sDir = PROFILEMAN->GetProfileDir((ProfileSlot)pn) + "Screenshots/";
|
||||
CString sFileName = SaveScreenshot( sDir, true, true );
|
||||
int iScreenshotIndex = pProfile->GetNextScreenshotIndex();
|
||||
CString sFileName = SaveScreenshot( sDir, true, true, iScreenshotIndex );
|
||||
CString sPath = sDir+sFileName;
|
||||
|
||||
if( !sFileName.empty() )
|
||||
{
|
||||
Profile* pProfile = PROFILEMAN->GetProfile(pn);
|
||||
Profile::Screenshot screenshot;
|
||||
screenshot.sFileName = sFileName;
|
||||
screenshot.sMD5 = CRYPTMAN->GetMD5( sPath );
|
||||
screenshot.highScore = m_HighScore[pn];
|
||||
screenshot.time = time(NULL);
|
||||
pProfile->AddScreenshot( screenshot );
|
||||
}
|
||||
|
||||
|
||||
+14
-12
@@ -1110,7 +1110,7 @@ int main(int argc, char* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature )
|
||||
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex )
|
||||
{
|
||||
//
|
||||
// Find a file name for the screenshot
|
||||
@@ -1123,23 +1123,25 @@ CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature
|
||||
|
||||
/* Files should be of the form "screen######.xxx". Ignore the extension; find
|
||||
* the last file of this form, and use the next number. This way, we don't
|
||||
* write the same screenshot number for different formats (screen0011.bmp,
|
||||
* screen0011.jpg), and we always increase from the end, so if screen0003.jpg
|
||||
* write the same screenshot number for different formats (screen00011.bmp,
|
||||
* screen00011.jpg), and we always increase from the end, so if screen00003.jpg
|
||||
* is deleted, we won't fill in the hole (which makes screenshots hard to find). */
|
||||
int fileno = -1;
|
||||
for( int i = files.size()-1; i >= 0; --i )
|
||||
if( sscanf( files[i], "screen%d.%*s", &fileno ) == 1 )
|
||||
break;
|
||||
if( iIndex == -1 )
|
||||
{
|
||||
for( int i = files.size()-1; i >= 0; --i )
|
||||
if( sscanf( files[i], "screen%d.%*s", &iIndex ) == 1 )
|
||||
break;
|
||||
|
||||
if( fileno == -1 )
|
||||
fileno = 0;
|
||||
else
|
||||
++fileno;
|
||||
if( iIndex == -1 )
|
||||
iIndex = 0;
|
||||
else
|
||||
++iIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// Save the screenshot
|
||||
//
|
||||
CString sFileName = ssprintf( "screen%04d.%s",fileno,bSaveCompressed ? "jpg" : "bmp" );
|
||||
CString sFileName = ssprintf( "screen%05d.%s",iIndex,bSaveCompressed ? "jpg" : "bmp" );
|
||||
CString sPath = sDir+sFileName;
|
||||
bool bResult = DISPLAY->SaveScreenshot( sPath, bSaveCompressed ? RageDisplay::jpg : RageDisplay::bmp );
|
||||
if( !bResult )
|
||||
|
||||
@@ -22,7 +22,7 @@ void SaveGamePrefsToDisk();
|
||||
void ChangeCurrentGame( Game g );
|
||||
|
||||
// If successful, return filename of screenshot in sDir, else return ""
|
||||
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature );
|
||||
CString SaveScreenshot( CString sDir, bool bSaveCompressed, bool bMakeSignature, int iIndex = -1 );
|
||||
|
||||
#if defined(_WINDOWS)
|
||||
#include "windows.h"
|
||||
|
||||
Reference in New Issue
Block a user