*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
This commit is contained in:
dimok321 2010-01-17 23:59:59 +00:00
parent ca9455aa53
commit d16ba4ed6c
7 changed files with 97 additions and 112 deletions

View File

@ -127,9 +127,8 @@ int main(int argc, char *argv[])
printf("\n\tInitialize USB (wake up)"); 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_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(); printf("\n\tInitialize sd card");
SDCard_Init(); // mount SD for loading cfg's
s32 ret;
bool bootDevice_found=false; bool bootDevice_found=false;
if (argc >= 1) { if (argc >= 1) {
@ -140,17 +139,7 @@ int main(int argc, char *argv[])
bootDevice_found = true; bootDevice_found = true;
} }
printf("\n\tInitializing controllers"); CheckForCIOS();
/** 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:/
if (!bootDevice_found) if (!bootDevice_found)
{ {
@ -170,6 +159,17 @@ int main(int argc, char *argv[])
CFG_Load(); CFG_Load();
printf("done"); 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(); LoadAppCIOS();
printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision()); printf("\n\tcIOS = %u (Rev %u)",IOS_GetVersion(), IOS_GetRevision());
@ -181,6 +181,10 @@ int main(int argc, char *argv[])
LoadHeadlessID(argv[1]); 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 //! Init the rest of the System
Sys_Init(); Sys_Init();
Wpad_Init(); Wpad_Init();

View File

@ -281,13 +281,8 @@ int MainMenu(int menu) {
bgImg = new GuiImage(background); bgImg = new GuiImage(background);
mainWindow->Append(bgImg); mainWindow->Append(bgImg);
bgMusic = new GuiBGM(bg_music_ogg, bg_music_ogg_size, Settings.volume); bgMusic->Play();
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();
}
ResumeGui(); ResumeGui();
@ -324,6 +319,8 @@ int MainMenu(int menu) {
CloseXMLDatabase(); CloseXMLDatabase();
NewTitles::DestroyInstance(); 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. 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(); ResumeGui();
ExitGUIThreads(); ExitGUIThreads();

View File

@ -39,37 +39,6 @@ void HaltCheck()
usleep(50); 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() int CheckPartition()
{ {
s32 ret2 = -1; s32 ret2 = -1;
@ -190,7 +159,11 @@ static void * CheckDevices (void *arg)
{ {
LWP_SetThreadPriority(LWP_GetSelf(), 0); LWP_SetThreadPriority(LWP_GetSelf(), 0);
ReloadHDD_Settings(); if(strstr(Settings.ogg_path, "USB:/") != 0)
{
bgMusic->Load(Settings.ogg_path);
bgMusic->Play();
}
checkthreadState = 1; checkthreadState = 1;
} }

View File

@ -1426,7 +1426,7 @@ int MenuSettings()
{ {
bgMusic->LoadStandard(); bgMusic->LoadStandard();
bgMusic->Play(); bgMusic->Play();
options2.SetValue(Idx, "%s", tr("Standard")); options2.SetValue(0, "%s", tr("Standard"));
} }
} }

View File

@ -42,11 +42,9 @@ u8 listDisplay = 0;
u8 partition = -1; u8 partition = -1;
char alternatedname[40]; char alternatedname[40];
#define TITLE_MAX 200
struct ID_Title { struct ID_Title {
char id[6]; char id[6];
char title[TITLE_MAX]; char * title;
}; };
struct ID_Control { struct ID_Control {
@ -391,8 +389,9 @@ char *cfg_get_title(u8 *id)
return NULL; return NULL;
int i; int i;
for (i=0; i<num_title; i++) { for (i=0; i<num_title; i++)
if (memcmp(id, cfg_title[i].id, 6) == 0) { {
if (strncmp((char*) id, cfg_title[i].id, 6) == 0) {
return cfg_title[i].title; return cfg_title[i].title;
} }
} }
@ -411,20 +410,31 @@ char *get_title(struct discHdr *header)
void title_set(char *id, char *title) void title_set(char *id, char *title)
{ {
if(!id || !title)
return;
if(!cfg_title)
cfg_title = (struct ID_Title *) malloc(sizeof(struct ID_Title));
char *idt = cfg_get_title((u8*)id); char *idt = cfg_get_title((u8*)id);
if (idt) { if (idt) {
// replace // replace
strlcpy(idt, title, TITLE_MAX); free(idt);
idt = strdup(title);
} else { } else {
cfg_title = realloc(cfg_title, (num_title+1) * sizeof(struct ID_Title)); struct ID_Title * tmpStruct = (struct ID_Title *) realloc(cfg_title, (num_title+1) * sizeof(struct ID_Title));
if (!cfg_title) { if (!tmpStruct) {
// error // error
CFG_Cleanup();
num_title = 0; num_title = 0;
return; return;
} }
cfg_title = tmpStruct;
// add // add
strcpy(cfg_title[num_title].id, id); strncpy(cfg_title[num_title].id, id, 6);
strlcpy(cfg_title[num_title].title, title, TITLE_MAX); cfg_title[num_title].title = strdup(title);
num_title++; num_title++;
} }
} }
@ -433,7 +443,8 @@ void titles_default() {
int i; int i;
for (i=0; i<num_title; i++) { for (i=0; i<num_title; i++) {
memset(cfg_title[i].id, 0, 6); memset(cfg_title[i].id, 0, 6);
strlcpy(cfg_title[i].title, "", TITLE_MAX); free(cfg_title[i].title);
cfg_title[i].title = NULL;
} }
} }
@ -1868,7 +1879,15 @@ void CFG_LoadGlobal(void) {
cfg_parsefile(GXGlobal_cfg, &global_cfg_set); cfg_parsefile(GXGlobal_cfg, &global_cfg_set);
} }
void CFG_Cleanup(void) { void CFG_Cleanup(void)
{
int i = 0;
for(i = 0; i < num_title; i++)
{
if(cfg_title[i].title)
free(cfg_title[i].title);
cfg_title[i].title = NULL;
}
if (cfg_title) { if (cfg_title) {
free(cfg_title); free(cfg_title);
cfg_title = NULL; cfg_title = NULL;

View File

@ -316,48 +316,20 @@ s32 CheckForCIOS()
} }
} }
//Needed for Settings load of HDD
printf("\n\tReloading ios 222...");
ret = IOS_ReloadIOSsafe(222);
printf("%d", ret);
if (ret < 0)
{
printf("\n\tIOS 222 failed, reloading ios 249...");
ret = IOS_ReloadIOSsafe(249);
printf("%d", ret);
if (ret < 0) {
printf("\n\tIOS 222 failed, reloading ios 250...");
ret = IOS_ReloadIOSsafe(250);
printf("%d", ret);
if (ret < 0) {
printf("\n\tERROR: cIOS could not be loaded!\n");
sleep(5);
SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);
}
}
}
else
{
SDCard_Init();
//only for 222 loading ehc modules
printf("\n\tLoad ehc module");
load_ehc_module();
SDCard_deInit();
}
return ret; return ret;
} }
int LoadAppCIOS() int LoadAppCIOS()
{ {
s32 ret = 1; s32 ret = 1;
bool IOS_Reloaded = false;
/* Load Custom IOS */ /* Load Custom IOS */
SDCard_deInit();// unmount SD for reloading IOS SDCard_deInit();// unmount SD for reloading IOS
USBDevice_deInit();// unmount USB for reloading IOS USBDevice_deInit();// unmount USB for reloading IOS
USBStorage_Deinit(); USBStorage_Deinit();
//this is needed otherwise IOS_Reload fails
IOS_ReloadIOSsafe(249);
if (Settings.cios == ios222 && IOS_GetVersion() != 222) if (Settings.cios == ios222 && IOS_GetVersion() != 222)
{ {
printf("\n\tReloading IOS to config setting (222)..."); printf("\n\tReloading IOS to config setting (222)...");
@ -368,7 +340,6 @@ int LoadAppCIOS()
Settings.cios = ios249; Settings.cios = ios249;
IOS_ReloadIOSsafe(249); IOS_ReloadIOSsafe(249);
} }
IOS_Reloaded = true;
} }
if ((Settings.cios == ios249 && IOS_GetVersion() != 249) if ((Settings.cios == ios249 && IOS_GetVersion() != 249)
@ -381,11 +352,10 @@ int LoadAppCIOS()
Settings.cios = ios222; Settings.cios = ios222;
ret = IOS_ReloadIOSsafe(222); ret = IOS_ReloadIOSsafe(222);
} }
IOS_Reloaded = true;
} }
SDCard_Init(); SDCard_Init();
if(IOS_GetVersion() == 222 && IOS_Reloaded) if(IOS_GetVersion() == 222)
load_ehc_module(); load_ehc_module();
USBDevice_Init(); USBDevice_Init();

