mirror of
https://github.com/libretro/RetroArch
synced 2025-02-04 21:40:02 +00:00
(GX) filter filebrowser by file extension
This commit is contained in:
parent
c26413dd9a
commit
2554ec311d
@ -148,6 +148,13 @@ static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char exts[256];
|
||||||
|
if (core_chooser)
|
||||||
|
strlcpy(exts, "dol|DOL", sizeof(exts));
|
||||||
|
else
|
||||||
|
strlcpy(exts, rarch_console_get_rom_ext(), sizeof(exts));
|
||||||
|
struct string_list *ext_list = string_split(exts, "|");
|
||||||
|
|
||||||
char _dir[PATH_MAX];
|
char _dir[PATH_MAX];
|
||||||
snprintf(_dir, sizeof(_dir), "%s/", directory);
|
snprintf(_dir, sizeof(_dir), "%s/", directory);
|
||||||
DIR *dir = opendir(_dir);
|
DIR *dir = opendir(_dir);
|
||||||
@ -158,35 +165,37 @@ static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
|
|||||||
while ((entry = readdir(dir)))
|
while ((entry = readdir(dir)))
|
||||||
{
|
{
|
||||||
char stat_path[PATH_MAX];
|
char stat_path[PATH_MAX];
|
||||||
|
const char *file_ext = path_get_extension(entry->d_name);
|
||||||
snprintf(stat_path, sizeof(stat_path), "%s/%s", directory, entry->d_name);
|
snprintf(stat_path, sizeof(stat_path), "%s/%s", directory, entry->d_name);
|
||||||
|
bool is_dir;
|
||||||
|
|
||||||
#ifdef _DIRENT_HAVE_D_TYPE
|
#ifdef _DIRENT_HAVE_D_TYPE
|
||||||
if (entry->d_type != DT_REG && entry->d_type != DT_DIR)
|
is_dir = (entry->d_type == DT_DIR);
|
||||||
|
if (entry->d_type != DT_REG && !is_dir)
|
||||||
continue;
|
continue;
|
||||||
#else
|
#else
|
||||||
struct stat st;
|
struct stat st;
|
||||||
if (stat(stat_path, &st) < 0)
|
if (stat(stat_path, &st) < 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!S_ISDIR(st.st_mode) && !S_ISREG(st.st_mode))
|
is_dir = S_ISDIR(st.st_mode);
|
||||||
|
if (!S_ISREG(st.st_mode) && !is_dir)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (core_chooser && (strstr(entry->d_name, default_paths.executable_extension) != entry->d_name + strlen(entry->d_name) - 4 ||
|
if (core_chooser && (is_dir || strcasecmp(entry->d_name, default_paths.salamander_file) == 0))
|
||||||
strcasecmp(entry->d_name, default_paths.salamander_file) == 0))
|
continue;
|
||||||
|
|
||||||
|
if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
file_cb(ctx,
|
file_cb(ctx,
|
||||||
entry->d_name,
|
entry->d_name,
|
||||||
#ifdef _DIRENT_HAVE_D_TYPE
|
is_dir ? RGUI_FILE_DIRECTORY : RGUI_FILE_PLAIN, 0);
|
||||||
(entry->d_type == DT_DIR)
|
|
||||||
#else
|
|
||||||
S_ISDIR(st.st_mode)
|
|
||||||
#endif
|
|
||||||
? RGUI_FILE_DIRECTORY : RGUI_FILE_PLAIN, 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
|
string_list_free(ext_list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user