From 23c8150b6ef5f36ef79e964a01344086554e14b7 Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Wed, 23 Mar 2016 00:29:52 +0100 Subject: [PATCH 1/2] Reintroduce new parse_input scheme. This reverts commit 2323cef8d16bff7b1ad09a036da7bd6f58848226. --- retroarch.c | 54 ++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/retroarch.c b/retroarch.c index 75f4ea08af..874f00a972 100644 --- a/retroarch.c +++ b/retroarch.c @@ -609,6 +609,7 @@ static void parse_input(int argc, char *argv[]) const char *optstring = NULL; global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); + bool explicit_menu = false; const struct option opts[] = { #ifdef HAVE_DYNAMIC @@ -658,7 +659,29 @@ static void parse_input(int argc, char *argv[]) { NULL, 0, NULL, 0 } }; - current_core_type = CORE_TYPE_PLAIN; + /* Handling the core type is finicky. Based on the arguments we pass in, + * we handle it differently. + * Some current cases which track desired behavior and how it is supposed to work: + * + * Dynamically linked RA: + * ./retroarch -> CORE_TYPE_DUMMY + * ./retroarch -v -> CORE_TYPE_DUMMY + verbose + * ./retroarch --menu -> CORE_TYPE_DUMMY + * ./retroarch --menu -v -> CORE_TYPE_DUMMY + verbose + * ./retroarch -L contentless-core -> CORE_TYPE_PLAIN + * ./retroarch -L content-core -> CORE_TYPE_PLAIN + FAIL (This currently crashes) + * ./retroarch [-L content-core] ROM -> CORE_TYPE_PLAIN + * ./retroarch <-L or ROM> --menu -> FAIL + * + * The heuristic here seems to be that if we use the -L CLI option or + * optind < argc at the end we should set CORE_TYPE_PLAIN. + * To handle --menu, we should ensure that CORE_TYPE_DUMMY is still set + * otherwise, fail early, since the CLI options are non-sensical. + * We could also simply ignore --menu in this case to be more friendly with + * bogus arguments. + */ + + current_core_type = CORE_TYPE_DUMMY; *global->subsystem = '\0'; global->has_set.save_path = false; global->has_set.state_path = false; @@ -684,12 +707,6 @@ static void parse_input(int argc, char *argv[]) runloop_ctl(RUNLOOP_CTL_UNSET_OVERRIDES_ACTIVE, NULL); - if (argc < 2) - { - current_core_type = CORE_TYPE_DUMMY; - return; - } - /* Make sure we can call parse_input several times ... */ optind = 0; optstring = "hs:fvS:A:c:U:DN:d:" @@ -817,6 +834,9 @@ static void parse_input(int argc, char *argv[]) runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, optarg); global->has_set.libretro = true; } + + /* We requested explicit core, so use PLAIN core type. */ + current_core_type = CORE_TYPE_PLAIN; break; #endif case 'P': @@ -904,7 +924,7 @@ static void parse_input(int argc, char *argv[]) break; case RA_OPT_MENU: - current_core_type = CORE_TYPE_DUMMY; + explicit_menu = true; break; #ifdef HAVE_NETPLAY @@ -995,20 +1015,24 @@ static void parse_input(int argc, char *argv[]) } } - if (rarch_ctl(RARCH_CTL_IS_DUMMY_CORE, NULL)) + if (explicit_menu && current_core_type != CORE_TYPE_DUMMY) { - if (optind < argc) - { - RARCH_ERR("--menu was used, but content file was passed as well.\n"); - retro_fail(1, "parse_input()"); - } + RARCH_ERR("--menu was used, but content file or libretro core was passed as well.\n"); + retro_fail(1, "parse_input()"); } - else if (!*global->subsystem && optind < argc) + + if (!*global->subsystem && optind < argc) { + /* We requested explicit ROM, so use PLAIN core type. */ + current_core_type = CORE_TYPE_PLAIN; rarch_ctl(RARCH_CTL_SET_PATHS, (void*)argv[optind]); } else if (*global->subsystem && optind < argc) + { + /* We requested explicit ROM, so use PLAIN core type. */ + current_core_type = CORE_TYPE_PLAIN; set_special_paths(argv + optind, argc - optind); + } else content_ctl(CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT, NULL); From b96d365968ad7f5d11c24f2df2bd2ea99f7cca9d Mon Sep 17 00:00:00 2001 From: Hans-Kristian Arntzen Date: Wed, 23 Mar 2016 00:46:15 +0100 Subject: [PATCH 2/2] Only set CORE_TYPE_PLAIN for non-directory -L. Fixes crash on Android startup which uses -L CLI argument. -L can also set core directory, even though it's not supposed to be used anymore. Also, on Android, the cores directory might not be populated, so ignore arguments which are not valid. --- retroarch.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/retroarch.c b/retroarch.c index 874f00a972..6053de552c 100644 --- a/retroarch.c +++ b/retroarch.c @@ -829,14 +829,20 @@ static void parse_input(int argc, char *argv[]) "Setting libretro_directory to \"%s\" instead.\n", optarg); } - else + else if (path_file_exists(optarg)) { runloop_ctl(RUNLOOP_CTL_SET_LIBRETRO_PATH, optarg); global->has_set.libretro = true; + + /* We requested explicit core, so use PLAIN core type. */ + current_core_type = CORE_TYPE_PLAIN; + } + else + { + RARCH_WARN("--libretro argument \"%s\" is neither a file nor directory. Ignoring.\n", + optarg); } - /* We requested explicit core, so use PLAIN core type. */ - current_core_type = CORE_TYPE_PLAIN; break; #endif case 'P':