From 2a3d46466da9d409fe0a05bf1ce474a186429f98 Mon Sep 17 00:00:00 2001 From: fritsch Date: Mon, 2 Dec 2019 11:00:42 +0100 Subject: [PATCH 1/3] ProfileManager: Fall back to master profile if profile.xml not loadable / parseable --- xbmc/profiles/ProfileManager.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/xbmc/profiles/ProfileManager.cpp b/xbmc/profiles/ProfileManager.cpp index 3b57dcd16fc6c..b57460b808eca 100644 --- a/xbmc/profiles/ProfileManager.cpp +++ b/xbmc/profiles/ProfileManager.cpp @@ -189,6 +189,15 @@ bool CProfileManager::Load() ret = false; } } + if (!ret) + { + CLog::Log(LOGERROR, + "Failed to load profile - might be corrupted - falling back to master profile"); + m_profiles.clear(); + CFile::Delete(file); + + ret = true; + } if (m_profiles.empty()) { // add the master user From a982498ca1f5c02745c6c90bd9c738211beef316 Mon Sep 17 00:00:00 2001 From: fritsch Date: Mon, 2 Dec 2019 11:56:15 +0100 Subject: [PATCH 2/3] XBMCTinyXML: Properly Flush when writing xml to disk --- xbmc/utils/XBMCTinyXML.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/xbmc/utils/XBMCTinyXML.cpp b/xbmc/utils/XBMCTinyXML.cpp index ac1ca9d75becb..f647ede257ed0 100644 --- a/xbmc/utils/XBMCTinyXML.cpp +++ b/xbmc/utils/XBMCTinyXML.cpp @@ -110,7 +110,11 @@ bool CXBMCTinyXML::SaveFile(const std::string& filename) const { TiXmlPrinter printer; Accept(&printer); - return file.Write(printer.CStr(), printer.Size()) == static_cast(printer.Size()); + bool suc = file.Write(printer.CStr(), printer.Size()) == static_cast(printer.Size()); + if (suc) + file.Flush(); + + return suc; } return false; } From c35f34556cc05331b56449b5f0afc9b3e835e1ff Mon Sep 17 00:00:00 2001 From: fritsch Date: Thu, 12 Dec 2019 11:19:55 +0100 Subject: [PATCH 3/3] ProfileManager: Save changes when they happen --- xbmc/profiles/ProfileManager.cpp | 34 +++++++++++++++++--------------- xbmc/profiles/ProfileManager.h | 13 +++++++++--- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/xbmc/profiles/ProfileManager.cpp b/xbmc/profiles/ProfileManager.cpp index b57460b808eca..8276aa484af6f 100644 --- a/xbmc/profiles/ProfileManager.cpp +++ b/xbmc/profiles/ProfileManager.cpp @@ -129,12 +129,6 @@ void CProfileManager::OnSettingsLoaded() CDirectory::Create(URIUtils::AddFileToFolder(strDir,"mixed")); } -void CProfileManager::OnSettingsSaved() const -{ - // save mastercode - Save(); -} - void CProfileManager::OnSettingsCleared() { Clear(); @@ -289,7 +283,6 @@ bool CProfileManager::LoadProfile(unsigned int index) pWindow->ResetControlStates(); UpdateCurrentProfileDate(); - Save(); FinalizeLoadProfile(); return true; @@ -369,7 +362,6 @@ bool CProfileManager::LoadProfile(unsigned int index) lock.Leave(); UpdateCurrentProfileDate(); - Save(); FinalizeLoadProfile(); return true; @@ -589,19 +581,26 @@ int CProfileManager::GetProfileIndex(const std::string &name) const void CProfileManager::AddProfile(const CProfile &profile) { - CSingleLock lock(m_critical); - // data integrity check - covers off migration from old profiles.xml, - // incrementing of the m_nextIdProfile,and bad data coming in - m_nextProfileId = std::max(m_nextProfileId, profile.getId() + 1); + { + CSingleLock lock(m_critical); + // data integrity check - covers off migration from old profiles.xml, + // incrementing of the m_nextIdProfile,and bad data coming in + m_nextProfileId = std::max(m_nextProfileId, profile.getId() + 1); - m_profiles.push_back(profile); + m_profiles.push_back(profile); + } + Save(); } void CProfileManager::UpdateCurrentProfileDate() { CSingleLock lock(m_critical); if (m_currentProfile < m_profiles.size()) + { m_profiles[m_currentProfile].setDate(); + CSingleExit exit(m_critical); + Save(); + } } void CProfileManager::LoadMasterProfileForLogin() @@ -729,7 +728,10 @@ void CProfileManager::OnSettingAction(std::shared_ptr setting) void CProfileManager::SetCurrentProfileId(unsigned int profileId) { - CSingleLock lock(m_critical); - m_currentProfile = profileId; - CSpecialProtocol::SetProfilePath(GetProfileUserDataFolder()); + { + CSingleLock lock(m_critical); + m_currentProfile = profileId; + CSpecialProtocol::SetProfilePath(GetProfileUserDataFolder()); + } + Save(); } diff --git a/xbmc/profiles/ProfileManager.h b/xbmc/profiles/ProfileManager.h index e7bb7adc59376..96a729817950d 100644 --- a/xbmc/profiles/ProfileManager.h +++ b/xbmc/profiles/ProfileManager.h @@ -35,7 +35,6 @@ class CProfileManager : protected ISettingsHandler, void Uninitialize(); void OnSettingsLoaded() override; - void OnSettingsSaved() const override; void OnSettingsCleared() override; bool Load(); @@ -108,7 +107,11 @@ class CProfileManager : protected ISettingsHandler, /*! \brief Toggle login screen use on and off Toggles the login screen state */ - void ToggleLoginScreen() { m_usingLoginScreen = !m_usingLoginScreen; } + void ToggleLoginScreen() + { + m_usingLoginScreen = !m_usingLoginScreen; + Save(); + } /*! \brief Are we the master user? \return true if the current profile is the master user, false otherwise @@ -155,7 +158,11 @@ class CProfileManager : protected ISettingsHandler, used profile will be loaded \return the id to the autologin profile */ - void SetAutoLoginProfileId(const int profileId) { m_autoLoginProfile = profileId; } + void SetAutoLoginProfileId(const int profileId) + { + m_autoLoginProfile = profileId; + Save(); + } /*! \brief Retrieve the name of a particular profile by index \param profileId profile index for which to retrieve the name