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>
|
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
#include "network/networkops.h"
|
2009-12-12 19:04:35 +01:00
|
|
|
#include "Theme_List.h"
|
2011-06-25 21:50:57 +02:00
|
|
|
#include "xml/tinyxml.h"
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
Theme_List::Theme_List(const char * url)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
if (!IsNetworkInit())
|
|
|
|
return;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
u8 *buffer = NULL;
|
|
|
|
u32 size = 0;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
DownloadWithResponse(url, &buffer, &size);
|
2011-06-25 21:50:57 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!buffer)
|
|
|
|
return;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
const char *xml = strstr((char *) buffer, "<?xml version=");
|
|
|
|
if(!xml)
|
2011-06-25 21:50:57 +02:00
|
|
|
{
|
|
|
|
free(buffer);
|
|
|
|
return;
|
|
|
|
}
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
ParseXML(xml);
|
2011-06-25 21:50:57 +02:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
free(buffer);
|
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
|
|
|
}
|
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
bool Theme_List::ParseXML(const char * xmlfile)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
TiXmlDocument xmlDoc;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
if(!xmlDoc.Parse(xmlfile))
|
|
|
|
return false;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
TiXmlElement *themesNode = xmlDoc.FirstChildElement("themes");
|
2011-07-26 00:28:22 +02:00
|
|
|
if (!themesNode)
|
|
|
|
return false;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
TiXmlElement *theme = themesNode->FirstChildElement("theme");
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
while(theme)
|
|
|
|
{
|
|
|
|
int i = ThemesList.size();
|
|
|
|
ThemesList.resize(i+1);
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
TiXmlElement *node = NULL;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
node = theme->FirstChildElement("name");
|
|
|
|
if(node && node->FirstChild() && node->FirstChild()->Value())
|
|
|
|
ThemesList[i].themetitle = node->FirstChild()->Value();
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
node = theme->FirstChildElement("creator");
|
|
|
|
if(node && node->FirstChild() && node->FirstChild()->Value())
|
|
|
|
ThemesList[i].author = node->FirstChild()->Value();
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
node = theme->FirstChildElement("thumbpath");
|
|
|
|
if(node && node->FirstChild() && node->FirstChild()->Value())
|
|
|
|
ThemesList[i].imagelink = node->FirstChild()->Value();
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
node = theme->FirstChildElement("downloadpath");
|
|
|
|
if(node && node->FirstChild() && node->FirstChild()->Value())
|
|
|
|
ThemesList[i].downloadlink = node->FirstChild()->Value();
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2011-06-25 21:50:57 +02:00
|
|
|
node = theme->FirstChildElement("averagerating");
|
|
|
|
if(node && node->FirstChild() && node->FirstChild()->Value())
|
|
|
|
ThemesList[i].rating = atoi(node->FirstChild()->Value());
|
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
theme = theme->NextSiblingElement();
|
|
|
|
}
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return true;
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|
|
|
|
|
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-07-26 00:28:22 +02:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
|
|
|
return NULL;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02: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-07-26 00:28:22 +02:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
|
|
|
return NULL;
|
2011-01-02 10:23:44 +01:00
|
|
|
|
2011-07-26 00:28:22 +02: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-07-26 00:28:22 +02:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
|
|
|
return NULL;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02: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-07-26 00:28:22 +02:00
|
|
|
if (ind < 0 || ind >= (int) ThemesList.size())
|
|
|
|
return NULL;
|
2009-12-12 19:04:35 +01:00
|
|
|
|
2011-07-26 00:28:22 +02:00
|
|
|
return ThemesList[ind].downloadlink.c_str();
|
2009-12-12 19:04:35 +01:00
|
|
|
}
|