/*************************************************************************** * Browse subdirectories **************************************************************************/ int CustomBrowser::ParseDirectory(bool filteringList UNUSED) { gettingList = true; ResetBrowser(); std::string fulldir(browserRootDir); fulldir += browserDir; //! open the directory dir = opendir(fulldir.c_str()); if(dir == NULL) { //! if we can't open the dir, try opening the root dir browserDir.clear(); fulldir = browserRootDir; dir = opendir(fulldir.c_str()); if(dir == NULL) { gettingList = false; return -1; } } currentpath = fulldir; ParseDirEntries(); gettingList = false; return browserList.size(); }
int ParseDirectory() { bool mounted = false; ResetBrowser(); // reset browser // add trailing slash if(browser.dir[strlen(browser.dir)-1] != '/') strcat(browser.dir, "/"); mounted = ChangeInterface(browser.dir, SILENT); if(mounted){ dir = opendir(browser.dir); if(dir == NULL){ //Profile folder not found, attempt to create it. char temp[128]; strcpy(temp, browser.dir); temp[strlen(browser.dir)-1] = 0; mkdir(temp, 0777); dir = opendir(browser.dir); } }else{ return -1; } if (dir == NULL) return -1; ParseProfilesDir(); // index first 20 entries return browser.numEntries; }
bool AutoloadGame(char* filepath, char* filename) { ResetBrowser(); selectLoadedFile = 1; std::string dir(filepath); dir.assign(&dir[dir.find_last_of(":") + 2]); strncpy(GCSettings.LoadFolder, dir.c_str(), sizeof(GCSettings.LoadFolder)); OpenGameList(); for(int i = 0; i < browser.numEntries; i++) { // Skip it if (strcmp(browserList[i].filename, ".") == 0 || strcmp(browserList[i].filename, "..") == 0) { continue; } if(strcasestr(browserList[i].filename, filename) != NULL) { browser.selIndex = i; if(IsSz()) { BrowserLoadSz(); browser.selIndex = 1; } break; } } if(BrowserLoadFile() > 0) { return true; } return false; }
int OpenProfilesFolder() { sprintf(browser.dir, "%s/profiles/", appPath); int device = 0; FindDevice(browser.dir, &device); CleanupPath(browser.dir); ResetBrowser(); // reset browser return ParseDirectory(); }
/**************************************************************************** * ParseMCDirectory * * Parses a list of all files on the specified memory card ***************************************************************************/ int ParseMCDirectory (int slot) { card_dir CardDir; int CardError; int entryNum = 0; // Try to mount the card CardError = MountMC(slot, NOTSILENT); if (CardError == 0) { CardError = CARD_FindFirst (slot, &CardDir, TRUE); while (CardError != CARD_ERROR_NOFILE) { BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (entryNum+1) * sizeof(BROWSERENTRY)); if(!newBrowserList) // failed to allocate required memory { ResetBrowser(); ErrorPrompt("Out of memory: too many files!"); entryNum = -1; break; } else { browserList = newBrowserList; } memset(&(browserList[entryNum]), 0, sizeof(BROWSERENTRY)); // clear the new entry strncpy(browserList[entryNum].filename, (char *)CardDir.filename, MAXJOLIET); StripExt(browserList[entryNum].displayname, browserList[entryNum].filename); // hide file extension browserList[entryNum].length = CardDir.filelen; entryNum++; CardError = CARD_FindNext (&CardDir); } CARD_Unmount(slot); } // Sort the file list qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback); CancelAction(); browser.numEntries = entryNum; return entryNum; }
/**************************************************************************** * BrowserLoadFile * * Loads the selected ROM ***************************************************************************/ int BrowserLoadFile() { int loaded = 0; int device; if(!FindDevice(browser.dir, &device)) return 0; // check that this is a valid ROM if(!IsValidROM()) goto done; // store the filename (w/o ext) - used for sram/freeze naming StripExt(Memory.ROMFilename, browserList[browser.selIndex].filename); snprintf(GCSettings.LastFileLoaded, MAXPATHLEN, "%s", browserList[browser.selIndex].filename); strncpy(Memory.ROMFilePath, browser.dir, PATH_MAX); SNESROMSize = 0; S9xDeleteCheats(); Memory.LoadROM("ROM"); if (SNESROMSize == 0) { ErrorPrompt("Error loading game!"); } else if(bsxBiosLoadFailed) { ErrorPrompt("BS-X BIOS file not found!"); } else { // load SRAM or snapshot if (GCSettings.AutoLoad == 1) LoadSRAMAuto(SILENT); else if (GCSettings.AutoLoad == 2) LoadSnapshotAuto(SILENT); ResetBrowser(); loaded = 1; } done: CancelAction(); return loaded; }
/**************************************************************************** * BrowserLoadFile * * Loads the selected ROM ***************************************************************************/ int BrowserLoadFile() { int loaded = 0; int device; if(!FindDevice(browser.dir, &device)) return 0; GetFileSize(browser.selIndex); // check that this is a valid ROM if(!IsValidROM()) goto done; // store the filename (w/o ext) - used for sram/freeze naming StripExt(Memory.ROMFilename, browserList[browser.selIndex].filename); strcpy(loadedFile, browserList[browser.selIndex].filename); SNESROMSize = 0; S9xDeleteCheats(); Memory.LoadROM("ROM"); if (SNESROMSize <= 0) { ErrorPrompt("Error loading game!"); } else { // load SRAM or snapshot if (GCSettings.AutoLoad == 1) LoadSRAMAuto(SILENT); else if (GCSettings.AutoLoad == 2) LoadSnapshotAuto(SILENT); ResetBrowser(); loaded = 1; } done: CancelAction(); return loaded; }
/**************************************************************************** * BrowserLoadFile * * Loads the selected ROM ***************************************************************************/ int BrowserLoadFile() { int device; if(!FindDevice(browser.dir, &device)) return 0; // store the filename (w/o ext) - used for sram/freeze naming StripExt(ROMFilename, browserList[browser.selIndex].filename); snprintf(GCSettings.LastFileLoaded, MAXPATHLEN, "%s", browserList[browser.selIndex].filename); loadingFile = true; ROMLoaded = LoadVBAROM(); loadingFile = false; if (!ROMLoaded) { if(inSz) { browser.selIndex = 0; BrowserChangeFolder(); } ErrorPrompt("Error loading game!"); } else { if (GCSettings.AutoLoad == 1) LoadBatteryOrStateAuto(FILE_SRAM, SILENT); else if (GCSettings.AutoLoad == 2) LoadBatteryOrStateAuto(FILE_SNAPSHOT, SILENT); ResetBrowser(); } CancelAction(); return ROMLoaded; }
/*************************************************************************** * Browse subdirectories **************************************************************************/ int ParseDirectory() { DIR *dir = NULL; char fulldir[MAXPATHLEN]; struct dirent *entry; // reset browser ResetBrowser(); // open the directory sprintf(fulldir, "%s%s", rootdir, browser.dir); // add currentDevice to path dir = opendir(fulldir); // if we can't open the dir, try opening the root dir if (dir == NULL) { sprintf(browser.dir, "/"); dir = opendir(rootdir); if (dir == NULL) { return -1; } } // index files/folders int entryNum = 0; while ((entry = readdir(dir))) { if (strcmp(entry->d_name, ".") == 0) continue; BROWSERENTRY * newBrowserList = (BROWSERENTRY *) realloc(browserList, (entryNum + 1) * sizeof (BROWSERENTRY)); if (!newBrowserList) // failed to allocate required memory { ResetBrowser(); entryNum = -1; break; } else { browserList = newBrowserList; } memset(&(browserList[entryNum]), 0, sizeof (BROWSERENTRY)); // clear the new entry strncpy(browserList[entryNum].filename, entry->d_name, MAXJOLIET); if (strcmp(entry->d_name, "..") == 0) { sprintf(browserList[entryNum].displayname, "Up One Level"); browserList[entryNum].isdir = 1; // flag this as a dir } else { strncpy(browserList[entryNum].displayname, entry->d_name, MAXDISPLAY); // crop name for display if (entry->d_type == DT_DIR) browserList[entryNum].isdir = 1; // flag this as a dir } printf("entry->d_name = %s\r\n",entry->d_name); entryNum++; } // close directory closedir(dir); // Sort the file list qsort(browserList, entryNum, sizeof (BROWSERENTRY), FileSortCallback); browser.numEntries = entryNum; return entryNum; }
/*************************************************************************** * 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; }
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; }
int SzParse(char * filepath, int method) { if(!filepath) return 0; int nbfiles = 0; // save the length/offset of this file unsigned int filelen = browserList[browser.selIndex].length; u64 fileoff = browserList[browser.selIndex].offset; // setup archive stream SzArchiveStream.offset = 0; SzArchiveStream.len = filelen; SzArchiveStream.pos = 0; // open file switch (method) { case METHOD_SD: case METHOD_USB: case METHOD_SMB: file = fopen (filepath, "rb"); if(!file) return 0; break; case METHOD_DVD: SwitchDVDFolder(filepath); break; } // set szMethod to current chosen load method szMethod = method; // 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 // reset browser ResetBrowser(); // add '..' folder in case the user wants exit the 7z strncpy(browserList[0].displayname, "..", 2); browserList[0].isdir = 1; browserList[0].offset = fileoff; browserList[0].length = filelen; // 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; BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (SzJ+1) * sizeof(BROWSERENTRY)); if(!newBrowserList) // failed to allocate required memory { ResetBrowser(); WaitPrompt("Out of memory: too many files!"); nbfiles = 0; break; } else { browserList = newBrowserList; } memset(&(browserList[SzJ]), 0, sizeof(BROWSERENTRY)); // clear the new entry // parse information about this file to the dvd file list structure strncpy(browserList[SzJ].filename, SzF->Name, MAXJOLIET); // copy joliet name (useless...) strncpy(browserList[SzJ].displayname, SzF->Name, MAXDISPLAY); // crop name for display browserList[SzJ].length = SzF->Size; // filesize browserList[SzJ].offset = SzI; // the extraction function identifies the file with this number browserList[SzJ].isdir = 0; // only files will be displayed (-> no flags) SzJ++; } nbfiles = SzJ; } else { SzArDbExFree(&SzDb, SzAllocImp.Free); } } // close file switch (method) { case METHOD_SD: case METHOD_USB: case METHOD_SMB: fclose(file); break; } 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(!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; }