From 086ee3f37690f0a023cbe94f576a90b4c2538b90 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 24 Apr 2005 19:39:54 +0000 Subject: [PATCH] split GetMemoryCardProfileDirectoriesToTry store directory imported from --- stepmania/src/ProfileManager.cpp | 42 ++++++++++++++++++++++++++------ stepmania/src/ProfileManager.h | 5 ++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index b32771972a..f644026d58 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -130,6 +130,15 @@ bool ProfileManager::LoadLocalProfileFromMachine( PlayerNumber pn ) return LoadProfile( pn, sDir, false ) == Profile::success; } +void ProfileManager::GetMemoryCardProfileDirectoriesToTry( vector &asDirsToTry ) +{ + /* Try to load the preferred profile. */ + asDirsToTry.push_back( PREFSMAN->m_sMemoryCardProfileSubdir ); + + /* If that failed, try loading from all fallback directories. */ + split( g_sMemoryCardProfileImportSubdirs, ";", asDirsToTry, true ); +} + bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) { UnloadProfile( pn ); @@ -139,13 +148,9 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) return false; vector asDirsToTry; + GetMemoryCardProfileDirectoriesToTry( asDirsToTry ); - /* Try to load the preferred profile. */ - asDirsToTry.push_back( PREFSMAN->m_sMemoryCardProfileSubdir ); - - /* If that failed, try loading from all fallback directories. */ - split( g_sMemoryCardProfileImportSubdirs, ";", asDirsToTry, true ); - + int iLoadedFrom = -1; for( unsigned i = 0; i < asDirsToTry.size(); ++i ) { const CString &sSubdir = asDirsToTry[i]; @@ -160,10 +165,18 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) * a directory for edits before playing, so keep searching if the directory * exists with exists with no scores. */ Profile::LoadResult res = LoadProfile( pn, sDir, true ); - if( res != Profile::failed_no_profile ) + if( res == Profile::success ) + iLoadedFrom = i; + else if( res != Profile::failed_no_profile ) break; } + /* Store the directory we imported from, for display purposes. */ + if( iLoadedFrom > 0 ) + { + m_sProfileDirImportedFrom[pn] = asDirsToTry[iLoadedFrom]; + } + /* If we imported a profile fallback directory, change the memory card * directory back to the preferred directory: never write over imported * scores. */ @@ -209,6 +222,7 @@ bool ProfileManager::SaveProfile( PlayerNumber pn ) const void ProfileManager::UnloadProfile( PlayerNumber pn ) { m_sProfileDir[pn] = ""; + m_sProfileDirImportedFrom[pn] = ""; m_bWasLoadedFromMemoryCard[pn] = false; m_bLastLoadWasTamperedOrCorrupt[pn] = false; m_bLastLoadWasFromLastGood[pn] = false; @@ -353,6 +367,20 @@ CString ProfileManager::GetProfileDir( ProfileSlot slot ) const } } +CString ProfileManager::GetProfileDirImportedFrom( ProfileSlot slot ) const +{ + switch( slot ) + { + case PROFILE_SLOT_PLAYER_1: + case PROFILE_SLOT_PLAYER_2: + return m_sProfileDirImportedFrom[slot]; + case PROFILE_SLOT_MACHINE: + return ""; + default: + ASSERT(0); + } +} + const Profile* ProfileManager::GetProfile( ProfileSlot slot ) const { switch( slot ) diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index ad6710e48a..757643543f 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -32,6 +32,7 @@ public: void SaveAllProfiles() const; bool SaveProfile( PlayerNumber pn ) const; void UnloadProfile( PlayerNumber pn ); + void GetMemoryCardProfileDirectoriesToTry( vector &asDirsToTry ); // // General data @@ -53,6 +54,7 @@ public: const Profile* GetProfile( ProfileSlot slot ) const; Profile* GetProfile( ProfileSlot slot ) { return (Profile*) ((const ProfileManager *) this)->GetProfile(slot); } CString GetProfileDir( ProfileSlot slot ) const; + CString GetProfileDirImportedFrom( ProfileSlot slot ) const; Profile* GetMachineProfile() { return &m_MachineProfile; } @@ -94,6 +96,9 @@ private: // on a memory card. CString m_sProfileDir[NUM_PLAYERS]; + // MemoryCardProfileImportSubdirs name, if the profile was imported. + CString m_sProfileDirImportedFrom[NUM_PLAYERS]; + bool m_bWasLoadedFromMemoryCard[NUM_PLAYERS]; bool m_bLastLoadWasTamperedOrCorrupt[NUM_PLAYERS]; // true if Stats.xml was present, but failed to load (probably because of a signature failure) bool m_bLastLoadWasFromLastGood[NUM_PLAYERS]; // if true, then m_bLastLoadWasTamperedOrCorrupt is also true