mirror of
https://github.com/CTCaer/RetroArch.git
synced 2025-02-21 20:22:43 +00:00
Add sorting and size query to dir_list_new.
This commit is contained in:
parent
e455e52e06
commit
a1f5715431
14
driver.c
14
driver.c
@ -481,17 +481,13 @@ static void init_shader_dir(void)
|
||||
return;
|
||||
|
||||
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.size = dir_list_size(g_extern.shader_dir.elems);
|
||||
g_extern.shader_dir.ptr = 0;
|
||||
|
||||
if (g_extern.shader_dir.elems)
|
||||
{
|
||||
while (g_extern.shader_dir.elems[g_extern.shader_dir.size])
|
||||
{
|
||||
RARCH_LOG("Found shader \"%s\"\n", g_extern.shader_dir.elems[g_extern.shader_dir.size]);
|
||||
g_extern.shader_dir.size++;
|
||||
}
|
||||
}
|
||||
dir_list_sort(g_extern.shader_dir.elems);
|
||||
|
||||
for (unsigned i = 0; i < g_extern.shader_dir.size; i++)
|
||||
RARCH_LOG("Found shader \"%s\"\n", g_extern.shader_dir.elems[i]);
|
||||
}
|
||||
|
||||
static void deinit_shader_dir(void)
|
||||
|
2
file.h
2
file.h
@ -44,6 +44,8 @@ bool init_rom_file(enum rarch_game_type type);
|
||||
// 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, bool include_dirs);
|
||||
size_t dir_list_size(char * const *dir_list);
|
||||
void dir_list_sort(char **dir_list);
|
||||
void dir_list_free(char **dir_list);
|
||||
|
||||
bool path_is_directory(const char *path);
|
||||
|
34
file_path.c
34
file_path.c
@ -110,7 +110,8 @@ static void string_list_free(char **list)
|
||||
|
||||
static char **string_split(const char *str, const char *delim)
|
||||
{
|
||||
char *copy = NULL;
|
||||
char *copy = NULL;
|
||||
const char *tmp = NULL;
|
||||
struct string_list list;
|
||||
|
||||
if (!string_list_init(&list))
|
||||
@ -120,7 +121,7 @@ static char **string_split(const char *str, const char *delim)
|
||||
if (!copy)
|
||||
return NULL;
|
||||
|
||||
const char *tmp = strtok(copy, delim);
|
||||
tmp = strtok(copy, delim);
|
||||
while (tmp)
|
||||
{
|
||||
if (!string_list_append(&list, tmp))
|
||||
@ -159,6 +160,31 @@ static const char *path_get_extension(const char *path)
|
||||
return "";
|
||||
}
|
||||
|
||||
size_t dir_list_size(char * const *dir_list)
|
||||
{
|
||||
if (!dir_list)
|
||||
return 0;
|
||||
|
||||
size_t size = 0;
|
||||
while (*dir_list++)
|
||||
size++;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
static int qstrcmp(const void *a, const void *b)
|
||||
{
|
||||
return strcmp(*(char * const*)a, *(char * const*)b);
|
||||
}
|
||||
|
||||
void dir_list_sort(char **dir_list)
|
||||
{
|
||||
if (!dir_list)
|
||||
return;
|
||||
|
||||
qsort(dir_list, dir_list_size(dir_list), sizeof(char*), qstrcmp);
|
||||
}
|
||||
|
||||
#ifdef _WIN32 // Because the API is just fucked up ...
|
||||
char **dir_list_new(const char *dir, const char *ext, bool include_dirs)
|
||||
{
|
||||
@ -188,7 +214,7 @@ char **dir_list_new(const char *dir, const char *ext, bool include_dirs)
|
||||
if (!include_dirs && path_is_directory(name))
|
||||
continue;
|
||||
|
||||
if (!string_list_find_elem(ext_list, file_ext))
|
||||
if (!path_is_directory(name) && !string_list_find_elem(ext_list, file_ext))
|
||||
continue;
|
||||
|
||||
char file_path[PATH_MAX];
|
||||
@ -238,7 +264,7 @@ char **dir_list_new(const char *dir, const char *ext, bool include_dirs)
|
||||
if (!include_dirs && path_is_directory(name))
|
||||
continue;
|
||||
|
||||
if (!string_list_find_elem(ext_list, file_ext))
|
||||
if (!path_is_directory(name) && !string_list_find_elem(ext_list, file_ext))
|
||||
continue;
|
||||
|
||||
char file_path[PATH_MAX];
|
||||
|
Loading…
x
Reference in New Issue
Block a user