From 1abb3cd8b2b289e6fdc8c0dbf45ed049f66c5a47 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 24 Apr 2005 19:18:46 +0000 Subject: [PATCH] working on importing scores --- stepmania/src/ProfileManager.cpp | 45 ++++++++++++++++++++++++++------ stepmania/src/ProfileManager.h | 2 +- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/stepmania/src/ProfileManager.cpp b/stepmania/src/ProfileManager.cpp index 3f7b433be0..b32771972a 100644 --- a/stepmania/src/ProfileManager.cpp +++ b/stepmania/src/ProfileManager.cpp @@ -29,6 +29,12 @@ ProfileManager* PROFILEMAN = NULL; // global and accessable from anywhere in our #define MACHINE_PROFILE_DIR "Data/MachineProfile/" const CString LAST_GOOD_DIR = "LastGood/"; +// Directories to search for a profile if m_sMemoryCardProfileSubdir doesn't +// exist, separated by ";": +static Preference g_sMemoryCardProfileImportSubdirs( + Options, "MemoryCardProfileImportSubdirs", "" ); + + ProfileManager::ProfileManager() { } @@ -70,7 +76,7 @@ void ProfileManager::GetLocalProfileNames( vector &asNamesOut ) const } -bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) +Profile::LoadResult ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ) { LOG->Trace( "LoadingProfile P%d, %s, %d", pn+1, sProfileDir.c_str(), bIsMemCard ); @@ -107,7 +113,7 @@ bool ProfileManager::LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIs LOG->Trace( "Done loading profile - result %d", lr ); - return lr == Profile::success; + return lr; } bool ProfileManager::LoadLocalProfileFromMachine( PlayerNumber pn ) @@ -121,7 +127,7 @@ bool ProfileManager::LoadLocalProfileFromMachine( PlayerNumber pn ) CString sDir = USER_PROFILES_DIR + sProfileID + "/"; - return LoadProfile( pn, sDir, false ); + return LoadProfile( pn, sDir, false ) == Profile::success; } bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) @@ -132,13 +138,36 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn ) if( MEMCARDMAN->GetCardState(pn) != MEMORY_CARD_STATE_READY ) return false; - CString sDir = MEM_CARD_MOUNT_POINT[pn]; + vector asDirsToTry; - // tack on a subdirectory so that we don't write everything to the root - sDir += PREFSMAN->m_sMemoryCardProfileSubdir + "/"; + /* Try to load the preferred profile. */ + asDirsToTry.push_back( PREFSMAN->m_sMemoryCardProfileSubdir ); - bool bSuccess; - bSuccess = LoadProfile( pn, sDir, true ); + /* If that failed, try loading from all fallback directories. */ + split( g_sMemoryCardProfileImportSubdirs, ";", asDirsToTry, true ); + + for( unsigned i = 0; i < asDirsToTry.size(); ++i ) + { + const CString &sSubdir = asDirsToTry[i]; + CString sDir = MEM_CARD_MOUNT_POINT[pn] + sSubdir + "/"; + + /* If the load fails with Profile::no_profile, keep searching. However, + * if it fails with failed_tampered, data existed but couldn't be loaded; + * we don't want to mess with it, since it's confusing and may wipe out + * recoverable backup data. The only time we really want to import data + * is on the very first use, when the new profile doesn't exist at all, + * but we also want to import scores in the case where the player created + * 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 ) + break; + } + + /* If we imported a profile fallback directory, change the memory card + * directory back to the preferred directory: never write over imported + * scores. */ + m_sProfileDir[pn] = MEM_CARD_MOUNT_POINT[pn] + PREFSMAN->m_sMemoryCardProfileSubdir + "/"; return true; // If a card is inserted, we want to use the memory card to save - even if the Profile load failed. } diff --git a/stepmania/src/ProfileManager.h b/stepmania/src/ProfileManager.h index 4ac3c580a1..ad6710e48a 100644 --- a/stepmania/src/ProfileManager.h +++ b/stepmania/src/ProfileManager.h @@ -88,7 +88,7 @@ public: void PushSelf( lua_State *L ); private: - bool LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ); + Profile::LoadResult LoadProfile( PlayerNumber pn, CString sProfileDir, bool bIsMemCard ); // Directory that contains the profile. Either on local machine or // on a memory card.