Example #1
0
void Recurse(TiXmlNode * pParentNode, CCObject * pParentObj)
{
  std::string keyValue;
  for (TiXmlNode * pNode = pParentNode->FirstChild(); pNode; pNode = pNode->NextSiblingElement())
  {
    TiXmlElement * pNodeNE = pNode->ToElement();
    if (pNodeNE == NULL) continue;
    const char * szValue = pNodeNE->Value();
    const char * szText = pNodeNE->GetText();
    if (_stricmp(szValue, "key") == 0)
    {
      keyValue = szText;
    }
    else if (_stricmp(szValue, "dict") == 0)
    {
      CCDictionary * pNewDict = new CCDictionary;
      addObject(pParentObj, keyValue, pNewDict);
        
      Recurse(pNode, pNewDict);
    }
    else if (_stricmp(szValue, "array") == 0)
    {
      CCArray * pNewArray = new CCArray();
      addObject(pParentObj, keyValue, pNewArray);
        
      Recurse(pNode, pNewArray);
    }
    else if (_stricmp(szValue, "string") == 0)
    {
      const char * szIn = szText == NULL ? "" : szText;
      std::wstring ret = ConvertToWString(szIn);
      CCString * pString = new CCString(ret.c_str());
      addObject(pParentObj, keyValue, pString);
    }
    else if (_stricmp(szValue, "false") == 0 || _stricmp(szValue, "true") == 0)
    {
      CCBool * pBool = new CCBool(_stricmp(szValue, "true") == 0);
      addObject(pParentObj, keyValue, pBool);
    }
    else if (_stricmp(szValue, "integer") == 0)
    {
      CCInteger * pInt = new CCInteger(atoi(szText));
      addObject(pParentObj, keyValue, pInt);
    }
    else if (_stricmp(szValue, "real") == 0)
    {
      CCReal * pReal = new CCReal(atof(szText));
      addObject(pParentObj, keyValue, pReal);
    }
    else if (_stricmp(szValue, "date") == 0)
    {
      CCDate * pDate = new CCDate(getTimeFromString(szText));
      addObject(pParentObj, keyValue, pDate);
    }
    else
    {
      assert(!"unknown value");
    }
  }
}
Example #2
0
bool html_parse::_parse(TiXmlDocument& doc)
{
    TiXmlElement* rootElement = doc.RootElement();
    if (!rootElement)
    {
        return false;
    }

    std::string rootName = rootElement->ValueStr();
    if (rootName.empty()
        || rootName != "html")
    {
        return false;
    }

    for (TiXmlNode* nodeRoot = rootElement->FirstChildElement();
        nodeRoot != nullptr;
        nodeRoot = nodeRoot->NextSiblingElement())
    {
        html_object* object = new html_object;
        if (!object)
        {
            continue;
        }

        if (object->parse(nodeRoot))
        {
            m_htmlElement.push_back(object);
        }
    }
    return true;
}
Example #3
0
  XML_Element_c XML_Element_c::next() const {
    if(!m_handle.ToNode()) {
      std::cerr << "Bad XML_Element_c attempted to access next field\n";
      throw XML_Element_Ungood();
    }

    TiXmlNode * node = m_handle.ToNode();
    return XML_Element_c(node ? node->NextSiblingElement() : 0);
  }
Example #4
0
const char* SimXMLDocument::readComment( S32 index )
{
   // Clear the current attribute pointer
   m_CurrentAttribute = 0;

   // Push the first element found under the current element of the given name
   if(!m_paNode.empty())
   {
      const int iLastElement = m_paNode.size() - 1;
      TiXmlElement* pNode = m_paNode[iLastElement];
      if(!pNode)
      {
         return "";
      }
      TiXmlNode* node = pNode->FirstChild();
      for( S32 i = 0; i < index; i++ )
      {
         if( !node )
            return "";

         node = node->NextSiblingElement();
      }

      if( node )
      {
         TiXmlComment* comment = node->ToComment();
         if( comment )
            return comment->Value();
      }
   }
   else
   {
      if(!m_qDocument)
      {
         return "";
      }
      TiXmlNode* node = m_qDocument->FirstChild();
      for( S32 i = 0; i < index; i++ )
      {
         if( !node )
            return "";

         node = node->NextSibling();
      }

      if( node )
      {
         TiXmlComment* comment = node->ToComment();
         if( comment )
            return comment->Value();
      }
   }
   return "";
}
Example #5
0
TiXmlNode * readXMLConfig::SelectSingleNodeByRootEle(TiXmlElement* RootElement,string & nodeName,string nodeAttrName,string nodeAttrValue)  
{  
	//加载一个XML的文档对象。  
	 
	//  TiXmlDocument *xmlDoc = new TiXmlDocument(cXmlName);  
	//  if(!xmlDoc->LoadFile())  //是tinyXml会自动处理文档的BOM  
	//  {  
	//      return NULL;  
	//  }  
	//    
	//    
	//  if(xmlDoc == NULL)  
	//  {  
	//      return NULL;  
	//  }  
	 
	//获得根元素  
	//TiXmlElement *RootElement = xmlDoc->RootElement();  
    if(RootElement == NULL)  
    {  
        // cout << "parse error,can't get root element" << endl;
        dzlog_error("parse error,can't get root element.");  
        return NULL;  
    }  
     
    TiXmlNode * pNode  = NULL;  
    TiXmlNode * pSelectNode = NULL;  
    string msg = "";  
     
    for(pNode=RootElement->FirstChildElement();pNode;pNode=pNode->NextSiblingElement())  
    {  
         
        pSelectNode = selectChildNode(pNode,nodeName,nodeAttrName,nodeAttrValue);  
        if(pSelectNode)  
        {  
            break;  
        }  
    }  
     
    if(pSelectNode)  
    {  
        //cout << "解析成功" << endl;  
        //cout << pSelectNode->Value() << endl;  
        return pSelectNode;  
    }  
    else  
    {  
        // cout << "parse error,can't get node" << endl;  
        dzlog_error("parse error,can't get node.");  
        return NULL;  
    }  
     
}
Example #6
0
void CGUIIncludes::ResolveParametersForNode(TiXmlElement *node, const Params& params)
{
  if (!node)
    return;
  std::string newValue;
  // run through this element's attributes, resolving any parameters
  TiXmlAttribute *attribute = node->FirstAttribute();
  while (attribute)
  {
    ResolveParamsResult result = ResolveParameters(attribute->ValueStr(), newValue, params);
    if (result == SINGLE_UNDEFINED_PARAM_RESOLVED && strcmp(node->Value(), "param") == 0 &&
        strcmp(attribute->Name(), "value") == 0 && node->Parent() && strcmp(node->Parent()->Value(), "include") == 0)
    {
      // special case: passing <param name="someName" value="$PARAM[undefinedParam]" /> to the nested include
      // this usually happens when trying to forward a missing parameter from the enclosing include to the nested include
      // problem: since 'undefinedParam' is not defined, it expands to <param name="someName" value="" /> and overrides any default value set with <param name="someName" default="someValue" /> in the nested include
      // to prevent this, we'll completely remove this parameter from the nested include call so that the default value can be correctly picked up later
      node->Parent()->RemoveChild(node);
      return;
    }
    else if (result != NO_PARAMS_FOUND)
      attribute->SetValue(newValue);
    attribute = attribute->Next();
  }
  // run through this element's value and children, resolving any parameters
  TiXmlNode *child = node->FirstChild();
  if (child)
  {
    if (child->Type() == TiXmlNode::TINYXML_TEXT)
    {
      ResolveParamsResult result = ResolveParameters(child->ValueStr(), newValue, params);
      if (result == SINGLE_UNDEFINED_PARAM_RESOLVED && strcmp(node->Value(), "param") == 0 &&
          node->Parent() && strcmp(node->Parent()->Value(), "include") == 0)
      {
        // special case: passing <param name="someName">$PARAM[undefinedParam]</param> to the nested include
        // we'll remove the offending param tag same as above
        node->Parent()->RemoveChild(node);
      }
      else if (result != NO_PARAMS_FOUND)
        child->SetValue(newValue);
    }
    else if (child->Type() == TiXmlNode::TINYXML_ELEMENT)
    {
      do
      {
        TiXmlElement *next = child->NextSiblingElement();   // save next as current child might be removed from the tree
        ResolveParametersForNode(static_cast<TiXmlElement *>(child), params);
        child = next;
      }
      while (child);
    }
  }
}
Example #7
0
bool CXmlOpeation::Parse_XML_define_File(char* pFileName, _Proc_Define_Info& obj_Proc_Define_Info)
{
	Close();
	m_pTiXmlDocument = new TiXmlDocument(pFileName);
	if(NULL == m_pTiXmlDocument)
	{
		return false;
	}

	if(false == m_pTiXmlDocument->LoadFile())
	{
		return false;
	}

	TiXmlNode* pMainNode     = NULL;

	//获得根元素
	m_pRootElement = m_pTiXmlDocument->RootElement();

	if(NULL == m_pRootElement)
	{
		return false;
	}

	//获得工程名称
	sprintf_safe(obj_Proc_Define_Info.m_szProcName, MAX_BUFF_50, "%s", (char* )m_pRootElement->Attribute("ProcName"));

	//循环获取预定义信息
	for(pMainNode = m_pRootElement->FirstChildElement();pMainNode;pMainNode = pMainNode->NextSiblingElement())
	{
		_Define_Info obj_Define_Info;

		//获得Lua文件信息
		int nMainType = pMainNode->Type();

		if(nMainType != TiXmlText::TINYXML_ELEMENT)
		{
			continue;
		}

		TiXmlElement* pMainElement = pMainNode->ToElement();
		sprintf_safe(obj_Define_Info.m_szSrcType, MAX_BUFF_50, "%s", pMainElement->Attribute("srcType"));
		sprintf_safe(obj_Define_Info.m_szTagType, MAX_BUFF_50, "%s", pMainElement->Attribute("tagType"));
		sprintf_safe(obj_Define_Info.m_szDesc, MAX_BUFF_100, "%s", pMainElement->Attribute("desc"));
		obj_Proc_Define_Info.obj_vec_Define_Info.push_back(obj_Define_Info);
	}

	delete m_pTiXmlDocument;
	m_pTiXmlDocument = NULL;

	return true;
}
Example #8
0
	int getElementSum(TiXmlNode *node, const char * name)
	{
		int ret = 0;
		if (node == NULL || name == NULL) return ret;
		TiXmlNode *keyNode = node->FirstChildElement(name);
		if (keyNode == NULL) return ret;
		while (keyNode != NULL)
		{
			++ret;
			keyNode = keyNode->NextSiblingElement(name);
		}
		return ret;
	}
