Simplify menu_content_find_first_core

This commit is contained in:
twinaphex 2016-06-15 18:52:27 +02:00
parent a8042bdc0c
commit df9f1585de
3 changed files with 19 additions and 21 deletions

View File

@ -461,6 +461,7 @@ static int file_load_with_detect_core_wrapper(size_t idx, size_t entry_idx,
{ {
menu_content_ctx_defer_info_t def_info; menu_content_ctx_defer_info_t def_info;
content_ctx_info_t content_info = {0}; content_ctx_info_t content_info = {0};
char new_core_path[PATH_MAX_LENGTH] = {0};
char menu_path_new[PATH_MAX_LENGTH] = {0}; char menu_path_new[PATH_MAX_LENGTH] = {0};
int ret = 0; int ret = 0;
const char *menu_path = NULL; const char *menu_path = NULL;
@ -494,7 +495,8 @@ static int file_load_with_detect_core_wrapper(size_t idx, size_t entry_idx,
def_info.s = menu->deferred_path; def_info.s = menu->deferred_path;
def_info.len = sizeof(menu->deferred_path); def_info.len = sizeof(menu->deferred_path);
if (menu_content_find_first_core(&def_info, false)) if (menu_content_find_first_core(&def_info, false, new_core_path,
sizeof(new_core_path)))
ret = -1; ret = -1;
if ( !is_carchive && !string_is_empty(path) if ( !is_carchive && !string_is_empty(path)
@ -509,9 +511,7 @@ static int file_load_with_detect_core_wrapper(size_t idx, size_t entry_idx,
switch (ret) switch (ret)
{ {
case -1: case -1:
command_event(CMD_EVENT_LOAD_CORE, NULL); task_push_content_load_default(new_core_path, NULL,
task_push_content_load_default(NULL, NULL,
&content_info, CORE_TYPE_PLAIN, &content_info, CORE_TYPE_PLAIN,
CONTENT_MODE_LOAD_CONTENT_WITH_NEW_CORE_FROM_MENU, CONTENT_MODE_LOAD_CONTENT_WITH_NEW_CORE_FROM_MENU,
NULL, NULL); NULL, NULL);
@ -2334,6 +2334,7 @@ static int action_ok_load_archive_detect_core(const char *path,
{ {
menu_content_ctx_defer_info_t def_info; menu_content_ctx_defer_info_t def_info;
content_ctx_info_t content_info = {0}; content_ctx_info_t content_info = {0};
char new_core_path[PATH_MAX_LENGTH] = {0};
int ret = 0; int ret = 0;
core_info_list_t *list = NULL; core_info_list_t *list = NULL;
menu_handle_t *menu = NULL; menu_handle_t *menu = NULL;
@ -2358,7 +2359,7 @@ static int action_ok_load_archive_detect_core(const char *path,
def_info.s = menu->deferred_path; def_info.s = menu->deferred_path;
def_info.len = sizeof(menu->deferred_path); def_info.len = sizeof(menu->deferred_path);
if (menu_content_find_first_core(&def_info, false)) if (menu_content_find_first_core(&def_info, false, new_core_path, sizeof(new_core_path)))
ret = -1; ret = -1;
fill_pathname_join(detect_content_path, menu_path, content_path, fill_pathname_join(detect_content_path, menu_path, content_path,
@ -2367,11 +2368,10 @@ static int action_ok_load_archive_detect_core(const char *path,
switch (ret) switch (ret)
{ {
case -1: case -1:
command_event(CMD_EVENT_LOAD_CORE, NULL); task_push_content_load_default(new_core_path, NULL,
task_push_content_load_default(NULL, NULL,
&content_info, &content_info,
CORE_TYPE_PLAIN, CORE_TYPE_PLAIN,
CONTENT_MODE_LOAD_CONTENT_WITH_CURRENT_CORE_FROM_MENU, CONTENT_MODE_LOAD_CONTENT_WITH_NEW_CORE_FROM_MENU,
NULL, NULL); NULL, NULL);
return 0; return 0;
case 0: case 0:

View File

@ -125,9 +125,9 @@ error:
* selection needs to be made from a list, otherwise * selection needs to be made from a list, otherwise
* returns true and fills in @s with path to core. * returns true and fills in @s with path to core.
**/ **/
bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info, bool load_content_with_current_core) bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info, bool load_content_with_current_core,
char *new_core_path, size_t len)
{ {
char new_core_path[PATH_MAX_LENGTH] = {0};
const core_info_t *info = NULL; const core_info_t *info = NULL;
core_info_list_t *core_info = NULL; core_info_list_t *core_info = NULL;
const char *default_info_dir = NULL; const char *default_info_dir = NULL;
@ -185,13 +185,10 @@ bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info, bool
return false; return false;
if (info) if (info)
strlcpy(new_core_path, info->path, sizeof(new_core_path)); strlcpy(new_core_path, info->path, len);
runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, def_info->s); runloop_ctl(RUNLOOP_CTL_SET_CONTENT_PATH, def_info->s);
if (path_file_exists(new_core_path))
runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, new_core_path);
return true; return true;
} }

View File

@ -60,7 +60,8 @@ typedef struct menu_content_ctx_defer_info
size_t len; size_t len;
} menu_content_ctx_defer_info_t; } menu_content_ctx_defer_info_t;
bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info, bool load_content_with_current_core); bool menu_content_find_first_core(menu_content_ctx_defer_info_t *def_info, bool load_content_with_current_core,
char *new_core_path, size_t len);
bool menu_content_ctl(enum menu_content_ctl_state state, void *data); bool menu_content_ctl(enum menu_content_ctl_state state, void *data);