fix slow browser issue

This commit is contained in:
dborth 2011-03-24 01:02:33 +00:00
parent 720306a188
commit ce4ee053b6
5 changed files with 34 additions and 25 deletions

View File

@ -498,6 +498,8 @@ int BrowserLoadFile()
if(!FindDevice(browser.dir, &device))
return 0;
GetFileSize(browser.selIndex);
// check that this is a valid ROM
if(!IsValidROM())
goto done;
@ -566,7 +568,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++;
@ -575,7 +576,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++;
@ -584,7 +584,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++;
@ -593,7 +592,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++;
@ -602,7 +600,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++;
@ -611,7 +608,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++;

View File

@ -36,7 +36,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

View File

@ -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;
@ -530,11 +546,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");
@ -662,7 +676,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++;

View File

@ -34,6 +34,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();

View File

@ -374,7 +374,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;