mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-04 18:45:05 +01:00
*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:
parent
5c26c4082a
commit
063072a6c9
@ -2,8 +2,8 @@
|
||||
<app version="1">
|
||||
<name> USB Loader GX</name>
|
||||
<coder>USB Loader GX Team</coder>
|
||||
<version>1.0 r859</version>
|
||||
<release_date>200912120047</release_date>
|
||||
<version>1.0 r860</version>
|
||||
<release_date>200912121501</release_date>
|
||||
<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.
|
||||
The interactive GUI is completely controllable with WiiMote, Classic Controller or GC Controller.
|
||||
|
File diff suppressed because one or more lines are too long
@ -10,6 +10,7 @@
|
||||
#ifndef _HOMEBREWBROWSE_H_
|
||||
#define _HOMEBREWBROWSE_H_
|
||||
|
||||
int roundup(float number);
|
||||
int MenuHomebrewBrowse();
|
||||
|
||||
#endif
|
||||
|
@ -1,162 +1,164 @@
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "menus.h"
|
||||
#include "wpad.h"
|
||||
#include "fatmounter.h"
|
||||
#include "usbloader/getentries.h"
|
||||
#include "usbloader/wbfs.h"
|
||||
|
||||
extern bool load_from_fat;
|
||||
extern char game_partition[6];
|
||||
extern char headlessID[8];
|
||||
|
||||
/****************************************************************************
|
||||
* MenuCheck
|
||||
***************************************************************************/
|
||||
int MenuCheck() {
|
||||
gprintf("\nMenuCheck()");
|
||||
int menu = MENU_NONE;
|
||||
int i = 0;
|
||||
int choice;
|
||||
s32 ret2, wbfsinit;
|
||||
OptionList options;
|
||||
options.length = i;
|
||||
|
||||
VIDEO_WaitVSync ();
|
||||
|
||||
wbfsinit = WBFS_Init(WBFS_DEVICE_USB);
|
||||
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"));
|
||||
SDCard_deInit();
|
||||
USBDevice_deInit();
|
||||
WPAD_Flush(0);
|
||||
WPAD_Disconnect(0);
|
||||
WPAD_Shutdown();
|
||||
if (ret2 == 1) {
|
||||
Settings.cios = ios249;
|
||||
} else if (ret2 == 2) {
|
||||
Settings.cios = ios222;
|
||||
} else {
|
||||
Sys_LoadMenu();
|
||||
}
|
||||
ret2 = DiscWait(tr("No USB Device"), tr("Waiting for USB Device"), 0, 0, 1);
|
||||
//reinitialize SD and USB
|
||||
Wpad_Init();
|
||||
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
||||
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
||||
if (ret2 < 0) {
|
||||
WindowPrompt (tr("Error !"),tr("USB Device not found"), tr("OK"));
|
||||
Sys_LoadMenu();
|
||||
}
|
||||
}
|
||||
|
||||
ret2 = -1;
|
||||
memset(game_partition, 0, 6);
|
||||
load_from_fat = false;
|
||||
|
||||
extern PartList partitions;
|
||||
// Added for slow HDD
|
||||
for (int runs = 0; runs < 10; runs++) {
|
||||
if (Partition_GetList(WBFS_DEVICE_USB, &partitions) != 0) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Settings.partition != -1 && partitions.num > 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);
|
||||
|
||||
if (ret2 == 0)
|
||||
{
|
||||
load_from_fat = pinfo.fs_type == FS_TYPE_FAT32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (partitions.wbfs_n != 0) {
|
||||
ret2 = WBFS_Open();
|
||||
for (int p = 0; p < partitions.num; p++) {
|
||||
if (partitions.pinfo[p].fs_type == FS_TYPE_WBFS) {
|
||||
Settings.partition = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} 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)
|
||||
u32 count;
|
||||
for (int i = 0; i < partitions.num; i++) {
|
||||
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)) {
|
||||
// Get the game count...
|
||||
WBFS_GetCount(&count);
|
||||
|
||||
if (count > 0) {
|
||||
load_from_fat = true;
|
||||
Settings.partition = i;
|
||||
break;
|
||||
} else {
|
||||
WBFS_Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret2 >= 0 || load_from_fat) {
|
||||
cfg_save_global();
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
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"));
|
||||
if (choice == 0) {
|
||||
Sys_LoadMenu();
|
||||
} else {
|
||||
load_from_fat = choice == 1;
|
||||
menu = MENU_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
ret2 = Disc_Init();
|
||||
if (ret2 < 0) {
|
||||
WindowPrompt (tr("Error !"),tr("Could not initialize DIP module!"),tr("OK"));
|
||||
Sys_LoadMenu();
|
||||
}
|
||||
|
||||
if (shutdown == 1)
|
||||
Sys_Shutdown();
|
||||
if (reset == 1)
|
||||
Sys_Reboot();
|
||||
|
||||
if (wbfsinit < 0) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// titles.txt loaded after database to override database titles with custom titles
|
||||
//snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path);
|
||||
//cfg_parsefile(pathname, &title_set);
|
||||
|
||||
//Spieleliste laden
|
||||
__Menu_GetEntries(0);
|
||||
|
||||
if (strcmp(headlessID,"")!=0)
|
||||
menu = MENU_EXIT;
|
||||
|
||||
if (menu == MENU_NONE)
|
||||
menu = MENU_DISCLIST;
|
||||
|
||||
//for HDDs with issues
|
||||
if (wbfsinit < 0) {
|
||||
sleep(1);
|
||||
USBDevice_Init();
|
||||
SDCard_Init();
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
#include <dirent.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "menus.h"
|
||||
#include "wpad.h"
|
||||
#include "fatmounter.h"
|
||||
#include "usbloader/getentries.h"
|
||||
#include "usbloader/wbfs.h"
|
||||
|
||||
extern bool load_from_fat;
|
||||
extern char game_partition[6];
|
||||
extern char headlessID[8];
|
||||
|
||||
/****************************************************************************
|
||||
* MenuCheck
|
||||
***************************************************************************/
|
||||
int MenuCheck() {
|
||||
gprintf("\nMenuCheck()");
|
||||
int menu = MENU_NONE;
|
||||
int i = 0;
|
||||
int choice;
|
||||
s32 ret2, wbfsinit;
|
||||
OptionList options;
|
||||
options.length = i;
|
||||
|
||||
VIDEO_WaitVSync ();
|
||||
|
||||
wbfsinit = WBFS_Init(WBFS_DEVICE_USB);
|
||||
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"));
|
||||
SDCard_deInit();
|
||||
USBDevice_deInit();
|
||||
WPAD_Flush(0);
|
||||
WPAD_Disconnect(0);
|
||||
WPAD_Shutdown();
|
||||
if (ret2 == 1) {
|
||||
Settings.cios = ios249;
|
||||
} else if (ret2 == 2) {
|
||||
Settings.cios = ios222;
|
||||
} else {
|
||||
Sys_LoadMenu();
|
||||
}
|
||||
ret2 = DiscWait(tr("No USB Device"), tr("Waiting for USB Device"), 0, 0, 1);
|
||||
//reinitialize SD and USB
|
||||
Wpad_Init();
|
||||
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
||||
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
||||
if (ret2 < 0) {
|
||||
WindowPrompt (tr("Error !"),tr("USB Device not found"), tr("OK"));
|
||||
Sys_LoadMenu();
|
||||
}
|
||||
}
|
||||
|
||||
ret2 = -1;
|
||||
memset(game_partition, 0, 6);
|
||||
load_from_fat = false;
|
||||
|
||||
extern PartList partitions;
|
||||
// Added for slow HDD
|
||||
for (int runs = 0; runs < 10; runs++) {
|
||||
if (Partition_GetList(WBFS_DEVICE_USB, &partitions) != 0) {
|
||||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Settings.partition != -1 && partitions.num > 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);
|
||||
|
||||
if (ret2 == 0)
|
||||
{
|
||||
load_from_fat = pinfo.fs_type == FS_TYPE_FAT32;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (partitions.wbfs_n != 0) {
|
||||
ret2 = WBFS_Open();
|
||||
for (int p = 0; p < partitions.num; p++) {
|
||||
if (partitions.pinfo[p].fs_type == FS_TYPE_WBFS) {
|
||||
Settings.partition = p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} 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)
|
||||
u32 count;
|
||||
for (int i = 0; i < partitions.num; i++) {
|
||||
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)) {
|
||||
// Get the game count...
|
||||
WBFS_GetCount(&count);
|
||||
|
||||
if (count > 0) {
|
||||
load_from_fat = true;
|
||||
Settings.partition = i;
|
||||
break;
|
||||
} else {
|
||||
WBFS_Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (ret2 >= 0 || load_from_fat) {
|
||||
cfg_save_global();
|
||||
break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
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"));
|
||||
if (choice == 0) {
|
||||
Sys_LoadMenu();
|
||||
} else {
|
||||
load_from_fat = choice == 1;
|
||||
menu = MENU_FORMAT;
|
||||
}
|
||||
}
|
||||
|
||||
ret2 = Disc_Init();
|
||||
if (ret2 < 0) {
|
||||
WindowPrompt (tr("Error !"),tr("Could not initialize DIP module!"),tr("OK"));
|
||||
Sys_LoadMenu();
|
||||
}
|
||||
|
||||
if (shutdown == 1)
|
||||
Sys_Shutdown();
|
||||
if (reset == 1)
|
||||
Sys_Reboot();
|
||||
|
||||
if (wbfsinit < 0) {
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
// titles.txt loaded after database to override database titles with custom titles
|
||||
//snprintf(pathname, sizeof(pathname), "%stitles.txt", Settings.titlestxt_path);
|
||||
//cfg_parsefile(pathname, &title_set);
|
||||
|
||||
//Spieleliste laden
|
||||
__Menu_GetEntries(0);
|
||||
|
||||
//THIS SHIT MAKES THE LOADER NOT RUN FROM SENDELF
|
||||
//Think of something else pune.
|
||||
//if (strcmp(headlessID,"")!=0)
|
||||
//menu = MENU_EXIT;
|
||||
|
||||
if (menu == MENU_NONE)
|
||||
menu = MENU_DISCLIST;
|
||||
|
||||
//for HDDs with issues
|
||||
if (wbfsinit < 0) {
|
||||
sleep(1);
|
||||
USBDevice_Init();
|
||||
SDCard_Init();
|
||||
}
|
||||
|
||||
return menu;
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ static void ProgressWindow(const char *title, const char *msg1, const char *msg2
|
||||
int tmp;
|
||||
while (showProgress) {
|
||||
|
||||
VIDEO_WaitVSync ();
|
||||
usleep(20000);
|
||||
|
||||
GameInstallProgress();
|
||||
|
||||
@ -325,7 +325,8 @@ void ProgressStop() {
|
||||
* Callbackfunction for updating the progress values
|
||||
* 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)
|
||||
return;
|
||||
|
||||
@ -342,37 +343,38 @@ void ShowProgress(const char *title, const char *msg1, char *dynmsg2, f32 done,
|
||||
if (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) {
|
||||
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);
|
||||
}
|
||||
|
||||
@ -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);
|
||||
else
|
||||
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;
|
||||
progressDone = 100.0*done/total;
|
||||
changed = true;
|
||||
|
||||
LWP_ResumeThread(progressthread);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "libwiigui/gui.h"
|
||||
#include "prompts/PromptWindows.h"
|
||||
#include "prompts/ProgressWindow.h"
|
||||
#include "homebrewboot/HomebrewBrowse.h"
|
||||
#include "network/networkops.h"
|
||||
#include "themes/Theme_List.h"
|
||||
#include "menu.h"
|
||||
@ -68,9 +69,9 @@ bool DownloadTheme(const char *url, const char *title)
|
||||
|
||||
u32 done = 0;
|
||||
|
||||
int blocksize = 1024;
|
||||
int blocksize = 1024*5;
|
||||
|
||||
u8 *buffer = (u8*) malloc(blocksize);
|
||||
u8 *buffer = new u8[blocksize];
|
||||
|
||||
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"));
|
||||
return false;
|
||||
}
|
||||
else if (ret == 0)
|
||||
break;
|
||||
|
||||
fwrite(buffer, 1, blocksize, file);
|
||||
|
||||
done += ret;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
delete [] buffer;
|
||||
fclose(file);
|
||||
|
||||
ProgressStop();
|
||||
|
||||
if(done != (u32) filesize)
|
||||
{
|
||||
remove(filepath);
|
||||
WindowPrompt(tr("Download failed."), tr("Connection lost..."), tr("OK"));
|
||||
return false;
|
||||
}
|
||||
|
||||
ZipFile zipfile(filepath);
|
||||
|
||||
bool result = zipfile.ExtractAll(path);
|
||||
@ -249,10 +259,10 @@ int Theme_Downloader()
|
||||
{
|
||||
int pagesize = 4;
|
||||
int menu = MENU_NONE;
|
||||
bool pagechanged = 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 ***/
|
||||
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume);
|
||||
@ -388,18 +398,6 @@ int Theme_Downloader()
|
||||
PageIndicatorBtn.SetTrigger(&trigA);
|
||||
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);
|
||||
if (Settings.wsprompt == yes)
|
||||
{
|
||||
@ -426,7 +424,30 @@ int Theme_Downloader()
|
||||
char url[300];
|
||||
int currentpage = 1;
|
||||
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)
|
||||
{
|
||||
@ -438,202 +459,145 @@ int Theme_Downloader()
|
||||
w.Append(&GoLeftBtn);
|
||||
w.Append(&GoRightBtn);
|
||||
w.Append(&PageIndicatorBtn);
|
||||
w.Append(&PageIndicator2Btn);
|
||||
w.Append(&wifiBtn);
|
||||
w.Append(&HomeBtn);
|
||||
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);
|
||||
PageindicatorTxt.SetText(url);
|
||||
|
||||
int SitePageCount = Theme->GetSitepageCount();
|
||||
int ThemesOnPage = Theme->GetThemeCount();
|
||||
int n = 0;
|
||||
|
||||
pagechanged = false;
|
||||
|
||||
if(!ThemesOnPage)
|
||||
for(int i = currenttheme; (i < (currenttheme+pagesize)); i++)
|
||||
{
|
||||
WindowPrompt(tr("No themes found on the site."), 0, "OK");
|
||||
pagechanged = true;
|
||||
menu = MENU_SETTINGS;
|
||||
ShowProgress(tr("Downloading image:"), 0, (char *) Theme->GetThemeTitle(i), n, pagesize);
|
||||
|
||||
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();
|
||||
w.RemoveAll();
|
||||
w.Append(&background);
|
||||
w.Append(&titleTxt);
|
||||
w.Append(&backBtn);
|
||||
w.Append(&GoLeftBtn);
|
||||
w.Append(&GoRightBtn);
|
||||
w.Append(&PageIndicatorBtn);
|
||||
w.Append(&PageIndicator2Btn);
|
||||
w.Append(&wifiBtn);
|
||||
w.Append(&HomeBtn);
|
||||
ResumeGui();
|
||||
if(MainButtonTxt[i])
|
||||
w.Append(MainButton[i]);
|
||||
}
|
||||
ResumeGui();
|
||||
|
||||
sprintf(url, "%i", currentloaderpage);
|
||||
Pageindicator2Txt.SetText(url);
|
||||
listchanged = false;
|
||||
|
||||
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);
|
||||
|
||||
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)
|
||||
Initialize_Network();
|
||||
wifiBtn.ResetState();
|
||||
}
|
||||
else if (backBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
listchanged = true;
|
||||
menu = MENU_SETTINGS;
|
||||
backBtn.ResetState();
|
||||
break;
|
||||
}
|
||||
else if (GoRightBtn.GetState() == STATE_CLICKED)
|
||||
{
|
||||
listchanged = true;
|
||||
currenttheme += pagesize;
|
||||
currentpage++;
|
||||
if(currenttheme >= 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);
|
||||
|
||||
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]);
|
||||
currentpage = 1;
|
||||
currenttheme = 0;
|
||||
}
|
||||
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++)
|
||||
{
|
||||
if(MainButtonTxt[i])
|
||||
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)
|
||||
if(MainButton[i]->GetState() == STATE_CLICKED)
|
||||
{
|
||||
Initialize_Network();
|
||||
wifiBtn.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();
|
||||
}
|
||||
snprintf(url, sizeof(url), "%s", Theme->GetDownloadLink(currenttheme+i));
|
||||
Theme_Prompt(Theme->GetThemeTitle(currenttheme+i), Theme->GetThemeAuthor(currenttheme+i), ImageData[i], url);
|
||||
MainButton[i]->ResetState();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,251 +1,242 @@
|
||||
/***************************************************************************
|
||||
* 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"
|
||||
|
||||
#define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp))
|
||||
|
||||
static void copyhtmlsting(const char *from, char *outtext, const char *stopat, u32 &cnt)
|
||||
{
|
||||
u32 cnt2 = 0;
|
||||
|
||||
u32 stringlength = strlen(from);
|
||||
|
||||
while ((stringcompare(from, stopat, cnt+strlen(stopat)) != 0) && (cnt2 < 1024) && (cnt < stringlength))
|
||||
{
|
||||
outtext[cnt2] = from[cnt];
|
||||
cnt2++;
|
||||
cnt++;
|
||||
}
|
||||
outtext[cnt2] = '\0';
|
||||
}
|
||||
|
||||
Theme_List::Theme_List(const char * url)
|
||||
{
|
||||
Theme = NULL;
|
||||
themescount = 0;
|
||||
sitepages = 0;
|
||||
|
||||
if (!IsNetworkInit())
|
||||
{
|
||||
themescount = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
struct block file = downloadfile(url);
|
||||
|
||||
if (!file.data || !file.size)
|
||||
{
|
||||
themescount = -2;
|
||||
return;
|
||||
}
|
||||
|
||||
u32 cnt = 0;
|
||||
char temp[1024];
|
||||
|
||||
Theme = (Theme_Info *) malloc(sizeof(Theme_Info));
|
||||
if (!Theme) {
|
||||
free(file.data);
|
||||
themescount = -3;
|
||||
return;
|
||||
}
|
||||
|
||||
memset(&Theme[themescount], 0, sizeof(Theme_Info));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Theme_List::~Theme_List()
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
if(Theme)
|
||||
free(Theme);
|
||||
Theme = NULL;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetThemeTitle(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].themetitle;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetThemeAuthor(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].author;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetImageLink(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].imagelink;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetDownloadLink(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].downloadlink;
|
||||
}
|
||||
|
||||
int Theme_List::GetThemeCount()
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
/***************************************************************************
|
||||
* 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"
|
||||
#include "prompts/PromptWindows.h"
|
||||
|
||||
#define stringcompare(text, cmp, pos) strncasecmp((const char*) &text[pos-strlen(cmp)], (const char*) cmp, strlen((const char*) cmp))
|
||||
|
||||
static void copyhtmlsting(const char *from, char *outtext, const char *stopat, u32 &cnt)
|
||||
{
|
||||
u32 cnt2 = 0;
|
||||
|
||||
u32 stringlength = strlen(from);
|
||||
|
||||
while ((stringcompare(from, stopat, cnt+strlen(stopat)) != 0) && (cnt2 < 1024) && (cnt < stringlength))
|
||||
{
|
||||
outtext[cnt2] = from[cnt];
|
||||
cnt2++;
|
||||
cnt++;
|
||||
}
|
||||
outtext[cnt2] = '\0';
|
||||
}
|
||||
|
||||
Theme_List::Theme_List(const char * url)
|
||||
{
|
||||
Theme = NULL;
|
||||
themescount = 0;
|
||||
|
||||
if (!IsNetworkInit())
|
||||
{
|
||||
themescount = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
struct block file = downloadfile(url);
|
||||
|
||||
if (!file.data || !file.size)
|
||||
{
|
||||
themescount = -2;
|
||||
return;
|
||||
}
|
||||
|
||||
themescount = CountThemes(file.data);
|
||||
if (themescount <= 0)
|
||||
{
|
||||
free(file.data);
|
||||
return;
|
||||
}
|
||||
|
||||
ParseXML(file.data);
|
||||
|
||||
free(file.data);
|
||||
}
|
||||
|
||||
Theme_List::~Theme_List()
|
||||
{
|
||||
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)
|
||||
delete [] Theme[i].imagelink;
|
||||
if(Theme[i].downloadlink)
|
||||
delete [] Theme[i].downloadlink;
|
||||
Theme[i].themetitle = NULL;
|
||||
Theme[i].author = NULL;
|
||||
Theme[i].imagelink = NULL;
|
||||
Theme[i].downloadlink = NULL;
|
||||
}
|
||||
|
||||
if(Theme)
|
||||
delete [] Theme;
|
||||
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)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].themetitle;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetThemeAuthor(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].author;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetImageLink(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].imagelink;
|
||||
}
|
||||
|
||||
const char * Theme_List::GetDownloadLink(int ind)
|
||||
{
|
||||
if (ind > themescount || ind < 0 || !Theme || themescount <= 0)
|
||||
return NULL;
|
||||
else
|
||||
return Theme[ind].downloadlink;
|
||||
}
|
||||
|
||||
int Theme_List::GetThemeCount()
|
||||
{
|
||||
return themescount;
|
||||
}
|
||||
|
||||
static int ListCompare(const void *a, const void *b)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -1,58 +1,55 @@
|
||||
/****************************************************************************
|
||||
* Theme_List Class
|
||||
* for USB Loader GX
|
||||
* by dimok
|
||||
***************************************************************************/
|
||||
#ifndef ___THEMELIST_H_
|
||||
#define ___THEMELIST_H_
|
||||
|
||||
#include "network/networkops.h"
|
||||
#include "network/http.h"
|
||||
|
||||
typedef struct _theme_info
|
||||
{
|
||||
char themetitle[100];
|
||||
char author[50];
|
||||
char *imagelink;
|
||||
char *downloadlink;
|
||||
bool direct[2];
|
||||
} Theme_Info;
|
||||
|
||||
|
||||
class Theme_List
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param url from where to get the list of links
|
||||
Theme_List(const char *url);
|
||||
//!Destructor
|
||||
~Theme_List();
|
||||
//! Get the a theme title
|
||||
//!\param list index
|
||||
const char * GetThemeTitle(int index);
|
||||
//! Get the author of the theme
|
||||
//!\param list index
|
||||
const char * GetThemeAuthor(int index);
|
||||
//! Get the author of the theme
|
||||
//!\param list index
|
||||
const char * GetImageLink(int index);
|
||||
//! Get the download link of the theme
|
||||
//!\param list 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
|
||||
int GetThemeCount();
|
||||
//! Get the number of pages counted on which there are Themes
|
||||
int GetSitepageCount();
|
||||
//! Sort list
|
||||
void SortList();
|
||||
protected:
|
||||
int themescount;
|
||||
int sitepages;
|
||||
Theme_Info *Theme;
|
||||
};
|
||||
|
||||
#endif
|
||||
/****************************************************************************
|
||||
* Theme_List Class
|
||||
* for USB Loader GX
|
||||
* by dimok
|
||||
***************************************************************************/
|
||||
#ifndef ___THEMELIST_H_
|
||||
#define ___THEMELIST_H_
|
||||
|
||||
#include "network/networkops.h"
|
||||
#include "network/http.h"
|
||||
|
||||
typedef struct _theme_info
|
||||
{
|
||||
char *themetitle;
|
||||
char *author;
|
||||
char *imagelink;
|
||||
char *downloadlink;
|
||||
u8 rating;
|
||||
} Theme_Info;
|
||||
|
||||
|
||||
class Theme_List
|
||||
{
|
||||
public:
|
||||
//!Constructor
|
||||
//!\param url from where to get the list of links
|
||||
Theme_List(const char *url);
|
||||
//!Destructor
|
||||
~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
|
||||
//!\param list index
|
||||
const char * GetThemeTitle(int index);
|
||||
//! Get the author of the theme
|
||||
//!\param list index
|
||||
const char * GetThemeAuthor(int index);
|
||||
//! Get the author of the theme
|
||||
//!\param list index
|
||||
const char * GetImageLink(int index);
|
||||
//! Get the download link of the theme
|
||||
//!\param list index
|
||||
const char * GetDownloadLink(int index);
|
||||
//! Get the number of links counted
|
||||
int GetThemeCount();
|
||||
//! Sort list
|
||||
void SortList();
|
||||
protected:
|
||||
int themescount;
|
||||
Theme_Info *Theme;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -61,7 +61,7 @@ static mxml_node_t *nodefound=NULL;
|
||||
static mxml_index_t *nodeindex=NULL;
|
||||
static mxml_index_t *nodeindextmp=NULL;
|
||||
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;
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *noden
|
||||
if (attributename != NULL) {
|
||||
strlcpy(dest,mxmlElementGetAttr(nodefound, attributename),destsize);
|
||||
} else {
|
||||
get_text(nodefound, element_text, sizeof(element_text));
|
||||
get_nodetext(nodefound, element_text, sizeof(element_text));
|
||||
strlcpy(dest,element_text,destsize);
|
||||
}
|
||||
} else {
|
||||
@ -308,7 +308,7 @@ void LoadTitlesFromXML(char *langtxt, bool forcejptoen)
|
||||
strcpy(title_text,"");
|
||||
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);
|
||||
|
||||
// if language is not forced, use game language setting from config
|
||||
@ -402,7 +402,7 @@ bool LoadGameInfoFromXML(char* gameid, char* langtxt)
|
||||
while (1) {
|
||||
nodeid = mxmlIndexFind(nodeindex,"id", 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)) {
|
||||
break;
|
||||
}
|
||||
@ -718,8 +718,8 @@ char *MemInfo() {
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* get_text() - 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 */
|
||||
/* get_nodetext() - Get the text for a node, taken from mini-mxml example mxmldoc.c */
|
||||
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 */
|
||||
int len; /* Length of node */
|
||||
mxml_node_t *current; /* Current node */
|
||||
@ -760,7 +760,7 @@ int GetRatingForGame(char *gameid)
|
||||
while (1) {
|
||||
nodeid = mxmlIndexFind(nodeindex,"id", 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)) {
|
||||
break;
|
||||
}
|
||||
|
@ -66,7 +66,8 @@ extern "C" {
|
||||
void GetTextFromNode(mxml_node_t *currentnode, mxml_node_t *topnode, char *nodename,
|
||||
char *attributename, char *value, int descend, char *dest, int destsize);
|
||||
int GetRatingForGame(char *gameid);
|
||||
|
||||
char * get_nodetext(mxml_node_t *node, char *buffer, int buflen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user