2009-07-20 20:53:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* HomebrewXML Class
|
|
|
|
* for USB Loader GX
|
|
|
|
***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "xml/xml.h"
|
|
|
|
|
|
|
|
#include "HomebrewXML.h"
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
HomebrewXML::HomebrewXML() {
|
2009-07-20 20:53:28 +02:00
|
|
|
strcpy(name,"");
|
|
|
|
strcpy(coder,"");
|
|
|
|
strcpy(version,"");
|
|
|
|
strcpy(releasedate,"");
|
|
|
|
strcpy(shortdescription,"");
|
|
|
|
strcpy(longdescription,"");
|
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
HomebrewXML::~HomebrewXML() {
|
2009-07-20 20:53:28 +02:00
|
|
|
}
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
int HomebrewXML::LoadHomebrewXMLData(const char* filename) {
|
|
|
|
mxml_node_t *nodedataHB = NULL;
|
|
|
|
mxml_node_t *nodetreeHB = NULL;
|
|
|
|
char tmp1[40];
|
2009-07-20 20:53:28 +02:00
|
|
|
|
|
|
|
/* Load XML file */
|
|
|
|
FILE *filexml;
|
|
|
|
filexml = fopen(filename, "rb");
|
|
|
|
if (!filexml) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nodetreeHB = mxmlLoadFile(NULL, filexml, MXML_NO_CALLBACK);
|
|
|
|
fclose(filexml);
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
if (nodetreeHB == NULL) {
|
|
|
|
return -2;
|
2009-07-20 20:53:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
nodedataHB = mxmlFindElement(nodetreeHB, nodetreeHB, "app", NULL, NULL, MXML_DESCEND);
|
2009-07-30 07:41:12 +02:00
|
|
|
if (nodedataHB == NULL) {
|
|
|
|
return -5;
|
|
|
|
}
|
2009-07-20 20:53:28 +02:00
|
|
|
|
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "name", NULL, NULL, MXML_DESCEND, name,sizeof(name));
|
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "coder", NULL, NULL, MXML_DESCEND, coder,sizeof(coder));
|
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "version", NULL, NULL, MXML_DESCEND, version,sizeof(version));
|
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "release_date", NULL, NULL, MXML_DESCEND, tmp1,sizeof(tmp1));
|
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "short_description", NULL, NULL, MXML_DESCEND, shortdescription,sizeof(shortdescription));
|
|
|
|
GetTextFromNode(nodedataHB, nodedataHB, (char*) "long_description", NULL, NULL, MXML_DESCEND, longdescription,sizeof(longdescription));
|
|
|
|
|
|
|
|
int len = (strlen(tmp1)-6); //length of the date string without the 200000 at the end
|
|
|
|
|
|
|
|
if (len == 8)
|
|
|
|
snprintf(releasedate, sizeof(releasedate), "%c%c/%c%c/%c%c%c%c", tmp1[4],tmp1[5],tmp1[6],tmp1[7],tmp1[0],tmp1[1],tmp1[2],tmp1[3]);
|
|
|
|
else if (len == 6)
|
|
|
|
snprintf(releasedate, sizeof(releasedate), "%c%c/%c%c%c%c", tmp1[4],tmp1[5],tmp1[0],tmp1[1],tmp1[2],tmp1[3]);
|
|
|
|
else snprintf(releasedate, sizeof(releasedate), "%s", tmp1);
|
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
free(nodedataHB);
|
|
|
|
free(nodetreeHB);
|
2009-07-20 20:53:28 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
return 1;
|
2009-07-20 20:53:28 +02:00
|
|
|
}
|