diff --git a/src/Profile.cpp b/src/Profile.cpp index 524b059c7a..25ca4123b7 100644 --- a/src/Profile.cpp +++ b/src/Profile.cpp @@ -789,6 +789,29 @@ void Profile::IncrementCategoryPlayCount( StepsType st, RankingCategory rc ) if( X==NULL ) LOG->Warn("Failed to read section " #X); \ else Load##X##FromNode(X); } +void Profile::LoadCustomFunction( RString sDir ) +{ + /* Get the theme's custom load function: + * [Profile] + * CustomLoadFunction=function(profile, profileDir) ... end + */ + Lua *L = LUA->Get(); + LuaReference customLoadFunc = THEME->GetMetricR("Profile", "CustomLoadFunction"); + customLoadFunc.PushSelf(L); + ASSERT_M(!lua_isnil(L, -1), "CustomLoadFunction not defined"); + + // Pass profile and profile directory as arguments + this->PushSelf(L); + LuaHelpers::Push(L, sDir); + + // Run it + RString sError; + if (!LuaHelpers::RunScriptOnStack(L, sError, 2, 0)) + LOG->Warn("Error running CustomLoadFunction: %s", sError.c_str()); + + LUA->Release(L); +} + ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature ) { CHECKPOINT; @@ -881,25 +904,7 @@ ProfileLoadResult Profile::LoadAllFromDir( RString sDir, bool bRequireSignature if (ret != ProfileLoadResult_Success) return ret; - /* Get the theme's custom load function: - * [Profile] - * CustomLoadFunction=function(profile, profileDir) ... end - */ - Lua *L = LUA->Get(); - LuaReference customLoadFunc = THEME->GetMetricR("Profile", "CustomLoadFunction"); - customLoadFunc.PushSelf(L); - ASSERT_M(!lua_isnil(L, -1), "CustomLoadFunction not defined"); - - // Pass profile and profile directory as arguments - this->PushSelf(L); - LuaHelpers::Push(L, sDir); - - // Run it - RString sError; - if (!LuaHelpers::RunScriptOnStack(L, sError, 2, 0)) - LOG->Warn("Error running CustomLoadFunction: %s", sError.c_str()); - - LUA->Release(L); + LoadCustomFunction( sDir ); return ProfileLoadResult_Success; } diff --git a/src/Profile.h b/src/Profile.h index 60f676479b..383d3d4c27 100644 --- a/src/Profile.h +++ b/src/Profile.h @@ -349,6 +349,7 @@ public: // Loading and saving ProfileLoadResult LoadAllFromDir( RString sDir, bool bRequireSignature ); + void LoadCustomFunction( RString sDir ); bool SaveAllToDir( RString sDir, bool bSignData ) const; ProfileLoadResult LoadEditableDataFromDir( RString sDir ); diff --git a/src/ProfileManager.cpp b/src/ProfileManager.cpp index 9bca938ed4..f00ab076ad 100644 --- a/src/ProfileManager.cpp +++ b/src/ProfileManager.cpp @@ -148,7 +148,7 @@ ProfileLoadResult ProfileManager::LoadProfile( PlayerNumber pn, RString sProfile // Try to load the original, non-backup data. ProfileLoadResult lr = GetProfile(pn)->LoadAllFromDir( m_sProfileDir[pn], PREFSMAN->m_bSignProfileData ); - + RString sBackupDir = m_sProfileDir[pn] + LAST_GOOD_SUBDIR; if( lr == ProfileLoadResult_Success ) @@ -201,6 +201,8 @@ bool ProfileManager::LoadLocalProfileFromMachine( PlayerNumber pn ) return false; } + GetProfile(pn)->LoadCustomFunction( m_sProfileDir[pn] ); + return true; } @@ -247,7 +249,7 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn, bool bLoadEdits m_sProfileDirImportedFrom[pn] = asDirsToTry[i]; break; } - + if( res == ProfileLoadResult_FailedTampered ) { m_bNewProfile[pn] = false; @@ -277,7 +279,7 @@ bool ProfileManager::LoadProfileFromMemoryCard( PlayerNumber pn, bool bLoadEdits return true; // If a card is inserted, we want to use the memory card to save - even if the Profile load failed. } - + bool ProfileManager::LoadFirstAvailableProfile( PlayerNumber pn, bool bLoadEdits ) { if( LoadProfileFromMemoryCard(pn, bLoadEdits) ) diff --git a/src/ThemeManager.cpp b/src/ThemeManager.cpp index ecdf20efd3..b2cbf5d8ad 100644 --- a/src/ThemeManager.cpp +++ b/src/ThemeManager.cpp @@ -12,6 +12,8 @@ #include "RageFile.h" #if !defined(SMPACKAGE) #include "ScreenManager.h" +#include "ProfileManager.h" +#include "Profile.h" #include "ActorUtil.h" #endif #include "Foreach.h" @@ -415,12 +417,20 @@ void ThemeManager::SwitchThemeAndLanguage( const RString &sThemeName_, const RSt // reload common sounds if( SCREENMAN != NULL ) SCREENMAN->ThemeChanged(); + #endif /* Lua globals can use metrics which are cached, and vice versa. Update Lua * globals first; it's Lua's job to explicitly update cached metrics that it * uses. */ UpdateLuaGlobals(); + + // Reload MachineProfile with new theme's CustomLoadFunction + if( PROFILEMAN != NULL ) + { + Profile* pProfile = PROFILEMAN->GetMachineProfile(); + pProfile->LoadCustomFunction( "/Save/MachineProfile/" ); + } } // Use theme metrics for localization.