Example #9
0
void CXmlSiblingElemIter::MoveNext()
{
	if (m_pCurNode)
	{
		TiXmlNode* pNode = m_pCurNode;
		while ((pNode = pNode->NextSiblingElement()))
		{
			if (pNode->Value() == m_strSiblingName)
			{
				break;
			}
		}
		m_pCurNode = pNode;
	}
}
Example #10
0
bool ParameterSet::ReadFromXML(TiXmlNode &root)
{
	TiXmlNode* paraNode = root.FirstChild("Parameter");
	while (paraNode!=NULL)
	{
		TiXmlElement *elem = paraNode->ToElement();
		if (elem!=NULL)
		{
			const char* att=elem->Attribute("Type");
			if (att!=NULL)
			{
				Parameter* newPara=NULL;
				if (strcmp(att,"Const")==0) newPara = new Parameter();
				else if (strcmp(att,"Linear")==0) newPara = new LinearParameter();
				if (newPara!=NULL)
				{
					if (newPara->ReadFromXML(*elem)==true) this->InsertParameter(newPara);
				}
			}
		}
        paraNode=paraNode->NextSiblingElement("Parameter");
	};
	return true;
}
Example #11
0
bool CStageXMLParse::_Parse(TiXmlDocument& TinyXML)
{
    TiXmlElement* tiRoot = TinyXML.RootElement();
    if (!tiRoot)
    {
        return false;
    }
    std::string sRootName = tiRoot->Value();
    if (sRootName != STAGE_ROOT_GAME)
    {
        return false;
    }

    TiXmlNode* tiFirst = tiRoot->FirstChild(STAGE_GAME);
    if (tiFirst == NULL)
    {
        return false;
    }

    for (TiXmlElement* tiStage = tiFirst->ToElement();
            tiStage != NULL;
            tiStage = tiStage->NextSiblingElement())
    {
        CStageXMLStage* pStage = new CStageXMLStage;
        if (tiStage->Attribute(ID_OBJECT) != NULL)
        {
            pStage->SetId(tiStage->Attribute(ID_OBJECT));
        }
        if (tiStage->Attribute(NAME_OBJECT) != NULL)
        {
            pStage->SetName(tiStage->Attribute(NAME_OBJECT));
        }
        if (tiStage->Attribute(STAGE_MAP_OBJECT) != NULL)
        {
            pStage->SetMap(tiStage->Attribute(STAGE_MAP_OBJECT));
        }
        if (tiStage->Attribute(STAGE_CHAT) != NULL)
        {
            pStage->SetChat(tiStage->Attribute(STAGE_CHAT));
        }
        if (tiStage->Attribute(STAGE_DIFFICULTY_OBJECT) != NULL)
        {
            pStage->SetDifficulty(::atol(tiStage->Attribute(STAGE_DIFFICULTY_OBJECT)));
        }

        if (tiStage->Attribute(TYPE_OBJECT) != NULL)
        {
            pStage->SetType(tiStage->Attribute(TYPE_OBJECT));
        }

        TiXmlNode* tiEnemyItem = tiFirst->FirstChild(ITEM_GAME);
        if (tiEnemyItem != NULL)
        {
            for (TiXmlElement* tiItem = tiEnemyItem->FirstChildElement();
                    tiItem != NULL;
                    tiItem = tiItem->NextSiblingElement())
            {
                CStageXMLItem* pItem = new CStageXMLItem(tiItem->Attribute(ITEM_WAY_OBJECT));
                if (tiItem->Attribute(ID_OBJECT) != NULL)
                {
                    pItem->SetId(tiItem->Attribute(ID_OBJECT));
                }
                if (tiItem->Attribute(TYPE_OBJECT) != NULL)
                {
                    pItem->SetType(tiItem->Attribute(TYPE_OBJECT));
                }
                if (tiItem->Attribute(ITEM_NUMBER_OBJECT) != NULL)
                {
                    pItem->SetNumber(atol(tiItem->Attribute(ITEM_NUMBER_OBJECT)));
                }
                int PosX = 0, PosY = 0;
                if (tiItem->Attribute(POSX_OBJECT) != NULL)
                {
                    PosX = atoi(tiItem->Attribute(POSX_OBJECT));
                }
                if (tiItem->Attribute(POSY_OBJECT) != NULL)
                {
                    PosY = atoi(tiItem->Attribute(POSY_OBJECT));
                }
                pItem->SetPoint(PosX, PosY);
                pStage->PushItem(pItem);
            }
        }

        TiXmlNode* tiEnemy = tiStage->FirstChild(ENEMY_GAME);
        if (tiEnemy == NULL)
        {
            return false;
        }
        for (TiXmlElement* tiElementEnemy = tiEnemy->ToElement();
                tiElementEnemy != NULL;
                tiElementEnemy = tiElementEnemy->NextSiblingElement())
        {
            CStageXMLEnemy* pEnemy = new CStageXMLEnemy;
            if (tiElementEnemy->Attribute(ID_OBJECT) != NULL)
            {
                pEnemy->SetId(tiElementEnemy->Attribute(ID_OBJECT));
            }
            if (tiElementEnemy->Attribute(NAME_OBJECT) != NULL)
            {
                pEnemy->SetName(tiElementEnemy->Attribute(NAME_OBJECT));
            }
            if (tiElementEnemy->Attribute(TYPE_OBJECT) != NULL)
            {
                pEnemy->SetType(tiElementEnemy->Attribute(TYPE_OBJECT));
            }

            int PosX = 0, PosY = 0;
            if (tiElementEnemy->Attribute(POSX_OBJECT) != NULL)
            {
                PosX = atoi(tiElementEnemy->Attribute(POSX_OBJECT));
            }
            else
            {
                PosX = 0;
            }
            if (tiElementEnemy->Attribute(POSY_OBJECT) != NULL)
            {
                PosY = atoi(tiElementEnemy->Attribute(POSY_OBJECT));
            }
            else
            {
                PosY = 0;
            }
            pEnemy->SetPoint(PosX, PosY);

            if (tiElementEnemy->Attribute(ENEMY_APPEAR_OBJECT) != NULL)
            {
                pEnemy->SetAppear(atol(tiElementEnemy->Attribute(ENEMY_APPEAR_OBJECT)));
            }
            if (tiElementEnemy->Attribute(ENEMY_BIND_OBJECT) != NULL)
            {
                pEnemy->SetBind(tiElementEnemy->Attribute(ENEMY_BIND_OBJECT));
            }

            TiXmlNode* tiEnemyItem = tiEnemy->FirstChild(ITEM_GAME);
            if (tiEnemyItem == NULL)
            {
                return false;
            }
            for (TiXmlElement* tiItem = tiEnemyItem->ToElement();
                    tiItem != NULL;
                    tiItem = tiEnemyItem->NextSiblingElement())
            {
                CStageXMLItem* pItem = new CStageXMLItem(tiItem->Attribute(ITEM_WAY_OBJECT));
                if (tiItem->Attribute(ID_OBJECT) != NULL)
                {
                    pItem->SetId(tiItem->Attribute(ID_OBJECT));
                }
                if (tiItem->Attribute(TYPE_OBJECT) != NULL)
                {
                    pItem->SetType(tiItem->Attribute(TYPE_OBJECT));
                }
                if (tiItem->Attribute(ITEM_NUMBER_OBJECT) != NULL)
                {
                    pItem->SetNumber(atol(tiItem->Attribute(ITEM_NUMBER_OBJECT)));
                }
                int PosX = 0, PosY = 0;
                if (tiItem->Attribute(POSX_OBJECT) != NULL)
                {
                    PosX = atoi(tiItem->Attribute(POSX_OBJECT));
                }
                if (tiItem->Attribute(POSY_OBJECT) != NULL)
                {
                    PosY = atoi(tiItem->Attribute(POSY_OBJECT));
                }
                pItem->SetPoint(PosX, PosY);
                pEnemy->PushItem(pItem);
            }
            pStage->PushEnemy(pEnemy);
        }
        m_mapStage[::atol(pStage->GetId().c_str())] = pStage;
    }
    return true;
}
Example #12
0
bool CXmlOpeation::Parse_XML_Test_Assemble(const char* pFileName, _Test_Assemble& obj_Test_Assemble)
{
        Close();
        m_pTiXmlDocument = new TiXmlDocument(pFileName);
        if(NULL == m_pTiXmlDocument)
        {
                return false;
        }

        if(false == m_pTiXmlDocument->LoadFile())
        {
                return false;
        }

        TiXmlNode* pMainNode     = NULL;
        TiXmlNode* pSecondNode   = NULL;
        TiXmlNode* pThreeNode    = NULL;
        TiXmlNode* pColumnNode   = NULL;

        //获得根元素
        m_pRootElement = m_pTiXmlDocument->RootElement();

        if(NULL == m_pRootElement)
        {
                return false;
        }

        //获得测试集信息
        sprintf_safe(obj_Test_Assemble.m_szTestAssembleName, MAX_BUFF_50, "%s", (char* )m_pRootElement->Attribute("Name"));
        sprintf_safe(obj_Test_Assemble.m_szDesc, MAX_BUFF_100, "%s", (char* )m_pRootElement->Attribute("desc"));
        sprintf_safe(obj_Test_Assemble.m_szIP, MAX_BUFF_50, "%s", (char* )m_pRootElement->Attribute("IP"));
        sprintf_safe(obj_Test_Assemble.m_szOrder, MAX_BUFF_50, "%s", (char* )m_pRootElement->Attribute("ORDER"));
        obj_Test_Assemble.m_nPort = atoi((char* )m_pRootElement->Attribute("Port"));

        //循环获取预定义信息
        for(pMainNode = m_pRootElement->FirstChildElement();pMainNode;pMainNode = pMainNode->NextSiblingElement())
        {
                _Command_Info obj_Command_Info;

                int nMainType = pMainNode->Type();

                if(nMainType != TiXmlText::TINYXML_ELEMENT)
                {
                        continue;
                }

                TiXmlElement* pMainElement = pMainNode->ToElement();
                sprintf_safe(obj_Command_Info.m_szCommandName, MAX_BUFF_50, "%s", (char* )pMainElement->Attribute("CommandName"));
                obj_Command_Info.m_nCount    = atoi((char* )pMainElement->Attribute("Count"));
                obj_Command_Info.m_nTimeCost = atoi((char* )pMainElement->Attribute("TimeCost"));
                if(pMainElement->Attribute("ThreadCount") != NULL)
                {
                        obj_Command_Info.m_nThreadCount = atoi((char* )pMainElement->Attribute("ThreadCount"));
                }

                for(pSecondNode = pMainElement->FirstChildElement();pSecondNode;pSecondNode = pSecondNode->NextSiblingElement())
                {
                        int nMainType = pMainNode->Type();

                        if(nMainType != TiXmlText::TINYXML_ELEMENT)
                        {
                                continue;
                        }

                        TiXmlElement* pSecondElement = pSecondNode->ToElement();
                        if(strcmp("Packet_Send", pSecondElement->Value()) == 0)
                        {
                                //获得所有元素信息
                                for(pThreeNode = pSecondElement->FirstChildElement();pThreeNode;pThreeNode = pThreeNode->NextSiblingElement())
                                {
                                        TiXmlElement* pThreeElement = pThreeNode->ToElement();
                                        _Data_Info obj_Data_Info;
                                        sprintf_safe(obj_Data_Info.m_szDataType, MAX_BUFF_50, "%s", (char* )pThreeElement->Value());
                                        sprintf_safe(obj_Data_Info.m_szDataName, MAX_BUFF_50, "%s", (char* )pThreeElement->Attribute("name"));
                                        if(NULL != pThreeElement->Attribute("length"))
                                        {
                                                obj_Data_Info.m_nLength =  atoi((char* )pThreeElement->Attribute("length"));
                                        }
                                        if(NULL != pThreeElement->Attribute("IsString"))
                                        {
                                                if(strcmp("1", pThreeElement->Attribute("IsString")) == 0)
                                                {
                                                        obj_Data_Info.m_blIsString = true;
                                                }
                                                else
                                                {
                                                        obj_Data_Info.m_blIsString = false;
                                                }
                                        }
                                        if(NULL != (char* )pThreeElement->GetText())
                                        {
                                                obj_Data_Info.m_strValue = (string)pThreeElement->GetText();
                                        }
                                        obj_Command_Info.m_obj_Packet_Send.m_obj_Data_Info_List.push_back(obj_Data_Info);
                                }
                        }
                        else if(strcmp("Packet_Recv", pSecondElement->Value()) == 0)
                        {
                                //获得所有元素信息
                                for(pThreeNode = pSecondElement->FirstChildElement();pThreeNode;pThreeNode = pThreeNode->NextSiblingElement())
                                {
                                        TiXmlElement* pThreeElement = pThreeNode->ToElement();
                                        _Data_Info obj_Data_Info;
                                        sprintf_safe(obj_Data_Info.m_szDataType, MAX_BUFF_50, "%s", (char* )pThreeElement->Value());
                                        sprintf_safe(obj_Data_Info.m_szDataName, MAX_BUFF_50, "%s", (char* )pThreeElement->Attribute("name"));
                                        if(NULL != pThreeElement->Attribute("length"))
                                        {
                                                obj_Data_Info.m_nLength =  atoi((char* )pThreeElement->Attribute("length"));
                                        }
                                        if(NULL != pThreeElement->Attribute("IsString"))
                                        {
                                                if(strcmp("1", pThreeElement->Attribute("IsString")) == 0)
                                                {
                                                        obj_Data_Info.m_blIsString = true;
                                                }
                                                else
                                                {
                                                        obj_Data_Info.m_blIsString = false;
                                                }
                                        }
                                        if(NULL != (char* )pThreeElement->GetText())
                                        {
                                                obj_Data_Info.m_strValue = (string)((char* )pThreeElement->GetText());
                                        }
                                        obj_Command_Info.m_obj_Packet_Recv.m_obj_Data_Info_List.push_back(obj_Data_Info);
                                }
                        }
                }

                obj_Test_Assemble.m_obj_Command_Info_List.push_back(obj_Command_Info);
        }

        delete m_pTiXmlDocument;
        m_pTiXmlDocument = NULL;
        return true;
}
Example #13
0
bool CAdvancedSettings::Load()
{
  // NOTE: This routine should NOT set the default of any of these parameters
  //       it should instead use the versions of GetString/Integer/Float that
  //       don't take defaults in.  Defaults are set in the constructor above
  CStdString advancedSettingsXML;
  advancedSettingsXML  = g_settings.GetUserDataItem("advancedsettings.xml");
  TiXmlDocument advancedXML;
  if (!CFile::Exists(advancedSettingsXML))
  { // tell the user it doesn't exist
    CLog::Log(LOGNOTICE, "No advancedsettings.xml to load (%s)", advancedSettingsXML.c_str());
    return false;
  }

  if (!advancedXML.LoadFile(advancedSettingsXML))
  {
    CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", advancedSettingsXML.c_str(), advancedXML.ErrorRow(), advancedXML.ErrorDesc());
    return false;
  }

  TiXmlElement *pRootElement = advancedXML.RootElement();
  if (!pRootElement || strcmpi(pRootElement->Value(),"advancedsettings") != 0)
  {
    CLog::Log(LOGERROR, "Error loading %s, no <advancedsettings> node", advancedSettingsXML.c_str());
    return false;
  }

  // succeeded - tell the user it worked
  CLog::Log(LOGNOTICE, "Loaded advancedsettings.xml from %s", advancedSettingsXML.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", advancedSettingsXML.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::GetFloat(pElement, "karaokesyncdelay", m_karaokeSyncDelay, -3.0f, 3.0f);
    // 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, 48000);

    TiXmlElement* pAudioExcludes = pElement->FirstChildElement("excludefromlisting");
    if (pAudioExcludes)
      GetCustomRegexps(pAudioExcludes, m_audioExcludeFromListingRegExps);

    pAudioExcludes = pElement->FirstChildElement("excludefromscan");
    if (pAudioExcludes)
      GetCustomRegexps(pAudioExcludes, m_audioExcludeFromScanRegExps);

    XMLUtils::GetBoolean(pElement, "applydrc", m_audioApplyDrc);
    XMLUtils::GetBoolean(pElement, "dvdplayerignoredtsinwav", m_dvdplayerIgnoreDTSinWAV);
  }

  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::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);
  }

  pElement = pRootElement->FirstChildElement("musiclibrary");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "hideallitems", m_bMusicLibraryHideAllItems);
    XMLUtils::GetInt(pElement, "recentlyaddeditems", m_iMusicLibraryRecentlyAddedItems, 1, INT_MAX);
    XMLUtils::GetBoolean(pElement, "prioritiseapetags", m_prioritiseAPEv2tags);
    XMLUtils::GetBoolean(pElement, "allitemsonbottom", m_bMusicLibraryAllItemsOnBottom);
    XMLUtils::GetBoolean(pElement, "albumssortbyartistthenyear", m_bMusicLibraryAlbumsSortByArtistThenYear);
    XMLUtils::GetString(pElement, "albumformat", m_strMusicLibraryAlbumFormat);
    XMLUtils::GetString(pElement, "albumformatright", m_strMusicLibraryAlbumFormatRight);
    XMLUtils::GetString(pElement, "itemseparator", m_musicItemSeparator);
  }

  pElement = pRootElement->FirstChildElement("videolibrary");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "hideallitems", m_bVideoLibraryHideAllItems);
    XMLUtils::GetBoolean(pElement, "allitemsonbottom", m_bVideoLibraryAllItemsOnBottom);
    XMLUtils::GetInt(pElement, "recentlyaddeditems", m_iVideoLibraryRecentlyAddedItems, 1, INT_MAX);
    XMLUtils::GetBoolean(pElement, "hiderecentlyaddeditems", m_bVideoLibraryHideRecentlyAddedItems);
    XMLUtils::GetBoolean(pElement, "hideemptyseries", m_bVideoLibraryHideEmptySeries);
    XMLUtils::GetBoolean(pElement, "cleanonupdate", m_bVideoLibraryCleanOnUpdate);
    XMLUtils::GetString(pElement, "itemseparator", m_videoItemSeparator);
    XMLUtils::GetBoolean(pElement, "exportautothumbs", m_bVideoLibraryExportAutoThumbs);
    XMLUtils::GetBoolean(pElement, "importwatchedstate", m_bVideoLibraryImportWatchedState);

    TiXmlElement* pMyMovies = pElement->FirstChildElement("mymovies");
    if (pMyMovies)
      XMLUtils::GetBoolean(pMyMovies, "categoriestogenres", m_bVideoLibraryMyMoviesCategoriesToGenres);
  }

  pElement = pRootElement->FirstChildElement("videoscanner");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "ignoreerrors", m_bVideoScannerIgnoreErrors);
  }

  pElement = pRootElement->FirstChildElement("slideshow");
  if (pElement)
  {
    XMLUtils::GetFloat(pElement, "panamount", m_slideshowPanAmount, 0.0f, 20.0f);
    XMLUtils::GetFloat(pElement, "zoomamount", m_slideshowZoomAmount, 0.0f, 20.0f);
    XMLUtils::GetFloat(pElement, "blackbarcompensation", m_slideshowBlackBarCompensation, 0.0f, 50.0f);
  }

  pElement = pRootElement->FirstChildElement("lcd");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "rows", m_lcdRows, 1, 4);
    XMLUtils::GetInt(pElement, "columns", m_lcdColumns, 1, 40);
    XMLUtils::GetInt(pElement, "address1", m_lcdAddress1, 0, 0x100);
    XMLUtils::GetInt(pElement, "address2", m_lcdAddress2, 0, 0x100);
    XMLUtils::GetInt(pElement, "address3", m_lcdAddress3, 0, 0x100);
    XMLUtils::GetInt(pElement, "address4", m_lcdAddress4, 0, 0x100);
  }

  pElement = pRootElement->FirstChildElement("network");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "autodetectpingtime", m_autoDetectPingTime, 1, 240);
    XMLUtils::GetInt(pElement, "curlclienttimeout", m_curlconnecttimeout, 1, 1000);
    XMLUtils::GetInt(pElement, "curllowspeedtime", m_curllowspeedtime, 1, 1000);
    XMLUtils::GetInt(pElement, "curlretries", m_curlretries, 0, 10);
    XMLUtils::GetUInt(pElement, "cachemembuffersize", m_cacheMemBufferSize);
  }

  pElement = pRootElement->FirstChildElement("samba");
  if (pElement)
  {
    XMLUtils::GetString(pElement,  "doscodepage",   m_sambadoscodepage);
    XMLUtils::GetInt(pElement, "clienttimeout", m_sambaclienttimeout, 5, 100);
    XMLUtils::GetBoolean(pElement, "statfiles", m_sambastatfiles);
  }

  pElement = pRootElement->FirstChildElement("httpdirectory");
  if (pElement)
    XMLUtils::GetBoolean(pElement, "statfilesize", m_bHTTPDirectoryStatFilesize);

  pElement = pRootElement->FirstChildElement("ftp");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "remotethumbs", m_bFTPThumbs);
  }

  pElement = pRootElement->FirstChildElement("loglevel");
  if (pElement)
  { // read the loglevel setting, so set the setting advanced to hide it in GUI
    // as altering it will do nothing - we don't write to advancedsettings.xml
    XMLUtils::GetInt(pRootElement, "loglevel", m_logLevelHint, LOG_LEVEL_NONE, LOG_LEVEL_MAX);
    CSettingBool *setting = (CSettingBool *)g_guiSettings.GetSetting("debug.showloginfo");
    if (setting)
    {
      const char* hide;
      if (!((hide = pElement->Attribute("hide")) && strnicmp("false", hide, 4) == 0))
        setting->SetAdvanced();
    }
    g_advancedSettings.m_logLevel = std::max(g_advancedSettings.m_logLevel, g_advancedSettings.m_logLevelHint);
    CLog::SetLogLevel(g_advancedSettings.m_logLevel);
  }

  pElement = pRootElement->FirstChildElement("python");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "verbose", m_bPythonVerbose);
  }

  XMLUtils::GetString(pRootElement, "cddbaddress", m_cddbAddress);

  XMLUtils::GetBoolean(pRootElement, "usepcdvdrom", m_usePCDVDROM);
  XMLUtils::GetBoolean(pRootElement, "nodvdrom", m_noDVDROM);
  XMLUtils::GetBoolean(pRootElement, "enableintro", m_enableintro);
  XMLUtils::GetBoolean(pRootElement, "fasterscanning", m_fastscanning);
  XMLUtils::GetBoolean(pRootElement, "slowscrolling", m_slowscrolling);
  XMLUtils::GetBoolean(pRootElement, "splash", m_splashImage);
  XMLUtils::GetBoolean(pRootElement, "disablemodchipdetection", m_DisableModChipDetection);
  XMLUtils::GetBoolean(pRootElement, "powersave", m_bPowerSave);

  XMLUtils::GetInt(pRootElement, "songinfoduration", m_songInfoDuration, 0, INT_MAX);
  XMLUtils::GetInt(pRootElement, "busydialogdelay", m_busyDialogDelay, 0, 5000);
  XMLUtils::GetInt(pRootElement, "playlistretries", m_playlistRetries, -1, 5000);
  XMLUtils::GetInt(pRootElement, "playlisttimeout", m_playlistTimeout, 0, 5000);

  XMLUtils::GetBoolean(pRootElement,"virtualshares", m_bVirtualShares);
  XMLUtils::GetBoolean(pRootElement,"navigatevirtualkeyboard", m_bNavVKeyboard);

  //Tuxbox
  pElement = pRootElement->FirstChildElement("tuxbox");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "streamtsport", m_iTuxBoxStreamtsPort, 0, 65535);
    XMLUtils::GetBoolean(pElement, "audiochannelselection", m_bTuxBoxAudioChannelSelection);
    XMLUtils::GetBoolean(pElement, "submenuselection", m_bTuxBoxSubMenuSelection);
    XMLUtils::GetBoolean(pElement, "pictureicon", m_bTuxBoxPictureIcon);
    XMLUtils::GetBoolean(pElement, "sendallaudiopids", m_bTuxBoxSendAllAPids);
    XMLUtils::GetInt(pElement, "epgrequesttime", m_iTuxBoxEpgRequestTime, 0, 3600);
    XMLUtils::GetInt(pElement, "defaultsubmenu", m_iTuxBoxDefaultSubMenu, 1, 4);
    XMLUtils::GetInt(pElement, "defaultrootmenu", m_iTuxBoxDefaultRootMenu, 0, 4);
    XMLUtils::GetInt(pElement, "zapwaittime", m_iTuxBoxZapWaitTime, 0, 120);
    XMLUtils::GetBoolean(pElement, "zapstream", m_bTuxBoxZapstream);
    XMLUtils::GetInt(pElement, "zapstreamport", m_iTuxBoxZapstreamPort, 0, 65535);
  }

  // Myth TV
  pElement = pRootElement->FirstChildElement("myth");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "movielength", m_iMythMovieLength);
  }

  // EDL commercial break handling
  pElement = pRootElement->FirstChildElement("edl");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "mergeshortcommbreaks", m_bEdlMergeShortCommBreaks);
    XMLUtils::GetInt(pElement, "maxcommbreaklength", m_iEdlMaxCommBreakLength, 0, 10 * 60); // Between 0 and 10 minutes
    XMLUtils::GetInt(pElement, "mincommbreaklength", m_iEdlMinCommBreakLength, 0, 5 * 60);  // Between 0 and 5 minutes
    XMLUtils::GetInt(pElement, "maxcommbreakgap", m_iEdlMaxCommBreakGap, 0, 5 * 60);        // Between 0 and 5 minutes.
    XMLUtils::GetInt(pElement, "maxstartgap", m_iEdlMaxStartGap, 0, 10 * 60);               // Between 0 and 10 minutes
    XMLUtils::GetInt(pElement, "commbreakautowait", m_iEdlCommBreakAutowait, 0, 10);        // Between 0 and 10 seconds
    XMLUtils::GetInt(pElement, "commbreakautowind", m_iEdlCommBreakAutowind, 0, 10);        // Between 0 and 10 seconds
  }

  // picture exclude regexps
  TiXmlElement* pPictureExcludes = pRootElement->FirstChildElement("pictureexcludes");
  if (pPictureExcludes)
    GetCustomRegexps(pPictureExcludes, m_pictureExcludeFromListingRegExps);

  // picture extensions
  CStdString extraExtensions;
  TiXmlElement* pExts = pRootElement->FirstChildElement("pictureextensions");
  if (pExts)
    GetCustomExtensions(pExts,g_settings.m_pictureExtensions);

  // music extensions
  pExts = pRootElement->FirstChildElement("musicextensions");
  if (pExts)
    GetCustomExtensions(pExts,g_settings.m_musicExtensions);

  // video extensions
  pExts = pRootElement->FirstChildElement("videoextensions");
  if (pExts)
    GetCustomExtensions(pExts,g_settings.m_videoExtensions);

  m_vecTokens.clear();
  CLangInfo::LoadTokens(pRootElement->FirstChild("sorttokens"),m_vecTokens);

  XMLUtils::GetBoolean(pRootElement, "displayremotecodes", m_displayRemoteCodes);

  // TODO: Should cache path be given in terms of our predefined paths??
  //       Are we even going to have predefined paths??
  CSettings::GetPath(pRootElement, "cachepath", m_cachePath);
  URIUtils::AddSlashAtEnd(m_cachePath);

  XMLUtils::GetBoolean(pRootElement, "ftpshowcache", m_FTPShowCache);

  g_LangCodeExpander.LoadUserCodes(pRootElement->FirstChildElement("languagecodes"));

  // trailer matching regexps
  TiXmlElement* pTrailerMatching = pRootElement->FirstChildElement("trailermatching");
  if (pTrailerMatching)
    GetCustomRegexps(pTrailerMatching, m_trailerMatchRegExps);

  //everything thats a trailer is not a movie
  m_moviesExcludeFromScanRegExps.insert(m_moviesExcludeFromScanRegExps.end(),
                                        m_trailerMatchRegExps.begin(),
                                        m_trailerMatchRegExps.end());

  // stacking regexps
  TiXmlElement* pVideoStacking = pRootElement->FirstChildElement("moviestacking");
  if (pVideoStacking)
    GetCustomRegexps(pVideoStacking, m_videoStackRegExps);

  //tv stacking regexps
  TiXmlElement* pTVStacking = pRootElement->FirstChildElement("tvshowmatching");
  if (pTVStacking)
    GetCustomTVRegexps(pTVStacking, m_tvshowStackRegExps);

  // path substitutions
  TiXmlElement* pPathSubstitution = pRootElement->FirstChildElement("pathsubstitution");
  if (pPathSubstitution)
  {
    m_pathSubstitutions.clear();
    CLog::Log(LOGDEBUG,"Configuring path substitutions");
    TiXmlNode* pSubstitute = pPathSubstitution->FirstChildElement("substitute");
    while (pSubstitute)
    {
      CStdString strFrom, strTo;
      TiXmlNode* pFrom = pSubstitute->FirstChild("from");
      if (pFrom)
        strFrom = pFrom->FirstChild()->Value();
      TiXmlNode* pTo = pSubstitute->FirstChild("to");
      if (pTo)
        strTo = pTo->FirstChild()->Value();

      if (!strFrom.IsEmpty() && !strTo.IsEmpty())
      {
        CLog::Log(LOGDEBUG,"  Registering substition pair:");
        CLog::Log(LOGDEBUG,"    From: [%s]", strFrom.c_str());
        CLog::Log(LOGDEBUG,"    To:   [%s]", strTo.c_str());
        // keep literal commas since we use comma as a seperator
        strFrom.Replace(",",",,");
        strTo.Replace(",",",,");
        m_pathSubstitutions.push_back(strFrom + " , " + strTo);
      }
      else
      {
        // error message about missing tag
        if (strFrom.IsEmpty())
          CLog::Log(LOGERROR,"  Missing <from> tag");
        else
          CLog::Log(LOGERROR,"  Missing <to> tag");
      }

      // get next one
      pSubstitute = pSubstitute->NextSiblingElement("substitute");
    }
  }

  XMLUtils::GetInt(pRootElement, "remoterepeat", m_remoteRepeat, 1, INT_MAX);
  XMLUtils::GetFloat(pRootElement, "controllerdeadzone", m_controllerDeadzone, 0.0f, 1.0f);
  XMLUtils::GetInt(pRootElement, "thumbsize", m_thumbSize, 0, 1024);
  XMLUtils::GetInt(pRootElement, "fanartheight", m_fanartHeight, 0, 1080);
  //dds support
  XMLUtils::GetBoolean(pRootElement, "useddsfanart", m_useddsfanart);


  XMLUtils::GetBoolean(pRootElement, "playlistasfolders", m_playlistAsFolders);
  XMLUtils::GetBoolean(pRootElement, "detectasudf", m_detectAsUdf);

  // music thumbs
  CStdString extraThumbs;
  TiXmlElement* pThumbs = pRootElement->FirstChildElement("musicthumbs");
  if (pThumbs)
  {
    // remove before add so that the defaults can be restored after user defined ones
    // (ie, the list can be:cover.jpg|cover.png|folder.jpg)
    CSettings::GetString(pThumbs, "remove", extraThumbs, "");
    if (extraThumbs != "")
    {
      CStdStringArray thumbs;
      StringUtils::SplitString(extraThumbs, "|", thumbs);
      for (unsigned int i = 0; i < thumbs.size(); ++i)
      {
        int iPos = m_musicThumbs.Find(thumbs[i]);
        if (iPos == -1)
          continue;
        m_musicThumbs.erase(iPos, thumbs[i].size() + 1);
      }
    }
    CSettings::GetString(pThumbs, "add", extraThumbs,"");
    if (extraThumbs != "")
    {
      if (!m_musicThumbs.IsEmpty())
        m_musicThumbs += "|";
      m_musicThumbs += extraThumbs;
    }
  }

  // dvd thumbs
  pThumbs = pRootElement->FirstChildElement("dvdthumbs");
  if (pThumbs)
  {
    // remove before add so that the defaults can be restored after user defined ones
    // (ie, the list can be:cover.jpg|cover.png|folder.jpg)
    CSettings::GetString(pThumbs, "remove", extraThumbs, "");
    if (extraThumbs != "")
    {
      CStdStringArray thumbs;
      StringUtils::SplitString(extraThumbs, "|", thumbs);
      for (unsigned int i = 0; i < thumbs.size(); ++i)
      {
        int iPos = m_dvdThumbs.Find(thumbs[i]);
        if (iPos == -1)
          continue;
        m_dvdThumbs.erase(iPos, thumbs[i].size() + 1);
      }
    }
    CSettings::GetString(pThumbs, "add", extraThumbs,"");
    if (extraThumbs != "")
    {
      if (!m_dvdThumbs.IsEmpty())
        m_dvdThumbs += "|";
      m_dvdThumbs += extraThumbs;
    }
  }

  // movie fanarts
  TiXmlElement* pFanart = pRootElement->FirstChildElement("fanart");
  if (pFanart)
    GetCustomExtensions(pFanart,m_fanartImages);

  // music filename->tag filters
  TiXmlElement* filters = pRootElement->FirstChildElement("musicfilenamefilters");
  if (filters)
  {
    TiXmlNode* filter = filters->FirstChild("filter");
    while (filter)
    {
      if (filter->FirstChild())
        m_musicTagsFromFileFilters.push_back(filter->FirstChild()->ValueStr());
      filter = filter->NextSibling("filter");
    }
  }

  TiXmlElement* pHostEntries = pRootElement->FirstChildElement("hosts");
  if (pHostEntries)
  {
    TiXmlElement* element = pHostEntries->FirstChildElement("entry");
    while(element)
    {
      CStdString name  = element->Attribute("name");
      CStdString value;
      if(element->GetText())
        value = element->GetText();

      if(name.length() > 0 && value.length() > 0)
        CDNSNameCache::Add(name, value);
      element = element->NextSiblingElement("entry");
    }
  }

  XMLUtils::GetInt(pRootElement, "bginfoloadermaxthreads", m_bgInfoLoaderMaxThreads);
  m_bgInfoLoaderMaxThreads = std::max(3, m_bgInfoLoaderMaxThreads);

  // load in the GUISettings overrides:
  g_guiSettings.LoadXML(pRootElement, true);  // true to hide the settings we read in

  return true;
}
Example #14
0
bool CAdvancedSettings::Load()
{
  // NOTE: This routine should NOT set the default of any of these parameters
  //       it should instead use the versions of GetString/Integer/Float that
  //       don't take defaults in.  Defaults are set in the constructor above
  CStdString advancedSettingsXML;
  advancedSettingsXML  = g_settings.GetUserDataItem("advancedsettings.xml");
  TiXmlDocument advancedXML;
  if (!CFile::Exists(advancedSettingsXML))
  { // tell the user it doesn't exist
    CLog::Log(LOGNOTICE, "No advancedsettings.xml to load (%s)", advancedSettingsXML.c_str());
    return false;
  }

  if (!advancedXML.LoadFile(advancedSettingsXML))
  {
    CLog::Log(LOGERROR, "Error loading %s, Line %d\n%s", advancedSettingsXML.c_str(), advancedXML.ErrorRow(), advancedXML.ErrorDesc());
    return false;
  }

  TiXmlElement *pRootElement = advancedXML.RootElement();
  if (!pRootElement || strcmpi(pRootElement->Value(),"advancedsettings") != 0)
  {
    CLog::Log(LOGERROR, "Error loading %s, no <advancedsettings> node", advancedSettingsXML.c_str());
    return false;
  }

  // succeeded - tell the user it worked
  CLog::Log(LOGNOTICE, "Loaded advancedsettings.xml from %s", advancedSettingsXML.c_str());

  // Dump contents of AS.xml to debug log
  TiXmlPrinter printer;
  printer.SetLineBreak("\n");
  printer.SetIndent("  ");
  advancedXML.Accept(&printer);
  CLog::Log(LOGDEBUG, "Contents of %s are...\n%s", advancedSettingsXML.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);
    XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_audioPlayCountMinimumPercent, 0.0f, 100.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);  
    
    TiXmlElement* pDDPlusCert = pElement->FirstChildElement("ddpluscert");
    if( pDDPlusCert )
    {
      XMLUtils::GetBoolean(pDDPlusCert, "ltrtmode", m_ddplus.ltmode);  
      XMLUtils::GetBoolean(pDDPlusCert, "rfmode", m_ddplus.rfmode);
      XMLUtils::GetBoolean(pDDPlusCert, "lfemode", m_ddplus.lfemode);
      XMLUtils::GetBoolean(pDDPlusCert, "drc", m_ddplus.drc);
      CStdString mono;
      XMLUtils::GetString(pDDPlusCert, "monomode", mono);
      if( mono == "stereo" )     m_ddplus.monomode = __ddplus::_stereo;
      else if( mono == "left" )  m_ddplus.monomode = __ddplus::_left;
      else if( mono == "right" ) m_ddplus.monomode = __ddplus::_right;
      else if( mono == "mixed" ) m_ddplus.monomode = __ddplus::_mixed;
    }
  }

  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);
    XMLUtils::GetFloat(pElement, "playcountminimumpercent", m_videoPlayCountMinimumPercent, 0.0f, 100.0f);
    XMLUtils::GetInt(pElement, "ignoreatstart", m_videoIgnoreAtStart, 0, 900);
    XMLUtils::GetInt(pElement, "ignoreatend", m_videoIgnoreAtEnd, 0, 900);

    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,"postprocessing",m_videoPPFFmpegType);

	m_DXVACheckCompatibilityPresent = XMLUtils::GetBoolean(pElement,"checkdxvacompatibility", m_DXVACheckCompatibility);
  }

  pElement = pRootElement->FirstChildElement("musiclibrary");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "hideallitems", m_bMusicLibraryHideAllItems);
    XMLUtils::GetInt(pElement, "recentlyaddeditems", m_iMusicLibraryRecentlyAddedItems, 1, INT_MAX);
    XMLUtils::GetBoolean(pElement, "prioritiseapetags", m_prioritiseAPEv2tags);
    XMLUtils::GetBoolean(pElement, "allitemsonbottom", m_bMusicLibraryAllItemsOnBottom);
    XMLUtils::GetBoolean(pElement, "albumssortbyartistthenyear", m_bMusicLibraryAlbumsSortByArtistThenYear);
    XMLUtils::GetString(pElement, "albumformat", m_strMusicLibraryAlbumFormat);
    XMLUtils::GetString(pElement, "albumformatright", m_strMusicLibraryAlbumFormatRight);
    XMLUtils::GetString(pElement, "itemseparator", m_musicItemSeparator);
  }

  pElement = pRootElement->FirstChildElement("videolibrary");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "hideallitems", m_bVideoLibraryHideAllItems);
    XMLUtils::GetBoolean(pElement, "allitemsonbottom", m_bVideoLibraryAllItemsOnBottom);
    XMLUtils::GetInt(pElement, "recentlyaddeditems", m_iVideoLibraryRecentlyAddedItems, 1, INT_MAX);
    XMLUtils::GetBoolean(pElement, "hiderecentlyaddeditems", m_bVideoLibraryHideRecentlyAddedItems);
    XMLUtils::GetBoolean(pElement, "hideemptyseries", m_bVideoLibraryHideEmptySeries);
    XMLUtils::GetBoolean(pElement, "cleanonupdate", m_bVideoLibraryCleanOnUpdate);
    XMLUtils::GetString(pElement, "itemseparator", m_videoItemSeparator);
    XMLUtils::GetBoolean(pElement, "exportautothumbs", m_bVideoLibraryExportAutoThumbs);
    
    TiXmlElement* pMyMovies = pElement->FirstChildElement("mymovies");
    if (pMyMovies)
      XMLUtils::GetBoolean(pMyMovies, "categoriestogenres", m_bVideoLibraryMyMoviesCategoriesToGenres);
  }
  // Backward-compatibility of ExternalPlayer config
  pElement = pRootElement->FirstChildElement("externalplayer");
  if (pElement)
  {
    CLog::Log(LOGWARNING, "External player configuration has been removed from advancedsettings.xml.  It can now be configed in userdata/playercorefactory.xml");
  }
  pElement = pRootElement->FirstChildElement("slideshow");
  if (pElement)
  {
    XMLUtils::GetFloat(pElement, "panamount", m_slideshowPanAmount, 0.0f, 20.0f);
    XMLUtils::GetFloat(pElement, "zoomamount", m_slideshowZoomAmount, 0.0f, 20.0f);
    XMLUtils::GetFloat(pElement, "blackbarcompensation", m_slideshowBlackBarCompensation, 0.0f, 50.0f);
  }

  pElement = pRootElement->FirstChildElement("lcd");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "rows", m_lcdRows, 1, 4);
    XMLUtils::GetInt(pElement, "columns", m_lcdColumns, 1, 40);
    XMLUtils::GetInt(pElement, "address1", m_lcdAddress1, 0, 0x100);
    XMLUtils::GetInt(pElement, "address2", m_lcdAddress2, 0, 0x100);
    XMLUtils::GetInt(pElement, "address3", m_lcdAddress3, 0, 0x100);
    XMLUtils::GetInt(pElement, "address4", m_lcdAddress4, 0, 0x100);
    XMLUtils::GetBoolean(pElement, "heartbeat", m_lcdHeartbeat);
    XMLUtils::GetInt(pElement, "scrolldelay", m_lcdScrolldelay, -8, 8);
  }
  pElement = pRootElement->FirstChildElement("network");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "autodetectpingtime", m_autoDetectPingTime, 1, 240);
    XMLUtils::GetInt(pElement, "curlclienttimeout", m_curlconnecttimeout, 1, 1000);
    XMLUtils::GetInt(pElement, "curllowspeedtime", m_curllowspeedtime, 1, 1000);
    XMLUtils::GetInt(pElement, "curlretries", m_curlretries, 0, 10);
  }

  pElement = pRootElement->FirstChildElement("samba");
  if (pElement)
  {
    XMLUtils::GetString(pElement,  "doscodepage",   m_sambadoscodepage);
    XMLUtils::GetInt(pElement, "clienttimeout", m_sambaclienttimeout, 5, 100);
    XMLUtils::GetBoolean(pElement, "statfiles", m_sambastatfiles);
  }

  pElement = pRootElement->FirstChildElement("httpdirectory");
  if (pElement)
    XMLUtils::GetBoolean(pElement, "statfilesize", m_bHTTPDirectoryStatFilesize);

  XMLUtils::GetString(pRootElement, "cddbaddress", m_cddbAddress);
