*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

@ -1,162 +1,164 @@
#include <dirent.h> #include <dirent.h>
#include <unistd.h> #include <unistd.h>
#include "menus.h" #include "menus.h"
#include "wpad.h" #include "wpad.h"
#include "fatmounter.h" #include "fatmounter.h"
#include "usbloader/getentries.h" #include "usbloader/getentries.h"
#include "usbloader/wbfs.h" #include "usbloader/wbfs.h"
extern bool load_from_fat; extern bool load_from_fat;
extern char game_partition[6]; extern char game_partition[6];
extern char headlessID[8]; extern char headlessID[8];
/**************************************************************************** /****************************************************************************
* MenuCheck * MenuCheck
***************************************************************************/ ***************************************************************************/
int MenuCheck() { int MenuCheck() {
gprintf("\nMenuCheck()"); gprintf("\nMenuCheck()");
int menu = MENU_NONE; int menu = MENU_NONE;
int i = 0; int i = 0;
int choice; int choice;
s32 ret2, wbfsinit; s32 ret2, wbfsinit;
OptionList options; OptionList options;
options.length = i; options.length = i;
VIDEO_WaitVSync (); VIDEO_WaitVSync ();
wbfsinit = WBFS_Init(WBFS_DEVICE_USB); wbfsinit = WBFS_Init(WBFS_DEVICE_USB);
if (wbfsinit < 0) { if (wbfsinit < 0) {
ret2 = WindowPrompt(tr("No USB Device found."), tr("Do you want to retry for 30 secs?"), "cIOS249", "cIOS222", tr("Back to Wii Menu")); ret2 = WindowPrompt(tr("No USB Device found."), tr("Do you want to retry for 30 secs?"), "cIOS249", "cIOS222", tr("Back to Wii Menu"));
SDCard_deInit(); SDCard_deInit();
USBDevice_deInit(); USBDevice_deInit();
WPAD_Flush(0); WPAD_Flush(0);
WPAD_Disconnect(0); WPAD_Disconnect(0);
WPAD_Shutdown(); WPAD_Shutdown();
if (ret2 == 1) { if (ret2 == 1) {
Settings.cios = ios249; Settings.cios = ios249;
} else if (ret2 == 2) { } else if (ret2 == 2) {
Settings.cios = ios222; Settings.cios = ios222;
} else { } else {
Sys_LoadMenu(); Sys_LoadMenu();
} }
ret2 = DiscWait(tr("No USB Device"), tr("Waiting for USB Device"), 0, 0, 1); ret2 = DiscWait(tr("No USB Device"), tr("Waiting for USB Device"), 0, 0, 1);
//reinitialize SD and USB //reinitialize SD and USB
Wpad_Init(); Wpad_Init();
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
if (ret2 < 0) { if (ret2 < 0) {
WindowPrompt (tr("Error !"),tr("USB Device not found"), tr("OK")); WindowPrompt (tr("Error !"),tr("USB Device not found"), tr("OK"));
Sys_LoadMenu(); Sys_LoadMenu();
} }
} }
ret2 = -1; ret2 = -1;
memset(game_partition, 0, 6); memset(game_partition, 0, 6);
load_from_fat = false; load_from_fat = false;
extern PartList partitions; extern PartList partitions;
// Added for slow HDD // Added for slow HDD
for (int runs = 0; runs < 10; runs++) { for (int runs = 0; runs < 10; runs++) {
if (Partition_GetList(WBFS_DEVICE_USB, &partitions) != 0) { if (Partition_GetList(WBFS_DEVICE_USB, &partitions) != 0) {
sleep(1); sleep(1);
continue; continue;
} }
if (Settings.partition != -1 && partitions.num > Settings.partition) { if (Settings.partition != -1 && partitions.num > Settings.partition) {
PartInfo pinfo = partitions.pinfo[Settings.partition]; PartInfo pinfo = partitions.pinfo[Settings.partition];
ret2 = WBFS_OpenPart(pinfo.fs_type == FS_TYPE_FAT32, pinfo.fat_i, partitions.pentry[Settings.partition].sector, partitions.pentry[Settings.partition].size, (char *) &game_partition); ret2 = WBFS_OpenPart(pinfo.fs_type == FS_TYPE_FAT32, pinfo.fat_i, partitions.pentry[Settings.partition].sector, partitions.pentry[Settings.partition].size, (char *) &game_partition);
if (ret2 == 0) if (ret2 == 0)
{ {
load_from_fat = pinfo.fs_type == FS_TYPE_FAT32; load_from_fat = pinfo.fs_type == FS_TYPE_FAT32;
break; break;
} }
} }
if (partitions.wbfs_n != 0) { if (partitions.wbfs_n != 0) {
ret2 = WBFS_Open(); ret2 = WBFS_Open();
for (int p = 0; p < partitions.num; p++) { for (int p = 0; p < partitions.num; p++) {
if (partitions.pinfo[p].fs_type == FS_TYPE_WBFS) { if (partitions.pinfo[p].fs_type == FS_TYPE_WBFS) {
Settings.partition = p; Settings.partition = p;
break; break;
} }
} }
} else if (Sys_IsHermes() && partitions.fat_n != 0) { } else if (Sys_IsHermes() && partitions.fat_n != 0) {
// Loop through FAT partitions, and find the first partition with games on it (if there is one) // Loop through FAT partitions, and find the first partition with games on it (if there is one)
u32 count; u32 count;
for (int i = 0; i < partitions.num; i++) { for (int i = 0; i < partitions.num; i++) {
if (partitions.pinfo[i].fs_type == FS_TYPE_FAT32) { if (partitions.pinfo[i].fs_type == FS_TYPE_FAT32) {
if (!WBFS_OpenPart(1, partitions.pinfo[i].fat_i, partitions.pentry[i].sector, partitions.pentry[i].size, (char *) &game_partition)) { if (!WBFS_OpenPart(1, partitions.pinfo[i].fat_i, partitions.pentry[i].sector, partitions.pentry[i].size, (char *) &game_partition)) {
// Get the game count... // Get the game count...
WBFS_GetCount(&count); WBFS_GetCount(&count);
if (count > 0) { if (count > 0) {
load_from_fat = true; load_from_fat = true;
Settings.partition = i; Settings.partition = i;
break; break;
} else { } else {
WBFS_Close(); WBFS_Close();
} }
} }
} }
} }
} }
if (ret2 >= 0 || load_from_fat) { if (ret2 >= 0 || load_from_fat) {
cfg_save_global(); cfg_save_global();
break; break;
} }
sleep(1); sleep(1);
} }
if (ret2 < 0 && !load_from_fat) { if (ret2 < 0 && !load_from_fat) {
choice = WindowPrompt(tr("No WBFS or FAT game partition found"),tr("You need to select or format a partition"), tr("Select"), tr("Format"), tr("Return")); choice = WindowPrompt(tr("No WBFS or FAT game partition found"),tr("You need to select or format a partition"), tr("Select"), tr("Format"), tr("Return"));
if (choice == 0) { if (choice == 0) {
Sys_LoadMenu(); Sys_LoadMenu();
} else { } else {
load_from_fat = choice == 1; load_from_fat = choice == 1;
menu = MENU_FORMAT; menu = MENU_FORMAT;
} }
} }
ret2 = Disc_Init(); ret2 = Disc_Init();
if (ret2 < 0) { if (ret2 < 0) {
WindowPrompt (tr("Error !"),tr("Could not initialize DIP module!"),tr("OK")); WindowPrompt (tr("Error !"),tr("Could not initialize DIP module!"),tr("OK"));
Sys_LoadMenu(); Sys_LoadMenu();
} }
if (shutdown == 1) if (shutdown == 1)
Sys_Shutdown(); Sys_Shutdown();
if (reset == 1) if (reset == 1)
Sys_Reboot(); Sys_Reboot();
if (wbfsinit < 0) { if (wbfsinit < 0) {
sleep(1); sleep(1);
} }
// open database if needed, load titles if needed // open database if needed, load titles if needed
OpenXMLDatabase(Settings.titlestxt_path,Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride==1?true:false, true); OpenXMLDatabase(Settings.titlestxt_path,Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride==1?true:false, true);
// titles.txt loaded after database to override database titles with custom titles // titles.txt loaded after database to override database titles with custom titles
//snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path); //snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path);
//cfg_parsefile(pathname, &title_set); //cfg_parsefile(pathname, &title_set);
//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)
if (menu == MENU_NONE) //menu = MENU_EXIT;
menu = MENU_DISCLIST;
if (menu == MENU_NONE)
//for HDDs with issues menu = MENU_DISCLIST;
if (wbfsinit < 0) {
sleep(1); //for HDDs with issues
USBDevice_Init(); if (wbfsinit < 0) {
SDCard_Init(); sleep(1);
} USBDevice_Init();
SDCard_Init();
return menu; }
}
return menu;
}

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

