From ff64399e18083cd03c527550bdee6ef1e6a1b2a1 Mon Sep 17 00:00:00 2001 From: dborth Date: Thu, 24 Mar 2011 01:03:29 +0000 Subject: [PATCH] fix slow browser issue --- source/filebrowser.cpp | 8 ++----- source/filebrowser.h | 1 - source/fileop.cpp | 47 +++++++++++++++++++++++++++--------------- source/fileop.h | 1 + source/gcunzip.cpp | 2 +- 5 files changed, 34 insertions(+), 25 deletions(-) diff --git a/source/filebrowser.cpp b/source/filebrowser.cpp index 4444d78..b5c7a3f 100644 --- a/source/filebrowser.cpp +++ b/source/filebrowser.cpp @@ -464,6 +464,8 @@ int BrowserLoadFile() if(!FindDevice(browser.dir, &device)) return 0; + GetFileSize(browser.selIndex); + // check that this is a valid ROM if(!IsValidROM()) goto done; @@ -558,7 +560,6 @@ int BrowserChangeFolder() sprintf(browserList[i].filename, "sd:/"); sprintf(browserList[i].displayname, "SD Card"); browserList[i].length = 0; - browserList[i].mtime = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; @@ -567,7 +568,6 @@ int BrowserChangeFolder() sprintf(browserList[i].filename, "usb:/"); sprintf(browserList[i].displayname, "USB Mass Storage"); browserList[i].length = 0; - browserList[i].mtime = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_USB; i++; @@ -576,7 +576,6 @@ int BrowserChangeFolder() sprintf(browserList[i].filename, "carda:/"); sprintf(browserList[i].displayname, "SD Gecko Slot A"); browserList[i].length = 0; - browserList[i].mtime = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; @@ -585,7 +584,6 @@ int BrowserChangeFolder() sprintf(browserList[i].filename, "cardb:/"); sprintf(browserList[i].displayname, "SD Gecko Slot B"); browserList[i].length = 0; - browserList[i].mtime = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SD; i++; @@ -594,7 +592,6 @@ int BrowserChangeFolder() sprintf(browserList[i].filename, "smb:/"); sprintf(browserList[i].displayname, "Network Share"); browserList[i].length = 0; - browserList[i].mtime = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_SMB; i++; @@ -603,7 +600,6 @@ int BrowserChangeFolder() sprintf(browserList[i].filename, "dvd:/"); sprintf(browserList[i].displayname, "Data DVD"); browserList[i].length = 0; - browserList[i].mtime = 0; browserList[i].isdir = 1; browserList[i].icon = ICON_DVD; i++; diff --git a/source/filebrowser.h b/source/filebrowser.h index e99912d..f41fac7 100644 --- a/source/filebrowser.h +++ b/source/filebrowser.h @@ -33,7 +33,6 @@ typedef struct typedef struct { size_t length; // file length - time_t mtime; // file modified time int isdir; // 0 - file, 1 - directory char filename[MAXJOLIET + 1]; // full filename char displayname[MAXJOLIET + 1]; // name for browser display diff --git a/source/fileop.cpp b/source/fileop.cpp index be88478..ff3f0e1 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -58,7 +58,7 @@ static lwp_t parsethread = LWP_THREAD_NULL; static DIR * dir = NULL; static bool parseHalt = true; static bool parseFilter = true; -bool ParseDirEntries(); +static bool ParseDirEntries(); int selectLoadedFile = 0; // device thread @@ -476,15 +476,30 @@ static char *GetExt(char *file) return ext; } -bool ParseDirEntries() +bool GetFileSize(int i) +{ + if(browserList[i].length > 0) + return true; + + struct stat filestat; + char path[MAXPATHLEN+1]; + snprintf(path, MAXPATHLEN, "%s%s", browser.dir, browserList[i].filename); + + if(stat(path, &filestat) < 0) + return false; + + browserList[i].length = filestat.st_size; + return true; +} + +static bool ParseDirEntries() { if(!dir) return false; char *ext; - char path[MAXPATHLEN+1]; struct dirent *entry = NULL; - struct stat filestat; + int isdir; int i = 0; @@ -500,19 +515,20 @@ bool ParseDirEntries() if(strcmp(entry->d_name, "..") == 0) { - filestat.st_mode = _IFDIR; + isdir = 1; } else { - ext = GetExt(entry->d_name); - snprintf(path, MAXPATHLEN, "%s%s", browser.dir, entry->d_name); - - if(stat(path, &filestat) < 0) - continue; - + 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 && (filestat.st_mode & _IFDIR) == 0) + if(parseFilter && !isdir) { + ext = GetExt(entry->d_name); + if(ext == NULL) continue; @@ -531,11 +547,9 @@ bool ParseDirEntries() } snprintf(browserList[browser.numEntries+i].filename, MAXJOLIET, "%s", entry->d_name); - browserList[browser.numEntries+i].length = filestat.st_size; - browserList[browser.numEntries+i].mtime = filestat.st_mtime; - browserList[browser.numEntries+i].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir + browserList[browser.numEntries+i].isdir = isdir; // flag this as a dir - if(browserList[browser.numEntries+i].isdir) + if(isdir) { if(strcmp(entry->d_name, "..") == 0) sprintf(browserList[browser.numEntries+i].displayname, "Up One Level"); @@ -661,7 +675,6 @@ ParseDirectory(bool waitParse, bool filter) sprintf(browserList[0].filename, ".."); sprintf(browserList[0].displayname, "Up One Level"); browserList[0].length = 0; - browserList[0].mtime = 0; browserList[0].isdir = 1; // flag this as a dir browserList[0].icon = ICON_FOLDER; browser.numEntries++; diff --git a/source/fileop.h b/source/fileop.h index 8c3f4b7..fe3b0f0 100644 --- a/source/fileop.h +++ b/source/fileop.h @@ -29,6 +29,7 @@ char * StripDevice(char * path); bool ChangeInterface(int device, bool silent); bool ChangeInterface(char * filepath, bool silent); void CreateAppPath(char * origpath); +bool GetFileSize(int i); int ParseDirectory(bool waitParse = false, bool filter = true); void AllocSaveBuffer(); void FreeSaveBuffer(); diff --git a/source/gcunzip.cpp b/source/gcunzip.cpp index 7e64583..65ce638 100644 --- a/source/gcunzip.cpp +++ b/source/gcunzip.cpp @@ -373,7 +373,7 @@ int SzParse(char * filepath) int device; - if(!FindDevice(browser.dir, &device)) + if(!FindDevice(browser.dir, &device) || !GetFileSize(browser.selIndex)) return 0; int nbfiles = 0;