fix slow browser issue

This commit is contained in:
dborth 2011-03-24 01:04:02 +00:00
parent 22d1cfea45
commit 4591df7e28
6 changed files with 38 additions and 25 deletions

View File

@ -533,7 +533,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++;
@ -542,7 +541,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++;
@ -551,7 +549,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++;
@ -560,7 +557,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++;
@ -569,7 +565,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++;
@ -578,7 +573,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

@ -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

View File

@ -56,7 +56,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
@ -474,15 +474,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;
@ -498,19 +513,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++;

View File

@ -31,6 +31,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

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

View File

@ -899,6 +899,12 @@ bool LoadVBAROM()
return false;
}
if(!GetFileSize(browser.selIndex))
{
ErrorPrompt("Error loading game!");
return false;
}
srcWidth = 0;
srcHeight = 0;
srcPitch = 0;