add GetLocalProfileIDFromIndex

This commit is contained in:
Chris Danford
2005-08-14 23:01:34 +00:00
parent 4bf63f6220
commit 57b593c65e
2 changed files with 21 additions and 12 deletions
+20 -12
View File
@@ -38,8 +38,8 @@ const CString LAST_GOOD_SUBDIR = "LastGood/";
// exist, separated by ";": // exist, separated by ";":
static Preference<CString> g_sMemoryCardProfileImportSubdirs( "MemoryCardProfileImportSubdirs", "" ); static Preference<CString> g_sMemoryCardProfileImportSubdirs( "MemoryCardProfileImportSubdirs", "" );
static CString LocalProfileIdToDir( const CString &sProfileID ) { return USER_PROFILES_DIR + sProfileID + "/"; } static CString LocalProfileIDToDir( const CString &sProfileID ) { return USER_PROFILES_DIR + sProfileID + "/"; }
static CString LocalProfileDirToId( const CString &sDir ) { return Basename( sDir ); } static CString LocalProfileDirToID( const CString &sDir ) { return Basename( sDir ); }
struct DirAndProfile struct DirAndProfile
{ {
@@ -166,7 +166,7 @@ bool ProfileManager::LoadLocalProfileFromMachine( PlayerNumber pn )
return false; return false;
} }
m_sProfileDir[pn] = LocalProfileIdToDir( sProfileID ); m_sProfileDir[pn] = LocalProfileIDToDir( sProfileID );
m_bWasLoadedFromMemoryCard[pn] = false; m_bWasLoadedFromMemoryCard[pn] = false;
m_bLastLoadWasFromLastGood[pn] = false; m_bLastLoadWasFromLastGood[pn] = false;
@@ -305,7 +305,7 @@ bool ProfileManager::SaveLocalProfile( CString sProfileID )
{ {
Profile *pProfile = GetLocalProfile( sProfileID ); Profile *pProfile = GetLocalProfile( sProfileID );
ASSERT( pProfile != NULL ); ASSERT( pProfile != NULL );
CString sDir = LocalProfileIdToDir( sProfileID ); CString sDir = LocalProfileIDToDir( sProfileID );
bool b = pProfile->SaveAllToDir( sDir, PREFSMAN->m_bSignProfileData ); bool b = pProfile->SaveAllToDir( sDir, PREFSMAN->m_bSignProfileData );
return b; return b;
} }
@@ -336,7 +336,7 @@ const Profile* ProfileManager::GetProfile( PlayerNumber pn ) const
} }
else else
{ {
CString sProfileID = LocalProfileDirToId( m_sProfileDir[pn] ); CString sProfileID = LocalProfileDirToID( m_sProfileDir[pn] );
return GetLocalProfile( sProfileID ); return GetLocalProfile( sProfileID );
} }
} }
@@ -370,7 +370,7 @@ void ProfileManager::RefreshLocalProfilesFromDisk()
const Profile *ProfileManager::GetLocalProfile( const CString &sProfileID ) const const Profile *ProfileManager::GetLocalProfile( const CString &sProfileID ) const
{ {
CString sDir = LocalProfileIdToDir( sProfileID ); CString sDir = LocalProfileIDToDir( sProfileID );
FOREACH_CONST( DirAndProfile, g_vLocalProfile, dap ) FOREACH_CONST( DirAndProfile, g_vLocalProfile, dap )
{ {
const CString &sOther = dap->sDir; const CString &sOther = dap->sDir;
@@ -408,7 +408,7 @@ bool ProfileManager::CreateLocalProfile( CString sName, CString &sProfileIDOut )
// //
// Save it to disk. // Save it to disk.
// //
CString sProfileDir = LocalProfileIdToDir( sProfileID ); CString sProfileDir = LocalProfileIDToDir( sProfileID );
if( !pProfile->SaveAllToDir(sProfileDir, PREFSMAN->m_bSignProfileData) ) if( !pProfile->SaveAllToDir(sProfileDir, PREFSMAN->m_bSignProfileData) )
{ {
delete pProfile; delete pProfile;
@@ -432,7 +432,7 @@ void ProfileManager::AddLocalProfileByID( Profile *pProfile, CString sProfileID
// insert // insert
g_vLocalProfile.push_back( DirAndProfile() ); g_vLocalProfile.push_back( DirAndProfile() );
DirAndProfile &dap = g_vLocalProfile.back(); DirAndProfile &dap = g_vLocalProfile.back();
dap.sDir = LocalProfileIdToDir( sProfileID ); dap.sDir = LocalProfileIDToDir( sProfileID );
dap.profile = *pProfile; dap.profile = *pProfile;
} }
@@ -444,7 +444,7 @@ bool ProfileManager::RenameLocalProfile( CString sProfileID, CString sNewName )
ASSERT( pProfile ); ASSERT( pProfile );
pProfile->m_sDisplayName = sNewName; pProfile->m_sDisplayName = sNewName;
CString sProfileDir = LocalProfileIdToDir( sProfileID ); CString sProfileDir = LocalProfileIDToDir( sProfileID );
return pProfile->SaveAllToDir( sProfileDir, PREFSMAN->m_bSignProfileData ); return pProfile->SaveAllToDir( sProfileDir, PREFSMAN->m_bSignProfileData );
} }
@@ -452,7 +452,7 @@ bool ProfileManager::DeleteLocalProfile( CString sProfileID )
{ {
Profile *pProfile = ProfileManager::GetLocalProfile( sProfileID ); Profile *pProfile = ProfileManager::GetLocalProfile( sProfileID );
ASSERT( pProfile ); ASSERT( pProfile );
CString sProfileDir = LocalProfileIdToDir( sProfileID ); CString sProfileDir = LocalProfileIDToDir( sProfileID );
FOREACH( DirAndProfile, g_vLocalProfile, i ) FOREACH( DirAndProfile, g_vLocalProfile, i )
{ {
@@ -740,7 +740,7 @@ void ProfileManager::GetLocalProfileIDs( vector<CString> &vsProfileIDsOut ) cons
vsProfileIDsOut.clear(); vsProfileIDsOut.clear();
FOREACH_CONST( DirAndProfile, g_vLocalProfile, i) FOREACH_CONST( DirAndProfile, g_vLocalProfile, i)
{ {
CString sID = LocalProfileDirToId( i->sDir ); CString sID = LocalProfileDirToID( i->sDir );
vsProfileIDsOut.push_back( sID ); vsProfileIDsOut.push_back( sID );
} }
} }
@@ -754,7 +754,7 @@ void ProfileManager::GetLocalProfileDisplayNames( vector<CString> &vsProfileDisp
int ProfileManager::GetLocalProfileIndexFromID( CString sProfileID ) const int ProfileManager::GetLocalProfileIndexFromID( CString sProfileID ) const
{ {
CString sDir = LocalProfileIdToDir( sProfileID ); CString sDir = LocalProfileIDToDir( sProfileID );
FOREACH_CONST( DirAndProfile, g_vLocalProfile, i ) FOREACH_CONST( DirAndProfile, g_vLocalProfile, i )
{ {
if( i->sDir == sProfileID ) if( i->sDir == sProfileID )
@@ -763,6 +763,12 @@ int ProfileManager::GetLocalProfileIndexFromID( CString sProfileID ) const
return -1; return -1;
} }
CString ProfileManager::GetLocalProfileIDFromIndex( int iIndex )
{
CString sID = LocalProfileDirToID( g_vLocalProfile[iIndex].sDir );
return sID;
}
Profile *ProfileManager::GetLocalProfileFromIndex( int iIndex ) Profile *ProfileManager::GetLocalProfileFromIndex( int iIndex )
{ {
return &g_vLocalProfile[iIndex].profile; return &g_vLocalProfile[iIndex].profile;
@@ -796,6 +802,7 @@ public:
return 1; return 1;
} }
static int GetLocalProfileFromIndex( T* p, lua_State *L ) { Profile *pProfile = p->GetLocalProfileFromIndex(IArg(1)); ASSERT(pProfile); pProfile->PushSelf(L); return 1; } static int GetLocalProfileFromIndex( T* p, lua_State *L ) { Profile *pProfile = p->GetLocalProfileFromIndex(IArg(1)); ASSERT(pProfile); pProfile->PushSelf(L); return 1; }
static int GetLocalProfileIDFromIndex( T* p, lua_State *L ) { lua_pushstring(L, p->GetLocalProfileIDFromIndex(IArg(1)) ); return 1; }
static int GetLocalProfileIndexFromID( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLocalProfileIndexFromID(SArg(1)) ); return 1; } static int GetLocalProfileIndexFromID( T* p, lua_State *L ) { lua_pushnumber(L, p->GetLocalProfileIndexFromID(SArg(1)) ); return 1; }
static int GetNumLocalProfiles( T* p, lua_State *L ) { lua_pushnumber(L, p->GetNumLocalProfiles() ); return 1; } static int GetNumLocalProfiles( T* p, lua_State *L ) { lua_pushnumber(L, p->GetNumLocalProfiles() ); return 1; }
@@ -807,6 +814,7 @@ public:
ADD_METHOD( SaveMachineProfile ) ADD_METHOD( SaveMachineProfile )
ADD_METHOD( GetLocalProfile ) ADD_METHOD( GetLocalProfile )
ADD_METHOD( GetLocalProfileFromIndex ) ADD_METHOD( GetLocalProfileFromIndex )
ADD_METHOD( GetLocalProfileIDFromIndex )
ADD_METHOD( GetLocalProfileIndexFromID ) ADD_METHOD( GetLocalProfileIndexFromID )
ADD_METHOD( GetNumLocalProfiles ) ADD_METHOD( GetNumLocalProfiles )
Luna<T>::Register( L ); Luna<T>::Register( L );
+1
View File
@@ -32,6 +32,7 @@ public:
const Profile *GetLocalProfile( const CString &sProfileID ) const; const Profile *GetLocalProfile( const CString &sProfileID ) const;
Profile *GetLocalProfile( const CString &sProfileID ) { return (Profile*) ((const ProfileManager *) this)->GetLocalProfile(sProfileID); } Profile *GetLocalProfile( const CString &sProfileID ) { return (Profile*) ((const ProfileManager *) this)->GetLocalProfile(sProfileID); }
Profile *GetLocalProfileFromIndex( int iIndex ); Profile *GetLocalProfileFromIndex( int iIndex );
CString GetLocalProfileIDFromIndex( int iIndex );
bool CreateLocalProfile( CString sName, CString &sProfileIDOut ); bool CreateLocalProfile( CString sName, CString &sProfileIDOut );
void AddLocalProfileByID( Profile *pProfile, CString sProfileID ); // transfers ownership of pProfile void AddLocalProfileByID( Profile *pProfile, CString sProfileID ); // transfers ownership of pProfile