From 2b727fa941bcbf0e58466d317b05f27ee398bcc2 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 18 Nov 2015 11:15:23 +0100 Subject: [PATCH] Add RARCH_MAIN_CTL_SET_LIBRETRO_PATH/RARCH_MAIN_CTL_SET_CONTENT_PATH --- configuration.c | 3 +-- dynamic.c | 9 +++------ gfx/common/win32_common.cpp | 8 +++----- menu/cbs/menu_cbs_ok.c | 5 ++--- menu/menu.c | 6 ++---- retroarch.c | 12 +++++------- runloop.c | 16 ++++++++++++++++ runloop.h | 2 ++ ui/drivers/ui_cocoa.m | 28 +++++++++++++--------------- 9 files changed, 47 insertions(+), 42 deletions(-) diff --git a/configuration.c b/configuration.c index cfba60a08d..0cfb275ccf 100644 --- a/configuration.c +++ b/configuration.c @@ -784,8 +784,7 @@ static void config_set_defaults(void) fill_pathname_expand_special(settings->libretro_directory, g_defaults.dir.core, sizeof(settings->libretro_directory)); if (*g_defaults.path.core) - strlcpy(settings->libretro, g_defaults.path.core, - sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, g_defaults.path.core); if (*g_defaults.dir.database) strlcpy(settings->content_database, g_defaults.dir.database, sizeof(settings->content_database)); diff --git a/dynamic.c b/dynamic.c index a40d53f88c..51e3d65dc4 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1284,11 +1284,9 @@ bool rarch_environment_cb(unsigned cmd, void *data) case RETRO_ENVIRONMENT_SET_LIBRETRO_PATH: RARCH_LOG("Environ (Private) SET_LIBRETRO_PATH.\n"); - if (path_file_exists((const char*)data)) - strlcpy(settings->libretro, (const char*)data, - sizeof(settings->libretro)); - else + if (!path_file_exists((const char*)data)) return false; + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, data); break; case RETRO_ENVIRONMENT_EXEC: @@ -1297,8 +1295,7 @@ bool rarch_environment_cb(unsigned cmd, void *data) { *global->path.fullpath = '\0'; if (data) - strlcpy(global->path.fullpath, (const char*)data, - sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, data); } #if defined(RARCH_CONSOLE) diff --git a/gfx/common/win32_common.cpp b/gfx/common/win32_common.cpp index 01fde13a69..2903e087ad 100644 --- a/gfx/common/win32_common.cpp +++ b/gfx/common/win32_common.cpp @@ -320,9 +320,6 @@ LRESULT win32_menu_loop(HWND owner, WPARAM wparam) enum event_command cmd = EVENT_CMD_NONE; bool do_wm_close = false; settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); - - (void)global; switch (mode) { @@ -352,11 +349,11 @@ LRESULT win32_menu_loop(HWND owner, WPARAM wparam) switch (mode) { case ID_M_LOAD_CORE: - strlcpy(settings->libretro, win32_file, sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, win32_file); cmd = EVENT_CMD_LOAD_CORE; break; case ID_M_LOAD_CONTENT: - strlcpy(global->path.fullpath, win32_file, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, win32_file); cmd = EVENT_CMD_LOAD_CONTENT; do_wm_close = true; break; @@ -411,6 +408,7 @@ LRESULT win32_menu_loop(HWND owner, WPARAM wparam) default: if (mode >= ID_M_WINDOW_SCALE_1X && mode <= ID_M_WINDOW_SCALE_10X) { + global_t *global = global_get_ptr(); unsigned idx = (mode - (ID_M_WINDOW_SCALE_1X-1)); global->pending.windowed_scale = idx; cmd = EVENT_CMD_RESIZE_WINDOWED_SCALE; diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 2722202931..0b37509d54 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -636,7 +636,7 @@ static int generic_action_ok(const char *path, case ACTION_OK_LOAD_CORE: flush_char = NULL; flush_type = MENU_SETTINGS; - strlcpy(settings->libretro, action_path, sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, action_path); event_command(EVENT_CMD_LOAD_CORE); #if defined(HAVE_DYNAMIC) @@ -1346,8 +1346,7 @@ static int action_ok_file_load_or_resume(const char *path, if (!strcmp(menu->deferred_path, global->path.fullpath)) return generic_action_ok_command(EVENT_CMD_RESUME); - strlcpy(global->path.fullpath, - menu->deferred_path, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, menu->deferred_path); event_command(EVENT_CMD_LOAD_CORE); rarch_ctl(RARCH_ACTION_STATE_LOAD_CONTENT, NULL); diff --git a/menu/menu.c b/menu/menu.c index d3ee6a5da1..55f5cc295e 100644 --- a/menu/menu.c +++ b/menu/menu.c @@ -127,18 +127,16 @@ int menu_common_load_content( const char *core_path, const char *fullpath, bool persist, enum rarch_core_type type) { - settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); enum event_command cmd = EVENT_CMD_NONE; if (core_path) { - strlcpy(settings->libretro, core_path, sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, (void*)core_path); event_command(EVENT_CMD_LOAD_CORE); } if (fullpath) - strlcpy(global->path.fullpath, fullpath, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, (void*)fullpath); switch (type) { diff --git a/retroarch.c b/retroarch.c index 7b399fd636..69db9c8dc5 100644 --- a/retroarch.c +++ b/retroarch.c @@ -246,7 +246,7 @@ static void set_basename(const char *path) char *dst = NULL; global_t *global = global_get_ptr(); - strlcpy(global->path.fullpath, path, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, (void*)path); strlcpy(global->name.base, path, sizeof(global->name.base)); #ifdef HAVE_COMPRESSION @@ -725,8 +725,7 @@ static void parse_input(int argc, char *argv[]) } else { - strlcpy(settings->libretro, optarg, - sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, optarg); global->has_set.libretro = true; } break; @@ -1545,7 +1544,7 @@ void rarch_playlist_load_content(void *data, unsigned idx) free(path_check); } - strlcpy(settings->libretro, core_path, sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, (void*)core_path); #ifdef HAVE_MENU if (menu) @@ -1622,10 +1621,9 @@ int rarch_defer_core(core_info_list_t *core_info, const char *dir, if (supported != 1) return 0; - strlcpy(global->path.fullpath, s, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, s); if (path_file_exists(new_core_path)) - strlcpy(settings->libretro, new_core_path, - sizeof(settings->libretro)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, new_core_path); return -1; } diff --git a/runloop.c b/runloop.c index 0f912f92d6..bdb7424ab6 100644 --- a/runloop.c +++ b/runloop.c @@ -317,6 +317,22 @@ bool rarch_main_ctl(enum rarch_main_ctl_state state, void *data) switch (state) { + case RARCH_MAIN_CTL_SET_LIBRETRO_PATH: + { + const char *fullpath = (const char*)data; + if (!fullpath) + return false; + strlcpy(settings->libretro, fullpath, sizeof(settings->libretro)); + } + break; + case RARCH_MAIN_CTL_SET_CONTENT_PATH: + { + const char *fullpath = (const char*)data; + if (!fullpath) + return false; + strlcpy(global->path.fullpath, fullpath, sizeof(global->path.fullpath)); + } + break; case RARCH_MAIN_CTL_CHECK_STATE: { event_cmd_state_t *cmd = (event_cmd_state_t*)data; diff --git a/runloop.h b/runloop.h index 893641c6eb..33d5139f63 100644 --- a/runloop.h +++ b/runloop.h @@ -38,6 +38,8 @@ enum rarch_main_ctl_state { RARCH_MAIN_CTL_IS_IDLE = 0, RARCH_MAIN_CTL_SET_IDLE, + RARCH_MAIN_CTL_SET_CONTENT_PATH, + RARCH_MAIN_CTL_SET_LIBRETRO_PATH, RARCH_MAIN_CTL_IS_SLOWMOTION, RARCH_MAIN_CTL_SET_SLOWMOTION, RARCH_MAIN_CTL_IS_PAUSED, diff --git a/ui/drivers/ui_cocoa.m b/ui/drivers/ui_cocoa.m index 8cefbf9662..8eb9d00e18 100644 --- a/ui/drivers/ui_cocoa.m +++ b/ui/drivers/ui_cocoa.m @@ -276,8 +276,7 @@ extern void action_ok_push_quick_menu(void); NSString *__core = [filenames objectAtIndex:0]; const char *core_name = global ? global->menu.info.library_name : NULL; - if (global) - strlcpy(global->path.fullpath, __core.UTF8String, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, __core.UTF8String); if (core_name) ui_companion_event_command(EVENT_CMD_LOAD_CONTENT); @@ -308,17 +307,17 @@ extern void action_ok_push_quick_menu(void); if (__core) { - strlcpy(settings->libretro, __core.UTF8String, sizeof(settings->libretro)); - ui_companion_event_command(EVENT_CMD_LOAD_CORE); - - if (menu->load_no_content && settings->core.set_supports_no_game_enable) - { - int ret = 0; - *global->path.fullpath = '\0'; - ret = menu_common_load_content(NULL, NULL, false, CORE_TYPE_PLAIN); - if (ret == -1) - action_ok_push_quick_menu(); - } + rarch_main_ctl(RARCH_MAIN_CTL_SET_LIBRETRO_PATH, __core.UTF8String); + ui_companion_event_command(EVENT_CMD_LOAD_CORE); + + if (menu->load_no_content && settings->core.set_supports_no_game_enable) + { + int ret = 0; + *global->path.fullpath = '\0'; + ret = menu_common_load_content(NULL, NULL, false, CORE_TYPE_PLAIN); + if (ret == -1) + action_ok_push_quick_menu(); + } } } }]; @@ -343,8 +342,7 @@ extern void action_ok_push_quick_menu(void); NSString *__core = url.path; const char *core_name = global ? global->menu.info.library_name : NULL; - if (global) - strlcpy(global->path.fullpath, __core.UTF8String, sizeof(global->path.fullpath)); + rarch_main_ctl(RARCH_MAIN_CTL_SET_CONTENT_PATH, __core.UTF8String); if (core_name) ui_companion_event_command(EVENT_CMD_LOAD_CONTENT);