diff --git a/libretro-common/lists/dir_list.c b/libretro-common/lists/dir_list.c index e8415fcf07..417b0faa30 100644 --- a/libretro-common/lists/dir_list.c +++ b/libretro-common/lists/dir_list.c @@ -86,73 +86,6 @@ void dir_list_free(struct string_list *list) string_list_free(list); } -/** - * parse_dir_entry: - * @name : name of the directory listing entry. - * @file_path : file path of the directory listing entry. - * @is_dir : is the directory listing a directory? - * @include_dirs : include directories as part of the finished directory listing? - * @include_compressed : Include compressed files, even if not part of ext_list. - * @list : pointer to directory listing. - * @ext_list : pointer to allowed file extensions listing. - * @file_ext : file extension of the directory listing entry. - * - * Parses a directory listing. - * - * Returns: zero on success, -1 on error, 1 if we should - * continue to the next entry in the directory listing. - **/ -static int parse_dir_entry(const char *name, char *file_path, - bool is_dir, bool include_dirs, bool include_compressed, - struct string_list *list, struct string_list *ext_list, - const char *file_ext) -{ - union string_list_elem_attr attr; - - attr.i = RARCH_FILETYPE_UNSET; - - if (string_is_equal(name, ".") || string_is_equal(name, "..")) - return 1; - - if (is_dir) - { - if (!include_dirs) - return 1; - attr.i = RARCH_DIRECTORY; - } - else - { - bool is_compressed_file; - bool supported_by_core = false; - if ((is_compressed_file = path_is_compressed_file(file_path))) - attr.i = RARCH_COMPRESSED_ARCHIVE; - - /* - * If the file format is explicitly supported by the libretro-core, we - * need to immediately load it and not designate it as a compressed file. - * - * Example: .zip could be supported as a image by the core and as a - * compressed_file. In that case, we have to interpret it as a image. - * - * */ - if (string_list_find_elem_prefix(ext_list, ".", file_ext)) - { - attr.i = RARCH_PLAIN_FILE; - supported_by_core = true; - } - - if (ext_list && - ((!is_compressed_file && !supported_by_core) || - (!supported_by_core && !include_compressed))) - return 1; - } - - if (!string_list_append(list, file_path, attr)) - return -1; - - return 0; -} - /** * dir_list_read: * @dir : directory path. @@ -179,39 +112,57 @@ static int dir_list_read(const char *dir, while (retro_readdir(entry)) { + union string_list_elem_attr attr; char file_path[PATH_MAX_LENGTH]; - bool is_dir = false; - int ret = 0; const char *name = retro_dirent_get_name(entry); - const char *file_ext = ""; + + if (!include_hidden && *name == '.') + continue; + if (!strcmp(name, ".") || !strcmp(name, "..")) + continue; file_path[0] = '\0'; - fill_pathname_join(file_path, dir, name, sizeof(file_path)); - is_dir = retro_dirent_is_dir(entry, NULL); - if(!is_dir) - file_ext = path_get_extension(name); - - if (!include_hidden) + if (retro_dirent_is_dir(entry, NULL)) { - if (*name == '.') + if (recursive) + dir_list_read(file_path, list, ext_list, include_dirs, + include_hidden, include_compressed, recursive); + + if (!include_dirs) continue; + attr.i = RARCH_DIRECTORY; + } + else + { + const char *file_ext = path_get_extension(name); + + attr.i = RARCH_FILETYPE_UNSET; + + /* + * If the file format is explicitly supported by the libretro-core, we + * need to immediately load it and not designate it as a compressed file. + * + * Example: .zip could be supported as a image by the core and as a + * compressed_file. In that case, we have to interpret it as a image. + * + * */ + if (string_list_find_elem_prefix(ext_list, ".", file_ext)) + attr.i = RARCH_PLAIN_FILE; + else + { + bool is_compressed_file; + if ((is_compressed_file = path_is_compressed_file(file_path))) + attr.i = RARCH_COMPRESSED_ARCHIVE; + + if (ext_list && + (!is_compressed_file || !include_compressed)) + continue; + } } - if(is_dir && recursive) - { - if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) - continue; - - dir_list_read(file_path, list, ext_list, include_dirs, - include_hidden, include_compressed, recursive); - } - - ret = parse_dir_entry(name, file_path, is_dir, - include_dirs, include_compressed, list, ext_list, file_ext); - - if (ret == -1) + if (!string_list_append(list, file_path, attr)) goto error; }