Set up dir_list_new so that we can use it for the 360/PS3 filebrowser

This commit is contained in:
Twinaphex 2012-06-10 03:50:06 +02:00
parent 3a01bad0ec
commit df6a9a0f85
6 changed files with 29 additions and 17 deletions

View File

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

View File

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

View File

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

2
file.h
View File

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

View File

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

View File

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