From ed39cf26555fba7420961f7721d13117fc07fa14 Mon Sep 17 00:00:00 2001 From: dsbomb Date: Tue, 29 Apr 2008 17:23:13 +0000 Subject: [PATCH] add WiiSD directory parsing --- source/drivers/gamecube/gcdvd.c | 110 +++++++++++++++++++++++--------- source/drivers/gamecube/info.c | 2 +- source/drivers/gamecube/sz.c | 4 +- 3 files changed, 84 insertions(+), 32 deletions(-) diff --git a/source/drivers/gamecube/gcdvd.c b/source/drivers/gamecube/gcdvd.c index 723429a..3ad1178 100644 --- a/source/drivers/gamecube/gcdvd.c +++ b/source/drivers/gamecube/gcdvd.c @@ -67,7 +67,7 @@ extern int ChosenSlot; extern bool isWii; int UseSDCARD = 0; -int UseFrontSDCARD = 0; +int UseWiiSDCARD = 0; sd_file * filehandle = NULL; char rootSDdir[SDCARD_MAX_PATH_LEN]; char rootWiiSDdir[SDCARD_MAX_PATH_LEN]; @@ -426,23 +426,21 @@ int parsedir() { /*************************************************************************** * Update SDCARD curent directory name ***************************************************************************/ -int updateSDdirname() -{ +int updateSDdirname() { int size=0; char *test; char temp[1024]; /* current directory doesn't change */ - if (strcmp(filelist[selection].filename,".") == 0) return 0; + if (strcmp(filelist[selection].filename,".") == 0) + return 0; /* go up to parent directory */ - else if (strcmp(filelist[selection].filename,"..") == 0) - { + if (strcmp(filelist[selection].filename,"..") == 0) { /* determine last subdirectory namelength */ sprintf(temp,"%s",rootSDdir); - test= strtok(temp,"\\"); - while (test != NULL) - { + test = strtok(temp,"\\"); + while (test != NULL) { size = strlen(test); test = strtok(NULL,"\\"); } @@ -453,32 +451,70 @@ int updateSDdirname() /* handles root name */ //sprintf(tmpCompare, "dev%d:",ChosenSlot); - if (strcmp(rootSDdir, sdslot ? "dev1:":"dev0:") == 0)sprintf(rootSDdir,"dev%d:\\fceu\\..", sdslot); + if (strcmp(rootSDdir, sdslot ? "dev1:":"dev0:") == 0) + sprintf(rootSDdir,"dev%d:\\%s\\..", sdslot, FCEUDIR); return 1; - } - else - { + } else { /* test new directory namelength */ - if ((strlen(rootSDdir)+1+strlen(filelist[selection].filename)) < SDCARD_MAX_PATH_LEN) - { + if ((strlen(rootSDdir)+1+strlen(filelist[selection].filename)) < SDCARD_MAX_PATH_LEN) { /* handles root name */ - //sprintf(tmpCompare, "dev%d:\\fceu\\..",ChosenSlot); - //if (strcmp(rootSDdir, tmpCompare) == 0) sprintf(rootSDdir,"dev%d:",ChosenSlot); - if (strcmp(rootSDdir, sdslot ? "dev1:\\fceu\\.." : "dev0:\\fceu\\..") == 0) sprintf(rootSDdir,"dev%d:",sdslot); + sprintf(temp, "dev%d:\\%s\\..", sdslot, FCEUDIR); + if (strcmp(rootSDdir, temp) == 0) + sprintf(rootSDdir,"dev%d:",sdslot); /* update current directory name */ sprintf(rootSDdir, "%s\\%s",rootSDdir, filelist[selection].filename); return 1; - } - else - { + } else { WaitPrompt ("Dirname is too long !"); return -1; } } } +#ifdef HW_RVL +/*************************************************************************** + * * Update WiiSDCARD curent directory name + * ***************************************************************************/ +int updateWiiSDdirname() { + int size=0; + char *test; + char temp[1024]; + + /* current directory doesn't change */ + if (strcmp(filelist[selection].filename,".") == 0) + return 0; + + /* go up to parent directory */ + else if (strcmp(filelist[selection].filename,"..") == 0) { + /* determine last subdirectory namelength */ + sprintf(temp,"%s",rootWiiSDdir); + test = strtok(temp,"/"); + while (test != NULL) { + size = strlen(test); + test = strtok(NULL,"/"); + } + + /* remove last subdirectory name */ + size = strlen(rootWiiSDdir) - size - 1; + rootWiiSDdir[size] = 0; + + return 1; + } else { + /* test new directory namelength */ + if ((strlen(rootWiiSDdir)+1+strlen(filelist[selection].filename)) < SDCARD_MAX_PATH_LEN) { + /* update current directory name */ + sprintf(rootWiiSDdir, "%s/%s",rootWiiSDdir, filelist[selection].filename); + return 1; + } else { + WaitPrompt ((char*)"Dirname is too long !"); + return -1; + } + } +} +#endif + /*************************************************************************** * Browse SDCARD subdirectories ***************************************************************************/ @@ -602,7 +638,7 @@ void ShowFiles( int offset, int selection ) { char dir[1024]; if (UseSDCARD) strcpy(dir, rootSDdir); - else if (UseFrontSDCARD) + else if (UseWiiSDCARD) strcpy(dir, rootWiiSDdir); else dir[0] = 0; @@ -698,6 +734,22 @@ void FileSelector() { haverom = 1; // quit SD menu haveSDdir = 0; // reset everything at next access } +#ifdef HW_RVL + } else if (UseWiiSDCARD) { + /* update current directory and set new entry list if directory has changed */ + int status = updateWiiSDdirname(); + if (status == 1) { + maxfiles = parseWiiSDdirectory(); + if (!maxfiles) { + WaitPrompt ((char*)"Error reading directory !"); + haverom = 1; // quit SD menu + haveWiiSDdir = 0; // reset everything at next access + } + } else if (status == -1) { + haverom = 1; // quit SD menu + haveWiiSDdir = 0; // reset everything at next access + } +#endif } else { rootdir = filelist[selection].offset; rootdirlength = filelist[selection].length; @@ -735,7 +787,7 @@ void FileSelector() { } } else { #ifdef HW_RVL - if (UseFrontSDCARD) { + if (UseWiiSDCARD) { strncpy(finfo.fname, filelist[selection].filename, 12); int l = strlen(finfo.fname); if (l > 12) l = 12; @@ -768,7 +820,7 @@ int LoadDVDFile( unsigned char *buffer ) { FIL fp; u32 bytes_read = 0, bytes_read_total = 0; - if(UseFrontSDCARD) { + if(UseWiiSDCARD) { ShowAction((char*)"Loading ... Wait"); char filename[1024]; sprintf(filename, "%s/%s", rootWiiSDdir, finfo.fname); @@ -907,8 +959,8 @@ int OpenDVD() { } #ifdef HW_RVL -int OpenFrontSD () { - UseFrontSDCARD = 1; +int OpenWiiSD () { + UseWiiSDCARD = 1; UseSDCARD = 0; haveSDdir = 0; char msg[128]; @@ -954,7 +1006,7 @@ int OpenFrontSD () { int OpenSD () { UseSDCARD = 1; - UseFrontSDCARD = 0; + UseWiiSDCARD = 0; haveWiiSDdir = 0; char msg[128]; @@ -965,7 +1017,7 @@ int OpenSD () { havedir = 0; /* Reset SDCARD root directory */ - sprintf(rootSDdir,"dev%d:\\fceu\\roms",ChosenSlot); + sprintf(rootSDdir,"dev%d:\\%s\\%s", FCEUDIR, SAVEDIR, ChosenSlot); sdslot = ChosenSlot; /* Parse initial root directory and get entries list */ @@ -980,7 +1032,7 @@ int OpenSD () { haveSDdir = 1; } else { /* no entries found */ - sprintf (msg, "Error reading dev%d:\\fceu\\roms", ChosenSlot); + sprintf (msg, "Error reading %s", rootSDdir); WaitPrompt (msg); return 0; } diff --git a/source/drivers/gamecube/info.c b/source/drivers/gamecube/info.c index e3b78d4..58d19a4 100644 --- a/source/drivers/gamecube/info.c +++ b/source/drivers/gamecube/info.c @@ -913,7 +913,7 @@ int MediaSelect() { case MEDIA_SDCARD: #ifdef HW_RVL if (ChosenSlot == SLOT_WIISD) { - OpenFrontSD(); + OpenWiiSD(); } else #endif OpenSD(); diff --git a/source/drivers/gamecube/sz.c b/source/drivers/gamecube/sz.c index 92db6da..5b2cd84 100644 --- a/source/drivers/gamecube/sz.c +++ b/source/drivers/gamecube/sz.c @@ -10,7 +10,7 @@ #include "sz.h" extern int UseSDCARD; -extern int UseFrontSDCARD; +extern int UseWiiSDCARD; extern sd_file *filehandle; // 7zip error list @@ -70,7 +70,7 @@ int dvd_buffered_read(void *dst, u32 len, u64 offset) { GetSDInfo(); SDCARD_SeekFile(filehandle, offset, SDCARD_SEEK_SET); SDCARD_ReadFile(filehandle, &dvdsf_buffer, len); - } else if (!UseFrontSDCARD) + } else if (!UseWiiSDCARD) ret = dvd_read(&dvdsf_buffer, len, offset); dvdsf_last_offset = offset; dvdsf_last_length = len;