#ifdef HAS_HAL
  XMLUtils::GetBoolean(pRootElement, "usehalmount", m_useHalMount);
#endif
  XMLUtils::GetBoolean(pRootElement, "nodvdrom", m_noDVDROM);
  XMLUtils::GetBoolean(pRootElement, "usemultipaths", m_useMultipaths);
#ifdef HAS_SDL
  XMLUtils::GetBoolean(pRootElement, "fullscreen", m_startFullScreen);
#endif

  XMLUtils::GetInt(pRootElement, "songinfoduration", m_songInfoDuration, 0, INT_MAX);
  XMLUtils::GetInt(pRootElement, "busydialogdelay", m_busyDialogDelay, 0, 5000);
  XMLUtils::GetInt(pRootElement, "playlistretries", m_playlistRetries, -1, 5000);
  XMLUtils::GetInt(pRootElement, "playlisttimeout", m_playlistTimeout, 0, 5000);


  XMLUtils::GetBoolean(pRootElement,"rootovershoot",m_bUseEvilB);
  XMLUtils::GetBoolean(pRootElement,"glrectanglehack", m_GLRectangleHack);
  XMLUtils::GetInt(pRootElement,"skiploopfilter", m_iSkipLoopFilter, -16, 48);
  XMLUtils::GetFloat(pRootElement, "forcedswaptime", m_ForcedSwapTime, 0.0, 100.0);
  XMLUtils::GetBoolean(pRootElement,"osx_gl_fullscreen", m_osx_GLFullScreen);

  XMLUtils::GetFloat(pRootElement,"sleepbeforeflip", m_sleepBeforeFlip, 0.0f, 1.0f);
  XMLUtils::GetBoolean(pRootElement,"virtualshares", m_bVirtualShares);

  //Tuxbox
  pElement = pRootElement->FirstChildElement("tuxbox");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "audiochannelselection", m_bTuxBoxAudioChannelSelection);
    XMLUtils::GetBoolean(pElement, "submenuselection", m_bTuxBoxSubMenuSelection);
    XMLUtils::GetBoolean(pElement, "pictureicon", m_bTuxBoxPictureIcon);
    XMLUtils::GetBoolean(pElement, "sendallaudiopids", m_bTuxBoxSendAllAPids);
    XMLUtils::GetInt(pElement, "epgrequesttime", m_iTuxBoxEpgRequestTime, 0, 3600);
    XMLUtils::GetInt(pElement, "defaultsubmenu", m_iTuxBoxDefaultSubMenu, 1, 4);
    XMLUtils::GetInt(pElement, "defaultrootmenu", m_iTuxBoxDefaultRootMenu, 0, 4);
    XMLUtils::GetInt(pElement, "zapwaittime", m_iTuxBoxZapWaitTime, 0, 120);
  }
  
  // Myth TV
  pElement = pRootElement->FirstChildElement("myth");
  if (pElement)
  {
    XMLUtils::GetInt(pElement, "movielength", m_iMythMovieLength);
  }

  // EDL commercial break handling
  pElement = pRootElement->FirstChildElement("edl");
  if (pElement)
  {
    XMLUtils::GetBoolean(pElement, "mergeshortcommbreaks", m_bEdlMergeShortCommBreaks);
    XMLUtils::GetInt(pElement, "maxcommbreaklength", m_iEdlMaxCommBreakLength, 0, 10 * 60); // Between 0 and 10 minutes 
    XMLUtils::GetInt(pElement, "mincommbreaklength", m_iEdlMinCommBreakLength, 0, 5 * 60);  // Between 0 and 5 minutes
    XMLUtils::GetInt(pElement, "maxcommbreakgap", m_iEdlMaxCommBreakGap, 0, 5 * 60);        // Between 0 and 5 minutes.
    XMLUtils::GetInt(pElement, "maxstartgap", m_iEdlMaxStartGap, 0, 10 * 60);               // Between 0 and 10 minutes
  }

  // picture exclude regexps
  TiXmlElement* pPictureExcludes = pRootElement->FirstChildElement("pictureexcludes");
  if (pPictureExcludes)
    GetCustomRegexps(pPictureExcludes, m_pictureExcludeFromListingRegExps);

  // picture extensions
  CStdString extraExtensions;
  TiXmlElement* pExts = pRootElement->FirstChildElement("pictureextensions");
  if (pExts)
    GetCustomExtensions(pExts,g_stSettings.m_pictureExtensions);

  // music extensions
  pExts = pRootElement->FirstChildElement("musicextensions");
  if (pExts)
    GetCustomExtensions(pExts,g_stSettings.m_musicExtensions);

  // video extensions
  pExts = pRootElement->FirstChildElement("videoextensions");
  if (pExts)
    GetCustomExtensions(pExts,g_stSettings.m_videoExtensions);

  m_vecTokens.clear();
  CLangInfo::LoadTokens(pRootElement->FirstChild("sorttokens"),m_vecTokens);

  XMLUtils::GetBoolean(pRootElement, "displayremotecodes", m_displayRemoteCodes);

  // TODO: Should cache path be given in terms of our predefined paths??
  //       Are we even going to have predefined paths??
  CSettings::GetPath(pRootElement, "cachepath", m_cachePath);
  CUtil::AddSlashAtEnd(m_cachePath);

  g_LangCodeExpander.LoadUserCodes(pRootElement->FirstChildElement("languagecodes"));

  // stacking regexps
  TiXmlElement* pVideoStacking = pRootElement->FirstChildElement("moviestacking");
  if (pVideoStacking)
    GetCustomRegexps(pVideoStacking, m_videoStackRegExps);

  //tv stacking regexps
  TiXmlElement* pTVStacking = pRootElement->FirstChildElement("tvshowmatching");
  if (pTVStacking)
    GetCustomTVRegexps(pTVStacking, m_tvshowStackRegExps);

  // path substitutions
  TiXmlElement* pPathSubstitution = pRootElement->FirstChildElement("pathsubstitution");
  if (pPathSubstitution)
  {
    m_pathSubstitutions.clear();
    CLog::Log(LOGDEBUG,"Configuring path substitutions");
    TiXmlNode* pSubstitute = pPathSubstitution->FirstChildElement("substitute");
    while (pSubstitute)
    {
      CStdString strFrom, strTo;
      TiXmlNode* pFrom = pSubstitute->FirstChild("from");
      if (pFrom)
        strFrom = pFrom->FirstChild()->Value();
      TiXmlNode* pTo = pSubstitute->FirstChild("to");
      if (pTo)
        strTo = pTo->FirstChild()->Value();

      if (!strFrom.IsEmpty() && !strTo.IsEmpty())
      {
        CLog::Log(LOGDEBUG,"  Registering substition pair:");
        CLog::Log(LOGDEBUG,"    From: [%s]", strFrom.c_str());
        CLog::Log(LOGDEBUG,"    To:   [%s]", strTo.c_str());
        // keep literal commas since we use comma as a seperator
        strFrom.Replace(",",",,");
        strTo.Replace(",",",,");
        m_pathSubstitutions.push_back(strFrom + " , " + strTo);
      }
      else
      {
        // error message about missing tag
        if (strFrom.IsEmpty())
          CLog::Log(LOGERROR,"  Missing <from> tag");
        else
          CLog::Log(LOGERROR,"  Missing <to> tag");
      }

      // get next one
      pSubstitute = pSubstitute->NextSiblingElement("substitute");
    }
  }

  XMLUtils::GetInt(pRootElement, "remotedelay", m_remoteDelay, 1, 20);
  XMLUtils::GetFloat(pRootElement, "controllerdeadzone", m_controllerDeadzone, 0.0f, 1.0f);
  XMLUtils::GetInt(pRootElement, "thumbsize", m_thumbSize, 64, 1024);
  XMLUtils::GetBoolean(pRootElement, "useddsfanart", m_useDDSFanart);

  XMLUtils::GetBoolean(pRootElement, "playlistasfolders", m_playlistAsFolders);
  XMLUtils::GetBoolean(pRootElement, "detectasudf", m_detectAsUdf);

  // music thumbs
  CStdString extraThumbs;
  TiXmlElement* pThumbs = pRootElement->FirstChildElement("musicthumbs");
  if (pThumbs)
    GetCustomExtensions(pThumbs,m_musicThumbs);

  // dvd thumbs
  pThumbs = pRootElement->FirstChildElement("dvdthumbs");
  if (pThumbs)
    GetCustomExtensions(pThumbs,m_dvdThumbs);

  // movie fanarts
  TiXmlElement* pFanart = pRootElement->FirstChildElement("fanart");
  if (pFanart)
    GetCustomExtensions(pFanart,m_fanartImages);

  // music filename->tag filters
  TiXmlElement* filters = pRootElement->FirstChildElement("musicfilenamefilters");
  if (filters)
  {
    TiXmlNode* filter = filters->FirstChild("filter");
    while (filter)
    {
      if (filter->FirstChild())
        m_musicTagsFromFileFilters.push_back(filter->FirstChild()->ValueStr());
      filter = filter->NextSibling("filter");
    }
  }

  TiXmlElement* pHostEntries = pRootElement->FirstChildElement("hosts");
  if (pHostEntries)
  {
    TiXmlElement* element = pHostEntries->FirstChildElement("entry");
    while(element)
    {
      CStdString name  = element->Attribute("name");
      CStdString value;
      if(element->GetText())
        value = element->GetText();

      if(name.length() > 0 && value.length() > 0)
        CDNSNameCache::Add(name, value);
      element = element->NextSiblingElement("entry");
    }
  }

  XMLUtils::GetString(pRootElement, "cputempcommand", m_cpuTempCmd);
  XMLUtils::GetString(pRootElement, "gputempcommand", m_gpuTempCmd);

  XMLUtils::GetBoolean(pRootElement, "alwaysontop", m_alwaysOnTop);

  XMLUtils::GetInt(pRootElement, "bginfoloadermaxthreads", m_bgInfoLoaderMaxThreads);
  m_bgInfoLoaderMaxThreads = std::max(1, m_bgInfoLoaderMaxThreads);

  XMLUtils::GetBoolean(pRootElement, "measurerefreshrate", m_measureRefreshrate);
  XMLUtils::GetBoolean(pRootElement,"wireframe",m_bWireFrameMode);
  XMLUtils::GetBoolean(pRootElement,"countpixels",m_bCountPixels);
  XMLUtils::GetInt(pRootElement, "logfilesize", m_logFileSize);

  XMLUtils::GetBoolean(pRootElement, "forcevideohardwaredecoding", m_bForceVideoHardwareDecoding);
  XMLUtils::GetBoolean(pRootElement, "forceaudiohardwarepassthrough", m_bForceAudioHardwarePassthrough);
  XMLUtils::GetBoolean(pRootElement, "forcewmv3flushing", m_bForceWMV3Flushing);

  XMLUtils::GetBoolean(pRootElement,"allowd3d9ex", m_AllowD3D9Ex);
  XMLUtils::GetBoolean(pRootElement,"forced3d9ex", m_ForceD3D9Ex);
  XMLUtils::GetBoolean(pRootElement,"allowdynamictextures", m_AllowDynamicTextures);
  XMLUtils::GetUInt(pRootElement,"restrictcapsmask", m_RestrictCapsMask);

  // Disk Quota settings
  pElement = pRootElement->FirstChildElement("quota");
  if (pElement)
  {

    uint32_t tmp_size = 0;
    if (XMLUtils::GetUInt(pElement, "httpcachemaxsize", tmp_size))
    {
      m_httpCacheMaxSize = tmp_size * 1024;
    }
    if (XMLUtils::GetUInt(pElement, "appsmaxsize", tmp_size))
    {
      m_appsMaxSize = tmp_size * 1024;
    }
    if (XMLUtils::GetUInt(pElement, "thumbsmaxsize", tmp_size))
    {
      m_thumbsMaxSize = tmp_size * 1024;
    }
  }

  // load in the GUISettings overrides:
  g_guiSettings.LoadXML(pRootElement, true);  // true to hide the settings we read in

  return true;
}
Example #15
0
bool CXmlOpeation::Parse_Class_File(const char* pFileName, vecClassInfo& objvecClassInfo)
{
	Close();
	m_pTiXmlDocument = new TiXmlDocument(pFileName);
	if(NULL == m_pTiXmlDocument)
	{
		return false;
	}

	if(false == m_pTiXmlDocument->LoadFile())
	{
		Close();
		return false;
	}

	TiXmlNode* pMainNode = NULL;
	//获得根元素
	m_pRootElement = m_pTiXmlDocument->RootElement();

	//循环打印出每一个变量
	if(NULL == m_pRootElement)
	{
		return false;
	}

	//获得根元素的子元素
	for(pMainNode = m_pRootElement->FirstChildElement();pMainNode;pMainNode=pMainNode->NextSiblingElement())
	{
		_Class_Info objClassInfo;

		int nMainType = pMainNode->Type();

		if(nMainType != TiXmlText::TINYXML_ELEMENT)
		{
			continue;
		}

		TiXmlElement* pMainElement = pMainNode->ToElement();

		//获得元素的名称
		sprintf_safe(objClassInfo.m_szXMLName, 60, pMainElement->Value());
		sprintf_safe(objClassInfo.m_szDesc, 100, "%s", pMainElement->Attribute("desc"));

		//printf("Root=%s.\n", m_pRootElement->Value());

		TiXmlNode* pNode = NULL;

		for(pNode = pMainElement->FirstChildElement();pNode;pNode=pNode->NextSiblingElement())
		{
			int nType = pNode->Type();
			if(nType == TiXmlText::TINYXML_ELEMENT)
			{
				//printf("Name=%s,Values=%s.\n", pNode->Value(), pNode->ToElement()->GetText());
				_Property objProperty;
				sprintf_safe(objProperty.m_szPropertyName, 50, "%s", pNode->Value());
				if(strcmp(pNode->ToElement()->GetText(), "char") == 0)
				{
					objProperty.m_emType = PROPERTY_CHAR;

					//同时获得字符串最大长度
					char* pLength = (char* )pNode->ToElement()->Attribute("length");
					if(NULL != pLength)
					{
						objProperty.m_nLength = (int)atoi(pLength);
					}

					//获得Stream的指定长度
					char* pStreamLength = (char* )pNode->ToElement()->Attribute("StreamLength");
					if(NULL != pStreamLength)
					{
						sprintf_safe(objProperty.m_szStreamLength, 10, "%s", pStreamLength);
					}
				}
				else if(strcmp(pNode->ToElement()->GetText(), "string") == 0)
				{
					objProperty.m_emType = PROPERTY_STRING;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "uint8") == 0)
				{
					objProperty.m_emType = PROPERTY_UINT8;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "uint16") == 0)
				{
					objProperty.m_emType = PROPERTY_UINT16;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "uint32") == 0)
				{
					objProperty.m_emType = PROPERTY_UINT32;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "uint64") == 0)
				{
					objProperty.m_emType = PROPERTY_UINT64;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "int8") == 0)
				{
					objProperty.m_emType = PROPERTY_INT8;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "int16") == 0)
				{
					objProperty.m_emType = PROPERTY_INT16;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "int32") == 0)
				{
					objProperty.m_emType = PROPERTY_INT32;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "float32") == 0)
				{
					objProperty.m_emType = PROPERTY_FLOAT32;
				}
				else if(strcmp(pNode->ToElement()->GetText(), "float64") == 0)
				{
					objProperty.m_emType = PROPERTY_FLOAT64;
				}
				else
				{
					//不是基本类型,是类
					objProperty.m_emType = PROPERTY_UNKNOW;
					sprintf_safe(objProperty.m_szClassName, 100, "%s", pNode->ToElement()->GetText());
				}

				//查看参数类别
				if(NULL != pNode->ToElement()->Attribute("class"))
				{
					if(strcmp(pNode->ToElement()->Attribute("class"), "vector") == 0)
					{
						objProperty.m_emClass = CLASS_VECTOR;
					}
					else if(strcmp(pNode->ToElement()->Attribute("class"), "map") == 0)
					{
						objProperty.m_emClass = CLASS_MAP;

						//如果是map 则查看keyName和keyType
						sprintf_safe(objProperty.m_szKeyName, 100, "%s", pNode->ToElement()->Attribute("keyName"));

						if(strcmp(pNode->ToElement()->Attribute("KeyClass"), "string") == 0)
						{
							objProperty.m_emKeyType = PROPERTY_STRING;
						}
						else if(strcmp(pNode->ToElement()->Attribute("KeyClass"), "uint16") == 0)
						{
							objProperty.m_emKeyType = PROPERTY_UINT16;
						}
						else if(strcmp(pNode->ToElement()->Attribute("KeyClass"), "uint32") == 0)
						{
							objProperty.m_emKeyType = PROPERTY_UINT32;
						}
					}
				}

				//得到参数描述信息
				sprintf_safe(objProperty.m_szDesc, 100, "%s", pNode->ToElement()->Attribute("desc"));
				objClassInfo.m_vecProperty.push_back(objProperty);
			}
		}

		objvecClassInfo.push_back(objClassInfo);
	}

	Close();
	return true;
}
Example #16
0
OsStatus ForwardRules::parseRouteMatchContainer(const Url& requestUri,
                                              const SipMessage& request,
                                              UtlString& routeToString,
                                              UtlString& mappingType,
                                              bool& authRequired,
                                              TiXmlNode* routesNode,
                                              TiXmlNode* previousRouteMatchNode)
{
   UtlString testHost;
   requestUri.getHostAddress(testHost);
   int testPort = requestUri.getHostPort();
   if(testPort == SIP_PORT)
   {
      testPort = PORT_NONE;
   }
   
   UtlBoolean routeMatchFound = false;
   OsStatus methodMatchFound = OS_FAILED;
   
  	TiXmlElement* routesElement = routesNode->ToElement();

   TiXmlNode* routeMatchNode = previousRouteMatchNode;
   // Iterate through routes container children looking for 
   // route tags
   while ( (routeMatchNode = routesElement->IterateChildren(routeMatchNode)) 
      && methodMatchFound != OS_SUCCESS)
   {
      // Skip non-elements
      if(routeMatchNode && routeMatchNode->Type() != TiXmlNode::ELEMENT)
      {
         continue;
      }

      // Skip non-route elements
      TiXmlElement* routeMatchElement = routeMatchNode->ToElement();
      UtlString tagValue =  routeMatchElement->Value();
      if(tagValue.compareTo(XML_TAG_ROUTEMATCH) != 0 )
      {
         continue;
      }

      mappingType.remove(0);
      routeToString.remove(0);
      const char* mappingTypePtr = 
          routeMatchElement->Attribute(XML_ATT_MAPPINGTYPE);

      //get the mapping Type attribute
      mappingType.append(mappingTypePtr ? mappingTypePtr : "");

      // Iterate through the route container's children looking
      // for routeFrom, routeIPv4subnet, or routeDnsWildcard elements
      TiXmlNode* routeFromPatternNode = NULL;
      for( routeFromPatternNode = routeMatchElement->FirstChildElement();
         routeFromPatternNode;
         routeFromPatternNode = routeFromPatternNode->NextSiblingElement() )
      {
         // Skip elements that aren't of the "domainMatches" family 
         enum {ret_from, ret_ip, ret_dns} routeElementType ;

         const char *name = routeFromPatternNode->Value() ;
         if (strcmp(name, XML_TAG_ROUTEFROM) == 0)
         {
            routeElementType = ret_from;
         }
         else if (strcmp(name, XML_TAG_ROUTEIPV4SUBNET) == 0)
         {
            routeElementType = ret_ip;
         }
         else if (strcmp(name, XML_TAG_ROUTEDNSWILDCARD) == 0)
         {
            routeElementType = ret_dns;
         }
         else
         {
            continue ;
         }


         //found "domainMatches" pattern tag
         TiXmlElement* routeFromPatternElement = routeFromPatternNode->ToElement();
         //get the text value from it
         TiXmlNode* routeFromPatternText = routeFromPatternElement->FirstChild();
         if(routeFromPatternText && routeFromPatternText->Type() == TiXmlNode::TEXT)
         {
            TiXmlText* Xmlpattern = routeFromPatternText->ToText();
            if (Xmlpattern)
            {
               UtlString pattern = Xmlpattern->Value();

               switch(routeElementType)
               {
                  case ret_from: // a routeFrom element matches host and port
                  {
                     Url xmlUrl(pattern.data());
                     UtlString xmlHost;
                     xmlUrl.getHostAddress(xmlHost);
                     int xmlPort = xmlUrl.getHostPort();

                     // See if the host and port of the routeFrom elelment
                     // match that of the URI
                     if( (xmlHost.compareTo(testHost, UtlString::ignoreCase) == 0) &&
                        ((xmlPort == SIP_PORT && testPort == PORT_NONE) ||
                         xmlPort == testPort) )
                     {
                        routeMatchFound = true;
                        Os::Logger::instance().log(FAC_SIP, PRI_DEBUG, "ForwardRules::parseRouteMatchContainer - routeFrom %s matches %s", testHost.data(), pattern.data());
                     }
                  }
                  break ;

                  case ret_ip: // a routeIPv4subnet matches if the subnet does
                  {
                     // "pattern" is a subnet in CIDR notation (x.y.z.q/size)
                     // "testHost is supposed to be an IPv4 dotted quad

                     routeMatchFound = mPatterns->
                                          IPv4subnet(testHost, pattern);
                  }
                  break ;

                  case ret_dns: // a routeDnsWildcard matches if the domain name does
                  {
                     // "pattern" is a wildcard DNS (*.pingtel.com)
                     // "testHost is a FQDN
                     routeMatchFound = mPatterns->
                                          DnsWildcard(testHost, pattern);
  
                  }
                  break ;
               }

               if (routeMatchFound)
               {
                  previousRouteMatchNode = routeMatchNode;
                  // Find a match to the request method and recurse
                  // to find child element field(s) matches  and
                  // get the routeTo value
                  methodMatchFound = parseMethodMatchContainer(request,
                     routeToString,
                     authRequired,
                     routeMatchNode);

                  if( methodMatchFound == OS_SUCCESS)
                     break;
               }
            }
         }
      }
   }
   return methodMatchFound;
}
Example #17
0
bool CXmlOpeation::Parse_Plug_In_Project(const char* pFileName, _Project_Info& objProjectInfo)
{
	Close();
	m_pTiXmlDocument = new TiXmlDocument(pFileName);
	if(NULL == m_pTiXmlDocument)
	{
		return false;
	}

	if(false == m_pTiXmlDocument->LoadFile())
	{
		Close();
		return false;
	}

	TiXmlNode* pMainNode = NULL;
	//获得根元素
	m_pRootElement = m_pTiXmlDocument->RootElement();

	//循环打印出每一个变量
	if(NULL == m_pRootElement)
	{
		return false;
	}

	//获得头元素
	char* pName = (char* )m_pRootElement->Attribute("Name");
	if(NULL != pName)
	{
		sprintf_safe(objProjectInfo.m_szProjectName, 100, "%s", pName);
	}

	char* pDesc = (char* )m_pRootElement->Attribute("desc");
	if(NULL != pDesc)
	{
		sprintf_safe(objProjectInfo.m_szProjectDesc, 200, "%s", pDesc);
	}

	char* pKeyID = (char* )m_pRootElement->Attribute("keyID");
	if(NULL != pKeyID)
	{
		sprintf_safe(objProjectInfo.m_szProjectKey, 100, "%s", pKeyID);
	}

	//获得其中的数据体
	TiXmlNode* pNode = NULL;
	for(pNode = m_pRootElement->FirstChildElement();pNode;pNode=pNode->NextSiblingElement())
	{
		TiXmlElement* pSecondElement = pNode->ToElement();
		if(strcmp(pSecondElement->Value(), "Define") == 0)
		{
			_Define_Info obj_Define_Info;
			char* pTemp = (char* )pSecondElement->Attribute("DefName");
			if(NULL != pTemp)
			{
				sprintf_safe(obj_Define_Info.m_szDefineName, 100, "%s", pTemp);
			}
			pTemp = (char* )pSecondElement->Attribute("type");
			if(NULL != pTemp)
			{
				sprintf_safe(obj_Define_Info.m_szType, 20, "%s", pTemp);
			}
			pTemp = (char* )pSecondElement->Attribute("DefValue");
			if(NULL != pTemp)
			{
				sprintf_safe(obj_Define_Info.m_szDefineValue, 100, "%s", pTemp);
			}
			objProjectInfo.m_objDefineInfoList.push_back(obj_Define_Info);
		}
		else if(strcmp(pSecondElement->Value(), "Command") == 0)
		{
			_Command_Info_Func obj_Command_Info;
			char* pTemp = (char* )pSecondElement->Attribute("CommandIn");
			if(NULL != pTemp)
			{
				sprintf_safe(obj_Command_Info.m_szCommandInID, 50, "%s", pTemp);
			}
			pTemp = (char* )pSecondElement->Attribute("CommandOut");
			if(NULL != pTemp)
			{
				sprintf_safe(obj_Command_Info.m_szCommandOutID, 50, "%s", pTemp);
			}
			pTemp = (char* )pSecondElement->Attribute("FuncName");
			if(NULL != pTemp)
			{
				sprintf_safe(obj_Command_Info.m_szCommandFuncName, 100, "%s", pTemp);
			}

			TiXmlNode* pObjectNode = NULL;
			for(pObjectNode = pSecondElement->FirstChildElement();pObjectNode;pObjectNode=pObjectNode->NextSiblingElement())
			{
				_Object_Info obj_Object_Info;
				TiXmlElement* pThreeElement = pObjectNode->ToElement();

				pTemp = (char* )pThreeElement->Attribute("class");
				if(NULL != pTemp)
				{
					sprintf_safe(obj_Object_Info.m_szClassName, 50, "%s", pTemp);
				}
				pTemp = (char* )pThreeElement->Attribute("PacketType");
				if(NULL != pTemp)
				{
					if(strcmp(pTemp, "HEAD") == 0)
					{
						obj_Object_Info.m_emPacketType = PACKET_TYPE_HEAD;
					}
					else if(strcmp(pTemp, "BODY") == 0)
					{
						obj_Object_Info.m_emPacketType = PACKET_TYPE_BODY;
					}
					else if(strcmp(pTemp, "RETURN") == 0)
					{
						obj_Object_Info.m_emPacketType = PACKET_TYPE_RETURN;
					}
				}

				obj_Command_Info.m_vecObjectInfo.push_back(obj_Object_Info);
			}

			objProjectInfo.m_objCommandList.push_back(obj_Command_Info);
		}
	}

	Close();
	return true;
}
Example #18
0
bool CStageXMLParse::_Parse(TiXmlDocument& TinyXML)
{
    TiXmlElement* tiRoot = TinyXML.RootElement();
    if (!tiRoot)
    {
        return false;
    }
    std::string sRootName = tiRoot->Value();
    if (sRootName != STAGE_ROOT_GAME)
    {
        return false;
    }

    TiXmlNode* tiFirst = tiRoot->FirstChild(STAGE_GAME);
    if (tiFirst == NULL)
    {
        return false;
    }

    for (TiXmlElement* tiStage = tiFirst->ToElement();
        tiStage != NULL;
        tiStage = tiStage->NextSiblingElement())
    {
        CStageXMLStage* pStage = new CStageXMLStage;
        if (!BaseParse(pStage, tiStage))
        {
            continue;
        }
        std::string strMap;
        std::string strChat;
        int nDifficulty = 0;
        Unit::GetXmlStrAttributeA(tiStage ,STAGE_MAP_OBJECT, strMap);
        Unit::GetXmlStrAttributeA(tiStage ,STAGE_CHAT, strChat);
        Unit::GetXmlIntAttribute(tiStage ,STAGE_DIFFICULTY_OBJECT, nDifficulty);
        pStage->SetMap(strMap);
        pStage->SetChat(strChat);
        pStage->SetDifficulty(nDifficulty);

        TiXmlNode* tiEnemyItem = tiFirst->FirstChild(ITEM_GAME);
        if (tiEnemyItem != NULL)
        {
            for (TiXmlElement* tiItem = tiEnemyItem->FirstChildElement();
                tiItem != NULL;
                tiItem = tiItem->NextSiblingElement())
            {
                CStageXMLItem* pItem = new CStageXMLItem(tiItem->Attribute(ITEM_WAY_OBJECT));
                if (!BaseParse(pItem, tiItem))
                {
                    continue;
                }
                if(!_ParseItem(tiItem, pItem))
                {
                    continue;
                }
                PosObject posobjitem;
                BasePos(&posobjitem, tiItem);
                pItem->SetPoint(posobjitem.PosX, posobjitem.PosY);
                pStage->PushItem(pItem);
            }
        }

        TiXmlNode* tiEnemy = tiStage->FirstChild(ENEMY_GAME);
        if (tiEnemy == NULL)
        {
            return false;
        }
        for (TiXmlElement* tiElementEnemy = tiEnemy->ToElement();
            tiElementEnemy != NULL;
            tiElementEnemy = tiElementEnemy->NextSiblingElement())
        {
            CStageXMLEnemy* pEnemy = new CStageXMLEnemy;
            if (!BaseParse(pEnemy, tiElementEnemy))
            {
                continue;
            }
            PosObject posobjenemy;
            BasePos(&posobjenemy, tiElementEnemy);
            pEnemy->SetPoint(posobjenemy.PosX, posobjenemy.PosY);

            _ParseEnemy(tiElementEnemy, pEnemy);

            TiXmlNode* tiEnemyItem = tiEnemy->FirstChild(ITEM_GAME);
            if (tiEnemyItem == NULL)
            {
                return false;
            }
            for (TiXmlElement* tiItem = tiEnemyItem->ToElement();
                tiItem != NULL;
                tiItem = tiEnemyItem->NextSiblingElement())
            {
                CStageXMLItem* pItem = new CStageXMLItem(tiItem->Attribute(ITEM_WAY_OBJECT));
                if (!BaseParse(pItem, tiItem))
                {
                    continue;
                }
                if(!_ParseItem(tiItem, pItem))
                {
                    continue;
                }
                PosObject posobjitem;
                BasePos(&posobjitem, tiItem);
                pItem->SetPoint(posobjitem.PosX, posobjitem.PosY);
                pEnemy->PushItem(pItem);
            }
            pStage->PushEnemy(pEnemy);
        }
        m_mapStage[::atol(pStage->GetId().c_str())] = pStage;
    }
    return true;
}
//DecodeXml
int CParseDevice::DecodeXml(const char *xml, int sock_fd)
{
	if (NULL == xml)
	{
		printf("ERROR:Empty xml message...\n");
		return -1;
	}
	TiXmlDocument *handle = new TiXmlDocument();
	TiXmlPrinter *printer = new TiXmlPrinter();
	handle->Parse(xml);
	TiXmlNode* EnvelopeNode = handle->FirstChild("Envelope");
	const char * EnvelopeType = EnvelopeNode->ToElement()->Attribute("type");
	if(EnvelopeType != NULL){
		if(!strcmp(EnvelopeType,"r_pregister")){
			cms_fd = sock_fd;
			return  0;
		}
		if (cms_fd == sock_fd){
			if(!strcmp(EnvelopeType,"getrtspuri")){
				EnvelopeNode->ToElement()->SetAttribute("type","r_getrtspuri");
				TiXmlNode* profileNode = EnvelopeNode->FirstChildElement("profile"); 
				int count = 0;
				while(profileNode){
					DeviceInfo devInfo;
					memset(&devInfo, 0, sizeof(devInfo));
					const char* szXmlValue = NULL;
					TiXmlNode* profile = profileNode->FirstChildElement("deviceip");
					if(profile != NULL){
						szXmlValue = profile->ToElement()->GetText();
						devInfo.m_nId = rtspcount++;
						int a[4];
						sscanf(szXmlValue, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
						char ipbuffer[32];
						sprintf(ipbuffer, "%xx%xx%xx%x%c",a[0],     a[1], a[2], a[3], (char)(count +103 ));
						strncpy(devInfo.m_szIdname, ipbuffer, strlen(ipbuffer));
					}
					profile = profileNode->FirstChildElement("token");
					if(profile != NULL){
						szXmlValue = profile->ToElement()->GetText();
					}
					profile = profileNode->FirstChildElement("sourceuri");
					if(profile != NULL){
						szXmlValue = profile->ToElement()->GetText();
						if(szXmlValue != NULL)
							strncpy(devInfo.m_szSourceUrl, szXmlValue, sizeof(devInfo.m_szSourceUrl));
					}

					//Add Device
					if(strcmp(devInfo.m_szSourceUrl,"") != 0){
						if (success != AddDevice(devInfo)){
							printf("ERROR:Add new ProxySession:%s Falied!",devInfo.m_szSourceUrl);
							TiXmlText *DestContent = new TiXmlText("None");
							TiXmlElement *DestElement = new TiXmlElement("desturi");
							DestElement->LinkEndChild(DestContent);
							profileNode->ToElement()->LinkEndChild(DestElement);
						}else{
							char desturl[500];
							memset(desturl,0,strlen(desturl));
							sprintf(desturl, "rtsp://%s:8554/%s", server_addr, devInfo.m_szIdname);
							printf("INFO:Add new ProxySession:%s\nProxy this Session from %s\n",devInfo.m_szSourceUrl,desturl);
							TiXmlText *DestContent = new TiXmlText(desturl);
							TiXmlElement *DestElement = new TiXmlElement("desturi");
							DestElement->LinkEndChild(DestContent);
							profileNode->ToElement()->LinkEndChild(DestElement);
						}
					}

					profileNode = profileNode->NextSiblingElement("profile");
					count++;
				}   
				handle->Accept( printer );  
				if (send ( sock_fd, printer->CStr() , strlen(const_cast<char *>(printer->CStr())), 0) == - 1) { 
                    				perror ( "ERROR:Send error\n" ); 
                    				return -1;
                			} 
                			delete handle;
                			delete printer;
				return 0; 
			}
		}
	}
	return -1;
 }
Example #20
0
void CAppManager::LimitAppsDirSize(uint32_t appsDirMAxSize)
{

  CStdString appsDir = _P("special://home/apps/");

  // if dir is small enough, break
  if (CUtil::GetDirSize(appsDir) < appsDirMAxSize)
  {
    return;
  }

  typedef std::multimap<int, CStdString> appsMmapT;
  appsMmapT appsMmap;
  std::set<int>  appsMSortedKeys;


  CStdString fileName = _P("special://profile/apps/apps.xml");
  CStdString strValue, appName;
  std::map<CStdString, TiXmlNode *> appIdToXmlNodeMap;
  TiXmlDocument xmlDoc;
  TiXmlElement *pRootElement = NULL;

  //load xml file
  if ( xmlDoc.LoadFile( fileName) )
  {
    pRootElement = xmlDoc.RootElement();
    if (pRootElement)
    {
      strValue = pRootElement->Value();
      if ( strValue != "apps")
      {
        CLog::Log(LOGERROR, "failed to load apps.xml file");
        return;
      }
    }
  }

  TiXmlNode *pAppNode = pRootElement->FirstChild("app");
  TiXmlNode *pIdNode = NULL, *pLastOpenedDateNode = NULL;

  CLog::Log(LOGDEBUG, "reading apps.xml file");
  // read the content of app.xml file
  while (pAppNode > 0)
  {
    pIdNode = pAppNode->FirstChild("id");
    appName = pIdNode->FirstChild()->Value();
    pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
    int lastOpenedTime = atoi(pLastOpenedDateNode->FirstChild()->Value());
    appsMmap.insert(std::make_pair(lastOpenedTime, appName));
    appsMSortedKeys.insert(lastOpenedTime);
    appIdToXmlNodeMap.insert(std::make_pair(appName, pAppNode));
    pAppNode = pAppNode->NextSiblingElement("app");
  }


  std::set<int>::iterator  sortKeyIt = appsMSortedKeys.begin();

  CLog::Log(LOGDEBUG, "check apps dir size and change it if needed");
  while ((CUtil::GetDirSize(appsDir) > appsDirMAxSize) && sortKeyIt != appsMSortedKeys.end())
  {
    appsMmapT::iterator appsIt = appsMmap.find(*sortKeyIt);

    while ((CUtil::GetDirSize(appsDir) > appsDirMAxSize) && appsIt != appsMmap.end() )
    {
    // get the least recently used app
      CStdString appName = (*appsIt).second;
    CLog::Log(LOGINFO, "delete application %s", appName.c_str());

    CAppManager::UninstallApp(appName);
      appsMmap.erase(appsIt);
      appsIt = appsMmap.find(*sortKeyIt);
  }

    sortKeyIt ++;
  }

  //file have been changed, save
  xmlDoc.SaveFile();
}
Example #21
0
void InformationStorage::loadAll(string file)
{
	//Clear out the object types first
	terrainTypes.clear();
	buildingTypes.clear();
	unitTypes.clear();
	
	TiXmlDocument doc( file.c_str());
	if(doc.LoadFile())
	{
		TiXmlHandle hDoc(&doc);
		TiXmlElement* pElem;
		TiXmlHandle hRoot(0);
		pElem = hDoc.FirstChildElement().Element();
		hRoot=TiXmlHandle(pElem);


		//--------------------------------Load in Units----------------------

		TiXmlNode* pUnitNode=hRoot.FirstChild( "Units" ).FirstChild().ToNode();
		TiXmlNode* pUnitInfoNode;
		//For loop will cycle through each unit within the Units tag
		for( pUnitNode; pUnitNode; pUnitNode=pUnitNode->NextSiblingElement())
		{
			//Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use 
			//query attributes for combat stats.
			UnitInfo u = UnitInfo();
			u.load(pUnitNode);
			unitTypes[u.id] = u;
		}



		//----------------------Load in Terrain-------------------------------

		TiXmlNode* pTerrainNode=hRoot.FirstChild( "Terrain" ).FirstChild().ToNode();
		TiXmlNode* pTerrainInfoNode;
		//For loop will cycle through each unit within the Units tag
		for( pTerrainNode; pTerrainNode; pTerrainNode=pTerrainNode->NextSiblingElement())
		{
			//Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use 
			//query attributes for combat stats.
			TerrainInfo t = TerrainInfo();
			t.load(pTerrainNode);
			terrainTypes[t.id] = t;
		}


		//---------------------------------Load in Buildings--------------------------------------

		TiXmlNode* pBuildingNode=hRoot.FirstChild( "Buildings" ).FirstChild().ToNode();
		//TiXmlNode* pBuildingInfoNode;
		//TiXmlNode* pProductionIDNode;
		//For loop will cycle through each unit within the Units tag
		for( pBuildingNode; pBuildingNode; pBuildingNode=pBuildingNode->NextSiblingElement())
		{
			//Need to iterate through the data of a unit; can make a pointer to the first child of pUnitNode for ID, get NextSiblingElement for other elements, use 
			//query attributes for combat stats.
			BuildingInfo b = BuildingInfo();
			b.load(pBuildingNode);
			buildingTypes[b.id] = b;
		}

		//-------------------------------Load in Commander Cards--------------------------------
		TiXmlNode* pCardNode = hRoot.FirstChild( "Cards" ).FirstChild().ToNode();
		for( pCardNode; pCardNode; pCardNode=pCardNode->NextSiblingElement())
		{
			CardInfo c = CardInfo();
			c.load(pCardNode);
			cardTypes[c.id] = c;
		}


	}
	else
	{
		//std::cout << "\nFailed to load the units\n";
	}

	DeveloperConsole::write("Buildings Loaded: ");
	DeveloperConsole::writeLine(buildingTypes.size());
	DeveloperConsole::write("Units Loaded: ");
	DeveloperConsole::writeLine(unitTypes.size());
	DeveloperConsole::write("Terrain Loaded: ");
	DeveloperConsole::writeLine(terrainTypes.size());
	

}
Example #22
0
bool CXmlOpeation::Parse_XML_File(char* pFileName, _Proc_Info& obj_Proc_Info)
{
	Close();
	m_pTiXmlDocument = new TiXmlDocument(pFileName);
	if(NULL == m_pTiXmlDocument)
	{
		return false;
	}

	if(false == m_pTiXmlDocument->LoadFile())
	{
		return false;
	}

	TiXmlNode* pMainNode = NULL;
	//获得根元素
	m_pRootElement = m_pTiXmlDocument->RootElement();
	sprintf_safe(obj_Proc_Info.m_szProcName, MAX_BUFF_50, "%s", m_pRootElement->ToElement()->Attribute("ProcName"));


	//循环打印出每一个变量
	if(NULL == m_pRootElement)
	{
		return false;
	}

	//获得根元素的子元素
	for(pMainNode = m_pRootElement->FirstChildElement();pMainNode;pMainNode=pMainNode->NextSiblingElement())
	{
		_Class_Info obj_Class_Info;

		int nMainType = pMainNode->Type();

		if(nMainType != TiXmlText::TINYXML_ELEMENT)
		{
			continue;
		}

		TiXmlElement* pMainElement = pMainNode->ToElement();

		//获得根元素的名称
		sprintf_safe(obj_Class_Info.m_szXMLName, MAX_BUFF_50, pMainElement->Value());
		sprintf_safe(obj_Class_Info.m_szDesc, MAX_BUFF_100, "%s", pMainElement->Attribute("desc"));
		char* pPoolCount = (char* )pMainElement->Attribute("PoolCount");
		if(NULL != pPoolCount)
		{
			obj_Class_Info.m_nPollCount =atoi(pPoolCount);
		}

		//printf("Root=%s.\n", m_pRootElement->Value());
		//遍历类内容
		TiXmlNode* pNode = NULL;

		for(pNode = pMainElement->FirstChildElement();pNode;pNode=pNode->NextSiblingElement())
		{
			int nType = pNode->Type();
			if(nType == TiXmlText::TINYXML_ELEMENT)
			{
				//printf("Name=%s,Values=%s.\n", pNode->Value(), pNode->ToElement()->GetText());
				_Property objProperty;
				sprintf_safe(objProperty.m_szPropertyName, MAX_BUFF_50, "%s", pNode->Value());
				sprintf_safe(objProperty.m_szProperyType, MAX_BUFF_50, "%s", pNode->ToElement()->GetText());

				//同时获得字符串最大长度
				char* pLength = (char* )pNode->ToElement()->Attribute("length");
				if(NULL != pLength)
				{
					objProperty.m_nLength = (int)atoi(pLength);
				}
				
				sprintf_safe(objProperty.m_szDesc, 100, "%s", pNode->ToElement()->Attribute("desc"));

				obj_Class_Info.m_vecProperty.push_back(objProperty);
			}
		}

		obj_Proc_Info.obj_vec_Class_Info.push_back(obj_Class_Info);
	}

	delete m_pTiXmlDocument;
	m_pTiXmlDocument = NULL;

	return true;
}
Example #23
0
/**
 * 构建这样的树结构
 *[A]------|
 * |	   |
 * |	  [A1]
 * |	   |
 * |	  [A2]----|
 * |	   |	[A21]----|
 * |       |      |      |
 * |	 NULL     NULL [A211]
 * |		         |
 * |		       [A212]
 * |			 |
 * |			NULL
 *[B]
 * */
tixmlCodeNode * tixmlCode::traceNode1(tixmlCodeNode *root,TiXmlNode *node)
{
    static std::string WHILE = "while";
    static std::string WHEN = "when";
    static std::string IF = "if";

    tixmlCodeNode * now = NULL;
    tixmlCodeNode * parent = root;
    tixmlCodeNode * pre = NULL;
    TiXmlNode *nowNode = node;
    while (!nowNode || nowNode->Type() != TiXmlNode::TINYXML_ELEMENT)
    {
        nowNode	= nowNode->NextSiblingElement();
    }
    if (!nowNode || nowNode->Type() != TiXmlNode::TINYXML_ELEMENT) return NULL;
    while (true)
    {
        if (!nowNode) // 当前节点为空
        {
            if (!parent) break;
            nowNode = parent->element->NextSiblingElement();
            parent = parent->parent;
            if (!parent) break;
            continue;
        }
        now = new tixmlCodeNode;
        if (!root)
        {
            root = now;
        }

        now->init(nowNode->ToElement());
//			printf("[script]处理节点 %s\n",now->nodeName.str());
        std::string& name = now->nodeName;
        if (name == WHILE || name == WHEN || name == IF)
        {
            void * code = getAction(now->getAttr("action"));
//				if (!code) printf("[script] 处理节点 %s 获取action 失败\n",now->getAttr("action"));
            now->setExtData(code);
        }
        else
        {
            void* code = getAction(now->nodeName.c_str());
//				if (!code) printf("[script] 处理节点 %s 获取action 失败\n",now->nodeName.str());
            now->setExtData(code);
        }
        if (pre && !pre->next)
        {
            pre->next = now;
//				printf("[script]---------------- 处理节点 %s 的下一个节点 %s-----------\n",pre->nodeName.str(),now->nodeName.str());
            pre = NULL;
        }
        now->parent = parent;
        if (now->parent)
        {
            if (parent->childs.size())
                pre = parent->childs.back();
            parent->childs.push_back(now);
        }
        TiXmlNode * child = nowNode->FirstChildElement();
        TiXmlNode *tchild = nowNode->FirstChild();
        if ((child == NULL || (tchild && tchild->Type() == TiXmlNode::TINYXML_TEXT)) && parent) // 如果当前无孩子 且有父亲节点
        {
            if (tchild)
            {
                // 获取节点的文档描述
                TiXmlText *pText = tchild->ToText();
                if (pText)
                {
                    //std::string str;
                    //str<<*nowNode;
                    //sys::sString value(str.c_str());
                    std::string value(pText->Value());
//						std::string vs = value.toXmlString();
                    now->setText(value);
                    //	printf("----获取文本内容 %s----\n",vs.str());
                }
            }
            if (pre && !pre->next)
            {
                pre->next = now;
                //	printf("[SCRIPT]--------------- 当前节点 %s 下一个节点%s -----------\n",pre->nodeName.str(),now->nodeName.str());
            }
            if (!now->element->NextSiblingElement())
            {
                pre = NULL;// TODO now;
                nowNode = parent->element->NextSiblingElement();
                parent = parent->parent;
                if (parent)
                {
                    //	printf("[script] 回溯到父节点:%s\n",parent->nodeName.str());
                }
                else break;
            }
            else
            {
                nowNode = now->element->NextSiblingElement();
            }
            if (parent)
            {
                // printf("[script] 当前节点%s无孩子节点 有父节点%s\n",now->nodeName.str(),parent->nodeName.str());
            }
            else
                break;

        }
        else if (child) // 当前有孩子
        {
            if (pre && !pre->next)
            {
                pre->next = now;
                //			printf("[SCRIPT]--------------- 当前节点 %s 下一个节点%s -----------\n",pre->nodeName.str(),now->nodeName.str());
            }
            nowNode = child; // 准备执行下一个节点
            //	printf("[script]当前节点有孩子节点 %s\n",now->nodeName.str());
            parent = now;
        }
        else // 当前无孩子 且 无 父亲节点 则退出
        {
            break;
        }
    }
    return root;
}
Example #24
0
HaloReadError Fluidity::ReadHalos(const string& filename, int& process, int& nprocs, map<int, int>& npnodes, map<int, vector<vector<int> > >& send, map<int, vector<vector<int> > >& recv){ 
  // Read the halo file
  TiXmlDocument doc(filename);
  if(!doc.LoadFile()){
    doc.ErrorDesc();
    return HALO_READ_FILE_NOT_FOUND;
  }
  
  const char* charBuffer;
  ostringstream buffer;
   
  // Extract the XML header
  TiXmlNode* header = doc.FirstChild();
  while(header != NULL and header->Type() != TiXmlNode::DECLARATION){
    header = header->NextSibling();
  }

  // Extract the root node
  TiXmlNode* rootNode = header->NextSiblingElement();
  if(rootNode == NULL){
    return HALO_READ_FILE_INVALID;
  }
  TiXmlElement* rootEle = rootNode->ToElement();
  
  // Extract process
  charBuffer = rootEle->Attribute("process");
  if(charBuffer == NULL){
    return HALO_READ_FILE_INVALID;
  }
  process = atoi(charBuffer);
  if(process < 0){
    return HALO_READ_FILE_INVALID;
  }
  
  // Extract nprocs
  charBuffer = rootEle->Attribute("nprocs");
  if(charBuffer == NULL){
    return HALO_READ_FILE_INVALID;
  }
  nprocs = atoi(charBuffer);
  if(process >= nprocs){
    return HALO_READ_FILE_INVALID;
  }
  
  // Extract halo data for each process for each level
  npnodes.clear();
  send.clear();
  recv.clear();
  // Find the next halo element
  for(TiXmlNode* haloNode = rootEle->FirstChildElement("halo");haloNode != NULL;haloNode = haloNode->NextSiblingElement("halo")){
    if(haloNode == NULL){
      break;
    }
    TiXmlElement* haloEle = haloNode->ToElement();
    
    // Extract the level
    charBuffer = haloEle->Attribute("level");
    if(charBuffer == NULL){
      // Backwards compatibility
      charBuffer = haloEle->Attribute("tag");
      if(charBuffer == NULL){
        return HALO_READ_FILE_INVALID;
      }
    }
    int level = atoi(charBuffer);
    send[level] = vector<vector<int> >(nprocs);
    recv[level] = vector<vector<int> >(nprocs);

    // Extract n_private_nodes
    charBuffer = haloEle->Attribute("n_private_nodes");
    if(charBuffer == NULL){
      return HALO_READ_FILE_INVALID;
    }
    npnodes[level] = atoi(charBuffer);
    if(npnodes[level] < 0){
      return HALO_READ_FILE_INVALID;
    }
    
    // Find the next halo_data element
    for(TiXmlNode* dataNode = haloEle->FirstChildElement("halo_data");dataNode != NULL;dataNode = dataNode->NextSiblingElement("halo_data")){
      if(dataNode == NULL){
        break;
      }
      TiXmlElement* dataEle = dataNode->ToElement();
    
      // Extract the process
      charBuffer = dataEle->Attribute("process");
      if(charBuffer == NULL){
        return HALO_READ_FILE_INVALID;
      }
      int proc = atoi(charBuffer);
      if(proc < 0 or proc >= nprocs){
        return HALO_READ_FILE_INVALID;
      }
      
      // Check that data for this level and process has not already been extracted
      if(send[level][proc].size() > 0 or recv[level][proc].size() > 0){
        return HALO_READ_FILE_INVALID;
      }
      
      // Permit empty send and receive data elements
      send[level][proc] = vector<int>();
      recv[level][proc] = vector<int>();
      
      // Extract the send data
      TiXmlNode* sendDataNode = dataEle->FirstChildElement("send");
      if(sendDataNode != NULL){
        TiXmlNode* sendDataTextNode = sendDataNode->FirstChild();
        while(sendDataTextNode != NULL and sendDataTextNode->Type() != TiXmlNode::TEXT){
          sendDataTextNode = sendDataTextNode->NextSibling();
        }
        if(sendDataTextNode != NULL){
          vector<string> tokens;
          Tokenize(sendDataTextNode->ValueStr(), tokens, " ");
          for(size_t i = 0;i < tokens.size();i++){
            send[level][proc].push_back(atoi(tokens[i].c_str()));
          }
        }
      }
      
      // Extract the receive data
      TiXmlNode* recvDataNode = dataEle->FirstChildElement("receive");
      if(recvDataNode != NULL){
      TiXmlNode* recvDataTextNode = recvDataNode->FirstChild();
        while(recvDataTextNode != NULL and recvDataTextNode->Type() != TiXmlNode::TEXT){
          recvDataTextNode = recvDataTextNode->NextSibling();
        }
        if(recvDataTextNode != NULL){
          vector<string> tokens;
          Tokenize(recvDataTextNode->ValueStr(), tokens, " ");
          for(size_t i = 0;i < tokens.size();i++){
            recv[level][proc].push_back(atoi(tokens[i].c_str()));
          }
        }
      }
    }
  }

  return HALO_READ_SUCCESS;
}
Example #25
0
void CAppManager::UpdateAppStat(const std::string& AppId)
{
  CStdString fileName = _P("special://profile/apps/apps.xml");
  CStdString strValue, currAppStr;
  CStdString tmp;
  CStdString appsPath = _P("special://home/apps/");
  CAppDescriptor::AppDescriptorsMap installedAppsDesc;

  GetInstalledAppsInternal(installedAppsDesc, appsPath, "", false);

  TiXmlDocument xmlDoc;
  TiXmlElement *pRootElement = NULL;
  TiXmlNode *pTempNode = NULL;
  bool fixDoc = true;

  CLog::Log(LOGINFO, "updating %s's information in apps.xml", AppId.c_str());

  if ( xmlDoc.LoadFile( fileName) )
  {
    pRootElement = xmlDoc.RootElement();
    if (pRootElement)
    {
      strValue = pRootElement->Value();
      if ( strValue == "apps")
      {
        fixDoc = false;
      }
    }
  }

  if (fixDoc)
  {
    if (pRootElement)
    {
      xmlDoc.RemoveChild(pRootElement);
    }
    else
    {
      pTempNode = xmlDoc.FirstChild();
      if (pTempNode > 0)
        xmlDoc.RemoveChild(pTempNode);
    }

    pRootElement = new TiXmlElement( "apps" );
    pRootElement->SetAttribute("version", "1.0");
    xmlDoc.LinkEndChild(pRootElement);
  }

  TiXmlNode *pAppNode = pRootElement->FirstChild("app");
  TiXmlNode *pOpenedCntNode = NULL, *pIdNode = NULL, *pLastOpenedDateNode = NULL;

  while (pAppNode > 0)
  {
    pIdNode = pAppNode->FirstChild("id");
    if (pIdNode && pIdNode->FirstChild())
    {
      currAppStr = pIdNode->FirstChild()->Value();
      if (currAppStr == AppId)
      {
        pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
        pOpenedCntNode = pAppNode->FirstChild("timesopened");
        if (pOpenedCntNode && pOpenedCntNode->FirstChild())
        {

          int openedCnt = atoi (pOpenedCntNode->FirstChild()->Value());
          openedCnt++;
          tmp = BOXEE::BXUtils::IntToString(openedCnt);

          pOpenedCntNode->FirstChild()->SetValue(tmp.c_str());
          //CLog::Log(LOGDEBUG,"    Found name: %s", strName.c_str());
        }
        else
        {
          if (pOpenedCntNode)
          {
            pAppNode->RemoveChild(pOpenedCntNode);
          }
          TiXmlElement * timesOpenedElement = new TiXmlElement( "timesopened" );
          TiXmlText * timesOpenedText = new TiXmlText( "1" );
          timesOpenedElement->LinkEndChild( timesOpenedText );
          pAppNode->LinkEndChild(timesOpenedElement);
        }
        if (pLastOpenedDateNode)
        {
          pAppNode->RemoveChild(pLastOpenedDateNode);
        }

        tmp = BOXEE::BXUtils::IntToString(std::time(NULL));
        TiXmlElement * lastOpenedElement = new TiXmlElement( "lastopeneddate" );
        TiXmlText * lastOpenedText = new TiXmlText(tmp.c_str());
        lastOpenedElement->LinkEndChild( lastOpenedText );
        pAppNode->LinkEndChild(lastOpenedElement);
      }

      CLog::Log(LOGDEBUG, "deleting %s from apps map\n", currAppStr.c_str());
      installedAppsDesc.erase(currAppStr);
    }
    pAppNode = pAppNode->NextSiblingElement("app");

  }

  tmp = BOXEE::BXUtils::IntToString(std::time(NULL));

  CAppDescriptor::AppDescriptorsMap::iterator it = installedAppsDesc.begin();
  for (; it != installedAppsDesc.end(); it++)
  {
    TiXmlElement * appElement = new TiXmlElement( "app" );
    pRootElement->LinkEndChild(appElement);

    TiXmlElement * appIdElement = new TiXmlElement( "id" );
    TiXmlText * appIdText = new TiXmlText(it->first);
    appIdElement->LinkEndChild( appIdText );
    appElement->LinkEndChild(appIdElement);

    TiXmlElement * timesOpenedElement = new TiXmlElement( "timesopened" );
    TiXmlText * timesOpenedText = new TiXmlText( "1" );
    timesOpenedElement->LinkEndChild( timesOpenedText );
    appElement->LinkEndChild(timesOpenedElement);

    TiXmlElement * lastOpenedElement = new TiXmlElement( "lastopeneddate" );
    TiXmlText * lastOpenedText = new TiXmlText(tmp.c_str());
    lastOpenedElement->LinkEndChild( lastOpenedText );
    appElement->LinkEndChild(lastOpenedElement);

    CLog::Log(LOGINFO, "adding %s to app.xml file\n", it->first.c_str());

  }

  xmlDoc.SaveFile();

  m_mapAppNameToStat.clear();
  pRootElement = xmlDoc.RootElement();
  pAppNode = pRootElement->FirstChild("app");

  CLog::Log(LOGDEBUG, "reading apps.xml file");
  // read the content of app.xml file
  while (pAppNode > 0)
  {
    pIdNode = pAppNode->FirstChild("id");
    currAppStr = pIdNode->FirstChild()->Value();
    pLastOpenedDateNode = pAppNode->FirstChild("lastopeneddate");
    pOpenedCntNode = pAppNode->FirstChild("timesopened");
    int lastOpenedTime = 1;
    int timesOpened = 1;
    if (pOpenedCntNode && pLastOpenedDateNode->FirstChild())
    {
      lastOpenedTime = BOXEE::BXUtils::StringToInt(pLastOpenedDateNode->FirstChild()->Value());
    }
    if (pOpenedCntNode && pOpenedCntNode->FirstChild())
    {
      timesOpened = BOXEE::BXUtils::StringToInt(pOpenedCntNode->FirstChild()->Value());
    }
    std::map<CStdString, int> statsMap;
    statsMap["lastopeneddate"] = lastOpenedTime;
    statsMap["timesopened"] = timesOpened;
    m_mapAppNameToStat[currAppStr] = statsMap;
    pAppNode = pAppNode->NextSiblingElement("app");
  }
}
void CSettingsManager::write_SettingsXML()
{
  try
  {
    if(m_Settings.size() > 0)
    {
      TiXmlDocument doc;
      // ToDo: check all TiXml* generations!
      TiXmlDeclaration *declaration = new TiXmlDeclaration("1.0", "", "");
      doc.LinkEndChild(declaration);
      TiXmlComment *autoGenComment = new TiXmlComment();
      autoGenComment->SetValue(" THIS IS A AUTO GENERTATED FILE. DO NOT EDIT! ");
      doc.LinkEndChild(autoGenComment);

      for(SettingsMap::iterator mapIter = m_Settings.begin(); mapIter != m_Settings.end(); mapIter++)
      {
        vector<string> tokens;
        strTokenizer(mapIter->first, SETTINGS_SEPERATOR_STR, tokens);
        if(tokens.size() != 3)
        {
          doc.Clear();
          KODI->Log(LOG_ERROR, "Line: %i func: %s, Saving XML-File failed! Wrong SettingsMap string! Please call contact Addon author!\n", __LINE__, __func__, m_XMLFilename.c_str());
          return;
        }

        TiXmlElement *mainCategory = NULL;
        // check if this main category is already available
        for(TiXmlNode *element = doc.FirstChild(); element && !mainCategory; element = element->NextSiblingElement())
        {
          if(element->Value() == tokens[0])
          {
            mainCategory = static_cast<TiXmlElement*>(element);
          }
        }

        if(!mainCategory)
        { // create new main category
          mainCategory = new TiXmlElement(tokens[0]);
          doc.LinkEndChild(mainCategory);
        }

        TiXmlElement *settingsGroup = new TiXmlElement("settings_group");
        settingsGroup->SetAttribute("sub_category", tokens[1].c_str());
        settingsGroup->SetAttribute("group_name", tokens[2].c_str());
        mainCategory->LinkEndChild(settingsGroup);

        for(CSettingsList::iterator setIter=mapIter->second.begin(); setIter != mapIter->second.end(); setIter++)
        {
          if(!*setIter)
          {
            KODI->Log(LOG_ERROR, "Line: %i func: %s, invalid settings element! Please call contact Addon author!\n", __LINE__, __func__);
            return;
          }
          TiXmlElement *setting = new TiXmlElement("setting");
          setting->SetAttribute("key", (*setIter)->get_Key().c_str());

          switch((*setIter)->get_Type())
          {
            case ISettingsElement::STRING_SETTING:
              setting->SetAttribute("string", STRING_SETTINGS(*setIter)->get_Setting().c_str());
            break;

            case ISettingsElement::UNSIGNED_INT_SETTING:
              setting->SetAttribute("unsigned_int", toString(UNSIGNED_INT_SETTINGS(*setIter)->get_Setting()).c_str());
            break;

            case ISettingsElement::INT_SETTING:
              setting->SetAttribute("int", INT_SETTINGS(*setIter)->get_Setting());
            break;

            case ISettingsElement::FLOAT_SETTING:
              setting->SetDoubleAttribute("float", (double)FLOAT_SETTINGS(*setIter)->get_Setting());
            break;

            case ISettingsElement::DOUBLE_SETTING:
              setting->SetDoubleAttribute("double", DOUBLE_SETTINGS(*setIter)->get_Setting());
            break;

            case ISettingsElement::BOOL_SETTING:
              if(BOOL_SETTINGS(*setIter)->get_Setting())
              {
                setting->SetAttribute("bool", "true");
              }
              else
              {
                setting->SetAttribute("bool", "false");
              }
            break;

            default:
              KODI->Log(LOG_ERROR, "Line: %i func: %s, invalid settings type! Please call contact Addon author!\n", __LINE__, __func__);
              return;
            break;
          }

          settingsGroup->LinkEndChild(setting);
        }
      }

      if(!doc.SaveFile(m_XMLFilename.c_str()))
      {
        KODI->Log(LOG_ERROR, "Couldn't save XML settings to file %s", m_XMLFilename.c_str());
      }
    }
  }
  catch(bad_alloc &e)
  {
    KODI->Log(LOG_ERROR, "In function: %s a invalid memory allocation accured! Not enough free memory? Exception message: %s\n", __func__, e.what());
  }
}