2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* HomebrewXML Class
|
|
|
|
* for USB Loader GX
|
|
|
|
***************************************************************************/
|
2010-10-24 21:08:03 +02:00
|
|
|
#include <gctypes.h>
|
2009-10-01 01:10:58 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2010-10-24 21:08:03 +02:00
|
|
|
#include "FileOperations/fileops.h"
|
2023-01-01 18:00:14 +01:00
|
|
|
#include "xml/pugixml.hpp"
|
2011-06-14 19:53:19 +02:00
|
|
|
#include "gecko.h"
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
#include "HomebrewXML.h"
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
#define ENTRIE_SIZE 8192
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
/* qparam filename Filepath of the XML file */
|
2023-01-01 18:00:14 +01:00
|
|
|
int HomebrewXML::LoadHomebrewXMLData(const char *filename)
|
2010-09-17 18:15:18 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
Name.clear();
|
|
|
|
Coder.clear();
|
|
|
|
Version.clear();
|
|
|
|
ShortDescription.clear();
|
|
|
|
LongDescription.clear();
|
|
|
|
Releasedate.clear();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
pugi::xml_document xmlDoc;
|
|
|
|
pugi::xml_parse_result result = xmlDoc.load_file(filename);
|
|
|
|
if (!result)
|
|
|
|
return 0;
|
2011-06-14 19:53:19 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
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");
|
2011-06-14 19:53:19 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
std::string ReleaseText = xmlDoc.child("app").child_value("release_date");
|
|
|
|
if (ReleaseText.length() >= 6)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
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;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
2010-10-24 21:08:03 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
for (pugi::xml_node arg : xmlDoc.child("app").child("arguments").children("arg"))
|
|
|
|
Arguments.push_back(arg.text().as_string());
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return 1;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
int HomebrewXML::SaveHomebrewXMLData(const char *filename)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
|
|
|
const int max_line_size = 4096;
|
2015-03-08 17:49:07 +01:00
|
|
|
char *line = new (std::nothrow) char[max_line_size];
|
2023-01-01 18:00:14 +01:00
|
|
|
if (!line)
|
|
|
|
return 0;
|
2014-05-04 16:42:52 +02:00
|
|
|
|
|
|
|
FILE *fp = fopen(filename, "wb");
|
2023-01-01 18:00:14 +01:00
|
|
|
if (!fp)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
delete[] line;
|
2014-05-04 16:42:52 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-01-01 18:00:14 +01:00
|
|
|
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);
|
2014-05-04 16:42:52 +02:00
|
|
|
if (Arguments.size() > 0)
|
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
snprintf(line, max_line_size, " <arguments>\n");
|
|
|
|
fputs(line, fp);
|
|
|
|
for (u8 i = 0; i < Arguments.size(); i++)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
2023-01-01 18:00:14 +01:00
|
|
|
snprintf(line, max_line_size, " <arg>%s</arg>\n", Arguments[i].c_str());
|
|
|
|
fputs(line, fp);
|
2014-05-04 16:42:52 +02:00
|
|
|
}
|
2023-01-01 18:00:14 +01:00
|
|
|
snprintf(line, max_line_size, " </arguments>\n");
|
|
|
|
fputs(line, fp);
|
2014-05-04 16:42:52 +02:00
|
|
|
}
|
2023-01-01 18:00:14 +01:00
|
|
|
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);
|
|
|
|
|
2014-05-04 16:42:52 +02:00
|
|
|
fclose(fp);
|
2023-01-01 18:00:14 +01:00
|
|
|
delete[] line;
|
2014-05-04 16:42:52 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set argument */
|
2023-01-01 18:00:14 +01:00
|
|
|
void HomebrewXML::SetArgument(const char *argument)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
|
|
|
// Crop value from argument, if present
|
2023-01-01 18:00:14 +01:00
|
|
|
char argName[strlen(argument) + 1];
|
2014-05-04 16:42:52 +02:00
|
|
|
strcpy(argName, argument);
|
|
|
|
char *ptr = strrchr(argName, '=');
|
2023-01-01 18:00:14 +01:00
|
|
|
if (ptr)
|
|
|
|
*(ptr + 1) = 0;
|
2014-05-04 16:42:52 +02:00
|
|
|
|
|
|
|
// Check if argument already exists and edit it
|
|
|
|
bool found = false;
|
2023-01-01 18:00:14 +01:00
|
|
|
for (u8 i = 0; i < Arguments.size(); i++)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
|
|
|
size_t pos = Arguments[i].find(argName);
|
2023-01-01 18:00:14 +01:00
|
|
|
if (pos != std::string::npos)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
|
|
|
Arguments[i] = argument;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if it doesn't exist, add the new argument.
|
2023-01-01 18:00:14 +01:00
|
|
|
if (!found)
|
2014-05-04 16:42:52 +02:00
|
|
|
Arguments.push_back(argument);
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
/* Get name */
|
2023-01-01 18:00:14 +01:00
|
|
|
const char *HomebrewXML::GetName() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
return Name.c_str();
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Name */
|
2023-01-01 18:00:14 +01:00
|
|
|
void HomebrewXML::SetName(char *newName)
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
Name = newName;
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get coder */
|
2023-01-01 18:00:14 +01:00
|
|
|
const char *HomebrewXML::GetCoder() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
return Coder.c_str();
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get version */
|
2023-01-01 18:00:14 +01:00
|
|
|
const char *HomebrewXML::GetVersion() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
return Version.c_str();
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
2014-05-04 16:42:52 +02:00
|
|
|
/* Set version */
|
2023-01-01 18:00:14 +01:00
|
|
|
void HomebrewXML::SetVersion(const char *newVer)
|
2014-05-04 16:42:52 +02:00
|
|
|
{
|
|
|
|
Version = newVer;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
/* Get releasedate */
|
2023-01-01 18:00:14 +01:00
|
|
|
const char *HomebrewXML::GetReleasedate() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
return Releasedate.c_str();
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get shortdescription */
|
2023-01-01 18:00:14 +01:00
|
|
|
const char *HomebrewXML::GetShortDescription() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
return ShortDescription.c_str();
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get longdescription */
|
2023-01-01 18:00:14 +01:00
|
|
|
const char *HomebrewXML::GetLongDescription() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
return LongDescription.c_str();
|
2010-09-24 02:48:03 +02:00
|
|
|
}
|