2009-12-12 19:04:35 +01:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2009
|
|
|
|
* by USB Loader GX Team
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* Theme_List Class
|
|
|
|
* for the USB Loader GX
|
|
|
|
***************************************************************************/
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gctypes.h>
|
|
|
|
|
|
|
|
#include "Theme_List.h"
|
|
|
|
#include "xml/xml.h"
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
Theme_List::Theme_List(const char * url)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if (!IsNetworkInit())
|
2009-12-12 19:04:35 +01:00
|
|
|
return;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
struct block file = downloadfile(url);
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
if (!file.data)
|
2009-12-12 19:04:35 +01:00
|
|
|
return;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
ParseXML(file.data);
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
free(file.data);
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
Theme_List::~Theme_List()
|
|
|
|
{
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
bool Theme_List::ParseXML(const u8 * xmlfile)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
char element_text[1024];
|
2010-09-24 02:48:03 +02:00
|
|
|
memset(element_text, 0, sizeof(element_text));
|
2010-09-19 01:16:05 +02:00
|
|
|
mxml_node_t *nodetree = NULL;
|
|
|
|
mxml_node_t *nodedata = NULL;
|
|
|
|
mxml_node_t *nodeid = NULL;
|
|
|
|
mxml_index_t *nodeindex = NULL;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodetree = mxmlLoadString(NULL, (const char *) xmlfile, MXML_OPAQUE_CALLBACK);
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (nodetree == NULL)
|
2009-12-12 19:04:35 +01:00
|
|
|
return false;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodedata = mxmlFindElement(nodetree, nodetree, "themes", NULL, NULL, MXML_DESCEND);
|
|
|
|
if (nodedata == NULL)
|
2009-12-12 19:04:35 +01:00
|
|
|
return false;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
nodeindex = mxmlIndexNew(nodedata, "name", NULL);
|
|
|
|
nodeid = mxmlIndexReset(nodeindex);
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
while((nodeid = mxmlIndexFind(nodeindex, "name", NULL)) != NULL)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2011-01-02 10:23:44 +01:00
|
|
|
int i = ThemesList.size();
|
|
|
|
ThemesList.resize(i+1);
|
|
|
|
|
|
|
|
element_text[0] = '\0';
|
|
|
|
get_nodetext(nodeid, element_text, sizeof(element_text));
|
|
|
|
ThemesList[i].themetitle = element_text;
|
|
|
|
|
|
|
|
element_text[0] = '\0';
|
|
|
|
GetTextFromNode(nodeid, nodedata, (char *) "creator", NULL, NULL, MXML_NO_DESCEND, element_text, sizeof(element_text));
|
|
|
|
ThemesList[i].author = element_text;
|
|
|
|
|
|
|
|
element_text[0] = '\0';
|
|
|
|
GetTextFromNode(nodeid, nodedata, (char *) "thumbpath", NULL, NULL, MXML_NO_DESCEND, element_text, sizeof(element_text));
|
|
|
|
ThemesList[i].imagelink = element_text;
|
|
|
|
|
|
|
|
element_text[0] = '\0';
|
|
|
|
GetTextFromNode(nodeid, nodedata, (char *) "downloadpath", NULL, NULL, MXML_NO_DESCEND, element_text, sizeof(element_text));
|
|
|
|
ThemesList[i].downloadlink = element_text;
|
|
|
|
|
|
|
|
element_text[0] = '\0';
|
|
|
|
GetTextFromNode(nodeid, nodedata, (char *) "averagerating", NULL, NULL, MXML_NO_DESCEND, element_text, sizeof(element_text));
|
|
|
|
ThemesList[i].rating = atoi(element_text);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
mxmlIndexDelete(nodeindex);
|
2011-01-02 10:23:44 +01:00
|
|
|
mxmlDelete(nodedata);
|
|
|
|
mxmlDelete(nodetree);
|
2009-12-12 19:04:35 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
const char * Theme_List::GetThemeTitle(int ind) const
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-01-02 10:23:44 +01:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
2009-12-12 19:04:35 +01:00
|
|
|
return NULL;
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
else return ThemesList[ind].themetitle.c_str();
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
const char * Theme_List::GetThemeAuthor(int ind) const
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-01-02 10:23:44 +01:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
2009-12-12 19:04:35 +01:00
|
|
|
return NULL;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
|
|
|
return ThemesList[ind].author.c_str();
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
const char * Theme_List::GetImageLink(int ind) const
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-01-02 10:23:44 +01:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
2009-12-12 19:04:35 +01:00
|
|
|
return NULL;
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
return ThemesList[ind].imagelink.c_str();
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
const char * Theme_List::GetDownloadLink(int ind) const
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-01-02 10:23:44 +01:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
|
|
|
return NULL;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-01-02 10:23:44 +01:00
|
|
|
return ThemesList[ind].downloadlink.c_str();
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|