@ -1,251 +1,242 @@
/*************************************************************************** /***************************************************************************
* Copyright (C) 2009 * Copyright (C) 2009
* by USB Loader GX Team * by USB Loader GX Team
* *
* This software is provided 'as-is', without any express or implied * This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any * warranty. In no event will the authors be held liable for any
* damages arising from the use of this software. * damages arising from the use of this software.
* *
* Permission is granted to anyone to use this software for any * Permission is granted to anyone to use this software for any
* purpose, including commercial applications, and to alter it and * purpose, including commercial applications, and to alter it and
* redistribute it freely, subject to the following restrictions: * redistribute it freely, subject to the following restrictions:
* *
* 1. The origin of this software must not be misrepresented; you * 1. The origin of this software must not be misrepresented; you
* must not claim that you wrote the original software. If you use * must not claim that you wrote the original software. If you use
* this software in a product, an acknowledgment in the product * this software in a product, an acknowledgment in the product
* documentation would be appreciated but is not required. * documentation would be appreciated but is not required.
* *
* 2. Altered source versions must be plainly marked as such, and * 2. Altered source versions must be plainly marked as such, and
* must not be misrepresented as being the original software. * must not be misrepresented as being the original software.
* *
* 3. This notice may not be removed or altered from any source * 3. This notice may not be removed or altered from any source
* distribution. * distribution.
* *
* Theme_List Class * Theme_List Class
* for the USB Loader GX * for the USB Loader GX
***************************************************************************/ ***************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <gctypes.h> #include <gctypes.h>
#include "Theme_List.h" #include "Theme_List.h"
#include "xml/xml.h"
#define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp)) #include "prompts/PromptWindows.h"
static void copyhtmlsting(const char *from, char *outtext, const char *stopat, u32 &cnt) #define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp))
{
u32 cnt2 = 0; static void copyhtmlsting(const char *from, char *outtext, const char *stopat, u32 &cnt)
{
u32 stringlength = strlen(from); u32 cnt2 = 0;
while ((stringcompare(from, stopat, cnt+strlen(stopat)) != 0) && (cnt2 < 1024) && (cnt < stringlength)) u32 stringlength = strlen(from);
{
outtext[cnt2] = from[cnt]; while ((stringcompare(from, stopat, cnt+strlen(stopat)) != 0) && (cnt2 < 1024) && (cnt < stringlength))
cnt2++; {
cnt++; outtext[cnt2] = from[cnt];
} cnt2++;
outtext[cnt2] = '\0'; cnt++;
} }
outtext[cnt2] = '\0';
Theme_List::Theme_List(const char * url) }
{
Theme = NULL; Theme_List::Theme_List(const char * url)
themescount = 0; {
sitepages = 0; Theme = NULL;
themescount = 0;
if (!IsNetworkInit())
{ if (!IsNetworkInit())
themescount = -1; {
return; themescount = -1;
} return;
}
struct block file = downloadfile(url);
struct block file = downloadfile(url);
if (!file.data || !file.size)
{ if (!file.data || !file.size)
themescount = -2; {
return; themescount = -2;
} return;
}
u32 cnt = 0;
char temp[1024]; themescount = CountThemes(file.data);
if (themescount <= 0)
Theme = (Theme_Info *) malloc(sizeof(Theme_Info)); {
if (!Theme) { free(file.data);
free(file.data); return;
themescount = -3; }
return;
} ParseXML(file.data);
memset(&Theme[themescount], 0, sizeof(Theme_Info)); free(file.data);
}
while (cnt < file.size) {
Theme_List::~Theme_List()
if(stringcompare(file.data, "\"themetitle\">", cnt) == 0) {
{ for (int i = 0; i < themescount; i++)
Theme = (Theme_Info *) realloc(Theme, (themescount+1)*sizeof(Theme_Info)); {
if(Theme[i].themetitle)
if (!Theme) delete [] Theme[i].themetitle;
{ if(Theme[i].author)
for (int i = 0; i < themescount; i++) delete [] Theme[i].author;
{ if(Theme[i].imagelink)
if(Theme[i].imagelink) delete [] Theme[i].imagelink;
delete [] Theme[i].imagelink; if(Theme[i].downloadlink)
if(Theme[i].imagelink) delete [] Theme[i].downloadlink;
delete [] Theme[i].downloadlink; Theme[i].themetitle = NULL;
Theme[i].imagelink = NULL; Theme[i].author = NULL;
Theme[i].downloadlink = NULL; Theme[i].imagelink = NULL;
} Theme[i].downloadlink = NULL;
free(Theme); }
Theme = NULL;
free(file.data); if(Theme)
themescount = -4; delete [] Theme;
break; Theme = NULL;
} }
memset(&(Theme[themescount]), 0, sizeof(Theme_Info));
int Theme_List::CountThemes(const u8 * xmlfile)
copyhtmlsting((const char *) file.data, temp, "</", cnt); {
char tmp[200];
snprintf(Theme[themescount].themetitle, sizeof(Theme[themescount].themetitle), "%s", temp); u32 cnt = 0;
u32 stringlength = strlen((const char *) xmlfile);
while (cnt < file.size && stringcompare(file.data, "\"themecreated\">By: ", cnt) != 0) memset(tmp, 0, sizeof(tmp));
cnt++;
while (cnt < stringlength)
copyhtmlsting((const char *) file.data, temp, " - <", cnt); {
if (stringcompare(xmlfile, "<totalthemes>", cnt) == 0)
snprintf(Theme[themescount].author, sizeof(Theme[themescount].author), "%s", temp); {
copyhtmlsting((const char *) xmlfile, tmp, ">", cnt);
while(cnt < file.size && stringcompare(file.data, "class=\"image\" src=\"", cnt) != 0) break;
cnt++; }
cnt++;
copyhtmlsting((const char *) file.data, temp, "\" ", cnt); }
tmp[cnt+1] = 0;
Theme[themescount].imagelink = new char[strlen(temp)+1];
return atoi(tmp);
snprintf(Theme[themescount].imagelink, strlen(temp)+1, "%s", temp); }
if (strncmp(Theme[themescount].imagelink, "http://", strlen("http://")) != 0) bool Theme_List::ParseXML(const u8 * xmlfile)
Theme[themescount].direct[0] = false; {
else char element_text[1024];
Theme[themescount].direct[0] = true; memset(element_text, 0, sizeof(element_text));
mxml_node_t *nodetree=NULL;
while(cnt < file.size && stringcompare(file.data, "href=\"getfile.php", cnt+strlen("getfile.php")) != 0) mxml_node_t *nodedata=NULL;
cnt++; mxml_node_t *nodeid=NULL;
mxml_index_t *nodeindex=NULL;
copyhtmlsting((const char *) file.data, temp, "\">", cnt);
nodetree = mxmlLoadString(NULL, (const char *) xmlfile, MXML_OPAQUE_CALLBACK);
Theme[themescount].downloadlink = new char[strlen(temp)+1];
if (nodetree == NULL)
snprintf(Theme[themescount].downloadlink, strlen(temp)+1, "%s", temp); {
return false;
if (strncmp(Theme[themescount].downloadlink, "http://", strlen("http://")) != 0) }
Theme[themescount].direct[1] = false;
else nodedata = mxmlFindElement(nodetree, nodetree, "themes", NULL, NULL, MXML_DESCEND);
Theme[themescount].direct[1] = true; if (nodedata == NULL)
{
themescount++; return false;
} }
if(stringcompare(file.data, "/themes.php?creator=&sort=1&page=", cnt) == 0) nodeindex = mxmlIndexNew(nodedata,"name", NULL);
{ nodeid = mxmlIndexReset(nodeindex);
copyhtmlsting((const char *) file.data, temp, "class", cnt);
int currentvalue = atoi(temp); Theme = new Theme_Info[themescount];
memset(Theme, 0, sizeof(Theme));
if(currentvalue > sitepages);
sitepages = currentvalue; for (int i = 0; i < themescount; i++)
} {
nodeid = mxmlIndexFind(nodeindex,"name", NULL);
cnt++; if (nodeid != NULL)
} {
get_nodetext(nodeid, element_text, sizeof(element_text));
free(file.data); Theme[i].themetitle = new char[strlen(element_text)+2];
} snprintf(Theme[i].themetitle,strlen(element_text)+1, "%s", element_text);
Theme_List::~Theme_List() GetTextFromNode(nodeid, nodedata, (char *) "creator", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
{ Theme[i].author = new char[strlen(element_text)+2];
for (int i = 0; i < themescount; i++) snprintf(Theme[i].author,strlen(element_text)+1, "%s", element_text);
{
if(Theme[i].imagelink) GetTextFromNode(nodeid, nodedata, (char *) "thumbpath", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
delete [] Theme[i].imagelink; Theme[i].imagelink = new char[strlen(element_text)+2];
if(Theme[i].imagelink) snprintf(Theme[i].imagelink,strlen(element_text)+1, "%s", element_text);
delete [] Theme[i].downloadlink;
Theme[i].imagelink = NULL; GetTextFromNode(nodeid, nodedata, (char *) "downloadpath", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
Theme[i].downloadlink = NULL; Theme[i].downloadlink = new char[strlen(element_text)+2];
} snprintf(Theme[i].downloadlink,strlen(element_text)+1, "%s", element_text);
if(Theme) GetTextFromNode(nodeid, nodedata, (char *) "averagerating", NULL, NULL, MXML_NO_DESCEND, element_text,sizeof(element_text));
free(Theme); Theme[i].rating = atoi(element_text);
Theme = NULL; }
} }
const char * Theme_List::GetThemeTitle(int ind) nodetree=NULL;
{ nodedata=NULL;
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) nodeid=NULL;
return NULL; nodeindex=NULL;
else mxmlIndexDelete(nodeindex);
return Theme[ind].themetitle; free(nodetree);
} free(nodedata);
free(nodeid);
const char * Theme_List::GetThemeAuthor(int ind)
{ return true;
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) }
return NULL;
else const char * Theme_List::GetThemeTitle(int ind)
return Theme[ind].author; {
} if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
return NULL;
const char * Theme_List::GetImageLink(int ind) else
{ return Theme[ind].themetitle;
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) }
return NULL;
else const char * Theme_List::GetThemeAuthor(int ind)
return Theme[ind].imagelink; {
} if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
return NULL;
const char * Theme_List::GetDownloadLink(int ind) else
{ return Theme[ind].author;
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) }
return NULL;
else const char * Theme_List::GetImageLink(int ind)
return Theme[ind].downloadlink; {
} if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
return NULL;
int Theme_List::GetThemeCount() else
{ return Theme[ind].imagelink;
return themescount; }
}
const char * Theme_List::GetDownloadLink(int ind)
int Theme_List::GetSitepageCount() {
{ if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
return sitepages; return NULL;
} else
return Theme[ind].downloadlink;
bool Theme_List::IsDirectImageLink(int ind) }
{
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) int Theme_List::GetThemeCount()
return false; {
else return themescount;
return Theme[ind].direct[0]; }
}
static int ListCompare(const void *a, const void *b)
bool Theme_List::IsDirectDownloadLink(int ind) {
{ Theme_Info *ab = (Theme_Info*) a;
if (ind > themescount || ind < 0 || !Theme || themescount <= 0) Theme_Info *bb = (Theme_Info*) b;
return false;
else return stricmp((char *) ab->themetitle, (char *) bb->themetitle);
return Theme[ind].direct[1]; }
} void Theme_List::SortList()
{
static int ListCompare(const void *a, const void *b) qsort(Theme, themescount, sizeof(Theme_Info), ListCompare);
{ }
Theme_Info *ab = (Theme_Info*) a;
Theme_Info *bb = (Theme_Info*) b;
return stricmp((char *) ab->themetitle, (char *) bb->themetitle);
}
void Theme_List::SortList()
{
qsort(Theme, themescount, sizeof(Theme_Info), ListCompare);
}

