Code de-duplication

This commit is contained in:
twinaphex 2015-09-04 22:48:20 +02:00
parent 5f91c3ade6
commit c0feef5b2f

View File

@ -559,7 +559,8 @@ enum
ACTION_OK_LOAD_CHEAT_FILE, ACTION_OK_LOAD_CHEAT_FILE,
ACTION_OK_APPEND_DISK_IMAGE, ACTION_OK_APPEND_DISK_IMAGE,
ACTION_OK_LOAD_CONFIG_FILE, ACTION_OK_LOAD_CONFIG_FILE,
ACTION_OK_LOAD_CORE ACTION_OK_LOAD_CORE,
ACTION_OK_LOAD_WALLPAPER
}; };
@ -589,6 +590,17 @@ static int generic_action_ok(const char *path,
switch (id) switch (id)
{ {
case ACTION_OK_LOAD_WALLPAPER:
flush_char = NULL;
flush_type = 49;
if (path_file_exists(action_path))
{
strlcpy(settings->menu.wallpaper, action_path, sizeof(settings->menu.wallpaper));
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, action_path, "cb_menu_wallpaper", 0, 1,
true);
}
break;
case ACTION_OK_LOAD_CORE: case ACTION_OK_LOAD_CORE:
flush_char = NULL; flush_char = NULL;
flush_type = MENU_SETTINGS; flush_type = MENU_SETTINGS;
@ -608,59 +620,59 @@ static int generic_action_ok(const char *path,
#elif defined(RARCH_CONSOLE) #elif defined(RARCH_CONSOLE)
/* Core selection on non-console just updates directory listing. /* Core selection on non-console just updates directory listing.
* Will take effect on new content load. */ * Will take effect on new content load. */
ret = -1; ret = -1;
event_command(EVENT_CMD_RESTART_RETROARCH); event_command(EVENT_CMD_RESTART_RETROARCH);
#endif #endif
break; break;
case ACTION_OK_LOAD_CONFIG_FILE: case ACTION_OK_LOAD_CONFIG_FILE:
disp->msg_force = true; disp->msg_force = true;
if (rarch_replace_config(action_path)) if (rarch_replace_config(action_path))
{ {
menu_navigation_clear(nav, false); menu_navigation_clear(nav, false);
ret = -1; ret = -1;
} }
break; break;
#ifdef HAVE_SHADER_MANAGER #ifdef HAVE_SHADER_MANAGER
case ACTION_OK_LOAD_PRESET: case ACTION_OK_LOAD_PRESET:
menu_shader_manager_set_preset(menu->shader, menu_shader_manager_set_preset(menu->shader,
video_shader_parse_type(action_path, RARCH_SHADER_NONE), video_shader_parse_type(action_path, RARCH_SHADER_NONE),
action_path); action_path);
break; break;
#endif #endif
#ifdef HAVE_SHADER_MANAGER #ifdef HAVE_SHADER_MANAGER
case ACTION_OK_LOAD_SHADER_PASS: case ACTION_OK_LOAD_SHADER_PASS:
strlcpy( strlcpy(
menu->shader->pass[hack_shader_pass].source.path, menu->shader->pass[hack_shader_pass].source.path,
action_path, action_path,
sizeof(menu->shader->pass[hack_shader_pass].source.path)); sizeof(menu->shader->pass[hack_shader_pass].source.path));
video_shader_resolve_parameters(NULL, menu->shader); video_shader_resolve_parameters(NULL, menu->shader);
break; break;
#endif #endif
case ACTION_OK_LOAD_RECORD_CONFIGFILE: case ACTION_OK_LOAD_RECORD_CONFIGFILE:
strlcpy(global->record.config, action_path, strlcpy(global->record.config, action_path,
sizeof(global->record.config)); sizeof(global->record.config));
break; break;
case ACTION_OK_LOAD_REMAPPING_FILE: case ACTION_OK_LOAD_REMAPPING_FILE:
input_remapping_load_file(action_path); input_remapping_load_file(action_path);
break; break;
case ACTION_OK_LOAD_CHEAT_FILE: case ACTION_OK_LOAD_CHEAT_FILE:
if (global->cheat) if (global->cheat)
cheat_manager_free(global->cheat); cheat_manager_free(global->cheat);
global->cheat = cheat_manager_load(action_path); global->cheat = cheat_manager_load(action_path);
if (!global->cheat) if (!global->cheat)
goto error; goto error;
break; break;
case ACTION_OK_APPEND_DISK_IMAGE: case ACTION_OK_APPEND_DISK_IMAGE:
event_disk_control_append_image(action_path); event_disk_control_append_image(action_path);
event_command(EVENT_CMD_RESUME); event_command(EVENT_CMD_RESUME);
break; break;
default: default:
break; break;
} }
menu_list_flush_stack(menu_list, flush_char, flush_type); menu_list_flush_stack(menu_list, flush_char, flush_type);
@ -671,6 +683,14 @@ error:
return -1; return -1;
} }
static int action_ok_menu_wallpaper_load(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
return generic_action_ok(path, label, type, idx, entry_idx,
ACTION_OK_LOAD_WALLPAPER, MENU_SETTINGS);
}
static int action_ok_core_load(const char *path, static int action_ok_core_load(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
@ -728,44 +748,6 @@ static int action_ok_shader_pass_load(const char *path,
} }
static int action_ok_menu_wallpaper_load(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx)
{
char wallpaper_path[PATH_MAX_LENGTH];
const char *menu_label = NULL;
const char *menu_path = NULL;
menu_file_list_cbs_t *cbs = NULL;
menu_list_t *menu_list = menu_list_get_ptr();
settings_t *settings = config_get_ptr();
if (!menu_list)
return -1;
menu_list_get_last_stack(menu_list, &menu_path, &menu_label,
NULL, NULL);
cbs = menu_list_get_last_stack_actiondata(menu_list);
if (!cbs)
return -1;
fill_pathname_join(wallpaper_path, menu_path, path, sizeof(wallpaper_path));
if (path_file_exists(wallpaper_path))
{
strlcpy(settings->menu.wallpaper, wallpaper_path, sizeof(settings->menu.wallpaper));
rarch_main_data_msg_queue_push(DATA_TYPE_IMAGE, wallpaper_path, "cb_menu_wallpaper", 0, 1,
true);
}
menu_list_pop_stack_by_needle(menu_list, cbs->setting->name);
return 0;
}
static int action_ok_cheat(const char *path, static int action_ok_cheat(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
@ -876,7 +858,7 @@ static int action_ok_path_scan_directory(const char *path,
static int action_ok_core_deferred_set(const char *path, static int action_ok_core_deferred_set(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
char core_display_name[PATH_MAX_LENGTH] = {0}; char core_display_name[PATH_MAX_LENGTH];
menu_handle_t *menu = menu_driver_get_ptr(); menu_handle_t *menu = menu_driver_get_ptr();
menu_list_t *menu_list = menu_list_get_ptr(); menu_list_t *menu_list = menu_list_get_ptr();
if (!menu || !menu_list) if (!menu || !menu_list)
@ -925,9 +907,6 @@ static int action_ok_deferred_list_stub(const char *path,
return 0; return 0;
} }
enum enum
{ {
ACTION_OK_FFMPEG = 0, ACTION_OK_FFMPEG = 0,
@ -1035,10 +1014,10 @@ static int action_ok_file_load(const char *path,
static int action_ok_set_path(const char *path, static int action_ok_set_path(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
const char *menu_path = NULL; const char *menu_path = NULL;
const char *menu_label = NULL; const char *menu_label = NULL;
menu_file_list_cbs_t *cbs = NULL; menu_file_list_cbs_t *cbs = NULL;
menu_list_t *menu_list = menu_list_get_ptr(); menu_list_t *menu_list = menu_list_get_ptr();
if (!menu_list) if (!menu_list)
return -1; return -1;
@ -1056,8 +1035,6 @@ static int action_ok_set_path(const char *path,
return 0; return 0;
} }
static int generic_action_ok_command(enum event_command cmd) static int generic_action_ok_command(enum event_command cmd)
{ {
if (!event_command(cmd)) if (!event_command(cmd))
@ -1656,7 +1633,8 @@ static int action_ok_load_archive_detect_core(const char *path,
{ {
case -1: case -1:
event_command(EVENT_CMD_LOAD_CORE); event_command(EVENT_CMD_LOAD_CORE);
return menu_common_load_content(false, CORE_TYPE_PLAIN); ret = menu_common_load_content(false, CORE_TYPE_PLAIN);
break;
case 0: case 0:
ret = generic_action_ok_displaylist_push(path, label, type, ret = generic_action_ok_displaylist_push(path, label, type,
selected, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST); selected, entry_idx, ACTION_OK_DL_DEFERRED_CORE_LIST);