From 904fda37d4b15ff6aa7383d3e15810f81c74bdcf Mon Sep 17 00:00:00 2001 From: "ardi@ist-einmalig.de" Date: Mon, 1 Jun 2009 15:50:18 +0000 Subject: [PATCH] NOTE: this commit requires "make clean" and the new libfat (see Downloads libfat-01-06-2009) * clean up the wild mounts and unmounts (this and the new libfat fix the download-bug) * reorganize shutdowns and reboots use now the functions Sys_Reboot(), Sys_Shutdown(), Sys_ShutdownToIdel(), Sys_ShutdownToStandby() and Sys_BackToLoader() this functions stops the GUI-Thread, Shutdowns the Audio, Video, WPad and unmounts the SD and USB --- source/fatmounter.c | 47 +-- source/fst.c | 6 +- source/libwiigui/gui_customoptionbrowser.h | 1 - source/main.cpp | 274 ++++++------- source/main.h | 2 - source/menu.cpp | 452 ++++++++++----------- source/menu.h | 11 +- source/{sys.c => sys.cpp} | 81 +++- source/sys.h | 9 +- 9 files changed, 457 insertions(+), 426 deletions(-) rename source/{sys.c => sys.cpp} (60%) diff --git a/source/fatmounter.c b/source/fatmounter.c index c41f79f6..d1cdf513 100644 --- a/source/fatmounter.c +++ b/source/fatmounter.c @@ -1,33 +1,31 @@ #include #include +#include #include #include #include #include #include -#define CACHE 32 -#define SECTORS 128 +#define CACHE 4 +#define SECTORS 64 int USBDevice_Init() { - //right now only mounts first partition and only under IOS36 - __io_usbstorage.startup(); - - if (fatMount("USB", &__io_usbstorage, 0, CACHE, SECTORS)) { - return 1; - } - -return -1; + //closing all open Files write back the cache and then shutdown em! + fatUnmount("USB:/"); + //right now only mounts first partition + if (fatMount("USB", &__io_usbstorage, 0, CACHE, SECTORS)) { + return 1; + } + return -1; } void USBDevice_deInit() { - //First unmount all the devs... - fatUnmount("USB:/"); - //...and then shutdown em! - __io_usbstorage.shutdown(); + //closing all open Files write back the cache and then shutdown em! + fatUnmount("USB:/"); } int isSdInserted() @@ -37,21 +35,16 @@ int isSdInserted() int SDCard_Init() { - //mount SD if inserted - __io_wiisd.startup(); - if (!isSdInserted()){ - return -1; - } - if (fatMount("SD", &__io_wiisd, 0, CACHE, SECTORS)) { - return 1; - } -return -1; + //closing all open Files write back the cache and then shutdown em! + fatUnmount("SD:/"); + //right now only mounts first partition + if (fatMount("SD", &__io_wiisd, 0, CACHE, SECTORS)) + return 1; + return -1; } void SDCard_deInit() { - //First unmount all the devs... - fatUnmount("SD:/"); - //...and then shutdown em! - __io_wiisd.shutdown(); + //closing all open Files write back the cache and then shutdown em! + fatUnmount("SD:/"); } diff --git a/source/fst.c b/source/fst.c index d73235b7..18770a8e 100644 --- a/source/fst.c +++ b/source/fst.c @@ -73,7 +73,7 @@ u32 do_sd_code(char *filename) fp = fopen(filepath, "rb"); if (!fp) { - fatUnmount("SD"); + fatUnmount("SD:/"); __io_wiisd.shutdown(); return 0; } @@ -93,7 +93,7 @@ u32 do_sd_code(char *filename) if(ret != filesize){ free(filebuff); fclose(fp); - fatUnmount("SD"); + fatUnmount("SD:/"); __io_wiisd.shutdown(); return 0; } @@ -106,7 +106,7 @@ u32 do_sd_code(char *filename) free(filebuff); fclose(fp); - fatUnmount("SD"); + fatUnmount("SD:/"); __io_wiisd.shutdown(); return 1; diff --git a/source/libwiigui/gui_customoptionbrowser.h b/source/libwiigui/gui_customoptionbrowser.h index 1ba29893..3a6be5e3 100644 --- a/source/libwiigui/gui_customoptionbrowser.h +++ b/source/libwiigui/gui_customoptionbrowser.h @@ -1,5 +1,4 @@ #include "gui.h" -extern int SetValue(int i, const char *format, ...) __attribute__((format(printf,2,3))); class customOptionList { public: diff --git a/source/main.cpp b/source/main.cpp index dd588b51..6d9bcf2f 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,130 +1,117 @@ -/**************************************************************************** - * libwiigui Template - * Tantric 2009 - * - * demo.cpp - * Basic template/demonstration of libwiigui capabilities. For a - * full-featured app using many more extensions, check out Snes9x GX. - ***************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include - -#include "FreeTypeGX.h" -#include "video.h" -#include "audio.h" -#include "menu.h" -#include "input.h" -#include "filelist.h" -#include "main.h" -#include "http.h" -#include "dns.h" -#include "fatmounter.h" -#include "disc.h" -#include "wbfs.h" -#include "sys.h" -#include "video2.h" -#include "wpad.h" -#include "cfg.h" -#include "language.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; -int ExitRequested = 0; -bool netcheck = false; - - -/*Networking - Forsaekn*/ -int Net_Init(char *ip){ - - s32 res; - while ((res = net_init()) == -EAGAIN) - { - usleep(100 * 1000); //100ms - } - - if (if_config(ip, NULL, NULL, true) < 0) { - printf(" Error reading IP address, exiting"); - usleep(1000 * 1000 * 1); //1 sec - return FALSE; - } - return TRUE; -} - -void ExitApp() -{ - ShutoffRumble(); - StopGX(); - ShutdownAudio(); +/**************************************************************************** + * libwiigui Template + * Tantric 2009 + * + * demo.cpp + * Basic template/demonstration of libwiigui capabilities. For a + * full-featured app using many more extensions, check out Snes9x GX. + ***************************************************************************/ - if(isSdInserted()) - SDCard_deInit(); - - //WPAD_Flush(0); - //WPAD_Disconnect(0); - //WPAD_Shutdown(); - //exit(0); -} - -void -DefaultSettings() -{ - Settings.video = discdefault; - Settings.vpatch = off; - Settings.language = ConsoleLangDefault; - Settings.ocarina = off; - Settings.hddinfo = hr12; - Settings.sinfo = ((THEME.showID) ? GameID : Neither); - Settings.rumble = RumbleOn; - if (THEME.showRegion) - { - Settings.sinfo = ((Settings.sinfo == GameID) ? Both : GameRegion); - } - Settings.volume = v80; - Settings.tooltips = TooltipsOn; - snprintf(Settings.unlockCode, sizeof(Settings.unlockCode), "ab121b"); - Settings.parentalcontrol = 0; - Settings.cios = ios249; - Settings.xflip = no; +#include +#include +#include +#include +#include +#include +#include + +#include "FreeTypeGX.h" +#include "video.h" +#include "audio.h" +#include "menu.h" +#include "input.h" +#include "filelist.h" +#include "main.h" +#include "http.h" +#include "dns.h" +#include "fatmounter.h" +#include "disc.h" +#include "wbfs.h" +#include "sys.h" +#include "video2.h" +#include "wpad.h" +#include "cfg.h" +#include "language.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; +bool netcheck = false; + + +/*Networking - Forsaekn*/ +int Net_Init(char *ip){ + + s32 res; + while ((res = net_init()) == -EAGAIN) + { + usleep(100 * 1000); //100ms + } + + if (if_config(ip, NULL, NULL, true) < 0) { + printf(" Error reading IP address, exiting"); + usleep(1000 * 1000 * 1); //1 sec + return FALSE; + } + return TRUE; +} + +void +DefaultSettings() +{ + Settings.video = discdefault; + Settings.vpatch = off; + Settings.language = ConsoleLangDefault; + Settings.ocarina = off; + Settings.hddinfo = hr12; + Settings.sinfo = ((THEME.showID) ? GameID : Neither); + Settings.rumble = RumbleOn; + if (THEME.showRegion) + { + Settings.sinfo = ((Settings.sinfo == GameID) ? Both : GameRegion); + } + Settings.volume = v80; + Settings.tooltips = TooltipsOn; + snprintf(Settings.unlockCode, sizeof(Settings.unlockCode), "ab121b"); + Settings.parentalcontrol = 0; + Settings.cios = ios249; + Settings.xflip = no; Settings.qboot = no; Settings.unicodefix = 0; Settings.wiilight = 1; Settings.patchcountrystrings = 0; - - CFG_LoadGlobal(); -} - - -int -main(int argc, char *argv[]) -{ - + + CFG_LoadGlobal(); +} + +// check for libfat.a from 1. Jun 2009 +extern int LibFat4USB_Loader_GX; +int fatCheck = LibFat4USB_Loader_GX; // remove when libfat newer than 1. Jun 2009 + +int +main(int argc, char *argv[]) +{ + s32 ret2; - - SDCard_Init(); + + SDCard_Init(); // mount SD for loading cfg's lang_default(); CFG_Load(); - DefaultSettings(); + DefaultSettings(); - SDCard_deInit(); + SDCard_deInit();// unmount SD for reloading IOS /* Load Custom IOS */ - if(Settings.cios == ios222) { + if(Settings.cios == ios222) { ret2 = IOS_ReloadIOS(222); if (ret2 < 0) { Settings.cios = ios249; @@ -133,33 +120,34 @@ main(int argc, char *argv[]) } else { ret2 = IOS_ReloadIOS(249); } - - if (ret2 < 0) { - printf("ERROR: cIOS could not be loaded!"); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + + if (ret2 < 0) { + printf("ERROR: cIOS could not be loaded!"); + SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } - - SDCard_Init(); - - Sys_Init(); - //Video_SetMode(); - //Con_Init(CONSOLE_XCOORD, CONSOLE_YCOORD, CONSOLE_WIDTH, CONSOLE_HEIGHT); - //Wpad_Init(); - - PAD_Init(); - InitVideo(); // Initialise video - InitAudio(); // Initialize audio - - - fontSystem = new FreeTypeGX(); - fontSystem->loadFont(font_ttf, font_ttf_size, 0); - fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); - - fontClock = new FreeTypeGX(); - fontClock->loadFont(clock_ttf, clock_ttf_size, 0); - fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); - - InitGUIThreads(); - MainMenu(MENU_CHECK); - return 0; -} + + SDCard_Init(); // now mount SD:/ + USBDevice_Init(); // and mount USB:/ + + Sys_Init(); + + InitVideo(); // Initialise video + InitAudio(); // Initialize audio + + PAD_Init(); // initialize PAD/WPAD + Wpad_Init(); + WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); + WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); + + fontSystem = new FreeTypeGX(); + fontSystem->loadFont(font_ttf, font_ttf_size, 0); + fontSystem->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); + + fontClock = new FreeTypeGX(); + fontClock->loadFont(clock_ttf, clock_ttf_size, 0); + fontClock->setCompatibilityMode(FTGX_COMPATIBILITY_DEFAULT_TEVOP_GX_PASSCLR | FTGX_COMPATIBILITY_DEFAULT_VTXDESC_GX_NONE); + + InitGUIThreads(); + MainMenu(MENU_CHECK); + return 0; +} diff --git a/source/main.h b/source/main.h index 14755619..ac66d5d8 100644 --- a/source/main.h +++ b/source/main.h @@ -12,9 +12,7 @@ extern struct SSettings Settings; -void ExitApp(); void DefaultSettings(); -extern int ExitRequested; extern FreeTypeGX *fontSystem; extern bool netcheck; extern int Net_Init(char *ip); diff --git a/source/menu.cpp b/source/menu.cpp index e812567b..ace8cdbc 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -19,6 +19,7 @@ #include "libwiigui/gui.h" #include "menu.h" #include "main.h" +#include "audio.h" #include "input.h" #include "http.h" #include "dns.h" @@ -66,6 +67,7 @@ static s32 gameSelected = 0, gameStart = 0; static GuiWindow * mainWindow = NULL; static lwp_t guithread = LWP_THREAD_NULL; static bool guiHalt = true; +static int ExitRequested = 0; static GuiImageData progressbar(progressbar_png); static GuiImage progressbarImg(&progressbar); int godmode = 0; @@ -404,15 +406,15 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, dialogBoxImg.SetWidescreen(CFG.widescreen); } - GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,55); - GuiText msgTxt(msg, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msgTxt(msg, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); msgTxt.SetPosition(0,-40); msgTxt.SetMaxWidth(430); - GuiText btn1Txt(btn1Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn1Txt(btn1Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn1Img(&btnOutline); if (Settings.wsprompt == yes){ btn1Txt.SetWidescreen(CFG.widescreen); @@ -423,7 +425,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, btn1.SetLabel(&btn1Txt); btn1.SetState(STATE_SELECTED); - GuiText btn2Txt(btn2Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn2Txt(btn2Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn2Img(&btnOutline); if (Settings.wsprompt == yes){ btn2Txt.SetWidescreen(CFG.widescreen); @@ -434,7 +436,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, if(!btn3Label && !btn4Label) btn2.SetTrigger(&trigB); - GuiText btn3Txt(btn3Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn3Txt(btn3Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn3Img(&btnOutline); if (Settings.wsprompt == yes){ btn3Txt.SetWidescreen(CFG.widescreen); @@ -445,7 +447,7 @@ WindowPrompt(const char *title, const char *msg, const char *btn1Label, if(!btn4Label) btn3.SetTrigger(&trigB); - GuiText btn4Txt(btn4Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn4Txt(btn4Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn4Img(&btnOutline); if (Settings.wsprompt == yes){ btn4Txt.SetWidescreen(CFG.widescreen); @@ -985,7 +987,7 @@ int GameWindowPrompt() GuiTooltip nameBtnTT(LANGUAGE.RenameGameonWBFS); if (Settings.wsprompt == yes) nameBtnTT.SetWidescreen(CFG.widescreen); - GuiText nameTxt("", 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{50, 50, 50, 255}); + GuiText nameTxt("", 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); if (Settings.wsprompt == yes) nameTxt.SetWidescreen(CFG.widescreen); nameTxt.SetMaxWidth(350, GuiText::SCROLL); @@ -1003,7 +1005,7 @@ int GameWindowPrompt() nameBtn.SetEffectGrow(); } - GuiText sizeTxt(NULL, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{50, 50, 50, 255}); //TODO: get the size here + GuiText sizeTxt(NULL, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //TODO: get the size here sizeTxt.SetAlignment(ALIGN_RIGHT, ALIGN_TOP); sizeTxt.SetPosition(-60,70); @@ -1033,7 +1035,7 @@ int GameWindowPrompt() btn1.SetTrigger(&trigA); btn1.SetState(STATE_SELECTED); - GuiText btn2Txt(LANGUAGE.Back, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn2Txt(LANGUAGE.Back, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn2Img(&btnOutline); if (Settings.wsprompt == yes){ btn2Txt.SetWidescreen(CFG.widescreen); @@ -1054,7 +1056,7 @@ int GameWindowPrompt() btn2.SetLabel(&btn2Txt); btn2.SetTrigger(&trigB); - GuiText btn3Txt(LANGUAGE.settings, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn3Txt(LANGUAGE.settings, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn3Img(&btnOutline); if (Settings.wsprompt == yes){ btn3Txt.SetWidescreen(CFG.widescreen); @@ -1454,15 +1456,15 @@ DiscWait(const char *title, const char *msg, const char *btn1Label, const char * dialogBoxImg.SetWidescreen(CFG.widescreen); } - GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,60); - GuiText msgTxt(msg, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msgTxt(msg, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); msgTxt.SetPosition(0,-40); msgTxt.SetMaxWidth(430); - GuiText btn1Txt(btn1Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn1Txt(btn1Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn1Img(&btnOutline); if (Settings.wsprompt == yes){ btn1Txt.SetWidescreen(CFG.widescreen); @@ -1485,7 +1487,7 @@ DiscWait(const char *title, const char *msg, const char *btn1Label, const char * btn1.SetTrigger(&trigB); btn1.SetState(STATE_SELECTED); - GuiText btn2Txt(btn2Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn2Txt(btn2Label, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn2Img(&btnOutline); if (Settings.wsprompt == yes){ btn2Txt.SetWidescreen(CFG.widescreen); @@ -1509,7 +1511,7 @@ DiscWait(const char *title, const char *msg, const char *btn1Label, const char * } } - GuiText timerTxt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText timerTxt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); timerTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); timerTxt.SetPosition(0,160); @@ -1531,12 +1533,10 @@ DiscWait(const char *title, const char *msg, const char *btn1Label, const char * mainWindow->ChangeFocus(&promptWindow); ResumeGui(); - SDCard_deInit(); - if(IsDeviceWait) { while(i >= 0) { - timerTxt.SetTextf("%u%s", i,LANGUAGE.secondsleft); + timerTxt.SetTextf("%u %s", i,LANGUAGE.secondsleft); VIDEO_WaitVSync(); if(Settings.cios == ios222) { ret = IOS_ReloadIOS(222); @@ -1599,7 +1599,7 @@ FormatingPartition(const char *title, partitionEntry *entry) dialogBoxImg.SetWidescreen(CFG.widescreen); } - GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,60); @@ -1657,16 +1657,16 @@ int NetworkInitPromp(int choice2) dialogBoxImg.SetWidescreen(CFG.widescreen); } - GuiText titleTxt(LANGUAGE.InitializingNetwork, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(LANGUAGE.InitializingNetwork, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,60); char msg[20] = " "; - GuiText msgTxt(msg, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msgTxt(msg, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); msgTxt.SetPosition(0,-40); - GuiText btn1Txt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn1Txt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn1Img(&btnOutline); if (Settings.wsprompt == yes){ btn1Txt.SetWidescreen(CFG.widescreen); @@ -1869,14 +1869,14 @@ ProgressWindow(const char *title, const char *msg) progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); progressbarImg.SetPosition(25, 40); - GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,60); - GuiText msgTxt(msg, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msgTxt(msg, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); msgTxt.SetPosition(0,120); - GuiText prsTxt("%", 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText prsTxt("%", 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); prsTxt.SetAlignment(ALIGN_RIGHT, ALIGN_MIDDLE); prsTxt.SetPosition(-188,40); @@ -1989,22 +1989,22 @@ ProgressDownloadWindow(int choice2) progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); progressbarImg.SetPosition(25, 40); - GuiText titleTxt(LANGUAGE.Downloadingfile, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(LANGUAGE.Downloadingfile, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,60); - GuiText msgTxt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msgTxt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); msgTxt.SetPosition(0,130); - GuiText msg2Txt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msg2Txt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); msg2Txt.SetPosition(0,100); prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); prTxt.SetPosition(0, 40); - GuiText btn1Txt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn1Txt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn1Img(&btnOutline); if (Settings.wsprompt == yes){ btn1Txt.SetWidescreen(CFG.widescreen); @@ -2060,64 +2060,75 @@ ProgressDownloadWindow(int choice2) } } - while (i < cntMissFiles) { + while (i < cntMissFiles) + { - prTxt.SetTextf("%i%%", 100*i/cntMissFiles); + prTxt.SetTextf("%i%%", 100*i/cntMissFiles); - if ((Settings.wsprompt == yes) && (CFG.widescreen)){/////////////adjust for widescreen - progressbarImg.SetPosition(80,40); - progressbarImg.SetTile(80*i/cntMissFiles); - } else { - progressbarImg.SetTile(100*i/cntMissFiles); - } + if ((Settings.wsprompt == yes) && (CFG.widescreen)) + { + //adjust for widescreen + progressbarImg.SetPosition(80,40); + progressbarImg.SetTile(80*i/cntMissFiles); + } + else + { + progressbarImg.SetTile(100*i/cntMissFiles); + } - msgTxt.SetTextf("%i %s", cntMissFiles - i, LANGUAGE.filesleft); - msg2Txt.SetTextf("%s", missingFiles[i]); + msgTxt.SetTextf("%i %s", cntMissFiles - i, LANGUAGE.filesleft); + msg2Txt.SetTextf("%s", missingFiles[i]); - //download boxart image - char imgPath[100]; - char URLFile[100]; - if (choice2 == 2) { - sprintf(URLFile,"http://www.theotherzone.com/wii/3d/176/248/%s",missingFiles[i]); // For 3D Covers - sprintf(imgPath,"%s%s", CFG.covers_path, missingFiles[i]); - } - if(choice2 == 3) { - sprintf(URLFile,"http://www.theotherzone.com/wii/diskart/160/160/%s",missingFiles[i]); - sprintf(imgPath,"%s%s", CFG.disc_path, missingFiles[i]); - } - if(choice2 == 1) { - sprintf(URLFile,"http://www.theotherzone.com/wii/resize/160/224/%s",missingFiles[i]); - sprintf(imgPath,"%s%s", CFG.covers_path, missingFiles[i]); - } + //download boxart image + char imgPath[100]; + char URLFile[100]; + if (choice2 == 2) + { + sprintf(URLFile,"http://www.theotherzone.com/wii/3d/176/248/%s",missingFiles[i]); // For 3D Covers + sprintf(imgPath,"%s%s", CFG.covers_path, missingFiles[i]); + } + if(choice2 == 3) + { + sprintf(URLFile,"http://www.theotherzone.com/wii/diskart/160/160/%s",missingFiles[i]); + sprintf(imgPath,"%s%s", CFG.disc_path, missingFiles[i]); + } + if(choice2 == 1) + { + sprintf(URLFile,"http://www.theotherzone.com/wii/resize/160/224/%s",missingFiles[i]); + sprintf(imgPath,"%s%s", CFG.covers_path, missingFiles[i]); + } - struct block file = downloadfile(URLFile);//reject known bad images + struct block file = downloadfile(URLFile);//reject known bad images - if (file.size == 36864 || file.size <= 1024 || file.size == 7386 || file.data == NULL) { - cntNotFound++; - i++; - } else { - - if(file.data != NULL) - { - // save png to sd card - FILE *pfile; - pfile = fopen(imgPath, "wb"); - fwrite(file.data,1,file.size,pfile); - fclose (pfile); - free(file.data); - } - i++; - } - - if(btn1.GetState() == STATE_CLICKED) { - cntNotFound = cntMissFiles-i+cntNotFound; - break; - } + if (file.size == 36864 || file.size <= 1024 || file.size == 7386 || file.data == NULL) { + cntNotFound++; + i++; + } + else + { + if(file.data != NULL) + { + // save png to sd card + FILE *pfile=NULL; + if((pfile = fopen(imgPath, "wb"))!=NULL) + { + fwrite(file.data,1,file.size,pfile); + fclose (pfile); + } + free(file.data); + } + i++; + } + if(btn1.GetState() == STATE_CLICKED) + { + cntNotFound = cntMissFiles-i+cntNotFound; + break; + } } /**Temporary redownloading 1st image because of a fucking corruption bug **/ - +/* char URLFile[100]; if (choice2 == 2) { sprintf(URLFile,"http://www.theotherzone.com/wii/3d/176/248/%s",missingFiles[0]); // For 3D Covers @@ -2146,7 +2157,7 @@ ProgressDownloadWindow(int choice2) free(file.data); } } - +*/ HaltGui(); mainWindow->Remove(&promptWindow); @@ -2218,23 +2229,23 @@ ProgressUpdateWindow() char title[50]; sprintf(title, "%s", LANGUAGE.CheckingforUpdates); - GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); titleTxt.SetPosition(0,50); char msg[50]; sprintf(msg, "%s", LANGUAGE.InitializingNetwork); - GuiText msgTxt(msg, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msgTxt(msg, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msgTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); msgTxt.SetPosition(0,140); char msg2[50] = " "; - GuiText msg2Txt(msg2, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText msg2Txt(msg2, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); msg2Txt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); msg2Txt.SetPosition(0, 50); prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE); prTxt.SetPosition(0, 7); - GuiText btn1Txt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText btn1Txt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage btn1Img(&btnOutline); if (Settings.wsprompt == yes){ btn1Txt.SetWidescreen(CFG.widescreen); @@ -2314,10 +2325,10 @@ ProgressUpdateWindow() int revnumber = 0; int currentrev = atoi(SVN_REV); - SDCard_deInit(); +/// SDCard_deInit(); struct block file = downloadfile("http://www.techjawa.com/usbloadergx/rev.txt"); FILE *pfile; - SDCard_Init(); +/// SDCard_Init(); if(file.data != NULL) { @@ -2442,9 +2453,7 @@ ProgressUpdateWindow() if(!failed && ret >= 0) { WindowPrompt(LANGUAGE.Successfullyupdated , LANGUAGE.Restarting, LANGUAGE.ok, 0, 0, 0); - ExitApp(); - if (*((u32*) 0x80001800)) exit(0); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_BackToLoader(); } promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50); @@ -2514,13 +2523,14 @@ UpdateGUI (void *arg) if(ExitRequested) { - for(int a = 0; a < 255; a += 15) + for(int a = 5; a < 255; a += 10) { mainWindow->Draw(); Menu_DrawRectangle(0,0,screenwidth,screenheight,(GXColor){0, 0, 0, a},1); Menu_Render(); } - ExitApp(); + ShutoffRumble(); + return 0; } } } @@ -2537,7 +2547,12 @@ InitGUIThreads() { LWP_CreateThread (&guithread, UpdateGUI, NULL, NULL, 0, 70); } - +void +ExitGUIThreads() +{ + ExitRequested = 1; + LWP_JoinThread(guithread, NULL); +} /**************************************************************************** * EntryCmp ***************************************************************************/ @@ -2732,7 +2747,7 @@ static int OnScreenKeyboard(char * var, u32 maxlen, int min) GuiTrigger trigB; trigB.SetSimpleTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B); - GuiText okBtnTxt(LANGUAGE.ok, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText okBtnTxt(LANGUAGE.ok, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage okBtnImg(&btnOutline); if (Settings.wsprompt == yes){ okBtnTxt.SetWidescreen(CFG.widescreen); @@ -2740,7 +2755,7 @@ static int OnScreenKeyboard(char * var, u32 maxlen, int min) } GuiButton okBtn(&okBtnImg,&okBtnImg, 0, 4, 5, 15, &trigA, &btnSoundOver, &btnClick,1); okBtn.SetLabel(&okBtnTxt); - GuiText cancelBtnTxt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText cancelBtnTxt(LANGUAGE.Cancel, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); GuiImage cancelBtnImg(&btnOutline); if (Settings.wsprompt == yes){ cancelBtnTxt.SetWidescreen(CFG.widescreen); @@ -2949,8 +2964,8 @@ static int MenuInstall() mainWindow->Remove(&w); ResumeGui(); - SDCard_deInit(); - SDCard_Init(); +/// SDCard_deInit(); +/// SDCard_Init(); return menu; } @@ -3176,13 +3191,13 @@ static int MenuDiscList() countBtn.SetImageOver(&countBtnImg); countBtn.SetAlpha(255); } - if (Settings.gameDisplay==list) + if (Settings.gameDisplay==list) { listBtn.SetImage(&listBtnImg); listBtn.SetImageOver(&listBtnImg); - listBtn.SetAlpha(255); + listBtn.SetAlpha(255); } - else if (Settings.gameDisplay==grid) + else if (Settings.gameDisplay==grid) { gridBtn.SetImage(&gridBtnImg); gridBtn.SetImageOver(&gridBtnImg); @@ -3371,22 +3386,9 @@ static int MenuDiscList() choice = WindowPrompt(LANGUAGE.HowtoShutdown,0,LANGUAGE.FullShutdown, LANGUAGE.ShutdowntoIdle, LANGUAGE.Cancel,0); if(choice == 2) { - WPAD_Flush(0); - WPAD_Disconnect(0); - WPAD_Shutdown(); - - /* Set LED mode */ - ret = CONF_GetIdleLedMode(); - if(ret >= 0 && ret <= 2) - STM_SetLedMode(ret); - - STM_ShutdownToIdle(); - + Sys_ShutdownToIdel(); } else if(choice == 1) { - WPAD_Flush(0); - WPAD_Disconnect(0); - WPAD_Shutdown(); - STM_ShutdownToStandby(); + Sys_ShutdownToStandby(); } else { poweroffBtn.ResetState(); if (Settings.gameDisplay==list){gameBrowser.SetFocus(1);} @@ -3410,15 +3412,11 @@ static int MenuDiscList() if(choice == 3) { - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); // Back to System Menu + Sys_LoadMenu(); // Back to System Menu } else if (choice == 2) { - ExitApp(); - if (*((u32*) 0x80001800)) exit(0); - // Channel Version - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_BackToLoader(); } else { homeBtn.ResetState(); if (Settings.gameDisplay==list){gameBrowser.SetFocus(1);} @@ -3615,7 +3613,7 @@ static int MenuDiscList() } countBtn.ResetState(); - } + } else if(listBtn.GetState() == STATE_CLICKED) { if (Settings.gameDisplay!=list){ @@ -3623,7 +3621,7 @@ static int MenuDiscList() mainWindow->Remove(&gameGrid); gridBtn.SetImage(&gridBtnImg_g); gridBtn.SetImageOver(&gridBtnImg_g); - gridBtn.SetAlpha(180); + gridBtn.SetAlpha(180); } if (Settings.gameDisplay==carousel) { mainWindow->Remove(&gameCarousel); @@ -3675,12 +3673,12 @@ static int MenuDiscList() } } listBtn.ResetState(); - } + } - else if (gridBtn.GetState() == STATE_CLICKED) { - if (Settings.gameDisplay!=grid){ - if (Settings.gameDisplay==list) { - mainWindow->Remove(&gameBrowser); + else if (gridBtn.GetState() == STATE_CLICKED) { + if (Settings.gameDisplay!=grid){ + if (Settings.gameDisplay==list) { + mainWindow->Remove(&gameBrowser); if (GameIDTxt) w.Remove(GameIDTxt); if (GameRegionTxt) w.Remove(GameRegionTxt); w.Remove(&DownloadBtn); @@ -3734,12 +3732,12 @@ static int MenuDiscList() w.Append(&carouselBtn); if(isSdInserted()) { cfg_save_global(); - } + } } - gridBtn.ResetState(); - } + gridBtn.ResetState(); + } - else if (carouselBtn.GetState() == STATE_CLICKED) { + else if (carouselBtn.GetState() == STATE_CLICKED) { if (Settings.gameDisplay!=carousel){ if (Settings.gameDisplay==list) mainWindow->Remove(&gameBrowser); @@ -3995,31 +3993,25 @@ static int MenuDiscList() } // if we have used the network or cios222 we need to reload the disklist - if(networkisinitialized == 1 || ios2 == 1 || Settings.cios == ios222) { + if(networkisinitialized == 1 || ios2 == 1 || Settings.cios == ios222) + { + if(ios2 == 1) + { + ret = Sys_IosReload(222); - - if(ios2 == 1) { - - ret = Sys_IosReload(222); - - if(ret < 0) { - Wpad_Init(); - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - - WindowPrompt(LANGUAGE.YoudonthavecIOS,LANGUAGE.LoadingincIOS,LANGUAGE.ok, 0,0,0); - - Sys_IosReload(249); - ios2 = 0; + if(ret < 0) + { + WindowPrompt(LANGUAGE.YoudonthavecIOS,LANGUAGE.LoadingincIOS,LANGUAGE.ok, 0,0,0); + Sys_IosReload(249); + ios2 = 0; + } + } + else + { + ret = Sys_IosReload(249); + } } - } else { - - ret = Sys_IosReload(249); - - } - } - /* Set USB mode */ ret = Disc_SetUSB(header->id, ios2); if (ret < 0) { @@ -4089,31 +4081,24 @@ static int MenuDiscList() } // if we have used the network or cios222 we need to reload the disklist - if(networkisinitialized == 1 || ios2 == 1 || Settings.cios == ios222) { - - - if(ios2 == 1) { - - ret = Sys_IosReload(222); - - if(ret < 0) { - Wpad_Init(); - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - - WindowPrompt(LANGUAGE.YoudonthavecIOS,LANGUAGE.LoadingincIOS,LANGUAGE.ok, 0,0,0); - - Sys_IosReload(249); - ios2 = 0; + if(networkisinitialized == 1 || ios2 == 1 || Settings.cios == ios222) + { + if(ios2 == 1) + { + ret = Sys_IosReload(222); + if(ret < 0) + { + WindowPrompt(LANGUAGE.YoudonthavecIOS,LANGUAGE.LoadingincIOS,LANGUAGE.ok, 0,0,0); + Sys_IosReload(249); + ios2 = 0; + } + } + else + { + ret = Sys_IosReload(249); + } } - } else { - - ret = Sys_IosReload(249); - - } - } - /* Set USB mode */ @@ -4191,6 +4176,7 @@ static int MenuDiscList() static int MenuFormat() { + USBDevice_deInit(); int menu = MENU_NONE; char imgPath[100]; @@ -4386,9 +4372,6 @@ static int MenuFormat() choice = WindowPrompt (LANGUAGE.ShutdownSystem,LANGUAGE.Areyousure,LANGUAGE.Yes,LANGUAGE.No,0,0); if(choice == 1) { - WPAD_Flush(0); - WPAD_Disconnect(0); - WPAD_Shutdown(); Sys_Shutdown(); } @@ -4397,8 +4380,7 @@ static int MenuFormat() choice = WindowPrompt (LANGUAGE.ReturntoWiiMenu,LANGUAGE.Areyousure,LANGUAGE.Yes,LANGUAGE.No,0,0); if(choice == 1) { - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_LoadMenu(); } } } @@ -4419,6 +4401,7 @@ static int MenuFormat() mainWindow->Remove(&optionBrowser); mainWindow->Remove(&w); ResumeGui(); + USBDevice_Init(); return menu; } @@ -4474,7 +4457,7 @@ static int MenuSettings() settingsbackgroundbtn.SetPosition(0, 0); settingsbackgroundbtn.SetImage(&settingsbackground); - GuiText backBtnTxt(LANGUAGE.Back , 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText backBtnTxt(LANGUAGE.Back , 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); backBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage backBtnImg(&btnOutline); if (Settings.wsprompt == yes){ @@ -5420,15 +5403,11 @@ static int MenuSettings() if(choice == 3) { - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); // Back to System Menu + Sys_LoadMenu(); // Back to System Menu } else if (choice == 2) { - ExitApp(); - if (*((u32*) 0x80001800)) exit(0); - // Channel Version - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_BackToLoader(); } else { @@ -5514,7 +5493,7 @@ int GameSettings(struct discHdr * header) settingsbackgroundbtn.SetPosition(0, 0); settingsbackgroundbtn.SetImage(&settingsbackground); - GuiText saveBtnTxt(LANGUAGE.Save, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText saveBtnTxt(LANGUAGE.Save, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); saveBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage saveBtnImg(&btnOutline); if (Settings.wsprompt == yes){ @@ -5524,7 +5503,7 @@ int GameSettings(struct discHdr * header) saveBtn.SetScale(0.9); saveBtn.SetLabel(&saveBtnTxt); - GuiText cancelBtnTxt(LANGUAGE.Back, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText cancelBtnTxt(LANGUAGE.Back, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); cancelBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage cancelBtnImg(&btnOutline); if (Settings.wsprompt == yes){ @@ -5535,7 +5514,7 @@ int GameSettings(struct discHdr * header) cancelBtn.SetLabel(&cancelBtnTxt); cancelBtn.SetTrigger(&trigB); - GuiText deleteBtnTxt(LANGUAGE.Uninstall, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); //{0, 0, 0, 255}); + GuiText deleteBtnTxt(LANGUAGE.Uninstall, 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255}); deleteBtnTxt.SetMaxWidth(btnOutline.GetWidth()-30); GuiImage deleteBtnImg(&btnOutline); if (Settings.wsprompt == yes){ @@ -5752,7 +5731,7 @@ static int MenuCheck() int menu = MENU_NONE; int i = 0; int choice; - s32 ret2; + s32 ret, ret2; OptionList options; options.length = i; partitionEntry partitions[MAX_PARTITIONS]; @@ -5762,87 +5741,92 @@ static int MenuCheck() ret2 = WBFS_Init(WBFS_DEVICE_USB); if (ret2 < 0) { - //initialize WiiMote for Prompt - Wpad_Init(); - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); ret2 = WindowPrompt(LANGUAGE.NoUSBDevicefound, LANGUAGE.Doyouwanttoretryfor30secs, "cIOS249", "cIOS222", LANGUAGE.BacktoWiiMenu, 0); - //shutdown SD - SDCard_deInit(); if(ret2 == 1) { - Settings.cios = ios249; - } else if(ret2 == 2) { - Settings.cios = ios222; + Settings.cios = ios249; + } else if(ret2 == 2) { + if(Settings.cios != ios222) + { + //shutdown WiiMote before IOS Reload + WPAD_Flush(0); + WPAD_Disconnect(0); + WPAD_Shutdown(); + + //shutdown SD and USB before IOS Reload + SDCard_deInit(); + USBDevice_deInit(); + ret = IOS_ReloadIOS(222); + if(ret < 0) + IOS_ReloadIOS(249); + //reinitialize WiiMote for Prompt + PAD_Init(); + Wpad_Init(); + WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); + WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); + //reinitialize SD and USB + SDCard_Init(); + USBDevice_Init(); + if(ret < 0) + WindowPrompt(LANGUAGE.YoudonthavecIOS,LANGUAGE.LoadingincIOS,LANGUAGE.ok, 0,0,0); + else + Settings.cios = ios222; + } } else { - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_LoadMenu(); } + //shutdown WiiMote before IOS Reload WPAD_Flush(0); WPAD_Disconnect(0); WPAD_Shutdown(); - SDCard_Init(); + //shutdown SD and USB before IOS Reload in DiscWait + SDCard_deInit(); + USBDevice_deInit(); + ret2 = DiscWait(LANGUAGE.NoUSBDevice, LANGUAGE.WaitingforUSBDevice, 0, 0, 1); - PAD_Init(); + //reinitialize WiiMote for Prompt + PAD_Init(); Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); + //reinitialize SD and USB SDCard_Init(); + USBDevice_Init(); } if (ret2 < 0) { - SDCard_Init(); WindowPrompt (LANGUAGE.Error,LANGUAGE.USBDevicenotfound, LANGUAGE.ok, 0,0,0); - SDCard_deInit(); - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } else { - PAD_Init(); - Wpad_Init(); - WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); - WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - SDCard_Init(); - } - + Sys_LoadMenu(); + } + ret2 = Disc_Init(); if (ret2 < 0) { - SDCard_Init(); WindowPrompt (LANGUAGE.Error,LANGUAGE.CouldnotinitializeDIPmodule,LANGUAGE.ok, 0,0,0); - SDCard_deInit(); - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_LoadMenu(); } ret2 = WBFS_Open(); if (ret2 < 0) { - SDCard_Init(); choice = WindowPrompt(LANGUAGE.NoWBFSpartitionfound, LANGUAGE.Youneedtoformatapartition, LANGUAGE.Format, LANGUAGE.Return,0,0); - SDCard_deInit(); if(choice == 0) { - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - + Sys_LoadMenu(); } else { /* Get partition entries */ u32 sector_size; ret2 = Partition_GetEntries(partitions, §or_size); if (ret2 < 0) { - SDCard_Init(); WindowPrompt (LANGUAGE.Nopartitionsfound,0, LANGUAGE.Restart, 0,0,0); - SDCard_deInit(); - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_LoadMenu(); } menu = MENU_FORMAT; - } } @@ -6302,6 +6286,7 @@ int MainMenu(int menu) break; } } + ExitGUIThreads(); bgMusic->Stop(); @@ -6319,7 +6304,11 @@ int MainMenu(int menu) delete cover; delete coverImg; - ExitApp(); + StopGX(); + ShutdownAudio(); + + SDCard_deInit(); + USBDevice_deInit(); struct discHdr *header = &gameList[gameSelected]; struct Game_CFG* game_cfg = CFG_get_game_opt(header->id); @@ -6461,8 +6450,7 @@ int MainMenu(int menu) int ret = 0; ret = Disc_WiiBoot(videoselected, cheat, vipatch, Settings.patchcountrystrings); if (ret < 0) { - ExitApp(); - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); + Sys_LoadMenu(); } return 0; diff --git a/source/menu.h b/source/menu.h index 47b1a0f2..fbda92a2 100644 --- a/source/menu.h +++ b/source/menu.h @@ -11,7 +11,16 @@ #include -void InitGUIThreads(); +#ifdef __cplusplus +//extern "C" +//{ +#endif +void InitGUIThreads(void); +void ExitGUIThreads(void); +#ifdef __cplusplus +//} +#endif + int MainMenu (int menuitem); void wiilight(int enable); int GameSettings(struct discHdr *); diff --git a/source/sys.c b/source/sys.cpp similarity index 60% rename from source/sys.c rename to source/sys.cpp index 645851cb..c687bbda 100644 --- a/source/sys.c +++ b/source/sys.cpp @@ -8,6 +8,8 @@ #include "disc.h" #include "wbfs.h" #include "video.h" +#include "audio.h" +#include "menu.h" #include "fatmounter.h" /* Constants */ @@ -41,9 +43,21 @@ void Sys_Init(void) SYS_SetPowerCallback(__Sys_PowerCallback); } +static void _ExitApp() +{ + ExitGUIThreads(); + StopGX(); + ShutdownAudio(); + + SDCard_deInit(); + USBDevice_deInit(); +} + + void Sys_Reboot(void) { /* Restart console */ + _ExitApp(); STM_RebootSystem(); } @@ -51,8 +65,9 @@ int Sys_IosReload(int IOS) { s32 ret; - if(isSdInserted()) + //shutdown SD and USB before IOS Reload in DiscWait SDCard_deInit(); + USBDevice_deInit(); WPAD_Flush(0); WPAD_Disconnect(0); @@ -62,35 +77,49 @@ int Sys_IosReload(int IOS) USBStorage_Deinit(); - __IOS_ShutdownSubsystems(); - ret = IOS_ReloadIOS(IOS); - if(ret < 0) { - return ret; - } - PAD_Init(); Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - if(IOS == 249 || IOS == 222) { - ret = WBFS_Init(WBFS_DEVICE_USB); - ret = Disc_Init(); - ret = WBFS_Open(); + if(ret < 0) { + return ret; } + + if(IOS == 249 || IOS == 222 || IOS == 223) { + ret = WBFS_Init(WBFS_DEVICE_USB); + if(ret>=0) + { + ret = Disc_Init(); + if(ret>=0) + ret = WBFS_Open(); + } + } + //reinitialize SD and USB + SDCard_Init(); + USBDevice_Init(); return ret; } -void Sys_Shutdown(void) + + +#define ShutdownToDefault 0 +#define ShutdownToIdle 1 +#define ShutdownToStandby 2 + +static void _Sys_Shutdown(int SHUTDOWN_MODE) { - Wpad_Disconnect(); + _ExitApp(); + WPAD_Flush(0); + WPAD_Disconnect(0); + WPAD_Shutdown(); /* Poweroff console */ - if(CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE) { + if((CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE && SHUTDOWN_MODE != ShutdownToStandby) || SHUTDOWN_MODE == ShutdownToIdle) { s32 ret; /* Set LED mode */ @@ -105,13 +134,37 @@ void Sys_Shutdown(void) STM_ShutdownToStandby(); } } +void Sys_Shutdown(void) +{ + _Sys_Shutdown(ShutdownToDefault); +} +void Sys_ShutdownToIdel(void) +{ + _Sys_Shutdown(ShutdownToIdle); +} +void Sys_ShutdownToStandby(void) +{ + _Sys_Shutdown(ShutdownToStandby); +} void Sys_LoadMenu(void) { + _ExitApp(); /* Return to the Wii system menu */ SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } +void Sys_BackToLoader(void) +{ + if (*((u32*) 0x80001800)) + { + _ExitApp(); + exit(0); + } + // Channel Version + Sys_LoadMenu(); +} + s32 Sys_GetCerts(signed_blob **certs, u32 *len) { static signed_blob certificates[CERTS_LEN] ATTRIBUTE_ALIGN(32); diff --git a/source/sys.h b/source/sys.h index 74d7fb62..28b3cb7e 100644 --- a/source/sys.h +++ b/source/sys.h @@ -3,18 +3,21 @@ #ifdef __cplusplus extern "C" -{ +//{ #endif /* Prototypes */ void Sys_Init(void); void Sys_Reboot(void); void Sys_Shutdown(void); -void Sys_LoadMenu(void); +void Sys_ShutdownToIdel(void); +void Sys_ShutdownToStandby(void); +void Sys_LoadMenu(void); +void Sys_BackToLoader(void); int Sys_IosReload(int IOS); s32 Sys_GetCerts(signed_blob **, u32 *); #ifdef __cplusplus -} +//} #endif #endif