From d16ba4ed6cbe27f5b999636fbdbb14e8c7c75f6f Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Sun, 17 Jan 2010 23:59:59 +0000 Subject: [PATCH] *Fix for startup problems. Especially for those with wiitdb. *Startup is now using libogc usbstorage for loading configs *Improved storing gametitles from wiitdb with less memory usage *Added freeing of the memory allocated for wiitdb titles (oh boy) *Changed wiitdb.zip search --- source/main.cpp | 32 ++++++++++++++----------- source/menu.cpp | 11 ++++----- source/menu/device_check.cpp | 37 ++++------------------------- source/settings/Settings.cpp | 2 +- source/settings/cfg.c | 43 +++++++++++++++++++++++---------- source/sys.cpp | 38 ++++------------------------- source/xml/xml.c | 46 ++++++++++++++++++++++++++---------- 7 files changed, 97 insertions(+), 112 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index c64dd86a..81ce2627 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -127,9 +127,8 @@ int main(int argc, char *argv[]) printf("\n\tInitialize USB (wake up)"); USBDevice_Init();// seems enough to wake up some HDDs if they are in sleep mode when the loader starts (tested with WD MyPassport Essential 2.5") - USBDevice_deInit(); - - s32 ret; + printf("\n\tInitialize sd card"); + SDCard_Init(); // mount SD for loading cfg's bool bootDevice_found=false; if (argc >= 1) { @@ -140,17 +139,7 @@ int main(int argc, char *argv[]) bootDevice_found = true; } - printf("\n\tInitializing controllers"); - - /** PAD_Init has to be before InitVideo don't move that **/ - PAD_Init(); // initialize PAD/WPAD - - ret = CheckForCIOS(); - - printf("\n\tInitialize sd card"); - SDCard_Init(); // mount SD for loading cfg's - printf("\n\tInitialize usb device"); - USBDevice_Init(); // and mount USB:/ + CheckForCIOS(); if (!bootDevice_found) { @@ -170,6 +159,17 @@ int main(int argc, char *argv[]) CFG_Load(); printf("done"); + printf("\n\tLoading Background Music..."); + bgMusic = new GuiBGM(bg_music_ogg, bg_music_ogg_size, Settings.volume); + if(strstr(Settings.ogg_path, "USB:") == 0) + bgMusic->Load(Settings.ogg_path); + bgMusic->SetLoop(Settings.musicloopmode); //loop music + + printf("\n\tOpening XML Database..."); + // open database if available, load titles if needed + if(!OpenXMLDatabase(Settings.titlestxt_path,Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride == 1 ? true: false, true)) + printf("failed"); + LoadAppCIOS(); printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision()); @@ -181,6 +181,10 @@ int main(int argc, char *argv[]) LoadHeadlessID(argv[1]); } + + printf("\n\tInitializing controllers"); + /** PAD_Init has to be before InitVideo don't move that **/ + PAD_Init(); // initialize PAD/WPAD //! Init the rest of the System Sys_Init(); Wpad_Init(); diff --git a/source/menu.cpp b/source/menu.cpp index cbf08030..38f709f6 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -281,13 +281,8 @@ int MainMenu(int menu) { bgImg = new GuiImage(background); mainWindow->Append(bgImg); - bgMusic = new GuiBGM(bg_music_ogg, bg_music_ogg_size, Settings.volume); - bgMusic->SetLoop(Settings.musicloopmode); //loop music - if(strstr(Settings.ogg_path, "USB:/") == 0) //usb is not detected at this point yet - { - bgMusic->Load(Settings.ogg_path); - bgMusic->Play(); - } + bgMusic->Play(); + ResumeGui(); @@ -324,6 +319,8 @@ int MainMenu(int menu) { CloseXMLDatabase(); NewTitles::DestroyInstance(); + CFG_Cleanup(); + if (strcmp(headlessID,"")!=0)//the GUIthread was never started, so it cant be ended and joined properly if headless mode was used. so we resume it and close it. ResumeGui(); ExitGUIThreads(); diff --git a/source/menu/device_check.cpp b/source/menu/device_check.cpp index be6499cb..d3149996 100644 --- a/source/menu/device_check.cpp +++ b/source/menu/device_check.cpp @@ -39,37 +39,6 @@ void HaltCheck() usleep(50); } -void ReloadHDD_Settings() -{ - if(strstr(bootDevice, "USB:") != 0) - { - CFG_Load(); - int ios = 249; - switch(Settings.cios) - { - case ios249: - ios = 249; - break; - case ios222: - ios = 222; - break; - case ios250: - ios = 250; - break; - } - if(ios != IOS_GetVersion()) - Sys_ChangeIos(ios); - } - if(strstr(Settings.ogg_path, "USB:/") != 0) - { - bgMusic->Load(Settings.ogg_path); - bgMusic->Play(); - } - - // open database if available, load titles if needed - OpenXMLDatabase(Settings.titlestxt_path,Settings.db_language, Settings.db_JPtoEN, true, Settings.titlesOverride == 1 ? true: false, true); -} - int CheckPartition() { s32 ret2 = -1; @@ -190,7 +159,11 @@ static void * CheckDevices (void *arg) { LWP_SetThreadPriority(LWP_GetSelf(), 0); - ReloadHDD_Settings(); + if(strstr(Settings.ogg_path, "USB:/") != 0) + { + bgMusic->Load(Settings.ogg_path); + bgMusic->Play(); + } checkthreadState = 1; } diff --git a/source/settings/Settings.cpp b/source/settings/Settings.cpp index 3b18bed0..ea20541f 100644 --- a/source/settings/Settings.cpp +++ b/source/settings/Settings.cpp @@ -1426,7 +1426,7 @@ int MenuSettings() { bgMusic->LoadStandard(); bgMusic->Play(); - options2.SetValue(Idx, "%s", tr("Standard")); + options2.SetValue(0, "%s", tr("Standard")); } } diff --git a/source/settings/cfg.c b/source/settings/cfg.c index 8118e7fc..7064a85c 100644 --- a/source/settings/cfg.c +++ b/source/settings/cfg.c @@ -42,11 +42,9 @@ u8 listDisplay = 0; u8 partition = -1; char alternatedname[40]; -#define TITLE_MAX 200 - struct ID_Title { char id[6]; - char title[TITLE_MAX]; + char * title; }; struct ID_Control { @@ -391,8 +389,9 @@ char *cfg_get_title(u8 *id) return NULL; int i; - for (i=0; i #include "unzip/unzip.h" #include "settings/cfg.h" +#include "listfiles.h" +#include "usbloader/partition_usbloader.h" #include "xml/xml.h" -//#include "cfg.h" -//#include "xml.h" + extern struct SSettings Settings; // for loader GX extern void title_set(char *id, char *title); extern char* trimcopy(char *dest, char *src, int size); -extern char game_partition[6]; /* config */ static bool xmldebug = false; -static char xmlcfg_filename[100] = "wiitdb"; static int xmlmaxsize = 1572864; @@ -64,22 +63,45 @@ int xmlloadtime = 0; char * get_nodetext(mxml_node_t *node, char *buffer, int buflen); bool xml_loaded = false; +static void SearchXMLFile(char * pathname) +{ + int i = 0; + char temppath[MAXPATHLEN]; + + for(i = 0; i < 4; i++) + { + snprintf(temppath, sizeof(temppath), "%swiitdb_WBFS%i.zip", pathname, i); + if(checkfile(temppath)) + { + sprintf(pathname, "%s", temppath); + return; + } + snprintf(temppath, sizeof(temppath), "%swiitdb_FAT%i.zip", pathname, i); + if(checkfile(temppath)) + { + sprintf(pathname, "%s", temppath); + return; + } + snprintf(temppath, sizeof(temppath), "%swiitdb_NTFS%i.zip", pathname, i); + if(checkfile(temppath)) + { + sprintf(pathname, "%s", temppath); + return; + } + } + + sprintf(pathname, "%swiitdb.zip", pathname); +} /* load renamed titles from proper names and game info XML, needs to be after cfg_load_games */ bool OpenXMLDatabase(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool openfile, bool loadtitles, bool keepopen) { if (!xml_loaded) { bool opensuccess = false; - char pathname[200]; + char pathname[400]; snprintf(pathname, sizeof(pathname), "%s", xmlfilepath); if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/",pathname); - snprintf(pathname, sizeof(pathname), "%s%s_%s.zip", pathname, xmlcfg_filename, game_partition); + SearchXMLFile(pathname); if (openfile) opensuccess = OpenXMLFile(pathname); - if (!opensuccess) { - snprintf(pathname, sizeof(pathname), "%s", xmlfilepath); - if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/",pathname); - snprintf(pathname, sizeof(pathname), "%swiitdb.zip", pathname); - if (openfile) opensuccess = OpenXMLFile(pathname); - } if (!opensuccess && openfile) { CloseXMLDatabase(); return false;