From 0c18da5d4928c040fb16ce3380565b24dff73b73 Mon Sep 17 00:00:00 2001 From: jdgleaver Date: Wed, 17 Jun 2020 11:41:50 +0100 Subject: [PATCH] (Disk Control Interface) Enable 'Load New Disc' while disk tray is open --- disk_control_interface.c | 18 +++++++--- intl/msg_hash_us.h | 4 +++ menu/cbs/menu_cbs_ok.c | 70 ++++++++++++++++++++++++++++-------- menu/cbs/menu_cbs_sublabel.c | 20 ++++++++++- menu/menu_displaylist.c | 26 +++++++------- msg_hash.h | 3 ++ retroarch.c | 37 ++++++++++++++++--- 7 files changed, 140 insertions(+), 38 deletions(-) diff --git a/disk_control_interface.c b/disk_control_interface.c index c03773b192..2c1d93d5dc 100644 --- a/disk_control_interface.c +++ b/disk_control_interface.c @@ -489,6 +489,7 @@ bool disk_control_append_image( disk_control_interface_t *disk_control, const char *image_path) { + bool initial_disk_ejected = false; unsigned initial_index = 0; unsigned new_index = 0; const char *image_filename = NULL; @@ -518,11 +519,15 @@ bool disk_control_append_image( if (string_is_empty(image_filename)) return false; + /* Get initial disk eject state */ + initial_disk_ejected = disk_control_get_eject_state(disk_control); + /* Cache initial image index */ initial_index = disk_control->cb.get_image_index(); - /* Eject disk */ - if (!disk_control_set_eject_state(disk_control, true, false)) + /* If tray is currently closed, eject disk */ + if (!initial_disk_ejected && + !disk_control_set_eject_state(disk_control, true, false)) goto error; /* Append image */ @@ -542,8 +547,10 @@ bool disk_control_append_image( if (!disk_control_set_index(disk_control, new_index, false)) goto error; - /* Insert disk */ - if (!disk_control_set_eject_state(disk_control, false, false)) + /* If tray was initially closed, insert disk + * (i.e. leave system in the state we found it) */ + if (!initial_disk_ejected && + !disk_control_set_eject_state(disk_control, false, false)) goto error; /* Display log */ @@ -573,7 +580,8 @@ error: if (!disk_control->cb.get_eject_state()) disk_control_set_eject_state(disk_control, true, false); disk_control_set_index(disk_control, initial_index, false); - disk_control_set_eject_state(disk_control, false, false); + if (!initial_disk_ejected) + disk_control_set_eject_state(disk_control, false, false); snprintf( msg, sizeof(msg), "%s: %s", diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 840456805a..cf5d638777 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -6068,6 +6068,10 @@ MSG_HASH( MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND, "Eject current disc, select a new disc from the filesystem then insert it and close the virtual disc tray. NOTE: This is a legacy feature. It is instead recommended to load multi-disc titles via M3U playlists, which allow disc selection using the 'Eject/Insert Disc' and 'Current Disc Index' options." ) +MSG_HASH( + MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND_TRAY_OPEN, + "Select a new disc from the filesystem and insert it without closing the virtual disc tray. NOTE: This is a legacy feature. It is instead recommended to load multi-disc titles via M3U playlists, which allow disc selection using the 'Current Disc Index' option." + ) MSG_HASH( MENU_ENUM_LABEL_VALUE_DISK_INDEX, "Current Disc Index" diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 56a0ff0887..3156114086 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -99,7 +99,6 @@ enum ACTION_OK_LOAD_RECORD_CONFIGFILE, ACTION_OK_LOAD_REMAPPING_FILE, ACTION_OK_LOAD_CHEAT_FILE, - ACTION_OK_APPEND_DISK_IMAGE, ACTION_OK_SUBSYSTEM_ADD, ACTION_OK_LOAD_CONFIG_FILE, ACTION_OK_LOAD_CORE, @@ -1767,19 +1766,6 @@ static int generic_action_ok(const char *path, } } break; - case ACTION_OK_APPEND_DISK_IMAGE: - { - settings_t *settings = config_get_ptr(); - bool menu_insert_disk_resume = settings->bools.menu_insert_disk_resume; - - flush_char = msg_hash_to_str( - MENU_ENUM_LABEL_DISK_OPTIONS); - command_event(CMD_EVENT_DISK_APPEND_IMAGE, action_path); - - if (menu_insert_disk_resume) - generic_action_ok_command(CMD_EVENT_RESUME); - } - break; case ACTION_OK_SUBSYSTEM_ADD: flush_type = MENU_SETTINGS; content_add_subsystem(action_path); @@ -1876,7 +1862,6 @@ DEFAULT_ACTION_OK_SET(action_ok_set_path_video_layout,ACTION_OK_SET_PATH_VIDEO_L DEFAULT_ACTION_OK_SET(action_ok_set_path, ACTION_OK_SET_PATH, MSG_UNKNOWN) DEFAULT_ACTION_OK_SET(action_ok_load_core, ACTION_OK_LOAD_CORE, MSG_UNKNOWN) DEFAULT_ACTION_OK_SET(action_ok_config_load, ACTION_OK_LOAD_CONFIG_FILE, MSG_UNKNOWN) -DEFAULT_ACTION_OK_SET(action_ok_disk_image_append, ACTION_OK_APPEND_DISK_IMAGE, MSG_UNKNOWN) DEFAULT_ACTION_OK_SET(action_ok_subsystem_add, ACTION_OK_SUBSYSTEM_ADD, MSG_UNKNOWN) DEFAULT_ACTION_OK_SET(action_ok_cheat_file_load, ACTION_OK_LOAD_CHEAT_FILE, MENU_ENUM_LABEL_CORE_CHEAT_OPTIONS) DEFAULT_ACTION_OK_SET(action_ok_cheat_file_load_append, ACTION_OK_LOAD_CHEAT_FILE_APPEND, MENU_ENUM_LABEL_CORE_CHEAT_OPTIONS) @@ -6154,6 +6139,61 @@ static int action_ok_disk_cycle_tray_status(const char *path, return 0; } +static int action_ok_disk_image_append(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ + rarch_system_info_t *sys_info = runloop_get_system_info(); + menu_handle_t *menu = menu_driver_get_ptr(); + const char *menu_path = NULL; + settings_t *settings = config_get_ptr(); +#ifdef HAVE_AUDIOMIXER + bool audio_enable_menu = settings->bools.audio_enable_menu; + bool audio_enable_menu_ok = settings->bools.audio_enable_menu_ok; +#endif + bool menu_insert_disk_resume = settings->bools.menu_insert_disk_resume; + char image_path[PATH_MAX_LENGTH]; + + image_path[0] = '\0'; + + if (!menu) + return menu_cbs_exit(); + +#ifdef HAVE_AUDIOMIXER + if (audio_enable_menu && audio_enable_menu_ok) + audio_driver_mixer_play_menu_sound(AUDIO_MIXER_SYSTEM_SLOT_OK); +#endif + + /* Get file path of new disk image */ + menu_entries_get_last_stack(&menu_path, + NULL, NULL, NULL, NULL); + + if (!string_is_empty(menu_path)) + { + if (!string_is_empty(path)) + fill_pathname_join(image_path, + menu_path, path, sizeof(image_path)); + else + strlcpy(image_path, menu_path, sizeof(image_path)); + } + + /* Append image */ + command_event(CMD_EVENT_DISK_APPEND_IMAGE, image_path); + + /* In all cases, return to the disk options menu */ + menu_entries_flush_stack(msg_hash_to_str(MENU_ENUM_LABEL_DISK_OPTIONS), 0); + + /* > If disk tray is open, reset menu selection to + * the 'insert disk' option + * > If disk try is closed and user has enabled + * 'menu_insert_disk_resume', resume running content */ + if (sys_info && disk_control_get_eject_state(&sys_info->disk_control)) + menu_navigation_set_selection(0); + else if (menu_insert_disk_resume) + generic_action_ok_command(CMD_EVENT_RESUME); + + return 0; +} + static int action_ok_manual_content_scan_start(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index df3d106c06..273be76327 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -584,7 +584,6 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_latency_frames, DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_latency_frames_range, MENU_ENUM_SUBLABEL_NETPLAY_INPUT_LATENCY_FRAMES_RANGE) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_disk_tray_eject, MENU_ENUM_SUBLABEL_DISK_TRAY_EJECT) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_disk_tray_insert, MENU_ENUM_SUBLABEL_DISK_TRAY_INSERT) -DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_disk_image_append, MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_disk_index, MENU_ENUM_SUBLABEL_DISK_INDEX) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_disk_options, MENU_ENUM_SUBLABEL_DISK_OPTIONS) DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_menu_throttle_framerate, MENU_ENUM_SUBLABEL_MENU_ENUM_THROTTLE_FRAMERATE) @@ -951,6 +950,25 @@ static int action_bind_sublabel_subsystem_load( return 0; } +static int action_bind_sublabel_disk_image_append( + file_list_t *list, + unsigned type, unsigned i, + const char *label, const char *path, + char *s, size_t len) +{ + rarch_system_info_t *sys_info = runloop_get_system_info(); + enum msg_hash_enums enum_idx = MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND; + + /* Check whether disk is currently ejected */ + if (sys_info && + disk_control_get_eject_state(&sys_info->disk_control)) + enum_idx = MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND_TRAY_OPEN; + + strlcpy(s, msg_hash_to_str(enum_idx), len); + + return 1; +} + static int action_bind_sublabel_remap_kbd_sublabel( file_list_t *list, unsigned type, unsigned i, diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 3ae2508148..7c67765977 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3620,19 +3620,19 @@ static unsigned menu_displaylist_parse_disk_options( if (!disk_control_append_enabled(&sys_info->disk_control)) return count; - /* Append image does the following: - * > Open tray - * > Append disk image - * > Close tray - * It therefore only makes sense to show this option - * if a disk is currently inserted */ - if (!disk_ejected) - if (menu_entries_append_enum(list, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISK_IMAGE_APPEND), - msg_hash_to_str(MENU_ENUM_LABEL_DISK_IMAGE_APPEND), - MENU_ENUM_LABEL_DISK_IMAGE_APPEND, - MENU_SETTINGS_CORE_DISK_OPTIONS_DISK_IMAGE_APPEND, 0, 0)) - count++; + /* Always show a 'DISK_IMAGE_APPEND' entry + * > If tray is currently shut, this will: + * - Open tray + * - Append disk image + * - Close tray + * > If tray is currently open, this will + * only append a disk image */ + if (menu_entries_append_enum(list, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_DISK_IMAGE_APPEND), + msg_hash_to_str(MENU_ENUM_LABEL_DISK_IMAGE_APPEND), + MENU_ENUM_LABEL_DISK_IMAGE_APPEND, + MENU_SETTINGS_CORE_DISK_OPTIONS_DISK_IMAGE_APPEND, 0, 0)) + count++; return count; } diff --git a/msg_hash.h b/msg_hash.h index ae7df97325..8e8d5c2313 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1967,6 +1967,9 @@ enum msg_hash_enums MENU_LABEL(SHUTDOWN), MENU_LABEL(REBOOT), MENU_LABEL(DISK_IMAGE_APPEND), + + MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND_TRAY_OPEN, + MENU_LABEL(SUBSYSTEM_ADD), MENU_LABEL(SUBSYSTEM_LOAD), MENU_LABEL(CORE_LIST), diff --git a/retroarch.c b/retroarch.c index e7e863c51d..842524b3c0 100644 --- a/retroarch.c +++ b/retroarch.c @@ -15308,11 +15308,40 @@ bool command_event(enum event_command cmd, void *data) break; case CMD_EVENT_DISK_APPEND_IMAGE: { - const char *path = (const char*)data; - if (string_is_empty(path)) - return false; - if (!command_event_disk_control_append_image(p_rarch, path)) + const char *path = (const char*)data; + rarch_system_info_t *sys_info = &p_rarch->runloop_system; + + if (string_is_empty(path) || !sys_info) return false; + + if (disk_control_enabled(&sys_info->disk_control)) + { + bool success = false; +#if defined(HAVE_MENU) + bool refresh = false; + /* Get initial disk eject state */ + bool initial_disk_ejected = disk_control_get_eject_state(&sys_info->disk_control); +#endif + /* Append disk image */ + success = command_event_disk_control_append_image(p_rarch, path); + +#if defined(HAVE_MENU) + /* Appending a disk image may or may not affect + * the disk tray eject status. If status has changed, + * must refresh the disk options menu */ + if (initial_disk_ejected != disk_control_get_eject_state(&sys_info->disk_control)) + { + menu_entries_ctl(MENU_ENTRIES_CTL_SET_REFRESH, &refresh); + menu_driver_ctl(RARCH_MENU_CTL_SET_PREVENT_POPULATE, NULL); + } +#endif + return success; + } + else + runloop_msg_queue_push( + msg_hash_to_str(MSG_CORE_DOES_NOT_SUPPORT_DISK_OPTIONS), + 1, 120, true, + NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO); } break; case CMD_EVENT_DISK_EJECT_TOGGLE: