Create dir_list_initialize/dir_list_deinitialize

This commit is contained in:
twinaphex 2020-08-24 18:56:25 +02:00
parent cde5d37eb2
commit 8a479e6006
3 changed files with 35 additions and 8 deletions

View File

@ -911,26 +911,26 @@ void core_info_get_name(const char *path, char *s, size_t len,
bool get_display_name)
{
size_t i;
struct string_list contents;
const char *path_basedir = !string_is_empty(path_info) ?
path_info : dir_cores;
struct string_list *contents = dir_list_new(
dir_cores, exts, false, dir_show_hidden_files, false, false);
const char *core_path_basename = path_basename(path);
if (!contents)
if (!dir_list_initialize(&contents,
dir_cores, exts, false, dir_show_hidden_files, false, false))
return;
for (i = 0; i < contents->size; i++)
for (i = 0; i < contents.size; i++)
{
struct config_entry_list
*entry = NULL;
config_file_t *conf = NULL;
const char *current_path = contents->elems[i].data;
const char *current_path = contents.elems[i].data;
if (!string_is_equal(path_basename(current_path), core_path_basename))
continue;
conf = core_info_list_iterate(contents->elems[i].data,
conf = core_info_list_iterate(contents.elems[i].data,
path_basedir);
if (!conf)
@ -948,8 +948,7 @@ void core_info_get_name(const char *path, char *s, size_t len,
break;
}
dir_list_free(contents);
contents = NULL;
dir_list_deinitialize(&contents);
}
size_t core_info_list_num_info_files(core_info_list_t *core_info_list)

View File

@ -24,6 +24,7 @@
#define __LIBRETRO_SDK_DIR_LIST_H
#include <retro_common_api.h>
#include <boolean.h>
#include <lists/string_list.h>
@ -63,6 +64,12 @@ bool dir_list_append(struct string_list *list, const char *dir, const char *ext,
struct string_list *dir_list_new(const char *dir, const char *ext,
bool include_dirs, bool include_hidden, bool include_compressed, bool recursive);
bool dir_list_initialize(struct string_list *list,
const char *dir,
const char *ext, bool include_dirs,
bool include_hidden, bool include_compressed,
bool recursive);
/**
* dir_list_sort:
* @list : pointer to the directory listing.
@ -82,6 +89,8 @@ void dir_list_sort(struct string_list *list, bool dir_first);
**/
void dir_list_free(struct string_list *list);
bool dir_list_deinitialize(struct string_list *list);
RETRO_END_DECLS
#endif

View File

@ -86,6 +86,13 @@ void dir_list_free(struct string_list *list)
string_list_free(list);
}
bool dir_list_deinitialize(struct string_list *list)
{
if (!list)
return false;
return string_list_deinitialize(list);
}
/**
* dir_list_read:
* @dir : directory path.
@ -249,3 +256,15 @@ struct string_list *dir_list_new(const char *dir,
return list;
}
bool dir_list_initialize(struct string_list *list,
const char *dir,
const char *ext, bool include_dirs,
bool include_hidden, bool include_compressed,
bool recursive)
{
if (!list)
return NULL;
return dir_list_append(list, dir, ext, include_dirs,
include_hidden, include_compressed, recursive);
}