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"
|
2009-10-01 01:10:58 +02:00
|
|
|
#include "xml/xml.h"
|
|
|
|
|
|
|
|
#include "HomebrewXML.h"
|
|
|
|
|
2010-09-17 18:15:18 +02: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 */
|
|
|
|
int HomebrewXML::LoadHomebrewXMLData(const char* filename)
|
2010-09-17 18:15:18 +02:00
|
|
|
{
|
2010-10-24 21:08:03 +02:00
|
|
|
Name.clear();
|
|
|
|
Coder.clear();
|
|
|
|
Version.clear();
|
|
|
|
ShortDescription.clear();
|
|
|
|
LongDescription.clear();
|
|
|
|
Releasedate.clear();
|
2009-10-01 01:10:58 +02:00
|
|
|
|
|
|
|
/* Load XML file */
|
2010-10-24 21:08:03 +02:00
|
|
|
u8 * xmlbuffer = NULL;
|
|
|
|
u64 size = 0;
|
|
|
|
LoadFileToMem(filename, &xmlbuffer, &size);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
if(!xmlbuffer)
|
|
|
|
return -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
mxml_node_t * nodetree = mxmlLoadString(NULL, (const char *) xmlbuffer, MXML_OPAQUE_CALLBACK);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
if (!nodetree)
|
|
|
|
return -2;
|
|
|
|
|
|
|
|
mxml_node_t * node = mxmlFindElement(nodetree, nodetree, "app", NULL, NULL, MXML_DESCEND_FIRST);
|
|
|
|
if (!node)
|
|
|
|
return -5;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-17 18:15:18 +02:00
|
|
|
char * Entrie = new char[ENTRIE_SIZE];
|
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
Entrie[0] = '\0';
|
|
|
|
GetTextFromNode(node, nodetree, (char*) "name", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
Name = Entrie;
|
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
Entrie[0] = '\0';
|
|
|
|
GetTextFromNode(node, nodetree, (char*) "coder", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
Coder = Entrie;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
Entrie[0] = '\0';
|
|
|
|
GetTextFromNode(node, nodetree, (char*) "version", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
Version = Entrie;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
Entrie[0] = '\0';
|
|
|
|
GetTextFromNode(node, nodetree, (char*) "short_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
ShortDescription = Entrie;
|
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
Entrie[0] = '\0';
|
|
|
|
GetTextFromNode(node, nodetree, (char*) "long_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
LongDescription = Entrie;
|
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
Entrie[0] = '\0';
|
|
|
|
GetTextFromNode(node, nodetree, (char*) "release_date", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
int len = (strlen(Entrie) - 6); //length of the date string without the 200000 at the end
|
|
|
|
if (len == 8)
|
|
|
|
snprintf(Entrie, ENTRIE_SIZE, "%c%c/%c%c/%c%c%c%c", Entrie[4], Entrie[5], Entrie[6], Entrie[7], Entrie[0],
|
|
|
|
Entrie[1], Entrie[2], Entrie[3]);
|
|
|
|
else if (len == 6)
|
|
|
|
snprintf(Entrie, ENTRIE_SIZE, "%c%c/%c%c%c%c", Entrie[4], Entrie[5], Entrie[0], Entrie[1], Entrie[2], Entrie[3]);
|
|
|
|
else snprintf(Entrie, ENTRIE_SIZE, "%s", Entrie);
|
2010-09-17 18:15:18 +02:00
|
|
|
|
|
|
|
Releasedate = Entrie;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
delete[] Entrie;
|
2010-09-17 18:15:18 +02:00
|
|
|
|
2010-10-24 21:08:03 +02:00
|
|
|
mxmlDelete(node);
|
|
|
|
mxmlDelete(nodetree);
|
|
|
|
free(xmlbuffer);
|
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
|
|
|
/* Get name */
|
2010-10-24 21:08:03 +02:00
|
|
|
const char * HomebrewXML::GetName() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
|
|
|
return Name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Name */
|
|
|
|
void HomebrewXML::SetName(char * newName)
|
|
|
|
{
|
|
|
|
Name = newName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get coder */
|
2010-10-24 21:08:03 +02:00
|
|
|
const char * HomebrewXML::GetCoder() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
|
|
|
return Coder.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get version */
|
2010-10-24 21:08:03 +02:00
|
|
|
const char * HomebrewXML::GetVersion() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
|
|
|
return Version.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get releasedate */
|
2010-10-24 21:08:03 +02:00
|
|
|
const char * HomebrewXML::GetReleasedate() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
|
|
|
return Releasedate.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get shortdescription */
|
2010-10-24 21:08:03 +02:00
|
|
|
const char * HomebrewXML::GetShortDescription() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
|
|
|
return ShortDescription.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get longdescription */
|
2010-10-24 21:08:03 +02:00
|
|
|
const char * HomebrewXML::GetLongDescription() const
|
2010-09-24 02:48:03 +02:00
|
|
|
{
|
|
|
|
return LongDescription.c_str();
|
|
|
|
}
|