diff --git a/stepmania/src/HighScore.cpp b/stepmania/src/HighScore.cpp index 06bb9c135c..666e31bcc3 100644 --- a/stepmania/src/HighScore.cpp +++ b/stepmania/src/HighScore.cpp @@ -189,6 +189,30 @@ void HighScoreList::LoadFromNode( const XNode* pNode ) } } +XNode* Screenshot::CreateNode() const +{ + XNode* pNode = new XNode; + pNode->name = "Screenshot"; + + // TRICKY: Don't write "name to fill in" markers. + pNode->AppendChild( "FileName", sFileName ); + pNode->AppendChild( "MD5", sMD5 ); + pNode->AppendChild( highScore.CreateNode() ); + + return pNode; +} + +void Screenshot::LoadFromNode( const XNode* pNode ) +{ + ASSERT( pNode->name == "Screenshot" ); + + pNode->GetChildValue( "FileName", sFileName ); + pNode->GetChildValue( "MD5", sMD5 ); + XNode* pHighScore = pNode->GetChild( "HighScore" ); + if( pHighScore ) + highScore.LoadFromNode( pHighScore ); +} + /* * (c) 2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/HighScore.h b/stepmania/src/HighScore.h index 298692220d..62e4c8b169 100644 --- a/stepmania/src/HighScore.h +++ b/stepmania/src/HighScore.h @@ -92,6 +92,16 @@ struct HighScoreList void LoadFromNode( const XNode* pNode ); }; +struct Screenshot +{ + CString sFileName; // no directory part - just the file name + CString sMD5; // MD5 hash of the screenshot file + HighScore highScore; + + XNode* CreateNode() const; + void LoadFromNode( const XNode* pNode ); +}; + #endif /* diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 56ae41aa88..c55c87a65b 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -1263,7 +1263,7 @@ void Profile::SaveMachinePublicKeyToDir( CString sDir ) const FileCopy( CRYPTMAN->GetPublicKeyFileName(), sDir+PUBLIC_KEY_FILE ); } -void Profile::AddScreenshot( Screenshot screenshot ) +void Profile::AddScreenshot( const Screenshot &screenshot ) { m_vScreenshots.push_back( screenshot ); } @@ -1273,26 +1273,13 @@ void Profile::LoadScreenshotDataFromNode( const XNode* pNode ) CHECKPOINT; ASSERT( pNode->name == "ScreenshotData" ); - for( XNodes::const_iterator screenshot = pNode->childs.begin(); - screenshot != pNode->childs.end(); - screenshot++ ) + FOREACH_CONST( XNode*, pNode->childs, screenshot ) { if( (*screenshot)->name != "Screenshot" ) WARN_AND_CONTINUE; Screenshot ss; - - if( !(*screenshot)->GetChildValue("FileName",ss.sFileName) ) - WARN; - - if( !(*screenshot)->GetChildValue("MD5",ss.sMD5) ) - WARN; - - if( !(*screenshot)->GetChildValue("Time",(int&)ss.time) ) // time_t is a signed long on Win32. Is this ok on other platforms? - WARN; - - if( !(*screenshot)->GetChildValue("MachineGuid",ss.sMachineGuid) ) - WARN; + ss.LoadFromNode( *screenshot ); m_vScreenshots.push_back( ss ); } @@ -1308,16 +1295,9 @@ XNode* Profile::SaveScreenshotDataCreateNode() const XNode* pNode = new XNode; pNode->name = "ScreenshotData"; - for( unsigned i=0; iAppendChild( "Screenshot" ); - - pScreenshotNode->AppendChild( "FileName", ss.sFileName ); - pScreenshotNode->AppendChild( "MD5", ss.sMD5 ); - pScreenshotNode->AppendChild( "Time", (int) ss.time ); - pScreenshotNode->AppendChild( "MachineGuid", ss.sMachineGuid ); + XNode* pScreenshotNode = pNode->AppendChild( ss->CreateNode() ); } return pNode; @@ -1328,9 +1308,7 @@ void Profile::LoadCalorieDataFromNode( const XNode* pNode ) CHECKPOINT; ASSERT( pNode->name == "CalorieData" ); - for( XNodes::const_iterator pDay = pNode->childs.begin(); - pDay != pNode->childs.end(); - pDay++ ) + FOREACH_CONST( XNode*, pNode->childs, pDay ) { if( (*pDay)->name != "Day" ) WARN_AND_CONTINUE; diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 52bb50a674..a3ef25c909 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -174,15 +174,8 @@ public: // // Screenshot Data // - struct Screenshot - { - CString sFileName; // no directory part - just the file name - CString sMD5; // MD5 hash of the screenshot file - time_t time; // return value of time() when screenshot was taken - CString sMachineGuid; // where this screenshot was taken - }; vector m_vScreenshots; - void AddScreenshot( Screenshot screenshot ); + void AddScreenshot( const Screenshot &screenshot ); int GetNextScreenshotIndex() { return m_vScreenshots.size(); } diff --git a/stepmania/src/ProfileHtml.cpp b/stepmania/src/ProfileHtml.cpp index af65b13e39..59b1a2d12f 100644 --- a/stepmania/src/ProfileHtml.cpp +++ b/stepmania/src/ProfileHtml.cpp @@ -1138,7 +1138,7 @@ void PrintBookkeeping( RageFile &f, const Profile *pProfile, CString sTitle, vec PRINT_CLOSE(f); } -void PrintScreenshot( RageFile &f, const Profile::Screenshot &ss ) +void PrintScreenshot( RageFile &f, const Screenshot &ss ) { CString sImagePath = SCREENSHOTS_SUBDIR+ss.sFileName; CString sImgHtml = ssprintf("", sImagePath.c_str(), sImagePath.c_str() ); @@ -1153,8 +1153,7 @@ void PrintScreenshot( RageFile &f, const Profile::Screenshot &ss ) TABLE_LINE2( "File", ss.sFileName ); TABLE_LINE2( "MD5", ss.sMD5 ); - TABLE_LINE2( "Time", (CString)ctime(&ss.time) ); - TABLE_LINE2( "Machine", ss.sMachineGuid ); + TABLE_LINE2( "Results", HighScoreToString(ss.highScore) ); END_TABLE; @@ -1172,9 +1171,9 @@ void PrintScreenshots( RageFile &f, const Profile *pProfile, CString sTitle, CSt for( int i = (int)pProfile->m_vScreenshots.size()-1; i >= 0; i-- ) { - Profile::Screenshot ss = pProfile->m_vScreenshots[i]; + Screenshot ss = pProfile->m_vScreenshots[i]; tm new_time; - localtime_r( &ss.time, &new_time ); + localtime_r( &ss.highScore.time, &new_time ); int iYear = new_time.tm_year+1900; int iMonth = new_time.tm_mon+1; CString sNewMonth = ssprintf("%02d/%d", iMonth, iYear ); diff --git a/stepmania/src/ScreenAward.cpp b/stepmania/src/ScreenAward.cpp index 79a948f015..46f02bc0b5 100644 --- a/stepmania/src/ScreenAward.cpp +++ b/stepmania/src/ScreenAward.cpp @@ -107,11 +107,10 @@ void ScreenAward::Input( const DeviceInput& DeviceI, const InputEventType type, if( !sFileName.empty() ) { - Profile::Screenshot screenshot; + Screenshot screenshot; screenshot.sFileName = sFileName; screenshot.sMD5 = CRYPTMAN->GetMD5( sPath ); - screenshot.time = time(NULL); - screenshot.sMachineGuid = PROFILEMAN->GetMachineProfile()->m_sGuid; + // FIXME: save HighScore pProfile->AddScreenshot( screenshot ); } diff --git a/stepmania/src/ScreenEvaluation.cpp b/stepmania/src/ScreenEvaluation.cpp index 8ce6ebc699..f0c89fecd0 100644 --- a/stepmania/src/ScreenEvaluation.cpp +++ b/stepmania/src/ScreenEvaluation.cpp @@ -1392,6 +1392,8 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t if( GameI.IsValid() ) { PlayerNumber pn = GAMESTATE->GetCurrentStyleDef()->ControllerToPlayerNumber( GameI.controller ); + HighScore &hs = m_HighScore[pn]; + if( CodeDetector::EnteredCode(GameI.controller, CodeDetector::CODE_SAVE_SCREENSHOT) ) { @@ -1406,11 +1408,10 @@ void ScreenEvaluation::Input( const DeviceInput& DeviceI, const InputEventType t if( !sFileName.empty() ) { - Profile::Screenshot screenshot; + Screenshot screenshot; screenshot.sFileName = sFileName; screenshot.sMD5 = CRYPTMAN->GetMD5( sPath ); - screenshot.time = time(NULL); - screenshot.sMachineGuid = PROFILEMAN->GetMachineProfile()->m_sGuid; + screenshot.highScore = hs; pProfile->AddScreenshot( screenshot ); }