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::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;
+8
View File
@@ -416,6 +416,14 @@ enum Stage
const CString& StageToString( Stage s );
enum ProfileLoadResult
{
ProfileLoadResult_Success,
ProfileLoadResult_FailedNoProfile,
ProfileLoadResult_FailedTampered
};
#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); \
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 <html> 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 );
+3 -4
View File
@@ -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 );
+18 -18
View File
@@ -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 );
+1 -2
View File
@@ -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<CString> &asDirsToTry ) const;
// Directory that contains the profile. Either on local machine or