2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* HomebrewXML Class
|
|
|
|
* for USB Loader GX
|
|
|
|
***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#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
|
|
|
/* Initializes a new instance of the HomebrewXML class. */
|
|
|
|
HomebrewXML::HomebrewXML()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finalizes an instance of the HomebrewXML class. */
|
|
|
|
HomebrewXML::~HomebrewXML()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/* qparam filename Filepath of the XML file */
|
|
|
|
int HomebrewXML::LoadHomebrewXMLData(const char* filename)
|
2010-09-17 18:15:18 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
mxml_node_t *nodedataHB = NULL;
|
|
|
|
mxml_node_t *nodetreeHB = NULL;
|
|
|
|
|
|
|
|
/* Load XML file */
|
|
|
|
FILE *filexml;
|
2010-09-24 02:48:03 +02:00
|
|
|
filexml = fopen(filename, "rb");
|
|
|
|
if (!filexml) return -1;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodetreeHB = mxmlLoadFile(NULL, filexml, MXML_OPAQUE_CALLBACK);
|
|
|
|
fclose(filexml);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (nodetreeHB == NULL) return -2;
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodedataHB = mxmlFindElement(nodetreeHB, nodetreeHB, "app", NULL, NULL, MXML_DESCEND);
|
|
|
|
if (nodedataHB == NULL) 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-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "name", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
Name = Entrie;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (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-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (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-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "short_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
ShortDescription = Entrie;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "long_description", NULL, NULL, MXML_DESCEND, Entrie, ENTRIE_SIZE);
|
2010-09-17 18:15:18 +02:00
|
|
|
LongDescription = Entrie;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (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
|
|
|
free(nodedataHB);
|
|
|
|
free(nodetreeHB);
|
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
|
|
|
|
2009-10-01 01:10:58 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
|
|
|
|
/* Get name */
|
|
|
|
const char * HomebrewXML::GetName()
|
|
|
|
{
|
|
|
|
return Name.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Name */
|
|
|
|
void HomebrewXML::SetName(char * newName)
|
|
|
|
{
|
|
|
|
Name = newName;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get coder */
|
|
|
|
const char * HomebrewXML::GetCoder()
|
|
|
|
{
|
|
|
|
return Coder.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get version */
|
|
|
|
const char * HomebrewXML::GetVersion()
|
|
|
|
{
|
|
|
|
return Version.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get releasedate */
|
|
|
|
const char * HomebrewXML::GetReleasedate()
|
|
|
|
{
|
|
|
|
return Releasedate.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get shortdescription */
|
|
|
|
const char * HomebrewXML::GetShortDescription()
|
|
|
|
{
|
|
|
|
return ShortDescription.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get longdescription */
|
|
|
|
const char * HomebrewXML::GetLongDescription()
|
|
|
|
{
|
|
|
|
return LongDescription.c_str();
|
|
|
|
}
|