diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index 783dd05590..4130d4ef63 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -939,17 +939,17 @@ void GameCommand::ApplySelf( const vector &vpns ) const Profile backup = *PROFILEMAN->GetMachineProfile(); - Profile::LoadResult lr = PROFILEMAN->GetMachineProfile()->LoadAllFromDir( sDir, PREFSMAN->m_bSignProfileData ); + ProfileLoadResult lr = PROFILEMAN->GetMachineProfile()->LoadAllFromDir( sDir, PREFSMAN->m_bSignProfileData ); switch( lr ) { - case Profile::success: + case ProfileLoadResult_Success: SCREENMAN->SystemMessage( ssprintf("Machine stats loaded from P%d card.",pn+1) ); break; - case Profile::failed_no_profile: + case ProfileLoadResult_FailedNoProfile: SCREENMAN->SystemMessage( ssprintf("There is no machine profile on P%d card.",pn+1) ); *PROFILEMAN->GetMachineProfile() = backup; break; - case Profile::failed_tampered: + case ProfileLoadResult_FailedTampered: SCREENMAN->SystemMessage( ssprintf("The profile on P%d card contains corrupt or tampered data.",pn+1) ); *PROFILEMAN->GetMachineProfile() = backup; break; diff --git a/stepmania/src/GameConstantsAndTypes.h b/stepmania/src/GameConstantsAndTypes.h index fbcc0a3688..4b94591944 100644 --- a/stepmania/src/GameConstantsAndTypes.h +++ b/stepmania/src/GameConstantsAndTypes.h @@ -416,6 +416,14 @@ enum Stage const CString& StageToString( Stage s ); +enum ProfileLoadResult +{ + ProfileLoadResult_Success, + ProfileLoadResult_FailedNoProfile, + ProfileLoadResult_FailedTampered +}; + + #endif /* diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index f0c0826dc6..04a3dcbb0d 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -788,7 +788,7 @@ void Profile::IncrementCategoryPlayCount( StepsType st, RankingCategory rc ) if( X==NULL ) LOG->Warn("Failed to read section " #X); \ else Load##X##FromNode(X); } -Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignature ) +ProfileLoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignature ) { CHECKPOINT; @@ -802,7 +802,7 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur // Check for the existance of stats.xml CString fn = sDir + STATS_XML; if( !IsAFile(fn) ) - return failed_no_profile; + return ProfileLoadResult_FailedNoProfile; // // Don't unreasonably large stats.xml files. @@ -813,7 +813,7 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur if( iBytes > MAX_PLAYER_STATS_XML_SIZE_BYTES ) { LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() ); - return failed_tampered; + return ProfileLoadResult_FailedTampered; } } @@ -827,7 +827,7 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur if( !CryptManager::VerifyFileWithFile(sStatsXmlSigFile, sDontShareFile) ) { LOG->Warn( "The don't share check for '%s' failed. Data will be ignored.", sStatsXmlSigFile.c_str() ); - return failed_tampered; + return ProfileLoadResult_FailedTampered; } LOG->Trace( "Done." ); @@ -836,7 +836,7 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur if( !CryptManager::VerifyFileWithFile(fn, sStatsXmlSigFile) ) { LOG->Warn( "The signature check for '%s' failed. Data will be ignored.", fn.c_str() ); - return failed_tampered; + return ProfileLoadResult_FailedTampered; } LOG->Trace( "Done." ); } @@ -844,23 +844,23 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur LOG->Trace( "Loading %s", fn.c_str() ); XNode xml; if( !xml.LoadFromFile(fn) ) - return failed_tampered; + return ProfileLoadResult_FailedTampered; LOG->Trace( "Done." ); return LoadStatsXmlFromNode( &xml ); } -Profile::LoadResult Profile::LoadStatsXmlFromNode( const XNode *xml, bool bIgnoreEditable ) +ProfileLoadResult Profile::LoadStatsXmlFromNode( const XNode *xml, bool bIgnoreEditable ) { /* The placeholder stats.xml file has an tag. Don't load it, but don't * warn about it. */ if( xml->m_sName == "html" ) - return failed_no_profile; + return ProfileLoadResult_FailedNoProfile; if( xml->m_sName != "Stats" ) { WARN_M( xml->m_sName ); - return failed_tampered; + return ProfileLoadResult_FailedTampered; } /* These are loaded from Editable, so we usually want to ignore them @@ -887,7 +887,7 @@ Profile::LoadResult Profile::LoadStatsXmlFromNode( const XNode *xml, bool bIgnor m_iWeightPounds = iWeightPounds; } - return success; + return ProfileLoadResult_Success; } bool Profile::SaveAllToDir( CString sDir, bool bSignData ) const @@ -1106,7 +1106,7 @@ XNode* Profile::SaveGeneralDataCreateNode() const return pGeneralDataNode; } -Profile::LoadResult Profile::LoadEditableDataFromDir( CString sDir ) +ProfileLoadResult Profile::LoadEditableDataFromDir( CString sDir ) { CString fn = sDir + EDITABLE_INI; @@ -1117,11 +1117,11 @@ Profile::LoadResult Profile::LoadEditableDataFromDir( CString sDir ) if( iBytes > MAX_EDITABLE_INI_SIZE_BYTES ) { LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() ); - return failed_tampered; + return ProfileLoadResult_FailedTampered; } if( !IsAFile(fn) ) - return failed_no_profile; + return ProfileLoadResult_FailedNoProfile; IniFile ini; ini.ReadFile( fn ); @@ -1140,7 +1140,7 @@ Profile::LoadResult Profile::LoadEditableDataFromDir( CString sDir ) if( m_iWeightPounds != 0 ) CLAMP( m_iWeightPounds, 20, 1000 ); - return success; + return ProfileLoadResult_Success; } void Profile::LoadGeneralDataFromNode( const XNode* pNode ) @@ -1150,10 +1150,10 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode ) CString s; const XNode* pTemp; - pNode->GetChildValue( "DisplayName", m_sDisplayName ); - pNode->GetChildValue( "Character", m_sCharacter ); - pNode->GetChildValue( "LastUsedHighScoreName", m_sLastUsedHighScoreName ); - pNode->GetChildValue( "WeightPounds", m_iWeightPounds ); + pNode->GetChildValue( "DisplayName", m_sDisplayName ); + pNode->GetChildValue( "Character", m_sCharacter ); + pNode->GetChildValue( "LastUsedHighScoreName", m_sLastUsedHighScoreName ); + pNode->GetChildValue( "WeightPounds", m_iWeightPounds ); pNode->GetChildValue( "Guid", m_sGuid ); pNode->GetChildValue( "SortOrder", s ); m_SortOrder = StringToSortOrder( s ); pNode->GetChildValue( "LastDifficulty", s ); m_LastDifficulty = StringToDifficulty( s ); diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 3a3a4fe880..4764e1eadb 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -300,12 +300,11 @@ public: // // Loading and saving // - enum LoadResult { success, failed_no_profile, failed_tampered }; - LoadResult LoadAllFromDir( CString sDir, bool bRequireSignature ); + ProfileLoadResult LoadAllFromDir( CString sDir, bool bRequireSignature ); bool SaveAllToDir( CString sDir, bool bSignData ) const; - LoadResult LoadEditableDataFromDir( CString sDir ); - LoadResult LoadStatsXmlFromNode( const XNode* pNode, bool bIgnoreEditable = true ); + ProfileLoadResult LoadEditableDataFromDir( CString sDir ); + ProfileLoadResult LoadStatsXmlFromNode( const XNode* pNode, bool bIgnoreEditable = true ); void LoadGeneralDataFromNode( const XNode* pNode ); void LoadSongScoresFromNode( const XNode* pNode ); void LoadCourseScoresFromNode( const XNode* pNode ); diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index dd5a2e119f..46b58ab98c 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -71,7 +71,7 @@ void ProfileManager::Init() RefreshLocalProfilesFromDisk(); } -int ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) +ProfileLoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) { LOG->Trace( "LoadingProfile P%d, %s, %d", pn+1, sProfileDir.c_str(), bIsMemCard ); @@ -84,35 +84,35 @@ int ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsM m_bLastLoadWasFromLastGood[pn] = false; // Try to load the original, non-backup data. - Profile::LoadResult lr = GetProfile(pn)->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); + ProfileLoadResult lr = GetProfile(pn)->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); CString sBackupDir = m_sProfileDir[pn] + LAST_GOOD_DIR; // Save a backup of the non-backup profile now that we've loaded it and know // it's good. This should be reasonably fast because we're only saving Stats.xml // and signatures - not all of the files in the Profile. - if( lr == Profile::success ) + if( lr == ProfileLoadResult_Success ) { Profile::BackupToDir( m_sProfileDir[pn], sBackupDir ); } - m_bLastLoadWasTamperedOrCorrupt[pn] = lr == Profile::failed_tampered; + m_bLastLoadWasTamperedOrCorrupt[pn] = lr == ProfileLoadResult_FailedTampered; // // Try to load from the backup if the original data fails to load // - if( lr == Profile::failed_tampered ) + if( lr == ProfileLoadResult_FailedTampered ) { lr = GetProfile(pn)->LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData ); - m_bLastLoadWasFromLastGood[pn] = lr == Profile::success; + m_bLastLoadWasFromLastGood[pn] = lr == ProfileLoadResult_Success; /* If the LastGood profile doesn't exist at all, and the actual profile was failed_tampered, * then the error should be failed_tampered and not failed_no_profile. */ - if( lr == Profile::failed_no_profile ) + if( lr == ProfileLoadResult_FailedNoProfile ) { - LOG->Trace( "Profile was corrupt and LastGood for %s doesn't exist; error is Profile::failed_tampered", + LOG->Trace( "Profile was corrupt and LastGood for %s doesn't exist; error is ProfileLoadResult_FailedTampered", sProfileDir.c_str() ); - lr = Profile::failed_tampered; + lr = ProfileLoadResult_FailedTampered; } } @@ -169,7 +169,7 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) const CString &sSubdir = asDirsToTry[i]; CString sDir = MEM_CARD_MOUNT_POINT[pn] + sSubdir + "/"; - /* If the load fails with Profile::failed_no_profile, keep searching. However, + /* If the load fails with ProfileLoadResult_FailedNoProfile, keep searching. However, * if it fails with failed_tampered, data existed but couldn't be loaded; * we don't want to mess with it, since it's confusing and may wipe out * recoverable backup data. The only time we really want to import data @@ -177,8 +177,8 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) * but we also want to import scores in the case where the player created * a directory for edits before playing, so keep searching if the directory * exists with exists with no scores. */ - Profile::LoadResult res = (Profile::LoadResult) LoadProfile( pn, sDir, true ); - if( res == Profile::success ) + ProfileLoadResult res = LoadProfile( pn, sDir, true ); + if( res == ProfileLoadResult_Success ) { /* If importing, store the directory we imported from, for display purposes. */ if( i > 0 ) @@ -186,7 +186,7 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) break; } - if( res == Profile::failed_tampered ) + if( res == ProfileLoadResult_FailedTampered ) break; } @@ -230,13 +230,13 @@ bool ProfileManager::FastLoadProfileNameFromMemoryCard( CString sRootDir, CStrin CString sDir = sRootDir + sSubdir + "/"; Profile profile; - Profile::LoadResult res = profile.LoadEditableDataFromDir( sDir ); - if( res == Profile::success ) + ProfileLoadResult res = profile.LoadEditableDataFromDir( sDir ); + if( res == ProfileLoadResult_Success ) { sName = profile.GetDisplayNameOrHighScoreName(); return true; } - else if( res != Profile::failed_no_profile ) + else if( res != ProfileLoadResult_FailedNoProfile ) break; } @@ -448,8 +448,8 @@ void ProfileManager::SaveMachineProfile() const void ProfileManager::LoadMachineProfile() { - Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false); - if( lr == Profile::failed_no_profile ) + ProfileLoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false); + if( lr == ProfileLoadResult_FailedNoProfile ) { m_pMachineProfile->InitAll(); m_pMachineProfile->SaveAllToDir( MACHINE_PROFILE_DIR, PREFSMAN->m_bSignProfileData ); diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index f7035d9aef..3946c39813 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -111,8 +111,7 @@ public: void PushSelf( lua_State *L ); private: - // returns Profile::LoadResult, but we don't want to depend on Profile - int LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ); + ProfileLoadResult LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ); void GetMemoryCardProfileDirectoriesToTry( vector &asDirsToTry ) const; // Directory that contains the profile. Either on local machine or