*Changed Theme Download to parse XML now

*Removed punes headlessID because it doesnt allow a start of the loader over SendElf anymore
This commit is contained in:
dimok321 2009-12-12 18:04:35 +00:00
parent 5c26c4082a
commit 063072a6c9
10 changed files with 665 additions and 707 deletions

View File

@ -2,8 +2,8 @@
<app version="1"> <app version="1">
<name> USB Loader GX</name> <name> USB Loader GX</name>
<coder>USB Loader GX Team</coder> <coder>USB Loader GX Team</coder>
<version>1.0 r859</version> <version>1.0 r860</version>
<release_date>200912120047</release_date> <release_date>200912121501</release_date>
<short_description>Loads games from USB-devices</short_description> <short_description>Loads games from USB-devices</short_description>
<long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times. <long_description>USB Loader GX is a libwiigui based USB iso loader with a wii-like GUI. You can install games to your HDDs and boot them with shorter loading times.
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller. The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.

File diff suppressed because one or more lines are too long

View File

@ -10,6 +10,7 @@
#ifndef _HOMEBREWBROWSE_H_ #ifndef _HOMEBREWBROWSE_H_
#define _HOMEBREWBROWSE_H_ #define _HOMEBREWBROWSE_H_
int roundup(float number);
int MenuHomebrewBrowse(); int MenuHomebrewBrowse();
#endif #endif

View File

