From aecbf71a9066370b35727f5b51fbf0e08a21d95f Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 15 Sep 2013 15:36:45 +0200 Subject: [PATCH] Begin adding config swapping support to RGUI. --- frontend/menu/menu_common.c | 102 ++++++++++++++++++++++++++---------- frontend/menu/menu_common.h | 4 ++ frontend/menu/rgui.c | 31 ++++++++++- 3 files changed, 107 insertions(+), 30 deletions(-) diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index 94d3c7a162..842ff11841 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -472,6 +472,47 @@ void load_menu_game_history(unsigned game_index) #endif } +static void menu_init_history(void) +{ + if (rgui->history) + { + rom_history_free(rgui->history); + rgui->history = NULL; + } + + if (*g_extern.config_path) + { + char history_path[PATH_MAX]; + if (*g_settings.game_history_path) + strlcpy(history_path, g_settings.game_history_path, sizeof(history_path)); + else + { + fill_pathname_resolve_relative(history_path, g_extern.config_path, + ".retroarch-game-history.txt", sizeof(history_path)); + } + + RARCH_LOG("[RGUI]: Opening history: %s.\n", history_path); + rgui->history = rom_history_init(history_path, g_settings.game_history_size); + } +} + +static void menu_update_libretro_info(void) +{ + *rgui->libretro_dir = '\0'; +#ifdef HAVE_DYNAMIC + libretro_free_system_info(&rgui->info); + if (path_is_directory(g_settings.libretro)) + strlcpy(rgui->libretro_dir, g_settings.libretro, sizeof(rgui->libretro_dir)); + else if (*g_settings.libretro) + { + fill_pathname_basedir(rgui->libretro_dir, g_settings.libretro, sizeof(rgui->libretro_dir)); + libretro_get_system_info(g_settings.libretro, &rgui->info, NULL); + } +#else + retro_get_system_info(&rgui->info); +#endif +} + bool load_menu_game(void) { if (g_extern.main_is_init) @@ -484,13 +525,15 @@ bool load_menu_game(void) args.sram_path = *g_extern.savefile_dir ? g_extern.savefile_dir : NULL; args.state_path = *g_extern.savestate_dir ? g_extern.savestate_dir : NULL; args.rom_path = *g_extern.fullpath ? g_extern.fullpath : NULL; - args.libretro_path = g_settings.libretro; + args.libretro_path = *g_settings.libretro ? g_settings.libretro : NULL; args.no_rom = rgui->load_no_rom; rgui->load_no_rom = false; if (rarch_main_init_wrap(&args) == 0) { RARCH_LOG("rarch_main_init_wrap() succeeded.\n"); + menu_update_libretro_info(); + menu_init_history(); return true; } else @@ -520,24 +563,16 @@ void menu_init(void) rgui->frame_buf_show = true; rgui->current_pad = 0; -#ifdef HAVE_DYNAMIC - if (path_is_directory(g_settings.libretro)) - strlcpy(rgui->libretro_dir, g_settings.libretro, sizeof(rgui->libretro_dir)); - else if (*g_settings.libretro) - { - fill_pathname_basedir(rgui->libretro_dir, g_settings.libretro, sizeof(rgui->libretro_dir)); - libretro_get_system_info(g_settings.libretro, &rgui->info, NULL); - } -#else - retro_get_system_info(&rgui->info); -#endif + menu_update_libretro_info(); + if (*g_extern.config_path) + fill_pathname_basedir(rgui->config_dir, g_extern.config_path, sizeof(rgui->config_dir)); #ifdef HAVE_FILEBROWSER if (!(strlen(g_settings.rgui_browser_directory) > 0)) strlcpy(g_settings.rgui_browser_directory, default_paths.filebrowser_startup_dir, sizeof(g_settings.rgui_browser_directory)); - rgui->browser = (filebrowser_t*)calloc(1, sizeof(*(rgui->browser))); + rgui->browser = (filebrowser_t*)calloc(1, sizeof(*(rgui->browser))); if (rgui->browser == NULL) { @@ -565,21 +600,7 @@ void menu_init(void) shader_manager_init(rgui); #endif - if (*g_extern.config_path) - { - char history_path[PATH_MAX]; - if (*g_settings.game_history_path) - strlcpy(history_path, g_settings.game_history_path, sizeof(history_path)); - else - { - fill_pathname_resolve_relative(history_path, g_extern.config_path, - ".retroarch-game-history.txt", sizeof(history_path)); - } - - RARCH_LOG("[RGUI]: Opening history: %s.\n", history_path); - rgui->history = rom_history_init(history_path, g_settings.game_history_size); - } - + menu_init_history(); rgui->last_time = rarch_get_time_usec(); } @@ -880,3 +901,28 @@ deinit: } #endif #endif + +// Quite intrusive and error prone. +// Likely to have lots of small bugs. +// Cleanly exit the main loop to ensure that all the tiny details get set properly. +// This should mitigate most of the smaller bugs. +bool menu_replace_config(const char *path) +{ + if (strcmp(path, g_extern.config_path) == 0) + return false; + + if (g_extern.config_save_on_exit && *g_extern.config_path) + config_save_file(g_extern.config_path); + + strlcpy(g_extern.config_path, path, sizeof(g_extern.config_path)); + g_extern.block_config_read = false; + + // Load dummy core. + *g_extern.fullpath = '\0'; + *g_settings.libretro = '\0'; // Load core in new config. + g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME); + rgui->load_no_rom = false; + + return true; +} + diff --git a/frontend/menu/menu_common.h b/frontend/menu/menu_common.h index 0ff3f1ba77..e5ef7a0024 100644 --- a/frontend/menu/menu_common.h +++ b/frontend/menu/menu_common.h @@ -129,6 +129,7 @@ typedef enum RGUI_SETTINGS_OPEN_FILEBROWSER, RGUI_SETTINGS_OPEN_HISTORY, RGUI_SETTINGS_CORE, + RGUI_SETTINGS_CONFIG, RGUI_SETTINGS_CORE_OPTIONS, RGUI_SETTINGS_AUDIO_OPTIONS, RGUI_SETTINGS_INPUT_OPTIONS, @@ -247,6 +248,7 @@ typedef struct #ifdef HAVE_DYNAMIC char libretro_dir[PATH_MAX]; #endif + char config_dir[PATH_MAX]; struct retro_system_info info; bool load_no_rom; @@ -292,6 +294,8 @@ void menu_rom_history_push(const char *path, const char *core_path, const char *core_name); void menu_rom_history_push_current(void); +bool menu_replace_config(const char *path); + #ifdef __cplusplus } #endif diff --git a/frontend/menu/rgui.c b/frontend/menu/rgui.c index f3cb3dfa2e..40cfbe5f1c 100644 --- a/frontend/menu/rgui.c +++ b/frontend/menu/rgui.c @@ -443,6 +443,8 @@ static void render_text(rgui_handle_t *rgui) if (menu_type == RGUI_SETTINGS_CORE) snprintf(title, sizeof(title), "CORE SELECTION %s", dir); + else if (menu_type == RGUI_SETTINGS_CONFIG) + snprintf(title, sizeof(title), "CONFIG %s", dir); else if (menu_type == RGUI_SETTINGS_DISK_APPEND) snprintf(title, sizeof(title), "DISK APPEND %s", dir); else if (menu_type == RGUI_SETTINGS_VIDEO_OPTIONS) @@ -561,6 +563,7 @@ static void render_text(rgui_handle_t *rgui) else #endif if (menu_type == RGUI_SETTINGS_CORE || + menu_type == RGUI_SETTINGS_CONFIG || #ifdef HAVE_OVERLAY menu_type == RGUI_SETTINGS_OVERLAY_PRESET || #endif @@ -738,6 +741,12 @@ static void render_text(rgui_handle_t *rgui) snprintf(type_str, sizeof(type_str), "%u", current + 1); break; } + case RGUI_SETTINGS_CONFIG: + if (*g_extern.config_path) + fill_pathname_base(type_str, g_extern.config_path, sizeof(type_str)); + else + strlcpy(type_str, "", sizeof(type_str)); + break; case RGUI_SETTINGS_OPEN_FILEBROWSER: case RGUI_SETTINGS_OPEN_HISTORY: case RGUI_SETTINGS_CORE_OPTIONS: @@ -1490,6 +1499,7 @@ static void rgui_settings_populate_entries(rgui_handle_t *rgui) #ifndef HAVE_DYNAMIC rgui_list_push(rgui->selection_buf, "Restart RetroArch", RGUI_SETTINGS_RESTART_EMULATOR, 0); #endif + rgui_list_push(rgui->selection_buf, "RetroArch Config", RGUI_SETTINGS_CONFIG, 0); rgui_list_push(rgui->selection_buf, "Quit RetroArch", RGUI_SETTINGS_QUIT_RARCH, 0); } @@ -2369,6 +2379,8 @@ static int rgui_settings_iterate(rgui_handle_t *rgui, rgui_action_t action) label = ""; // Shouldn't happen ... #endif } + else if (type == RGUI_SETTINGS_CONFIG) + label = rgui->config_dir; else if (type == RGUI_SETTINGS_DISK_APPEND) label = rgui->base_path; @@ -2419,7 +2431,7 @@ static int rgui_settings_iterate(rgui_handle_t *rgui, rgui_action_t action) rgui->selection_ptr = 0; rgui->need_refresh = true; } - else if ((menu_type_is_settings(type) || type == RGUI_SETTINGS_CORE || type == RGUI_SETTINGS_DISK_APPEND) && action == RGUI_ACTION_OK) + else if ((menu_type_is_settings(type) || type == RGUI_SETTINGS_CORE || type == RGUI_SETTINGS_CONFIG || type == RGUI_SETTINGS_DISK_APPEND) && action == RGUI_ACTION_OK) { rgui_list_push(rgui->menu_stack, label, type, rgui->selection_ptr); rgui->selection_ptr = 0; @@ -2471,7 +2483,9 @@ static int rgui_settings_iterate(rgui_handle_t *rgui, rgui_action_t action) #ifdef HAVE_OVERLAY menu_type == RGUI_SETTINGS_OVERLAY_PRESET || #endif - menu_type == RGUI_SETTINGS_CORE || menu_type == RGUI_SETTINGS_DISK_APPEND || + menu_type == RGUI_SETTINGS_CORE || + menu_type == RGUI_SETTINGS_CONFIG || + menu_type == RGUI_SETTINGS_DISK_APPEND || menu_type == RGUI_SETTINGS_OPEN_HISTORY)) { rgui->need_refresh = false; @@ -2584,6 +2598,8 @@ static bool directory_parse(rgui_handle_t *rgui, const char *directory, unsigned char ext_buf[1024]; if (menu_type == RGUI_SETTINGS_CORE) exts = EXT_EXECUTABLES; + else if (menu_type == RGUI_SETTINGS_CONFIG) + exts = "cfg"; #ifdef HAVE_SHADER_MANAGER else if (menu_type == RGUI_SETTINGS_SHADER_PRESET) exts = "cgp|glslp"; @@ -2731,6 +2747,7 @@ static int rgui_iterate(void *data, unsigned action) type == RGUI_SETTINGS_OVERLAY_PRESET || #endif type == RGUI_SETTINGS_CORE || + type == RGUI_SETTINGS_CONFIG || type == RGUI_SETTINGS_DISK_APPEND || type == RGUI_FILE_DIRECTORY) { @@ -2796,6 +2813,15 @@ static int rgui_iterate(void *data, unsigned action) rgui_flush_menu_stack(rgui); } + else if (menu_type == RGUI_SETTINGS_CONFIG) + { + char config[PATH_MAX]; + fill_pathname_join(config, dir, path, sizeof(config)); + rgui_flush_menu_stack(rgui); + rgui->msg_force = true; + if (menu_replace_config(config)) + ret = -1; + } #ifdef HAVE_OVERLAY else if (menu_type == RGUI_SETTINGS_OVERLAY_PRESET) { @@ -2918,6 +2944,7 @@ static int rgui_iterate(void *data, unsigned action) menu_type == RGUI_SETTINGS_OVERLAY_PRESET || #endif menu_type == RGUI_SETTINGS_CORE || + menu_type == RGUI_SETTINGS_CONFIG || menu_type == RGUI_SETTINGS_OPEN_HISTORY || menu_type == RGUI_SETTINGS_DISK_APPEND)) {