2009-06-01 17:50:18 +02:00
|
|
|
/****************************************************************************
|
2009-07-31 22:15:55 +02:00
|
|
|
* USB Loader GX Team
|
|
|
|
*
|
|
|
|
* Main loadup of the application
|
2009-06-01 17:50:18 +02:00
|
|
|
*
|
2009-07-31 22:15:55 +02:00
|
|
|
* libwiigui
|
|
|
|
* Tantric 2009
|
2009-06-01 17:50:18 +02:00
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2009-06-10 01:26:03 +02:00
|
|
|
#include <sys/dir.h>
|
2009-06-01 17:50:18 +02:00
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
|
2009-07-31 22:15:55 +02:00
|
|
|
#include "libwiigui/gui.h"
|
2009-07-30 07:41:12 +02:00
|
|
|
#include "usbloader/wbfs.h"
|
2009-06-13 02:24:36 +02:00
|
|
|
#include "settings/cfg.h"
|
2009-06-23 20:59:28 +02:00
|
|
|
#include "language/gettext.h"
|
2009-06-13 02:24:36 +02:00
|
|
|
#include "mload/mload.h"
|
2009-06-01 17:50:18 +02:00
|
|
|
#include "FreeTypeGX.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "audio.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "filelist.h"
|
2009-07-28 18:44:19 +02:00
|
|
|
#include "listfiles.h"
|
2009-06-01 17:50:18 +02:00
|
|
|
#include "main.h"
|
|
|
|
#include "fatmounter.h"
|
|
|
|
#include "sys.h"
|
|
|
|
#include "wpad.h"
|
|
|
|
#include "fat.h"
|
|
|
|
|
|
|
|
/* Constants */
|
|
|
|
#define CONSOLE_XCOORD 260
|
|
|
|
#define CONSOLE_YCOORD 115
|
|
|
|
#define CONSOLE_WIDTH 340
|
|
|
|
#define CONSOLE_HEIGHT 218
|
|
|
|
|
|
|
|
FreeTypeGX *fontSystem=0;
|
|
|
|
FreeTypeGX *fontClock=0;
|
|
|
|
|
2009-07-31 22:15:55 +02:00
|
|
|
static void BootUpProblems()
|
|
|
|
{
|
|
|
|
s32 ret2;
|
|
|
|
|
|
|
|
// load main font from file, or default to built-in font
|
|
|
|
fontSystem = new FreeTypeGX();
|
|
|
|
fontSystem->loadFont(NULL, font_ttf, font_ttf_size, 0);
|
|
|
|
fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
|
|
|
|
|
|
|
GuiImageData bootimageData(gxlogo_png);
|
|
|
|
GuiImage bootimage(&bootimageData);
|
|
|
|
GuiText boottext(NULL, 20, (GXColor) {255, 255, 255, 255});
|
|
|
|
boottext.SetPosition(200, 240-1.2*bootimage.GetHeight()/2+250);
|
|
|
|
bootimage.SetPosition(320-1.2*bootimage.GetWidth()/2, 240-1.2*bootimage.GetHeight()/2);
|
|
|
|
bootimage.SetScale(1.2);
|
|
|
|
|
2009-09-19 12:38:21 +02:00
|
|
|
GuiImageData usbimageData(usbport_png);
|
|
|
|
GuiImage usbimage(&usbimageData);
|
|
|
|
usbimage.SetPosition(400,300);
|
|
|
|
usbimage.SetScale(.7);
|
|
|
|
usbimage.SetAlpha(200);
|
|
|
|
|
2009-08-20 00:25:42 +02:00
|
|
|
time_t curtime;
|
|
|
|
time_t endtime = time(0) + 30;
|
|
|
|
do {
|
|
|
|
ret2 = IOS_ReloadIOS(249);
|
|
|
|
if (ret2 < 0) {
|
|
|
|
ret2 = IOS_ReloadIOS(222);
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_Init();
|
2009-08-20 00:25:42 +02:00
|
|
|
load_ehc_module();
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_deInit();
|
2009-08-20 00:25:42 +02:00
|
|
|
if(ret2 <0) {
|
|
|
|
boottext.SetText("ERROR: cIOS could not be loaded!");
|
|
|
|
bootimage.Draw();
|
|
|
|
boottext.Draw();
|
|
|
|
Menu_Render();
|
|
|
|
sleep(5);
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret2 = WBFS_Init(WBFS_DEVICE_USB);
|
|
|
|
if (ret2 >= 0) {
|
|
|
|
boottext.SetText("Loading...");
|
|
|
|
bootimage.Draw();
|
|
|
|
boottext.Draw();
|
|
|
|
Menu_Render();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
curtime = time(0);
|
|
|
|
boottext.SetTextf("Waiting for your slow USB Device: %i secs...", int(endtime-curtime));
|
|
|
|
while(curtime == time(0)) {
|
|
|
|
boottext.Draw();
|
|
|
|
bootimage.Draw();
|
2009-09-19 12:38:21 +02:00
|
|
|
if (endtime-curtime<15)usbimage.Draw();
|
2009-08-20 00:25:42 +02:00
|
|
|
Menu_Render();
|
|
|
|
}
|
|
|
|
} while((endtime-time(0)) > 0);
|
2009-07-31 22:15:55 +02:00
|
|
|
|
|
|
|
if(ret2 < 0) {
|
2009-08-06 13:09:20 +02:00
|
|
|
boottext.SetText("ERROR: USB device could not be loaded!");
|
2009-09-19 12:38:21 +02:00
|
|
|
usbimage.Draw();
|
2009-07-31 22:15:55 +02:00
|
|
|
bootimage.Draw();
|
|
|
|
boottext.Draw();
|
|
|
|
Menu_Render();
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
///delete font to load up custom if set
|
|
|
|
if(fontSystem) {
|
|
|
|
delete fontSystem;
|
|
|
|
fontSystem = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-01 17:50:18 +02:00
|
|
|
int
|
2009-07-30 07:41:12 +02:00
|
|
|
main(int argc, char *argv[]) {
|
2009-07-31 22:15:55 +02:00
|
|
|
|
|
|
|
s32 ret;
|
|
|
|
bool startupproblem = false;
|
2009-07-30 07:41:12 +02:00
|
|
|
|
|
|
|
bool bootDevice_found=false;
|
|
|
|
if (argc >= 1) {
|
|
|
|
if (!strncasecmp(argv[0], "usb:/", 5)) {
|
|
|
|
strcpy(bootDevice, "USB:");
|
|
|
|
bootDevice_found = true;
|
|
|
|
} else if (!strncasecmp(argv[0], "sd:/", 4))
|
|
|
|
bootDevice_found = true;
|
|
|
|
}
|
2009-06-01 17:50:18 +02:00
|
|
|
|
2009-07-31 22:15:55 +02:00
|
|
|
/** PAD_Init has to be before InitVideo don't move that **/
|
|
|
|
PAD_Init(); // initialize PAD/WPAD
|
2009-09-30 05:57:15 +02:00
|
|
|
|
|
|
|
USBDevice_deInit();// seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5")
|
|
|
|
|
2009-07-31 22:15:55 +02:00
|
|
|
ret = IOS_ReloadIOS(249);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
ret = IOS_ReloadIOS(222);
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_Init();
|
2009-07-30 07:41:12 +02:00
|
|
|
load_ehc_module();
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_deInit();
|
2009-07-31 22:15:55 +02:00
|
|
|
if(ret <0) {
|
2009-08-06 13:09:20 +02:00
|
|
|
printf("\n\tERROR: cIOS could not be loaded!\n");
|
2009-07-31 22:15:55 +02:00
|
|
|
sleep(5);
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = WBFS_Init(WBFS_DEVICE_USB);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
ret = IOS_ReloadIOS(222);
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_Init();
|
2009-07-31 22:15:55 +02:00
|
|
|
load_ehc_module();
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_deInit();
|
2009-07-31 23:16:02 +02:00
|
|
|
if(ret < 0) {
|
|
|
|
InitVideo(); // Initialise video
|
|
|
|
Menu_Render();
|
|
|
|
BootUpProblems();
|
|
|
|
startupproblem = true;
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = WBFS_Init(WBFS_DEVICE_USB);
|
|
|
|
|
|
|
|
if(ret < 0) {
|
|
|
|
InitVideo(); // Initialise video
|
|
|
|
Menu_Render();
|
|
|
|
BootUpProblems();
|
|
|
|
startupproblem = true;
|
|
|
|
ret = 1;
|
2009-07-31 22:15:55 +02:00
|
|
|
}
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SDCard_Init(); // mount SD for loading cfg's
|
|
|
|
USBDevice_Init(); // and mount USB:/
|
|
|
|
|
|
|
|
if (!bootDevice_found) {
|
|
|
|
//try USB
|
|
|
|
//left in all the dol and elf files in this check in case this is the first time running the app and they dont have the config
|
|
|
|
if (checkfile((char*) "USB:/config/GXglobal.cfg") || (checkfile((char*) "USB:/apps/usbloader_gx/boot.elf"))
|
|
|
|
|| checkfile((char*) "USB:/apps/usbloadergx/boot.dol") || (checkfile((char*) "USB:/apps/usbloadergx/boot.elf"))
|
|
|
|
|| checkfile((char*) "USB:/apps/usbloader_gx/boot.dol"))
|
|
|
|
strcpy(bootDevice, "USB:");
|
|
|
|
}
|
|
|
|
|
|
|
|
gettextCleanUp();
|
|
|
|
CFG_Load();
|
2009-05-03 20:53:31 +02:00
|
|
|
|
|
|
|
/* Load Custom IOS */
|
2009-07-30 07:41:12 +02:00
|
|
|
if (Settings.cios == ios222 && IOS_GetVersion() != 222) {
|
2009-07-06 01:01:29 +02:00
|
|
|
SDCard_deInit();// unmount SD for reloading IOS
|
|
|
|
USBDevice_deInit();// unmount USB for reloading IOS
|
2009-07-31 22:15:55 +02:00
|
|
|
ret = IOS_ReloadIOS(222);
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_Init();
|
2009-06-13 02:24:36 +02:00
|
|
|
load_ehc_module();
|
2009-07-31 22:15:55 +02:00
|
|
|
if (ret < 0) {
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_deInit();
|
2009-05-03 20:53:31 +02:00
|
|
|
Settings.cios = ios249;
|
2009-07-31 22:15:55 +02:00
|
|
|
ret = IOS_ReloadIOS(249);
|
2009-05-03 20:53:31 +02:00
|
|
|
}
|
2009-07-06 01:01:29 +02:00
|
|
|
SDCard_Init(); // now mount SD:/
|
|
|
|
USBDevice_Init(); // and mount USB:/
|
2009-07-30 07:41:12 +02:00
|
|
|
} else if (Settings.cios == ios249 && IOS_GetVersion() != 249) {
|
2009-07-06 01:01:29 +02:00
|
|
|
SDCard_deInit();// unmount SD for reloading IOS
|
|
|
|
USBDevice_deInit();// unmount USB for reloading IOS
|
2009-07-31 22:15:55 +02:00
|
|
|
ret = IOS_ReloadIOS(249);
|
|
|
|
if (ret < 0) {
|
2009-07-06 01:01:29 +02:00
|
|
|
Settings.cios = ios222;
|
2009-07-31 22:15:55 +02:00
|
|
|
ret = IOS_ReloadIOS(222);
|
2009-09-30 05:57:15 +02:00
|
|
|
SDCard_Init();
|
2009-07-06 01:01:29 +02:00
|
|
|
load_ehc_module();
|
2009-07-30 07:41:12 +02:00
|
|
|
}
|
2009-07-06 01:01:29 +02:00
|
|
|
SDCard_Init(); // now mount SD:/
|
|
|
|
USBDevice_Init(); // and mount USB:/
|
2009-09-30 05:57:15 +02:00
|
|
|
}
|
2009-06-01 17:50:18 +02:00
|
|
|
|
2009-07-31 22:15:55 +02:00
|
|
|
if (ret < 0) {
|
2009-08-06 13:09:20 +02:00
|
|
|
printf("ERROR: cIOS could not be loaded!");
|
2009-07-30 07:41:12 +02:00
|
|
|
sleep(5);
|
|
|
|
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
|
|
|
|
}
|
2009-06-01 17:50:18 +02:00
|
|
|
|
2009-07-31 22:15:55 +02:00
|
|
|
//! Init the rest of the System
|
2009-07-30 07:41:12 +02:00
|
|
|
Sys_Init();
|
|
|
|
Wpad_Init();
|
2009-07-31 22:15:55 +02:00
|
|
|
if(!startupproblem)
|
|
|
|
InitVideo();
|
2009-07-30 07:41:12 +02:00
|
|
|
InitAudio(); // Initialize audio
|
2009-07-28 18:44:19 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR);
|
|
|
|
WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight);
|
2009-06-15 17:37:18 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
// load main font from file, or default to built-in font
|
|
|
|
fontSystem = new FreeTypeGX();
|
|
|
|
char *fontPath = NULL;
|
|
|
|
asprintf(&fontPath, "%sfont.ttf", CFG.theme_path);
|
|
|
|
fontSystem->loadFont(fontPath, font_ttf, font_ttf_size, 0);
|
|
|
|
fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
|
|
|
free(fontPath);
|
2009-06-01 17:50:18 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
fontClock = new FreeTypeGX();
|
|
|
|
fontClock->loadFont(NULL, clock_ttf, clock_ttf_size, 0);
|
|
|
|
fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE);
|
2009-06-01 17:50:18 +02:00
|
|
|
|
2009-07-30 07:41:12 +02:00
|
|
|
InitGUIThreads();
|
|
|
|
MainMenu(MENU_CHECK);
|
|
|
|
return 0;
|
2009-06-01 17:50:18 +02:00
|
|
|
}
|
2009-07-06 01:01:29 +02:00
|
|
|
|