mirror of
https://github.com/libretro/RetroArch
synced 2025-01-29 00:32:49 +00:00
(filebrowser_parse) Use non-heap allocated string_list functions
This commit is contained in:
parent
5ce53c3c01
commit
318ac1f667
@ -438,6 +438,33 @@ end:
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool file_archive_get_file_list_noalloc(struct string_list *list,
|
||||
const char *path,
|
||||
const char *valid_exts)
|
||||
{
|
||||
struct archive_extract_userdata userdata;
|
||||
|
||||
strlcpy(userdata.archive_path, path, sizeof(userdata.archive_path));
|
||||
userdata.current_file_path[0] = '\0';
|
||||
userdata.first_extracted_file_path = NULL;
|
||||
userdata.extraction_directory = NULL;
|
||||
userdata.archive_path_size = 0;
|
||||
userdata.ext = NULL;
|
||||
userdata.list = list;
|
||||
userdata.found_file = false;
|
||||
userdata.list_only = true;
|
||||
userdata.crc = 0;
|
||||
userdata.transfer = NULL;
|
||||
userdata.dec = NULL;
|
||||
|
||||
if (!userdata.list)
|
||||
return false;
|
||||
if (!file_archive_walk(path, valid_exts,
|
||||
file_archive_get_file_list_cb, &userdata))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* file_archive_get_file_list:
|
||||
* @path : filename path of archive
|
||||
@ -463,18 +490,14 @@ struct string_list *file_archive_get_file_list(const char *path,
|
||||
userdata.dec = NULL;
|
||||
|
||||
if (!userdata.list)
|
||||
goto error;
|
||||
|
||||
return NULL;
|
||||
if (!file_archive_walk(path, valid_exts,
|
||||
file_archive_get_file_list_cb, &userdata))
|
||||
goto error;
|
||||
|
||||
return userdata.list;
|
||||
|
||||
error:
|
||||
if (userdata.list)
|
||||
{
|
||||
string_list_free(userdata.list);
|
||||
return NULL;
|
||||
return NULL;
|
||||
}
|
||||
return userdata.list;
|
||||
}
|
||||
|
||||
bool file_archive_perform_mode(const char *path, const char *valid_exts,
|
||||
|
@ -164,6 +164,10 @@ bool file_archive_extract_file(char *archive_path, size_t archive_path_size,
|
||||
const char *valid_exts, const char *extraction_dir,
|
||||
char *out_path, size_t len);
|
||||
|
||||
bool file_archive_get_file_list_noalloc(struct string_list *list,
|
||||
const char *path,
|
||||
const char *valid_exts);
|
||||
|
||||
/**
|
||||
* file_archive_get_file_list:
|
||||
* @path : filename path of archive
|
||||
|
@ -169,7 +169,8 @@ static void filebrowser_parse(
|
||||
{
|
||||
size_t i, list_size;
|
||||
const struct retro_subsystem_info *subsystem;
|
||||
struct string_list *str_list = NULL;
|
||||
bool ret = false;
|
||||
struct string_list str_list = {0};
|
||||
unsigned items_found = 0;
|
||||
unsigned files_count = 0;
|
||||
unsigned dirs_count = 0;
|
||||
@ -180,6 +181,9 @@ static void filebrowser_parse(
|
||||
? path_is_compressed_file(path) : false;
|
||||
rarch_system_info_t *system = runloop_get_system_info();
|
||||
|
||||
if (!string_list_initialize(&str_list))
|
||||
return;
|
||||
|
||||
/* Core fully loaded, use the subsystem data */
|
||||
if (system->subsystem.data)
|
||||
subsystem = system->subsystem.data + content_get_subsystem();
|
||||
@ -187,6 +191,7 @@ static void filebrowser_parse(
|
||||
else
|
||||
subsystem = subsystem_data + content_get_subsystem();
|
||||
|
||||
|
||||
if (info)
|
||||
{
|
||||
if (info->type_default == FILE_TYPE_SHADER_PRESET ||
|
||||
@ -201,9 +206,11 @@ static void filebrowser_parse(
|
||||
if (info && path_is_compressed)
|
||||
{
|
||||
if (filebrowser_types != FILEBROWSER_SELECT_FILE_SUBSYSTEM)
|
||||
str_list = file_archive_get_file_list(path, info->exts);
|
||||
ret = file_archive_get_file_list_noalloc(&str_list,
|
||||
path, info->exts);
|
||||
else if (subsystem && subsystem_current_count > 0)
|
||||
str_list = file_archive_get_file_list(path,
|
||||
ret = file_archive_get_file_list_noalloc(&str_list,
|
||||
path,
|
||||
subsystem->roms[
|
||||
content_get_subsystem_rom_id()].valid_extensions);
|
||||
}
|
||||
@ -212,15 +219,16 @@ static void filebrowser_parse(
|
||||
if (filebrowser_types == FILEBROWSER_SELECT_FILE_SUBSYSTEM)
|
||||
{
|
||||
if (subsystem && subsystem_current_count > 0 && content_get_subsystem_rom_id() < subsystem->num_roms)
|
||||
str_list = dir_list_new(path,
|
||||
ret = dir_list_initialize(&str_list,
|
||||
path,
|
||||
(filter_ext && info) ? subsystem->roms[content_get_subsystem_rom_id()].valid_extensions : NULL,
|
||||
true, show_hidden_files, true, false);
|
||||
}
|
||||
else if (info && ((info->type_default == FILE_TYPE_MANUAL_SCAN_DAT) || (info->type_default == FILE_TYPE_SIDELOAD_CORE)))
|
||||
str_list = dir_list_new(path,
|
||||
ret = dir_list_initialize(&str_list, path,
|
||||
info->exts, true, show_hidden_files, false, false);
|
||||
else
|
||||
str_list = dir_list_new(path,
|
||||
ret = dir_list_initialize(&str_list, path,
|
||||
(filter_ext && info) ? info->exts : NULL,
|
||||
true, show_hidden_files, true, false);
|
||||
}
|
||||
@ -257,7 +265,7 @@ static void filebrowser_parse(
|
||||
break;
|
||||
}
|
||||
|
||||
if (!str_list)
|
||||
if (!ret)
|
||||
{
|
||||
const char *str = path_is_compressed
|
||||
? msg_hash_to_str(MENU_ENUM_LABEL_VALUE_UNABLE_TO_READ_COMPRESSED_FILE)
|
||||
@ -269,16 +277,11 @@ static void filebrowser_parse(
|
||||
goto end;
|
||||
}
|
||||
|
||||
dir_list_sort(str_list, true);
|
||||
dir_list_sort(&str_list, true);
|
||||
|
||||
list_size = str_list->size;
|
||||
list_size = str_list.size;
|
||||
|
||||
if (list_size == 0)
|
||||
{
|
||||
string_list_free(str_list);
|
||||
str_list = NULL;
|
||||
}
|
||||
else
|
||||
if (list_size > 0)
|
||||
{
|
||||
for (i = 0; i < list_size; i++)
|
||||
{
|
||||
@ -286,11 +289,11 @@ static void filebrowser_parse(
|
||||
bool is_dir = false;
|
||||
enum msg_hash_enums enum_idx = MSG_UNKNOWN;
|
||||
enum msg_file_type file_type = FILE_TYPE_NONE;
|
||||
const char *path = str_list->elems[i].data;
|
||||
const char *path = str_list.elems[i].data;
|
||||
|
||||
label[0] = '\0';
|
||||
|
||||
switch (str_list->elems[i].attr.i)
|
||||
switch (str_list.elems[i].attr.i)
|
||||
{
|
||||
case RARCH_DIRECTORY:
|
||||
file_type = FILE_TYPE_DIRECTORY;
|
||||
@ -416,8 +419,7 @@ static void filebrowser_parse(
|
||||
}
|
||||
}
|
||||
|
||||
if (str_list && str_list->size > 0)
|
||||
string_list_free(str_list);
|
||||
string_list_deinitialize(&str_list);
|
||||
|
||||
if (items_found == 0)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user