Example #1
0
bool BXBoxeeServices::Parse()
{
    TiXmlHandle docHandle(&m_doc);
    TiXmlNode* pTSChild = docHandle.FirstChild("services").FirstChild("timestamp").FirstChild().Node();

    if (pTSChild)
    {
        m_timestamp = atoi(pTSChild->Value());
    }

    TiXmlElement *pChild = docHandle.FirstChild("services").Element();
    if (!pChild)
    {
        LOG(LOG_LEVEL_ERROR,"BXBoxeeServices::Parse - FAILED to find <applications> node");
        return false;
    }

    m_services.clear();

    TiXmlNode *pMsgNode = 0;
    while ((pMsgNode = pChild->IterateChildren(pMsgNode)) != NULL)
    {
        if (pMsgNode->ValueStr().compare("object") == 0)
        {
            BXObject obj;
            if (obj.FromXML(pMsgNode))
            {
                m_services.push_back(obj);
            }
        }
    }

    return true;
}
Example #2
0
void COptions::SetXmlValue(unsigned int nID, wxString value)
{
	if (!m_pXmlFile)
		return;

	// No checks are made about the validity of the value, that's done in SetOption

	char *utf8 = ConvUTF8(value);
	if (!utf8)
		return;

	TiXmlElement *settings = m_pXmlFile->GetElement()->FirstChildElement("Settings");
	if (!settings)
	{
		TiXmlNode *node = m_pXmlFile->GetElement()->LinkEndChild(new TiXmlElement("Settings"));
		if (!node)
		{
			delete [] utf8;
			return;
		}
		settings = node->ToElement();
		if (!settings)
		{
			delete [] utf8;
			return;
		}
	}
	else
	{
		TiXmlNode *node = 0;
		while ((node = settings->IterateChildren("Setting", node)))
		{
			TiXmlElement *setting = node->ToElement();
			if (!setting)
				continue;

			const char *attribute = setting->Attribute("name");
			if (!attribute)
				continue;
			if (strcmp(attribute, options[nID].name))
				continue;

			//setting->RemoveAttribute("type");
			setting->Clear();
			//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
			setting->LinkEndChild(new TiXmlText(utf8));

			delete [] utf8;
			return;
		}
	}
	wxASSERT(options[nID].name[0]);
	TiXmlElement *setting = new TiXmlElement("Setting");
	setting->SetAttribute("name", options[nID].name);
	//setting->SetAttribute("type", (options[nID].type == string) ? "string" : "number");
	setting->LinkEndChild(new TiXmlText(utf8));
	settings->LinkEndChild(setting);

	delete [] utf8;
}
bool CWebBrowserDownloadHandler::LoadDownloadHistory(bool initial)
{
  TiXmlDocument xmlDoc;
  std::string strSettingsFile = kodi::GetBaseUserPath("download_history.xml");

  if (!xmlDoc.LoadFile(strSettingsFile))
  {
    if (initial)
    {
      if (!SaveDownloadHistory())
      {
        kodi::Log(ADDON_LOG_ERROR, "failed to create initial settings data file at '%s'", strSettingsFile.c_str());
        return false;
      }
      return true;
    }
    else
      kodi::Log(ADDON_LOG_ERROR, "invalid settings data (no/invalid data file found at '%s')", strSettingsFile.c_str());
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "downloadhistory") != 0)
  {
    if (!initial)
      kodi::Log(ADDON_LOG_ERROR, "invalid download history data (no <downloadhistory> tag found)");
    return false;
  }

  /* load history */
  TiXmlElement *pElement = pRootElement->FirstChildElement("histories");
  if (pElement)
  {
    TiXmlNode *pChannelNode = nullptr;
    while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != nullptr)
    {
      std::string name;
      if (!XMLUtils::GetString(pChannelNode, "name", name))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without name");
        continue;
      }

      std::string url;
      if (!XMLUtils::GetString(pChannelNode, "url", url))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without url (%s)", name.c_str());
        continue;
      }

      std::string path;
      if (!XMLUtils::GetString(pChannelNode, "path", path))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without path (%s)", name.c_str());
        continue;
      }

      long time;
      if (!XMLUtils::GetLong(pChannelNode, "time", time))
      {
        kodi::Log(ADDON_LOG_ERROR, "Download defined in history without time (%s)", name.c_str());
        continue;
      }

      std::shared_ptr<CDownloadItem> downloadItem = std::make_shared<CDownloadItem>(name, url, path, time);
      m_finishedDownloads[url] = downloadItem;
    }
  }

  return true;
}
Example #4
0
void TextureControl::LoadSupportedSets() {
	TiXmlDocument* doc;
	TiXmlElement* setElem;
	TiXmlElement* subSetElem;
	TiXmlElement* chanElem;
	TiXmlElement* elem;
	TiXmlNode* prevChan;
	TiXmlNode* prevSubSet;
	
	string fileSetName;
	string setName;
	string subSetName;
	string chanName;
	string setPath;
	string fileName;
	string fileFormat;
	string buf;
	int size;
	int compress;
	int alpha;
	unsigned int Flags;
	TargetTextureSet* ptts;

	WIN32_FIND_DATA findData;
	HANDLE hFind;
	hFind = FindFirstFile("SetDefs\\*.xml",&findData);
	do {
		fileSetName = "SetDefs\\";
		fileSetName += findData.cFileName;	

		doc = new TiXmlDocument(fileSetName.c_str());
		bool loadOkay = doc->LoadFile();
		if(!loadOkay) {
			delete doc;
			continue;
		}

		setElem = doc->FirstChildElement("TextureSet");
		while(setElem) {
			setName = setElem->Attribute("Name");
			elem = setElem->FirstChildElement("Path");
			if(elem) setPath = elem->GetText();

			ptts = new TargetTextureSet(setName,setPath);

			prevSubSet = NULL;
			while(prevSubSet = setElem->IterateChildren("SubSet",prevSubSet)) {
				subSetElem = prevSubSet->ToElement();
				subSetName = subSetElem->Attribute("Name");

				prevChan = NULL;
				while( prevChan = subSetElem->IterateChildren("Channel",prevChan) ){
					chanElem = prevChan->ToElement();
					chanName = chanElem->Attribute("Name");

					elem = chanElem->FirstChildElement("FileName");
					if(elem) fileName = elem->GetText();
					elem = chanElem->FirstChildElement("FileFormat");
					if(elem) fileFormat = elem->GetText();
					elem = chanElem->FirstChildElement("Size");
					if(elem) size = atoi(elem->GetText());

					Flags = 0; compress = 0; alpha = 0;
					elem = chanElem->FirstChildElement("CompressTex");
					if(elem) compress = atoi(elem->GetText());
					if(!compress) 
						Flags = TTS_FLAG_DDSUNCOMPRESSED;
					elem = chanElem->FirstChildElement("HasAlpha");
					if(elem) alpha = atoi(elem->GetText());
					if(alpha)
						Flags |= TTS_FLAG_HASALPHA;

					ptts->AddSetFile(subSetName, chanName, fileName,fileFormat,size,Flags);
				}
			}
			supportedSets.push_back(ptts);
			setElem = setElem->NextSiblingElement("TextureSet");
		}
		delete doc;
	} while(FindNextFile(hFind,&findData)) ;
}
Example #5
0
bool PVRXinFanData::LoadXinFanData(void)
{
  TiXmlDocument xmlDoc;
  string strSettingsFile = GetSettingsFile();

  if (!xmlDoc.LoadFile(strSettingsFile))
  {
    XBMC->Log(LOG_ERROR, "invalid XinFan.TV data (no/invalid data file found at '%s')", strSettingsFile.c_str());
    return false;
  }

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (strcmp(pRootElement->Value(), "xinfan") != 0)
  {
    XBMC->Log(LOG_ERROR, "invalid XinFan.TV data (no <xinfan> tag found)");
    return false;
  }

  /* load channels */
  int iUniqueChannelId = 0;
  TiXmlElement *pElement = pRootElement->FirstChildElement("channels");
  if (pElement)
  {
    TiXmlNode *pChannelNode = NULL;
    while ((pChannelNode = pElement->IterateChildren(pChannelNode)) != NULL)
    {
      CStdString strTmp;
      PVRXinFanChannel channel;
      channel.iUniqueId = ++iUniqueChannelId;

      /* channel name */
      if (!XMLUtils::GetString(pChannelNode, "name", strTmp))
        continue;
      channel.strChannelName = strTmp;

      /* radio/TV */
      XMLUtils::GetBoolean(pChannelNode, "radio", channel.bRadio);

      /* channel number */
      if (!XMLUtils::GetInt(pChannelNode, "number", channel.iChannelNumber))
        channel.iChannelNumber = iUniqueChannelId;

      /* sub channel number */
      if (!XMLUtils::GetInt(pChannelNode, "subnumber", channel.iSubChannelNumber))
        channel.iSubChannelNumber = 0;

      /* CAID */
      if (!XMLUtils::GetInt(pChannelNode, "encryption", channel.iEncryptionSystem))
        channel.iEncryptionSystem = 0;

      /* icon path */
      if (!XMLUtils::GetString(pChannelNode, "icon", strTmp))
        channel.strIconPath = m_strDefaultIcon;
      else
        channel.strIconPath = strTmp;

      /* stream url */
      if (!XMLUtils::GetString(pChannelNode, "stream", strTmp))
        channel.strStreamURL = m_strDefaultMovie;
      else
        channel.strStreamURL = strTmp;

      m_channels.push_back(channel);
    }
  }

  /* load channel groups */
  int iUniqueGroupId = 0;
  pElement = pRootElement->FirstChildElement("channelgroups");
  if (pElement)
  {
    TiXmlNode *pGroupNode = NULL;
    while ((pGroupNode = pElement->IterateChildren(pGroupNode)) != NULL)
    {
      CStdString strTmp;
      PVRXinFanChannelGroup group;
      group.iGroupId = ++iUniqueGroupId;

      /* group name */
      if (!XMLUtils::GetString(pGroupNode, "name", strTmp))
        continue;
      group.strGroupName = strTmp;

      /* radio/TV */
      XMLUtils::GetBoolean(pGroupNode, "radio", group.bRadio);
      
      /* sort position */
      XMLUtils::GetInt(pGroupNode, "position", group.iPosition);

      /* members */
      TiXmlNode* pMembers = pGroupNode->FirstChild("members");
      TiXmlNode *pMemberNode = NULL;
      while (pMembers != NULL && (pMemberNode = pMembers->IterateChildren(pMemberNode)) != NULL)
      {
        int iChannelId = atoi(pMemberNode->FirstChild()->Value());
        if (iChannelId > -1)
          group.members.push_back(iChannelId);
      }

      m_groups.push_back(group);
    }
  }

  /* load EPG entries */
  pElement = pRootElement->FirstChildElement("epg");
  if (pElement)
  {
    TiXmlNode *pEpgNode = NULL;
    while ((pEpgNode = pElement->IterateChildren(pEpgNode)) != NULL)
    {
      CStdString strTmp;
      int iTmp;
      PVRXinFanEpgEntry entry;

      /* broadcast id */
      if (!XMLUtils::GetInt(pEpgNode, "broadcastid", entry.iBroadcastId))
        continue;

      /* channel id */
      if (!XMLUtils::GetInt(pEpgNode, "channelid", iTmp))
        continue;
      PVRXinFanChannel &channel = m_channels.at(iTmp - 1);
      entry.iChannelId = channel.iUniqueId;

      /* title */
      if (!XMLUtils::GetString(pEpgNode, "title", strTmp))
        continue;
      entry.strTitle = strTmp;

      /* start */
      if (!XMLUtils::GetInt(pEpgNode, "start", iTmp))
        continue;
      entry.startTime = iTmp;

      /* end */
      if (!XMLUtils::GetInt(pEpgNode, "end", iTmp))
        continue;
      entry.endTime = iTmp;

      /* plot */
      if (XMLUtils::GetString(pEpgNode, "plot", strTmp))
        entry.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pEpgNode, "plotoutline", strTmp))
        entry.strPlotOutline = strTmp;

      /* icon path */
      if (XMLUtils::GetString(pEpgNode, "icon", strTmp))
        entry.strIconPath = strTmp;

      /* genre type */
      XMLUtils::GetInt(pEpgNode, "genretype", entry.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pEpgNode, "genresubtype", entry.iGenreSubType);

      XBMC->Log(LOG_DEBUG, "loaded EPG entry '%s' channel '%d' start '%d' end '%d'", entry.strTitle.c_str(), entry.iChannelId, entry.startTime, entry.endTime);
      channel.epg.push_back(entry);
    }
  }

  /* load recordings */
  iUniqueGroupId = 0; // reset unique ids
  pElement = pRootElement->FirstChildElement("recordings");
  if (pElement)
  {
    TiXmlNode *pRecordingNode = NULL;
    while ((pRecordingNode = pElement->IterateChildren(pRecordingNode)) != NULL)
    {
      CStdString strTmp;
      PVRXinFanRecording recording;

      /* recording title */
      if (!XMLUtils::GetString(pRecordingNode, "title", strTmp))
        continue;
      recording.strTitle = strTmp;

      /* recording url */
      if (!XMLUtils::GetString(pRecordingNode, "url", strTmp))
        recording.strStreamURL = m_strDefaultMovie;
      else
        recording.strStreamURL = strTmp;

      /* recording path */
      if (XMLUtils::GetString(pRecordingNode, "directory", strTmp))
        recording.strDirectory = strTmp;

      iUniqueGroupId++;
      strTmp.Format("%d", iUniqueGroupId);
      recording.strRecordingId = strTmp;

      /* channel name */
      if (XMLUtils::GetString(pRecordingNode, "channelname", strTmp))
        recording.strChannelName = strTmp;

      /* plot */
      if (XMLUtils::GetString(pRecordingNode, "plot", strTmp))
        recording.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pRecordingNode, "plotoutline", strTmp))
        recording.strPlotOutline = strTmp;

      /* genre type */
      XMLUtils::GetInt(pRecordingNode, "genretype", recording.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pRecordingNode, "genresubtype", recording.iGenreSubType);

      /* duration */
      XMLUtils::GetInt(pRecordingNode, "duration", recording.iDuration);

      /* recording time */
      if (XMLUtils::GetString(pRecordingNode, "time", strTmp))
      {
        time_t timeNow = time(NULL);
        struct tm* now = localtime(&timeNow);

        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);
          now->tm_mday--; // yesterday

          recording.recordingTime = mktime(now);
        }
      }

      m_recordings.push_back(recording);
    }
  }

  /* load deleted recordings */
  pElement = pRootElement->FirstChildElement("recordingsdeleted");
  if (pElement)
  {
    TiXmlNode *pRecordingNode = NULL;
    while ((pRecordingNode = pElement->IterateChildren(pRecordingNode)) != NULL)
    {
      CStdString strTmp;
      PVRXinFanRecording recording;

      /* recording title */
      if (!XMLUtils::GetString(pRecordingNode, "title", strTmp))
        continue;
      recording.strTitle = strTmp;

      /* recording url */
      if (!XMLUtils::GetString(pRecordingNode, "url", strTmp))
        recording.strStreamURL = m_strDefaultMovie;
      else
        recording.strStreamURL = strTmp;

      /* recording path */
      if (XMLUtils::GetString(pRecordingNode, "directory", strTmp))
        recording.strDirectory = strTmp;

      iUniqueGroupId++;
      strTmp.Format("%d", iUniqueGroupId);
      recording.strRecordingId = strTmp;

      /* channel name */
      if (XMLUtils::GetString(pRecordingNode, "channelname", strTmp))
        recording.strChannelName = strTmp;

      /* plot */
      if (XMLUtils::GetString(pRecordingNode, "plot", strTmp))
        recording.strPlot = strTmp;

      /* plot outline */
      if (XMLUtils::GetString(pRecordingNode, "plotoutline", strTmp))
        recording.strPlotOutline = strTmp;

      /* genre type */
      XMLUtils::GetInt(pRecordingNode, "genretype", recording.iGenreType);

      /* genre subtype */
      XMLUtils::GetInt(pRecordingNode, "genresubtype", recording.iGenreSubType);

      /* duration */
      XMLUtils::GetInt(pRecordingNode, "duration", recording.iDuration);

      /* recording time */
      if (XMLUtils::GetString(pRecordingNode, "time", strTmp))
      {
        time_t timeNow = time(NULL);
        struct tm* now = localtime(&timeNow);

        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);
          now->tm_mday--; // yesterday

          recording.recordingTime = mktime(now);
        }
      }

      m_recordingsDeleted.push_back(recording);
    }
  }

  /* load timers */
  pElement = pRootElement->FirstChildElement("timers");
  if (pElement)
  {
    TiXmlNode *pTimerNode = NULL;
    while ((pTimerNode = pElement->IterateChildren(pTimerNode)) != NULL)
    {
      CStdString strTmp;
      int iTmp;
      PVRXinFanTimer timer;
      time_t timeNow = time(NULL);
      struct tm* now = localtime(&timeNow);

      /* channel id */
      if (!XMLUtils::GetInt(pTimerNode, "channelid", iTmp))
        continue;
      PVRXinFanChannel &channel = m_channels.at(iTmp - 1);
      timer.iChannelId = channel.iUniqueId;

      /* state */
      if (XMLUtils::GetInt(pTimerNode, "state", iTmp))
        timer.state = (PVR_TIMER_STATE) iTmp;

      /* title */
      if (!XMLUtils::GetString(pTimerNode, "title", strTmp))
        continue;
      timer.strTitle = strTmp;

      /* summary */
      if (!XMLUtils::GetString(pTimerNode, "summary", strTmp))
        continue;
      timer.strSummary = strTmp;

      /* start time */
      if (XMLUtils::GetString(pTimerNode, "starttime", strTmp))
      {
        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);

          timer.startTime = mktime(now);
        }
      }

      /* end time */
      if (XMLUtils::GetString(pTimerNode, "endtime", strTmp))
      {
        CStdString::size_type delim = strTmp.Find(':');
        if (delim != CStdString::npos)
        {
          now->tm_hour = (int)strtol(strTmp.Left(delim), NULL, 0);
          now->tm_min  = (int)strtol(strTmp.Mid(delim + 1), NULL, 0);

          timer.endTime = mktime(now);
        }
      }

      XBMC->Log(LOG_DEBUG, "loaded timer '%s' channel '%d' start '%d' end '%d'", timer.strTitle.c_str(), timer.iChannelId, timer.startTime, timer.endTime);
      m_timers.push_back(timer);
    }
  }

  return true;
}