mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-22 03:09:15 +01:00
Change TinyXML to pugixml
Thanks to Oddx.
This commit is contained in:
parent
8ab03c4bf9
commit
fbfcba4200
@ -7,13 +7,11 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "FileOperations/fileops.h"
|
||||
#include "xml/tinyxml2.h"
|
||||
#include "xml/pugixml.hpp"
|
||||
#include "gecko.h"
|
||||
|
||||
#include "HomebrewXML.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
#define ENTRIE_SIZE 8192
|
||||
|
||||
/* qparam filename Filepath of the XML file */
|
||||
@ -26,64 +24,37 @@ int HomebrewXML::LoadHomebrewXMLData(const char* filename)
|
||||
LongDescription.clear();
|
||||
Releasedate.clear();
|
||||
|
||||
XMLDocument xmlDoc;
|
||||
if(xmlDoc.LoadFile(filename) != 0)
|
||||
return false;
|
||||
pugi::xml_document xmlDoc;
|
||||
pugi::xml_parse_result result = xmlDoc.load_file(filename);
|
||||
if (!result)
|
||||
return 0;
|
||||
|
||||
XMLElement *appNode = xmlDoc.FirstChildElement("app");
|
||||
if(!appNode)
|
||||
return false;
|
||||
Name = xmlDoc.child("app").child_value("name");
|
||||
Coder = xmlDoc.child("app").child_value("coder");
|
||||
Version = xmlDoc.child("app").child_value("version");
|
||||
ShortDescription = xmlDoc.child("app").child_value("short_description");
|
||||
LongDescription = xmlDoc.child("app").child_value("long_description");
|
||||
|
||||
XMLElement *node = NULL;
|
||||
|
||||
node = appNode->FirstChildElement("name");
|
||||
if(node && node->FirstChild() && node->FirstChild()->Value())
|
||||
Name = node->FirstChild()->Value();
|
||||
|
||||
node = appNode->FirstChildElement("coder");
|
||||
if(node && node->FirstChild() && node->FirstChild()->Value())
|
||||
Coder = node->FirstChild()->Value();
|
||||
|
||||
node = appNode->FirstChildElement("version");
|
||||
if(node && node->FirstChild() && node->FirstChild()->Value())
|
||||
Version = node->FirstChild()->Value();
|
||||
|
||||
node = appNode->FirstChildElement("short_description");
|
||||
if(node && node->FirstChild() && node->FirstChild()->Value())
|
||||
ShortDescription = node->FirstChild()->Value();
|
||||
|
||||
node = appNode->FirstChildElement("long_description");
|
||||
if(node && node->FirstChild() && node->FirstChild()->Value())
|
||||
LongDescription = node->FirstChild()->Value();
|
||||
|
||||
char ReleaseText[200];
|
||||
memset(ReleaseText, 0, sizeof(ReleaseText));
|
||||
|
||||
node = appNode->FirstChildElement("release_date");
|
||||
if(node && node->FirstChild() && node->FirstChild()->Value())
|
||||
snprintf(ReleaseText, sizeof(ReleaseText), node->FirstChild()->Value());
|
||||
|
||||
int len = (strlen(ReleaseText) - 6); //length of the date string without the 200000 at the end
|
||||
if (len == 8)
|
||||
snprintf(ReleaseText, sizeof(ReleaseText), "%c%c/%c%c/%c%c%c%c", ReleaseText[4], ReleaseText[5], ReleaseText[6], ReleaseText[7], ReleaseText[0], ReleaseText[1], ReleaseText[2], ReleaseText[3]);
|
||||
else if (len == 6)
|
||||
snprintf(ReleaseText, sizeof(ReleaseText), "%c%c/%c%c%c%c", ReleaseText[4], ReleaseText[5], ReleaseText[0], ReleaseText[1], ReleaseText[2], ReleaseText[3]);
|
||||
|
||||
Releasedate = ReleaseText;
|
||||
|
||||
node = appNode->FirstChildElement("arguments");
|
||||
if(!node)
|
||||
return 1;
|
||||
|
||||
XMLElement *argNode = node->FirstChildElement("arg");
|
||||
|
||||
while(argNode)
|
||||
std::string ReleaseText = xmlDoc.child("app").child_value("release_date");
|
||||
if (ReleaseText.length() >= 6)
|
||||
{
|
||||
if(argNode->FirstChild() && argNode->FirstChild()->Value())
|
||||
Arguments.push_back(std::string(argNode->FirstChild()->Value()));
|
||||
|
||||
argNode = argNode->NextSiblingElement();
|
||||
if (ReleaseText.find("/") == std::string::npos)
|
||||
{
|
||||
Releasedate = ReleaseText.substr(4, 2);
|
||||
if (ReleaseText.length() >= 8)
|
||||
{
|
||||
Releasedate.append("/");
|
||||
Releasedate.append(ReleaseText.substr(6, 2));
|
||||
}
|
||||
Releasedate.append("/");
|
||||
Releasedate.append(ReleaseText.substr(0, 4));
|
||||
}
|
||||
else
|
||||
Releasedate = ReleaseText;
|
||||
}
|
||||
|
||||
for (pugi::xml_node arg : xmlDoc.child("app").child("arguments").children("arg"))
|
||||
Arguments.push_back(arg.text().as_string());
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -92,7 +63,8 @@ int HomebrewXML::SaveHomebrewXMLData(const char* filename)
|
||||
{
|
||||
const int max_line_size = 4096;
|
||||
char *line = new (std::nothrow) char[max_line_size];
|
||||
if(!line) return 0;
|
||||
if (!line)
|
||||
return 0;
|
||||
|
||||
FILE *fp = fopen(filename, "wb");
|
||||
if (!fp)
|
||||
@ -101,25 +73,38 @@ int HomebrewXML::SaveHomebrewXMLData(const char* filename)
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(line, max_line_size,"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"); fputs(line, fp);
|
||||
snprintf(line, max_line_size,"<app version=\"1\">\n"); fputs(line, fp);
|
||||
snprintf(line, max_line_size," <name>%s</name>\n", GetName()); fputs(line, fp);
|
||||
snprintf(line, max_line_size," <coder>%s</coder>\n", GetCoder()); fputs(line, fp);
|
||||
snprintf(line, max_line_size," <version>%s</version>\n", GetVersion()); fputs(line, fp);
|
||||
snprintf(line, max_line_size," <release_date>%s</release_date>\n", GetReleasedate()); fputs(line, fp);
|
||||
snprintf(line, max_line_size, "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n");
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, "<app version=\"1\">\n");
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <name>%s</name>\n", GetName());
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <coder>%s</coder>\n", GetCoder());
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <version>%s</version>\n", GetVersion());
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <release_date>%s</release_date>\n", GetReleasedate());
|
||||
fputs(line, fp);
|
||||
if (Arguments.size() > 0)
|
||||
{
|
||||
snprintf(line, max_line_size," <arguments>\n"); fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <arguments>\n");
|
||||
fputs(line, fp);
|
||||
for (u8 i = 0; i < Arguments.size(); i++)
|
||||
{
|
||||
snprintf(line, max_line_size," <arg>%s</arg>\n", Arguments[i].c_str()); fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <arg>%s</arg>\n", Arguments[i].c_str());
|
||||
fputs(line, fp);
|
||||
}
|
||||
snprintf(line, max_line_size," </arguments>\n"); fputs(line, fp);
|
||||
snprintf(line, max_line_size, " </arguments>\n");
|
||||
fputs(line, fp);
|
||||
}
|
||||
snprintf(line, max_line_size," <ahb_access/>\n"); fputs(line, fp);
|
||||
snprintf(line, max_line_size," <short_description>%s</short_description>\n", GetShortDescription()); fputs(line, fp);
|
||||
snprintf(line, max_line_size," <long_description>%s</long_description>\n", GetLongDescription()); fputs(line, fp);
|
||||
snprintf(line, max_line_size,"</app>\n"); fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <ahb_access/>\n");
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <short_description>%s</short_description>\n", GetShortDescription());
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, " <long_description>%s</long_description>\n", GetLongDescription());
|
||||
fputs(line, fp);
|
||||
snprintf(line, max_line_size, "</app>\n");
|
||||
fputs(line, fp);
|
||||
|
||||
fclose(fp);
|
||||
delete[] line;
|
||||
@ -133,7 +118,8 @@ void HomebrewXML::SetArgument(const char* argument)
|
||||
char argName[strlen(argument) + 1];
|
||||
strcpy(argName, argument);
|
||||
char *ptr = strrchr(argName, '=');
|
||||
if(ptr) *(ptr+1) = 0;
|
||||
if (ptr)
|
||||
*(ptr + 1) = 0;
|
||||
|
||||
// Check if argument already exists and edit it
|
||||
bool found = false;
|
||||
|
@ -27,11 +27,9 @@
|
||||
#include "network/networkops.h"
|
||||
#include "network/https.h"
|
||||
#include "utils/StringTools.h"
|
||||
#include "xml/tinyxml2.h"
|
||||
#include "xml/pugixml.hpp"
|
||||
#include "gecko.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
Wiinnertag::Wiinnertag(const std::string &filepath)
|
||||
{
|
||||
ReadXML(filepath);
|
||||
@ -39,16 +37,17 @@ Wiinnertag::Wiinnertag(const std::string &filepath)
|
||||
|
||||
bool Wiinnertag::ReadXML(const std::string &filepath)
|
||||
{
|
||||
XMLDocument xmlDoc;
|
||||
if(xmlDoc.LoadFile(filepath.c_str()) != 0)
|
||||
pugi::xml_document xmlDoc;
|
||||
pugi::xml_parse_result result = xmlDoc.load_file(filepath.c_str());
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
XMLElement * node = xmlDoc.FirstChildElement("Tag");
|
||||
pugi::xml_node node = xmlDoc.child("Tag");
|
||||
|
||||
while (node != NULL)
|
||||
{
|
||||
const char * URL = node->Attribute("URL");
|
||||
const char * Key = node->Attribute("Key");
|
||||
const char *URL = node.attribute("URL").value();
|
||||
const char *Key = node.attribute("Key").value();
|
||||
|
||||
if (URL && Key)
|
||||
{
|
||||
@ -58,7 +57,7 @@ bool Wiinnertag::ReadXML(const std::string &filepath)
|
||||
tagList[size].second = Key;
|
||||
}
|
||||
|
||||
node = node->NextSiblingElement();
|
||||
node = node.next_sibling();
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -88,11 +87,11 @@ bool Wiinnertag::Send(const char *gameID)
|
||||
|
||||
bool Wiinnertag::TagGame(const char *gameID)
|
||||
{
|
||||
std::string fullpath = Settings.WiinnertagPath;
|
||||
if(fullpath.size() == 0)
|
||||
std::string fullpath(Settings.WiinnertagPath);
|
||||
if (fullpath.length() == 0)
|
||||
return false;
|
||||
|
||||
if(fullpath[fullpath.size()-1] != '/')
|
||||
if (fullpath.back() != '/')
|
||||
fullpath += '/';
|
||||
fullpath += "Wiinnertag.xml";
|
||||
|
||||
@ -102,27 +101,26 @@ bool Wiinnertag::TagGame(const char *gameID)
|
||||
|
||||
bool Wiinnertag::CreateExample(const std::string &filepath)
|
||||
{
|
||||
if(filepath.size() == 0)
|
||||
if (filepath.length() == 0)
|
||||
return false;
|
||||
|
||||
CreateSubfolder(filepath.c_str());
|
||||
|
||||
std::string fullpath = filepath;
|
||||
if(fullpath[fullpath.size()-1] != '/')
|
||||
if (fullpath.back() != '/')
|
||||
fullpath += '/';
|
||||
fullpath += "Wiinnertag.xml";
|
||||
|
||||
XMLDocument xmlDoc;
|
||||
pugi::xml_document xmlDoc;
|
||||
pugi::xml_node declaration = xmlDoc.append_child(pugi::node_declaration);
|
||||
declaration.append_attribute("version") = "1.0";
|
||||
declaration.append_attribute("encoding") = "UTF-8";
|
||||
|
||||
XMLDeclaration * declaration = xmlDoc.NewDeclaration();
|
||||
xmlDoc.InsertEndChild(declaration);
|
||||
pugi::xml_node Tag = xmlDoc.append_child("Tag");
|
||||
Tag.append_attribute("URL") = "https://tag.rc24.xyz/wii?game={ID6}&key={KEY}";
|
||||
Tag.append_attribute("Key") = "1234567890";
|
||||
|
||||
XMLElement *Tag = xmlDoc.NewElement("Tag");
|
||||
Tag->SetAttribute("URL", "https://tag.rc24.xyz/wii?game={ID6}&key={KEY}");
|
||||
Tag->SetAttribute("Key", "1234567890");
|
||||
xmlDoc.InsertEndChild(Tag);
|
||||
|
||||
xmlDoc.SaveFile(fullpath.c_str());
|
||||
xmlDoc.save_file(fullpath.c_str());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -90,18 +90,18 @@ static bool CheckNewGameTDBVersion(const char *url)
|
||||
if (file.gametdbcheck <= 0)
|
||||
return false;
|
||||
|
||||
std::string Title;
|
||||
std::string Filepath = Settings.titlestxt_path;
|
||||
if (Settings.titlestxt_path[Filepath.size() - 1] != '/')
|
||||
std::string Filepath(Settings.titlestxt_path);
|
||||
if (Filepath.back() != '/')
|
||||
Filepath += '/';
|
||||
Filepath += "wiitdb.xml";
|
||||
|
||||
GameTDB XML_DB;
|
||||
|
||||
if (!XML_DB.OpenFile((Filepath.c_str())))
|
||||
if (!XML_DB.OpenFile(Filepath.c_str()))
|
||||
return true; //! If no file exists we need the file
|
||||
|
||||
u64 ExistingVersion = XML_DB.GetGameTDBVersion();
|
||||
XML_DB.CloseFile();
|
||||
|
||||
gprintf("Existing GameTDB Version: %llu Online GameTDB Version: %llu\n", ExistingVersion, file.gametdbcheck);
|
||||
|
||||
@ -118,10 +118,9 @@ int UpdateGameTDB()
|
||||
|
||||
gprintf("Updating GameTDB...\n");
|
||||
|
||||
std::string ZipPath = Settings.titlestxt_path;
|
||||
if (Settings.titlestxt_path[ZipPath.size() - 1] != '/')
|
||||
std::string ZipPath(Settings.titlestxt_path);
|
||||
if (ZipPath.back() != '/')
|
||||
ZipPath += '/';
|
||||
|
||||
ZipPath += "wiitdb.zip";
|
||||
|
||||
int filesize = DownloadFileToPath(Settings.URL_GameTDB, ZipPath.c_str());
|
||||
|
@ -94,6 +94,7 @@ static int InternalShowGameInfo(struct discHdr *header)
|
||||
|
||||
if(!XML_DB.GetGameXMLInfo(ID, &GameInfo))
|
||||
{
|
||||
XML_DB.CloseFile();
|
||||
ShowError(tr("Could not find info for this game in the wiitdb.xml."));
|
||||
return -1;
|
||||
}
|
||||
@ -255,26 +256,26 @@ static int InternalShowGameInfo(struct discHdr *header)
|
||||
char linebuf2[100] = "";
|
||||
|
||||
// enable icons for required accessories
|
||||
for (u32 i = 0; i < GameInfo.AccessoirList.size(); ++i)
|
||||
for (u32 i = 0; i < GameInfo.AccessoryList.size(); ++i)
|
||||
{
|
||||
if(!GameInfo.AccessoirList[i].Required)
|
||||
if(!GameInfo.AccessoryList[i].Required)
|
||||
continue;
|
||||
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "guitar") == 0) guitar = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "drums") == 0) drums = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "dancepad") == 0) dancepad = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "motionplus") == 0) motionplus = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wheel") == 0) wheel = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "microphone") == 0) microphone = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "zapper") == 0) zapper = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nintendods") == 0) nintendods = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1;
|
||||
//if (strcmp(GameInfo.AccessoirList[i].Name.c_str(),"vitalitysensor")==0)
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "guitar") == 0) guitar = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "drums") == 0) drums = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "dancepad") == 0) dancepad = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "motionplus") == 0) motionplus = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "wheel") == 0) wheel = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "microphone") == 0) microphone = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "zapper") == 0) zapper = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "nintendods") == 0) nintendods = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1;
|
||||
//if (strcmp(GameInfo.AccessoryList[i].Name.c_str(),"vitalitysensor")==0)
|
||||
// vitalitysensor=1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "gamecube") == 0) gamecube = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "gamecube") == 0) gamecube = 1;
|
||||
}
|
||||
|
||||
// switch icons
|
||||
@ -331,26 +332,26 @@ static int InternalShowGameInfo(struct discHdr *header)
|
||||
else dancepadImgData = Resources::GetImageData("dancepad.png");
|
||||
|
||||
// look for optional accessories
|
||||
for (u32 i = 0; i < GameInfo.AccessoirList.size(); ++i)
|
||||
for (u32 i = 0; i < GameInfo.AccessoryList.size(); ++i)
|
||||
{
|
||||
if(GameInfo.AccessoirList[i].Required)
|
||||
if(GameInfo.AccessoryList[i].Required)
|
||||
continue;
|
||||
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "guitar") == 0) guitar = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "drums") == 0) drums = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "dancepad") == 0) dancepad = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "motionplus") == 0) motionplus = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wheel") == 0) wheel = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "microphone") == 0) microphone = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "zapper") == 0) zapper = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "nintendods") == 0) nintendods = 1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1;
|
||||
//if (strcmp(GameInfo.AccessoirList[i].Name.c_str(),"vitalitysensor")==0)
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "classiccontroller") == 0) classiccontroller = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "nunchuk") == 0) nunchuk = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "guitar") == 0) guitar = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "drums") == 0) drums = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "dancepad") == 0) dancepad = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "motionplus") == 0) motionplus = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "wheel") == 0) wheel = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "balanceboard") == 0) balanceboard = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "microphone") == 0) microphone = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "zapper") == 0) zapper = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "nintendods") == 0) nintendods = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "wiispeak") == 0) wiispeak = 1;
|
||||
//if (strcmp(GameInfo.AccessoryList[i].Name.c_str(),"vitalitysensor")==0)
|
||||
// vitalitysensor=1;
|
||||
if (strcmp(GameInfo.AccessoirList[i].Name.c_str(), "gamecube") == 0) gamecube = 1;
|
||||
if (strcmp(GameInfo.AccessoryList[i].Name.c_str(), "gamecube") == 0) gamecube = 1;
|
||||
}
|
||||
|
||||
dialogBoxImg1 = new GuiImage(&dialogBox1);
|
||||
|
@ -35,8 +35,6 @@
|
||||
#include "utils/StringTools.h"
|
||||
#include "svnrev.h"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
#define VALID_CONFIG_REV 1084
|
||||
|
||||
CGameCategories GameCategories;
|
||||
@ -48,7 +46,8 @@ CGameCategories::CGameCategories()
|
||||
|
||||
const std::vector<unsigned int> &CGameCategories::operator[](const char *id) const
|
||||
{
|
||||
if(!id) return defaultCategory;
|
||||
if (!id)
|
||||
return defaultCategory;
|
||||
|
||||
for (std::map<std::string, std::vector<unsigned int>>::const_iterator itr = List.begin(); itr != List.end(); itr++)
|
||||
{
|
||||
@ -61,63 +60,55 @@ const std::vector<unsigned int> &CGameCategories::operator[](const char *id) con
|
||||
|
||||
bool CGameCategories::Load(std::string filepath)
|
||||
{
|
||||
if(filepath.size() == 0)
|
||||
if (filepath.length() == 0)
|
||||
return false;
|
||||
|
||||
if(filepath[filepath.size()-1] != '/')
|
||||
if (filepath.back() != '/')
|
||||
filepath += '/';
|
||||
|
||||
filepath += "GXGameCategories.xml";
|
||||
configPath = filepath;
|
||||
|
||||
clear();
|
||||
|
||||
XMLDocument xmlDoc;
|
||||
if(xmlDoc.LoadFile(filepath.c_str()) != 0)
|
||||
pugi::xml_document xmlDoc;
|
||||
pugi::xml_parse_result result = xmlDoc.load_file(filepath.c_str());
|
||||
if (!result)
|
||||
return false;
|
||||
|
||||
if(!ValidVersion(xmlDoc.FirstChildElement("Revision")))
|
||||
pugi::xml_node root = xmlDoc.child("USBLoaderGX");
|
||||
if (!root)
|
||||
root = xmlDoc;
|
||||
|
||||
if (!ValidVersion(root.child("Revision")))
|
||||
return false;
|
||||
|
||||
XMLElement * node = xmlDoc.FirstChildElement("Categories");
|
||||
if(!node)
|
||||
pugi::xml_node categories = root.child("Categories");
|
||||
if (!categories)
|
||||
return false;
|
||||
|
||||
node = node->FirstChildElement("Category");
|
||||
|
||||
while(node != NULL)
|
||||
for (pugi::xml_node category : categories.children("Category"))
|
||||
{
|
||||
const char * ID = node->Attribute("ID");
|
||||
const char * Name = node->Attribute("Name");
|
||||
const char *ID = category.attribute("ID").value();
|
||||
const char *Name = category.attribute("Name").value();
|
||||
|
||||
if (ID && Name)
|
||||
CategoryList.SetCategory(atoi(ID), Name);
|
||||
|
||||
node = node->NextSiblingElement();
|
||||
}
|
||||
|
||||
node = xmlDoc.FirstChildElement("GameCategories");
|
||||
if(!node)
|
||||
pugi::xml_node gamecategories = root.child("GameCategories");
|
||||
if (!gamecategories)
|
||||
return false;
|
||||
|
||||
node = node->FirstChildElement("Game");
|
||||
|
||||
while(node != NULL)
|
||||
for (pugi::xml_node game : gamecategories.children("Game"))
|
||||
{
|
||||
const char * gameID = node->Attribute("ID");
|
||||
const char *gameID = game.attribute("ID").value();
|
||||
|
||||
XMLElement * category = node->FirstChildElement("Category");
|
||||
|
||||
while(category != NULL)
|
||||
for (pugi::xml_node category : game.children("Category"))
|
||||
{
|
||||
const char * categoryID = category->Attribute("ID");
|
||||
const char *categoryID = category.attribute("ID").value();
|
||||
if (gameID && categoryID)
|
||||
SetCategory(gameID, atoi(categoryID));
|
||||
|
||||
category = category->NextSiblingElement();
|
||||
}
|
||||
|
||||
node = node->NextSiblingElement();
|
||||
}
|
||||
|
||||
CategoryList.goToFirst();
|
||||
@ -137,55 +128,44 @@ bool CGameCategories::Save()
|
||||
CreateSubfolder(filepath);
|
||||
|
||||
StartProgress(tr("Generating GXGameCategories.xml"), tr("Please wait..."), 0, false, true);
|
||||
XMLDocument xmlDoc;
|
||||
|
||||
XMLDeclaration *declaration = xmlDoc.NewDeclaration();
|
||||
xmlDoc.InsertEndChild(declaration);
|
||||
XMLElement *Revision = xmlDoc.NewElement("Revision");
|
||||
XMLText *revText = xmlDoc.NewText(GetRev());
|
||||
Revision->InsertEndChild(revText);
|
||||
xmlDoc.InsertEndChild(Revision);
|
||||
pugi::xml_document xmlDoc;
|
||||
pugi::xml_node declaration = xmlDoc.append_child(pugi::node_declaration);
|
||||
declaration.append_attribute("version") = "1.0";
|
||||
declaration.append_attribute("encoding") = "UTF-8";
|
||||
|
||||
pugi::xml_node root = xmlDoc.append_child("USBLoaderGX");
|
||||
pugi::xml_node revision = root.append_child("Revision");
|
||||
revision.append_child(pugi::node_pcdata).set_value(GetRev());
|
||||
|
||||
int progressSize = CategoryList.size() + List.size();
|
||||
int progress = 0;
|
||||
|
||||
//! Add all categories as an ID map
|
||||
{
|
||||
//! On LinkEndChild TinyXML owns and deletes the elements allocated here.
|
||||
//! This is more memory efficient than making another copy of the elements.
|
||||
XMLElement *Categories = xmlDoc.NewElement("Categories");
|
||||
pugi::xml_node categories = root.append_child("Categories");
|
||||
|
||||
CategoryList.goToFirst();
|
||||
do
|
||||
{
|
||||
ShowProgress(progress, progressSize);
|
||||
|
||||
XMLElement *Category = xmlDoc.NewElement("Category");
|
||||
Category->SetAttribute("ID", fmt("%02i", CategoryList.getCurrentID()));
|
||||
Category->SetAttribute("Name", CategoryList.getCurrentName().c_str());
|
||||
|
||||
Categories->LinkEndChild(Category);
|
||||
pugi::xml_node category = categories.append_child("Category");
|
||||
category.append_attribute("ID") = fmt("%02i", CategoryList.getCurrentID());
|
||||
category.append_attribute("Name") = CategoryList.getCurrentName().c_str();
|
||||
|
||||
++progress;
|
||||
}
|
||||
while(CategoryList.goToNext());
|
||||
|
||||
xmlDoc.LinkEndChild(Categories);
|
||||
}
|
||||
} while (CategoryList.goToNext());
|
||||
|
||||
//! Add game specific categories now
|
||||
{
|
||||
//! On LinkEndChild TinyXML owns and deletes the elements allocated here.
|
||||
//! This is more memory efficient than making another copy of the elements.
|
||||
XMLElement *GameCategories = xmlDoc.NewElement("GameCategories");
|
||||
pugi::xml_node gamecategories = root.append_child("GameCategories");
|
||||
|
||||
for (std::map<std::string, std::vector<unsigned int>>::iterator itr = List.begin(); itr != List.end(); itr++)
|
||||
{
|
||||
ShowProgress(progress, progressSize);
|
||||
|
||||
XMLElement *Game = xmlDoc.NewElement("Game");
|
||||
Game->SetAttribute("ID", itr->first.c_str());
|
||||
Game->SetAttribute("Title", GameTitles.GetTitle(itr->first.c_str()));
|
||||
pugi::xml_node game = gamecategories.append_child("Game");
|
||||
game.append_attribute("ID") = itr->first.c_str();
|
||||
game.append_attribute("Title") = GameTitles.GetTitle(itr->first.c_str());
|
||||
|
||||
for (u32 i = 0; i < itr->second.size(); ++i)
|
||||
{
|
||||
@ -193,41 +173,35 @@ bool CGameCategories::Save()
|
||||
if (!CatName)
|
||||
CatName = "";
|
||||
|
||||
XMLElement *Category = xmlDoc.NewElement("Category");
|
||||
Category->SetAttribute("ID", fmt("%02i", itr->second[i]));
|
||||
Category->SetAttribute("Name", CatName);
|
||||
|
||||
Game->LinkEndChild(Category);
|
||||
pugi::xml_node category = game.append_child("Category");
|
||||
category.append_attribute("ID") = fmt("%02i", itr->second[i]);
|
||||
category.append_attribute("Name") = CatName;
|
||||
}
|
||||
|
||||
GameCategories->LinkEndChild(Game);
|
||||
++progress;
|
||||
}
|
||||
|
||||
xmlDoc.LinkEndChild(GameCategories);
|
||||
}
|
||||
|
||||
ShowProgress(tr("Writing GXGameCategories.xml"), tr("Please wait..."), 0, progressSize, progressSize, false, true);
|
||||
|
||||
xmlDoc.SaveFile(configPath.c_str());
|
||||
xmlDoc.save_file(configPath.c_str());
|
||||
ProgressStop();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CGameCategories::ValidVersion(XMLElement *revisionNode)
|
||||
bool CGameCategories::ValidVersion(pugi::xml_node revisionNode)
|
||||
{
|
||||
if(!revisionNode) return false;
|
||||
|
||||
if(!revisionNode->FirstChild() || !revisionNode->FirstChild()->Value())
|
||||
if (!revisionNode)
|
||||
return false;
|
||||
|
||||
return atoi(revisionNode->FirstChild()->Value()) >= VALID_CONFIG_REV;
|
||||
if (!revisionNode.first_child() || !revisionNode.first_child().value())
|
||||
return false;
|
||||
|
||||
return atoi(revisionNode.first_child().value()) >= VALID_CONFIG_REV;
|
||||
}
|
||||
|
||||
bool CGameCategories::SetCategory(const char *gameID, unsigned int id)
|
||||
{
|
||||
if(!gameID) return false;
|
||||
if (!gameID)
|
||||
return false;
|
||||
|
||||
char gameID6[7];
|
||||
snprintf(gameID6, sizeof(gameID6), gameID);
|
||||
@ -256,7 +230,8 @@ bool CGameCategories::SetCategory(const std::string &gameID, unsigned int id)
|
||||
|
||||
bool CGameCategories::ReplaceCategory(const char *gameID, unsigned int id)
|
||||
{
|
||||
if(!gameID) return false;
|
||||
if (!gameID)
|
||||
return false;
|
||||
|
||||
char gameID6[7];
|
||||
snprintf(gameID6, sizeof(gameID6), gameID);
|
||||
@ -266,7 +241,6 @@ bool CGameCategories::ReplaceCategory(const char *gameID, unsigned int id)
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool CGameCategories::ReplaceCategory(const std::string &gameID, unsigned int id)
|
||||
{
|
||||
List[gameID] = defaultCategory;
|
||||
@ -294,15 +268,14 @@ void CGameCategories::RemoveGameCategories(const std::string &gameID)
|
||||
for (std::map<std::string, std::vector<unsigned int>>::iterator itr = List.begin(); itr != List.end(); itr++)
|
||||
{
|
||||
if (gameID == itr->first)
|
||||
{
|
||||
List.erase(itr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGameCategories::RemoveCategory(const char *gameID, unsigned int id)
|
||||
{
|
||||
if(!gameID) return;
|
||||
if (!gameID)
|
||||
return;
|
||||
|
||||
std::string gameID6;
|
||||
for (int i = 0; i < 6 && gameID[i] != 0; ++i)
|
||||
@ -335,7 +308,8 @@ bool CGameCategories::isInCategory(const char *gameID, unsigned int id)
|
||||
if (id == 0) //! ID = 0 means category 'All' so it is always true
|
||||
return true;
|
||||
|
||||
if(!gameID) return false;
|
||||
if (!gameID)
|
||||
return false;
|
||||
|
||||
std::string gameID6;
|
||||
for (int i = 0; i < 6 && gameID[i] != 0; ++i)
|
||||
@ -367,25 +341,27 @@ bool CGameCategories::ImportFromGameTDB(const std::string &xmlpath)
|
||||
StartProgress(tr("Importing categories"), tr("Please wait..."), 0, false, true);
|
||||
|
||||
XML_DB.SetLanguageCode(Settings.db_language);
|
||||
wString filter(gameList.GetCurrentFilter());
|
||||
gameList.LoadUnfiltered();
|
||||
|
||||
for(int i = 0; i < gameList.size(); ++i)
|
||||
std::vector<struct discHdr *> headerlist;
|
||||
if (!gameList.GetGameListHeaders(headerlist, MODE_ALL))
|
||||
return false;
|
||||
|
||||
for (u32 i = 0; i < headerlist.size(); ++i)
|
||||
{
|
||||
ShowProgress(i, gameList.size());
|
||||
ShowProgress(i, headerlist.size());
|
||||
|
||||
std::vector<std::string> genreList;
|
||||
std::string GameType;
|
||||
|
||||
if(XML_DB.GetGameType((const char *) gameList[i]->id, GameType))
|
||||
if (XML_DB.GetGameType((const char *)headerlist[i]->id, GameType))
|
||||
{
|
||||
if (!CategoryList.findCategory(GameType))
|
||||
CategoryList.AddCategory(GameType);
|
||||
|
||||
this->SetCategory(gameList[i]->id, CategoryList.getCurrentID());
|
||||
this->SetCategory(headerlist[i]->id, CategoryList.getCurrentID());
|
||||
}
|
||||
|
||||
if(!XML_DB.GetGenreList((const char *) gameList[i]->id, genreList))
|
||||
if (!XML_DB.GetGenreList((const char *)headerlist[i]->id, genreList))
|
||||
continue;
|
||||
|
||||
for (u32 n = 0; n < genreList.size(); ++n)
|
||||
@ -393,13 +369,11 @@ bool CGameCategories::ImportFromGameTDB(const std::string &xmlpath)
|
||||
if (!CategoryList.findCategory(genreList[n]))
|
||||
CategoryList.AddCategory(genreList[n]);
|
||||
|
||||
this->SetCategory(gameList[i]->id, CategoryList.getCurrentID());
|
||||
this->SetCategory(headerlist[i]->id, CategoryList.getCurrentID());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
XML_DB.CloseFile();
|
||||
gameList.FilterList(filter.c_str());
|
||||
|
||||
ProgressStop();
|
||||
|
||||
|
@ -28,11 +28,9 @@
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "xml/tinyxml2.h"
|
||||
#include "xml/pugixml.hpp"
|
||||
#include "CCategoryList.hpp"
|
||||
|
||||
using namespace tinyxml2;
|
||||
|
||||
class CGameCategories
|
||||
{
|
||||
public:
|
||||
@ -58,7 +56,7 @@ class CGameCategories
|
||||
|
||||
CCategoryList CategoryList;
|
||||
protected:
|
||||
bool ValidVersion(XMLElement *xmlfile);
|
||||
bool ValidVersion(pugi::xml_node xmlfile);
|
||||
|
||||
std::string configPath;
|
||||
const std::vector<unsigned int> defaultCategory;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -26,12 +26,13 @@
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "pugixml.hpp"
|
||||
|
||||
typedef struct _Accessoir
|
||||
typedef struct _Accessory
|
||||
{
|
||||
std::string Name;
|
||||
bool Required;
|
||||
} Accessoir;
|
||||
} Accessory;
|
||||
|
||||
typedef struct _GameXMLInfo
|
||||
{
|
||||
@ -49,7 +50,7 @@ typedef struct _GameXMLInfo
|
||||
int WifiPlayers;
|
||||
std::vector<std::string> WifiFeatureList;
|
||||
int Players;
|
||||
std::vector<Accessoir> AccessoirList;
|
||||
std::vector<Accessory> AccessoryList;
|
||||
long CaseColor;
|
||||
|
||||
} GameXMLInfo;
|
||||
@ -86,6 +87,8 @@ class GameTDB
|
||||
bool GetSynopsis(const char *id, std::string &synopsis);
|
||||
//! Get the region of a game for a specific game id
|
||||
bool GetRegion(const char *id, std::string ®ion);
|
||||
//! Get the languages of a game for a specific game id
|
||||
bool GetLanguages(const char *id, std::string &languages);
|
||||
//! Get the developer of a game for a specific game id
|
||||
bool GetDeveloper(const char *id, std::string &dev);
|
||||
//! Get the publisher of a game for a specific game id
|
||||
@ -113,9 +116,9 @@ class GameTDB
|
||||
//! Get the player count for a specific game id
|
||||
//! Returns the amount of players or -1 if failed
|
||||
int GetPlayers(const char *id);
|
||||
//! Returns the amount of accessoirs found or -1 if failed
|
||||
//! Get the accessoir (inputs) list inside a std::vector for a specific game id
|
||||
int GetAccessoirList(const char * id, std::vector<Accessoir> & acc_list);
|
||||
//! Returns the amount of accessories found or -1 if failed
|
||||
//! Get the accessory (inputs) list inside a std::vector for a specific game id
|
||||
int GetAccessoryList(const char *id, std::vector<Accessory> &acc_list);
|
||||
//! Get the box (case) color for a specific game id
|
||||
//! Returns the color in RGB (first 3 bytes)
|
||||
int GetCaseColor(const char *id);
|
||||
@ -126,7 +129,7 @@ class GameTDB
|
||||
//! Translate genre list to configure language code
|
||||
void TranslateGenres(std::vector<std::string> &GenreList);
|
||||
//! Translate descriptors list to configure language code
|
||||
void TranslateDescriptors(std::vector<std::string> &DescList);
|
||||
//! void TranslateDescriptors(std::vector<std::string> &DescList);
|
||||
//! Convert a specific game rating to a std::string
|
||||
static const char *RatingToString(int rating);
|
||||
//! Convert a rating std::string to a rating number
|
||||
@ -137,22 +140,21 @@ class GameTDB
|
||||
unsigned long long GetGameTDBVersion();
|
||||
//! Get the entry count in the xml database
|
||||
inline size_t GetEntryCount() { return OffsetMap.size(); };
|
||||
|
||||
private:
|
||||
bool ParseFile();
|
||||
bool LoadGameOffsets(const char *path);
|
||||
bool SaveGameOffsets(const char *path);
|
||||
bool ParseGameNode(const char *id);
|
||||
inline int GetData(char *data, int offset, int size);
|
||||
inline char *LoadGameNode(const char *id);
|
||||
inline char * GetGameNode(const char * id);
|
||||
inline GameOffsets *GetGameOffset(const char *id);
|
||||
inline char * SeekLang(char * text, const char * langcode);
|
||||
inline char * GetNodeText(char * data, const char * nodestart, const char * nodeend);
|
||||
|
||||
std::vector<GameOffsets> OffsetMap;
|
||||
FILE *file;
|
||||
std::string LangCode;
|
||||
char * GameNodeCache;
|
||||
char GameIDCache[7];
|
||||
pugi::xml_document xmlDoc;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
77
source/xml/pugiconfig.hpp
Normal file
77
source/xml/pugiconfig.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* pugixml parser - version 1.13
|
||||
* --------------------------------------------------------
|
||||
* Copyright (C) 2006-2022, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
|
||||
* Report bugs and download new versions at https://pugixml.org/
|
||||
*
|
||||
* This library is distributed under the MIT License. See notice at the end
|
||||
* of this file.
|
||||
*
|
||||
* This work is based on the pugxml parser, which is:
|
||||
* Copyright (C) 2003, by Kristen Wegner (kristen@tima.net)
|
||||
*/
|
||||
|
||||
#ifndef HEADER_PUGICONFIG_HPP
|
||||
#define HEADER_PUGICONFIG_HPP
|
||||
|
||||
// Uncomment this to enable wchar_t mode
|
||||
// #define PUGIXML_WCHAR_MODE
|
||||
|
||||
// Uncomment this to enable compact mode
|
||||
// #define PUGIXML_COMPACT
|
||||
|
||||
// Uncomment this to disable XPath
|
||||
// #define PUGIXML_NO_XPATH
|
||||
|
||||
// Uncomment this to disable STL
|
||||
// #define PUGIXML_NO_STL
|
||||
|
||||
// Uncomment this to disable exceptions
|
||||
// #define PUGIXML_NO_EXCEPTIONS
|
||||
|
||||
// Set this to control attributes for public classes/functions, i.e.:
|
||||
// #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL
|
||||
// #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL
|
||||
// #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall
|
||||
// In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead
|
||||
|
||||
// Tune these constants to adjust memory-related behavior
|
||||
// #define PUGIXML_MEMORY_PAGE_SIZE 32768
|
||||
// #define PUGIXML_MEMORY_OUTPUT_STACK 10240
|
||||
// #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096
|
||||
|
||||
// Tune this constant to adjust max nesting for XPath queries
|
||||
// #define PUGIXML_XPATH_DEPTH_LIMIT 1024
|
||||
|
||||
// Uncomment this to switch to header-only version
|
||||
// #define PUGIXML_HEADER_ONLY
|
||||
|
||||
// Uncomment this to enable long long support
|
||||
// #define PUGIXML_HAS_LONG_LONG
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Copyright (c) 2006-2022 Arseny Kapoulkine
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person
|
||||
* obtaining a copy of this software and associated documentation
|
||||
* files (the "Software"), to deal in the Software without
|
||||
* restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following
|
||||
* conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
* OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
13158
source/xml/pugixml.cpp
Normal file
13158
source/xml/pugixml.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1506
source/xml/pugixml.hpp
Normal file
1506
source/xml/pugixml.hpp
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user