mirror of
https://github.com/libretro/RetroArch
synced 2024-12-27 15:29:23 +00:00
Allow dir_list_new to compare against dotted exts as well.
This commit is contained in:
parent
5a07d757e9
commit
07560e25b4
1
file.h
1
file.h
@ -61,6 +61,7 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_
|
||||
void dir_list_sort(struct string_list *list, bool dir_first);
|
||||
void dir_list_free(struct string_list *list);
|
||||
bool string_list_find_elem(const struct string_list *list, const char *elem);
|
||||
bool string_list_find_elem_prefix(const struct string_list *list, const char *prefix, const char *elem);
|
||||
struct string_list *string_split(const char *str, const char *delim);
|
||||
|
||||
bool path_is_directory(const char *path);
|
||||
|
22
file_path.c
22
file_path.c
@ -152,6 +152,24 @@ bool string_list_find_elem(const struct string_list *list, const char *elem)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool string_list_find_elem_prefix(const struct string_list *list, const char *prefix, const char *elem)
|
||||
{
|
||||
if (!list)
|
||||
return false;
|
||||
|
||||
char prefixed[PATH_MAX];
|
||||
snprintf(prefixed, sizeof(prefixed), "%s%s", prefix, elem);
|
||||
|
||||
for (size_t i = 0; i < list->size; i++)
|
||||
{
|
||||
if (strcmp(list->elems[i].data, elem) == 0 ||
|
||||
strcmp(list->elems[i].data, prefixed) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const char *path_get_extension(const char *path)
|
||||
{
|
||||
const char *ext = strrchr(path, '.');
|
||||
@ -222,7 +240,7 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_
|
||||
if (!include_dirs && is_dir)
|
||||
continue;
|
||||
|
||||
if (!is_dir && ext_list && !string_list_find_elem(ext_list, file_ext))
|
||||
if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext))
|
||||
continue;
|
||||
|
||||
char file_path[PATH_MAX];
|
||||
@ -279,7 +297,7 @@ struct string_list *dir_list_new(const char *dir, const char *ext, bool include_
|
||||
if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
|
||||
continue;
|
||||
|
||||
if (!is_dir && ext_list && !string_list_find_elem(ext_list, file_ext))
|
||||
if (!is_dir && ext_list && !string_list_find_elem_prefix(ext_list, ".", file_ext))
|
||||
continue;
|
||||
|
||||
char file_path[PATH_MAX];
|
||||
|
Loading…
Reference in New Issue
Block a user