RestrictedPercentage(TiXmlNode* xmlNode)
       : ISerialized(xmlNode){
             TiXmlElement* xmlElem = xmlNode->ToElement();
             const char *pKey = xmlElem->Value();
             const char *pText = xmlElem->GetText();

             if( pText ) { this->valueStr = pText; }
             else if( xmlElem->NoChildren() ) { this->valueStr = "NULL ( empty value )"; }
             else { this->valueStr = "NULL value ( Node has Children )"; }
             #ifdef ConsolePrint
                FileManager::instance().outFile_ << FileManager::instance().tap_.c_str() << "   " << xmlNode->Value() << " : " << this->valueStr.c_str() << std::endl;
             #endif
       }
Beispiel #2
0
bool loadXMLFile (TiXmlDocument &pXMLDoc, std::string XMLFilename, std::map<int,
                  std::string> * pMapXmlStrings, bool isSourceFile)
{
  if (!pXMLDoc.LoadFile(XMLFilename.c_str()))
  {
    printf ("%s %s\n", pXMLDoc.ErrorDesc(), XMLFilename.c_str());
    return false;
  }
  if (isSourceFile) GetEncoding(&pXMLDoc, sourceXMLEncoding);
    else GetEncoding(&pXMLDoc, foreignXMLEncoding);

  TiXmlElement* pRootElement = pXMLDoc.RootElement();
  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="strings")
  {
    printf ("error: No root element called: \"strings\" or no child found in input XML file: %s\n",
            XMLFilename.c_str());
    return false;
  }

  if (isSourceFile) GetComment(pRootElement->FirstChild(), -1);

  const TiXmlElement *pChildElement = pRootElement->FirstChildElement("string");
  const char* pAttrId = NULL;
  const char* pValue = NULL;
  std::string valueString;
  int id;

  while (pChildElement)
  {
    pAttrId=pChildElement->Attribute("id");
    if (pAttrId && !pChildElement->NoChildren())
    {
      id = atoi(pAttrId);
      if (pMapXmlStrings->find(id) == pMapXmlStrings->end())
      {
        pValue = pChildElement->FirstChild()->Value();
        valueString = EscapeLF(pValue);
        if (isSourceFile)
          multimapSourceXmlStrings.insert(std::pair<std::string,int>( valueString,id));

        (*pMapXmlStrings)[id] = valueString;

        if (pChildElement && isSourceFile) GetComment(pChildElement->NextSibling(), id);
      }
    }
    pChildElement = pChildElement->NextSiblingElement("string");
  }
  // Free up the allocated memory for the XML file
  pXMLDoc.Clear();
  return true;
}
//网络返回数据 刷新内存
void CMGetNewContent::OnSessionCmd(unsigned int nCmdID, unsigned int nCode, TiXmlDocument *pDoc)
{
    if (nCode == MER_OK)
    {
        TiXmlElement* pItem = pDoc->RootElement();
        
        if (pItem)
        {
            INT32 nCmdID = 0;
            
            pItem->QueryIntAttribute("no", &nCmdID);
            
            INT32 nErr = 0;
            
            if (pItem->QueryIntAttribute("errno", &nErr) == TIXML_SUCCESS)
            {
                if (nErr == 0)
                {
                    if (nCmdID == SERVICE_GETNEWCONTENT || nCmdID == SERVICE_GETRECOMMEND)
                    {
						if(!pItem->NoChildren())
                        {
                            TiXmlElement* pHeadItemList = pItem->FirstChildElement("largeimage");
                            if(pHeadItemList)
                                DoHeadItemList(pHeadItemList);
                            DoItemList(pItem);
                        }

                        if (m_lstItem && m_lstItem->size() > 0)
                        {
                        	if(m_pListener)
                        		m_pListener->OnUpdateDataFinish(m_pUserData, TResult::ESuccess);
                            return ;
                        }
                        else
                        {
                        	if(m_pListener)
                        		m_pListener->OnUpdateDataFinish(m_pUserData, TResult::ENothing);
                            return ;
                        }
                    }
                }
            }
        }
    }
    if(m_pListener)
    	m_pListener->OnUpdateDataFinish(m_pUserData, TResult::EUnknownError);
}
Beispiel #4
0
bool CRssReader::Parse(int iFeed)
{
  TiXmlElement* rootXmlNode = m_xml.RootElement();

  if (!rootXmlNode)
    return false;

  TiXmlElement* rssXmlNode = NULL;

  CStdString strValue = rootXmlNode->Value();
  if (( strValue.Find("rss") >= 0 ) || ( strValue.Find("rdf") >= 0 ))
  {
    rssXmlNode = rootXmlNode;
  }
  else
  {
    // Unable to find root <rss> or <rdf> node
    return false;
  }

  TiXmlElement* channelXmlNode = rssXmlNode->FirstChildElement("channel");
  if (channelXmlNode)
  {
    TiXmlElement* titleNode = channelXmlNode->FirstChildElement("title");
    if (titleNode && !titleNode->NoChildren())
    {
      CStdString strChannel = titleNode->FirstChild()->Value();
    CStdStringW strChannelUnicode;
    fromRSSToUTF16(strChannel, strChannelUnicode);
    AddString(strChannelUnicode, RSS_COLOR_CHANNEL, iFeed);

    AddString(": ", RSS_COLOR_CHANNEL, iFeed);
    }

    GetNewsItems(channelXmlNode,iFeed);
  }

  GetNewsItems(rssXmlNode,iFeed);

  // avoid trailing ' - '
  if( m_strFeed[iFeed].size() > 3 && m_strFeed[iFeed].Mid(m_strFeed[iFeed].size()-3) == L" - ")
  {
    m_strFeed[iFeed].erase(m_strFeed[iFeed].length()-3);
    m_strColors[iFeed].erase(m_strColors[iFeed].length()-3);
  }
  return true;
}
Beispiel #5
0
void RemoveRecursive( TiXmlElement* element, const set<string>& tagsToRemove )
{
	Remove( element, tagsToRemove );

	TiXmlElement* curr = element->FirstChildElement();
	while( curr != nullptr )
	{
		TiXmlElement* next = curr->NextSiblingElement();
		RemoveRecursive( curr, tagsToRemove );
		if( curr->NoChildren() )
		{
			element->RemoveChild( curr );
		}

		curr = next;
	}
}
Beispiel #6
0
bool CHTTPHandler::LoadCredentials (std::string CredentialsFilename)
{
  TiXmlDocument xmlPasswords;

  if (!xmlPasswords.LoadFile(CredentialsFilename.c_str()))
  {
    CLog::Log(logINFO, "HTTPHandler: No \".passwords.xml\" file exists in project dir. No password protected web download will be available.");
    return false;
  }

  CLog::Log(logINFO, "HTTPHandler: Succesfuly found the .passwsords.xml file: %s", CredentialsFilename.c_str());

  TiXmlElement* pRootElement = xmlPasswords.RootElement();

  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="websites")
  {
    CLog::Log(logWARNING, "HTTPHandler: No root element called \"websites\" in xml file.");
    return false;
  }

  CLoginData LoginData;

  const TiXmlElement *pChildElement = pRootElement->FirstChildElement("website");
  while (pChildElement && pChildElement->FirstChild())
  {
    std::string strWebSitePrefix = pChildElement->Attribute("prefix");
    if (pChildElement->FirstChild())
    {
      const TiXmlElement *pChildLOGINElement = pChildElement->FirstChildElement("login");
      if (pChildLOGINElement && pChildLOGINElement->FirstChild())
        LoginData.strLogin = pChildLOGINElement->FirstChild()->Value();
      const TiXmlElement *pChildPASSElement = pChildElement->FirstChildElement("password");
      if (pChildPASSElement && pChildPASSElement->FirstChild())
        LoginData.strPassword = pChildPASSElement->FirstChild()->Value();

      m_mapLoginData [strWebSitePrefix] = LoginData;
      CLog::Log(logINFO, "HTTPHandler: found login credentials for website prefix: %s", strWebSitePrefix.c_str());
    }
    pChildElement = pChildElement->NextSiblingElement("website");
  }

  return true;
};
Beispiel #7
0
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;
}
Beispiel #8
0
bool loadAddonXMLFile (std::string AddonXMLFilename)
{
  TiXmlDocument xmlAddonXML;

  if (!xmlAddonXML.LoadFile(AddonXMLFilename.c_str()))
  {
    printf ("%s %s\n", xmlAddonXML.ErrorDesc(), (WorkingDir + "addon.xml").c_str());
    return false;
  }

  GetEncoding(&xmlAddonXML, addonXMLEncoding);

  TiXmlElement* pRootElement = xmlAddonXML.RootElement();

  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="addon")
  {
    printf ("error: No root element called: \"addon\" or no child found in AddonXML file: %s\n",
            AddonXMLFilename.c_str());
    return false;
  }
  const char* pMainAttrId = NULL;

  pMainAttrId=pRootElement->Attribute("id");
  if (!pMainAttrId)
  {
    printf ("warning: No addon name was available in addon.xml file: %s\n", AddonXMLFilename.c_str());
    ProjName = "xbmc-unnamed";
  }
  else
    ProjName = EscapeLF(pMainAttrId);

  pMainAttrId=pRootElement->Attribute("version");
  if (!pMainAttrId)
  {
    printf ("warning: No version name was available in addon.xml file: %s\n", AddonXMLFilename.c_str());
    ProjVersion = "rev_unknown";
  }
  else
    ProjVersion = EscapeLF(pMainAttrId);

  pMainAttrId=pRootElement->Attribute("name");
  if (!pMainAttrId)
  {
    printf ("warning: No addon name was available in addon.xml file: %s\n", AddonXMLFilename.c_str());
    ProjTextName = "unknown";
  }
  else
    ProjTextName = EscapeLF(pMainAttrId);

  pMainAttrId=pRootElement->Attribute("provider-name");
  if (!pMainAttrId)
  {
    printf ("warning: No addon provider was available in addon.xml file: %s\n", AddonXMLFilename.c_str());
    ProjProvider = "unknown";
  }
  else
    ProjProvider = EscapeLF(pMainAttrId);

  std::string strAttrToSearch = "xbmc.addon.metadata";

  const TiXmlElement *pChildElement = pRootElement->FirstChildElement("extension");
  while (pChildElement && strcmp(pChildElement->Attribute("point"), "xbmc.addon.metadata") != 0)
    pChildElement = pChildElement->NextSiblingElement("extension");

  const TiXmlElement *pChildSummElement = pChildElement->FirstChildElement("summary");
  while (pChildSummElement && pChildSummElement->FirstChild())
  {
    std::string strLang = pChildSummElement->Attribute("lang");
    if (pChildSummElement->FirstChild())
    {
      std::string strValue = EscapeLF(pChildSummElement->FirstChild()->Value());
      mapAddonXMLData[strLang].strSummary = strValue;
    }
    pChildSummElement = pChildSummElement->NextSiblingElement("summary");
  }

  const TiXmlElement *pChildDescElement = pChildElement->FirstChildElement("description");
  while (pChildDescElement && pChildDescElement->FirstChild())
  {
    std::string strLang = pChildDescElement->Attribute("lang");
    if (pChildDescElement->FirstChild())
    {
      std::string strValue = EscapeLF(pChildDescElement->FirstChild()->Value());
      mapAddonXMLData[strLang].strDescription = strValue;
    }
    pChildDescElement = pChildDescElement->NextSiblingElement("description");
  }

  const TiXmlElement *pChildDisclElement = pChildElement->FirstChildElement("disclaimer");
  while (pChildDisclElement && pChildDisclElement->FirstChild())
  {
    std::string strLang = pChildDisclElement->Attribute("lang");
    if (pChildDisclElement->FirstChild())
    {
      std::string strValue = EscapeLF(pChildDisclElement->FirstChild()->Value());
      mapAddonXMLData[strLang].strDisclaimer = strValue;
    }
    pChildDisclElement = pChildDisclElement->NextSiblingElement("disclaimer");
  }

  return true;
}
bool CButtonMapXml::Load(void)
{
  TiXmlDocument xmlFile;
  if (!xmlFile.LoadFile(m_strResourcePath))
  {
    esyslog("Error opening %s: %s", m_strResourcePath.c_str(), xmlFile.ErrorDesc());
    return false;
  }

  TiXmlElement* pRootElement = xmlFile.RootElement();
  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueStr() != BUTTONMAP_XML_ROOT)
  {
    esyslog("Can't find root <%s> tag", BUTTONMAP_XML_ROOT);
    return false;
  }

  const TiXmlElement* pDevice = pRootElement->FirstChildElement(DEVICES_XML_ELEM_DEVICE);

  if (!pDevice)
  {
    esyslog("Can't find <%s> tag", DEVICES_XML_ELEM_DEVICE);
    return false;
  }

  if (!CDeviceXml::Deserialize(pDevice, m_device))
    return false;

  const TiXmlElement* pController = pDevice->FirstChildElement(BUTTONMAP_XML_ELEM_CONTROLLER);

  if (!pController)
  {
    esyslog("Device \"%s\": can't find <%s> tag", m_device.Name().c_str(), BUTTONMAP_XML_ELEM_CONTROLLER);
    return false;
  }

  // For logging purposes
  unsigned int totalFeatureCount = 0;

  while (pController)
  {
    const char* id = pController->Attribute(BUTTONMAP_XML_ATTR_CONTROLLER_ID);
    if (!id)
    {
      esyslog("Device \"%s\": <%s> tag has no attribute \"%s\"", m_device.Name().c_str(),
              BUTTONMAP_XML_ELEM_CONTROLLER, BUTTONMAP_XML_ATTR_CONTROLLER_ID);
      return false;
    }

    FeatureVector features;
    if (!Deserialize(pController, features))
      return false;

    if (features.empty())
    {
      esyslog("Device \"%s\" has no features for controller %s", m_device.Name().c_str(), id);
    }
    else
    {
      totalFeatureCount += features.size();
      m_buttonMap[id] = std::move(features);
    }

    pController = pController->NextSiblingElement(BUTTONMAP_XML_ELEM_CONTROLLER);
  }

  dsyslog("Loaded device \"%s\" with %u controller profiles and %u total features", m_device.Name().c_str(), m_buttonMap.size(), totalFeatureCount);

  return true;
}
bool CWeather::GetSearchResults(const CStdString &strSearch, CStdString &strResult)
{
  // Check to see if the user entered a weather.com code
  if (strSearch.size() == 8)
  {
    strResult = "";
    int i = 0;
    for (i = 0; i < 4; ++i)
    {
      strResult += toupper(strSearch[i]);
      if (!isalpha(strSearch[i]))
        break;
    }
    if (i == 4)
    {
      for ( ; i < 8; ++i)
      {
        strResult += strSearch[i];
        if (!isdigit(strSearch[i]))
          break;
      }
      if (i == 8)
      {
        return true; // match
      }
    }
    // no match, wipe string
    strResult = "";
  }

  CGUIDialogSelect *pDlgSelect = (CGUIDialogSelect*)g_windowManager.GetWindow(WINDOW_DIALOG_SELECT);
  CGUIDialogProgress *pDlgProgress = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS);

  //do the download
  CStdString strURL;
  CStdString strXML;
  XFILE::CFileCurl httpUtil;

  if (pDlgProgress)
  {
    pDlgProgress->SetHeading(410);       //"Accessing Weather.com"
    pDlgProgress->SetLine(0, 194);       //"Searching"
    pDlgProgress->SetLine(1, strSearch);
    pDlgProgress->SetLine(2, "");
    pDlgProgress->StartModal();
    pDlgProgress->Progress();
  }

  strURL.Format("http://xoap.weather.com/search/search?where=%s", strSearch);

  if (!httpUtil.Get(strURL, strXML))
  {
    if (pDlgProgress)
      pDlgProgress->Close();
    return false;
  }

  //some select dialog init stuff
  if (!pDlgSelect)
  {
    if (pDlgProgress)
      pDlgProgress->Close();
    return false;
  }

  pDlgSelect->SetHeading(396); //"Select Location"
  pDlgSelect->Reset();

  ///////////////////////////////
  // load the xml file
  ///////////////////////////////
  TiXmlDocument xmlDoc;
  xmlDoc.Parse(strXML.c_str());
  if (xmlDoc.Error())
    return false;

  TiXmlElement *pRootElement = xmlDoc.RootElement();
  if (pRootElement)
  {
    CStdString strItemTmp;
    TiXmlElement *pElement = pRootElement->FirstChildElement("loc");
    while (pElement)
    {
      if (!pElement->NoChildren())
      {
        strItemTmp.Format("%s - %s", pElement->Attribute("id"), pElement->FirstChild()->Value());
        pDlgSelect->Add(strItemTmp);
      }
      pElement = pElement->NextSiblingElement("loc");
    }
  }

  if (pDlgProgress)
    pDlgProgress->Close();

  pDlgSelect->EnableButton(true, 222); //'Cancel' button returns to weather settings
  pDlgSelect->DoModal();

  if (pDlgSelect->GetSelectedLabel() < 0)
  {
    if (pDlgSelect->IsButtonPressed())
    {
      pDlgSelect->Close(); //close the select dialog and return to weather settings
      return true;
    }
  }

  //copy the selected code into the settings
  if (pDlgSelect->GetSelectedLabel() >= 0)
    strResult = pDlgSelect->GetSelectedLabelText();

  if (pDlgProgress)
    pDlgProgress->Close();

  return true;
}
bool CUpdateXMLHandler::LoadXMLToMem (std::string rootDir)
{
    std::string UpdateXMLFilename = rootDir  + DirSepChar + "xbmc-txupdate.xml";
    TiXmlDocument xmlUpdateXML;

    if (!xmlUpdateXML.LoadFile(UpdateXMLFilename.c_str()))
    {
        CLog::Log(logERROR, "UpdXMLHandler: No 'xbmc-txupdate.xml' file exists in the specified project dir. Cannot continue. "
                  "Please create one!");
        return false;
    }

    CLog::Log(logINFO, "UpdXMLHandler: Succesfuly found the update.xml file in the specified project directory");

    TiXmlElement* pRootElement = xmlUpdateXML.RootElement();
    if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="resources")
    {
        CLog::Log(logERROR, "UpdXMLHandler: No root element called \"resources\" in xml file. Cannot continue. Please create it");
        return false;
    }

    std::string strProjName ;
    if (pRootElement->Attribute("projectname") && (strProjName = pRootElement->Attribute("projectname")) != "")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Found projectname in xbmc-txupdate.xml file: %s",strProjName.c_str());
        g_Settings.SetProjectname(strProjName);
    }
    else
        CLog::Log(logERROR, "UpdXMLHandler: No projectname specified in xbmc-txupdate.xml file. Cannot continue. "
                  "Please specify the Transifex projectname in the xml file");

    std::string strHTTPCacheExp;
    if (pRootElement->Attribute("http_cache_expire") && (strHTTPCacheExp = pRootElement->Attribute("http_cache_expire")) != "")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Found http cache expire time in xbmc-txupdate.xml file: %s", strHTTPCacheExp.c_str());
        g_Settings.SetHTTPCacheExpire(strtol(&strHTTPCacheExp[0], NULL, 10));
    }
    else
        CLog::Log(logINFO, "UpdXMLHandler: No http cache expire time specified in xbmc-txupdate.xml file. Using default value: %iminutes",
                  DEFAULTCACHEEXPIRE);

    std::string strMinCompletion;
    if (pRootElement->Attribute("min_completion") && (strMinCompletion = pRootElement->Attribute("min_completion")) != "")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Found min completion percentage in xbmc-txupdate.xml file: %s", strMinCompletion.c_str());
        g_Settings.SetMinCompletion(strtol(&strMinCompletion[0], NULL, 10));
    }
    else
        CLog::Log(logINFO, "UpdXMLHandler: No min completion percentage specified in xbmc-txupdate.xml file. Using default value: %i%",
                  DEFAULTMINCOMPLETION);

    std::string strMergedLangfileDir;
    if (pRootElement->Attribute("merged_langfiledir") && (strMergedLangfileDir = pRootElement->Attribute("merged_langfiledir")) != "")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Found merged language file directory in xbmc-txupdate.xml file: %s", strMergedLangfileDir.c_str());
        g_Settings.SetMergedLangfilesDir(strMergedLangfileDir);
    }
    else
        CLog::Log(logINFO, "UpdXMLHandler: No merged language file directory specified in xbmc-txupdate.xml file. Using default value: %s",
                  g_Settings.GetMergedLangfilesDir().c_str());

    std::string strTXUpdatelangfileDir;
    if (pRootElement->Attribute("temptxupdate_langfiledir") && (strTXUpdatelangfileDir = pRootElement->Attribute("temptxupdate_langfiledir")) != "")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Found temp tx update language file directory in xbmc-txupdate.xml file: %s", strTXUpdatelangfileDir.c_str());
        g_Settings.SetTXUpdateLangfilesDir(strTXUpdatelangfileDir);
    }
    else
        CLog::Log(logINFO, "UpdXMLHandler: No temp tx update language file directory specified in xbmc-txupdate.xml file. Using default value: %s",
                  g_Settings.GetTXUpdateLangfilesDir().c_str());

    std::string strSupportEmailAdd;
    if (pRootElement->Attribute("support_email") && (strSupportEmailAdd = pRootElement->Attribute("support_email")) != "")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Found support email address in xbmc-txupdate.xml file: %s", strSupportEmailAdd.c_str());
        g_Settings.SetSupportEmailAdd(strSupportEmailAdd);
    }
    else
        CLog::Log(logINFO, "UpdXMLHandler: No support email address specified in xbmc-txupdate.xml file. Using default value: %s",
                  g_Settings.GetSupportEmailAdd().c_str());

    std::string strForcePOComm;
    if (pRootElement->Attribute("forcePOComm") && (strForcePOComm = pRootElement->Attribute("forcePOComm")) == "true")
    {
        CLog::Log(logINFO, "UpdXMLHandler: Forced PO file comments for non English languages.", strMergedLangfileDir.c_str());
        g_Settings.SetForcePOComments(true);
    }

    const TiXmlElement *pChildResElement = pRootElement->FirstChildElement("resource");
    if (!pChildResElement || pChildResElement->NoChildren())
    {
        CLog::Log(logERROR, "UpdXMLHandler: No xml element called \"resource\" exists in the xml file. Cannot continue. Please create at least one");
        return false;
    }

    std::string strType;
    while (pChildResElement && pChildResElement->FirstChild())
    {
        CXMLResdata currResData;
        std::string strResName;
        if (!pChildResElement->Attribute("name") || (strResName = pChildResElement->Attribute("name")) == "")
        {
            CLog::Log(logERROR, "UpdXMLHandler: No name specified for resource. Cannot continue. Please specify it.");
            return false;
        }

        if (pChildResElement->FirstChild())
        {
            const TiXmlElement *pChildURLElement = pChildResElement->FirstChildElement("upstreamURL");
            if (pChildURLElement && pChildURLElement->FirstChild())
                currResData.strUpstreamURL = pChildURLElement->FirstChild()->Value();
            if (currResData.strUpstreamURL.empty())
                CLog::Log(logERROR, "UpdXMLHandler: UpstreamURL entry is empty or missing for resource %s", strResName.c_str());
            if (pChildURLElement->Attribute("filetype"))
                currResData.strLangFileType = pChildURLElement->Attribute("filetype"); // For PO no need to explicitly specify. Only for XML.
            if (pChildURLElement->Attribute("URLsuffix"))
                currResData.strURLSuffix = pChildURLElement->Attribute("URLsuffix"); // Some http servers need suffix strings after filename(eg. gitweb)
            if (pChildURLElement->Attribute("HasChangelog"))
            {
                std::string strHaschangelog = pChildURLElement->Attribute("HasChangelog"); // Note if the addon has upstream changelog
                currResData.bHasChangelog = strHaschangelog == "true";
            }
            if (pChildURLElement->Attribute("LogFormat"))
            {
                std::string strLogFormat = pChildURLElement->Attribute("LogFormat");
                currResData.strLogFormat = strLogFormat;
            }
            if (pChildURLElement->Attribute("LogFilename"))
            {
                std::string strLogFilename = pChildURLElement->Attribute("LogFilename");
                currResData.strLogFilename = strLogFilename;
            }

            const TiXmlElement *pChildUpstrLElement = pChildResElement->FirstChildElement("upstreamLangs");
            if (pChildUpstrLElement && pChildUpstrLElement->FirstChild())
                currResData.strLangsFromUpstream = pChildUpstrLElement->FirstChild()->Value();

            const TiXmlElement *pChildResTypeElement = pChildResElement->FirstChildElement("resourceType");
            if (pChildResTypeElement->Attribute("AddonXMLSuffix"))
                currResData.strAddonXMLSuffix = pChildResTypeElement->Attribute("AddonXMLSuffix"); // Some addons have unique addon.xml filename eg. pvr addons with .in suffix
            if (pChildResTypeElement && pChildResTypeElement->FirstChild())
            {
                strType = pChildResTypeElement->FirstChild()->Value();
                if (strType == "addon")
                    currResData.Restype = ADDON;
                else if (strType == "addon_nostrings")
                    currResData.Restype = ADDON_NOSTRINGS;
                else if (strType == "skin")
                    currResData.Restype = SKIN;
                else if (strType == "xbmc_core")
                    currResData.Restype = CORE;
            }
            if (currResData.Restype == UNKNOWN)
                CLog::Log(logERROR, "UpdXMLHandler: Unknown type found or missing resourceType field for resource %s", strResName.c_str());

            const TiXmlElement *pChildResDirElement = pChildResElement->FirstChildElement("resourceSubdir");
            if (pChildResDirElement && pChildResDirElement->FirstChild())
                currResData.strResDirectory = pChildResDirElement->FirstChild()->Value();
            if (pChildResDirElement->Attribute("writePO"))
            {
                std::string strBool = pChildResDirElement->Attribute("writePO");
                currResData.bWritePO = strBool == "true";
            }
            if (pChildResDirElement->Attribute("writeXML"))
            {
                std::string strBool = pChildResDirElement->Attribute("writeXML");
                currResData.bWriteXML = strBool == "true";
            }
            if (pChildResDirElement->Attribute("DIRprefix"))
                currResData.strDIRprefix = pChildResDirElement->Attribute("DIRprefix"); // If there is any SUBdirectory needed in the tree

            const TiXmlElement *pChildTXNameElement = pChildResElement->FirstChildElement("TXname");
            if (pChildTXNameElement && pChildTXNameElement->FirstChild())
                currResData.strTXResName = pChildTXNameElement->FirstChild()->Value();
            if (currResData.strTXResName.empty())
                CLog::Log(logERROR, "UpdXMLHandler: Transifex resource name is empty or missing for resource %s", strResName.c_str());

            m_mapXMLResdata[strResName] = currResData;
            CLog::Log(logINFO, "UpdXMLHandler: found resource in update.xml file: %s, Type: %s, SubDir: %s",
                      strResName.c_str(), strType.c_str(), currResData.strResDirectory.c_str());
        }
        pChildResElement = pChildResElement->NextSiblingElement("resource");
    }

    return true;
};
Beispiel #12
0
void CMBrowser::OnSessionCmd(unsigned int nCmdID, unsigned int nCode, TiXmlDocument* pDoc)
{

    if(nCmdID == SERVICE_GETCOURSEWAREBYID || nCmdID == SERVICE_GETNEWSBYID)
    {

        Clear();
        INT32 result = TResult::EUnknownError;
        if (nCode == MER_OK)
        {
            ASSERT(pDoc);

            TiXmlElement *pItem = pDoc->RootElement();
            INT32 nErr = 0;
            INT32 nCmdID = 0;
            pItem->QueryIntAttribute("no", &nCmdID);
            if (m_bPaging)
            {
				pItem->QueryIntAttribute("totalcount", &m_nTotalCount);
				pItem->QueryIntAttribute("pageno", &m_nPageNo);
				int count = m_nTotalCount/m_nPageSize;
				if(m_nTotalCount%m_nPageSize > 0)
					count++;
				m_bEnd = (m_nPageNo >= count);
            }

            if(pItem->QueryIntAttribute("errno", &nErr) == TIXML_SUCCESS)
            {
                if (nErr == 0)
                {
                    if(!pItem->NoChildren())
					{

                        TiXmlElement* plistItem = pItem->FirstChildElement("item");
                        while(plistItem)
                        {

                            TBrowserItem* bItem= new TCoursewareItem();
                            bItem->bIsHeadItem=FALSE;
                            if(nCmdID == SERVICE_GETCOURSEWAREBYID)
                                bItem->nModel = 1;
                            else
                                bItem->nModel = 0;

                            *bItem=plistItem;

                            m_lstItem -> push_back(bItem);

                            plistItem = plistItem->NextSiblingElement("item");
                        }
                    }

                    if(m_lstItem && m_lstItem->size() > 0)
						result = TResult::ESuccess;
					else
						result = TResult::ENothing;
                }
                else if(nErr = -17)
                {
                	result = TResult::ENoPowerCourse;
                }
            }
            else
                result = TResult::EProtocolFormatError;

        } else if (nCode == MERN_OFFLINE)
        {
            result = TResult::ENotSupportOffline;
        }
        else if(nCode == MERN_INITIALIZE)
        {
            result = TResult::ENetDisconnect;
        }
        else
            result = TResult::ENetTimeout;

        if(m_pListener)
            m_pListener->OnUpdateDataFinish(m_UserData, result);

    }
    else
        CMContenthandler::OnSessionCmd(nCmdID, nCode, pDoc);

}
Beispiel #13
0
bool CUpdateXMLHandler::DownloadXMLToMap (std::string strURL, std::map<std::string, CXMLResdata> &mapResourceData, std::string const &strTXProjectname)
{
  std::string strURLXMLFile = strURL + "xbmc-txupdate.xml";

  std::string strXMLFile = g_HTTPHandler.GetURLToSTR(strURLXMLFile);
  if (strXMLFile.empty())
    CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: http error getting XML file from upstream url: %s", strURL.c_str());

  TiXmlDocument xmlUpdateXML;

  if (!xmlUpdateXML.Parse(strXMLFile.c_str(), 0, TIXML_DEFAULT_ENCODING))
  {
    CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: UpdateXML file problem: %s %s\n", xmlUpdateXML.ErrorDesc(), strURL.c_str());
    return false;
  }

  TiXmlElement* pRootElement = xmlUpdateXML.RootElement();
  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="resources")
  {
    CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No root element called \"resources\" in xml file. Cannot continue. Please create it");
    return false;
  }

  std::string strProjName;
  if (!pRootElement->Attribute("projectname") || (strProjName = pRootElement->Attribute("projectname")) == "")
    CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No projectname specified in xbmc-txupdate.xml file. Cannot continue. "
                        "Please contact TeamXBMC about this problem!");

    CLog::Log(logINFO, "Reading xbmc-txupdate.xml file for project: %s", strTXProjectname.c_str());

  std::string strMergedLangfileDir;
  if (!pRootElement->Attribute("merged_langfiledir") || (strMergedLangfileDir = pRootElement->Attribute("merged_langfiledir")) == "")
    strMergedLangfileDir = DEFAULTMERGEDLANGDIR;

  const TiXmlElement *pChildResElement = pRootElement->FirstChildElement("resource");
  if (!pChildResElement || pChildResElement->NoChildren())
  {
    CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No xml element called \"resource\" exists in the xml file. Please contact TeamXBMC about this problem!");
    return false;
  }

  std::string strType;
  while (pChildResElement && pChildResElement->FirstChild())
  {
    CXMLResdata currResData;
    currResData.strTranslationrepoURL = strURL;
    currResData.strProjName = strProjName;
    currResData.strMergedLangfileDir = strMergedLangfileDir;

    std::string strResName;
    if (!pChildResElement->Attribute("name") || (strResName = pChildResElement->Attribute("name")) == "")
    {
      CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No name specified for resource. Cannot continue. Please contact TeamXBMC about this problem!");
      return false;
    }

    currResData.strResName = strResName;

    if (pChildResElement->FirstChild())
    {
      const TiXmlElement *pChildURLElement = pChildResElement->FirstChildElement("upstreamURL");
      if (pChildURLElement && pChildURLElement->FirstChild())
        currResData.strUpstreamURL = pChildURLElement->FirstChild()->Value();
      if (currResData.strUpstreamURL.empty())
        CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: UpstreamURL entry is empty or missing for resource %s", strResName.c_str());
      if (pChildURLElement->Attribute("filetype"))
        currResData.strLangFileType = pChildURLElement->Attribute("filetype"); // For PO no need to explicitly specify. Only for XML.
      if (pChildURLElement->Attribute("URLsuffix"))
        currResData.strURLSuffix = pChildURLElement->Attribute("URLsuffix"); // Some http servers need suffix strings after filename(eg. gitweb)
      if (pChildURLElement->Attribute("HasChangelog"))
      {
        std::string strHaschangelog = pChildURLElement->Attribute("HasChangelog"); // Note if the addon has upstream changelog
        currResData.bHasChangelog = strHaschangelog == "true";
      }
      if (pChildURLElement->Attribute("LogFormat"))
      {
        std::string strLogFormat = pChildURLElement->Attribute("LogFormat");
        currResData.strLogFormat = strLogFormat;
      }
      if (pChildURLElement->Attribute("LogFilename"))
      {
        std::string strLogFilename = pChildURLElement->Attribute("LogFilename");
        currResData.strLogFilename = strLogFilename;
      }

      const TiXmlElement *pChildUpstrLElement = pChildResElement->FirstChildElement("upstreamLangs");
      if (pChildUpstrLElement && pChildUpstrLElement->FirstChild())
        currResData.strLangsFromUpstream = pChildUpstrLElement->FirstChild()->Value();

      const TiXmlElement *pChildResTypeElement = pChildResElement->FirstChildElement("resourceType");
      if (pChildResTypeElement->Attribute("AddonXMLSuffix"))
        currResData.strAddonXMLSuffix = pChildResTypeElement->Attribute("AddonXMLSuffix"); // Some addons have unique addon.xml filename eg. pvr addons with .in suffix
      if (pChildResTypeElement && pChildResTypeElement->FirstChild())
      {
        strType = pChildResTypeElement->FirstChild()->Value();
        if (strType == "addon")
         currResData.Restype = ADDON;
        else if (strType == "addon_nostrings")
          currResData.Restype = ADDON_NOSTRINGS;
        else if (strType == "skin")
          currResData.Restype = SKIN;
        else if (strType == "xbmc_core")
          currResData.Restype = CORE;
      }
      if (currResData.Restype == UNKNOWN)
        CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: Unknown type found or missing resourceType field for resource %s", strResName.c_str());

      const TiXmlElement *pChildResDirElement = pChildResElement->FirstChildElement("resourceSubdir");
      if (pChildResDirElement && pChildResDirElement->FirstChild())
        currResData.strResDirectory = pChildResDirElement->FirstChild()->Value();
      if (pChildResDirElement->Attribute("writePO"))
      {
	      std::string strBool = pChildResDirElement->Attribute("writePO");
        currResData.bWritePO = strBool == "true";
      }
      if (pChildResDirElement->Attribute("writeXML"))
      {
	      std::string strBool = pChildResDirElement->Attribute("writeXML");
        currResData.bWriteXML = strBool == "true";
      }
      if (pChildResDirElement->Attribute("DIRprefix"))
        currResData.strDIRprefix = pChildResDirElement->Attribute("DIRprefix"); // If there is any SUBdirectory needed in the tree

      const TiXmlElement *pChildTXNameElement = pChildResElement->FirstChildElement("TXname");
      if (pChildTXNameElement && pChildTXNameElement->FirstChild())
        currResData.strTXResName = pChildTXNameElement->FirstChild()->Value();
      if (currResData.strTXResName.empty())
        CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: Transifex resource name is empty or missing for resource %s", strResName.c_str());

      currResData.strResNameFull = strTXProjectname + "/" + strResName;
      mapResourceData[currResData.strResNameFull] = currResData;
    }
    pChildResElement = pChildResElement->NextSiblingElement("resource");
  }

  return true;
};
Beispiel #14
0
bool MainFrame::TransferNode(TiXmlNode** node, const wxArrayString& path)
{
  if (!path.IsEmpty())
  {
    int           level     = 0;
    TiXmlElement* element   = mCfgDst->FirstChildElement("CodeBlocksConfig");
    TiXmlNode*    node_copy = (*node)->Clone();

    if (!TiXmlSuccess(mCfgDst))
      return false;

    for (size_t i=0; i<path.Count(); ++i)
    {
      wxString section_path = path.Item(i);

      if (element->NoChildren())
      {
        // element has no children -> create new child named after section
        element = (TiXmlElement*) element->InsertEndChild(
          TiXmlElement(
#if wxUSE_UNICODE
            section_path.mb_str(wxConvUTF8)
#else
            (wxChar*)section_path.mb_str()
#endif
          ));
      }// if
      else
      {
        // element has children -> find child named after section
        TiXmlElement* new_element = element->FirstChildElement(
#if wxUSE_UNICODE
          section_path.mb_str(wxConvUTF8)
#else
          (wxChar*)section_path.mb_str()
#endif
        );

        if (!new_element)
        {
          // child could not be found -> create child named after section
          element = (TiXmlElement*) element->InsertEndChild(TiXmlElement(
#if wxUSE_UNICODE
            section_path.mb_str(wxConvUTF8)
#else
            (wxChar*)section_path.mb_str()
#endif
            ));
        }
        else
        {
          // child has been found -> switch to this child
          element = new_element;
        }
      }// else

      if (!element)
        return false;

      // ...continue with next section.
    }

    TiXmlNode* parent_node = element->Parent();
    parent_node->ReplaceChild(element, *node_copy);

    return true;
  }

  return false;
}// TransferNode
Beispiel #15
0
void MainFrame::OnBtnExportClick(wxCommandEvent& event)
{
  TiXmlDocument* doc = new TiXmlDocument();

  if (doc)
  {
    if (mCfgSrcValid)
    {
      wxMessageBox(wxT("You are about to export the selected node(s) to a backup C::B configuration file.\n"
                       "Please note that this is *not* complete because it includes the selected node(s) only.\n"
                       "It's purpose is to backup misc. nodes for transferring them using cb_share_config."),
                   wxT("Information"), wxICON_INFORMATION);

      TiXmlDeclaration* decl = new TiXmlDeclaration("1.0", "UTF-8", "yes");
      TiXmlElement*     root = new TiXmlElement("CodeBlocksConfig");
      // NOTE (Morten#1#): This has to be in sync with C::B SDK (confimanager)!
      root->SetAttribute("version", 1);

      doc->LinkEndChild(decl);
      doc->LinkEndChild(root);

      // Save all (checked) variables of lstEnvVars
      int items_selected = 0;
      for (int i=0; i<clbCfgSrc->GetCount(); ++i)
      {
        if (clbCfgSrc->IsChecked(i) && (mNodesSrc.size()>i))
        {
          items_selected++;

          TiXmlNode*    node     = mNodesSrc.at(i);
          wxString      path     = clbCfgSrc->GetString(i);
          wxArrayString path_arr = PathToArray(path);

          TiXmlElement* element  = root;
          for (size_t i=0; i<path_arr.Count(); ++i)
          {
            wxString section_path = path_arr.Item(i);
            if (element->NoChildren())
            {
              // element has no children -> create new child named after section
              element = (TiXmlElement*) element->InsertEndChild(
                TiXmlElement(
#if wxUSE_UNICODE
                  section_path.mb_str(wxConvUTF8)
#else
                  (wxChar*)section_path.mb_str()
#endif
                ));
            }// if
            else
            {
              // element has children -> find child named after section
              TiXmlElement* new_element = element->FirstChildElement(
#if wxUSE_UNICODE
                section_path.mb_str(wxConvUTF8)
#else
                (wxChar*)section_path.mb_str()
#endif
              );

              if (!new_element)
              {
                // child could not be found -> create child named after section
                element = (TiXmlElement*) element->InsertEndChild(TiXmlElement(
#if wxUSE_UNICODE
                  section_path.mb_str(wxConvUTF8)
#else
                  (wxChar*)section_path.mb_str()
#endif
                  ));
              }
              else
              {
                // child has been found -> switch to this child
                element = new_element;
              }
            }

            if (!element)
              return;
            // ...continue with next section.
          }

          TiXmlNode* parent_node = element->Parent();
          parent_node->ReplaceChild(element, *node);
        }
      }

      if (items_selected)
      {
        wxString filename = wxFileSelector
        (
          wxT("Choose a Code::Blocks backup configuration file"), // title
          wxT(""),                                                // default path
          wxT("backup.conf"),                                     // default file
          wxT("*.conf"),                                          // default extension
          wxT("Code::Blocks configuration files (*.conf)|*.conf|"
              "All files (*.*)|*.*"),                             // wildcards
          wxFD_SAVE                                               // flags
        );
        if (!filename.IsEmpty())
        {
          if (TiXmlSaveDocument(filename, doc))
          {
            wxMessageBox(wxT("Backup configuration file has been saved."),
                         wxT("Information"), wxICON_INFORMATION | wxOK);
          }
          else
          {
            wxMessageBox(wxT("Could not save backup configuration file."),
                         wxT("Warning"), wxICON_EXCLAMATION | wxOK);
          }
        }
      }
      else
      {
        wxMessageBox(wxT("There were no items selected to backup."),
                     wxT("Warning"), wxICON_EXCLAMATION | wxOK);
      }
    }

    delete doc;
  }
  else
  {
    wxMessageBox(wxT("Cannot create empty XML document...?!"),
                 wxT("Error"), wxICON_EXCLAMATION | wxOK);
  }
}// OnBtnExportClick
Beispiel #16
0
//This function loads a map from the specified .tmx file
void Game::LoadMap(string filename)
{
	//Create our Root Document handle and open it up
	TiXmlDocument Root(filename.c_str());
	if (!Root.LoadFile()) throw std::runtime_error(string("Failed to open level file: ") + filename);

	//Get a handle to our first set of 'layer' data in the map. This could be anything from a tile/object layer to tileset info,
	//so we need to check what it is before we do anything with it.
	TiXmlElement *Layer = Root.FirstChildElement("map")->FirstChildElement();

	//Clear out any existing object data
	GameStorage->ClearAll();

	//Loop through all layers we can find in the map data
	while (Layer)
	{
		//Check for an object layer that has child elements. Currently this is the only kind we're interested in.
		if (string(Layer->Value()) == "objectgroup" && !Layer->NoChildren())
		{
			//Get our first object in this layer
			TiXmlElement *Object = Layer->FirstChildElement();
			//Get the name of our layer
			string name(Layer->Attribute("name"));
			ColourType colour;

			//Convert name to lower-case
			for (int i = 0; i < name.length(); i++)
			{
				name[i] = tolower(name[i]);
			}

			//Loop through all objects
			while (Object)
			{
				string type((Object->Attribute("type") != NULL) ? Object->Attribute("type") : "");

				//Depending on the type of this layer, spawn a certain type of object
				if (name == "red")
				{
					colour = COLOUR_RED;
				}
				else if (name == "blue")
				{
					colour = COLOUR_BLUE;
				}
				else if (name == "yellow")
				{
					colour = COLOUR_YELLOW;
				}
				else if (name == "white")
				{
					colour = COLOUR_WHITE;
				}
				else if (name == "player")
				{
					player.ReadPosition(Object);
				}
				else if (name == "exit")
				{
					exit.ReadPosition(Object);
				}

				if (name != "player" && name != "exit")
				{
					if (type == "" || type == "normal")
					{
						GameStorage->AddObject(GameObjectPointer(new ColourBox(Object, colour)));
					}
					else if (type == "moveable")
					{

					}
					else if (type == "moving")
					{
						GameStorage->AddObject(GameObjectPointer(new MovingColourBlock(Object, colour)));
					}
				}

				Object = Object->NextSiblingElement();
			}
		}

		Layer = Layer->NextSiblingElement();
	}

	ColouredObject::SetCurrentColour(COLOUR_RED);
}
Beispiel #17
0
std::list<CInputData> CInputXMLHandler::ReadXMLToMem(string strFileName)
{
  std::string strXMLFile = g_File.ReadFileToStr(strFileName);
  if (strXMLFile.empty())
    CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: http error getting XML file from path: %s", strFileName.c_str());

  TiXmlDocument xmlUpdateXML;

  if (!xmlUpdateXML.Parse(strXMLFile.c_str(), 0, TIXML_DEFAULT_ENCODING))
    CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: UpdateXML file problem: %s %s\n", xmlUpdateXML.ErrorDesc(), strFileName.c_str());

  TiXmlElement* pRootElement = xmlUpdateXML.RootElement();
  if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="addonlist")
    CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: No root element called \"addonlist\" in xml file. Cannot continue. Please create it");

  const TiXmlElement *pChildResElement = pRootElement->FirstChildElement("addon");
  if (!pChildResElement || pChildResElement->NoChildren())
    CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: No xml element called \"addon\" exists in the xml file. Please contact TeamXBMC about this problem!");

  std::list<CInputData> listInputData;

  while (pChildResElement && pChildResElement->FirstChild())
  {
    CInputData currInputData;

    std::string strResName;
    if (!pChildResElement->Attribute("name") || (strResName = pChildResElement->Attribute("name")) == "")
      CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: No name specified for addon. Cannot continue.");

    currInputData.strAddonName = strResName;

    const TiXmlElement *pChildDirElement = pChildResElement->FirstChildElement("localdir");
    if (pChildDirElement && pChildDirElement->FirstChild())
      currInputData.strAddonDir = pChildDirElement->FirstChild()->Value();
    if (currInputData.strAddonDir.empty())
      CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: Local directory is missing for addon: %s", strResName.c_str());

    std::string strBool;
    const TiXmlElement *pChildSkipchlogElement = pChildResElement->FirstChildElement("skipchangelog");
    if (pChildSkipchlogElement && pChildSkipchlogElement->FirstChild())
      strBool = pChildSkipchlogElement->FirstChild()->Value();
    currInputData.bSkipChangelog = (strBool == "true");

    strBool.clear();
    const TiXmlElement *pChildSkipenglishElement = pChildResElement->FirstChildElement("skipenglish");
    if (pChildSkipenglishElement && pChildSkipenglishElement->FirstChild())
      strBool = pChildSkipenglishElement->FirstChild()->Value();
    currInputData.bSkipEnglishFile = (strBool == "true");

    const TiXmlElement *pChildGittemplElement = pChildResElement->FirstChildElement("gittemplate");
    if (pChildGittemplElement && pChildGittemplElement->FirstChild())
      currInputData.strGittemplate = pChildGittemplElement->FirstChild()->Value();
    std::string strGitExecPath;
    if (pChildGittemplElement->Attribute("gitexecpath") && (strGitExecPath = pChildGittemplElement->Attribute("gitexecpath")) != "")
      currInputData.strGitExecPath = strGitExecPath;

    listInputData.push_back(currInputData);

    pChildResElement = pChildResElement->NextSiblingElement("addon");
  }
  return listInputData;
}
Beispiel #18
0
void XMLParser::navigateChildren (int depth, XMLElement *parent, TiXmlElement *element)
{
	#ifdef defAPI_TINY_XML
		TiXmlElement *xeElm = element;
		xeElm = xeElm->FirstChildElement ();

		while (xeElm != 0)
		{
			XMLElement *xmlElment = new XMLElement ();
			const char *cParentValue = (const char *)element->Value ();
			const char *cValue = (const char *)xeElm->Value ();
			const char *cContent = 0;
			std::string strParentValue = "";
			std::string strValue = "";
			std::string strContent = "";

			if (xeElm->NoChildren () == false)
			{
				TiXmlNode *xeChild = xeElm->FirstChild ();

				if (xeChild != 0)
					cContent = xeChild->Value ();
			}

			if (cParentValue != 0)
				strParentValue = cParentValue;

			if (cValue != 0)
				strValue = cValue;

			if (cContent != 0)
				strContent = cContent;

			std::vector<std::string> aryAttributeNames;
			std::vector<std::string> aryAttributeValues;
			TiXmlAttribute *xaAtt = xeElm->FirstAttribute ();

			while (xaAtt != 0)
			{
				const char *cAttributeName = (const char *)xaAtt->Name ();
				std::string strAttributeName = "";
				const char *cAttributeValue = (const char *)xaAtt->Value ();
				std::string strAttributeValue = "";

				if (cAttributeName != 0)
					strAttributeName = cAttributeName;

				if (cAttributeValue != 0)
					strAttributeValue = cAttributeValue;

				aryAttributeNames.push_back (strAttributeName);
				aryAttributeValues.push_back (strAttributeValue);

				xaAtt = xaAtt->Next ();
			}

			xmlElment->parent = parent;
			xmlElment->tag = strValue;

			for (unsigned int iIdx = 0; iIdx < aryAttributeNames.size (); iIdx++)
				xmlElment->aryAttributeNames.push_back (aryAttributeNames.at (iIdx));

			for (unsigned int iIdx = 0; iIdx < aryAttributeValues.size (); iIdx++)
				xmlElment->aryAttributeValues.push_back (aryAttributeValues.at (iIdx));

			xmlElment->content = strContent;
			xmlElment->parentParser = this;

			if (parent == 0)
				aryElements->push_back (xmlElment);
			else
				parent->children->push_back (xmlElment);

			if (xeElm->NoChildren () == false)
				navigateChildren (depth++, xmlElment, xeElm);

			xeElm = xeElm->NextSiblingElement ();
		}
	#endif
}
Beispiel #19
0
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;
    std::string value;
    value = pNode->Value();
    StringUtils::ToLower(value);
    pNode->SetValue(value);
    while(pNode)
    {
      pChild = pNode->IterateChildren(pChild);
      if(pChild)
      {
        if (pChild->Type() == TiXmlNode::TINYXML_ELEMENT)
        {
          value = pChild->Value();
          StringUtils::ToLower(value);
          pChild->SetValue(value);

          TiXmlAttribute* pAttr = pChild->ToElement()->FirstAttribute();
          while(pAttr)
          {
            value = pAttr->Name();
            StringUtils::ToLower(value);
            pAttr->SetName(value);
            pAttr = pAttr->Next();
          }
        }

        pNode = pChild;
        pChild = NULL;
        continue;
      }

      pChild = pNode;
      pNode = pNode->Parent();
    }
    std::string roottitle;
    TiXmlElement *pElement = pRootElement->FirstChildElement();
    while (pElement)
    {
      value = pElement->Value();
      if (value == "title" && !pElement->NoChildren())
      {
        roottitle = pElement->FirstChild()->ValueStr();
      }
      else if (value == "entry")
      {
        std::string title(roottitle);

        TiXmlElement *pRef = pElement->FirstChildElement("ref");
        TiXmlElement *pTitle = pElement->FirstChildElement("title");

        if(pTitle && !pTitle->NoChildren())
          title = pTitle->FirstChild()->ValueStr();

        while (pRef)
        { // multiple references may apear for one entry
          // duration may exist on this level too
          value = XMLUtils::GetAttribute(pRef, "href");
          if (!value.empty())
          {
            if(title.empty())
              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 = XMLUtils::GetAttribute(pElement, "href");
        if (!value.empty())
        { // 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;
}
Beispiel #20
0
bool ConfigFile::ImportXML(std::string strXML)
{
    TiXmlDocument doc;
    
    //Load document from strXML using streams
    std::istringstream strIStream;
    strIStream.str(strXML);
    strIStream >> doc;
    
    if ( doc.NoChildren() )
	{
		std::cout << "Could not parse xml string. Error='" << doc.ErrorDesc() << "'. Using Default Data"  << std::endl;
        m_strLastError = doc.ErrorDesc();
        //Use already loaded defaults
		return false;
	}

    TiXmlNode* parent = 0;
    TiXmlNode* child = 0;
    TiXmlNode* tempChild = 0;
	TiXmlElement* configElement = 0;
	TiXmlElement* itemElement = 0;
    TiXmlElement* tempElement = 0;

	// Get the "configData" element.
    parent = doc.FirstChild( m_strIdentifier.c_str() );
	assert( parent  );
	configElement =parent->ToElement();
	assert( configElement  );	

	//Read all the configuration data
    for( child = configElement->FirstChild(); child; child = child->NextSibling() )
    {
        itemElement = child->ToElement();
	    assert( itemElement  );
        
        //convert to uppercase
        std::string strElement = itemElement->Value();

        //replace underscore with whitespace
        std::replace(strElement.begin(), strElement.end(), '_', ' ');

        ConfigAttribute element;
        element.strAttribute = strElement;
        element.strValue = itemElement->Attribute( "value");
        
        //Read the sub items from the file and store as an array
        if(!itemElement->NoChildren() || element.strValue == "Array()")
        {
            element.bIsArray = true;

            for( tempChild = itemElement->FirstChild(); tempChild; tempChild = tempChild->NextSibling() )
            {
                tempElement = tempChild->ToElement();
                assert( tempElement  );

                element.listValues.push_back(tempElement->Attribute( "value"));
            }

        }
        m_mapConfig[Uppercase(strElement)] = element;
    }

    return true;

    return true;
}
Beispiel #21
0
bool CSavestate::Deserialize(const std::string& path)
{
  Reset();

  TiXmlDocument xmlFile;
  if (!xmlFile.LoadFile(path))
  {
    CLog::Log(LOGERROR, "Failed to open %s: %s", path.c_str(), xmlFile.ErrorDesc());
    return false;
  }

  TiXmlElement* pElement = xmlFile.RootElement();
  if (!pElement || pElement->NoChildren() || pElement->ValueStr() != SAVESTATE_XML_ROOT)
  {
    CLog::Log(LOGERROR, "Can't find root <%s> tag", SAVESTATE_XML_ROOT);
    return false;
  }

  // Path
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_PATH, m_path))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_PATH);
    return false;
  }

  // Type
  std::string type;
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_TYPE, type))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_TYPE);
    return false;
  }
  m_type = CSavestateTranslator::TranslateType(type);
  if (m_type == SAVETYPE::UNKNOWN)
  {
    CLog::Log(LOGERROR, "Invalid savestate type: %s", type.c_str());
    return false;
  }

  // Slot
  if (m_type == SAVETYPE::SLOT)
  {
    if (!XMLUtils::GetInt(pElement, SAVESTATE_FIELD_SLOT, m_slot))
    {
      CLog::Log(LOGERROR, "Savestate has type \"%s\" but no <%s> element!", type.c_str(), SAVESTATE_FIELD_TYPE);
      return false;
    }
    if (m_slot < 0)
    {
      CLog::Log(LOGERROR, "Invalid savestate slot: %d", m_slot);
      return false;
    }
  }

  // Label (optional)
  XMLUtils::GetString(pElement, SAVESTATE_FIELD_LABEL, m_label);

  // Size
  long size;
  if (!XMLUtils::GetLong(pElement, SAVESTATE_FIELD_SIZE, size))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_SIZE);
    return false;
  }
  if (size < 0)
  {
    CLog::Log(LOGERROR, "Invalid savestate size: %ld", size);
    return false;
  }
  m_size = size;

  // Game client
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_GAMECLIENT, m_gameClient))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_GAMECLIENT);
    return false;
  }

  // Game path
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_GAME_PATH, m_gamePath))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_GAME_PATH);
    return false;
  }

  // Game CRC
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_GAME_CRC, m_gameCRC))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_GAME_CRC);
    return false;
  }

  // Playtime (frames)
  long playtimeFrames;
  if (!XMLUtils::GetLong(pElement, SAVESTATE_FIELD_FRAMES, playtimeFrames))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_FRAMES);
    return false;
  }
  if (playtimeFrames < 0)
  {
    CLog::Log(LOGERROR, "Invalid savestate frame count: %ld", playtimeFrames);
    return false;
  }
  m_size = playtimeFrames;

  // Playtime (wall clock)
  float playtimeWallClock;
  if (!XMLUtils::GetFloat(pElement, SAVESTATE_FIELD_WALLCLOCK, playtimeWallClock))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_WALLCLOCK);
    return false;
  }
  m_playtimeWallClock = playtimeWallClock;

  // Timestamp
  std::string timestamp;
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_TIMESTAMP, timestamp))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_TIMESTAMP);
    return false;
  }
  if (!m_timestamp.SetFromDBDateTime(timestamp))
  {
    CLog::Log(LOGERROR, "Invalid savestate timestamp: %s", timestamp.c_str());
    return false;
  }

  // Thumbnail
  if (!XMLUtils::GetString(pElement, SAVESTATE_FIELD_THUMBNAIL, m_thumbnail))
  {
    CLog::Log(LOGERROR, "Savestate has no <%s> element", SAVESTATE_FIELD_THUMBNAIL);
    return false;
  }

  return true;
}
Beispiel #22
0
void CMFileUpload::OnSessionCmd(unsigned int nCmdID, unsigned int nCode, TiXmlDocument* pDoc)
{
    INT32 result = TResult::EUnknownError;

	if (nCode == MER_OK)
	{
        TiXmlElement *pItem = pDoc->RootElement();

		INT32 nErr = -1;
        INT32 nCmdID = 0;

        pItem->QueryIntAttribute("no", &nCmdID);

        if (nCmdID == SERVICE_UPMESSAGEPICTURE || nCmdID == SERVICE_UPGROUPHEADER) {
            const CHAR* urlStr = NULL;

            if(!pItem->NoChildren())
            {

                TiXmlElement* psonItem = pItem->FirstChildElement("item");

                urlStr = psonItem->Attribute("url");
                if(urlStr){
                    url = urlStr;
                }

                urlStr = psonItem->Attribute("thumb_url");
                if(urlStr){
                    thumb_url = urlStr;
                }

            }
        }
        if(pItem->QueryIntAttribute("errno", &nErr) == TIXML_SUCCESS)
        {
            if (nErr == 0)
            {
                m_bUploaded = TRUE;

                result = TResult::ESuccess;
            }
            else
            {
                result = nErr;
            }
        }
        else
        {
            result = TResult::EProtocolFormatError;
        }
    }
    else if(nCode == MERN_INITIALIZE)
    {
		result = TResult::ENetDisconnect;
    }
	else if(nCode == MERN_OFFLINE)
    {
		result = TResult::ENotSupportOffline;
    }
	else
    {
		result = TResult::ENetTimeout;
    }



    if(m_nCurrIndex < m_lstItem->size())
    {

//    	CMFileInfo& file = m_lstItem->at(m_nCurrIndex);

//		sMsgCode = file.sMsgCode;


//    	file.OnSimpleResultFinish(result);

        if (m_pSimpleListener)
        	m_pSimpleListener->OnRequestFinish(m_UserData, result);

    }



    //该任务上传成功 从队列移除
//    if (m_bUploaded)
//    {
	Delete(m_nCurrIndex);
//    }
}