diff --git a/source/fileop.cpp b/source/fileop.cpp index 78e2b5f..4f339a6 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include #include @@ -55,7 +55,7 @@ bool isMounted[7] = { false, false, false, false, false, false, false }; // folder parsing thread static lwp_t parsethread = LWP_THREAD_NULL; -static DIR_ITER * dirIter = NULL; +static DIR *dir = NULL; static bool parseHalt = true; static bool parseFilter = true; bool ParseDirEntries(); @@ -480,27 +480,27 @@ static char *GetExt(char *file) bool ParseDirEntries() { - if(!dirIter) + if(!dir) return false; - char filename[MAXPATHLEN]; char *ext; + struct dirent *entry; struct stat filestat; int i = 0; - int res; while(i < 20) { - res = dirnext(dirIter,filename,&filestat); + entry = readdir(dir); - if(res != 0) + if(entry == NULL) break; - if(filename[0] == '.' && filename[1] != '.') + if(entry->d_name[0] == '.' && entry->d_name[1] != '.') continue; - ext = GetExt(filename); + ext = GetExt(entry->d_name); + stat(entry->d_name,&filestat); // don't show the file if it's not a valid ROM if(parseFilter && (filestat.st_mode & _IFDIR) == 0) @@ -520,14 +520,14 @@ bool ParseDirEntries() break; } - strncpy(browserList[browser.numEntries+i].filename, filename, MAXJOLIET); + strncpy(browserList[browser.numEntries+i].filename, entry->d_name, MAXJOLIET); 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 if(browserList[browser.numEntries+i].isdir) { - if(strcmp(filename, "..") == 0) + if(strcmp(entry->d_name, "..") == 0) sprintf(browserList[browser.numEntries+i].displayname, "Up One Level"); else strncpy(browserList[browser.numEntries+i].displayname, browserList[browser.numEntries+i].filename, MAXJOLIET); @@ -546,10 +546,10 @@ bool ParseDirEntries() browser.numEntries += i; - if(res != 0 || parseHalt) + if(entry == NULL || parseHalt) { - dirclose(dirIter); // close directory - dirIter = NULL; + closedir(dir); // close directory + dir = NULL; // try to find and select the last loaded file if(selectLoadedFile == 1 && parseHalt == 0 && loadedFile[0] != 0 && browser.dir[0] != 0) @@ -603,23 +603,23 @@ ParseDirectory(bool waitParse, bool filter) ResetBrowser(); // reset browser // open the directory - while(dirIter == NULL && retry == 1) + while(dir == NULL && retry == 1) { mounted = ChangeInterface(browser.dir, NOTSILENT); if(mounted) - dirIter = diropen(browser.dir); + dir = opendir(browser.dir); else return -1; - if(dirIter == NULL) + if(dir == NULL) { retry = ErrorPromptRetry("Error opening directory!"); } } // if we can't open the dir, try higher levels - if (dirIter == NULL) + if (dir == NULL) { char * devEnd = strrchr(browser.dir, '/'); @@ -632,13 +632,13 @@ ParseDirectory(bool waitParse, bool filter) break; devEnd[1] = 0; // strip remaining file listing - dirIter = diropen(browser.dir); - if (dirIter) + dir = opendir(browser.dir); + if (dir) break; } } - if(dirIter == NULL) + if(dir == NULL) return -1; if(IsDeviceRoot(browser.dir)) diff --git a/source/preferences.cpp b/source/preferences.cpp index df77068..c7aeea7 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include @@ -502,7 +502,7 @@ SavePrefs (bool silent) return false; sprintf(filepath, "%s%s", pathPrefix[device], APPFOLDER); - DIR_ITER *dir = diropen(filepath); + DIR *dir = opendir(filepath); if (!dir) { if(mkdir(filepath, 0777) != 0) @@ -516,7 +516,7 @@ SavePrefs (bool silent) } else { - dirclose(dir); + closedir(dir); } sprintf(filepath, "%s%s/%s", pathPrefix[device], APPFOLDER, PREF_FILE_NAME); sprintf(prefpath, "%s%s", pathPrefix[device], APPFOLDER); @@ -623,17 +623,17 @@ bool LoadPrefs() // rename snes9x to snes9xgx if(GCSettings.LoadMethod == DEVICE_SD) { - if(ChangeInterface(DEVICE_SD, NOTSILENT) && diropen("sd:/snes9x")) + if(ChangeInterface(DEVICE_SD, NOTSILENT) && opendir("sd:/snes9x")) rename("sd:/snes9x", "sd:/snes9xgx"); } else if(GCSettings.LoadMethod == DEVICE_USB) { - if(ChangeInterface(DEVICE_USB, NOTSILENT) && diropen("usb:/snes9x")) + if(ChangeInterface(DEVICE_USB, NOTSILENT) && opendir("usb:/snes9x")) rename("usb:/snes9x", "usb:/snes9xgx"); } else if(GCSettings.LoadMethod == DEVICE_SMB) { - if(ChangeInterface(DEVICE_SMB, NOTSILENT) && diropen("smb:/snes9x")) + if(ChangeInterface(DEVICE_SMB, NOTSILENT) && opendir("smb:/snes9x")) rename("smb:/snes9x", "smb:/snes9xgx"); }