bool CAddonInstaller::InstallFromZip(const std::string &path) { if (!g_passwordManager.CheckMenuLock(WINDOW_ADDON_BROWSER)) return false; CLog::Log(LOGDEBUG, "CAddonInstaller: installing from zip '%s'", CURL::GetRedacted(path).c_str()); // grab the descriptive XML document from the zip, and read it in CFileItemList items; // BUG: some zip files return a single item (root folder) that we think is stored, so we don't use the zip:// protocol CURL pathToUrl(path); CURL zipDir = URIUtils::CreateArchivePath("zip", pathToUrl, ""); if (!CDirectory::GetDirectory(zipDir, items) || items.Size() != 1 || !items[0]->m_bIsFolder) { CEventLog::GetInstance().AddWithNotification(EventPtr(new CNotificationEvent(24045, StringUtils::Format(g_localizeStrings.Get(24143).c_str(), path.c_str()), "special://xbmc/media/icon256x256.png", EventLevel::Error))); return false; } // TODO: possibly add support for github generated zips here? std::string archive = URIUtils::AddFileToFolder(items[0]->GetPath(), "addon.xml"); CXBMCTinyXML xml; AddonPtr addon; if (xml.LoadFile(archive) && CAddonMgr::GetInstance().LoadAddonDescriptionFromMemory(xml.RootElement(), addon)) { // set the correct path addon->Props().path = items[0]->GetPath(); addon->Props().icon = URIUtils::AddFileToFolder(items[0]->GetPath(), "icon.png"); // install the addon return DoInstall(addon, RepositoryPtr()); } CEventLog::GetInstance().AddWithNotification(EventPtr(new CNotificationEvent(24045, StringUtils::Format(g_localizeStrings.Get(24143).c_str(), path.c_str()), "special://xbmc/media/icon256x256.png", EventLevel::Error))); return false; }
bool CButtonTranslator::LoadKeymap(const CStdString &keymapPath) { CXBMCTinyXML xmlDoc; CLog::Log(LOGINFO, "Loading %s", keymapPath.c_str()); if (!xmlDoc.LoadFile(keymapPath)) { CLog::Log(LOGERROR, "Error loading keymap: %s, Line %d\n%s", keymapPath.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc()); return false; } TiXmlElement* pRoot = xmlDoc.RootElement(); CStdString strValue = pRoot->Value(); if ( strValue != "keymap") { CLog::Log(LOGERROR, "%s Doesn't contain <keymap>", keymapPath.c_str()); return false; } // run through our window groups TiXmlNode* pWindow = pRoot->FirstChild(); while (pWindow) { if (pWindow->Type() == TiXmlNode::TINYXML_ELEMENT) { int windowID = WINDOW_INVALID; const char *szWindow = pWindow->Value(); if (szWindow) { if (strcmpi(szWindow, "global") == 0) windowID = -1; else windowID = TranslateWindow(szWindow); } MapWindowActions(pWindow, windowID); } pWindow = pWindow->NextSibling(); } return true; }
bool CMediaManager::SaveSources() { CXBMCTinyXML xmlDoc; TiXmlElement xmlRootElement("mediasources"); TiXmlNode *pRoot = xmlDoc.InsertEndChild(xmlRootElement); if (!pRoot) return false; TiXmlElement networkNode("network"); TiXmlNode *pNetworkNode = pRoot->InsertEndChild(networkNode); if (pNetworkNode) { for (std::vector<CNetworkLocation>::iterator it = m_locations.begin(); it != m_locations.end(); ++it) { TiXmlElement locationNode("location"); locationNode.SetAttribute("id", (*it).id); TiXmlText value((*it).path); locationNode.InsertEndChild(value); pNetworkNode->InsertEndChild(locationNode); } } return xmlDoc.SaveFile(MEDIA_SOURCES_XML); }
bool CArtist::Save(TiXmlNode *node, const CStdString &tag, const CStdString& strPath) { if (!node) return false; // we start with a <tag> tag TiXmlElement artistElement(tag.c_str()); TiXmlNode *artist = node->InsertEndChild(artistElement); if (!artist) return false; XMLUtils::SetString(artist, "name", strArtist); XMLUtils::SetString(artist, "musicBrainzArtistID", strMusicBrainzArtistID); XMLUtils::SetStringArray(artist, "genre", genre); XMLUtils::SetStringArray(artist, "style", styles); XMLUtils::SetStringArray(artist, "mood", moods); XMLUtils::SetStringArray(artist, "yearsactive", yearsActive); XMLUtils::SetStringArray(artist, "instruments", instruments); XMLUtils::SetString(artist, "born", strBorn); XMLUtils::SetString(artist, "formed", strFormed); XMLUtils::SetString(artist, "biography", strBiography); XMLUtils::SetString(artist, "died", strDied); XMLUtils::SetString(artist, "disbanded", strDisbanded); if (!thumbURL.m_xml.empty()) { CXBMCTinyXML doc; doc.Parse(thumbURL.m_xml); const TiXmlNode* thumb = doc.FirstChild("thumb"); while (thumb) { artist->InsertEndChild(*thumb); thumb = thumb->NextSibling("thumb"); } } XMLUtils::SetString(artist, "path", strPath); if (fanart.m_xml.size()) { CXBMCTinyXML doc; doc.Parse(fanart.m_xml); artist->InsertEndChild(*doc.RootElement()); } // albums for (vector< pair<CStdString,CStdString> >::const_iterator it = discography.begin(); it != discography.end(); ++it) { // add a <album> tag TiXmlElement cast("album"); TiXmlNode *node = artist->InsertEndChild(cast); TiXmlElement title("title"); TiXmlNode *titleNode = node->InsertEndChild(title); TiXmlText name(it->first); titleNode->InsertEndChild(name); TiXmlElement year("year"); TiXmlNode *yearNode = node->InsertEndChild(year); TiXmlText name2(it->second); yearNode->InsertEndChild(name2); } return true; }
TEST(TestXBMCTinyXML, ParseFromString) { bool retval = false; // scraper results with unescaped & CXBMCTinyXML doc; CStdString data("<details><url function=\"ParseTMDBRating\" " "cache=\"tmdb-en-12244.json\">" "http://api.themoviedb.org/3/movie/12244" "?api_key=57983e31fb435df4df77afb854740ea9" "&language=en???</url></details>"); doc.Parse(data.c_str()); TiXmlNode *root = doc.RootElement(); if (root && root->ValueStr() == "details") { TiXmlElement *url = root->FirstChildElement("url"); if (url && url->FirstChild()) { retval = (url->FirstChild()->ValueStr() == "http://api.themoviedb.org/3/movie/12244?api_key=57983e31fb435df4df77afb854740ea9&language=en???"); } } EXPECT_TRUE(retval); }
bool CFanart::Unpack() { CXBMCTinyXML doc; doc.Parse(m_xml); m_fanart.clear(); TiXmlElement *fanart = doc.FirstChildElement("fanart"); while (fanart) { std::string url = XMLUtils::GetAttribute(fanart, "url"); TiXmlElement *fanartThumb = fanart->FirstChildElement("thumb"); while (fanartThumb) { if (!fanartThumb->NoChildren()) { SFanartData data; if (url.empty()) { data.strImage = fanartThumb->FirstChild()->ValueStr(); data.strPreview = XMLUtils::GetAttribute(fanartThumb, "preview"); } else { data.strImage = URIUtils::AddFileToFolder(url, fanartThumb->FirstChild()->ValueStr()); if (fanartThumb->Attribute("preview")) data.strPreview = URIUtils::AddFileToFolder(url, fanartThumb->Attribute("preview")); } data.strResolution = XMLUtils::GetAttribute(fanartThumb, "dim"); ParseColors(XMLUtils::GetAttribute(fanartThumb, "colors"), data.strColors); m_fanart.push_back(data); } fanartThumb = fanartThumb->NextSiblingElement("thumb"); } fanart = fanart->NextSiblingElement("fanart"); } return true; }
bool CFavouritesDirectory::LoadFavourites(const std::string& strPath, CFileItemList& items) { CXBMCTinyXML doc; if (!doc.LoadFile(strPath)) { CLog::Log(LOGERROR, "Unable to load %s (row %i column %i)", strPath.c_str(), doc.Row(), doc.Column()); return false; } TiXmlElement *root = doc.RootElement(); if (!root || strcmp(root->Value(), "favourites")) { CLog::Log(LOGERROR, "Favourites.xml doesn't contain the <favourites> root element"); return false; } TiXmlElement *favourite = root->FirstChildElement("favourite"); while (favourite) { // format: // <favourite name="Cool Video" thumb="foo.jpg">PlayMedia(c:\videos\cool_video.avi)</favourite> // <favourite name="My Album" thumb="bar.tbn">ActivateWindow(MyMusic,c:\music\my album)</favourite> // <favourite name="Apple Movie Trailers" thumb="path_to_thumb.png">RunScript(special://xbmc/scripts/apple movie trailers/default.py)</favourite> const char *name = favourite->Attribute("name"); const char *thumb = favourite->Attribute("thumb"); if (name && favourite->FirstChild()) { if(!items.Contains(favourite->FirstChild()->Value())) { CFileItemPtr item(new CFileItem(name)); item->SetPath(favourite->FirstChild()->Value()); if (thumb) item->SetArt("thumb", thumb); items.Add(item); } } favourite = favourite->NextSiblingElement("favourite"); } return true; }
bool CFavourites::Save(const CFileItemList &items) { CStdString 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->HasThumbnail()) favNode.SetAttribute("thumb", item->GetThumbnailImage().c_str()); TiXmlText execute(item->GetPath()); favNode.InsertEndChild(execute); rootNode->InsertEndChild(favNode); } URIUtils::AddFileToFolder(g_settings.GetProfileUserDataFolder(), "favourites.xml", favourites); return doc.SaveFile(favourites); }
bool GUIFontManager::OpenFontFile(CXBMCTinyXML& xmlDoc) { // Get the file to load fonts from: CStdString strPath = g_SkinInfo->GetSkinPath("Font.xml", &m_skinResolution); CLog::Log(LOGINFO, "Loading fonts from %s", strPath.c_str()); // first try our preferred file if ( !xmlDoc.LoadFile(strPath) ) { CLog::Log(LOGERROR, "Couldn't load %s", strPath.c_str()); return false; } TiXmlElement* pRootElement = xmlDoc.RootElement(); CStdString strValue = pRootElement->Value(); if (strValue != CStdString("fonts")) { CLog::Log(LOGERROR, "file %s doesnt start with <fonts>", strPath.c_str()); return false; } return true; }
bool CProfileManager::Save() const { const std::string file = PROFILES_FILE; CSingleLock lock(m_critical); CXBMCTinyXML xmlDoc; TiXmlElement xmlRootElement(XML_PROFILES); TiXmlNode *pRoot = xmlDoc.InsertEndChild(xmlRootElement); if (pRoot == nullptr) return false; XMLUtils::SetInt(pRoot, XML_LAST_LOADED, m_currentProfile); XMLUtils::SetBoolean(pRoot, XML_LOGIN_SCREEN, m_usingLoginScreen); XMLUtils::SetInt(pRoot, XML_AUTO_LOGIN, m_autoLoginProfile); XMLUtils::SetInt(pRoot, XML_NEXTID, m_nextProfileId); for (const auto& profile : m_profiles) profile.Save(pRoot); // save the file return xmlDoc.SaveFile(file); }
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::GetInstance().GetProfileUserDataFolder(), "favourites.xml"); return doc.SaveFile(favourites); }
bool CAddon::LoadUserSettings() { if (!SettingsInitialized()) return false; m_hasUserSettings = false; // there are no user settings if (!CFile::Exists(m_userSettingsPath)) { // mark the settings as loaded GetSettings()->SetLoaded(); return true; } CXBMCTinyXML doc; if (!doc.LoadFile(m_userSettingsPath)) { CLog::Log(LOGERROR, "CAddon[%s]: failed to load addon settings from %s", ID().c_str(), m_userSettingsPath.c_str()); return false; } return SettingsFromXML(doc); }
bool CMediaManager::LoadSources() { // clear our location list m_locations.clear(); // load xml file... CXBMCTinyXML xmlDoc; if ( !xmlDoc.LoadFile( MEDIA_SOURCES_XML ) ) return false; TiXmlElement* pRootElement = xmlDoc.RootElement(); if ( !pRootElement || strcmpi(pRootElement->Value(), "mediasources") != 0) { CLog::Log(LOGERROR, "Error loading %s, Line %d (%s)", MEDIA_SOURCES_XML, xmlDoc.ErrorRow(), xmlDoc.ErrorDesc()); return false; } // load the <network> block TiXmlNode *pNetwork = pRootElement->FirstChild("network"); if (pNetwork) { TiXmlElement *pLocation = pNetwork->FirstChildElement("location"); while (pLocation) { CNetworkLocation location; pLocation->Attribute("id", &location.id); if (pLocation->FirstChild()) { location.path = pLocation->FirstChild()->Value(); m_locations.push_back(location); } pLocation = pLocation->NextSiblingElement("location"); } } return true; }
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 CGUIWindow::LoadXML(const CStdString &strPath, const CStdString &strLowerPath) { // load window xml if we don't have it stored yet if (!m_windowXMLRootElement) { CXBMCTinyXML xmlDoc; std::string strPathLower = strPath; StringUtils::ToLower(strPathLower); if (!xmlDoc.LoadFile(strPath) && !xmlDoc.LoadFile(strPathLower) && !xmlDoc.LoadFile(strLowerPath)) { CLog::Log(LOGERROR, "unable to load:%s, Line %d\n%s", strPath.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc()); SetID(WINDOW_INVALID); return false; } m_windowXMLRootElement = (TiXmlElement*)xmlDoc.RootElement()->Clone(); } else CLog::Log(LOGDEBUG, "Using already stored xml root node for %s", strPath.c_str()); return Load(m_windowXMLRootElement); }
bool CEdl::ReadBeyondTV(const std::string& strMovie) { Clear(); std::string beyondTVFilename(URIUtils::ReplaceExtension(strMovie, URIUtils::GetExtension(strMovie) + ".chapters.xml")); if (!CFile::Exists(beyondTVFilename)) return false; CXBMCTinyXML xmlDoc; if (!xmlDoc.LoadFile(beyondTVFilename)) { CLog::Log(LOGERROR, "%s - Could not load Beyond TV file: %s. %s", __FUNCTION__, beyondTVFilename.c_str(), xmlDoc.ErrorDesc()); return false; } if (xmlDoc.Error()) { CLog::Log(LOGERROR, "%s - Could not parse Beyond TV file: %s. %s", __FUNCTION__, beyondTVFilename.c_str(), xmlDoc.ErrorDesc()); return false; } TiXmlElement *pRoot = xmlDoc.RootElement(); if (!pRoot || strcmp(pRoot->Value(), "cutlist")) { CLog::Log(LOGERROR, "%s - Invalid Beyond TV file: %s. Expected root node to be <cutlist>", __FUNCTION__, beyondTVFilename.c_str()); return false; } bool bValid = true; TiXmlElement *pRegion = pRoot->FirstChildElement("Region"); while (bValid && pRegion) { TiXmlElement *pStart = pRegion->FirstChildElement("start"); TiXmlElement *pEnd = pRegion->FirstChildElement("end"); if (pStart && pEnd && pStart->FirstChild() && pEnd->FirstChild()) { /* * Need to divide the start and end times by a factor of 10,000 to get msec. * E.g. <start comment="00:02:44.9980867">1649980867</start> * * Use atof so doesn't overflow 32 bit float or integer / long. * E.g. <end comment="0:26:49.0000009">16090090000</end> * * Don't use atoll even though it is more correct as it isn't natively supported by * Visual Studio. * * atof() returns 0 if there were any problems and will subsequently be rejected in AddCut(). */ Cut cut; cut.start = (int64_t)(atof(pStart->FirstChild()->Value()) / 10000); cut.end = (int64_t)(atof(pEnd->FirstChild()->Value()) / 10000); cut.action = COMM_BREAK; bValid = AddCut(cut); } else bValid = false; pRegion = pRegion->NextSiblingElement("Region"); } if (!bValid) { CLog::Log(LOGERROR, "%s - Invalid Beyond TV file: %s. Clearing any valid commercial breaks found.", __FUNCTION__, beyondTVFilename.c_str()); Clear(); return false; } else if (HasCut()) { CLog::Log(LOGDEBUG, "%s - Read %" PRIuS" commercial breaks from Beyond TV file: %s", __FUNCTION__, m_vecCuts.size(), beyondTVFilename.c_str()); return true; } else { CLog::Log(LOGDEBUG, "%s - No commercial breaks found in Beyond TV file: %s", __FUNCTION__, beyondTVFilename.c_str()); return false; } }
bool CDAVDirectory::GetDirectory(const CStdString& strPath, CFileItemList &items) { CCurlFile dav; CURL url(strPath); CStdString strRequest = "PROPFIND"; dav.SetCustomRequest(strRequest); dav.SetMimeType("text/xml; charset=\"utf-8\""); dav.SetRequestHeader("depth", 1); dav.SetPostData( "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" " <D:propfind xmlns:D=\"DAV:\">" " <D:prop>" " <D:resourcetype/>" " <D:getcontentlength/>" " <D:getlastmodified/>" " <D:creationdate/>" " <D:displayname/>" " </D:prop>" " </D:propfind>"); if (!dav.Open(url)) { CLog::Log(LOGERROR, "%s - Unable to get dav directory (%s)", __FUNCTION__, strPath.c_str()); return false; } CStdString strResponse; dav.ReadData(strResponse); CXBMCTinyXML davResponse; davResponse.Parse(strResponse.c_str()); if (!davResponse.Parse(strResponse)) { CLog::Log(LOGERROR, "%s - Unable to process dav directory (%s)", __FUNCTION__, strPath.c_str()); dav.Close(); return false; } TiXmlNode *pChild; // Iterate over all responses for (pChild = davResponse.RootElement()->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) { if (CDAVCommon::ValueWithoutNamespace(pChild, "response")) { CFileItem item; ParseResponse(pChild->ToElement(), item); CURL url2(strPath); CURL url3(item.GetPath()); CStdString itemPath(URIUtils::AddFileToFolder(url2.GetWithoutFilename(), url3.GetFileName())); if (item.GetLabel().IsEmpty()) { CStdString name(itemPath); URIUtils::RemoveSlashAtEnd(name); CURL::Decode(name); item.SetLabel(URIUtils::GetFileName(name)); } if (item.m_bIsFolder) URIUtils::AddSlashAtEnd(itemPath); // Add back protocol options if (!url2.GetProtocolOptions().IsEmpty()) itemPath += "|" + url2.GetProtocolOptions(); item.SetPath(itemPath); if (!item.GetPath().Equals(strPath)) { CFileItemPtr pItem(new CFileItem(item)); items.Add(pItem); } } } dav.Close(); return true; }
bool CRSSDirectory::GetDirectory(const CURL& url, CFileItemList &items) { const std::string pathToUrl(url.Get()); std::string strPath(pathToUrl); URIUtils::RemoveSlashAtEnd(strPath); std::map<std::string,CDateTime>::iterator it; items.SetPath(strPath); CSingleLock lock(m_section); if ((it=m_cache.find(strPath)) != m_cache.end()) { if (it->second > CDateTime::GetCurrentDateTime() && items.Load()) return true; m_cache.erase(it); } lock.Leave(); CXBMCTinyXML xmlDoc; if (!xmlDoc.LoadFile(strPath)) { CLog::Log(LOGERROR,"failed to load xml from <%s>. error: <%d>", strPath.c_str(), xmlDoc.ErrorId()); return false; } if (xmlDoc.Error()) { CLog::Log(LOGERROR,"error parsing xml doc from <%s>. error: <%d>", strPath.c_str(), xmlDoc.ErrorId()); return false; } TiXmlElement* rssXmlNode = xmlDoc.RootElement(); if (!rssXmlNode) return false; TiXmlHandle docHandle( &xmlDoc ); TiXmlElement* channelXmlNode = docHandle.FirstChild( "rss" ).FirstChild( "channel" ).Element(); if (channelXmlNode) ParseItem(&items, channelXmlNode, pathToUrl); else return false; TiXmlElement* child = NULL; for (child = channelXmlNode->FirstChildElement("item"); child; child = child->NextSiblingElement()) { // Create new item, CFileItemPtr item(new CFileItem()); ParseItem(item.get(), child, pathToUrl); item->SetProperty("isrss", "1"); // Use channel image if item doesn't have one if (!item->HasArt("thumb") && items.HasArt("thumb")) item->SetArt("thumb", items.GetArt("thumb")); if (!item->GetPath().empty()) items.Add(item); } items.AddSortMethod(SortByNone , 231, LABEL_MASKS("%L", "%D", "%L", "")); // FileName, Duration | Foldername, empty items.AddSortMethod(SortByLabel , 551, LABEL_MASKS("%L", "%D", "%L", "")); // FileName, Duration | Foldername, empty items.AddSortMethod(SortBySize , 553, LABEL_MASKS("%L", "%I", "%L", "%I")); // FileName, Size | Foldername, Size items.AddSortMethod(SortByDate , 552, LABEL_MASKS("%L", "%J", "%L", "%J")); // FileName, Date | Foldername, Date CDateTime time = CDateTime::GetCurrentDateTime(); int mins = 60; TiXmlElement* ttl = docHandle.FirstChild("rss").FirstChild("ttl").Element(); if (ttl) mins = strtol(ttl->FirstChild()->Value(),NULL,10); time += CDateTimeSpan(0,0,mins,0); items.SetPath(strPath); items.Save(); CSingleLock lock2(m_section); m_cache.insert(make_pair(strPath,time)); return true; }
bool CPlayListASX::LoadData(istream& stream) { CLog::Log(LOGNOTICE, "Parsing ASX"); if(stream.peek() == '[') { return LoadAsxIniInfo(stream); } else { CXBMCTinyXML xmlDoc; stream >> xmlDoc; if (xmlDoc.Error()) { CLog::Log(LOGERROR, "Unable to parse ASX info Error: %s", xmlDoc.ErrorDesc()); return false; } TiXmlElement *pRootElement = xmlDoc.RootElement(); // lowercase every element TiXmlNode *pNode = pRootElement; TiXmlNode *pChild = NULL; CStdString value; value = pNode->Value(); value.ToLower(); pNode->SetValue(value); while(pNode) { pChild = pNode->IterateChildren(pChild); if(pChild) { if (pChild->Type() == TiXmlNode::TINYXML_ELEMENT) { value = pChild->Value(); value.ToLower(); pChild->SetValue(value); TiXmlAttribute* pAttr = pChild->ToElement()->FirstAttribute(); while(pAttr) { value = pAttr->Name(); value.ToLower(); pAttr->SetName(value); pAttr = pAttr->Next(); } } pNode = pChild; pChild = NULL; continue; } pChild = pNode; pNode = pNode->Parent(); } CStdString roottitle = ""; TiXmlElement *pElement = pRootElement->FirstChildElement(); while (pElement) { value = pElement->Value(); if (value == "title") { roottitle = pElement->GetText(); } else if (value == "entry") { CStdString title(roottitle); TiXmlElement *pRef = pElement->FirstChildElement("ref"); TiXmlElement *pTitle = pElement->FirstChildElement("title"); if(pTitle) title = pTitle->GetText(); while (pRef) { // multiple references may apear for one entry // duration may exist on this level too value = pRef->Attribute("href"); if (value != "") { if(title.IsEmpty()) title = value; CLog::Log(LOGINFO, "Adding element %s, %s", title.c_str(), value.c_str()); CFileItemPtr newItem(new CFileItem(title)); newItem->SetPath(value); Add(newItem); } pRef = pRef->NextSiblingElement("ref"); } } else if (value == "entryref") { value = pElement->Attribute("href"); if (value != "") { // found an entryref, let's try loading that url auto_ptr<CPlayList> playlist(CPlayListFactory::Create(value)); if (NULL != playlist.get()) if (playlist->Load(value)) Add(*playlist); } } pElement = pElement->NextSiblingElement(); } } return true; }
// \brief Load the config file (sounds.xml) for nav sounds // Can be located in a folder "sounds" in the skin or from a // subfolder of the folder "sounds" in the root directory of // xbmc bool CGUIAudioManager::Load() { CSingleLock lock(m_cs); UnLoad(); if (CSettings::Get().GetString("lookandfeel.soundskin")=="OFF") return true; else Enable(true); std::string soundSkin = CSettings::Get().GetString("lookandfeel.soundskin"); if (soundSkin == "SKINDEFAULT") { m_strMediaDir = URIUtils::AddFileToFolder(g_SkinInfo->Path(), "sounds"); } else { //check if sound skin is located in home, otherwise fallback to built-ins m_strMediaDir = URIUtils::AddFileToFolder("special://home/sounds", soundSkin); if (!XFILE::CDirectory::Exists(m_strMediaDir)) m_strMediaDir = URIUtils::AddFileToFolder("special://xbmc/sounds", soundSkin); } std::string strSoundsXml = URIUtils::AddFileToFolder(m_strMediaDir, "sounds.xml"); // Load our xml file CXBMCTinyXML xmlDoc; CLog::Log(LOGINFO, "Loading %s", strSoundsXml.c_str()); // Load the config file if (!xmlDoc.LoadFile(strSoundsXml)) { CLog::Log(LOGNOTICE, "%s, Line %d\n%s", strSoundsXml.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc()); return false; } TiXmlElement* pRoot = xmlDoc.RootElement(); std::string strValue = pRoot->Value(); if ( strValue != "sounds") { CLog::Log(LOGNOTICE, "%s Doesn't contain <sounds>", strSoundsXml.c_str()); return false; } // Load sounds for actions TiXmlElement* pActions = pRoot->FirstChildElement("actions"); if (pActions) { TiXmlNode* pAction = pActions->FirstChild("action"); while (pAction) { TiXmlNode* pIdNode = pAction->FirstChild("name"); int id = 0; // action identity if (pIdNode && pIdNode->FirstChild()) { CButtonTranslator::TranslateActionString(pIdNode->FirstChild()->Value(), id); } TiXmlNode* pFileNode = pAction->FirstChild("file"); std::string strFile; if (pFileNode && pFileNode->FirstChild()) strFile += pFileNode->FirstChild()->Value(); if (id > 0 && !strFile.empty()) { std::string filename = URIUtils::AddFileToFolder(m_strMediaDir, strFile); IAESound *sound = LoadSound(filename); if (sound) m_actionSoundMap.insert(pair<int, IAESound *>(id, sound)); } pAction = pAction->NextSibling(); } } // Load window specific sounds TiXmlElement* pWindows = pRoot->FirstChildElement("windows"); if (pWindows) { TiXmlNode* pWindow = pWindows->FirstChild("window"); while (pWindow) { int id = 0; TiXmlNode* pIdNode = pWindow->FirstChild("name"); if (pIdNode) { if (pIdNode->FirstChild()) id = CButtonTranslator::TranslateWindow(pIdNode->FirstChild()->Value()); } CWindowSounds sounds; sounds.initSound = LoadWindowSound(pWindow, "activate" ); sounds.deInitSound = LoadWindowSound(pWindow, "deactivate"); if (id > 0) m_windowSoundMap.insert(pair<int, CWindowSounds>(id, sounds)); pWindow = pWindow->NextSibling(); } } return true; }
bool CLangInfo::Load(const CStdString& strFileName) { SetDefaults(); CXBMCTinyXML xmlDoc; if (!xmlDoc.LoadFile(strFileName)) { CLog::Log(LOGERROR, "unable to load %s: %s at line %d", strFileName.c_str(), xmlDoc.ErrorDesc(), xmlDoc.ErrorRow()); return false; } TiXmlElement* pRootElement = xmlDoc.RootElement(); CStdString strValue = pRootElement->Value(); if (strValue != CStdString("language")) { CLog::Log(LOGERROR, "%s Doesn't contain <language>", strFileName.c_str()); return false; } if (pRootElement->Attribute("locale")) m_defaultRegion.m_strLangLocaleName = pRootElement->Attribute("locale"); #ifdef _WIN32 // Windows need 3 chars isolang code if (m_defaultRegion.m_strLangLocaleName.length() == 2) { if (! g_LangCodeExpander.ConvertTwoToThreeCharCode(m_defaultRegion.m_strLangLocaleName, m_defaultRegion.m_strLangLocaleName, true)) m_defaultRegion.m_strLangLocaleName = ""; } if (!g_LangCodeExpander.ConvertWindowsToGeneralCharCode(m_defaultRegion.m_strLangLocaleName, m_languageCodeGeneral)) m_languageCodeGeneral = ""; #else if (m_defaultRegion.m_strLangLocaleName.length() != 3) { if (!g_LangCodeExpander.ConvertToThreeCharCode(m_languageCodeGeneral, m_defaultRegion.m_strLangLocaleName)) m_languageCodeGeneral = ""; } else m_languageCodeGeneral = m_defaultRegion.m_strLangLocaleName; #endif const TiXmlNode *pCharSets = pRootElement->FirstChild("charsets"); if (pCharSets && !pCharSets->NoChildren()) { const TiXmlNode *pGui = pCharSets->FirstChild("gui"); if (pGui && !pGui->NoChildren()) { CStdString strForceUnicodeFont = ((TiXmlElement*) pGui)->Attribute("unicodefont"); if (strForceUnicodeFont.Equals("true")) m_defaultRegion.m_forceUnicodeFont=true; m_defaultRegion.m_strGuiCharSet=pGui->FirstChild()->Value(); } const TiXmlNode *pSubtitle = pCharSets->FirstChild("subtitle"); if (pSubtitle && !pSubtitle->NoChildren()) m_defaultRegion.m_strSubtitleCharSet=pSubtitle->FirstChild()->Value(); } const TiXmlNode *pDVD = pRootElement->FirstChild("dvd"); if (pDVD && !pDVD->NoChildren()) { const TiXmlNode *pMenu = pDVD->FirstChild("menu"); if (pMenu && !pMenu->NoChildren()) m_defaultRegion.m_strDVDMenuLanguage=pMenu->FirstChild()->Value(); const TiXmlNode *pAudio = pDVD->FirstChild("audio"); if (pAudio && !pAudio->NoChildren()) m_defaultRegion.m_strDVDAudioLanguage=pAudio->FirstChild()->Value(); const TiXmlNode *pSubtitle = pDVD->FirstChild("subtitle"); if (pSubtitle && !pSubtitle->NoChildren()) m_defaultRegion.m_strDVDSubtitleLanguage=pSubtitle->FirstChild()->Value(); } const TiXmlNode *pRegions = pRootElement->FirstChild("regions"); if (pRegions && !pRegions->NoChildren()) { const TiXmlElement *pRegion=pRegions->FirstChildElement("region"); while (pRegion) { CRegion region(m_defaultRegion); region.m_strName=pRegion->Attribute("name"); if (region.m_strName.IsEmpty()) region.m_strName="N/A"; if (pRegion->Attribute("locale")) region.m_strRegionLocaleName = pRegion->Attribute("locale"); #ifdef _WIN32 // Windows need 3 chars regions code if (region.m_strRegionLocaleName.length() == 2) { if (! g_LangCodeExpander.ConvertLinuxToWindowsRegionCodes(region.m_strRegionLocaleName, region.m_strRegionLocaleName)) region.m_strRegionLocaleName = ""; } #endif const TiXmlNode *pDateLong=pRegion->FirstChild("datelong"); if (pDateLong && !pDateLong->NoChildren()) region.m_strDateFormatLong=pDateLong->FirstChild()->Value(); const TiXmlNode *pDateShort=pRegion->FirstChild("dateshort"); if (pDateShort && !pDateShort->NoChildren()) region.m_strDateFormatShort=pDateShort->FirstChild()->Value(); const TiXmlElement *pTime=pRegion->FirstChildElement("time"); if (pTime && !pTime->NoChildren()) { region.m_strTimeFormat=pTime->FirstChild()->Value(); region.m_strMeridiemSymbols[MERIDIEM_SYMBOL_AM]=pTime->Attribute("symbolAM"); region.m_strMeridiemSymbols[MERIDIEM_SYMBOL_PM]=pTime->Attribute("symbolPM"); } const TiXmlNode *pTempUnit=pRegion->FirstChild("tempunit"); if (pTempUnit && !pTempUnit->NoChildren()) region.SetTempUnit(pTempUnit->FirstChild()->Value()); const TiXmlNode *pSpeedUnit=pRegion->FirstChild("speedunit"); if (pSpeedUnit && !pSpeedUnit->NoChildren()) region.SetSpeedUnit(pSpeedUnit->FirstChild()->Value()); const TiXmlNode *pTimeZone=pRegion->FirstChild("timezone"); if (pTimeZone && !pTimeZone->NoChildren()) region.SetTimeZone(pTimeZone->FirstChild()->Value()); m_regions.insert(PAIR_REGIONS(region.m_strName, region)); pRegion=pRegion->NextSiblingElement("region"); } const CStdString& strName=g_guiSettings.GetString("locale.country"); SetCurrentRegion(strName); } LoadTokens(pRootElement->FirstChild("sorttokens"),g_advancedSettings.m_vecTokens); return true; }
bool CScraperUrl::Get(const SUrlEntry& scrURL, std::string& strHTML, XFILE::CCurlFile& http, const CStdString& cacheContext) { CURL url(scrURL.m_url); http.SetReferer(scrURL.m_spoof); CStdString strCachePath; if (scrURL.m_isgz) http.SetContentEncoding("gzip"); if (!scrURL.m_cache.empty()) { strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "scrapers/" + cacheContext + "/" + scrURL.m_cache); if (XFILE::CFile::Exists(strCachePath)) { XFILE::CFile file; XFILE::auto_buffer buffer; if (file.LoadFile(strCachePath, buffer)) { strHTML.assign(buffer.get(), buffer.length()); return true; } } } CStdString strHTML1(strHTML); if (scrURL.m_post) { CStdString strOptions = url.GetOptions(); strOptions = strOptions.substr(1); url.SetOptions(""); if (!http.Post(url.Get(), strOptions, strHTML1)) return false; } else if (!http.Get(url.Get(), strHTML1)) return false; strHTML = strHTML1; std::string mimeType(http.GetMimeType()); CMime::EFileType ftype = CMime::GetFileTypeFromMime(mimeType); if (ftype == CMime::FileTypeUnknown) ftype = CMime::GetFileTypeFromContent(strHTML); if (ftype == CMime::FileTypeZip || ftype == CMime::FileTypeGZip) { XFILE::CZipFile file; std::string strBuffer; int iSize = file.UnpackFromMemory(strBuffer,strHTML,scrURL.m_isgz); // FIXME: use FileTypeGZip instead of scrURL.m_isgz? if (iSize > 0) { strHTML = strBuffer; CLog::Log(LOGDEBUG, "%s: Archive \"%s\" was unpacked in memory", __FUNCTION__, scrURL.m_url.c_str()); } else CLog::Log(LOGWARNING, "%s: \"%s\" looks like archive, but cannot be unpacked", __FUNCTION__, scrURL.m_url.c_str()); } std::string reportedCharset(http.GetServerReportedCharset()); if (ftype == CMime::FileTypeHtml) { std::string realHtmlCharset, converted; if (!CCharsetDetection::ConvertHtmlToUtf8(strHTML, converted, reportedCharset, realHtmlCharset)) CLog::Log(LOGWARNING, "%s: Can't find precise charset for HTML \"%s\", using \"%s\" as fallback", __FUNCTION__, scrURL.m_url.c_str(), realHtmlCharset.c_str()); else CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for HTML \"%s\"", __FUNCTION__, realHtmlCharset.c_str(), scrURL.m_url.c_str()); strHTML = converted; } else if (ftype == CMime::FileTypeXml) { CXBMCTinyXML xmlDoc; xmlDoc.Parse(strHTML, reportedCharset); std::string realXmlCharset(xmlDoc.GetUsedCharset()); if (!realXmlCharset.empty()) { CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for XML \"%s\"", __FUNCTION__, realXmlCharset.c_str(), scrURL.m_url.c_str()); std::string converted; g_charsetConverter.ToUtf8(realXmlCharset, strHTML, converted); strHTML = converted; } } else if (ftype == CMime::FileTypePlainText || StringUtils::CompareNoCase(mimeType.substr(0, 5), "text/") == 0) { std::string realTextCharset, converted; CCharsetDetection::ConvertPlainTextToUtf8(strHTML, converted, reportedCharset, realTextCharset); strHTML = converted; if (reportedCharset != realTextCharset) CLog::Log(LOGWARNING, "%s: Using \"%s\" charset for plain text \"%s\" instead of server reported \"%s\" charset", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str(), reportedCharset.c_str()); else CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for plain text \"%s\"", __FUNCTION__, realTextCharset.c_str(), scrURL.m_url.c_str()); } else if (!reportedCharset.empty()) { CLog::Log(LOGDEBUG, "%s: Using \"%s\" charset for \"%s\"", __FUNCTION__, reportedCharset.c_str(), scrURL.m_url.c_str()); if (reportedCharset != "UTF-8") { std::string converted; g_charsetConverter.ToUtf8(reportedCharset, strHTML, converted); strHTML = converted; } } else CLog::Log(LOGDEBUG, "%s: Using content of \"%s\" as binary or text with \"UTF-8\" charset", __FUNCTION__, scrURL.m_url.c_str()); if (!scrURL.m_cache.empty()) { CStdString strCachePath = URIUtils::AddFileToFolder(g_advancedSettings.m_cachePath, "scrapers/" + cacheContext + "/" + scrURL.m_cache); XFILE::CFile file; if (file.OpenForWrite(strCachePath,true)) file.Write(strHTML.data(),strHTML.size()); file.Close(); } return true; }
bool CScrobbler::LoadJournal() { int journalVersion = 0; SubmissionJournalEntry entry; CXBMCTinyXML xmlDoc; CStdString JournalFileName = GetJournalFileName(); CSingleLock lock(m_queueLock); m_vecSubmissionQueue.clear(); if (!xmlDoc.LoadFile(JournalFileName)) { CLog::Log(LOGDEBUG, "%s: %s, Line %d (%s)", m_strLogPrefix.c_str(), JournalFileName.c_str(), xmlDoc.ErrorRow(), xmlDoc.ErrorDesc()); return false; } TiXmlElement *pRoot = xmlDoc.RootElement(); if (strcmpi(pRoot->Value(), "asjournal") != 0) { CLog::Log(LOGDEBUG, "%s: %s missing <asjournal>", m_strLogPrefix.c_str(), JournalFileName.c_str()); return false; } if (pRoot->Attribute("version")) journalVersion = atoi(pRoot->Attribute("version")); TiXmlNode *pNode = pRoot->FirstChild("entry"); for (; pNode; pNode = pNode->NextSibling("entry")) { entry.Clear(); XMLUtils::GetString(pNode, "artist", entry.strArtist); XMLUtils::GetString(pNode, "album", entry.strAlbum); XMLUtils::GetString(pNode, "title", entry.strTitle); XMLUtils::GetString(pNode, "length", entry.strLength); entry.length = atoi(entry.strLength.c_str()); XMLUtils::GetString(pNode, "starttime", entry.strStartTime); XMLUtils::GetString(pNode, "musicbrainzid", entry.strMusicBrainzID); if (journalVersion > 0) { XMLUtils::GetString(pNode, "tracknum", entry.strTrackNum); XMLUtils::GetString(pNode, "source", entry.strSource); XMLUtils::GetString(pNode, "rating", entry.strRating); } else { // Update from journal v0 // Convert start time stamp struct tm starttm; time_t startt; if (!strptime(entry.strStartTime.c_str(), "%Y-%m-%d %H:%M:%S", &starttm)) continue; if ((startt = mktime(&starttm)) == -1) continue; entry.strStartTime.Format("%d", startt); // url encode entries CURL::Encode(entry.strArtist); CURL::Encode(entry.strTitle); CURL::Encode(entry.strAlbum); CURL::Encode(entry.strMusicBrainzID); } m_vecSubmissionQueue.push_back(entry); } CLog::Log(LOGDEBUG, "%s: Journal loaded with %"PRIuS" entries.", m_strLogPrefix.c_str(), m_vecSubmissionQueue.size()); return !m_vecSubmissionQueue.empty(); }
bool CProfilesManager::LoadProfile(size_t index) { CSingleLock lock(m_critical); // check if the index is valid or not if (index >= m_profiles.size()) return false; // check if the profile is already active if (m_currentProfile == index) return true; // save any settings of the currently used skin if (g_SkinInfo != nullptr) g_SkinInfo->SaveSettings(); // unload any old settings CSettings::GetInstance().Unload(); SetCurrentProfileId(index); // load the new settings if (!CSettings::GetInstance().Load()) { CLog::Log(LOGFATAL, "CProfilesManager: unable to load settings for profile \"%s\"", m_profiles.at(index).getName().c_str()); return false; } CSettings::GetInstance().SetLoaded(); CreateProfileFolders(); CDatabaseManager::GetInstance().Initialize(); CButtonTranslator::GetInstance().Load(true); CInputManager::GetInstance().SetMouseEnabled(CSettings::GetInstance().GetBool(CSettings::SETTING_INPUT_ENABLEMOUSE)); g_infoManager.ResetCache(); g_infoManager.ResetLibraryBools(); if (m_currentProfile != 0) { CXBMCTinyXML doc; if (doc.LoadFile(URIUtils::AddFileToFolder(GetUserDataFolder(), "guisettings.xml"))) { CSettings::GetInstance().LoadSetting(doc.RootElement(), CSettings::SETTING_MASTERLOCK_MAXRETRIES); CSettings::GetInstance().LoadSetting(doc.RootElement(), CSettings::SETTING_MASTERLOCK_STARTUPLOCK); } } CPasswordManager::GetInstance().Clear(); // to set labels - shares are reloaded #if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE) MEDIA_DETECT::CDetectDVDMedia::UpdateState(); #endif // init windows CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_WINDOW_RESET); g_windowManager.SendMessage(msg); CUtil::DeleteDirectoryCache(); g_directoryCache.Clear(); return true; }
void CWakeOnAccess::LoadFromXML() { bool enabled = CSettings::Get().GetBool("powermanagement.wakeonaccess"); SetEnabled(enabled); CXBMCTinyXML xmlDoc; if (!xmlDoc.LoadFile(GetSettingFile())) { CLog::Log(LOGNOTICE, "%s - unable to load:%s", __FUNCTION__, GetSettingFile().c_str()); return; } TiXmlElement* pRootElement = xmlDoc.RootElement(); if (strcmpi(pRootElement->Value(), "onaccesswakeup")) { CLog::Log(LOGERROR, "%s - XML file %s doesnt contain <onaccesswakeup>", __FUNCTION__, GetSettingFile().c_str()); return; } m_entries.clear(); CLog::Log(LOGNOTICE,"WakeOnAccess - Load settings :"); int tmp; if (XMLUtils::GetInt(pRootElement, "netinittimeout", tmp, 0, 5 * 60)) m_netinit_sec = tmp; CLog::Log(LOGNOTICE," -Network init timeout : [%d] sec", m_netinit_sec); if (XMLUtils::GetInt(pRootElement, "netsettletime", tmp, 0, 5 * 1000)) m_netsettle_ms = tmp; CLog::Log(LOGNOTICE," -Network settle time : [%d] ms", m_netsettle_ms); const TiXmlNode* pWakeUp = pRootElement->FirstChildElement("wakeup"); while (pWakeUp) { WakeUpEntry entry; CStdString strtmp; if (XMLUtils::GetString(pWakeUp, "host", strtmp)) entry.host = strtmp; if (XMLUtils::GetString(pWakeUp, "mac", strtmp)) entry.mac = strtmp; if (entry.host.empty()) CLog::Log(LOGERROR, "%s - Missing <host> tag or it's empty", __FUNCTION__); else if (entry.mac.empty()) CLog::Log(LOGERROR, "%s - Missing <mac> tag or it's empty", __FUNCTION__); else { if (XMLUtils::GetInt(pWakeUp, "pingport", tmp, 0, USHRT_MAX)) entry.ping_port = (unsigned short) tmp; if (XMLUtils::GetInt(pWakeUp, "pingmode", tmp, 0, USHRT_MAX)) entry.ping_mode = (unsigned short) tmp; if (XMLUtils::GetInt(pWakeUp, "timeout", tmp, 10, 12 * 60 * 60)) entry.timeout.SetDateTimeSpan (0, 0, 0, tmp); if (XMLUtils::GetInt(pWakeUp, "waitonline", tmp, 0, 10 * 60)) // max 10 minutes entry.wait_online1_sec = tmp; if (XMLUtils::GetInt(pWakeUp, "waitonline2", tmp, 0, 10 * 60)) // max 10 minutes entry.wait_online2_sec = tmp; if (XMLUtils::GetInt(pWakeUp, "waitservices", tmp, 0, 5 * 60)) // max 5 minutes entry.wait_services_sec = tmp; CLog::Log(LOGNOTICE," Registering wakeup entry:"); CLog::Log(LOGNOTICE," HostName : %s", entry.host.c_str()); CLog::Log(LOGNOTICE," MacAddress : %s", entry.mac.c_str()); CLog::Log(LOGNOTICE," PingPort : %d", entry.ping_port); CLog::Log(LOGNOTICE," PingMode : %d", entry.ping_mode); CLog::Log(LOGNOTICE," Timeout : %d (sec)", GetTotalSeconds(entry.timeout)); CLog::Log(LOGNOTICE," WaitForOnline : %d (sec)", entry.wait_online1_sec); CLog::Log(LOGNOTICE," WaitForOnlineEx : %d (sec)", entry.wait_online2_sec); CLog::Log(LOGNOTICE," WaitForServices : %d (sec)", entry.wait_services_sec); m_entries.push_back(entry); } pWakeUp = pWakeUp->NextSiblingElement("wakeup"); // get next one } }
void CAdvancedSettings::ParseSettingsFile(const CStdString &file) { CXBMCTinyXML advancedXML; if (!CFile::Exists(file)) { CLog::Log(LOGNOTICE, "No settings file to load (%s)", file.c_str()); return; } if (!advancedXML.LoadFile(file)) { CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", file.c_str(), advancedXML.ErrorRow(), advancedXML.ErrorDesc()); return; } TiXmlElement *pRootElement = advancedXML.RootElement(); if (!pRootElement || strcmpi(pRootElement->Value(),"advancedsettings") != 0) { CLog::Log(LOGERROR, "Error loading %s, no <advancedsettings> node", file.c_str()); return; } // succeeded - tell the user it worked CLog::Log(LOGNOTICE, "Loaded settings file from %s", file.c_str()); // Dump contents of AS.xml to debug log TiXmlPrinter printer; printer.SetLineBreak("\n"); printer.SetIndent(" "); advancedXML.Accept(&printer); CLog::Log(LOGNOTICE, "Contents of %s are...\n%s", file.c_str(), printer.CStr()); TiXmlElement *pElement = pRootElement->FirstChildElement("audio"); if (pElement) { XMLUtils::GetFloat(pElement, "ac3downmixgain", m_ac3Gain, -96.0f, 96.0f); XMLUtils::GetInt(pElement, "headroom", m_audioHeadRoom, 0, 12); XMLUtils::GetString(pElement, "defaultplayer", m_audioDefaultPlayer); // 101 on purpose - can be used to never automark as watched XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_audioPlayCountMinimumPercent, 0.0f, 101.0f); XMLUtils::GetBoolean(pElement, "usetimeseeking", m_musicUseTimeSeeking); XMLUtils::GetInt(pElement, "timeseekforward", m_musicTimeSeekForward, 0, 6000); XMLUtils::GetInt(pElement, "timeseekbackward", m_musicTimeSeekBackward, -6000, 0); XMLUtils::GetInt(pElement, "timeseekforwardbig", m_musicTimeSeekForwardBig, 0, 6000); XMLUtils::GetInt(pElement, "timeseekbackwardbig", m_musicTimeSeekBackwardBig, -6000, 0); XMLUtils::GetInt(pElement, "percentseekforward", m_musicPercentSeekForward, 0, 100); XMLUtils::GetInt(pElement, "percentseekbackward", m_musicPercentSeekBackward, -100, 0); XMLUtils::GetInt(pElement, "percentseekforwardbig", m_musicPercentSeekForwardBig, 0, 100); XMLUtils::GetInt(pElement, "percentseekbackwardbig", m_musicPercentSeekBackwardBig, -100, 0); XMLUtils::GetInt(pElement, "resample", m_musicResample, 0, 192000); TiXmlElement* pAudioExcludes = pElement->FirstChildElement("excludefromlisting"); if (pAudioExcludes) GetCustomRegexps(pAudioExcludes, m_audioExcludeFromListingRegExps); pAudioExcludes = pElement->FirstChildElement("excludefromscan"); if (pAudioExcludes) GetCustomRegexps(pAudioExcludes, m_audioExcludeFromScanRegExps); XMLUtils::GetString(pElement, "audiohost", m_audioHost); XMLUtils::GetBoolean(pElement, "applydrc", m_audioApplyDrc); XMLUtils::GetBoolean(pElement, "dvdplayerignoredtsinwav", m_dvdplayerIgnoreDTSinWAV); XMLUtils::GetFloat(pElement, "limiterhold", m_limiterHold, 0.0f, 100.0f); XMLUtils::GetFloat(pElement, "limiterrelease", m_limiterRelease, 0.001f, 100.0f); } pElement = pRootElement->FirstChildElement("karaoke"); if (pElement) { XMLUtils::GetFloat(pElement, "syncdelaycdg", m_karaokeSyncDelayCDG, -3.0f, 3.0f); // keep the old name for comp XMLUtils::GetFloat(pElement, "syncdelaylrc", m_karaokeSyncDelayLRC, -3.0f, 3.0f); XMLUtils::GetBoolean(pElement, "alwaysreplacegenre", m_karaokeChangeGenreForKaraokeSongs ); XMLUtils::GetBoolean(pElement, "storedelay", m_karaokeKeepDelay ); XMLUtils::GetInt(pElement, "autoassignstartfrom", m_karaokeStartIndex, 1, 2000000000); XMLUtils::GetBoolean(pElement, "nocdgbackground", m_karaokeAlwaysEmptyOnCdgs ); XMLUtils::GetBoolean(pElement, "lookupsongbackground", m_karaokeUseSongSpecificBackground ); TiXmlElement* pKaraokeBackground = pElement->FirstChildElement("defaultbackground"); if (pKaraokeBackground) { const char* attr = pKaraokeBackground->Attribute("type"); if ( attr ) m_karaokeDefaultBackgroundType = attr; attr = pKaraokeBackground->Attribute("path"); if ( attr ) m_karaokeDefaultBackgroundFilePath = attr; } } pElement = pRootElement->FirstChildElement("video"); if (pElement) { XMLUtils::GetFloat(pElement, "subsdelayrange", m_videoSubsDelayRange, 10, 600); XMLUtils::GetFloat(pElement, "audiodelayrange", m_videoAudioDelayRange, 10, 600); XMLUtils::GetInt(pElement, "blackbarcolour", m_videoBlackBarColour, 0, 255); XMLUtils::GetString(pElement, "defaultplayer", m_videoDefaultPlayer); XMLUtils::GetString(pElement, "defaultdvdplayer", m_videoDefaultDVDPlayer); XMLUtils::GetBoolean(pElement, "fullscreenonmoviestart", m_fullScreenOnMovieStart); // 101 on purpose - can be used to never automark as watched XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_videoPlayCountMinimumPercent, 0.0f, 101.0f); XMLUtils::GetInt(pElement, "ignoresecondsatstart", m_videoIgnoreSecondsAtStart, 0, 900); XMLUtils::GetFloat(pElement, "ignorepercentatend", m_videoIgnorePercentAtEnd, 0, 100.0f); XMLUtils::GetInt(pElement, "smallstepbackseconds", m_videoSmallStepBackSeconds, 1, INT_MAX); XMLUtils::GetInt(pElement, "smallstepbacktries", m_videoSmallStepBackTries, 1, 10); XMLUtils::GetInt(pElement, "smallstepbackdelay", m_videoSmallStepBackDelay, 100, 5000); //MS XMLUtils::GetBoolean(pElement, "usetimeseeking", m_videoUseTimeSeeking); XMLUtils::GetInt(pElement, "timeseekforward", m_videoTimeSeekForward, 0, 6000); XMLUtils::GetInt(pElement, "timeseekbackward", m_videoTimeSeekBackward, -6000, 0); XMLUtils::GetInt(pElement, "timeseekforwardbig", m_videoTimeSeekForwardBig, 0, 6000); XMLUtils::GetInt(pElement, "timeseekbackwardbig", m_videoTimeSeekBackwardBig, -6000, 0); XMLUtils::GetInt(pElement, "percentseekforward", m_videoPercentSeekForward, 0, 100); XMLUtils::GetInt(pElement, "percentseekbackward", m_videoPercentSeekBackward, -100, 0); XMLUtils::GetInt(pElement, "percentseekforwardbig", m_videoPercentSeekForwardBig, 0, 100); XMLUtils::GetInt(pElement, "percentseekbackwardbig", m_videoPercentSeekBackwardBig, -100, 0); TiXmlElement* pVideoExcludes = pElement->FirstChildElement("excludefromlisting"); if (pVideoExcludes) GetCustomRegexps(pVideoExcludes, m_videoExcludeFromListingRegExps); pVideoExcludes = pElement->FirstChildElement("excludefromscan"); if (pVideoExcludes) GetCustomRegexps(pVideoExcludes, m_moviesExcludeFromScanRegExps); pVideoExcludes = pElement->FirstChildElement("excludetvshowsfromscan"); if (pVideoExcludes) GetCustomRegexps(pVideoExcludes, m_tvshowExcludeFromScanRegExps); pVideoExcludes = pElement->FirstChildElement("cleanstrings"); if (pVideoExcludes) GetCustomRegexps(pVideoExcludes, m_videoCleanStringRegExps); XMLUtils::GetString(pElement,"cleandatetime", m_videoCleanDateTimeRegExp); XMLUtils::GetString(pElement,"ppffmpegdeinterlacing",m_videoPPFFmpegDeint); XMLUtils::GetString(pElement,"ppffmpegpostprocessing",m_videoPPFFmpegPostProc); XMLUtils::GetBoolean(pElement,"vdpauscaling",m_videoVDPAUScaling); XMLUtils::GetFloat(pElement, "nonlinearstretchratio", m_videoNonLinStretchRatio, 0.01f, 1.0f); XMLUtils::GetBoolean(pElement,"enablehighqualityhwscalers", m_videoEnableHighQualityHwScalers); XMLUtils::GetFloat(pElement,"autoscalemaxfps",m_videoAutoScaleMaxFps, 0.0f, 1000.0f); XMLUtils::GetBoolean(pElement,"allowmpeg4vdpau",m_videoAllowMpeg4VDPAU); XMLUtils::GetBoolean(pElement,"allowmpeg4vaapi",m_videoAllowMpeg4VAAPI); XMLUtils::GetBoolean(pElement, "disablebackgrounddeinterlace", m_videoDisableBackgroundDeinterlace); XMLUtils::GetInt(pElement, "useocclusionquery", m_videoCaptureUseOcclusionQuery, -1, 1); TiXmlElement* pAdjustRefreshrate = pElement->FirstChildElement("adjustrefreshrate"); if (pAdjustRefreshrate) { TiXmlElement* pRefreshOverride = pAdjustRefreshrate->FirstChildElement("override"); while (pRefreshOverride) { RefreshOverride override = {0}; float fps; if (XMLUtils::GetFloat(pRefreshOverride, "fps", fps)) { override.fpsmin = fps - 0.01f; override.fpsmax = fps + 0.01f; } float fpsmin, fpsmax; if (XMLUtils::GetFloat(pRefreshOverride, "fpsmin", fpsmin) && XMLUtils::GetFloat(pRefreshOverride, "fpsmax", fpsmax)) { override.fpsmin = fpsmin; override.fpsmax = fpsmax; } float refresh; if (XMLUtils::GetFloat(pRefreshOverride, "refresh", refresh)) { override.refreshmin = refresh - 0.01f; override.refreshmax = refresh + 0.01f;
bool CDAVFile::Execute(const CURL& url) { CURL url2(url); ParseAndCorrectUrl(url2); CLog::Log(LOGDEBUG, "CDAVFile::Execute(%p) %s", (void*)this, m_url.c_str()); assert(!(!m_state->m_easyHandle ^ !m_state->m_multiHandle)); if( m_state->m_easyHandle == NULL ) g_curlInterface.easy_aquire(url2.GetProtocol().c_str(), url2.GetHostName().c_str(), &m_state->m_easyHandle, &m_state->m_multiHandle); // setup common curl options SetCommonOptions(m_state); SetRequestHeaders(m_state); lastResponseCode = m_state->Connect(m_bufferSize); if( lastResponseCode < 0 || lastResponseCode >= 400) return false; char* efurl; if (CURLE_OK == g_curlInterface.easy_getinfo(m_state->m_easyHandle, CURLINFO_EFFECTIVE_URL,&efurl) && efurl) m_url = efurl; if (lastResponseCode == 207) { std::string strResponse; ReadData(strResponse); CXBMCTinyXML davResponse; davResponse.Parse(strResponse); if (!davResponse.Parse(strResponse)) { CLog::Log(LOGERROR, "%s - Unable to process dav response (%s)", __FUNCTION__, m_url.c_str()); Close(); return false; } TiXmlNode *pChild; // Iterate over all responses for (pChild = davResponse.RootElement()->FirstChild(); pChild != 0; pChild = pChild->NextSibling()) { if (CDAVCommon::ValueWithoutNamespace(pChild, "response")) { std::string sRetCode = CDAVCommon::GetStatusTag(pChild->ToElement()); CRegExp rxCode; rxCode.RegComp("HTTP/1\\.1\\s(\\d+)\\s.*"); if (rxCode.RegFind(sRetCode) >= 0) { if (rxCode.GetSubCount()) { lastResponseCode = atoi(rxCode.GetMatch(1).c_str()); if( lastResponseCode < 0 || lastResponseCode >= 400) return false; } } } } } return true; }
bool CProfilesManager::Load(const std::string &file) { CSingleLock lock(m_critical); bool ret = true; // clear out our profiles m_profiles.clear(); if (CFile::Exists(file)) { CXBMCTinyXML profilesDoc; if (profilesDoc.LoadFile(file)) { const TiXmlElement *rootElement = profilesDoc.RootElement(); if (rootElement && StringUtils::EqualsNoCase(rootElement->Value(), XML_PROFILES)) { XMLUtils::GetUInt(rootElement, XML_LAST_LOADED, m_lastUsedProfile); XMLUtils::GetBoolean(rootElement, XML_LOGIN_SCREEN, m_usingLoginScreen); XMLUtils::GetInt(rootElement, XML_AUTO_LOGIN, m_autoLoginProfile); XMLUtils::GetInt(rootElement, XML_NEXTID, m_nextProfileId); CStdString defaultDir("special://home/userdata"); if (!CDirectory::Exists(defaultDir)) defaultDir = "special://xbmc/userdata"; const TiXmlElement* pProfile = rootElement->FirstChildElement(XML_PROFILE); while (pProfile) { CProfile profile(defaultDir); profile.Load(pProfile, GetNextProfileId()); AddProfile(profile); pProfile = pProfile->NextSiblingElement(XML_PROFILE); } } else { CLog::Log(LOGERROR, "CProfilesManager: error loading %s, no <profiles> node", file.c_str()); ret = false; } } else { CLog::Log(LOGERROR, "CProfilesManager: error loading %s, Line %d\n%s", file.c_str(), profilesDoc.ErrorRow(), profilesDoc.ErrorDesc()); ret = false; } } if (m_profiles.empty()) { // add the master user CProfile profile("special://masterprofile/", "Master user", 0); AddProfile(profile); } // check the validity of the previous profile index if (m_lastUsedProfile >= m_profiles.size()) m_lastUsedProfile = 0; SetCurrentProfileId(m_lastUsedProfile); // check the validity of the auto login profile index if (m_autoLoginProfile < -1 || m_autoLoginProfile >= (int)m_profiles.size()) m_autoLoginProfile = -1; else if (m_autoLoginProfile >= 0) SetCurrentProfileId(m_autoLoginProfile); // the login screen runs as the master profile, so if we're using this, we need to ensure // we switch to the master profile if (m_usingLoginScreen) SetCurrentProfileId(0); return ret; }
bool CVideoInfoTag::Save(TiXmlNode *node, const std::string &tag, bool savePathInfo, const TiXmlElement *additionalNode) { if (!node) return false; // we start with a <tag> tag TiXmlElement movieElement(tag.c_str()); TiXmlNode *movie = node->InsertEndChild(movieElement); if (!movie) return false; XMLUtils::SetString(movie, "title", m_strTitle); if (!m_strOriginalTitle.empty()) XMLUtils::SetString(movie, "originaltitle", m_strOriginalTitle); if (!m_strShowTitle.empty()) XMLUtils::SetString(movie, "showtitle", m_strShowTitle); if (!m_strSortTitle.empty()) XMLUtils::SetString(movie, "sorttitle", m_strSortTitle); if (!m_ratings.empty()) { TiXmlElement ratings("ratings"); for (const auto& it : m_ratings) { TiXmlElement rating("rating"); rating.SetAttribute("name", it.first.c_str()); XMLUtils::SetFloat(&rating, "value", it.second.rating); XMLUtils::SetInt(&rating, "votes", it.second.votes); rating.SetAttribute("max", 10); if (it.first == m_strDefaultRating) rating.SetAttribute("default", "true"); ratings.InsertEndChild(rating); } movie->InsertEndChild(ratings); } XMLUtils::SetInt(movie, "userrating", m_iUserRating); if (m_EpBookmark.timeInSeconds > 0) { TiXmlElement epbookmark("episodebookmark"); XMLUtils::SetFloat(&epbookmark, "position", (float)m_EpBookmark.timeInSeconds); if (!m_EpBookmark.playerState.empty()) { TiXmlElement playerstate("playerstate"); CXBMCTinyXML doc; doc.Parse(m_EpBookmark.playerState); playerstate.InsertEndChild(*doc.RootElement()); epbookmark.InsertEndChild(playerstate); } movie->InsertEndChild(epbookmark); } XMLUtils::SetInt(movie, "top250", m_iTop250); if (tag == "episodedetails" || tag == "tvshow") { XMLUtils::SetInt(movie, "season", m_iSeason); XMLUtils::SetInt(movie, "episode", m_iEpisode); XMLUtils::SetInt(movie, "displayseason",m_iSpecialSortSeason); XMLUtils::SetInt(movie, "displayepisode",m_iSpecialSortEpisode); } if (tag == "musicvideo") { XMLUtils::SetInt(movie, "track", m_iTrack); XMLUtils::SetString(movie, "album", m_strAlbum); } XMLUtils::SetString(movie, "outline", m_strPlotOutline); XMLUtils::SetString(movie, "plot", m_strPlot); XMLUtils::SetString(movie, "tagline", m_strTagLine); XMLUtils::SetInt(movie, "runtime", GetDuration() / 60); if (!m_strPictureURL.m_xml.empty()) { CXBMCTinyXML doc; doc.Parse(m_strPictureURL.m_xml); const TiXmlNode* thumb = doc.FirstChild("thumb"); while (thumb) { movie->InsertEndChild(*thumb); thumb = thumb->NextSibling("thumb"); } } if (m_fanart.m_xml.size()) { CXBMCTinyXML doc; doc.Parse(m_fanart.m_xml); movie->InsertEndChild(*doc.RootElement()); } XMLUtils::SetString(movie, "mpaa", m_strMPAARating); XMLUtils::SetInt(movie, "playcount", m_playCount); XMLUtils::SetDate(movie, "lastplayed", m_lastPlayed); if (savePathInfo) { XMLUtils::SetString(movie, "file", m_strFile); XMLUtils::SetString(movie, "path", m_strPath); XMLUtils::SetString(movie, "filenameandpath", m_strFileNameAndPath); XMLUtils::SetString(movie, "basepath", m_basePath); } if (!m_strEpisodeGuide.empty()) { CXBMCTinyXML doc; doc.Parse(m_strEpisodeGuide); if (doc.RootElement()) movie->InsertEndChild(*doc.RootElement()); else XMLUtils::SetString(movie, "episodeguide", m_strEpisodeGuide); } XMLUtils::SetString(movie, "id", GetUniqueID()); for (const auto& uniqueid : m_uniqueIDs) { TiXmlElement uniqueID("uniqueid"); uniqueID.SetAttribute("type", uniqueid.first); if (uniqueid.first == m_strDefaultUniqueID) uniqueID.SetAttribute("default", "true"); TiXmlText value(uniqueid.second); uniqueID.InsertEndChild(value); movie->InsertEndChild(uniqueID); } XMLUtils::SetStringArray(movie, "genre", m_genre); XMLUtils::SetStringArray(movie, "country", m_country); if (!m_strSet.empty()) { TiXmlElement set("set"); XMLUtils::SetString(&set, "name", m_strSet); if (!m_strSetOverview.empty()) XMLUtils::SetString(&set, "overview", m_strSetOverview); movie->InsertEndChild(set); } XMLUtils::SetStringArray(movie, "tag", m_tags); XMLUtils::SetStringArray(movie, "credits", m_writingCredits); XMLUtils::SetStringArray(movie, "director", m_director); if (HasPremiered()) XMLUtils::SetDate(movie, "premiered", m_premiered); if (HasYear()) XMLUtils::SetInt(movie, "year", GetYear()); XMLUtils::SetString(movie, "status", m_strStatus); XMLUtils::SetString(movie, "code", m_strProductionCode); XMLUtils::SetDate(movie, "aired", m_firstAired); XMLUtils::SetStringArray(movie, "studio", m_studio); XMLUtils::SetString(movie, "trailer", m_strTrailer); if (m_streamDetails.HasItems()) { // it goes fileinfo/streamdetails/[video|audio|subtitle] TiXmlElement fileinfo("fileinfo"); TiXmlElement streamdetails("streamdetails"); for (int iStream=1; iStream<=m_streamDetails.GetVideoStreamCount(); iStream++) { TiXmlElement stream("video"); XMLUtils::SetString(&stream, "codec", m_streamDetails.GetVideoCodec(iStream)); XMLUtils::SetFloat(&stream, "aspect", m_streamDetails.GetVideoAspect(iStream)); XMLUtils::SetInt(&stream, "width", m_streamDetails.GetVideoWidth(iStream)); XMLUtils::SetInt(&stream, "height", m_streamDetails.GetVideoHeight(iStream)); XMLUtils::SetInt(&stream, "durationinseconds", m_streamDetails.GetVideoDuration(iStream)); XMLUtils::SetString(&stream, "stereomode", m_streamDetails.GetStereoMode(iStream)); streamdetails.InsertEndChild(stream); } for (int iStream=1; iStream<=m_streamDetails.GetAudioStreamCount(); iStream++) { TiXmlElement stream("audio"); XMLUtils::SetString(&stream, "codec", m_streamDetails.GetAudioCodec(iStream)); XMLUtils::SetString(&stream, "language", m_streamDetails.GetAudioLanguage(iStream)); XMLUtils::SetInt(&stream, "channels", m_streamDetails.GetAudioChannels(iStream)); streamdetails.InsertEndChild(stream); } for (int iStream=1; iStream<=m_streamDetails.GetSubtitleStreamCount(); iStream++) { TiXmlElement stream("subtitle"); XMLUtils::SetString(&stream, "language", m_streamDetails.GetSubtitleLanguage(iStream)); streamdetails.InsertEndChild(stream); } fileinfo.InsertEndChild(streamdetails); movie->InsertEndChild(fileinfo); } /* if has stream details */ // cast for (iCast it = m_cast.begin(); it != m_cast.end(); ++it) { // add a <actor> tag TiXmlElement cast("actor"); TiXmlNode *node = movie->InsertEndChild(cast); XMLUtils::SetString(node, "name", it->strName); XMLUtils::SetString(node, "role", it->strRole); XMLUtils::SetInt(node, "order", it->order); XMLUtils::SetString(node, "thumb", it->thumbUrl.GetFirstThumb().m_url); } XMLUtils::SetStringArray(movie, "artist", m_artist); XMLUtils::SetStringArray(movie, "showlink", m_showLink); for (const auto& namedSeason : m_namedSeasons) { TiXmlElement season("namedseason"); season.SetAttribute("number", namedSeason.first); season.SetValue(namedSeason.second); movie->InsertEndChild(season); } TiXmlElement resume("resume"); XMLUtils::SetFloat(&resume, "position", (float)m_resumePoint.timeInSeconds); XMLUtils::SetFloat(&resume, "total", (float)m_resumePoint.totalTimeInSeconds); movie->InsertEndChild(resume); XMLUtils::SetDateTime(movie, "dateadded", m_dateAdded); if (additionalNode) movie->InsertEndChild(*additionalNode); return true; }
bool CProfilesManager::LoadProfile(size_t index) { CSingleLock lock(m_critical); // check if the index is valid or not if (index >= m_profiles.size()) return false; // check if the profile is already active if (m_currentProfile == index) return true; // unload any old settings CSettings::Get().Unload(); SetCurrentProfileId(index); // load the new settings if (!CSettings::Get().Load()) { CLog::Log(LOGFATAL, "CProfilesManager: unable to load settings for profile \"%s\"", m_profiles.at(index).getName().c_str()); return false; } CSettings::Get().SetLoaded(); CreateProfileFolders(); // Load the langinfo to have user charset <-> utf-8 conversion string strLanguage = CSettings::Get().GetString("locale.language"); strLanguage[0] = toupper(strLanguage[0]); string strLangInfoPath = StringUtils::Format("special://xbmc/language/%s/langinfo.xml", strLanguage.c_str()); CLog::Log(LOGINFO, "CProfilesManager: load language info file: %s", strLangInfoPath.c_str()); g_langInfo.Load(strLangInfoPath); CButtonTranslator::GetInstance().Load(true); g_localizeStrings.Load("special://xbmc/language/", strLanguage); CDatabaseManager::Get().Initialize(); g_Mouse.SetEnabled(CSettings::Get().GetBool("input.enablemouse")); g_infoManager.ResetCache(); g_infoManager.ResetLibraryBools(); // always reload the skin - we need it for the new language strings g_application.ReloadSkin(); if (m_currentProfile != 0) { CXBMCTinyXML doc; if (doc.LoadFile(URIUtils::AddFileToFolder(GetUserDataFolder(), "guisettings.xml"))) { CSettings::Get().LoadSetting(doc.RootElement(), "masterlock.maxretries"); CSettings::Get().LoadSetting(doc.RootElement(), "masterlock.startuplock"); } } CPasswordManager::GetInstance().Clear(); // to set labels - shares are reloaded #if !defined(TARGET_WINDOWS) && defined(HAS_DVD_DRIVE) MEDIA_DETECT::CDetectDVDMedia::UpdateState(); #endif // init windows CGUIMessage msg(GUI_MSG_NOTIFY_ALL, 0, 0, GUI_MSG_WINDOW_RESET); g_windowManager.SendMessage(msg); CUtil::DeleteDirectoryCache(); g_directoryCache.Clear(); return true; }