static bool ParseProfilesDir() { if(!dir) return false; char *ext; struct dirent *entry = NULL; int i = 0; while(i < MAX_BROWSER_SIZE) { entry = readdir(dir); if(entry == NULL) break; if(entry->d_name[0] == '.' && entry->d_name[1] != '.') continue; if(strcmp(entry->d_name, "..") == 0) continue; if(entry->d_type==DT_DIR) continue; ext = GetExt(entry->d_name); if(ext == NULL || stricmp(ext, "wtp") != 0) continue; if(!AddBrowserEntry()) { break; } snprintf(browserList[browser.numEntries+i].filename, MAXJOLIET, "%s", entry->d_name); StripExt(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename); // hide file extension i++; } // Sort the file list if(i >= 0) qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback); browser.numEntries += i; if(entry == NULL) { closedir(dir); // close directory dir = NULL; return false; // no more entries } return true; // more entries }
/*************************************************************************** * Browse subdirectories **************************************************************************/ int ParseDirectory(bool waitParse, bool filter) { int retry = 1; bool mounted = false; parseFilter = filter; ResetBrowser(); // reset browser // add trailing slash if(browser.dir[strlen(browser.dir)-1] != '/') strcat(browser.dir, "/"); // open the directory while(dir == NULL && retry == 1) { mounted = ChangeInterface(browser.dir, NOTSILENT); if(mounted) dir = opendir(browser.dir); else return -1; if(dir == NULL) retry = ErrorPromptRetry("Error opening directory!"); } // if we can't open the dir, try higher levels if (dir == NULL) { char * devEnd = strrchr(browser.dir, '/'); while(!IsDeviceRoot(browser.dir)) { devEnd[0] = 0; // strip slash devEnd = strrchr(browser.dir, '/'); if(devEnd == NULL) break; devEnd[1] = 0; // strip remaining file listing dir = opendir(browser.dir); if (dir) break; } } if(dir == NULL) return -1; if(IsDeviceRoot(browser.dir)) { AddBrowserEntry(); sprintf(browserList[0].filename, ".."); sprintf(browserList[0].displayname, "Up One Level"); browserList[0].length = 0; browserList[0].isdir = 1; // flag this as a dir browserList[0].icon = ICON_FOLDER; browser.numEntries++; } parseHalt = false; ParseDirEntries(); // index first 20 entries LWP_ResumeThread(parsethread); // index remaining entries if(waitParse) // wait for complete parsing { ShowAction("Loading..."); while(!LWP_ThreadIsSuspended(parsethread)) usleep(THREAD_SLEEP); CancelAction(); } return browser.numEntries; }
static bool ParseDirEntries() { if(!dir) return false; char *ext; struct dirent *entry = NULL; int isdir; int i = 0; while(i < 20 && !parseHalt) { entry = readdir(dir); if(entry == NULL) break; if(entry->d_name[0] == '.' && entry->d_name[1] != '.') continue; if(strcmp(entry->d_name, "..") == 0) { isdir = 1; } else { if(entry->d_type==DT_DIR) isdir = 1; else isdir = 0; // don't show the file if it's not a valid ROM if(parseFilter && !isdir) { ext = GetExt(entry->d_name); if(ext == NULL) continue; if( stricmp(ext, "agb") != 0 && stricmp(ext, "gba") != 0 && stricmp(ext, "bin") != 0 && stricmp(ext, "elf") != 0 && stricmp(ext, "mb") != 0 && stricmp(ext, "dmg") != 0 && stricmp(ext, "gb") != 0 && stricmp(ext, "gbc") != 0 && stricmp(ext, "cgb") != 0 && stricmp(ext, "sgb") != 0 && stricmp(ext, "zip") != 0 && stricmp(ext, "7z") != 0) continue; } } if(!AddBrowserEntry()) { parseHalt = true; break; } snprintf(browserList[browser.numEntries+i].filename, MAXJOLIET, "%s", entry->d_name); browserList[browser.numEntries+i].isdir = isdir; // flag this as a dir if(isdir) { if(strcmp(entry->d_name, "..") == 0) sprintf(browserList[browser.numEntries+i].displayname, "Up One Level"); else snprintf(browserList[browser.numEntries+i].displayname, MAXJOLIET, "%s", browserList[browser.numEntries+i].filename); browserList[browser.numEntries+i].icon = ICON_FOLDER; } else { StripExt(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename); // hide file extension } i++; } if(!parseHalt) { // Sort the file list if(i >= 0) qsort(browserList, browser.numEntries+i, sizeof(BROWSERENTRY), FileSortCallback); browser.numEntries += i; } if(entry == NULL || parseHalt) { closedir(dir); // close directory dir = NULL; return false; // no more entries } return true; // more entries }
int SzParse(char * filepath) { if(!filepath) return 0; int device; if(!FindDevice(browser.dir, &device) || !GetFileSize(browser.selIndex)) return 0; int nbfiles = 0; // save the length/offset of this file unsigned int filelen = browserList[browser.selIndex].length; // setup archive stream SzArchiveStream.offset = 0; SzArchiveStream.len = filelen; SzArchiveStream.pos = 0; // open file file = fopen (filepath, "rb"); if(!file) return 0; // set szMethod to current chosen load device szMethod = device; // set handler functions for reading data from SD/USB/SMB/DVD SzArchiveStream.InStream.Read = SzFileReadImp; SzArchiveStream.InStream.Seek = SzFileSeekImp; // set default 7Zip SDK handlers for allocation and freeing memory SzAllocImp.Alloc = SzAlloc; SzAllocImp.Free = SzFree; SzAllocTempImp.Alloc = SzAllocTemp; SzAllocTempImp.Free = SzFreeTemp; // prepare CRC and 7Zip database structures InitCrcTable(); SzArDbExInit(&SzDb); // open the archive SzRes = SzArchiveOpen(&SzArchiveStream.InStream, &SzDb, &SzAllocImp, &SzAllocTempImp); if (SzRes != SZ_OK) { SzDisplayError(SzRes); // free memory used by the 7z SDK SzClose(); } else // archive opened successfully { if(SzDb.Database.NumFiles > 0) { // Parses the 7z into a full file listing HaltParseThread(); // halt parsing ResetBrowser(); // reset browser // add '..' folder in case the user wants exit the 7z AddBrowserEntry(); sprintf(browserList[0].displayname, "Up One Level"); browserList[0].isdir = 1; browserList[0].length = filelen; browserList[0].icon = ICON_FOLDER; // get contents and parse them into file list structure unsigned int SzI, SzJ; SzJ = 1; for (SzI = 0; SzI < SzDb.Database.NumFiles; SzI++) { SzF = SzDb.Database.Files + SzI; // skip directories if (SzF->IsDirectory) continue; if(!AddBrowserEntry()) { ResetBrowser(); ErrorPrompt("Out of memory: too many files!"); SzClose(); SzJ = 0; break; } // parse information about this file to the file list structure snprintf(browserList[SzJ].filename, MAXJOLIET, "%s", SzF->Name); StripExt(browserList[SzJ].displayname, browserList[SzJ].filename); browserList[SzJ].length = SzF->Size; // filesize browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags) browserList[SzJ].filenum = SzI; // the extraction function identifies the file with this number SzJ++; } nbfiles = SzJ; } else { SzClose(); } } CancelAction(); // close file fclose(file); return nbfiles; }
/**************************************************************************** * BrowserChangeFolder * * Update current directory and set new entry list if directory has changed ***************************************************************************/ int BrowserChangeFolder() { int device = 0; FindDevice(browser.dir, &device); if(inSz && browser.selIndex == 0) // inside a 7z, requesting to leave { inSz = false; SzClose(); } if(!UpdateDirName()) return -1; HaltParseThread(); CleanupPath(browser.dir); ResetBrowser(); if(browser.dir[0] != 0) { if(strstr(browser.dir, ".7z")) { BrowserLoadSz(); } else { ParseDirectory(true, true); } FindAndSelectLastLoadedFile(); } if(browser.numEntries == 0) { browser.dir[0] = 0; int i=0; #ifdef HW_RVL AddBrowserEntry(); sprintf(browserList[i].filename, "sd:/"); sprintf(browserList[i].displayname, "SD Card"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "usb:/"); sprintf(browserList[i].displayname, "USB Mass Storage"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_USB; i++; #else AddBrowserEntry(); sprintf(browserList[i].filename, "carda:/"); sprintf(browserList[i].displayname, "SD Gecko Slot A"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "cardb:/"); sprintf(browserList[i].displayname, "SD Gecko Slot B"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; #endif AddBrowserEntry(); sprintf(browserList[i].filename, "smb:/"); sprintf(browserList[i].displayname, "Network Share"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SMB; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "dvd:/"); sprintf(browserList[i].displayname, "Data DVD"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_DVD; i++; browser.numEntries += i; } if(browser.dir[0] == 0) { GCSettings.LoadFolder[0] = 0; GCSettings.LoadMethod = 0; } else { char * path = StripDevice(browser.dir); if(path != NULL) strcpy(GCSettings.LoadFolder, path); FindDevice(browser.dir, &GCSettings.LoadMethod); } return browser.numEntries; }
/**************************************************************************** * BrowserChangeFolder * * Update current directory and set new entry list if directory has changed ***************************************************************************/ int BrowserChangeFolder() { int device = 0; FindDevice(browser.dir, &device); if(!UpdateDirName()){ return -1; } HaltParseThread(); // halt parsing CleanupPath(browser.dir); ResetBrowser(); // reset browser if(browser.dir[0] != 0){ ParseDirectory(); } if(browser.numEntries == 0) { browser.dir[0] = 0; int i=0; #if 0 AddBrowserEntry(); sprintf(browserList[i].filename, "uda:/"); sprintf(browserList[i].displayname, "USB Mass Storage"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_USB; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "sda0:/"); sprintf(browserList[i].displayname, "Hard Drive"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "smb:/"); sprintf(browserList[i].displayname, "Network Share"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SMB; i++; AddBrowserEntry(); sprintf(browserList[i].filename, "dvd:/"); sprintf(browserList[i].displayname, "Data DVD"); browserList[i].length = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_DVD; i++; #else // dynamic use int iusb = 0; int ihdd = 0; int imisc = 0; for (int id = 3; id < STD_MAX; id++) { if (devoptab_list[id]->structSize) { AddBrowserEntry(); sprintf(browserList[i].filename, "%s:/", devoptab_list[id]->name); browserList[i].length = 0; browserList[i].isdir = 1; switch(browserList[i].filename[0]) { case 'u': { browserList[i].icon = ICON_USB; sprintf(browserList[i].displayname, "USB Mass Storage %d", iusb++); break; } case 's': { browserList[i].icon = ICON_SD; sprintf(browserList[i].displayname, "Hard Drive %d", ihdd++); break; } default: { browserList[i].icon = ICON_DVD; sprintf(browserList[i].displayname, "DVD %d", imisc++); break; } } printf("findDevices : %s\r\n", browserList[i].filename); i++; } } #endif browser.numEntries += i; } if(browser.dir[0] == 0) { GCSettings.LoadFolder[0] = 0; GCSettings.LoadMethod = 0; } else { char * path = StripDevice(browser.dir); if(path != NULL) strcpy(GCSettings.LoadFolder, path); FindDevice(browser.dir, &GCSettings.LoadMethod); } return browser.numEntries; }