diff --git a/console/libretro_mgmt.c b/console/libretro_mgmt.c index b5995b4a24..48ed9a6dca 100644 --- a/console/libretro_mgmt.c +++ b/console/libretro_mgmt.c @@ -87,7 +87,7 @@ const char *rarch_manage_libretro_set_first_file(const char *libretro_path, cons //We need to set libretro to the first entry in the cores //directory so that it will be saved to the config file - char ** dir_list = dir_list_new(libretro_path, exe_ext); + char ** dir_list = dir_list_new(libretro_path, exe_ext, false); const char * retstr = NULL; const char * first_exe; diff --git a/console/salamander/main.c b/console/salamander/main.c index 429ea54178..8fb038e22e 100644 --- a/console/salamander/main.c +++ b/console/salamander/main.c @@ -87,9 +87,9 @@ static void find_and_set_first_file(void) // we can find in the RetroArch cores directory #if defined(_XBOX) - char ** dir_list = dir_list_new("game:\\", ".xex"); + char ** dir_list = dir_list_new("game:\\", ".xex", false); #elif defined(__CELLOS_LV2__) - char ** dir_list = dir_list_new(LIBRETRO_DIR_PATH, ".SELF"); + char ** dir_list = dir_list_new(LIBRETRO_DIR_PATH, ".SELF", false); #endif if (!dir_list) diff --git a/driver.c b/driver.c index 7f7fb83069..9e93197236 100644 --- a/driver.c +++ b/driver.c @@ -471,7 +471,7 @@ static void init_shader_dir(void) if (!*g_settings.video.shader_dir) return; - g_extern.shader_dir.elems = dir_list_new(g_settings.video.shader_dir, ".shader"); + g_extern.shader_dir.elems = dir_list_new(g_settings.video.shader_dir, ".shader", false); g_extern.shader_dir.size = 0; g_extern.shader_dir.ptr = 0; if (g_extern.shader_dir.elems) diff --git a/file.h b/file.h index 2fce5e9f49..2ad5972181 100644 --- a/file.h +++ b/file.h @@ -43,7 +43,7 @@ bool init_rom_file(enum rarch_game_type type); // Returns a NULL-terminated list of files in a directory with full paths. // If ext is NULL, any file will be picked. // If non-NULL, only files with extension ext are added. -char **dir_list_new(const char *dir, const char *ext); +char **dir_list_new(const char *dir, const char *ext, bool include_dirs); void dir_list_free(char **dir_list); bool path_is_directory(const char *path); diff --git a/file_path.c b/file_path.c index c38f366aa9..009c56106c 100644 --- a/file_path.c +++ b/file_path.c @@ -43,7 +43,7 @@ #endif // Yep, this is C alright ;) -char **dir_list_new(const char *dir, const char *ext) +char **dir_list_new(const char *dir, const char *ext, bool include_dirs) { size_t cur_ptr = 0; size_t cur_size = 32; @@ -94,13 +94,29 @@ char **dir_list_new(const char *dir, const char *ext) { // Not a perfect search of course, but hopefully good enough in practice. #ifdef _WIN32 - if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - continue; - if (ext && !strstr(ffd.cFileName, ext)) - continue; + if (include_dirs) + { + if (ext && !strstr(ffd.cFileName, ext) && !path_is_directory(ffd.cFileName)) + continue; + } + else + { + if (ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; + if (ext && !strstr(ffd.cFileName, ext)) + continue; + } #else - if (ext && !strstr(entry->d_name, ext)) - continue; + if (include_dirs) + { + if (ext && !strstr(entry->d_name, ext) && !path_is_directory(entry->d_name)) + continue; + } + else + { + if (ext && !strstr(entry->d_name, ext)) + continue; + } #endif dir_list[cur_ptr] = (char*)malloc(PATH_MAX); @@ -175,10 +191,6 @@ bool path_is_directory(const char *path) return false; return buf.st_mode & CELL_FS_S_IFDIR; -#elif defined(XENON) - // Dummy - (void)path; - return false; #else struct stat buf; if (stat(path, &buf) < 0) diff --git a/retroarch.c b/retroarch.c index 964c566a52..d4b683a5e5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1535,7 +1535,7 @@ static void set_savestate_auto_index(void) unsigned max_index = 0; - char **dir_list = dir_list_new(dir, NULL); + char **dir_list = dir_list_new(dir, NULL, false); if (!dir_list) return;