menu_displaylist_info - rewrite path

This commit is contained in:
twinaphex 2017-09-28 03:06:54 +02:00
parent 08ecfc74ec
commit 8b5f8d8c64
8 changed files with 88 additions and 54 deletions

View File

@ -446,7 +446,8 @@ static int deferred_push_cursor_manager_list_deferred(
char *query = NULL;
char *rdb = NULL;
settings_t *settings = config_get_ptr();
config_file_t *conf = config_file_new(info->path);
const char *path = info->path;
config_file_t *conf = path ? config_file_new(path) : NULL;
if (!conf || !settings)
goto end;
@ -467,13 +468,14 @@ static int deferred_push_cursor_manager_list_deferred(
free(info->path_b);
if (info->path_c && !string_is_empty(info->path_c))
free(info->path_c);
if (info->path && !string_is_empty(info->path))
free(info->path);
info->path_b = strdup(info->path);
info->path_c = strdup(query);
info->path = strdup(rdb_path);
strlcpy(info->path, rdb_path, sizeof(info->path));
ret = deferred_push_dlist(info, DISPLAYLIST_DATABASE_QUERY);
ret = deferred_push_dlist(info, DISPLAYLIST_DATABASE_QUERY);
end:
if (conf)
@ -488,9 +490,13 @@ end:
static int deferred_push_cursor_manager_list_generic(
menu_displaylist_info_t *info, enum database_query_type type)
{
int ret = -1;
char query[PATH_MAX_LENGTH];
struct string_list *str_list = string_split(info->path, "|");
int ret = -1;
const char *path = info->path;
struct string_list *str_list = path ? string_split(path, "|") : NULL;
if (!str_list)
goto end;
query[0] = '\0';
@ -503,9 +509,10 @@ static int deferred_push_cursor_manager_list_generic(
free(info->path_b);
if (info->path_c && !string_is_empty(info->path_c))
free(info->path_c);
if (info->path && !string_is_empty(info->path))
free(info->path);
strlcpy(info->path, str_list->elems[1].data, sizeof(info->path));
info->path = strdup(str_list->elems[1].data);
info->path_b = strdup(str_list->elems[0].data);
info->path_c = strdup(query);
@ -630,14 +637,14 @@ static int deferred_push_cursor_manager_list_deferred_query_subsearch(
if (string_is_empty(query))
goto end;
strlcpy(info->path, str_list->elems[1].data, sizeof(info->path));
if (info->path && !string_is_empty(info->path))
free(info->path);
if (info->path_b && !string_is_empty(info->path_b))
free(info->path_b);
info->path_b = strdup(str_list->elems[0].data);
if (info->path_c && !string_is_empty(info->path_c))
free(info->path_c);
info->path = strdup(str_list->elems[1].data);
info->path_b = strdup(str_list->elems[0].data);
info->path_c = strdup(query);
ret = deferred_push_dlist(info, DISPLAYLIST_DATABASE_QUERY);
@ -670,10 +677,26 @@ static int general_push(menu_displaylist_info_t *info,
case PUSH_DETECT_CORE_LIST:
break;
default:
fill_pathname_join(info->path, menu->scratch2_buf,
menu->scratch_buf, sizeof(info->path));
fill_pathname_join(info->label, menu->scratch2_buf,
menu->scratch_buf, sizeof(info->label));
{
char tmp_str[PATH_MAX_LENGTH];
char tmp_str2[PATH_MAX_LENGTH];
tmp_str[0] = '\0';
tmp_str2[0] = '\0';
fill_pathname_join(tmp_str, menu->scratch2_buf,
menu->scratch_buf, sizeof(tmp_str));
fill_pathname_join(tmp_str2, menu->scratch2_buf,
menu->scratch_buf, sizeof(tmp_str2));
if (info->path && !string_is_empty(info->path))
free(info->path);
if (info->label && !string_is_empty(info->label))
free(info->label);
info->path = strdup(tmp_str);
info->label = strdup(tmp_str2);
}
break;
}

View File

@ -877,7 +877,7 @@ int generic_action_ok_displaylist_push(const char *path,
if (info_label)
info.label = strdup(info_label);
if (info_path)
strlcpy(info.path, info_path, sizeof(info.path));
info.path = strdup(info_path);
if (menu_displaylist_ctl(dl_type, &info))
{

View File

@ -270,7 +270,8 @@ bool generic_menu_init_list(void *data)
msg_hash_to_str(MENU_ENUM_LABEL_MAIN_MENU));
info.enum_idx = MENU_ENUM_LABEL_MAIN_MENU;
menu_entries_append_enum(menu_stack, info.path,
menu_entries_append_enum(menu_stack,
info.path,
info.label,
MENU_ENUM_LABEL_MAIN_MENU,
info.type, info.flags, 0);

View File

@ -1860,8 +1860,8 @@ static void xmb_init_horizontal_list(xmb_handle_t *xmb)
menu_displaylist_info_init(&info);
info.list = xmb->horizontal_list;
strlcpy(info.path, settings->paths.directory_playlist, sizeof(info.path));
info.path = strdup(
settings->paths.directory_playlist);
info.label = strdup(
msg_hash_to_str(MENU_ENUM_LABEL_CONTENT_COLLECTION_LIST));
info.exts = strdup(

View File

@ -1573,9 +1573,10 @@ static int menu_displaylist_parse_playlist(menu_displaylist_info_t *info,
fill_buf[0] = path_copy[0] = '\0';
strlcpy(path_copy, info->path, path_size);
if (info->path && !string_is_empty(info->path))
strlcpy(path_copy, info->path, path_size);
path = path_copy;
path = path_copy;
playlist_get_index(playlist, i,
&path, &label, NULL, &core_name, NULL, NULL);
@ -3558,8 +3559,9 @@ static int menu_displaylist_parse_playlists(
struct string_list *str_list = NULL;
unsigned items_found = 0;
settings_t *settings = config_get_ptr();
const char *path = info->path;
if (string_is_empty(info->path))
if (string_is_empty(path))
{
if (frontend_driver_parse_drive_list(info->list, true) != 0)
menu_entries_append_enum(info->list, "/", "",
@ -3567,7 +3569,7 @@ static int menu_displaylist_parse_playlists(
return 0;
}
str_list = dir_list_new(info->path, NULL, true, settings->bools.show_hidden_files, true, false);
str_list = dir_list_new(path, NULL, true, settings->bools.show_hidden_files, true, false);
if (!str_list)
{
@ -3662,7 +3664,7 @@ static int menu_displaylist_parse_playlists(
file_type = FILE_TYPE_PLAYLIST_COLLECTION;
if (!string_is_empty(info->path))
if (!string_is_empty(path))
path = path_basename(path);
items_found++;
@ -3695,8 +3697,9 @@ static int menu_displaylist_parse_cores(
struct string_list *str_list = NULL;
unsigned items_found = 0;
settings_t *settings = config_get_ptr();
const char *path = info->path;
if (string_is_empty(info->path))
if (string_is_empty(path))
{
if (frontend_driver_parse_drive_list(info->list, true) != 0)
menu_entries_append_enum(info->list, "/", "",
@ -3704,7 +3707,7 @@ static int menu_displaylist_parse_cores(
return 0;
}
str_list = dir_list_new(info->path, info->exts,
str_list = dir_list_new(path, info->exts,
true, settings->bools.show_hidden_files, true, false);
{
@ -3712,14 +3715,14 @@ static int menu_displaylist_parse_cores(
out_dir[0] = '\0';
fill_pathname_parent_dir(out_dir, info->path,
fill_pathname_parent_dir(out_dir, path,
PATH_MAX_LENGTH * sizeof(char));
if (string_is_empty(out_dir))
{
menu_entries_prepend(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PARENT_DIRECTORY),
info->path,
path,
MENU_ENUM_LABEL_PARENT_DIRECTORY,
FILE_TYPE_PARENT_DIRECTORY, 0, 0);
}
@ -3787,7 +3790,7 @@ static int menu_displaylist_parse_cores(
/* Need to preserve slash first time. */
path = str_list->elems[i].data;
if (!string_is_empty(info->path))
if (!string_is_empty(path))
path = path_basename(path);
#ifndef HAVE_DYNAMIC
@ -4094,10 +4097,10 @@ static bool menu_displaylist_push_internal(
}
else
{
strlcpy(
info->path,
settings->paths.directory_playlist,
sizeof(info->path));
if (info->path && !string_is_empty(info->path))
free(info->path);
info->path = strdup(settings->paths.directory_playlist);
if (menu_displaylist_ctl(
DISPLAYLIST_DATABASE_PLAYLISTS, info))
@ -4145,7 +4148,7 @@ bool menu_displaylist_push(menu_displaylist_ctx_entry_t *entry)
info.enum_idx = enum_idx;
if (!string_is_empty(path))
strlcpy(info.path, path, sizeof(info.path));
info.path = strdup(path);
if (!string_is_empty(label))
info.label = strdup(label);
@ -4167,6 +4170,8 @@ bool menu_displaylist_push(menu_displaylist_ctx_entry_t *entry)
return true;
error:
if (info.path)
free(info.path);
if (info.label)
free(info.label);
return false;
@ -4331,15 +4336,13 @@ void menu_displaylist_info_free(menu_displaylist_info_t *info)
free(info->path_c);
if (info->label)
free(info->label);
if (info->path)
free(info->path);
info->exts = NULL;
info->path_b = NULL;
info->path_c = NULL;
info->label = NULL;
#if 0
if (info->path)
free(info->path);
info->path = NULL;
#endif
}
void menu_displaylist_info_init(menu_displaylist_info_t *info)
@ -4356,13 +4359,13 @@ void menu_displaylist_info_init(menu_displaylist_info_t *info)
info->push_builtin_cores = false;
info->download_core = false;
info->need_navigation_clear = false;
info->path[0] = '\0';
info->type = 0;
info->type_default = 0;
info->flags = 0;
info->label_hash = 0;
info->directory_ptr = 0;
info->label = NULL;
info->path = NULL;
info->path_b = NULL;
info->path_c = NULL;
info->exts = NULL;
@ -4449,13 +4452,13 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
if (!str_list)
return false;
strlcpy(info->path_b,
str_list->elems[1].data, sizeof(info->path_b));
if (info->path_b && !string_is_empty(info->path_b))
free(info->path_b);
if (info->label && !string_is_empty(info->label))
free(info->label);
info->label = strdup(str_list->elems[0].data);
info->path_b = strdup(str_list->elems[1].data);
info->label = strdup(str_list->elems[0].data);
string_list_free(str_list);
}
@ -4477,7 +4480,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
#else
ret = 0;
#endif
strlcpy(info->path, info->path_b, sizeof(info->path));
if (info->path && !string_is_empty(info->path))
free(info->path);
info->path = strdup(info->path_b);
info->need_sort = true;
info->need_refresh = true;
@ -6658,7 +6663,9 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
info->enum_idx = MENU_ENUM_LABEL_CONTENT_COLLECTION_LIST;
load_content = false;
use_filebrowser = true;
strlcpy(info->path, settings->paths.path_content_database, sizeof(info->path));
if (info->path)
free(info->path);
info->path = strdup(settings->paths.path_content_database);
break;
case DISPLAYLIST_DATABASE_CURSORS:
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);
@ -6668,8 +6675,10 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, void *data)
use_filebrowser = true;
if (info->exts && !string_is_empty(info->exts))
free(info->exts);
if (info->path)
free(info->path);
info->exts = strdup("dbc");
strlcpy(info->path, settings->paths.directory_cursor, sizeof(info->path));
info->path = strdup(settings->paths.directory_cursor);
break;
case DISPLAYLIST_CONFIG_FILES:
menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list);

View File

@ -184,7 +184,7 @@ typedef struct menu_displaylist_info
/* does the navigation index need to be cleared to 0 (first entry) ? */
bool need_navigation_clear;
char path[PATH_MAX_LENGTH];
char *path;
char *path_b;
char *path_c;
char *exts;

View File

@ -769,7 +769,7 @@ int menu_action_handle_setting(rarch_setting_t *setting,
menu_displaylist_info_init(&info);
strlcpy(info.path, setting->default_value.string, sizeof(info.path));
info.path = strdup(setting->default_value.string);
info.label = strdup(name);
info.type = type;
info.directory_ptr = selection;

View File

@ -63,7 +63,8 @@ void filebrowser_parse(void *data, unsigned type_data)
menu_displaylist_info_t *info = (menu_displaylist_info_t*)data;
enum menu_displaylist_ctl_state type = (enum menu_displaylist_ctl_state)
type_data;
bool path_is_compressed = path_is_compressed_file(info->path);
const char *path = info->path;
bool path_is_compressed = path ? path_is_compressed_file(path) : false;
bool filter_ext =
settings->bools.menu_navigation_browser_filter_supported_extensions_enable;
@ -73,9 +74,9 @@ void filebrowser_parse(void *data, unsigned type_data)
filter_ext = false;
if (path_is_compressed)
str_list = file_archive_get_file_list(info->path, info->exts);
str_list = file_archive_get_file_list(path, info->exts);
else
str_list = dir_list_new(info->path,
str_list = dir_list_new(path,
filter_ext ? info->exts : NULL,
true, settings->bools.show_hidden_files, true, false);
@ -171,7 +172,7 @@ void filebrowser_parse(void *data, unsigned type_data)
/* Need to preserve slash first time. */
if (!string_is_empty(info->path) && !path_is_compressed)
if (!string_is_empty(path) && !path_is_compressed)
path = path_basename(path);
if (filebrowser_types == FILEBROWSER_SELECT_COLLECTION)
@ -266,7 +267,7 @@ void filebrowser_parse(void *data, unsigned type_data)
end:
menu_entries_prepend(info->list,
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PARENT_DIRECTORY),
info->path,
path,
MENU_ENUM_LABEL_PARENT_DIRECTORY,
FILE_TYPE_PARENT_DIRECTORY, 0, 0);
}