void HouseManager::load(const std::string& fileName) { try { TiXmlDocument doc; doc.Parse(g_resources.readFileContents(fileName).c_str()); if(doc.Error()) stdext::throw_exception(stdext::format("failed to load '%s': %s (House XML)", fileName, doc.ErrorDesc())); TiXmlElement *root = doc.FirstChildElement(); if(!root || root->ValueTStr() != "houses") stdext::throw_exception("invalid root tag name"); for(TiXmlElement *elem = root->FirstChildElement(); elem; elem = elem->NextSiblingElement()) { if(elem->ValueTStr() != "house") stdext::throw_exception("invalid house tag."); uint32 houseId = elem->readType<uint32>("houseid"); HousePtr house = getHouse(houseId); if(!house) house = HousePtr(new House(houseId)), addHouse(house); house->load(elem); } } catch(std::exception& e) { g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what())); } }
void ThingTypeManager::loadXml(const std::string& file) { try { if(!isOtbLoaded()) stdext::throw_exception("OTB must be loaded before XML"); TiXmlDocument doc; doc.Parse(g_resources.readFileContents(file).c_str()); if(doc.Error()) stdext::throw_exception(stdext::format("failed to parse '%s': '%s'", file, doc.ErrorDesc())); TiXmlElement* root = doc.FirstChildElement(); if(!root || root->ValueTStr() != "items") stdext::throw_exception("invalid root tag name"); for(TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) { if(unlikely(element->ValueTStr() != "item")) continue; uint16 id = element->readType<uint16>("id"); if(id != 0) { std::vector<std::string> s_ids = stdext::split(element->Attribute("id"), ";"); for(const std::string& s : s_ids) { std::vector<int32> ids = stdext::split<int32>(s, "-"); if(ids.size() > 1) { int32 i = ids[0]; while(i <= ids[1]) parseItemType(i++, element); } else parseItemType(atoi(s.c_str()), element); } } else { std::vector<int32> begin = stdext::split<int32>(element->Attribute("fromid"), ";"); std::vector<int32> end = stdext::split<int32>(element->Attribute("toid"), ";"); if(begin[0] && begin.size() == end.size()) { size_t size = begin.size(); for(size_t i = 0; i < size; ++i) while(begin[i] <= end[i]) parseItemType(begin[i]++, element); } } } doc.Clear(); m_xmlLoaded = true; g_logger.debug("items.xml read successfully."); } catch(std::exception& e) { g_logger.error(stdext::format("Failed to load '%s' (XML file): %s", file, e.what())); } }
bool loadXMLFile (TiXmlDocument &pXMLDoc, std::string XMLFilename, std::map<int, std::string> * pMapXmlStrings, bool isSourceFile) { if (!pXMLDoc.LoadFile(XMLFilename.c_str())) { printf ("%s %s\n", pXMLDoc.ErrorDesc(), XMLFilename.c_str()); return false; } if (isSourceFile) GetEncoding(&pXMLDoc, sourceXMLEncoding); else GetEncoding(&pXMLDoc, foreignXMLEncoding); TiXmlElement* pRootElement = pXMLDoc.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="strings") { printf ("error: No root element called: \"strings\" or no child found in input XML file: %s\n", XMLFilename.c_str()); return false; } if (isSourceFile) GetComment(pRootElement->FirstChild(), -1); const TiXmlElement *pChildElement = pRootElement->FirstChildElement("string"); const char* pAttrId = NULL; const char* pValue = NULL; std::string valueString; int id; while (pChildElement) { pAttrId=pChildElement->Attribute("id"); if (pAttrId && !pChildElement->NoChildren()) { id = atoi(pAttrId); if (pMapXmlStrings->find(id) == pMapXmlStrings->end()) { pValue = pChildElement->FirstChild()->Value(); valueString = EscapeLF(pValue); if (isSourceFile) multimapSourceXmlStrings.insert(std::pair<std::string,int>( valueString,id)); (*pMapXmlStrings)[id] = valueString; if (pChildElement && isSourceFile) GetComment(pChildElement->NextSibling(), id); } } pChildElement = pChildElement->NextSiblingElement("string"); } // Free up the allocated memory for the XML file pXMLDoc.Clear(); return true; }
void ThingTypeManager::loadXml(const std::string& file) { /// Read XML TiXmlDocument doc; doc.Parse(g_resources.loadFile(file).c_str()); if(doc.Error()) stdext::throw_exception(stdext::format("failed to parse '%s': '%s'", file, doc.ErrorDesc())); TiXmlElement* root = doc.FirstChildElement(); if(!root || root->ValueTStr() != "items") stdext::throw_exception("invalid root tag name"); for (TiXmlElement *element = root->FirstChildElement(); element; element = element->NextSiblingElement()) { if(element->ValueTStr() != "item") continue; uint16 id = element->readType<uint16>("id"); if(id > 20000 && id < 20100) { id -= 20000; ItemTypePtr newType(new ItemType); newType->setServerId(id); addItemType(newType); } if(id != 0) parseItemType(id, element); else { uint16 fromId = element->readType<uint16>("fromid"), toId = element->readType<uint16>("toid"); for(uint16 i = fromId; i < toId; ++i) parseItemType(i, element); } } doc.Clear(); m_xmlLoaded = true; g_logger.debug("items.xml read successfully."); }
my_shared_ptr<Geometry> parseGeometry(TiXmlElement *g) { my_shared_ptr<Geometry> geom; if (!g) return geom; TiXmlElement *shape = g->FirstChildElement(); if (!shape) { logError("Geometry tag contains no child element."); return geom; } const std::string type_name = shape->ValueTStr().c_str(); if (type_name == "sphere") { Sphere *s = new Sphere(); geom.reset(s); if (parseSphere(*s, shape)) return geom; } else if (type_name == "box") { Box *b = new Box(); geom.reset(b); if (parseBox(*b, shape)) return geom; } else if (type_name == "cylinder") { Cylinder *c = new Cylinder(); geom.reset(c); if (parseCylinder(*c, shape)) return geom; } else if (type_name == "mesh") { Mesh *m = new Mesh(); geom.reset(m); if (parseMesh(*m, shape)) return geom; } else { logError("Unknown geometry type '%s'", type_name.c_str()); return geom; } return my_shared_ptr<Geometry>(); }
void Map::loadSpawns(const std::string &fileName) { if(!m_creatures.isLoaded()) stdext::throw_exception("cannot load spawns; monsters/nps aren't loaded."); TiXmlDocument doc; doc.Parse(g_resources.loadFile(fileName).c_str()); if(doc.Error()) stdext::throw_exception(stdext::format("cannot load spawns xml file '%s: '%s'", fileName, doc.ErrorDesc())); TiXmlElement* root = doc.FirstChildElement(); if(!root || root->ValueStr() != "spawns") stdext::throw_exception("malformed spawns file"); CreatureTypePtr cType(nullptr); for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) { if(node->ValueTStr() != "spawn") stdext::throw_exception("invalid spawn node"); Position centerPos = node->readPos("center"); for(TiXmlElement* cNode = node->FirstChildElement(); cNode; cNode = cNode->NextSiblingElement()) { if(cNode->ValueStr() != "monster" && cNode->ValueStr() != "npc") stdext::throw_exception(stdext::format("invalid spawn-subnode %s", cNode->ValueStr())); std::string cName = cNode->Attribute("name"); stdext::tolower(cName); stdext::trim(cName); if (!(cType = m_creatures.getCreature(cName))) continue; cType->setSpawnTime(cNode->readType<int>("spawntime")); CreaturePtr creature(new Creature); creature->setOutfit(cType->getOutfit()); stdext::ucwords(cName); creature->setName(cName); centerPos.x += cNode->readType<int>("x"); centerPos.y += cNode->readType<int>("y"); centerPos.z = cNode->readType<int>("z"); addThing(creature, centerPos, 4); } } }
//读取Rss文件的信息。 //传入参数 本地暂存文件的绝对路径。 bool ReadXmlFile(TCHAR* lpszTempRssXmlPath, string& rssFeedTitle, map<string, RssContent>& mXML) { string Title; RssContent Con; memset(&Con, 0, sizeof(Con)); char* cszTempRssXmlPath = FileEncode::UnicodeToAnsi((char*)lpszTempRssXmlPath); TiXmlDocument *myDocument = new TiXmlDocument(cszTempRssXmlPath); free(cszTempRssXmlPath); myDocument->LoadFile(); TiXmlElement *RootElement = myDocument->RootElement(); TiXmlElement *FirstElement = RootElement->FirstChildElement(); TiXmlElement *MyElement = FirstElement->FirstChildElement(); rssFeedTitle = MyElement->GetText(); while (MyElement != NULL) { while ((MyElement->ValueTStr()) != "item") { MyElement = MyElement->NextSiblingElement(); } TiXmlElement *MyElement_1 = MyElement->FirstChildElement(); while (MyElement_1->ValueTStr() != "title") { MyElement_1 = MyElement_1->NextSiblingElement(); } Title = MyElement_1->GetText(); while (MyElement_1->ValueTStr() != "link") { MyElement_1 = MyElement_1->NextSiblingElement(); } Con.Web = MyElement_1->GetText(); while (MyElement_1->ValueTStr() != "pubDate") { MyElement_1 = MyElement_1->NextSiblingElement(); } Con.Date = MyElement_1->GetText(); while (MyElement_1->ValueTStr() != "description") { MyElement_1 = MyElement_1->NextSiblingElement(); } Con.Description = MyElement_1->GetText(); mXML.insert(pair<string, RssContent>(Title, Con)); MyElement = MyElement->NextSiblingElement(); } return true; }
bool CHTTPHandler::LoadCredentials (std::string CredentialsFilename) { TiXmlDocument xmlPasswords; if (!xmlPasswords.LoadFile(CredentialsFilename.c_str())) { CLog::Log(logINFO, "HTTPHandler: No \".passwords.xml\" file exists in project dir. No password protected web download will be available."); return false; } CLog::Log(logINFO, "HTTPHandler: Succesfuly found the .passwsords.xml file: %s", CredentialsFilename.c_str()); TiXmlElement* pRootElement = xmlPasswords.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="websites") { CLog::Log(logWARNING, "HTTPHandler: No root element called \"websites\" in xml file."); return false; } CLoginData LoginData; const TiXmlElement *pChildElement = pRootElement->FirstChildElement("website"); while (pChildElement && pChildElement->FirstChild()) { std::string strWebSitePrefix = pChildElement->Attribute("prefix"); if (pChildElement->FirstChild()) { const TiXmlElement *pChildLOGINElement = pChildElement->FirstChildElement("login"); if (pChildLOGINElement && pChildLOGINElement->FirstChild()) LoginData.strLogin = pChildLOGINElement->FirstChild()->Value(); const TiXmlElement *pChildPASSElement = pChildElement->FirstChildElement("password"); if (pChildPASSElement && pChildPASSElement->FirstChild()) LoginData.strPassword = pChildPASSElement->FirstChild()->Value(); m_mapLoginData [strWebSitePrefix] = LoginData; CLog::Log(logINFO, "HTTPHandler: found login credentials for website prefix: %s", strWebSitePrefix.c_str()); } pChildElement = pChildElement->NextSiblingElement("website"); } return true; };
void CreatureManager::loadSpawns(const std::string& fileName) { if(!isLoaded()) { g_logger.warning("creatures aren't loaded yet to load spawns."); return; } if(m_spawnLoaded) { g_logger.warning("attempt to reload spawns."); return; } try { TiXmlDocument doc; doc.Parse(g_resources.readFileContents(fileName).c_str()); if(doc.Error()) stdext::throw_exception(stdext::format("cannot load spawns xml file '%s: '%s'", fileName, doc.ErrorDesc())); TiXmlElement* root = doc.FirstChildElement(); if(!root || root->ValueStr() != "spawns") stdext::throw_exception("malformed spawns file"); for(TiXmlElement* node = root->FirstChildElement(); node; node = node->NextSiblingElement()) { if(node->ValueTStr() != "spawn") stdext::throw_exception("invalid spawn node"); SpawnPtr spawn(new Spawn); spawn->load(node); m_spawns.insert(std::make_pair(spawn->getCenterPos(), spawn)); } doc.Clear(); m_spawnLoaded = true; } catch(std::exception& e) { g_logger.error(stdext::format("Failed to load '%s': %s", fileName, e.what())); } }
bool UrdfParser::parseGeometry(UrdfGeometry& geom, TiXmlElement* g, ErrorLogger* logger) { btAssert(g); TiXmlElement *shape = g->FirstChildElement(); if (!shape) { logger->reportError("Geometry tag contains no child element."); return false; } const std::string type_name = shape->ValueTStr().c_str(); if (type_name == "sphere") { geom.m_type = URDF_GEOM_SPHERE; if (!shape->Attribute("radius")) { logger->reportError("Sphere shape must have a radius attribute"); return false; } else { geom.m_sphereRadius = urdfLexicalCast<double>(shape->Attribute("radius")); } } else if (type_name == "box") { geom.m_type = URDF_GEOM_BOX; if (m_parseSDF) { TiXmlElement* size = shape->FirstChildElement("size"); if (0==size) { logger->reportError("box requires a size child element"); return false; } parseVector3(geom.m_boxSize,size->GetText(),logger); } else { if (!shape->Attribute("size")) { logger->reportError("box requires a size attribute"); return false; } else { parseVector3(geom.m_boxSize,shape->Attribute("size"),logger); } } } else if (type_name == "cylinder") { geom.m_type = URDF_GEOM_CYLINDER; if (!shape->Attribute("length") || !shape->Attribute("radius")) { logger->reportError("Cylinder shape must have both length and radius attributes"); return false; } geom.m_cylinderRadius = urdfLexicalCast<double>(shape->Attribute("radius")); geom.m_cylinderLength = urdfLexicalCast<double>(shape->Attribute("length")); } else if (type_name == "mesh") { geom.m_type = URDF_GEOM_MESH; if (m_parseSDF) { TiXmlElement* scale = shape->FirstChildElement("scale"); if (0==scale) { geom.m_meshScale.setValue(1,1,1); } else { parseVector3(geom.m_meshScale,scale->GetText(),logger); } TiXmlElement* filename = shape->FirstChildElement("uri"); geom.m_meshFileName = filename->GetText(); } else { if (!shape->Attribute("filename")) { logger->reportError("Mesh must contain a filename attribute"); return false; } geom.m_meshFileName = shape->Attribute("filename"); if (shape->Attribute("scale")) { parseVector3(geom.m_meshScale,shape->Attribute("scale"),logger); } else { geom.m_meshScale.setValue(1,1,1); } } } else { if (this->m_parseSDF) { if (type_name == "plane") { geom.m_type = URDF_GEOM_PLANE; TiXmlElement *n = shape->FirstChildElement("normal"); TiXmlElement *s = shape->FirstChildElement("size"); if ((0==n)||(0==s)) { logger->reportError("Plane shape must have both normal and size attributes"); return false; } parseVector3(geom.m_planeNormal,n->GetText(),logger); } } else { logger->reportError("Unknown geometry type:"); logger->reportError(type_name.c_str()); return false; } } return true; }
bool CUpdateXMLHandler::DownloadXMLToMap (std::string strURL, std::map<std::string, CXMLResdata> &mapResourceData, std::string const &strTXProjectname) { std::string strURLXMLFile = strURL + "xbmc-txupdate.xml"; std::string strXMLFile = g_HTTPHandler.GetURLToSTR(strURLXMLFile); if (strXMLFile.empty()) CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: http error getting XML file from upstream url: %s", strURL.c_str()); TiXmlDocument xmlUpdateXML; if (!xmlUpdateXML.Parse(strXMLFile.c_str(), 0, TIXML_DEFAULT_ENCODING)) { CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: UpdateXML file problem: %s %s\n", xmlUpdateXML.ErrorDesc(), strURL.c_str()); return false; } TiXmlElement* pRootElement = xmlUpdateXML.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="resources") { CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No root element called \"resources\" in xml file. Cannot continue. Please create it"); return false; } std::string strProjName; if (!pRootElement->Attribute("projectname") || (strProjName = pRootElement->Attribute("projectname")) == "") CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No projectname specified in xbmc-txupdate.xml file. Cannot continue. " "Please contact TeamXBMC about this problem!"); CLog::Log(logINFO, "Reading xbmc-txupdate.xml file for project: %s", strTXProjectname.c_str()); std::string strMergedLangfileDir; if (!pRootElement->Attribute("merged_langfiledir") || (strMergedLangfileDir = pRootElement->Attribute("merged_langfiledir")) == "") strMergedLangfileDir = DEFAULTMERGEDLANGDIR; const TiXmlElement *pChildResElement = pRootElement->FirstChildElement("resource"); if (!pChildResElement || pChildResElement->NoChildren()) { CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No xml element called \"resource\" exists in the xml file. Please contact TeamXBMC about this problem!"); return false; } std::string strType; while (pChildResElement && pChildResElement->FirstChild()) { CXMLResdata currResData; currResData.strTranslationrepoURL = strURL; currResData.strProjName = strProjName; currResData.strMergedLangfileDir = strMergedLangfileDir; std::string strResName; if (!pChildResElement->Attribute("name") || (strResName = pChildResElement->Attribute("name")) == "") { CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: No name specified for resource. Cannot continue. Please contact TeamXBMC about this problem!"); return false; } currResData.strResName = strResName; if (pChildResElement->FirstChild()) { const TiXmlElement *pChildURLElement = pChildResElement->FirstChildElement("upstreamURL"); if (pChildURLElement && pChildURLElement->FirstChild()) currResData.strUpstreamURL = pChildURLElement->FirstChild()->Value(); if (currResData.strUpstreamURL.empty()) CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: UpstreamURL entry is empty or missing for resource %s", strResName.c_str()); if (pChildURLElement->Attribute("filetype")) currResData.strLangFileType = pChildURLElement->Attribute("filetype"); // For PO no need to explicitly specify. Only for XML. if (pChildURLElement->Attribute("URLsuffix")) currResData.strURLSuffix = pChildURLElement->Attribute("URLsuffix"); // Some http servers need suffix strings after filename(eg. gitweb) if (pChildURLElement->Attribute("HasChangelog")) { std::string strHaschangelog = pChildURLElement->Attribute("HasChangelog"); // Note if the addon has upstream changelog currResData.bHasChangelog = strHaschangelog == "true"; } if (pChildURLElement->Attribute("LogFormat")) { std::string strLogFormat = pChildURLElement->Attribute("LogFormat"); currResData.strLogFormat = strLogFormat; } if (pChildURLElement->Attribute("LogFilename")) { std::string strLogFilename = pChildURLElement->Attribute("LogFilename"); currResData.strLogFilename = strLogFilename; } const TiXmlElement *pChildUpstrLElement = pChildResElement->FirstChildElement("upstreamLangs"); if (pChildUpstrLElement && pChildUpstrLElement->FirstChild()) currResData.strLangsFromUpstream = pChildUpstrLElement->FirstChild()->Value(); const TiXmlElement *pChildResTypeElement = pChildResElement->FirstChildElement("resourceType"); if (pChildResTypeElement->Attribute("AddonXMLSuffix")) currResData.strAddonXMLSuffix = pChildResTypeElement->Attribute("AddonXMLSuffix"); // Some addons have unique addon.xml filename eg. pvr addons with .in suffix if (pChildResTypeElement && pChildResTypeElement->FirstChild()) { strType = pChildResTypeElement->FirstChild()->Value(); if (strType == "addon") currResData.Restype = ADDON; else if (strType == "addon_nostrings") currResData.Restype = ADDON_NOSTRINGS; else if (strType == "skin") currResData.Restype = SKIN; else if (strType == "xbmc_core") currResData.Restype = CORE; } if (currResData.Restype == UNKNOWN) CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: Unknown type found or missing resourceType field for resource %s", strResName.c_str()); const TiXmlElement *pChildResDirElement = pChildResElement->FirstChildElement("resourceSubdir"); if (pChildResDirElement && pChildResDirElement->FirstChild()) currResData.strResDirectory = pChildResDirElement->FirstChild()->Value(); if (pChildResDirElement->Attribute("writePO")) { std::string strBool = pChildResDirElement->Attribute("writePO"); currResData.bWritePO = strBool == "true"; } if (pChildResDirElement->Attribute("writeXML")) { std::string strBool = pChildResDirElement->Attribute("writeXML"); currResData.bWriteXML = strBool == "true"; } if (pChildResDirElement->Attribute("DIRprefix")) currResData.strDIRprefix = pChildResDirElement->Attribute("DIRprefix"); // If there is any SUBdirectory needed in the tree const TiXmlElement *pChildTXNameElement = pChildResElement->FirstChildElement("TXname"); if (pChildTXNameElement && pChildTXNameElement->FirstChild()) currResData.strTXResName = pChildTXNameElement->FirstChild()->Value(); if (currResData.strTXResName.empty()) CLog::Log(logERROR, "CUpdateXMLHandler::DownloadXMLToMem: Transifex resource name is empty or missing for resource %s", strResName.c_str()); currResData.strResNameFull = strTXProjectname + "/" + strResName; mapResourceData[currResData.strResNameFull] = currResData; } pChildResElement = pChildResElement->NextSiblingElement("resource"); } return true; };
std::list<CInputData> CInputXMLHandler::ReadXMLToMem(string strFileName) { std::string strXMLFile = g_File.ReadFileToStr(strFileName); if (strXMLFile.empty()) CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: http error getting XML file from path: %s", strFileName.c_str()); TiXmlDocument xmlUpdateXML; if (!xmlUpdateXML.Parse(strXMLFile.c_str(), 0, TIXML_DEFAULT_ENCODING)) CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: UpdateXML file problem: %s %s\n", xmlUpdateXML.ErrorDesc(), strFileName.c_str()); TiXmlElement* pRootElement = xmlUpdateXML.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="addonlist") CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: No root element called \"addonlist\" in xml file. Cannot continue. Please create it"); const TiXmlElement *pChildResElement = pRootElement->FirstChildElement("addon"); if (!pChildResElement || pChildResElement->NoChildren()) CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: No xml element called \"addon\" exists in the xml file. Please contact TeamXBMC about this problem!"); std::list<CInputData> listInputData; while (pChildResElement && pChildResElement->FirstChild()) { CInputData currInputData; std::string strResName; if (!pChildResElement->Attribute("name") || (strResName = pChildResElement->Attribute("name")) == "") CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: No name specified for addon. Cannot continue."); currInputData.strAddonName = strResName; const TiXmlElement *pChildDirElement = pChildResElement->FirstChildElement("localdir"); if (pChildDirElement && pChildDirElement->FirstChild()) currInputData.strAddonDir = pChildDirElement->FirstChild()->Value(); if (currInputData.strAddonDir.empty()) CLog::Log(logERROR, "CInputXMLHandler::ReadXMLToMem: Local directory is missing for addon: %s", strResName.c_str()); std::string strBool; const TiXmlElement *pChildSkipchlogElement = pChildResElement->FirstChildElement("skipchangelog"); if (pChildSkipchlogElement && pChildSkipchlogElement->FirstChild()) strBool = pChildSkipchlogElement->FirstChild()->Value(); currInputData.bSkipChangelog = (strBool == "true"); strBool.clear(); const TiXmlElement *pChildSkipenglishElement = pChildResElement->FirstChildElement("skipenglish"); if (pChildSkipenglishElement && pChildSkipenglishElement->FirstChild()) strBool = pChildSkipenglishElement->FirstChild()->Value(); currInputData.bSkipEnglishFile = (strBool == "true"); const TiXmlElement *pChildGittemplElement = pChildResElement->FirstChildElement("gittemplate"); if (pChildGittemplElement && pChildGittemplElement->FirstChild()) currInputData.strGittemplate = pChildGittemplElement->FirstChild()->Value(); std::string strGitExecPath; if (pChildGittemplElement->Attribute("gitexecpath") && (strGitExecPath = pChildGittemplElement->Attribute("gitexecpath")) != "") currInputData.strGitExecPath = strGitExecPath; listInputData.push_back(currInputData); pChildResElement = pChildResElement->NextSiblingElement("addon"); } return listInputData; }
bool loadAddonXMLFile (std::string AddonXMLFilename) { TiXmlDocument xmlAddonXML; if (!xmlAddonXML.LoadFile(AddonXMLFilename.c_str())) { printf ("%s %s\n", xmlAddonXML.ErrorDesc(), (WorkingDir + "addon.xml").c_str()); return false; } GetEncoding(&xmlAddonXML, addonXMLEncoding); TiXmlElement* pRootElement = xmlAddonXML.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="addon") { printf ("error: No root element called: \"addon\" or no child found in AddonXML file: %s\n", AddonXMLFilename.c_str()); return false; } const char* pMainAttrId = NULL; pMainAttrId=pRootElement->Attribute("id"); if (!pMainAttrId) { printf ("warning: No addon name was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjName = "xbmc-unnamed"; } else ProjName = EscapeLF(pMainAttrId); pMainAttrId=pRootElement->Attribute("version"); if (!pMainAttrId) { printf ("warning: No version name was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjVersion = "rev_unknown"; } else ProjVersion = EscapeLF(pMainAttrId); pMainAttrId=pRootElement->Attribute("name"); if (!pMainAttrId) { printf ("warning: No addon name was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjTextName = "unknown"; } else ProjTextName = EscapeLF(pMainAttrId); pMainAttrId=pRootElement->Attribute("provider-name"); if (!pMainAttrId) { printf ("warning: No addon provider was available in addon.xml file: %s\n", AddonXMLFilename.c_str()); ProjProvider = "unknown"; } else ProjProvider = EscapeLF(pMainAttrId); std::string strAttrToSearch = "xbmc.addon.metadata"; const TiXmlElement *pChildElement = pRootElement->FirstChildElement("extension"); while (pChildElement && strcmp(pChildElement->Attribute("point"), "xbmc.addon.metadata") != 0) pChildElement = pChildElement->NextSiblingElement("extension"); const TiXmlElement *pChildSummElement = pChildElement->FirstChildElement("summary"); while (pChildSummElement && pChildSummElement->FirstChild()) { std::string strLang = pChildSummElement->Attribute("lang"); if (pChildSummElement->FirstChild()) { std::string strValue = EscapeLF(pChildSummElement->FirstChild()->Value()); mapAddonXMLData[strLang].strSummary = strValue; } pChildSummElement = pChildSummElement->NextSiblingElement("summary"); } const TiXmlElement *pChildDescElement = pChildElement->FirstChildElement("description"); while (pChildDescElement && pChildDescElement->FirstChild()) { std::string strLang = pChildDescElement->Attribute("lang"); if (pChildDescElement->FirstChild()) { std::string strValue = EscapeLF(pChildDescElement->FirstChild()->Value()); mapAddonXMLData[strLang].strDescription = strValue; } pChildDescElement = pChildDescElement->NextSiblingElement("description"); } const TiXmlElement *pChildDisclElement = pChildElement->FirstChildElement("disclaimer"); while (pChildDisclElement && pChildDisclElement->FirstChild()) { std::string strLang = pChildDisclElement->Attribute("lang"); if (pChildDisclElement->FirstChild()) { std::string strValue = EscapeLF(pChildDisclElement->FirstChild()->Value()); mapAddonXMLData[strLang].strDisclaimer = strValue; } pChildDisclElement = pChildDisclElement->NextSiblingElement("disclaimer"); } return true; }
bool CUpdateXMLHandler::LoadXMLToMem (std::string rootDir) { std::string UpdateXMLFilename = rootDir + DirSepChar + "xbmc-txupdate.xml"; TiXmlDocument xmlUpdateXML; if (!xmlUpdateXML.LoadFile(UpdateXMLFilename.c_str())) { CLog::Log(logERROR, "UpdXMLHandler: No 'xbmc-txupdate.xml' file exists in the specified project dir. Cannot continue. " "Please create one!"); return false; } CLog::Log(logINFO, "UpdXMLHandler: Succesfuly found the update.xml file in the specified project directory"); TiXmlElement* pRootElement = xmlUpdateXML.RootElement(); if (!pRootElement || pRootElement->NoChildren() || pRootElement->ValueTStr()!="resources") { CLog::Log(logERROR, "UpdXMLHandler: No root element called \"resources\" in xml file. Cannot continue. Please create it"); return false; } std::string strProjName ; if (pRootElement->Attribute("projectname") && (strProjName = pRootElement->Attribute("projectname")) != "") { CLog::Log(logINFO, "UpdXMLHandler: Found projectname in xbmc-txupdate.xml file: %s",strProjName.c_str()); g_Settings.SetProjectname(strProjName); } else CLog::Log(logERROR, "UpdXMLHandler: No projectname specified in xbmc-txupdate.xml file. Cannot continue. " "Please specify the Transifex projectname in the xml file"); std::string strHTTPCacheExp; if (pRootElement->Attribute("http_cache_expire") && (strHTTPCacheExp = pRootElement->Attribute("http_cache_expire")) != "") { CLog::Log(logINFO, "UpdXMLHandler: Found http cache expire time in xbmc-txupdate.xml file: %s", strHTTPCacheExp.c_str()); g_Settings.SetHTTPCacheExpire(strtol(&strHTTPCacheExp[0], NULL, 10)); } else CLog::Log(logINFO, "UpdXMLHandler: No http cache expire time specified in xbmc-txupdate.xml file. Using default value: %iminutes", DEFAULTCACHEEXPIRE); std::string strMinCompletion; if (pRootElement->Attribute("min_completion") && (strMinCompletion = pRootElement->Attribute("min_completion")) != "") { CLog::Log(logINFO, "UpdXMLHandler: Found min completion percentage in xbmc-txupdate.xml file: %s", strMinCompletion.c_str()); g_Settings.SetMinCompletion(strtol(&strMinCompletion[0], NULL, 10)); } else CLog::Log(logINFO, "UpdXMLHandler: No min completion percentage specified in xbmc-txupdate.xml file. Using default value: %i%", DEFAULTMINCOMPLETION); std::string strMergedLangfileDir; if (pRootElement->Attribute("merged_langfiledir") && (strMergedLangfileDir = pRootElement->Attribute("merged_langfiledir")) != "") { CLog::Log(logINFO, "UpdXMLHandler: Found merged language file directory in xbmc-txupdate.xml file: %s", strMergedLangfileDir.c_str()); g_Settings.SetMergedLangfilesDir(strMergedLangfileDir); } else CLog::Log(logINFO, "UpdXMLHandler: No merged language file directory specified in xbmc-txupdate.xml file. Using default value: %s", g_Settings.GetMergedLangfilesDir().c_str()); std::string strTXUpdatelangfileDir; if (pRootElement->Attribute("temptxupdate_langfiledir") && (strTXUpdatelangfileDir = pRootElement->Attribute("temptxupdate_langfiledir")) != "") { CLog::Log(logINFO, "UpdXMLHandler: Found temp tx update language file directory in xbmc-txupdate.xml file: %s", strTXUpdatelangfileDir.c_str()); g_Settings.SetTXUpdateLangfilesDir(strTXUpdatelangfileDir); } else CLog::Log(logINFO, "UpdXMLHandler: No temp tx update language file directory specified in xbmc-txupdate.xml file. Using default value: %s", g_Settings.GetTXUpdateLangfilesDir().c_str()); std::string strSupportEmailAdd; if (pRootElement->Attribute("support_email") && (strSupportEmailAdd = pRootElement->Attribute("support_email")) != "") { CLog::Log(logINFO, "UpdXMLHandler: Found support email address in xbmc-txupdate.xml file: %s", strSupportEmailAdd.c_str()); g_Settings.SetSupportEmailAdd(strSupportEmailAdd); } else CLog::Log(logINFO, "UpdXMLHandler: No support email address specified in xbmc-txupdate.xml file. Using default value: %s", g_Settings.GetSupportEmailAdd().c_str()); std::string strForcePOComm; if (pRootElement->Attribute("forcePOComm") && (strForcePOComm = pRootElement->Attribute("forcePOComm")) == "true") { CLog::Log(logINFO, "UpdXMLHandler: Forced PO file comments for non English languages.", strMergedLangfileDir.c_str()); g_Settings.SetForcePOComments(true); } const TiXmlElement *pChildResElement = pRootElement->FirstChildElement("resource"); if (!pChildResElement || pChildResElement->NoChildren()) { CLog::Log(logERROR, "UpdXMLHandler: No xml element called \"resource\" exists in the xml file. Cannot continue. Please create at least one"); return false; } std::string strType; while (pChildResElement && pChildResElement->FirstChild()) { CXMLResdata currResData; std::string strResName; if (!pChildResElement->Attribute("name") || (strResName = pChildResElement->Attribute("name")) == "") { CLog::Log(logERROR, "UpdXMLHandler: No name specified for resource. Cannot continue. Please specify it."); return false; } if (pChildResElement->FirstChild()) { const TiXmlElement *pChildURLElement = pChildResElement->FirstChildElement("upstreamURL"); if (pChildURLElement && pChildURLElement->FirstChild()) currResData.strUpstreamURL = pChildURLElement->FirstChild()->Value(); if (currResData.strUpstreamURL.empty()) CLog::Log(logERROR, "UpdXMLHandler: UpstreamURL entry is empty or missing for resource %s", strResName.c_str()); if (pChildURLElement->Attribute("filetype")) currResData.strLangFileType = pChildURLElement->Attribute("filetype"); // For PO no need to explicitly specify. Only for XML. if (pChildURLElement->Attribute("URLsuffix")) currResData.strURLSuffix = pChildURLElement->Attribute("URLsuffix"); // Some http servers need suffix strings after filename(eg. gitweb) if (pChildURLElement->Attribute("HasChangelog")) { std::string strHaschangelog = pChildURLElement->Attribute("HasChangelog"); // Note if the addon has upstream changelog currResData.bHasChangelog = strHaschangelog == "true"; } if (pChildURLElement->Attribute("LogFormat")) { std::string strLogFormat = pChildURLElement->Attribute("LogFormat"); currResData.strLogFormat = strLogFormat; } if (pChildURLElement->Attribute("LogFilename")) { std::string strLogFilename = pChildURLElement->Attribute("LogFilename"); currResData.strLogFilename = strLogFilename; } const TiXmlElement *pChildUpstrLElement = pChildResElement->FirstChildElement("upstreamLangs"); if (pChildUpstrLElement && pChildUpstrLElement->FirstChild()) currResData.strLangsFromUpstream = pChildUpstrLElement->FirstChild()->Value(); const TiXmlElement *pChildResTypeElement = pChildResElement->FirstChildElement("resourceType"); if (pChildResTypeElement->Attribute("AddonXMLSuffix")) currResData.strAddonXMLSuffix = pChildResTypeElement->Attribute("AddonXMLSuffix"); // Some addons have unique addon.xml filename eg. pvr addons with .in suffix if (pChildResTypeElement && pChildResTypeElement->FirstChild()) { strType = pChildResTypeElement->FirstChild()->Value(); if (strType == "addon") currResData.Restype = ADDON; else if (strType == "addon_nostrings") currResData.Restype = ADDON_NOSTRINGS; else if (strType == "skin") currResData.Restype = SKIN; else if (strType == "xbmc_core") currResData.Restype = CORE; } if (currResData.Restype == UNKNOWN) CLog::Log(logERROR, "UpdXMLHandler: Unknown type found or missing resourceType field for resource %s", strResName.c_str()); const TiXmlElement *pChildResDirElement = pChildResElement->FirstChildElement("resourceSubdir"); if (pChildResDirElement && pChildResDirElement->FirstChild()) currResData.strResDirectory = pChildResDirElement->FirstChild()->Value(); if (pChildResDirElement->Attribute("writePO")) { std::string strBool = pChildResDirElement->Attribute("writePO"); currResData.bWritePO = strBool == "true"; } if (pChildResDirElement->Attribute("writeXML")) { std::string strBool = pChildResDirElement->Attribute("writeXML"); currResData.bWriteXML = strBool == "true"; } if (pChildResDirElement->Attribute("DIRprefix")) currResData.strDIRprefix = pChildResDirElement->Attribute("DIRprefix"); // If there is any SUBdirectory needed in the tree const TiXmlElement *pChildTXNameElement = pChildResElement->FirstChildElement("TXname"); if (pChildTXNameElement && pChildTXNameElement->FirstChild()) currResData.strTXResName = pChildTXNameElement->FirstChild()->Value(); if (currResData.strTXResName.empty()) CLog::Log(logERROR, "UpdXMLHandler: Transifex resource name is empty or missing for resource %s", strResName.c_str()); m_mapXMLResdata[strResName] = currResData; CLog::Log(logINFO, "UpdXMLHandler: found resource in update.xml file: %s, Type: %s, SubDir: %s", strResName.c_str(), strType.c_str(), currResData.strResDirectory.c_str()); } pChildResElement = pChildResElement->NextSiblingElement("resource"); } return true; };