From 39656d87ec35c5fd6702fc5a0fa1739f5601bdac Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Fri, 12 Aug 2005 18:40:12 +0000 Subject: [PATCH] create new profiles without reloading all old ones --- stepmania/src/Profile.cpp | 17 +++++++++++------ stepmania/src/Profile.h | 2 +- stepmania/src/ProfileManager.cpp | 10 ++++++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/stepmania/src/Profile.cpp b/stepmania/src/Profile.cpp index 91cedc0d73..64f7f787a0 100644 --- a/stepmania/src/Profile.cpp +++ b/stepmania/src/Profile.cpp @@ -1889,15 +1889,20 @@ void Profile::BackupToDir( CString sFromDir, CString sToDir ) FileCopy( sFromDir+DONT_SHARE_SIG, sToDir+DONT_SHARE_SIG ); } -bool Profile::CreateNewProfile( CString sProfileDir, CString sName, bool bFillWithRandomCharacter ) +Profile *Profile::CreateNewProfile( CString sProfileDir, CString sName, bool bFillWithRandomCharacter ) { - Profile pro; - pro.m_sDisplayName = sName; + Profile *pProfile = new Profile; + pProfile->m_sDisplayName = sName; if( bFillWithRandomCharacter ) - pro.m_sCharacter = GAMESTATE->GetRandomCharacter()->m_sName; - bool bResult = pro.SaveAllToDir( sProfileDir, PREFSMAN->m_bSignProfileData ); + pProfile->m_sCharacter = GAMESTATE->GetRandomCharacter()->m_sName; + if( !pProfile->SaveAllToDir(sProfileDir, PREFSMAN->m_bSignProfileData) ) + { + delete pProfile; + return NULL; + } + FlushDirCache(); - return bResult; + return pProfile; } diff --git a/stepmania/src/Profile.h b/stepmania/src/Profile.h index 1740f3da0c..0529b09220 100644 --- a/stepmania/src/Profile.h +++ b/stepmania/src/Profile.h @@ -332,7 +332,7 @@ public: void SaveStatsWebPageToDir( CString sDir ) const; void SaveMachinePublicKeyToDir( CString sDir ) const; - static bool CreateNewProfile( CString sProfileDir, CString sName, bool bFillWithRandomCharacter ); + static Profile *CreateNewProfile( CString sProfileDir, CString sName, bool bFillWithRandomCharacter ); static void BackupToDir( CString sFromDir, CString sToDir ); // Lua diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index be81531bec..28350cd966 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -378,10 +378,11 @@ bool ProfileManager::CreateLocalProfile( CString sName, CString &sProfileIDOut ) bool ProfileManager::CreateLocalProfileByID( CString sName, CString sProfileID ) { CString sProfileDir = LocalProfileIdToDir( sProfileID ); - if( !Profile::CreateNewProfile(sProfileDir, sName, true) ) + Profile *pProfile = Profile::CreateNewProfile( sProfileDir, sName, true ); + if( pProfile == NULL ) return false; - RefreshLocalProfilesFromDisk(); + g_mapLocalProfileIdToProfile[sProfileID] = pProfile; return true; } @@ -434,8 +435,9 @@ void ProfileManager::LoadMachineProfile() Profile::LoadResult lr = m_pMachineProfile->LoadAllFromDir(MACHINE_PROFILE_DIR, false); if( lr == Profile::failed_no_profile ) { - Profile::CreateNewProfile( MACHINE_PROFILE_DIR, "Machine", false ); - m_pMachineProfile->LoadAllFromDir( MACHINE_PROFILE_DIR, false ); + Profile *pProfile = Profile::CreateNewProfile( MACHINE_PROFILE_DIR, "Machine", false ); + delete m_pMachineProfile; + m_pMachineProfile = pProfile; } // If the machine name has changed, make sure we use the new name