choose profileIDs for new local profiles such that ordering by creation time is preserved

This commit is contained in:
Chris Danford
2005-08-05 10:01:10 +00:00
parent aa832e4e4d
commit 10711f0c83
2 changed files with 24 additions and 16 deletions
+23 -16
View File
@@ -37,6 +37,7 @@ const CString LAST_GOOD_DIR = "LastGood/";
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 map<CString,Profile*> g_mapLocalProfileDirToProfile; static map<CString,Profile*> g_mapLocalProfileDirToProfile;
@@ -353,22 +354,20 @@ bool ProfileManager::CreateLocalProfile( CString sName, CString &sProfileIDOut )
ASSERT( !sName.empty() ); ASSERT( !sName.empty() );
// //
// Find a free directory name in the profiles directory // Find a directory directory name that's a number greater than all
// existing numbers. This preserves the "order by create date".
// //
CString sProfileID, sProfileDir; int iMaxProfileNumber = -1;
const int MAX_TRIES = 1000; vector<CString> vs;
int i; GetLocalProfileIDs( vs );
for( i=0; i<MAX_TRIES; i++ ) FOREACH_CONST( CString, vs, s )
{ iMaxProfileNumber = atoi( *s );
sProfileID = ssprintf("%08d",i);
sProfileDir = LocalProfileIdToDir( sProfileID );
if( !DoesFileExist(sProfileDir) )
break;
}
if( i == MAX_TRIES )
return false;
bool bResult = Profile::CreateNewProfile( sProfileDir, sName ); int iProfileNumber = iMaxProfileNumber + 1;
CString sProfileID = ssprintf( "%08d", iProfileNumber );
CString sProfileDir = LocalProfileIdToDir( sProfileID );
bool bResult = Profile::CreateNewProfile( sProfileDir, sName, true );
if( bResult ) if( bResult )
sProfileIDOut = sProfileID; sProfileIDOut = sProfileID;
else else
@@ -419,7 +418,7 @@ void ProfileManager::LoadMachineProfile()
Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false); Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false);
if( lr == Profile::failed_no_profile ) if( lr == Profile::failed_no_profile )
{ {
Profile::CreateNewProfile(MACHINE_PROFILE_DIR, "Machine"); Profile::CreateNewProfile( MACHINE_PROFILE_DIR, "Machine", false );
m_pMachineProfile->LoadAllFromDir( MACHINE_PROFILE_DIR, false ); m_pMachineProfile->LoadAllFromDir( MACHINE_PROFILE_DIR, false );
} }
@@ -669,7 +668,10 @@ void ProfileManager::GetLocalProfileIDs( vector<CString> &vsProfileIDsOut ) cons
{ {
vsProfileIDsOut.clear(); vsProfileIDsOut.clear();
FOREACHM_CONST( CString, Profile*, g_mapLocalProfileDirToProfile, iter ) FOREACHM_CONST( CString, Profile*, g_mapLocalProfileDirToProfile, iter )
vsProfileIDsOut.push_back( iter->first ); {
CString sID = LocalProfileDirToId( iter->first );
vsProfileIDsOut.push_back( sID );
}
} }
void ProfileManager::GetLocalProfileDisplayNames( vector<CString> &vsProfileDisplayNamesOut ) const void ProfileManager::GetLocalProfileDisplayNames( vector<CString> &vsProfileDisplayNamesOut ) const
@@ -679,6 +681,11 @@ void ProfileManager::GetLocalProfileDisplayNames( vector<CString> &vsProfileDisp
vsProfileDisplayNamesOut.push_back( iter->second->m_sDisplayName ); vsProfileDisplayNamesOut.push_back( iter->second->m_sDisplayName );
} }
int ProfileManager::GetNumLocalProfiles() const
{
return g_mapLocalProfileDirToProfile.size();
}
// lua start // lua start
#include "LuaBinding.h" #include "LuaBinding.h"
+1
View File
@@ -35,6 +35,7 @@ public:
bool DeleteLocalProfile( CString sProfileID ); bool DeleteLocalProfile( CString sProfileID );
void GetLocalProfileIDs( vector<CString> &vsProfileIDsOut ) const; void GetLocalProfileIDs( vector<CString> &vsProfileIDsOut ) const;
void GetLocalProfileDisplayNames( vector<CString> &vsProfileDisplayNamesOut ) const; void GetLocalProfileDisplayNames( vector<CString> &vsProfileDisplayNamesOut ) const;
int GetNumLocalProfiles() const;
bool LoadFirstAvailableProfile( PlayerNumber pn ); // memory card or local profile bool LoadFirstAvailableProfile( PlayerNumber pn ); // memory card or local profile