diff --git a/content.c b/content.c index c3574ddcf4..5e9c52c1b8 100644 --- a/content.c +++ b/content.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "msg_hash.h" #include "content.h" @@ -45,6 +46,8 @@ #include "movie.h" #include "patch.h" #include "system.h" +#include "retroarch.h" +#include "command_event.h" #include "libretro_version_1.h" #include "verbosity.h" @@ -52,6 +55,8 @@ #include "cheevos.h" #endif +#define MAX_ARGS 32 + struct sram_block { unsigned type; @@ -59,6 +64,204 @@ struct sram_block size_t size; }; +static void check_defaults_dir_create_dir(const char *path) +{ + if (path_is_directory(path)) + return; + path_mkdir(path); +} + +static void check_defaults_dirs(void) +{ + if (*g_defaults.dir.core_assets) + check_defaults_dir_create_dir(g_defaults.dir.core_assets); + if (*g_defaults.dir.remap) + check_defaults_dir_create_dir(g_defaults.dir.remap); + if (*g_defaults.dir.screenshot) + check_defaults_dir_create_dir(g_defaults.dir.screenshot); + if (*g_defaults.dir.core) + check_defaults_dir_create_dir(g_defaults.dir.core); + if (*g_defaults.dir.autoconfig) + check_defaults_dir_create_dir(g_defaults.dir.autoconfig); + if (*g_defaults.dir.audio_filter) + check_defaults_dir_create_dir(g_defaults.dir.audio_filter); + if (*g_defaults.dir.video_filter) + check_defaults_dir_create_dir(g_defaults.dir.video_filter); + if (*g_defaults.dir.assets) + check_defaults_dir_create_dir(g_defaults.dir.assets); + if (*g_defaults.dir.playlist) + check_defaults_dir_create_dir(g_defaults.dir.playlist); + if (*g_defaults.dir.core) + check_defaults_dir_create_dir(g_defaults.dir.core); + if (*g_defaults.dir.core_info) + check_defaults_dir_create_dir(g_defaults.dir.core_info); + if (*g_defaults.dir.overlay) + check_defaults_dir_create_dir(g_defaults.dir.overlay); + if (*g_defaults.dir.port) + check_defaults_dir_create_dir(g_defaults.dir.port); + if (*g_defaults.dir.shader) + check_defaults_dir_create_dir(g_defaults.dir.shader); + if (*g_defaults.dir.savestate) + check_defaults_dir_create_dir(g_defaults.dir.savestate); + if (*g_defaults.dir.sram) + check_defaults_dir_create_dir(g_defaults.dir.sram); + if (*g_defaults.dir.system) + check_defaults_dir_create_dir(g_defaults.dir.system); + if (*g_defaults.dir.resampler) + check_defaults_dir_create_dir(g_defaults.dir.resampler); + if (*g_defaults.dir.menu_config) + check_defaults_dir_create_dir(g_defaults.dir.menu_config); + if (*g_defaults.dir.content_history) + check_defaults_dir_create_dir(g_defaults.dir.content_history); + if (*g_defaults.dir.cache) + check_defaults_dir_create_dir(g_defaults.dir.cache); + if (*g_defaults.dir.database) + check_defaults_dir_create_dir(g_defaults.dir.database); + if (*g_defaults.dir.cursor) + check_defaults_dir_create_dir(g_defaults.dir.cursor); + if (*g_defaults.dir.cheats) + check_defaults_dir_create_dir(g_defaults.dir.cheats); +} + +/** + * rarch_main_init_wrap: + * @args : Input arguments. + * @argc : Count of arguments. + * @argv : Arguments. + * + * Generates an @argc and @argv pair based on @args + * of type rarch_main_wrap. + **/ +static void rarch_main_init_wrap( + const struct rarch_main_wrap *args, + int *argc, char **argv) +{ +#ifdef HAVE_FILE_LOGGER + int i; +#endif + + *argc = 0; + argv[(*argc)++] = strdup("retroarch"); + + if (!args->no_content) + { + if (args->content_path) + { + RARCH_LOG("Using content: %s.\n", args->content_path); + argv[(*argc)++] = strdup(args->content_path); + } +#ifdef HAVE_MENU + else + { + RARCH_LOG("No content, starting dummy core.\n"); + argv[(*argc)++] = strdup("--menu"); + } +#endif + } + + if (args->sram_path) + { + argv[(*argc)++] = strdup("-s"); + argv[(*argc)++] = strdup(args->sram_path); + } + + if (args->state_path) + { + argv[(*argc)++] = strdup("-S"); + argv[(*argc)++] = strdup(args->state_path); + } + + if (args->config_path) + { + argv[(*argc)++] = strdup("-c"); + argv[(*argc)++] = strdup(args->config_path); + } + +#ifdef HAVE_DYNAMIC + if (args->libretro_path) + { + argv[(*argc)++] = strdup("-L"); + argv[(*argc)++] = strdup(args->libretro_path); + } +#endif + + if (args->verbose) + argv[(*argc)++] = strdup("-v"); + +#ifdef HAVE_FILE_LOGGER + for (i = 0; i < *argc; i++) + RARCH_LOG("arg #%d: %s\n", i, argv[i]); +#endif +} + +/** + * content_load: + * @argc : Argument count. + * @argv : Argument variable list. + * @args : Arguments passed from callee. + * @environ_get : Function passed for environment_get function. + * + * Loads content file and starts up RetroArch. + * If no content file can be loaded, will start up RetroArch + * as-is. + * + * Returns: false (0) if rarch_main_init failed, otherwise true (1). + **/ +bool content_load(int argc, char **argv, void *args, + environment_get_t environ_get) +{ + unsigned i; + bool retval = true; + int rarch_argc = 0; + char *rarch_argv[MAX_ARGS] = {NULL}; + char *argv_copy [MAX_ARGS] = {NULL}; + char **rarch_argv_ptr = (char**)argv; + int *rarch_argc_ptr = (int*)&argc; + struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*) + calloc(1, sizeof(*wrap_args)); + + if (!wrap_args) + return false; + + (void)rarch_argc_ptr; + (void)rarch_argv_ptr; + + retro_assert(wrap_args); + + if (environ_get) + environ_get(rarch_argc_ptr, rarch_argv_ptr, args, wrap_args); + + if (wrap_args->touched) + { + rarch_main_init_wrap(wrap_args, &rarch_argc, rarch_argv); + memcpy(argv_copy, rarch_argv, sizeof(rarch_argv)); + rarch_argv_ptr = (char**)rarch_argv; + rarch_argc_ptr = (int*)&rarch_argc; + } + + rarch_ctl(RARCH_CTL_MAIN_DEINIT, NULL); + + wrap_args->argc = *rarch_argc_ptr; + wrap_args->argv = rarch_argv_ptr; + + if (!rarch_ctl(RARCH_CTL_MAIN_INIT, wrap_args)) + { + retval = false; + goto error; + } + + event_cmd_ctl(EVENT_CMD_RESUME, NULL); + + check_defaults_dirs(); + + frontend_driver_process_args(rarch_argc_ptr, rarch_argv_ptr); + +error: + for (i = 0; i < ARRAY_SIZE(argv_copy); i++) + free(argv_copy[i]); + free(wrap_args); + return retval; +} /** * read_content_file: diff --git a/content.h b/content.h index 9d35f82aba..ffc355078c 100644 --- a/content.h +++ b/content.h @@ -24,6 +24,8 @@ #include +#include "frontend/frontend_driver.h" + #ifdef __cplusplus extern "C" { #endif @@ -68,6 +70,22 @@ typedef struct ram_type int type; } ram_type_t; +/** + * main_load_content: + * @argc : Argument count. + * @argv : Argument variable list. + * @args : Arguments passed from callee. + * @environ_get : Function passed for environment_get function. + * + * Loads content file and starts up RetroArch. + * If no content file can be loaded, will start up RetroArch + * as-is. + * + * Returns: false (0) if rarch_main_init failed, otherwise true (1). + **/ +bool content_load(int argc, char **argv, + void *args, environment_get_t environ_get); + bool content_ctl(enum content_ctl_state state, void *data); #ifdef __cplusplus diff --git a/frontend/frontend.c b/frontend/frontend.c index 7955861cda..a8e3718037 100644 --- a/frontend/frontend.c +++ b/frontend/frontend.c @@ -16,7 +16,6 @@ */ #include -#include #include #ifdef HAVE_THREADS @@ -39,8 +38,6 @@ #include "../menu/menu_driver.h" #endif -#define MAX_ARGS 32 - #ifdef HAVE_THREADS static async_job_t *async_jobs; @@ -91,65 +88,6 @@ void main_exit(void *args) frontend_driver_free(); } -static void check_defaults_dir_create_dir(const char *path) -{ - if (path_is_directory(path)) - return; - path_mkdir(path); -} - -static void check_defaults_dirs(void) -{ - if (*g_defaults.dir.core_assets) - check_defaults_dir_create_dir(g_defaults.dir.core_assets); - if (*g_defaults.dir.remap) - check_defaults_dir_create_dir(g_defaults.dir.remap); - if (*g_defaults.dir.screenshot) - check_defaults_dir_create_dir(g_defaults.dir.screenshot); - if (*g_defaults.dir.core) - check_defaults_dir_create_dir(g_defaults.dir.core); - if (*g_defaults.dir.autoconfig) - check_defaults_dir_create_dir(g_defaults.dir.autoconfig); - if (*g_defaults.dir.audio_filter) - check_defaults_dir_create_dir(g_defaults.dir.audio_filter); - if (*g_defaults.dir.video_filter) - check_defaults_dir_create_dir(g_defaults.dir.video_filter); - if (*g_defaults.dir.assets) - check_defaults_dir_create_dir(g_defaults.dir.assets); - if (*g_defaults.dir.playlist) - check_defaults_dir_create_dir(g_defaults.dir.playlist); - if (*g_defaults.dir.core) - check_defaults_dir_create_dir(g_defaults.dir.core); - if (*g_defaults.dir.core_info) - check_defaults_dir_create_dir(g_defaults.dir.core_info); - if (*g_defaults.dir.overlay) - check_defaults_dir_create_dir(g_defaults.dir.overlay); - if (*g_defaults.dir.port) - check_defaults_dir_create_dir(g_defaults.dir.port); - if (*g_defaults.dir.shader) - check_defaults_dir_create_dir(g_defaults.dir.shader); - if (*g_defaults.dir.savestate) - check_defaults_dir_create_dir(g_defaults.dir.savestate); - if (*g_defaults.dir.sram) - check_defaults_dir_create_dir(g_defaults.dir.sram); - if (*g_defaults.dir.system) - check_defaults_dir_create_dir(g_defaults.dir.system); - if (*g_defaults.dir.resampler) - check_defaults_dir_create_dir(g_defaults.dir.resampler); - if (*g_defaults.dir.menu_config) - check_defaults_dir_create_dir(g_defaults.dir.menu_config); - if (*g_defaults.dir.content_history) - check_defaults_dir_create_dir(g_defaults.dir.content_history); - if (*g_defaults.dir.cache) - check_defaults_dir_create_dir(g_defaults.dir.cache); - if (*g_defaults.dir.database) - check_defaults_dir_create_dir(g_defaults.dir.database); - if (*g_defaults.dir.cursor) - check_defaults_dir_create_dir(g_defaults.dir.cursor); - if (*g_defaults.dir.cheats) - check_defaults_dir_create_dir(g_defaults.dir.cheats); -} - static void history_playlist_push(content_playlist_t *playlist, const char *path, const char *core_path, struct retro_system_info *info) @@ -180,146 +118,6 @@ static void history_playlist_push(content_playlist_t *playlist, NULL); } -/** - * rarch_main_init_wrap: - * @args : Input arguments. - * @argc : Count of arguments. - * @argv : Arguments. - * - * Generates an @argc and @argv pair based on @args - * of type rarch_main_wrap. - **/ -static void rarch_main_init_wrap( - const struct rarch_main_wrap *args, - int *argc, char **argv) -{ -#ifdef HAVE_FILE_LOGGER - int i; -#endif - - *argc = 0; - argv[(*argc)++] = strdup("retroarch"); - - if (!args->no_content) - { - if (args->content_path) - { - RARCH_LOG("Using content: %s.\n", args->content_path); - argv[(*argc)++] = strdup(args->content_path); - } -#ifdef HAVE_MENU - else - { - RARCH_LOG("No content, starting dummy core.\n"); - argv[(*argc)++] = strdup("--menu"); - } -#endif - } - - if (args->sram_path) - { - argv[(*argc)++] = strdup("-s"); - argv[(*argc)++] = strdup(args->sram_path); - } - - if (args->state_path) - { - argv[(*argc)++] = strdup("-S"); - argv[(*argc)++] = strdup(args->state_path); - } - - if (args->config_path) - { - argv[(*argc)++] = strdup("-c"); - argv[(*argc)++] = strdup(args->config_path); - } - -#ifdef HAVE_DYNAMIC - if (args->libretro_path) - { - argv[(*argc)++] = strdup("-L"); - argv[(*argc)++] = strdup(args->libretro_path); - } -#endif - - if (args->verbose) - argv[(*argc)++] = strdup("-v"); - -#ifdef HAVE_FILE_LOGGER - for (i = 0; i < *argc; i++) - RARCH_LOG("arg #%d: %s\n", i, argv[i]); -#endif -} - -/** - * main_load_content: - * @argc : Argument count. - * @argv : Argument variable list. - * @args : Arguments passed from callee. - * @environ_get : Function passed for environment_get function. - * - * Loads content file and starts up RetroArch. - * If no content file can be loaded, will start up RetroArch - * as-is. - * - * Returns: false (0) if rarch_main_init failed, otherwise true (1). - **/ -bool main_load_content(int argc, char **argv, void *args, - environment_get_t environ_get) -{ - unsigned i; - bool retval = true; - int rarch_argc = 0; - char *rarch_argv[MAX_ARGS] = {NULL}; - char *argv_copy [MAX_ARGS] = {NULL}; - char **rarch_argv_ptr = (char**)argv; - int *rarch_argc_ptr = (int*)&argc; - struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*) - calloc(1, sizeof(*wrap_args)); - - if (!wrap_args) - return false; - - (void)rarch_argc_ptr; - (void)rarch_argv_ptr; - - retro_assert(wrap_args); - - if (environ_get) - environ_get(rarch_argc_ptr, rarch_argv_ptr, args, wrap_args); - - if (wrap_args->touched) - { - rarch_main_init_wrap(wrap_args, &rarch_argc, rarch_argv); - memcpy(argv_copy, rarch_argv, sizeof(rarch_argv)); - rarch_argv_ptr = (char**)rarch_argv; - rarch_argc_ptr = (int*)&rarch_argc; - } - - rarch_ctl(RARCH_CTL_MAIN_DEINIT, NULL); - - wrap_args->argc = *rarch_argc_ptr; - wrap_args->argv = rarch_argv_ptr; - - if (!rarch_ctl(RARCH_CTL_MAIN_INIT, wrap_args)) - { - retval = false; - goto error; - } - - event_cmd_ctl(EVENT_CMD_RESUME, NULL); - - check_defaults_dirs(); - - frontend_driver_process_args(rarch_argc_ptr, rarch_argv_ptr); - -error: - for (i = 0; i < ARRAY_SIZE(argv_copy); i++) - free(argv_copy[i]); - free(wrap_args); - return retval; -} - /** * main_entry: * @@ -348,7 +146,7 @@ int rarch_main(int argc, char *argv[], void *data) if (frontend_driver_is_inited()) { - ret = main_load_content(argc, argv, args, + ret = content_load(argc, argv, args, frontend_driver_environment_get_ptr()); if (!ret) diff --git a/frontend/frontend.h b/frontend/frontend.h index 14f5315a8c..f1ca65c4fb 100644 --- a/frontend/frontend.h +++ b/frontend/frontend.h @@ -50,22 +50,6 @@ void main_exit(void *args); **/ int rarch_main(int argc, char *argv[], void *data); -/** - * main_load_content: - * @argc : Argument count. - * @argv : Argument variable list. - * @args : Arguments passed from callee. - * @environ_get : Function passed for environment_get function. - * - * Loads content file and starts up RetroArch. - * If no content file can be loaded, will start up RetroArch - * as-is. - * - * Returns: false (0) if rarch_main_init failed, otherwise true (1). - **/ -bool main_load_content(int argc, char **argv, - void *args, environment_get_t environ_get); - #ifdef __cplusplus } #endif diff --git a/menu/menu_content.c b/menu/menu_content.c index 93bca52247..216d95e94c 100644 --- a/menu/menu_content.c +++ b/menu/menu_content.c @@ -25,6 +25,7 @@ #include "menu_shader.h" #include "../core_info.h" +#include "../content.h" #include "../configuration.h" #include "../dynamic.h" #include "../defaults.h" @@ -123,7 +124,7 @@ static bool menu_content_load(void) if (*fullpath) fill_pathname_base(name, fullpath, sizeof(name)); - if (!(main_load_content(0, NULL, NULL, menu_content_environment_get))) + if (!(content_load(0, NULL, NULL, menu_content_environment_get))) { snprintf(msg, sizeof(msg), "Failed to load %s.\n", name); runloop_msg_queue_push(msg, 1, 90, false);