cleanup: move ProfileLoadResult into GameConstantsAndTypes so we don't take dependencies on Profile.h for ProfileLoadResult

This commit is contained in:
Chris Danford
2005-08-13 06:59:27 +00:00
parent 6e155cf810
commit ff7c122289
6 changed files with 52 additions and 46 deletions
+4 -4
View File
@@ -939,17 +939,17 @@ void GameCommand::ApplySelf( const vector<PlayerNumber> &vpns ) const
Profile backup = *PROFILEMAN->GetMachineProfile(); 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 ) switch( lr )
{ {
case Profile::success: case ProfileLoadResult_Success:
SCREENMAN->SystemMessage( ssprintf("Machine stats loaded from P%d card.",pn+1) ); SCREENMAN->SystemMessage( ssprintf("Machine stats loaded from P%d card.",pn+1) );
break; break;
case Profile::failed_no_profile: case ProfileLoadResult_FailedNoProfile:
SCREENMAN->SystemMessage( ssprintf("There is no machine profile on P%d card.",pn+1) ); SCREENMAN->SystemMessage( ssprintf("There is no machine profile on P%d card.",pn+1) );
*PROFILEMAN->GetMachineProfile() = backup; *PROFILEMAN->GetMachineProfile() = backup;
break; break;
case Profile::failed_tampered: case ProfileLoadResult_FailedTampered:
SCREENMAN->SystemMessage( ssprintf("The profile on P%d card contains corrupt or tampered data.",pn+1) ); SCREENMAN->SystemMessage( ssprintf("The profile on P%d card contains corrupt or tampered data.",pn+1) );
*PROFILEMAN->GetMachineProfile() = backup; *PROFILEMAN->GetMachineProfile() = backup;
break; break;
+8
View File
@@ -416,6 +416,14 @@ enum Stage
const CString& StageToString( Stage s ); const CString& StageToString( Stage s );
enum ProfileLoadResult
{
ProfileLoadResult_Success,
ProfileLoadResult_FailedNoProfile,
ProfileLoadResult_FailedTampered
};
#endif #endif
/* /*
+18 -18
View File
@@ -788,7 +788,7 @@ void Profile::IncrementCategoryPlayCount( StepsType st, RankingCategory rc )
if( X==NULL ) LOG->Warn("Failed to read section " #X); \ if( X==NULL ) LOG->Warn("Failed to read section " #X); \
else Load##X##FromNode(X); } else Load##X##FromNode(X); }
Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignature ) ProfileLoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignature )
{ {
CHECKPOINT; CHECKPOINT;
@@ -802,7 +802,7 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur
// Check for the existance of stats.xml // Check for the existance of stats.xml
CString fn = sDir + STATS_XML; CString fn = sDir + STATS_XML;
if( !IsAFile(fn) ) if( !IsAFile(fn) )
return failed_no_profile; return ProfileLoadResult_FailedNoProfile;
// //
// Don't unreasonably large stats.xml files. // 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 ) if( iBytes > MAX_PLAYER_STATS_XML_SIZE_BYTES )
{ {
LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() ); 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) ) if( !CryptManager::VerifyFileWithFile(sStatsXmlSigFile, sDontShareFile) )
{ {
LOG->Warn( "The don't share check for '%s' failed. Data will be ignored.", sStatsXmlSigFile.c_str() ); 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." ); LOG->Trace( "Done." );
@@ -836,7 +836,7 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur
if( !CryptManager::VerifyFileWithFile(fn, sStatsXmlSigFile) ) if( !CryptManager::VerifyFileWithFile(fn, sStatsXmlSigFile) )
{ {
LOG->Warn( "The signature check for '%s' failed. Data will be ignored.", fn.c_str() ); LOG->Warn( "The signature check for '%s' failed. Data will be ignored.", fn.c_str() );
return failed_tampered; return ProfileLoadResult_FailedTampered;
} }
LOG->Trace( "Done." ); LOG->Trace( "Done." );
} }
@@ -844,23 +844,23 @@ Profile::LoadResult Profile::LoadAllFromDir( CString sDir, bool bRequireSignatur
LOG->Trace( "Loading %s", fn.c_str() ); LOG->Trace( "Loading %s", fn.c_str() );
XNode xml; XNode xml;
if( !xml.LoadFromFile(fn) ) if( !xml.LoadFromFile(fn) )
return failed_tampered; return ProfileLoadResult_FailedTampered;
LOG->Trace( "Done." ); LOG->Trace( "Done." );
return LoadStatsXmlFromNode( &xml ); 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 <html> tag. Don't load it, but don't /* The placeholder stats.xml file has an <html> tag. Don't load it, but don't
* warn about it. */ * warn about it. */
if( xml->m_sName == "html" ) if( xml->m_sName == "html" )
return failed_no_profile; return ProfileLoadResult_FailedNoProfile;
if( xml->m_sName != "Stats" ) if( xml->m_sName != "Stats" )
{ {
WARN_M( xml->m_sName ); WARN_M( xml->m_sName );
return failed_tampered; return ProfileLoadResult_FailedTampered;
} }
/* These are loaded from Editable, so we usually want to ignore them /* 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; m_iWeightPounds = iWeightPounds;
} }
return success; return ProfileLoadResult_Success;
} }
bool Profile::SaveAllToDir( CString sDir, bool bSignData ) const bool Profile::SaveAllToDir( CString sDir, bool bSignData ) const
@@ -1106,7 +1106,7 @@ XNode* Profile::SaveGeneralDataCreateNode() const
return pGeneralDataNode; return pGeneralDataNode;
} }
Profile::LoadResult Profile::LoadEditableDataFromDir( CString sDir ) ProfileLoadResult Profile::LoadEditableDataFromDir( CString sDir )
{ {
CString fn = sDir + EDITABLE_INI; CString fn = sDir + EDITABLE_INI;
@@ -1117,11 +1117,11 @@ Profile::LoadResult Profile::LoadEditableDataFromDir( CString sDir )
if( iBytes > MAX_EDITABLE_INI_SIZE_BYTES ) if( iBytes > MAX_EDITABLE_INI_SIZE_BYTES )
{ {
LOG->Warn( "The file '%s' is unreasonably large. It won't be loaded.", fn.c_str() ); 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) ) if( !IsAFile(fn) )
return failed_no_profile; return ProfileLoadResult_FailedNoProfile;
IniFile ini; IniFile ini;
ini.ReadFile( fn ); ini.ReadFile( fn );
@@ -1140,7 +1140,7 @@ Profile::LoadResult Profile::LoadEditableDataFromDir( CString sDir )
if( m_iWeightPounds != 0 ) if( m_iWeightPounds != 0 )
CLAMP( m_iWeightPounds, 20, 1000 ); CLAMP( m_iWeightPounds, 20, 1000 );
return success; return ProfileLoadResult_Success;
} }
void Profile::LoadGeneralDataFromNode( const XNode* pNode ) void Profile::LoadGeneralDataFromNode( const XNode* pNode )
@@ -1150,10 +1150,10 @@ void Profile::LoadGeneralDataFromNode( const XNode* pNode )
CString s; CString s;
const XNode* pTemp; const XNode* pTemp;
pNode->GetChildValue( "DisplayName", m_sDisplayName ); pNode->GetChildValue( "DisplayName", m_sDisplayName );
pNode->GetChildValue( "Character", m_sCharacter ); pNode->GetChildValue( "Character", m_sCharacter );
pNode->GetChildValue( "LastUsedHighScoreName", m_sLastUsedHighScoreName ); pNode->GetChildValue( "LastUsedHighScoreName", m_sLastUsedHighScoreName );
pNode->GetChildValue( "WeightPounds", m_iWeightPounds ); pNode->GetChildValue( "WeightPounds", m_iWeightPounds );
pNode->GetChildValue( "Guid", m_sGuid ); pNode->GetChildValue( "Guid", m_sGuid );
pNode->GetChildValue( "SortOrder", s ); m_SortOrder = StringToSortOrder( s ); pNode->GetChildValue( "SortOrder", s ); m_SortOrder = StringToSortOrder( s );
pNode->GetChildValue( "LastDifficulty", s ); m_LastDifficulty = StringToDifficulty( s ); pNode->GetChildValue( "LastDifficulty", s ); m_LastDifficulty = StringToDifficulty( s );
+3 -4
View File
@@ -300,12 +300,11 @@ public:
// //
// Loading and saving // Loading and saving
// //
enum LoadResult { success, failed_no_profile, failed_tampered }; ProfileLoadResult LoadAllFromDir( CString sDir, bool bRequireSignature );
LoadResult LoadAllFromDir( CString sDir, bool bRequireSignature );
bool SaveAllToDir( CString sDir, bool bSignData ) const; bool SaveAllToDir( CString sDir, bool bSignData ) const;
LoadResult LoadEditableDataFromDir( CString sDir ); ProfileLoadResult LoadEditableDataFromDir( CString sDir );
LoadResult LoadStatsXmlFromNode( const XNode* pNode, bool bIgnoreEditable = true ); ProfileLoadResult LoadStatsXmlFromNode( const XNode* pNode, bool bIgnoreEditable = true );
void LoadGeneralDataFromNode( const XNode* pNode ); void LoadGeneralDataFromNode( const XNode* pNode );
void LoadSongScoresFromNode( const XNode* pNode ); void LoadSongScoresFromNode( const XNode* pNode );
void LoadCourseScoresFromNode( const XNode* pNode ); void LoadCourseScoresFromNode( const XNode* pNode );
+18 -18
View File
@@ -71,7 +71,7 @@ void ProfileManager::Init()
RefreshLocalProfilesFromDisk(); 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 ); 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; m_bLastLoadWasFromLastGood[pn] = false;
// Try to load the original, non-backup data. // 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; CString sBackupDir = m_sProfileDir[pn] + LAST_GOOD_DIR;
// Save a backup of the non-backup profile now that we've loaded it and know // 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 // 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. // and signatures - not all of the files in the Profile.
if( lr == Profile::success ) if( lr == ProfileLoadResult_Success )
{ {
Profile::BackupToDir( m_sProfileDir[pn], sBackupDir ); 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 // 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 ); 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, /* 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. */ * 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() ); sProfileDir.c_str() );
lr = Profile::failed_tampered; lr = ProfileLoadResult_FailedTampered;
} }
} }
@@ -169,7 +169,7 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn )
const CString &sSubdir = asDirsToTry[i]; const CString &sSubdir = asDirsToTry[i];
CString sDir = MEM_CARD_MOUNT_POINT[pn] + sSubdir + "/"; 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; * 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 * 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 * 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 * 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 * a directory for edits before playing, so keep searching if the directory
* exists with exists with no scores. */ * exists with exists with no scores. */
Profile::LoadResult res = (Profile::LoadResult) LoadProfile( pn, sDir, true ); ProfileLoadResult res = LoadProfile( pn, sDir, true );
if( res == Profile::success ) if( res == ProfileLoadResult_Success )
{ {
/* If importing, store the directory we imported from, for display purposes. */ /* If importing, store the directory we imported from, for display purposes. */
if( i > 0 ) if( i > 0 )
@@ -186,7 +186,7 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn )
break; break;
} }
if( res == Profile::failed_tampered ) if( res == ProfileLoadResult_FailedTampered )
break; break;
} }
@@ -230,13 +230,13 @@ bool ProfileManager::FastLoadProfileNameFromMemoryCard( CString sRootDir, CStrin
CString sDir = sRootDir + sSubdir + "/"; CString sDir = sRootDir + sSubdir + "/";
Profile profile; Profile profile;
Profile::LoadResult res = profile.LoadEditableDataFromDir( sDir ); ProfileLoadResult res = profile.LoadEditableDataFromDir( sDir );
if( res == Profile::success ) if( res == ProfileLoadResult_Success )
{ {
sName = profile.GetDisplayNameOrHighScoreName(); sName = profile.GetDisplayNameOrHighScoreName();
return true; return true;
} }
else if( res != Profile::failed_no_profile ) else if( res != ProfileLoadResult_FailedNoProfile )
break; break;
} }
@@ -448,8 +448,8 @@ void ProfileManager::SaveMachineProfile() const
void ProfileManager::LoadMachineProfile() void ProfileManager::LoadMachineProfile()
{ {
Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false); ProfileLoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false);
if( lr == Profile::failed_no_profile ) if( lr == ProfileLoadResult_FailedNoProfile )
{ {
m_pMachineProfile->InitAll(); m_pMachineProfile->InitAll();
m_pMachineProfile->SaveAllToDir( MACHINE_PROFILE_DIR, PREFSMAN->m_bSignProfileData ); m_pMachineProfile->SaveAllToDir( MACHINE_PROFILE_DIR, PREFSMAN->m_bSignProfileData );
+1 -2
View File
@@ -111,8 +111,7 @@ public:
void PushSelf( lua_State *L ); void PushSelf( lua_State *L );
private: private:
// returns Profile::LoadResult, but we don't want to depend on Profile ProfileLoadResult LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard );
int LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard );
void GetMemoryCardProfileDirectoriesToTry( vector<CString> &asDirsToTry ) const; void GetMemoryCardProfileDirectoriesToTry( vector<CString> &asDirsToTry ) const;
// Directory that contains the profile. Either on local machine or // Directory that contains the profile. Either on local machine or