View File

@ -1,58 +1,55 @@
/**************************************************************************** /****************************************************************************
* Theme_List Class * Theme_List Class
* for USB Loader GX * for USB Loader GX
* by dimok * by dimok
***************************************************************************/ ***************************************************************************/
#ifndef ___THEMELIST_H_ #ifndef ___THEMELIST_H_
#define ___THEMELIST_H_ #define ___THEMELIST_H_
#include "network/networkops.h" #include "network/networkops.h"
#include "network/http.h" #include "network/http.h"
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;
class Theme_List class Theme_List
{ {
public: public:
//!Constructor //!Constructor
//!\param url from where to get the list of links //!\param url from where to get the list of links
Theme_List(const char *url); Theme_List(const char *url);
//!Destructor //!Destructor
~Theme_List(); ~Theme_List();
//! Get the a theme title //!Get Themes into a struct from the XML file amount
//!\param list index bool ParseXML(const u8 * xmlfile);
const char * GetThemeTitle(int index); //!Get Theme amount
//! Get the author of the theme int CountThemes(const u8 * xmlfile);
//!\param list index //! Get the a theme title
const char * GetThemeAuthor(int index); //!\param list index
//! Get the author of the theme const char * GetThemeTitle(int index);
//!\param list index //! Get the author of the theme
const char * GetImageLink(int index); //!\param list index
//! Get the download link of the theme const char * GetThemeAuthor(int index);
//!\param list index //! Get the author of the theme
const char * GetDownloadLink(int index); //!\param list index
//! Is it a direct URL or just a file or path under the main url const char * GetImageLink(int index);
bool IsDirectImageLink(int index); //! Get the download link of the theme
//! Is it a direct URL or just a file or path under the main url //!\param list index
bool IsDirectDownloadLink(int index); const char * GetDownloadLink(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 //! Sort list
int GetSitepageCount(); void SortList();
//! Sort list protected:
void SortList(); int themescount;
protected: Theme_Info *Theme;
int themescount; };
int sitepages;
Theme_Info *Theme; #endif
};
#endif

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,7 +66,8 @@ 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
} }
#endif #endif