View File

@ -7,19 +7,18 @@ Load game information from XML - Lustar
#include <malloc.h> #include <malloc.h>
#include "unzip/unzip.h" #include "unzip/unzip.h"
#include "settings/cfg.h" #include "settings/cfg.h"
#include "listfiles.h"
#include "usbloader/partition_usbloader.h"
#include "xml/xml.h" #include "xml/xml.h"
//#include "cfg.h"
//#include "xml.h"
extern struct SSettings Settings; // for loader GX extern struct SSettings Settings; // for loader GX
extern void title_set(char *id, char *title); extern void title_set(char *id, char *title);
extern char* trimcopy(char *dest, char *src, int size); extern char* trimcopy(char *dest, char *src, int size);
extern char game_partition[6];
/* config */ /* config */
static bool xmldebug = false; static bool xmldebug = false;
static char xmlcfg_filename[100] = "wiitdb";
static int xmlmaxsize = 1572864; static int xmlmaxsize = 1572864;
@ -64,22 +63,45 @@ int xmlloadtime = 0;
char * get_nodetext(mxml_node_t *node, char *buffer, int buflen); char * get_nodetext(mxml_node_t *node, char *buffer, int buflen);
bool xml_loaded = false; 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 */ /* 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) { bool OpenXMLDatabase(char* xmlfilepath, char* argdblang, bool argJPtoEN, bool openfile, bool loadtitles, bool keepopen) {
if (!xml_loaded) { if (!xml_loaded) {
bool opensuccess = false; bool opensuccess = false;
char pathname[200]; char pathname[400];
snprintf(pathname, sizeof(pathname), "%s", xmlfilepath); snprintf(pathname, sizeof(pathname), "%s", xmlfilepath);
if (xmlfilepath[strlen(xmlfilepath) - 1] != '/') snprintf(pathname, sizeof(pathname), "%s/",pathname); 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 (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) { if (!opensuccess && openfile) {
CloseXMLDatabase(); CloseXMLDatabase();
return false; return false;