reducing ProfileManager.h dependency on Profile.h (many users only use

PManager to see if a profile is loaded, etc, not to access the actual profiles)
This commit is contained in:
Glenn Maynard
2005-07-01 04:46:32 +00:00
parent 96278f2eca
commit 04546763e0
2 changed files with 31 additions and 18 deletions
+21 -13
View File
@@ -1,5 +1,6 @@
#include "global.h"
#include "ProfileManager.h"
#include "Profile.h"
#include "RageUtil.h"
#include "PrefsManager.h"
#include "RageLog.h"
@@ -36,10 +37,16 @@ static Preference<CString> g_sMemoryCardProfileImportSubdirs( "MemoryCardProfile
ProfileManager::ProfileManager()
{
m_pMachineProfile = new Profile;
FOREACH_PlayerNumber(pn)
m_pProfile[pn] = new Profile;
}
ProfileManager::~ProfileManager()
{
delete m_pMachineProfile;
FOREACH_PlayerNumber(pn)
delete m_pProfile[pn];
}
void ProfileManager::Init()
@@ -77,7 +84,7 @@ void ProfileManager::GetLocalProfileNames( vector<CString> &asNamesOut ) const
Profile::LoadResult 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 );
ASSERT( !sProfileDir.empty() );
ASSERT( sProfileDir.Right(1) == "/" );
@@ -88,7 +95,7 @@ Profile::LoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfi
m_bLastLoadWasFromLastGood[pn] = false;
// Try to load the original, non-backup data.
Profile::LoadResult lr = m_Profile[pn].LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
Profile::LoadResult lr = m_pProfile[pn]->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
CString sBackupDir = m_sProfileDir[pn] + LAST_GOOD_DIR;
@@ -102,11 +109,12 @@ Profile::LoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfi
m_bLastLoadWasTamperedOrCorrupt[pn] = lr == Profile::failed_tampered;
//
// Try to load from the backup if the original data fails to load
//
if( lr == Profile::failed_tampered )
{
lr = m_Profile[pn].LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData );
lr = m_pProfile[pn]->LoadAllFromDir( sBackupDir, PREFSMAN->m_bSignProfileData );
m_bLastLoadWasFromLastGood[pn] = lr == Profile::success;
/* If the LastGood profile doesn't exist at all, and the actual profile was failed_tampered,
@@ -260,7 +268,7 @@ bool ProfileManager::SaveProfile( PlayerNumber pn ) const
if( m_sProfileDir[pn].empty() )
return false;
bool b = m_Profile[pn].SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
bool b = m_pProfile[pn]->SaveAllToDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData );
return b;
}
@@ -272,7 +280,7 @@ void ProfileManager::UnloadProfile( PlayerNumber pn )
m_bWasLoadedFromMemoryCard[pn] = false;
m_bLastLoadWasTamperedOrCorrupt[pn] = false;
m_bLastLoadWasFromLastGood[pn] = false;
m_Profile[pn].InitAll();
m_pProfile[pn]->InitAll();
SONGMAN->FreeAllLoadedFromProfile( (ProfileSlot) pn );
}
@@ -280,7 +288,7 @@ const Profile* ProfileManager::GetProfile( PlayerNumber pn ) const
{
ASSERT( pn >= 0 && pn<NUM_PLAYERS );
return &m_Profile[pn];
return m_pProfile[pn];
}
CString ProfileManager::GetPlayerName( PlayerNumber pn ) const
@@ -364,22 +372,22 @@ void ProfileManager::SaveMachineProfile() const
// If the machine name has changed, make sure we use the new name.
// It's important that this name be applied before the Player profiles
// are saved, so that the Player's profiles show the right machine name.
const_cast<ProfileManager *> (this)->m_MachineProfile.m_sDisplayName = PREFSMAN->m_sMachineName;
const_cast<ProfileManager *> (this)->m_pMachineProfile->m_sDisplayName = PREFSMAN->m_sMachineName;
m_MachineProfile.SaveAllToDir( MACHINE_PROFILE_DIR, false ); /* don't sign machine profiles */
m_pMachineProfile->SaveAllToDir( MACHINE_PROFILE_DIR, false ); /* don't sign machine profiles */
}
void ProfileManager::LoadMachineProfile()
{
Profile::LoadResult lr = m_MachineProfile.LoadAllFromDir(MACHINE_PROFILE_DIR, false);
Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false);
if( lr == Profile::failed_no_profile )
{
Profile::CreateNewProfile(MACHINE_PROFILE_DIR, "Machine");
m_MachineProfile.LoadAllFromDir( MACHINE_PROFILE_DIR, false );
m_pMachineProfile->LoadAllFromDir( MACHINE_PROFILE_DIR, false );
}
// If the machine name has changed, make sure we use the new name
m_MachineProfile.m_sDisplayName = PREFSMAN->m_sMachineName;
m_pMachineProfile->m_sDisplayName = PREFSMAN->m_sMachineName;
SONGMAN->FreeAllLoadedFromProfile( PROFILE_SLOT_MACHINE );
SONGMAN->LoadAllFromProfileDir( MACHINE_PROFILE_DIR, PROFILE_SLOT_MACHINE );
@@ -437,9 +445,9 @@ const Profile* ProfileManager::GetProfile( ProfileSlot slot ) const
if( m_sProfileDir[slot].empty() )
return NULL;
else
return &m_Profile[slot];
return m_pProfile[slot];
case PROFILE_SLOT_MACHINE:
return &m_MachineProfile;
return m_pMachineProfile;
default:
ASSERT(0);
}
+10 -5
View File
@@ -5,10 +5,16 @@
#include "PlayerNumber.h"
#include "GameConstantsAndTypes.h"
#include "HighScore.h"
#include "Difficulty.h"
#include "Profile.h"
class Profile;
class Song;
class Steps;
class Style;
class Course;
class Trail;
struct lua_State;
class ProfileManager
@@ -59,7 +65,7 @@ public:
CString GetProfileDir( ProfileSlot slot ) const;
CString GetProfileDirImportedFrom( ProfileSlot slot ) const;
Profile* GetMachineProfile() { return &m_MachineProfile; }
Profile* GetMachineProfile() { return m_pMachineProfile; }
CString GetPlayerName( PlayerNumber pn ) const;
bool ProfileWasLoadedFromMemoryCard( PlayerNumber pn ) const;
@@ -72,7 +78,7 @@ public:
//
int GetSongNumTimesPlayed( const Song* pSong, ProfileSlot card ) const;
bool IsSongNew( const Song* pSong ) const { return GetSongNumTimesPlayed(pSong,PROFILE_SLOT_MACHINE)==0; }
void AddStepsScore( const Song* pSong, const Steps* pSteps, PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut );
void AddStepsScore( const Song* pSong, const Steps* pSteps , PlayerNumber pn, HighScore hs, int &iPersonalIndexOut, int &iMachineIndexOut );
void IncrementStepsPlayCount( const Song* pSong, const Steps* pSteps, PlayerNumber pn );
HighScore GetHighScoreForDifficulty( const Song *s, const Style *st, ProfileSlot slot, Difficulty dc ) const;
@@ -108,10 +114,9 @@ private:
bool m_bLastLoadWasFromLastGood[NUM_PLAYERS]; // if true, then m_bLastLoadWasTamperedOrCorrupt is also true
// actual loaded profile data
Profile m_Profile[NUM_PLAYERS];
Profile m_MachineProfile;
Profile *m_pProfile[NUM_PLAYERS];
Profile *m_pMachineProfile;
};