@ -145,8 +145,10 @@ int MenuCheck() {
//Spieleliste laden //Spieleliste laden
__Menu_GetEntries(0); __Menu_GetEntries(0);
if (strcmp(headlessID,"")!=0) //THIS SHIT MAKES THE LOADER NOT RUN FROM SENDELF
menu = MENU_EXIT; //Think of something else pune.
//if (strcmp(headlessID,"")!=0)
//menu = MENU_EXIT;
if (menu == MENU_NONE) if (menu == MENU_NONE)
menu = MENU_DISCLIST; menu = MENU_DISCLIST;

View File

@ -253,7 +253,7 @@ static void ProgressWindow(const char *title, const char *msg1, const char *msg2
int tmp; int tmp;
while (showProgress) { while (showProgress) {
VIDEO_WaitVSync (); usleep(20000);
GameInstallProgress(); GameInstallProgress();
@ -325,7 +325,8 @@ void ProgressStop() {
* Callbackfunction for updating the progress values * Callbackfunction for updating the progress values
* Use this function as standard callback * Use this function as standard callback
***************************************************************************/ ***************************************************************************/
void ShowProgress(const char *title, const char *msg1, char *dynmsg2, f32 done, f32 total, bool swSize, bool swTime) { void ShowProgress(const char *title, const char *msg1, char *dynmsg2, f32 done, f32 total, bool swSize, bool swTime)
{
if (total <= 0) if (total <= 0)
return; return;
@ -342,37 +343,38 @@ void ShowProgress(const char *title, const char *msg1, char *dynmsg2, f32 done,
if (dynmsg2) if (dynmsg2)
dyn_message = dynmsg2; dyn_message = dynmsg2;
static u32 expected;
u32 elapsed, h, m, s, speed = 0;
if (!done) {
start = time(0);
expected = 300;
LWP_ResumeThread(progressthread);
}
//Elapsed time
elapsed = time(0) - start;
//Calculate speed in KB/s
if (elapsed > 0)
speed = done/(elapsed*KB_SIZE);
if (done != total) {
//Expected time
if (elapsed)
expected = (expected * 3 + elapsed * total / done) / 4;
//Remaining time
elapsed = (expected > elapsed) ? (expected - elapsed) : 0;
}
//Calculate time values
h = elapsed / 3600;
m = (elapsed / 60) % 60;
s = elapsed % 60;
if (swTime == true) { if (swTime == true) {
static u32 expected;
u32 elapsed, h, m, s, speed = 0;
if (!done) {
start = time(0);
expected = 300;
}
//Elapsed time
elapsed = time(0) - start;
//Calculate speed in KB/s
if (elapsed > 0)
speed = done/(elapsed*KB_SIZE);
if (done != total) {
//Expected time
if (elapsed)
expected = (expected * 3 + elapsed * total / done) / 4;
//Remaining time
elapsed = (expected > elapsed) ? (expected - elapsed) : 0;
}
//Calculate time values
h = elapsed / 3600;
m = (elapsed / 60) % 60;
s = elapsed % 60;
snprintf(progressTime, sizeof(progressTime), "%s %d:%02d:%02d",tr("Time left:"),h,m,s); snprintf(progressTime, sizeof(progressTime), "%s %d:%02d:%02d",tr("Time left:"),h,m,s);
} }
@ -383,13 +385,13 @@ void ShowProgress(const char *title, const char *msg1, char *dynmsg2, f32 done,
snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fMB/%0.2fMB", done * done/total / MB_SIZE, total/MB_SIZE); snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fMB/%0.2fMB", done * done/total / MB_SIZE, total/MB_SIZE);
else else
snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fGB/%0.2fGB", done * done/total / GB_SIZE, total/GB_SIZE); snprintf(progressSizeLeft, sizeof(progressSizeLeft), "%0.2fGB/%0.2fGB", done * done/total / GB_SIZE, total/GB_SIZE);
snprintf(progressSpeed, sizeof(progressSpeed), "%dKB/s", speed);
} }
showProgress = 1; showProgress = 1;
progressDone = 100.0*done/total; progressDone = 100.0*done/total;
changed = true; changed = true;
LWP_ResumeThread(progressthread);
} }
/**************************************************************************** /****************************************************************************

View File

@ -13,6 +13,7 @@
#include "libwiigui/gui.h" #include "libwiigui/gui.h"
#include "prompts/PromptWindows.h" #include "prompts/PromptWindows.h"
#include "prompts/ProgressWindow.h" #include "prompts/ProgressWindow.h"
#include "homebrewboot/HomebrewBrowse.h"
#include "network/networkops.h" #include "network/networkops.h"
#include "themes/Theme_List.h" #include "themes/Theme_List.h"
#include "menu.h" #include "menu.h"
@ -68,9 +69,9 @@ bool DownloadTheme(const char *url, const char *title)
u32 done = 0; u32 done = 0;
int blocksize = 1024; int blocksize = 1024*5;
u8 *buffer = (u8*) malloc(blocksize); u8 *buffer = new u8[blocksize];
while(done < (u32) filesize) while(done < (u32) filesize)
{ {
@ -89,17 +90,26 @@ bool DownloadTheme(const char *url, const char *title)
WindowPrompt(tr("Download failed."), tr("Transfer failed."), tr("OK")); WindowPrompt(tr("Download failed."), tr("Transfer failed."), tr("OK"));
return false; return false;
} }
else if (ret == 0)
break;
fwrite(buffer, 1, blocksize, file); fwrite(buffer, 1, blocksize, file);
done += ret; done += ret;
} }
free(buffer); delete [] buffer;
fclose(file); fclose(file);
ProgressStop(); ProgressStop();
if(done != (u32) filesize)
{
remove(filepath);
WindowPrompt(tr("Download failed."), tr("Connection lost..."), tr("OK"));
return false;
}
ZipFile zipfile(filepath); ZipFile zipfile(filepath);
bool result = zipfile.ExtractAll(path); bool result = zipfile.ExtractAll(path);
@ -249,10 +259,10 @@ int Theme_Downloader()
{ {
int pagesize = 4; int pagesize = 4;
int menu = MENU_NONE; int menu = MENU_NONE;
bool pagechanged = false;
bool listchanged = false; bool listchanged = false;
char THEME_LINK[30] = "http://wii.spiffy360.com/"; const char THEME_LINK[70] = "http://wii.spiffy360.com/themes.php?xml=1&category=1&adult=0";
//const char THEME_LINK_ADULT[70] = "http://wii.spiffy360.com/themes.php?xml=1&category=1&adult=1";
/*** Sound Variables ***/ /*** Sound Variables ***/
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume); GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume);
@ -388,18 +398,6 @@ int Theme_Downloader()
PageIndicatorBtn.SetTrigger(&trigA); PageIndicatorBtn.SetTrigger(&trigA);
PageIndicatorBtn.SetEffectGrow(); PageIndicatorBtn.SetEffectGrow();
GuiImage Pageindicator2Img(&PageindicatorImgData);
GuiText Pageindicator2Txt(NULL, 22, (GXColor) { 0, 0, 0, 255});
GuiButton PageIndicator2Btn(Pageindicator2Img.GetWidth(), Pageindicator2Img.GetHeight());
PageIndicator2Btn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
PageIndicator2Btn.SetPosition(150, 400);
PageIndicator2Btn.SetImage(&Pageindicator2Img);
PageIndicator2Btn.SetLabel(&Pageindicator2Txt);
PageIndicator2Btn.SetSoundOver(&btnSoundOver);
PageIndicator2Btn.SetSoundClick(&btnClick1);
PageIndicator2Btn.SetTrigger(&trigA);
PageIndicator2Btn.SetEffectGrow();
GuiImage wifiImg(&wifiImgData); GuiImage wifiImg(&wifiImgData);
if (Settings.wsprompt == yes) if (Settings.wsprompt == yes)
{ {
@ -426,7 +424,30 @@ int Theme_Downloader()
char url[300]; char url[300];
int currentpage = 1; int currentpage = 1;
int currenttheme = 0; int currenttheme = 0;
int currentloaderpage = 1;
HaltGui();
w.RemoveAll();
w.Append(&background);
w.Append(&titleTxt);
w.Append(&backBtn);
w.Append(&GoLeftBtn);
w.Append(&GoRightBtn);
w.Append(&PageIndicatorBtn);
w.Append(&wifiBtn);
w.Append(&HomeBtn);
ResumeGui();
ShowProgress(tr("Downloading Page List:"), "", (char *) tr("Please wait..."), 0, pagesize);
Theme = new Theme_List(THEME_LINK);
int ThemesOnPage = Theme->GetThemeCount();
if(!ThemesOnPage)
{
WindowPrompt(tr("No themes found on the site."), 0, "OK");
menu = MENU_SETTINGS;
}
while(menu == MENU_NONE) while(menu == MENU_NONE)
{ {
@ -438,202 +459,145 @@ int Theme_Downloader()
w.Append(&GoLeftBtn); w.Append(&GoLeftBtn);
w.Append(&GoRightBtn); w.Append(&GoRightBtn);
w.Append(&PageIndicatorBtn); w.Append(&PageIndicatorBtn);
w.Append(&PageIndicator2Btn);
w.Append(&wifiBtn); w.Append(&wifiBtn);
w.Append(&HomeBtn); w.Append(&HomeBtn);
ResumeGui(); ResumeGui();
ShowProgress(tr("Downloading Page List:"), "", (char *) tr("Please wait..."), 0, pagesize);
snprintf(url, sizeof(url), "%sthemes.php?creator=&sort=1&page=%i", THEME_LINK, currentpage);
if(Theme)
{
delete Theme;
Theme = NULL;
}
Theme = new Theme_List(url);
sprintf(url, "%i", currentpage); sprintf(url, "%i", currentpage);
PageindicatorTxt.SetText(url); PageindicatorTxt.SetText(url);
int SitePageCount = Theme->GetSitepageCount(); int n = 0;
int ThemesOnPage = Theme->GetThemeCount();
pagechanged = false; for(int i = currenttheme; (i < (currenttheme+pagesize)); i++)
if(!ThemesOnPage)
{ {
WindowPrompt(tr("No themes found on the site."), 0, "OK"); ShowProgress(tr("Downloading image:"), 0, (char *) Theme->GetThemeTitle(i), n, pagesize);
pagechanged = true;
menu = MENU_SETTINGS; if(MainButtonTxt[n])
delete MainButtonTxt[n];
if(ImageData[n])
delete ImageData[n];
if(Image[n])
delete Image[n];
MainButtonTxt[n] = NULL;
ImageData[n] = NULL;
Image[n] = NULL;
if(i < ThemesOnPage)
{
MainButtonTxt[n] = new GuiText(Theme->GetThemeTitle(i), 18, (GXColor) { 0, 0, 0, 255});
MainButtonTxt[n]->SetAlignment(ALIGN_CENTER, ALIGN_TOP);
MainButtonTxt[n]->SetPosition(0, 10);
MainButtonTxt[n]->SetMaxWidth(theme_box_Data.GetWidth()-10, GuiText::DOTTED);
sprintf(url, "%s", Theme->GetImageLink(i));
char filepath[300];
snprintf(filepath, sizeof(filepath), "%s/tmp/%s.jpg", Settings.theme_downloadpath, Theme->GetThemeTitle(i));
FILE * storefile = fopen(filepath, "rb");
if(!storefile)
{
struct block file = downloadfile(url);
char storepath[300];
snprintf(storepath, sizeof(storepath), "%s/tmp/", Settings.theme_downloadpath);
subfoldercreate(storepath);
if(file.data)
{
storefile = fopen(filepath, "wb");
fwrite(file.data, 1, file.size, storefile);
fclose(storefile);
}
ImageData[n] = new GuiImageData(file.data, file.size);
free(file.data);
}
else
{
fseek(storefile, 0, SEEK_END);
u32 filesize = ftell(storefile);
u8 *buffer = (u8*) malloc(filesize);
rewind(storefile);
fread(buffer, 1, filesize, storefile);
fclose(storefile);
ImageData[n] = new GuiImageData(buffer, filesize);
free(buffer);
buffer = NULL;
}
Image[n] = new GuiImage(ImageData[n]);
Image[n]->SetScale(0.4);
Image[n]->SetPosition(50, -45);
MainButton[n]->SetIcon(Image[n]);
MainButton[n]->SetLabel(MainButtonTxt[n]);
}
n++;
} }
while(!pagechanged) ProgressStop();
HaltGui();
for(int i = 0; i < pagesize; i++)
{ {
HaltGui(); if(MainButtonTxt[i])
w.RemoveAll(); w.Append(MainButton[i]);
w.Append(&background); }
w.Append(&titleTxt); ResumeGui();
w.Append(&backBtn);
w.Append(&GoLeftBtn);
w.Append(&GoRightBtn);
w.Append(&PageIndicatorBtn);
w.Append(&PageIndicator2Btn);
w.Append(&wifiBtn);
w.Append(&HomeBtn);
ResumeGui();
sprintf(url, "%i", currentloaderpage); listchanged = false;
Pageindicator2Txt.SetText(url);
int n = 0; while(!listchanged)
{
VIDEO_WaitVSync ();
for(int i = currenttheme; (i < (currenttheme+pagesize)); i++) if (shutdown == 1)
Sys_Shutdown();
else if (reset == 1)
Sys_Reboot();
else if (wifiBtn.GetState() == STATE_CLICKED)
{ {
ShowProgress(tr("Downloading image:"), 0, (char *) Theme->GetThemeTitle(i), n, pagesize); Initialize_Network();
wifiBtn.ResetState();
if(MainButtonTxt[n]) }
delete MainButtonTxt[n]; else if (backBtn.GetState() == STATE_CLICKED)
if(ImageData[n]) {
delete ImageData[n]; listchanged = true;
if(Image[n]) menu = MENU_SETTINGS;
delete Image[n]; backBtn.ResetState();
break;
MainButtonTxt[n] = NULL; }
ImageData[n] = NULL; else if (GoRightBtn.GetState() == STATE_CLICKED)
Image[n] = NULL; {
listchanged = true;
if(i < ThemesOnPage) currenttheme += pagesize;
currentpage++;
if(currenttheme >= ThemesOnPage)
{ {
MainButtonTxt[n] = new GuiText(Theme->GetThemeTitle(i), 18, (GXColor) { 0, 0, 0, 255}); currentpage = 1;
MainButtonTxt[n]->SetAlignment(ALIGN_CENTER, ALIGN_TOP); currenttheme = 0;
MainButtonTxt[n]->SetPosition(0, 10);
MainButtonTxt[n]->SetMaxWidth(theme_box_Data.GetWidth()-10, GuiText::DOTTED);
if(!Theme->IsDirectImageLink(i))
sprintf(url, "%s%s", THEME_LINK, Theme->GetImageLink(i));
else
sprintf(url, "%s", Theme->GetImageLink(i));
char filepath[300];
snprintf(filepath, sizeof(filepath), "%s/tmp/%s.jpg", Settings.theme_downloadpath, Theme->GetThemeTitle(i));
FILE * storefile = fopen(filepath, "rb");
if(!storefile)
{
struct block file = downloadfile(url);
char storepath[300];
snprintf(storepath, sizeof(storepath), "%s/tmp/", Settings.theme_downloadpath);
subfoldercreate(storepath);
if(file.data)
{
storefile = fopen(filepath, "wb");
fwrite(file.data, 1, file.size, storefile);
fclose(storefile);
}
ImageData[n] = new GuiImageData(file.data, file.size);
free(file.data);
}
else
{
fseek(storefile, 0, SEEK_END);
u32 filesize = ftell(storefile);
u8 *buffer = (u8*) malloc(filesize);
rewind(storefile);
fread(buffer, 1, filesize, storefile);
fclose(storefile);
ImageData[n] = new GuiImageData(buffer, filesize);
free(buffer);
buffer = NULL;
}
Image[n] = new GuiImage(ImageData[n]);
Image[n]->SetScale(0.4);
Image[n]->SetPosition(50, -45);
MainButton[n]->SetIcon(Image[n]);
MainButton[n]->SetLabel(MainButtonTxt[n]);
} }
n++; GoRightBtn.ResetState();
}
else if (GoLeftBtn.GetState() == STATE_CLICKED)
{
listchanged = true;
currenttheme -= pagesize;
currentpage--;
if(currenttheme < 0)
{
currentpage = roundup((ThemesOnPage+1.0f)/pagesize);
currenttheme = currentpage*pagesize-pagesize;
}
GoLeftBtn.ResetState();
} }
ProgressStop();
HaltGui();
for(int i = 0; i < pagesize; i++) for(int i = 0; i < pagesize; i++)
{ {
if(MainButtonTxt[i]) if(MainButton[i]->GetState() == STATE_CLICKED)
w.Append(MainButton[i]);
}
ResumeGui();
listchanged = false;
while(!listchanged)
{
VIDEO_WaitVSync ();
if (shutdown == 1)
Sys_Shutdown();
else if (reset == 1)
Sys_Reboot();
else if (wifiBtn.GetState() == STATE_CLICKED)
{ {
Initialize_Network(); snprintf(url, sizeof(url), "%s", Theme->GetDownloadLink(currenttheme+i));
wifiBtn.ResetState(); Theme_Prompt(Theme->GetThemeTitle(currenttheme+i), Theme->GetThemeAuthor(currenttheme+i), ImageData[i], url);
} MainButton[i]->ResetState();
else if (backBtn.GetState() == STATE_CLICKED)
{
listchanged = true;
pagechanged = true;
menu = MENU_SETTINGS;
backBtn.ResetState();
break;
}
else if (GoRightBtn.GetState() == STATE_CLICKED)
{
listchanged = true;
currenttheme += pagesize;
currentloaderpage++;
if(currenttheme >= ThemesOnPage)
{
pagechanged = true;
currentpage++;
if(currentpage > SitePageCount)
currentpage = 1;
currenttheme = 0;
currentloaderpage = 1;
}
GoRightBtn.ResetState();
}
else if (GoLeftBtn.GetState() == STATE_CLICKED)
{
listchanged = true;
currenttheme -= pagesize;
currentloaderpage--;
if(currenttheme < 0)
{
pagechanged = true;
currentpage--;
if(currentpage < 1)
currentpage = SitePageCount;
currenttheme = 0;
currentloaderpage = 1;
}
GoLeftBtn.ResetState();
}
for(int i = 0; i < pagesize; i++)
{
if(MainButton[i]->GetState() == STATE_CLICKED)
{
snprintf(url, sizeof(url), "%s%s", THEME_LINK, Theme->GetDownloadLink(currenttheme+i));
Theme_Prompt(Theme->GetThemeTitle(currenttheme+i), Theme->GetThemeAuthor(currenttheme+i), ImageData[i], url);
MainButton[i]->ResetState();
}
} }
} }
} }

View File

@ -30,6 +30,8 @@
#include <gctypes.h> #include <gctypes.h>
#include "Theme_List.h" #include "Theme_List.h"
#include "xml/xml.h"
#include "prompts/PromptWindows.h"
#define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp)) #define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp))
@ -52,7 +54,6 @@ Theme_List::Theme_List(const char * url)
{ {
Theme = NULL; Theme = NULL;
themescount = 0; themescount = 0;
sitepages = 0;
if (!IsNetworkInit()) if (!IsNetworkInit())
{ {
@ -68,97 +69,14 @@ Theme_List::Theme_List(const char * url)
return; return;
} }
u32 cnt = 0; themescount = CountThemes(file.data);
char temp[1024]; if (themescount <= 0)
{
Theme = (Theme_Info *) malloc(sizeof(Theme_Info));
if (!Theme) {
free(file.data); free(file.data);
themescount = -3;
return; return;
} }
memset(&Theme[themescount], 0, sizeof(Theme_Info)); ParseXML(file.data);
while (cnt < file.size) {
if(stringcompare(file.data, "\"themetitle\">", cnt) == 0)
{
Theme = (Theme_Info *) realloc(Theme, (themescount+1)*sizeof(Theme_Info));
if (!Theme)
{
for (int i = 0; i < themescount; i++)
{
if(Theme[i].imagelink)
delete [] Theme[i].imagelink;
if(Theme[i].imagelink)
delete [] Theme[i].downloadlink;
Theme[i].imagelink = NULL;
Theme[i].downloadlink = NULL;
}
free(Theme);
Theme = NULL;
free(file.data);
themescount = -4;
break;
}
memset(&(Theme[themescount]), 0, sizeof(Theme_Info));
copyhtmlsting((const char *) file.data, temp, "</", cnt);
snprintf(Theme[themescount].themetitle, sizeof(Theme[themescount].themetitle), "%s", temp);
while (cnt < file.size && stringcompare(file.data, "\"themecreated\">By: ", cnt) != 0)
cnt++;
copyhtmlsting((const char *) file.data, temp, " - <", cnt);
snprintf(Theme[themescount].author, sizeof(Theme[themescount].author), "%s", temp);
while(cnt < file.size && stringcompare(file.data, "class=\"image\" src=\"", cnt) != 0)
cnt++;
copyhtmlsting((const char *) file.data, temp, "\" ", cnt);
Theme[themescount].imagelink = new char[strlen(temp)+1];
snprintf(Theme[themescount].imagelink, strlen(temp)+1, "%s", temp);
if (strncmp(Theme[themescount].imagelink, "http://", strlen("http://")) != 0)
Theme[themescount].direct[0] = false;
else
Theme[themescount].direct[0] = true;
while(cnt < file.size && stringcompare(file.data, "href=\"getfile.php", cnt+strlen("getfile.php")) != 0)
cnt++;
copyhtmlsting((const char *) file.data, temp, "\">", cnt);
Theme[themescount].downloadlink = new char[strlen(temp)+1];
snprintf(Theme[themescount].downloadlink, strlen(temp)+1, "%s", temp);
if (strncmp(Theme[themescount].downloadlink, "http://", strlen("http://")) != 0)
Theme[themescount].direct[1] = false;
else
Theme[themescount].direct[1] = true;
themescount++;
}
if(stringcompare(file.data, "/themes.php?creator=&sort=1&page=", cnt) == 0)
{
copyhtmlsting((const char *) file.data, temp, "class", cnt);
int currentvalue = atoi(temp);
if(currentvalue > sitepages);
sitepages = currentvalue;
}
cnt++;
}
free(file.data); free(file.data);
} }
@ -167,19 +85,113 @@ Theme_List::~Theme_List()
{ {
for (int i = 0; i < themescount; i++) for (int i = 0; i < themescount; i++)
{ {
if(Theme[i].themetitle)
delete [] Theme[i].themetitle;
if(Theme[i].author)
delete [] Theme[i].author;
if(Theme[i].imagelink) if(Theme[i].imagelink)
delete [] Theme[i].imagelink; delete [] Theme[i].imagelink;
if(Theme[i].imagelink) if(Theme[i].downloadlink)
delete [] Theme[i].downloadlink; delete [] Theme[i].downloadlink;
Theme[i].themetitle = NULL;
Theme[i].author = NULL;
Theme[i].imagelink = NULL; Theme[i].imagelink = NULL;
Theme[i].downloadlink = NULL; Theme[i].downloadlink = NULL;
} }
if(Theme) if(Theme)
free(Theme); delete [] Theme;
Theme = NULL; Theme = NULL;
} }
int Theme_List::CountThemes(const u8 * xmlfile)
{
char tmp[200];
u32 cnt = 0;
u32 stringlength = strlen((const char *) xmlfile);
memset(tmp, 0, sizeof(tmp));
while (cnt < stringlength)
{
if (stringcompare(xmlfile, "<totalthemes>", cnt) == 0)
{
copyhtmlsting((const char *) xmlfile, tmp, ">", cnt);
break;
}
cnt++;
}
tmp[cnt+1] = 0;
return atoi(tmp);
}
bool Theme_List::ParseXML(const u8 * xmlfile)
{
char element_text[1024];
memset(element_text, 0, sizeof(element_text));
mxml_node_t *nodetree=NULL;
mxml_node_t *nodedata=NULL;
mxml_node_t *nodeid=NULL;
mxml_index_t *nodeindex=NULL;
nodetree = mxmlLoadString(NULL, (const char *) xmlfile, MXML_OPAQUE_CALLBACK);
if (nodetree == NULL)
{
return false;
}
nodedata = mxmlFindElement(nodetree, nodetree, "themes", NULL, NULL, MXML_DESCEND);
if (nodedata == NULL)
{
return false;
}
nodeindex = mxmlIndexNew(nodedata,"name", NULL);
nodeid = mxmlIndexReset(nodeindex);
Theme = new Theme_Info[themescount];
memset(Theme, 0, sizeof(Theme));
for (int i = 0; i < themescount; i++)
{
nodeid = mxmlIndexFind(nodeindex,"name", NULL);
if (nodeid != NULL)
{
get_nodetext(nodeid, element_text, sizeof(element_text));
Theme[i].themetitle = new char[strlen(element_text)+2];
snprintf(Theme[i].themetitle,strlen(element_text)+1, "%s", element_text);
GetTextFromNode(nodeid, nodedata, (char *) "creator", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
Theme[i].author = new char[strlen(element_text)+2];
snprintf(Theme[i].author,strlen(element_text)+1, "%s", element_text);
GetTextFromNode(nodeid, nodedata, (char *) "thumbpath", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
Theme[i].imagelink = new char[strlen(element_text)+2];
snprintf(Theme[i].imagelink,strlen(element_text)+1, "%s", element_text);
GetTextFromNode(nodeid, nodedata, (char *) "downloadpath", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
Theme[i].downloadlink = new char[strlen(element_text)+2];
snprintf(Theme[i].downloadlink,strlen(element_text)+1, "%s", element_text);
GetTextFromNode(nodeid, nodedata, (char *) "averagerating", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
Theme[i].rating = atoi(element_text);
}
}
nodetree=NULL;
nodedata=NULL;
nodeid=NULL;
nodeindex=NULL;
mxmlIndexDelete(nodeindex);
free(nodetree);
free(nodedata);
free(nodeid);
return true;
}
const char * Theme_List::GetThemeTitle(int ind) const char * Theme_List::GetThemeTitle(int ind)
{ {
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
@ -217,27 +229,6 @@ int Theme_List::GetThemeCount()
return themescount; return themescount;
} }
int Theme_List::GetSitepageCount()
{
return sitepages;
}
bool Theme_List::IsDirectImageLink(int ind)
{
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
return false;
else
return Theme[ind].direct[0];
}
bool Theme_List::IsDirectDownloadLink(int ind)
{
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
return false;
else
return Theme[ind].direct[1];
}
static int ListCompare(const void *a, const void *b) static int ListCompare(const void *a, const void *b)
{ {
Theme_Info *ab = (Theme_Info*) a; Theme_Info *ab = (Theme_Info*) a;

View File

@ -11,11 +11,11 @@
typedef struct _theme_info typedef struct _theme_info
{ {
char themetitle[100]; char *themetitle;
char author[50]; char *author;
char *imagelink; char *imagelink;
char *downloadlink; char *downloadlink;
bool direct[2]; u8 rating;
} Theme_Info; } Theme_Info;
@ -27,6 +27,10 @@ class Theme_List
Theme_List(const char *url); Theme_List(const char *url);
//!Destructor //!Destructor
~Theme_List(); ~Theme_List();
//!Get Themes into a struct from the XML file amount
bool ParseXML(const u8 * xmlfile);
//!Get Theme amount
int CountThemes(const u8 * xmlfile);
//! Get the a theme title //! Get the a theme title
//!\param list index //!\param list index
const char * GetThemeTitle(int index); const char * GetThemeTitle(int index);
@ -39,19 +43,12 @@ class Theme_List
//! Get the download link of the theme //! Get the download link of the theme
//!\param list index //!\param list index
const char * GetDownloadLink(int index); const char * GetDownloadLink(int index);
//! Is it a direct URL or just a file or path under the main url
bool IsDirectImageLink(int index);
//! Is it a direct URL or just a file or path under the main url
bool IsDirectDownloadLink(int index);
//! Get the number of links counted //! Get the number of links counted
int GetThemeCount(); int GetThemeCount();
//! Get the number of pages counted on which there are Themes
int GetSitepageCount();
//! Sort list //! Sort list
void SortList(); void SortList();
protected: protected:
int themescount; int themescount;
int sitepages;
Theme_Info *Theme; Theme_Info *Theme;
}; };

View File

@ -61,7 +61,7 @@ static mxml_node_t *nodefound=NULL;
static mxml_index_t *nodeindex=NULL; static mxml_index_t *nodeindex=NULL;
static mxml_index_t *nodeindextmp=NULL; static mxml_index_t *nodeindextmp=NULL;
int xmlloadtime = 0; int xmlloadtime = 0;
static char * get_text(mxml_node_t *node, char *buffer, int buflen); char * get_nodetext(mxml_node_t *node, char *buffer, int buflen);
bool xml_loaded = false; bool xml_loaded = false;
@ -111,7 +111,7 @@ void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *noden
if (attributename != NULL) { if (attributename != NULL) {
strlcpy(dest,mxmlElementGetAttr(nodefound, attributename),destsize); strlcpy(dest,mxmlElementGetAttr(nodefound, attributename),destsize);
} else { } else {
get_text(nodefound, element_text, sizeof(element_text)); get_nodetext(nodefound, element_text, sizeof(element_text));
strlcpy(dest,element_text,destsize); strlcpy(dest,element_text,destsize);
} }
} else { } else {
@ -308,7 +308,7 @@ void LoadTitlesFromXML(char *langtxt, bool forcejptoen)
strcpy(title_text,""); strcpy(title_text,"");
strcpy(title_text_EN,""); strcpy(title_text_EN,"");
get_text(nodeid, element_text, sizeof(element_text)); get_nodetext(nodeid, element_text, sizeof(element_text));
snprintf(id_text, 7, "%s",element_text); snprintf(id_text, 7, "%s",element_text);
// if language is not forced, use game language setting from config // if language is not forced, use game language setting from config
@ -402,7 +402,7 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
while (1) { while (1) {
nodeid = mxmlIndexFind(nodeindex,"id", NULL); nodeid = mxmlIndexFind(nodeindex,"id", NULL);
if (nodeid != NULL) { if (nodeid != NULL) {
get_text(nodeid, element_text, sizeof(element_text)); get_nodetext(nodeid, element_text, sizeof(element_text));
if (!strcmp(element_text,gameid)) { if (!strcmp(element_text,gameid)) {
break; break;
} }
@ -718,8 +718,8 @@ char *MemInfo() {
/*-------------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------------*/
/* get_text() - Get the text for a node, taken from mini-mxml example mxmldoc.c */ /* get_nodetext() - Get the text for a node, taken from mini-mxml example mxmldoc.c */
static char * get_text(mxml_node_t *node, char *buffer, int buflen) { /* O - Text in node, I - Node to get, I - Buffer, I - Size of buffer */ char * get_nodetext(mxml_node_t *node, char *buffer, int buflen) { /* O - Text in node, I - Node to get, I - Buffer, I - Size of buffer */
char *ptr, *end; /* Pointer into buffer, End of buffer */ char *ptr, *end; /* Pointer into buffer, End of buffer */
int len; /* Length of node */ int len; /* Length of node */
mxml_node_t *current; /* Current node */ mxml_node_t *current; /* Current node */
@ -760,7 +760,7 @@ int GetRatingForGame(char *gameid)
while (1) { while (1) {
nodeid = mxmlIndexFind(nodeindex,"id", NULL); nodeid = mxmlIndexFind(nodeindex,"id", NULL);
if (nodeid != NULL) { if (nodeid != NULL) {
get_text(nodeid, element_text, sizeof(element_text)); get_nodetext(nodeid, element_text, sizeof(element_text));
if (!strcmp(element_text,gameid)) { if (!strcmp(element_text,gameid)) {
break; break;
} }

View File

@ -66,6 +66,7 @@ extern "C" {
void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *nodename, void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *nodename,
char *attributename, char *value, int descend, char *dest, int destsize); char *attributename, char *value, int descend, char *dest, int destsize);
int GetRatingForGame(char *gameid); int GetRatingForGame(char *gameid);
char * get_nodetext(mxml_node_t *node, char *buffer, int buflen);
#ifdef __cplusplus #ifdef __cplusplus
} }