bool CFavouritesDirectory::Save(const CFileItemList &items) { std::string favourites; CXBMCTinyXML doc; TiXmlElement xmlRootElement("favourites"); TiXmlNode *rootNode = doc.InsertEndChild(xmlRootElement); if (!rootNode) return false; for (int i = 0; i < items.Size(); i++) { const CFileItemPtr item = items[i]; TiXmlElement favNode("favourite"); favNode.SetAttribute("name", item->GetLabel().c_str()); if (item->HasArt("thumb")) favNode.SetAttribute("thumb", item->GetArt("thumb").c_str()); TiXmlText execute(item->GetPath()); favNode.InsertEndChild(execute); rootNode->InsertEndChild(favNode); } favourites = URIUtils::AddFileToFolder(CProfilesManager::Get().GetProfileUserDataFolder(), "favourites.xml"); return doc.SaveFile(favourites); }
bool CFavouritesService::Persist() { CXBMCTinyXML doc; TiXmlElement xmlRootElement("favourites"); TiXmlNode *rootNode = doc.InsertEndChild(xmlRootElement); if (!rootNode) return false; for (const auto& item : m_favourites) { TiXmlElement favNode("favourite"); favNode.SetAttribute("name", item->GetLabel().c_str()); if (item->HasArt("thumb")) favNode.SetAttribute("thumb", item->GetArt("thumb").c_str()); const CURL url(item->GetPath()); TiXmlText execute(CURL::Decode(url.GetHostName())); favNode.InsertEndChild(execute); rootNode->InsertEndChild(favNode); } auto path = URIUtils::AddFileToFolder(m_userDataFolder, "favourites.xml"); return doc.SaveFile(path); }
bool CSettings::SaveSettings(const CStdString& strSettingsFile, CGUISettings *localSettings /* = NULL */) const { CXBMCTinyXML xmlDoc; TiXmlElement xmlRootElement("settings"); TiXmlNode *pRoot = xmlDoc.InsertEndChild(xmlRootElement); if (!pRoot) return false; // write our tags one by one - just a big list for now (can be flashed up later) if (!OnSettingsSaving()) return false; // mymusic settings TiXmlElement musicNode("mymusic"); TiXmlNode *pNode = pRoot->InsertEndChild(musicNode); if (!pNode) return false; { TiXmlElement childNode("playlist"); TiXmlNode *pChild = pNode->InsertEndChild(childNode); if (!pChild) return false; XMLUtils::SetBoolean(pChild, "repeat", m_bMyMusicPlaylistRepeat); XMLUtils::SetBoolean(pChild, "shuffle", m_bMyMusicPlaylistShuffle); } XMLUtils::SetInt(pNode, "needsupdate", m_musicNeedsUpdate); XMLUtils::SetInt(pNode, "startwindow", m_iMyMusicStartWindow); XMLUtils::SetBoolean(pNode, "songinfoinvis", m_bMyMusicSongInfoInVis); XMLUtils::SetBoolean(pNode, "songthumbinvis", m_bMyMusicSongThumbInVis); XMLUtils::SetPath(pNode, "defaultlibview", m_defaultMusicLibSource); // myvideos settings TiXmlElement videosNode("myvideos"); pNode = pRoot->InsertEndChild(videosNode); if (!pNode) return false; XMLUtils::SetInt(pNode, "startwindow", m_iVideoStartWindow); XMLUtils::SetBoolean(pNode, "stackvideos", m_videoStacking); XMLUtils::SetInt(pNode, "needsupdate", m_videoNeedsUpdate); XMLUtils::SetBoolean(pNode, "flatten", m_bMyVideoNavFlatten); { // playlist window TiXmlElement childNode("playlist"); TiXmlNode *pChild = pNode->InsertEndChild(childNode); if (!pChild) return false; XMLUtils::SetBoolean(pChild, "repeat", m_bMyVideoPlaylistRepeat); XMLUtils::SetBoolean(pChild, "shuffle", m_bMyVideoPlaylistShuffle); } // general settings TiXmlElement generalNode("general"); pNode = pRoot->InsertEndChild(generalNode); if (!pNode) return false; XMLUtils::SetInt(pNode, "systemtotaluptime", m_iSystemTimeTotalUp); XMLUtils::SetBoolean(pNode, "addonautoupdate", m_bAddonAutoUpdate); XMLUtils::SetBoolean(pNode, "addonnotifications", m_bAddonNotifications); XMLUtils::SetBoolean(pNode, "addonforeignfilter", m_bAddonForeignFilter); // audio settings TiXmlElement volumeNode("audio"); pNode = pRoot->InsertEndChild(volumeNode); if (!pNode) return false; XMLUtils::SetBoolean(pNode, "mute", m_bMute); XMLUtils::SetFloat(pNode, "fvolumelevel", m_fVolumeLevel); if (localSettings) // local settings to save localSettings->SaveXML(pRoot); else // save the global settings g_guiSettings.SaveXML(pRoot); OnSettingsSaved(); if (!Save(pRoot)) return false; // save the file return xmlDoc.SaveFile(strSettingsFile); }