Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #306 from Dak0ta/master

Add Unique Identifier to Profiles in profiles.xml
  • Loading branch information...
commit b9e483e9980c553d7972486583f9c82dfd12b5fb 2 parents 6331a46 + 1920f48
@jmarshallnz jmarshallnz authored
View
2  xbmc/settings/GUIDialogProfileSettings.cpp
@@ -322,7 +322,7 @@ bool CGUIDialogProfileSettings::ShowForProfile(unsigned int iProfile, bool first
}*/
// check for old profile settings
- CProfile profile;
+ CProfile profile(dialog->m_strDirectory,dialog->m_strName,g_settings.GetNextProfileId());
g_settings.AddProfile(profile);
bool bExists = CFile::Exists(URIUtils::AddFileToFolder("special://masterprofile/",
dialog->m_strDirectory+"/guisettings.xml"));
View
9 xbmc/settings/Profile.cpp
@@ -45,8 +45,9 @@ void CProfile::CLock::Validate()
code = "-";
}
-CProfile::CProfile(const CStdString &directory, const CStdString &name)
+CProfile::CProfile(const CStdString &directory, const CStdString &name, const int id)
{
+ m_id = id;
m_directory = directory;
m_name = name;
m_bDatabases = true;
@@ -69,8 +70,11 @@ void CProfile::setDate()
setDate(strDate+" - "+strTime);
}
-void CProfile::Load(const TiXmlNode *node)
+void CProfile::Load(const TiXmlNode *node, int nextIdProfile)
{
+ if (!XMLUtils::GetInt(node, "id", m_id))
+ m_id = nextIdProfile;
+
XMLUtils::GetString(node, "name", m_name);
XMLUtils::GetPath(node, "directory", m_directory);
XMLUtils::GetPath(node, "thumbnail", m_thumb);
@@ -101,6 +105,7 @@ void CProfile::Save(TiXmlNode *root) const
TiXmlElement profileNode("profile");
TiXmlNode *node = root->InsertEndChild(profileNode);
+ XMLUtils::SetInt(node, "id", m_id);
XMLUtils::SetString(node, "name", m_name);
XMLUtils::SetPath(node, "directory", m_directory);
XMLUtils::SetPath(node, "thumbnail", m_thumb);
View
6 xbmc/settings/Profile.h
@@ -49,13 +49,14 @@ class CProfile
bool programs;
};
- CProfile(const CStdString &directory = "", const CStdString &name = "");
+ CProfile(const CStdString &directory = "", const CStdString &name = "", const int id = -1);
~CProfile(void);
- void Load(const TiXmlNode *node);
+ void Load(const TiXmlNode *node, int nextIdProfile);
void Save(TiXmlNode *root) const;
const CStdString& getDate() const { return m_date;}
+ const int getId() const { return m_id; }
const CStdString& getName() const { return m_name;}
const CStdString& getDirectory() const { return m_directory;}
const CStdString& getThumb() const { return m_thumb;}
@@ -89,6 +90,7 @@ class CProfile
private:
CStdString m_directory;
+ int m_id;
CStdString m_name;
CStdString m_date;
CStdString m_thumb;
View
19 xbmc/settings/Settings.cpp
@@ -137,6 +137,7 @@ void CSettings::Initialize()
m_usingLoginScreen = false;
m_lastUsedProfile = 0;
m_currentProfile = 0;
+ m_nextIdProfile = 0;
m_activeKeyboardMapping = "default";
}
@@ -1023,6 +1024,7 @@ void CSettings::LoadProfiles(const CStdString& profilesFile)
{
XMLUtils::GetUInt(rootElement, "lastloaded", m_lastUsedProfile);
XMLUtils::GetBoolean(rootElement, "useloginscreen", m_usingLoginScreen);
+ XMLUtils::GetInt(rootElement, "nextIdProfile", m_nextIdProfile);
TiXmlElement* pProfile = rootElement->FirstChildElement("profile");
@@ -1032,8 +1034,8 @@ void CSettings::LoadProfiles(const CStdString& profilesFile)
while (pProfile)
{
CProfile profile(defaultDir);
- profile.Load(pProfile);
- m_vecProfiles.push_back(profile);
+ profile.Load(pProfile,GetNextProfileId());
+ AddProfile(profile);
pProfile = pProfile->NextSiblingElement("profile");
}
}
@@ -1046,8 +1048,8 @@ void CSettings::LoadProfiles(const CStdString& profilesFile)
if (m_vecProfiles.empty())
{ // add the master user
- CProfile profile("special://masterprofile/", "Master user");
- m_vecProfiles.push_back(profile);
+ CProfile profile("special://masterprofile/", "Master user",0);
+ AddProfile(profile);
}
// check the validity of the previous profile index
@@ -1070,6 +1072,7 @@ bool CSettings::SaveProfiles(const CStdString& profilesFile) const
if (!pRoot) return false;
XMLUtils::SetInt(pRoot,"lastloaded", m_currentProfile);
XMLUtils::SetBoolean(pRoot,"useloginscreen",m_usingLoginScreen);
+ XMLUtils::SetInt(pRoot,"nextIdProfile",m_nextIdProfile);
for (unsigned int i = 0; i < m_vecProfiles.size(); ++i)
m_vecProfiles[i].Save(pRoot);
@@ -1857,6 +1860,11 @@ const CProfile &CSettings::GetCurrentProfile() const
return emptyProfile;
}
+ int CSettings::GetCurrentProfileId() const
+ {
+ return GetCurrentProfile().getId();
+ }
+
void CSettings::UpdateCurrentProfileDate()
{
if (m_currentProfile < m_vecProfiles.size())
@@ -1892,6 +1900,9 @@ int CSettings::GetProfileIndex(const CStdString &name) const
void CSettings::AddProfile(const CProfile &profile)
{
+ //data integrity check - covers off migration from old profiles.xml, incrementing of the m_nextIdProfile,and bad data coming in
+ m_nextIdProfile = max(m_nextIdProfile, profile.getId() + 1);
+
m_vecProfiles.push_back(profile);
}
View
8 xbmc/settings/Settings.h
@@ -319,6 +319,13 @@ class CSettings
*/
unsigned int GetCurrentProfileIndex() const { return m_currentProfile; };
+ /*! \brief Retrieve the next id to use for a new profile
+ \return the unique <id> to be used when creating a new profile
+ */
+ int GetNextProfileId() const { return m_nextIdProfile; }; // used to get the value of m_nextIdProfile for use in new profile creation
+
+ int GetCurrentProfileId() const;
+
std::vector<RESOLUTION_INFO> m_ResInfo;
// utility functions for user data folders
@@ -399,6 +406,7 @@ class CSettings
bool m_usingLoginScreen;
unsigned int m_lastUsedProfile;
unsigned int m_currentProfile;
+ int m_nextIdProfile; // for tracking the next available id to give to a new profile to ensure id's are not re-used
};
extern class CSettings g_settings;
Please sign in to comment.
Something went wrong with that request. Please try again.