From feda5a7ba6891c999c26ccad766f6634d7ed54b2 Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Fri, 15 May 2009 20:03:19 +0000 Subject: [PATCH] *Changed some functions. *Fixed one bug that you couldnt get to FormatMenu *Added USB functions, not yet implemented (they dont work under cIOS249/cIOS222, only under IOS36 (original). right now function only works if partition 1 is fat/fat32) --- source/fatmounter.c | 55 ++++++++++++++++++++++++++ source/fatmounter.h | 19 +++++++++ source/main.cpp | 18 +++------ source/menu.cpp | 95 +++++++++++++++------------------------------ source/sys.c | 9 ++--- 5 files changed, 114 insertions(+), 82 deletions(-) create mode 100644 source/fatmounter.c create mode 100644 source/fatmounter.h diff --git a/source/fatmounter.c b/source/fatmounter.c new file mode 100644 index 00000000..c2fc24a0 --- /dev/null +++ b/source/fatmounter.c @@ -0,0 +1,55 @@ +#include +#include +#include +#include +#include +#include + +#define CACHE 8 + + +int USBDevice_Init() +{ + //right now only mounts first partition and only under IOS36 + __io_usbstorage.startup(); + + if (fatMountSimple("USB", &__io_usbstorage, 0, CACHE)) { + return 1; + } + +return -1; +} + +void USBDevice_deInit() +{ + //First unmount all the devs... + fatUnmount("USB"); + //...and then shutdown em! + __io_usbstorage.shutdown(); +} + +int isSdInserted() +{ + return __io_wiisd.isInserted(); +} + +int SDCard_Init() +{ + //mount SD if inserted + __io_wiisd.startup(); + if (!isSdInserted()){ + return -1; + } + if (fatMount("SD", &__io_wiisd, 0, CACHE)) { + return 1; + } +return -1; +} + +void SDCard_deInit() +{ + //First unmount all the devs... + fatUnmount("SD"); + //...and then shutdown em! + __io_wiisd.shutdown(); +} diff --git a/source/fatmounter.h b/source/fatmounter.h new file mode 100644 index 00000000..e2357020 --- /dev/null +++ b/source/fatmounter.h @@ -0,0 +1,19 @@ +#ifndef _FATMOUNTER_H_ +#define _FATMOUNTER_H_ + +#ifdef __cplusplus +extern "C" +{ +#endif + +int USBDevice_Init(); +void USBDevice_deInit(); +int isSdInserted(); +int SDCard_Init(); +void SDCard_deInit(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/source/main.cpp b/source/main.cpp index 42a388f3..947ea495 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -24,15 +24,13 @@ #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 -#include /* Constants */ @@ -70,8 +68,7 @@ void ExitApp() StopGX(); ShutdownAudio(); - fatUnmount("SD"); - __io_wiisd.shutdown(); + SDCard_deInit(); //WPAD_Flush(0); //WPAD_Disconnect(0); @@ -109,19 +106,15 @@ int main(int argc, char *argv[]) { - - s32 ret2; - __io_wiisd.startup(); - fatMountSimple("SD", &__io_wiisd); + SDCard_Init(); CFG_Load(argc, argv); DefaultSettings(); - fatUnmount("SD"); - __io_wiisd.shutdown(); + SDCard_deInit(); /* Load Custom IOS */ if(Settings.cios == ios222) { @@ -139,8 +132,7 @@ main(int argc, char *argv[]) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } - __io_wiisd.startup(); - fatMountSimple("SD", &__io_wiisd); + SDCard_Init(); Sys_Init(); //Video_SetMode(); diff --git a/source/menu.cpp b/source/menu.cpp index 63f1a081..052aed60 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -5,7 +5,6 @@ * menu.cpp * Menu flow routines - handles all menu logic ***************************************************************************/ - #include #include #include @@ -13,8 +12,6 @@ #include #include #include -#include -#include #include //CLOCK #include //CLOCK #include @@ -40,6 +37,7 @@ #include "libwiigui/gui_customoptionbrowser.h" #include "libwiigui/gui_gamebrowser.h" #include "mp3s.h" +#include "fatmounter.h" #define MAX_CHARACTERS 38 @@ -110,33 +108,6 @@ static void ResumeGui(); extern const u8 data1; -//libfat helper functions -int isSdInserted() { return __io_wiisd.isInserted(); } - -//Initialise SD CARD -int SDCard_Init() -{ - __io_wiisd.startup(); - if (!isSdInserted()){ - printf("No SD card inserted!"); - return -1; - - } if (!fatMountSimple ("SD", &__io_wiisd)){ - printf("Failed to mount front SD card!"); - return -1; - } - - return 1; -} - -void SDCARD_deInit() -{ - //First unmount all the devs... - fatUnmount ("SD"); - //...and then shutdown em! - __io_wiisd.shutdown(); -} - bool findfile(const char * filename, const char * path) { DIR *dir; @@ -897,7 +868,7 @@ int GameWindowPrompt() if(btn1.GetState() == STATE_CLICKED) { //boot choice = 1; - SDCARD_deInit(); + SDCard_deInit(); } else if(btn2.GetState() == STATE_CLICKED) { //back @@ -2001,7 +1972,6 @@ static int MenuInstall() char *name; static char buffer[MAX_CHARACTERS + 4]; - GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, vol); //GuiImageData battery(battery_png); @@ -2016,7 +1986,6 @@ static int MenuInstall() snprintf(imgPath, sizeof(imgPath), "%sbattery_bar.png", CFG.theme_path); GuiImageData batteryBar(imgPath, battery_bar_png); - #ifdef HW_RVL int i = 0, level; char txt[3]; @@ -2245,6 +2214,7 @@ static int MenuInstall() static int MenuDiscList() { + datagB=0; int menu = MENU_NONE, dataef=0; char imgPath[100]; @@ -2492,7 +2462,6 @@ static int MenuDiscList() clockTime.SetPosition(THEME.clock_x, THEME.clock_y); clockTime.SetFont(fontClock); - HaltGui(); GuiWindow w(screenwidth, screenheight); @@ -2669,9 +2638,11 @@ static int MenuDiscList() else if(sdcardBtn.GetState() == STATE_CLICKED) { - __io_wiisd.shutdown(); - __io_wiisd.startup(); - break; + SDCard_deInit(); + USBDevice_deInit(); + SDCard_Init(); + USBDevice_Init(); + sdcardBtn.ResetState(); } else if(DownloadBtn.GetState() == STATE_CLICKED) @@ -3080,7 +3051,7 @@ static int MenuDiscList() } } - HaltGui(); + HaltGui(); #ifdef HW_RVL for(i=0; i < 4; i++) @@ -3154,14 +3125,6 @@ static int MenuFormat() GuiTrigger trigHome; trigHome.SetButtonOnlyTrigger(-1, WPAD_BUTTON_HOME | WPAD_CLASSIC_BUTTON_HOME, 0); - GuiText titleTxt("Select the Partition", 18, (GXColor){0, 0, 0, 255}); - titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt.SetPosition(10,40); - - GuiText titleTxt2("you want to format:", 18, (GXColor){0, 0, 0, 255}); - titleTxt2.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - titleTxt2.SetPosition(20,60); - GuiImage poweroffBtnImg(&btnpwroff); GuiImage poweroffBtnImgOver(&btnpwroffOver); poweroffBtnImg.SetWidescreen(CFG.widescreen); @@ -3181,8 +3144,8 @@ static int MenuFormat() exitBtnImg.SetWidescreen(CFG.widescreen); exitBtnImgOver.SetWidescreen(CFG.widescreen); GuiButton exitBtn(btnhome.GetWidth(), btnhome.GetHeight()); - exitBtn.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); - exitBtn.SetPosition(240, 367); + exitBtn.SetAlignment(ALIGN_LEFT, ALIGN_BOTTOM); + exitBtn.SetPosition(0, -10); exitBtn.SetImage(&exitBtnImg); exitBtn.SetImageOver(&exitBtnImgOver); exitBtn.SetSoundOver(&btnSoundOver); @@ -3235,11 +3198,10 @@ static int MenuFormat() GuiOptionBrowser optionBrowser(THEME.selection_w, THEME.selection_h, &options, CFG.theme_path, bg_options_png, 1, 0); optionBrowser.SetPosition(THEME.selection_x, THEME.selection_y); optionBrowser.SetAlignment(ALIGN_LEFT, ALIGN_CENTRE); + optionBrowser.SetCol2Position(200); HaltGui(); GuiWindow w(screenwidth, screenheight); - w.Append(&titleTxt); - w.Append(&titleTxt2); w.Append(&poweroffBtn); w.Append(&exitBtn); @@ -3881,7 +3843,11 @@ static int MenuSettings() if ( result == 1 ) { strncpy(CFG.covers_path, entered, sizeof(CFG.covers_path)); WindowPrompt("Coverpath Changed",0,"OK",0,0,0); - cfg_save_global(); + if(isSdInserted() == 1) { + cfg_save_global(); + } else { + WindowPrompt("No SD-Card inserted!", "Insert a SD-Card to save.", "OK", 0,0,0); + } } } else @@ -3913,7 +3879,11 @@ static int MenuSettings() { strncpy(CFG.disc_path, entered, sizeof(CFG.disc_path)); WindowPrompt("Discpath Changed",0,"OK",0,0,0); - cfg_save_global(); + if(isSdInserted() == 1) { + cfg_save_global(); + } else { + WindowPrompt("No SD-Card inserted!", "Insert a SD-Card to save.", "OK", 0,0,0); + } } } else @@ -3945,7 +3915,11 @@ static int MenuSettings() { strncpy(CFG.theme_path, entered, sizeof(CFG.theme_path)); WindowPrompt("Themepath Changed",0,"OK",0,0,0); - cfg_save_global(); + if(isSdInserted() == 1) { + cfg_save_global(); + } else { + WindowPrompt("No SD-Card inserted!", "Insert a SD-Card to save.", "OK", 0,0,0); + } /////load new theme////////////// mainWindow->Remove(bgImg); CFG_Load1(); @@ -4434,13 +4408,11 @@ static int MenuCheck() VIDEO_WaitVSync (); - ret2 = WBFS_Init(WBFS_DEVICE_USB); if (ret2 < 0) { //shutdown SD - fatUnmount("SD"); - __io_wiisd.shutdown(); + SDCard_deInit(); //initialize WiiMote for Prompt Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); @@ -4468,8 +4440,7 @@ static int MenuCheck() Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - __io_wiisd.startup(); - fatMountSimple("SD", &__io_wiisd); + SDCard_Init(); } if (ret2 < 0) { WindowPrompt ("ERROR:","USB-Device not found!", "ok", 0,0,0); @@ -4479,8 +4450,7 @@ static int MenuCheck() Wpad_Init(); WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - __io_wiisd.startup(); - fatMountSimple("SD", &__io_wiisd); + SDCard_Init(); } ret2 = Disc_Init(); @@ -4490,7 +4460,6 @@ static int MenuCheck() } ret2 = WBFS_Open(); - if (ret2 < 0) { choice = WindowPrompt("No WBFS partition found!", @@ -4523,11 +4492,9 @@ static int MenuCheck() //Spieleliste laden __Menu_GetEntries(); - + if(menu == MENU_NONE) menu = MENU_DISCLIST; - - return menu; } diff --git a/source/sys.c b/source/sys.c index 6aa57315..727a73c1 100644 --- a/source/sys.c +++ b/source/sys.c @@ -1,7 +1,5 @@ #include #include -#include -#include #include "sys.h" #include "wpad.h" @@ -10,6 +8,7 @@ #include "disc.h" #include "wbfs.h" #include "video.h" +#include "fatmounter.h" /* Constants */ #define CERTS_LEN 0x280 @@ -52,8 +51,8 @@ int Sys_IosReload(int IOS) { s32 ret; - fatUnmount("SD"); - __io_wiisd.shutdown(); + SDCard_deInit(); + USBDevice_deInit(); WPAD_Flush(0); WPAD_Disconnect(0); @@ -74,7 +73,7 @@ int Sys_IosReload(int IOS) WPAD_SetDataFormat(WPAD_CHAN_ALL,WPAD_FMT_BTNS_ACC_IR); WPAD_SetVRes(WPAD_CHAN_ALL, screenwidth, screenheight); - if(IOS == 249 || IOS == 222) { + if(IOS == 249 || IOS == 222 || IOS == 223) { ret = WBFS_Init(WBFS_DEVICE_USB); ret = Disc_Init(); ret = WBFS_Open();