Example #1
0
bool CThemeProvider::ThemeHasSize(const wxString& themePath, const wxString& size)
{
	wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml"));
	TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false);
	if (!pDocument)
		return false;

	TiXmlElement* pTheme = pDocument->FirstChildElement("Theme");

	if (!pTheme)
	{
		delete pDocument->GetDocument();
		return false;
	}

	for (TiXmlElement* pSize = pTheme->FirstChildElement("size"); pSize; pSize = pSize->NextSiblingElement("size"))
	{
		const char* txt = pSize->GetText();
		if (!txt)
			continue;

		if (size == ConvLocal(txt))
		{
			delete pDocument->GetDocument();
			return true;
		}
	}

	delete pDocument->GetDocument();

	return false;
}
std::string CInitializer::GetSettingFromFile(std::string file, const std::string& name)
{
	TiXmlDocument xmldoc;
	if (!xmldoc.LoadFile(file.c_str()))
		return "";

	TiXmlElement* main = xmldoc.FirstChildElement("FileZilla3");
	if (!main)
		return "";

	TiXmlElement* settings = main->FirstChildElement("Settings");
	if (!settings)
		return "";

	for (TiXmlElement* setting = settings->FirstChildElement("Setting"); setting; setting = setting->NextSiblingElement("Setting"))
	{
		const char* nodeVal = setting->Attribute("name");
		if (!nodeVal || strcmp(nodeVal, name.c_str()))
			continue;

		TiXmlNode* textNode = setting->FirstChild();
		if (!textNode || !textNode->ToText())
			continue;

		return mkstr(textNode->Value());
	}

	return "";
}
Example #3
0
void CharacterLoader::Load(TiXmlDocument& doc)
{
	TiXmlElement* root = doc.FirstChildElement("Body");
	root = root->FirstChildElement("Character");
	while (root)
	{
		TiXmlAttribute* attribute = root->FirstAttribute();
		std::string str = attribute->Name();
		if (str == "name")
		{
			std::string characterName = attribute->Value();
			std::string fileName;
			int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
			TiXmlElement* element = root->FirstChildElement("a");
			
			while (element)
			{
				TiXmlAttribute* attrib = element->FirstAttribute();
				while (attrib)
				{
					std::string name = attrib->Name();
					std::string value = attrib->Value();
					addValue(characterName, name, value);

					attrib = attrib->Next();
				}
				element = element->NextSiblingElement("a");
			}

		}

		root = root->NextSiblingElement("Character");
	}
}
Example #4
0
std::list<wxString> CThemeProvider::GetThemeSizes(const wxString& themePath)
{
	std::list<wxString> sizes;

	wxFileName fn(wxGetApp().GetResourceDir() + themePath, _T("theme.xml"));
	TiXmlElement* pDocument = GetXmlFile(fn.GetFullPath(), false);
	if (!pDocument)
		return sizes;

	TiXmlElement* pTheme = pDocument->FirstChildElement("Theme");
	if (pTheme)
	{
		for (TiXmlElement* pSize = pTheme->FirstChildElement("size"); pSize; pSize = pSize->NextSiblingElement("size"))
		{
			const char* txt = pSize->GetText();
			if (!txt)
				continue;

			wxString size = ConvLocal(txt);
			if (size == _T(""))
				continue;

			sizes.push_back(size);
		}
	}

	delete pDocument->GetDocument();

	return sizes;
}
void XMLConfigReader::getAdaptersFromXML(TiXmlElement* ruleEngineElm, RuleEngine *engine) {
	for (TiXmlElement* adapterElm = ruleEngineElm->FirstChildElement("adapter");
			adapterElm != NULL; adapterElm = adapterElm->NextSiblingElement("adapter")) {
		TiXmlElement* conditionElm = adapterElm->FirstChildElement("rule");
		if(conditionElm != NULL){
			std::string rule = std::string(conditionElm->GetText());
			int delimiterLoc = rule.find(":");
			Adapter *adapter = new Adapter(new Rule(rule.substr(0, delimiterLoc),
					rule.substr(delimiterLoc + 1, rule.length()).at(0)));
			for (TiXmlElement* actionElm = adapterElm->FirstChildElement("action");
					actionElm != NULL; actionElm = actionElm->NextSiblingElement("action")) {
				std::string actionTxt = std::string(actionElm->GetText());
				if(actionTxt == "ADD"){
					adapter->addAction(ADD);
				} else if(actionTxt == "DEL"){
					adapter->addAction(DEL);
				} else if(actionTxt == "MOD"){
					adapter->addAction(MOD);
				} else if(actionTxt == "SHF"){
					adapter->addAction(SHF);
				} else {
					std::cerr << "Action: " << actionTxt << " not defined!!" << std::endl;
				}
			}
			engine->addAdapter(adapter);
		}
	}
}
Example #6
0
//-----------------------------------------------------
bool ReadXmlFile_unattend(string& szFileName)
{   //读取Xml文件,并遍历
    try
    {
        string fullPath = "D:\\"+szFileName;

        //创建一个XML的文档对象。
        TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str());
        myDocument->LoadFile();
        //获得根元素,即Persons。
        TiXmlElement *RootElement = myDocument->RootElement();
        //输出根元素名称,即输出Persons。
        cout << RootElement->Value() << endl;
        //获得第一个Person节点。
        TiXmlElement *FirstSettings = RootElement->FirstChildElement();
        //获得第一个Person的name节点和age节点和ID属性。
        TiXmlElement *Component = FirstSettings->FirstChildElement();
        TiXmlElement *ComputerName = Component->FirstChildElement();
        //输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。
        cout << Component->FirstChild()->Value() << endl;
        cout << ComputerName->FirstChild()->Value() << endl;

        ComputerName->FirstChild()->SetValue("asdf");

        myDocument->SaveFile(fullPath.c_str());//保存到文件

        cout << ComputerName->FirstChild()->Value() << endl;
    }
    catch (string& e)
    {
        return false;
    }
    return true;
}
Example #7
0
// XML format is of strUrls is:
// <TAG><url>...</url>...</TAG> (parsed by ParseElement) or <url>...</url> (ditto)
bool CScraperUrl::ParseEpisodeGuide(CStdString strUrls)
{
  if (strUrls.IsEmpty())
    return false;

  // ok, now parse the xml file
  if (!XMLUtils::HasUTF8Declaration(strUrls))
    g_charsetConverter.unknownToUTF8(strUrls);

  TiXmlDocument doc;
  doc.Parse(strUrls.c_str(),0,TIXML_ENCODING_UTF8);
  if (doc.RootElement())
  {
    TiXmlHandle docHandle( &doc );
    TiXmlElement *link = docHandle.FirstChild("episodeguide").Element();
    if (link->FirstChildElement("url"))
    {
      for (link = link->FirstChildElement("url"); link; link = link->NextSiblingElement("url"))
        ParseElement(link);
    }
    else if (link->FirstChild() && link->FirstChild()->Value())
      ParseElement(link);
  }
  else
    return false;

  return true;
}
Example #8
0
bool ReadXmlFile(std::string& szFileName)
{//读取Xml文件,并遍历
	try
	{
		std::string fullPath = GetAppPath();
		fullPath += "\\";
		fullPath += szFileName;
		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument(fullPath.c_str());
		myDocument->LoadFile();
		//获得根元素,即Persons。
		TiXmlElement *RootElement = myDocument->RootElement();
		//输出根元素名称,即输出Persons。
		std::cout << RootElement->Value() << std::endl;
		//获得第一个Person节点。
		TiXmlElement *FirstPerson = RootElement->FirstChildElement();
		//获得第一个Person的name节点和age节点和ID属性。
		TiXmlElement *NameElement = FirstPerson->FirstChildElement();
		TiXmlElement *AgeElement = NameElement->NextSiblingElement();
		TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
		//输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。
		std::cout << NameElement->FirstChild()->Value() << std::endl;
		std::cout << AgeElement->FirstChild()->Value() << std::endl;
		std::cout << IDAttribute->Value()<< std::endl;
	}
	catch (std::string& e)
	{
		return false;
	}
	return true;
}
Example #9
0
// XML format is of strUrls is:
// <TAG><url>...</url>...</TAG> (parsed by ParseElement) or <url>...</url> (ditto)
bool CScraperUrl::ParseEpisodeGuide(CStdString strUrls)
{
  if (strUrls.empty())
    return false;

  // ok, now parse the xml file
  CXBMCTinyXML doc;
  /* strUrls is coming from internal sources so strUrls is always in UTF-8 */
  doc.Parse(strUrls, TIXML_ENCODING_UTF8);
  if (doc.RootElement())
  {
    TiXmlHandle docHandle( &doc );
    TiXmlElement *link = docHandle.FirstChild("episodeguide").Element();
    if (link->FirstChildElement("url"))
    {
      for (link = link->FirstChildElement("url"); link; link = link->NextSiblingElement("url"))
        ParseElement(link);
    }
    else if (link->FirstChild() && link->FirstChild()->Value())
      ParseElement(link);
  }
  else
    return false;

  return true;
}
Example #10
0
bool MProject::loadXML(const char * filename)
{
	char rep[256];

	if(! filename)
		return false;

	// get rep
	getRepertory(rep, filename);

	// read document
	TiXmlDocument doc(filename);
	if(! doc.LoadFile())
		return false;
	
	TiXmlHandle hDoc(&doc);
	TiXmlElement * rootNode;
	TiXmlHandle hRoot(0);

	// maratis
	rootNode = hDoc.FirstChildElement().Element();
	if(! rootNode)
		return false;

	if(strcmp(rootNode->Value(), "Maratis") != 0)
		return false;

	hRoot = TiXmlHandle(rootNode);

	// Project
	TiXmlElement * projectNode = rootNode->FirstChildElement("Project");
	if(! projectNode)
		return false;

	// renderer
	TiXmlElement * rendererNode = projectNode->FirstChildElement("renderer");
	if(rendererNode)
	{
		const char * name = rendererNode->Attribute("name");
		if(name)
		{
			renderer = name;
		}
	}
	
	// start
	TiXmlElement * startNode = projectNode->FirstChildElement("start");
	if(startNode)
	{
		const char * file = startNode->Attribute("file");
		if(file)
		{
			char levelFilename[256];
			getGlobalFilename(levelFilename, rep, file);
			startLevel = levelFilename;
		}
	}

	return true;
}
bool MasterFile::LoadXML( TiXmlHandle hLoadedFiles )
{
    files.clear();
    TiXmlElement* pLoadedFiles = hLoadedFiles.ToElement();
    if( pLoadedFiles == nullptr )
    {
        return false;
    }

    TiXmlElement* pGirlsFiles = pLoadedFiles->FirstChildElement("Girls_Files");
    if( pGirlsFiles == nullptr )
    {
        return false;
    }

    for( TiXmlElement* pFile = pGirlsFiles->FirstChildElement("File");
        pFile != nullptr;
        pFile = pFile->NextSiblingElement("File") )
    {
        if( pFile->Attribute("Filename") )
        {
            add( pFile->Attribute("Filename") );
        }
    }

    return true;
}
void HelloWorld::parseTinyXmlFile()
{
	try
	{
		char filePath[1024]= {'\0'};
		memset(filePath,0,sizeof(filePath));
		strcat(filePath,CCFileUtils::sharedFileUtils()->getWriteablePath().c_str());
		strcat(filePath,"CreatedTinyXml.xml");

		//创建一个XML的文档对象。
		TiXmlDocument *myDocument = new TiXmlDocument(filePath);
		myDocument->LoadFile();
		//获得根元素,即Persons。
		TiXmlElement *RootElement = myDocument->RootElement();
		//输出根元素名称,即输出Persons。
		CCLOG(RootElement->Value());
		//获得第一个Person节点。
		TiXmlElement *FirstPerson = RootElement->FirstChildElement();
		//获得第一个Person的name节点和age节点和ID属性。
		TiXmlElement *NameElement = FirstPerson->FirstChildElement();
		TiXmlElement *AgeElement = NameElement->NextSiblingElement();
		TiXmlAttribute *IDAttribute = FirstPerson->FirstAttribute();
		//输出第一个Person的name内容,即周星星;age内容,即;ID属性,即。

		CCLOG(NameElement->FirstChild()->Value());
		CCLOG(AgeElement->FirstChild()->Value());
		CCLOG(IDAttribute->Value());
	}
	catch (string& e)
	{
		return ;
	}
	return ;
}
Example #13
0
void ImageLoader::Load(TiXmlDocument& doc)
{
	TiXmlElement* root = doc.FirstChildElement("Body");
	root = root->FirstChildElement("Image");
	while (root)
	{
		TiXmlAttribute* attribute = root->FirstAttribute();
		std::string str = attribute->Name();
		if (str == "name")
		{
			std::string imageName = attribute->Value();
			std::string fileName;
			int x1 = -1, x2 = -1, y1 = -1, y2 = -1;
			TiXmlElement* element = root->FirstChildElement("a");
			if (element)
			{
				if (element->Attribute("file"))
				{
					fileName = element->Attribute("file");
				}
			}

			element = root->FirstChildElement("rect");

			while (element)
			{

				TiXmlAttribute* attrib = element->FirstAttribute();
				while (attrib)
				{
					std::string name = attrib->Name();
					if (name == "x1")
					{
						x1 = attrib->IntValue();
					}
					else if (name == "x2")
					{
						x2 = attrib->IntValue();
					}
					else if (name == "y1")
					{
						y1 = attrib->IntValue();
					}
					else if (name == "y2")
					{
						y2 = attrib->IntValue();
					}

					attrib = attrib->Next();
				}
				element = element->NextSiblingElement("rect");
			}

			internalCreate(imageName, fileName, x1, y1, x2, y2);
		}

		root = root->NextSiblingElement("Image");
	}
}
Example #14
0
bool CSiteManager::ClearBookmarks(wxString sitePath)
{
	if (sitePath[0] != '0')
		return false;

	sitePath = sitePath.Mid(1);

	// We have to synchronize access to sitemanager.xml so that multiple processed don't write
	// to the same file or one is reading while the other one writes.
	CInterProcessMutex mutex(MUTEX_SITEMANAGER);

	CXmlFile file;
	TiXmlElement* pDocument = file.Load(_T("sitemanager"));

	if (!pDocument)
	{
		wxString msg = file.GetError() + _T("\n") + _("The bookmarks could not be cleared.");
		wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);

		return false;
	}

	TiXmlElement* pElement = pDocument->FirstChildElement("Servers");
	if (!pElement)
		return false;

	std::list<wxString> segments;
	if (!UnescapeSitePath(sitePath, segments))
	{
		wxMessageBox(_("Site path is malformed."), _("Invalid site path"));
		return 0;
	}

	TiXmlElement* pChild = GetElementByPath(pElement, segments);
	if (!pChild || strcmp(pChild->Value(), "Server"))
	{
		wxMessageBox(_("Site does not exist."), _("Invalid site path"));
		return 0;
	}

	TiXmlElement *pBookmark = pChild->FirstChildElement("Bookmark");
	while (pBookmark)
	{
		pChild->RemoveChild(pBookmark);
		pBookmark = pChild->FirstChildElement("Bookmark");
	}

	wxString error;
	if (!file.Save(&error))
	{
		if (COptions::Get()->GetOptionVal(OPTION_DEFAULT_KIOSKMODE) == 2)
			return true;

		wxString msg = wxString::Format(_("Could not write \"%s\", the selected sites could not be exported: %s"), file.GetFileName().GetFullPath().c_str(), error.c_str());
		wxMessageBox(msg, _("Error writing xml file"), wxICON_ERROR);
	}

	return true;
}
Example #15
0
bool SSHTablesConfig::Parse(string xmlFile) {
	TiXmlDocument *doc = new TiXmlDocument(xmlFile.c_str());
    if (doc->LoadFile()) {
		TiXmlElement *root = doc->RootElement();
		TiXmlElement *pack = root->FirstChildElement();
		while (pack != NULL) {
			if (string(pack->Value()) == "package-path") {
				packagePath = pack->GetText();
			}

			if (string(pack->Value()) == "tables") {
				TiXmlElement *t = pack->FirstChildElement();
				while (t != NULL) {
					if (string(t->Value()) == "table") {
						Table table;
						TiXmlElement *tb = t->FirstChildElement();
						while (tb != NULL) {	
							if (string(tb->Value()) == "name") {
								table.name = tb->GetText();
							}
							if (string(tb->Value()) == "schema") {
								table.schema = tb->GetText();
							}
							if (string(tb->Value()) == "objectName") {
								table.objectName = tb->GetText();
							}

							if (string(tb->Value()) == "columns") {
								TiXmlElement *col = tb->FirstChildElement();
								while (col != NULL) {
									if (string(col->Value()) == "column") {
										Column column = {"undefined", "undefined"};
										column.name = col->GetText();
										TiXmlAttribute *attr = col->FirstAttribute();
										while (attr != NULL) {
											if (string(attr->Name()) == "type") {
												column.type = attr->Value();
											}
											attr = attr->Next();
										}
										table.columns.push_back(column);
									}
									col = col->NextSiblingElement();
								}
							}
							tb = tb->NextSiblingElement();
						}
						t = t->NextSiblingElement();
						tables.push_back(table);
					}
				}
			}
			pack = pack->NextSiblingElement();
		}
		return true;
	}  
	return false;
}
Example #16
0
int ServerConf::ReadMailList(TiXmlElement *root)
{
	TiXmlElement *servercfg = root->FirstChildElement("clientconn");	
	if(!servercfg){
		AC_ERROR("read clientconn error");
		return -1;	
	}
	const char* str;
	str = servercfg->Attribute("beatthreadsleep", &m_Beatthreadsleep);	
	if(!str){	
		AC_ERROR("read beatthreadsleep error");
		return -1;	
	}	
	AC_INFO("client beatthreadsleep = %d",m_Beatthreadsleep);
	TiXmlElement *mailsvrcfg = servercfg->FirstChildElement("mailserver");
	while(mailsvrcfg)
	{
		s_SrvList tmps;
		str=mailsvrcfg->Attribute("servername");
		if(!str){
			AC_ERROR("read servername error");
			return -1;
		}
		AC_INFO("read servername :%s",str);
		tmps.srvname = str;
		str=mailsvrcfg->Attribute("sender");
		if(!str){
			AC_ERROR("read sender error");
			return -1;
		}
		AC_INFO("read sender :%s",str);
		tmps.sender = str;
		str=mailsvrcfg->Attribute("password");
		if(!str){
			AC_ERROR("read password error");
			return -1;
		}
		AC_INFO("read password :%s",str);
		tmps.password = str;
		TiXmlElement *mailcfg = mailsvrcfg->FirstChildElement("mail");	
		while(mailcfg){
			str = mailcfg->Attribute("mailname");		
			if(!str){
				AC_ERROR("read mailname error");
				return -1;
			}
			AC_INFO("read mailname :%s",str);
			string strtmp = str;
			tmps.ListOfMail.push_back(strtmp);
			mailcfg = mailcfg->NextSiblingElement("mail");
		}
		m_ListOfMail.push_back(tmps);
		mailsvrcfg = mailsvrcfg->NextSiblingElement("mailserver");
	}
	return 0;
}
Example #17
0
bool PlayerMng::LoadPlayerInitConf()
{
	TiXmlDocument xmlDoc;
	if (!xmlDoc.LoadFile("./xml/InitPlayerData.xml"))
	{
		return false;
	}

	TiXmlElement* pRoot = xmlDoc.RootElement();
	if (!pRoot)
	{
		return false;
	}

	TiXmlElement* pInitPlayerData = pRoot->FirstChildElement("InitPlayerData");
	if (!pInitPlayerData)
	{
		return false;
	}
	TiXmlElement* pPlayerData = pInitPlayerData->FirstChildElement("PlayerData");
	if (!pInitPlayerData)
	{
		return false;
	}

	try
	{
		m_playerInitData.uLevel = boost::lexical_cast<uint32_t>(pPlayerData->Attribute("Level"));
		m_playerInitData.uExp = boost::lexical_cast<uint32_t>(pPlayerData->Attribute("Exp"));
		m_playerInitData.uAp = boost::lexical_cast<uint32_t>(pPlayerData->Attribute("Ap"));
		m_playerInitData.uGold = boost::lexical_cast<uint32_t>(pPlayerData->Attribute("Gold"));
		m_playerInitData.uDiamond = boost::lexical_cast<uint32_t>(pPlayerData->Attribute("Diamond"));
		m_playerInitData.uGateId = boost::lexical_cast<uint32_t>(pPlayerData->Attribute("GateId"));

		// 读取初始英雄列表
		TiXmlElement* pHeroList = pInitPlayerData->FirstChildElement("Hero");
		if (!pHeroList)
		{
			return false;
		}

		uint32_t uHeroId1 = boost::lexical_cast<uint32_t>(pHeroList->Attribute("Hero1"));
		uint32_t uHeroId2 = boost::lexical_cast<uint32_t>(pHeroList->Attribute("Hero2"));
		uint32_t uHeroId3 = boost::lexical_cast<uint32_t>(pHeroList->Attribute("Hero3"));
		m_playerInitData.heroList.push_back(uHeroId1);
		m_playerInitData.heroList.push_back(uHeroId2);
		m_playerInitData.heroList.push_back(uHeroId3);
	}
	catch (boost::bad_lexical_cast& err)
	{
		ERRORLOG("bad lexical cast, error=[" << err.what() << "]");
		return false;
	}
	
	return true;
}
Example #18
0
bool CRssReader::Parse(int iFeed)
{
    TiXmlElement* rootXmlNode = m_xml.RootElement();

    if (!rootXmlNode)
        return false;

    TiXmlElement* rssXmlNode = NULL;

    std::string strValue = rootXmlNode->ValueStr();
    if (strValue.find("rss") != std::string::npos ||
            strValue.find("rdf") != std::string::npos)
        rssXmlNode = rootXmlNode;
    else
    {
        // Unable to find root <rss> or <rdf> node
        return false;
    }

    TiXmlElement* channelXmlNode = rssXmlNode->FirstChildElement("channel");
    if (channelXmlNode)
    {
        TiXmlElement* titleNode = channelXmlNode->FirstChildElement("title");
        if (titleNode && !titleNode->NoChildren())
        {
            std::string strChannel = titleNode->FirstChild()->Value();
            std::wstring strChannelUnicode;
            g_charsetConverter.utf8ToW(strChannel, strChannelUnicode, m_rtlText);
            AddString(strChannelUnicode, RSS_COLOR_CHANNEL, iFeed);

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

        GetNewsItems(channelXmlNode,iFeed);
    }

    GetNewsItems(rssXmlNode,iFeed);

    // avoid trailing ' - '
    if (m_strFeed[iFeed].size() > 3 && m_strFeed[iFeed].substr(m_strFeed[iFeed].size() - 3) == L" - ")
    {
        if (m_rtlText)
        {
            m_strFeed[iFeed].erase(0, 3);
            m_strColors[iFeed].erase(0, 3);
        }
        else
        {
            m_strFeed[iFeed].erase(m_strFeed[iFeed].length() - 3);
            m_strColors[iFeed].erase(m_strColors[iFeed].length() - 3);
        }
    }
    return true;
}
Example #19
0
bool ServerConfig::LoadServerConf(const char* pFilePath)
{
	if (!m_xmlDoc.LoadFile(pFilePath))
	{
		return false;
	}

	TiXmlElement* pRoot = m_xmlDoc.RootElement();
	if (!pRoot)
	{
		return false;
	}

	TiXmlElement* pHostServer = pRoot->FirstChildElement("HostServer");
	if (!pHostServer)
	{
		cout << "cannot find host server" << endl;
		return false;
	}

	TiXmlElement* pServer = pHostServer->FirstChildElement("bind");
	if (!pServer)
	{
		return false;
	}
	const char* pServerIp = pServer->Attribute("ip");
	const char* pServerPort = pServer->Attribute("port");
	if (pServerIp)
	{
		memcpy(m_szBindIp, pServerIp, strlen(pServerIp));
	}
	if (pServerPort)
	{
		m_nListenPort = boost::lexical_cast<int>(pServerPort);
	}

	// listen client info
	TiXmlElement* pClient = pHostServer->FirstChildElement("client");
	if (!pClient)
	{
		return false;
	}
	const char* pClientListenIp = pClient->Attribute("ip");
	const char* pClientListenPort = pClient->Attribute("port");
	if (pClientListenIp)
	{
		memcpy(m_szBindClientIp, pClientListenIp, strlen(pClientListenIp));
	}
	if (pClientListenPort)
	{
		m_nListenClientPort = boost::lexical_cast<int>(pClientListenPort);
	}
	
	return true;
}
Example #20
0
void DataModel::loadStage()
{
    TiXmlDocument* myDocument = new TiXmlDocument();
    unsigned char* pBuffer = NULL;
    ssize_t bufferSize = 0;
    pBuffer = FileUtils::getInstance()->getFileData("stage.xml", "r", &bufferSize);
    if (pBuffer) {
        myDocument->Parse((const char*)pBuffer);
        TiXmlElement* stage = myDocument->RootElement();
        TiXmlElement* points = stage->FirstChildElement();
        TiXmlElement* point = points->FirstChildElement();
        while (points) {
            const char *name = points->Attribute("name");
            __Array *temp = __Array::create();
            
            while (point) {
                TiXmlAttribute *x = point->FirstAttribute();
                int pointX = x->IntValue();
                int pointY = x->Next()->IntValue();
                if (_winSize.height < 1100) {
                    pointY = pointY - 25;
                }
                temp->addObject(new MyPoint(pointX ,_winSize.height / 1280.0 * pointY));
                point = point->NextSiblingElement();
            }
            if (StringUtils::format("s9%d",flag9) == std::string(name)) {
                stage9.pushBack(temp);
                flag9++;
            }
            if (StringUtils::format("s5%d",flag5) == std::string(name)) {
                stage5.pushBack(temp);
                flag5++;
            }
            if (StringUtils::format("s6%d",flag6) == std::string(name)) {
                stage6.pushBack(temp);
                flag6++;
            }
            point = points->FirstChildElement();
            points = points->NextSiblingElement();
        }
        Ref *obj;
        MyPoint *p;
        for (auto a: stage5) {
            
            CCARRAY_FOREACH(a, obj)
            {
                p = (MyPoint *)obj;
            }
            
        }

    }
 
}
Example #21
0
bool CLastFMDirectory::ParseAlbumList(CStdString url, CFileItemList &items)
{
  if (!RetrieveList(url))
    return false;

  TiXmlElement* pRootElement = m_xmlDoc.RootElement();

  TiXmlElement* pEntry = pRootElement->FirstChildElement("album");

  while(pEntry)
  {
    const char *artist = pRootElement->Attribute("artist");
    const char *name = NULL;
    const char *count = NULL;

    if (pEntry->Attribute("name"))
      name = pEntry->Attribute("name");
    else
    {
      TiXmlNode* nameNode = pEntry->FirstChild("name");
      if (nameNode && nameNode->FirstChild())
        name = nameNode->FirstChild()->Value();
    }

    TiXmlElement* artistElement = pEntry->FirstChildElement("artist");
    if (artistElement && artistElement->Attribute("name"))
      artist = artistElement->Attribute("name");
    else
    {
      if (artistElement && artistElement->FirstChild())
        artist = artistElement->FirstChild()->Value();
    }

    if (pEntry->Attribute("count"))
      count = pEntry->Attribute("count");
    else
    {
      TiXmlNode* countNode = pEntry->FirstChild("count");
      if (!countNode) countNode = pEntry->FirstChild("playcount");
      if (!countNode) countNode = pEntry->FirstChild("reach");
      if (countNode)
        count = countNode->FirstChild()->Value();
    }

    AddListEntry(name, artist, count, NULL, NULL,
        "lastfm://xbmc/artist/" + (CStdString)artist + "/", items);

    pEntry = pEntry->NextSiblingElement("album");
  }

  m_xmlDoc.Clear();
  return true;
}
Example #22
0
bool CRemoteDataObject::SetData(size_t len, const void* buf)
{
	char* data = (char*)buf;
	if (data[len - 1] != 0)
		return false;

	if (!m_xmlFile.ParseData(data))
		return false;

	TiXmlElement* pElement = m_xmlFile.GetElement();
	if (!pElement || !(pElement = pElement->FirstChildElement("RemoteDataObject")))
		return false;

	m_processId = GetTextElementInt(pElement, "ProcessId", -1);
	if (m_processId == -1)
		return false;

	TiXmlElement* pServer = pElement->FirstChildElement("Server");
	if (!pServer || !::GetServer(pServer, m_server))
		return false;

	wxString path = GetTextElement(pElement, "Path");
	if (path == _T("") || !m_path.SetSafePath(path))
		return false;

	m_fileList.clear();
	TiXmlElement* pFiles = pElement->FirstChildElement("Files");
	if (!pFiles)
		return false;

	for (TiXmlElement* pFile = pFiles->FirstChildElement("File"); pFile; pFile = pFile->NextSiblingElement("File"))
	{
		t_fileInfo info;
		info.name = GetTextElement(pFile, "Name");
		if (info.name == _T(""))
			return false;

		const int dir = GetTextElementInt(pFile, "Dir", -1);
		if (dir == -1)
			return false;
		info.dir = dir == 1;

		info.size = GetTextElementLongLong(pFile, "Size", -2);
		if (info.size <= -2)
			return false;

		info.link = GetTextElementBool(pFile, "Link", false);

		m_fileList.push_back(info);
	}

	return true;
}
Example #23
0
bool CLastFMDirectory::ParseTrackList(CStdString url, CFileItemList &items)
{
  if (!RetrieveList(url))
    return false;

  TiXmlElement* pRootElement = m_xmlDoc.RootElement();

  TiXmlElement* pEntry = pRootElement->FirstChildElement("track");

  while(pEntry)
  {
    TiXmlNode* name = pEntry->FirstChild("name");
    TiXmlNode* artist = pEntry->FirstChild("artist");
    TiXmlElement *date = pEntry->FirstChildElement("date");

    TiXmlNode* count;
    count = pEntry->FirstChild("count");
    if (!count) count = pEntry->FirstChild("playcount");
    if (!count) count = pEntry->FirstChild("match");

    if (name)
    {
      if (artist)
        AddListEntry(name->FirstChild()->Value(),
            artist->FirstChild()->Value(),
            (count) ? count->FirstChild()->Value() : ((date) ? date->FirstChild()->Value() : NULL),
            (date) ? date->Attribute("uts") : NULL,
            NULL, "lastfm://xbmc/artist/" + (CStdString)artist->FirstChild()->Value() + "/", items);
      else
        // no artist in xml, assuming we're retrieving track list for the artist in m_objname...
        AddListEntry(name->FirstChild()->Value(),
            m_objname.c_str(),
            (count) ? count->FirstChild()->Value() : NULL,
            NULL, NULL, "lastfm://xbmc/artist/" + m_objname + "/", items);
    }
    else
    {
      // no luck, try another way :)
      const char *name = pEntry->Attribute("name");
      const char *artist = pEntry->FirstChildElement("artist")->Attribute("name");
      const char *count = pEntry->Attribute("count");

      if (name)
        AddListEntry(name, artist, count, NULL, NULL,
            "lastfm://xbmc/artist/" + (CStdString)artist + "/", items);
    }

    pEntry = pEntry->NextSiblingElement("track");
  }

  m_xmlDoc.Clear();
  return true;
}
Example #24
0
//---------------------------------------------------------------------------
bool BitmapFont::AddTexturesFromZip( TiXmlDocument& metaDataDocument, ZipFile* zipFile, const std::string& metaDataFilePath )
{
	TiXmlElement* rootElement = metaDataDocument.RootElement();
	TiXmlElement* pageElement = rootElement->FirstChildElement( "pages" );
	const size_t lastSlashLocation = metaDataFilePath.rfind( '/' );
	for ( TiXmlElement* currentElement = pageElement->FirstChildElement( "page" ); currentElement != nullptr; currentElement = currentElement->NextSiblingElement( "page" ) )
	{
		Texture* texture = Texture::CreateOrGetTexture( zipFile, metaDataFilePath.substr( 0, lastSlashLocation + 1 ) + std::string( currentElement->Attribute( "file" ) ) );
		if ( !texture ) return false;
		m_glyphSheets.push_back( texture );
	}
	return true;
}
Example #25
0
void StatTracker::Load ( const char* path )
{
	TiXmlDocument doc;

	if ( doc.LoadFile ( path ) == false )
	{
		Reset();
		return;
	}

	TiXmlElement* pRoot = doc.RootElement ();

	if ( pRoot == nullptr )
		return;

	TiXmlElement* pTime = pRoot->FirstChildElement ( "Time" );

	pTime->QueryFloatAttribute	( "Total" , &m_fTimePlayed);
	pTime->QueryFloatAttribute	 ( "Build" , &m_fBuildPhaseTime);
	pTime->QueryFloatAttribute	( "Survival" , &m_fSurvivalTime);

	TiXmlElement* pDistance = pRoot->FirstChildElement ( "General" );

	pDistance->QueryFloatAttribute	 ( "Walking" , &m_fDistanceWalked);
	pDistance->Attribute ( "Rounds" , (int *)&m_uRoundsSurvived);
	pDistance->Attribute ( "RoundSpree" , (int *)&m_uConsecutiveRoundsSurvived);

	TiXmlElement* pViolence = pRoot->FirstChildElement ( "Violence" );

	pViolence->Attribute ( "Kills" , (int *)&m_uTotalKills);
	pViolence->QueryFloatAttribute	 ( "Blood" , &m_fBloodSpilled);
	pViolence->Attribute ( "Grenades" , (int *)&m_uGrenadesThrown);
	pViolence->Attribute ( "TotalShots" , (int *)&m_uTotalShotsFired);
	pViolence->Attribute ( "MachineGun" , (int *)&m_uMachineGunBullets);
	pViolence->Attribute ( "Shotgun" , (int *)&m_uShotgunShells);
	pViolence->Attribute ( "RPG" , (int *)&m_uRPGRounds);
	pViolence->Attribute ( "HatTrick" , (int *)&m_uHatTrickShots);

	TiXmlElement* pExchange = pRoot->FirstChildElement ( "Exchange" );

	pExchange->Attribute ( "WallsPlaced" , (int *)&m_uWallsPlaced);
	pExchange->Attribute ( "WallsPickedUp" , (int *)&m_uWallsPickedUp);
	pExchange->Attribute ( "WindowsPlaced" , (int *)&m_uWindowsPlaced);
	pExchange->Attribute ( "WindowsPickedUp" , (int *)&m_uWindowsPickedUp);
	pExchange->Attribute ( "TowersBought" , (int *)&m_uTowersBought);
	pExchange->Attribute ( "TowersSold" , (int *)&m_uTowersSold);
	pExchange->Attribute ( "TrapsBought" , (int *)&m_uTrapsBought);
	pExchange->Attribute ( "TrapsSold" , (int *)&m_uTrapsSold);
	pExchange->Attribute ( "Money" , (int *)&m_uMoneySpent);

}
Example #26
0
const std::list<CServer> CRecentServerList::GetMostRecentServers(bool lockMutex /*=true*/)
{
	CInterProcessMutex mutex(MUTEX_MOSTRECENTSERVERS, false);
	if (lockMutex)
		mutex.Lock();

	if (!m_XmlFile.HasFileName() || m_XmlFile.Modified())
		m_XmlFile.Load(_T("recentservers"));
	else
		return m_mostRecentServers;

	TiXmlElement* pElement = m_XmlFile.GetElement();
	if (!pElement || !(pElement = pElement->FirstChildElement("RecentServers")))
		return m_mostRecentServers;

	m_mostRecentServers.clear();
    
	bool modified = false;
	TiXmlElement* pServer = pElement->FirstChildElement("Server");
	while (pServer)
	{
		CServer server;
		if (!GetServer(pServer, server) || m_mostRecentServers.size() >= 10)
		{
			TiXmlElement* pRemove = pServer;
			pServer = pServer->NextSiblingElement("Server");
			pElement->RemoveChild(pRemove);
			modified = true;
		}
		else
		{
			std::list<CServer>::const_iterator iter;
			for (iter = m_mostRecentServers.begin(); iter != m_mostRecentServers.end(); iter++)
			{
				if (*iter == server)
					break;
			}
			if (iter == m_mostRecentServers.end())
				m_mostRecentServers.push_back(server);
			pServer = pServer->NextSiblingElement("Server");
		}
	}

	if (modified)
	{
		wxString error;
		m_XmlFile.Save(&error);
	}

	return m_mostRecentServers;
}
Example #27
0
void cPreMenu::LoadConfig()
{
	////////////////////////////////////////////////
	//Load the document
	TiXmlDocument *pXmlDoc = hplNew( TiXmlDocument, ("config/startup.cfg") );
	if(pXmlDoc->LoadFile()==false){
		Error("Couldn't load XML document 'config/startup.cfg'\n");
		hplDelete( pXmlDoc );
	}

	////////////////////////////////////////////////
	//Load the root
	TiXmlElement *pRootElem = pXmlDoc->FirstChildElement();
	if(pRootElem==NULL){
		Error("Couldn't load root from XML document 'config/startup.cfg'\n");
		hplDelete( pXmlDoc );
	}

	////////////////////////////////////////////////
	//Load the Main element.
	TiXmlElement *pMainElem = pRootElem->FirstChildElement("Main");
	if(pMainElem==NULL){
		Error("Couldn't load Main element from XML document 'config/startup.cfg'\n");
		hplDelete( pXmlDoc );
	}

	mbShowText = cString::ToBool(pMainElem->Attribute("ShowText"),false);

	////////////////////////////////////////////////
	//Load the Logos element.
	TiXmlElement *pLogosParentElem = pRootElem->FirstChildElement("Logos");
	if(pLogosParentElem==NULL){
		Error("Couldn't load Logs element from XML document 'config/startup.cfg'\n");
		hplDelete( pXmlDoc );
	}


	////////////////////////////////////////////////
	//Get logos
	TiXmlElement *pLogoElem = pLogosParentElem->FirstChildElement("Logo");
	for(; pLogoElem != NULL; pLogoElem = pLogoElem->NextSiblingElement("Logo"))
	{
		tString sFile = cString::ToString(pLogoElem->Attribute("File"),"");
		mvTexNames.push_back(sFile);

		//Log("Texture %s\n",sFile.c_str());
	}


	hplDelete( pXmlDoc );
}
void FileSystemOperator::LoadPreSavedContents() {
  struct dirent *entry;
  DIR *directory_handler = opendir(target_directory_path_.c_str());

  // Load all annotation file data in the specified directory
  while ((entry = readdir(directory_handler)) != NULL) {
    // Get entry's status (file name, permission...etc)
    struct stat status;
    std::string absolute_path = target_directory_path_ + std::string(entry->d_name);

    if (stat(absolute_path.c_str(), &status) == 0 &&
        S_ISREG(status.st_mode)) { // This entry is surely nomal file
      LabelData loaded_data;

      // Open this xml file
      TiXmlDocument xml_document(absolute_path);
      xml_document.LoadFile();

      // Parse its contents and insert into the structure
      TiXmlElement* root = xml_document.FirstChildElement("annotation");

      TiXmlElement* folder = root->FirstChildElement("folder");
      loaded_data.folder_name = std::string(folder->GetText());

      TiXmlElement* file = root->FirstChildElement("filename");
      loaded_data.file_name = std::string(file->GetText());

      TiXmlElement* size = root->FirstChildElement("size");
      TiXmlElement* width = size->FirstChildElement("width");
      TiXmlElement* height = size->FirstChildElement("height");
      TiXmlElement* depth = size->FirstChildElement("depth");
      loaded_data.width = std::atoi(width->GetText());
      loaded_data.height = std::atoi(height->GetText());
      loaded_data.depth = std::atoi(depth->GetText());

      TiXmlElement* object = root->FirstChildElement("object");
      TiXmlElement* name = object->FirstChildElement("name");
      loaded_data.state = static_cast<LightState>(std::atoi(name->GetText()));

      TiXmlElement* bounding_box = object->FirstChildElement("bndbox");
      TiXmlElement* x_min = bounding_box->FirstChildElement("xmin");
      TiXmlElement* y_min = bounding_box->FirstChildElement("ymin");
      TiXmlElement* x_max = bounding_box->FirstChildElement("xmax");
      TiXmlElement* y_max = bounding_box->FirstChildElement("ymax");
      loaded_data.x_start = std::atoi(x_min->GetText());
      loaded_data.y_start = std::atoi(y_min->GetText());
      loaded_data.x_end = std::atoi(x_max->GetText());
      loaded_data.y_end = std::atoi(y_max->GetText());

      // Insert loaded data into list
      int file_id = GetFileIDFromFilePath(entry->d_name);
      label_data_list_[file_id] = loaded_data;
    }
  }
}
Example #29
0
bool CGameWorld::init()
{
	m_iTime = Sys_GetTime();


	const char* pFilePath = "setup.xml";

	TiXmlDocument xmlDoc(pFilePath);
	if (!xmlDoc.LoadFile())
	{
		CORE("init:","load setup.xml error");
		return false;
	}
	TiXmlElement *root = xmlDoc.RootElement();  
	if (root==NULL)
	{
		CORE("init:","init error RootElement");
		return false;
	}
	


	if (!initConfig(root->FirstChildElement("config")))
	{
		CORE("init:","initConfig error");
		return false;
	}

	if (!initNet(root->FirstChildElement("net")))
	{
		CORE("init:","initNet error");
		return false;
	}

	if (!initDB(root->FirstChildElement("db")))
	{
		CORE("init:","initDB error");
		return false;
	}

	if (!initData())
	{
		return false;
	}


	return true;

}
void ProjectConfiguration::XmlLoad(TiXmlElement* Node,cbProject* Project)
{
    m_GlobalUsedLibs.Clear();
    m_TargetsUsedLibs.clear();
    m_DisableAuto = false;

    TiXmlElement* LibFinder = Node->FirstChildElement("lib_finder");
    if ( !LibFinder ) return;

    int noauto = 0;
    if ( (LibFinder->QueryIntAttribute("disable_auto",&noauto) == TIXML_SUCCESS) && noauto )
    {
        m_DisableAuto = true;
    }

    for ( TiXmlElement* Elem = LibFinder->FirstChildElement("lib");
            Elem;
            Elem = Elem->NextSiblingElement("lib") )
    {
        wxString LibName = cbC2U(Elem->Attribute("name"));
        if ( !LibName.IsEmpty() && m_GlobalUsedLibs.Index(LibName)==wxNOT_FOUND )
        {
            m_GlobalUsedLibs.Add(LibName);
        }
    }

    for ( TiXmlElement* Elem = LibFinder->FirstChildElement("target");
            Elem;
            Elem = Elem->NextSiblingElement("target") )
    {
        wxString TargetName = cbC2U(Elem->Attribute("name"));
        if ( !Project->GetBuildTarget(TargetName) ) continue;

        wxArrayString& Libs = m_TargetsUsedLibs[TargetName];
        for ( TiXmlElement* LibElem = Elem->FirstChildElement("lib");
                LibElem;
                LibElem = LibElem->NextSiblingElement("lib") )
        {
            wxString LibName = cbC2U(LibElem->Attribute("name"));
            if ( !LibName.IsEmpty() && Libs.Index(LibName)==wxNOT_FOUND )
            {
                Libs.Add(LibName);
            }
        }
    }

    // TODO: Invoke library settings check
}