Skip to content

Commit 56231db

Browse files
committed
Disc Control menu refactor
1 parent 74f2be3 commit 56231db

11 files changed

Lines changed: 187 additions & 240 deletions

command.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2369,17 +2369,6 @@ bool command_event_disk_control_append_image(
23692369
autosave_deinit();
23702370
#endif
23712371

2372-
/* TODO/FIXME: Need to figure out what to do with subsystems case. */
2373-
if (path_is_empty(RARCH_PATH_SUBSYSTEM))
2374-
{
2375-
/* Update paths for our new image.
2376-
* If we actually use append_image, we assume that we
2377-
* started out in a single disk case, and that this way
2378-
* of doing it makes the most sense. */
2379-
path_set(RARCH_PATH_NAMES, path);
2380-
runloop_path_fill_names();
2381-
}
2382-
23832372
command_event(CMD_EVENT_AUTOSAVE_INIT, NULL);
23842373

23852374
return true;

disk_control_interface.c

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -342,25 +342,19 @@ bool disk_control_set_eject_state(
342342
size_t _len;
343343

344344
if (!disk_control || !disk_control->cb.set_eject_state)
345-
return false;
345+
return err;
346346

347347
/* Set eject state */
348348
if (disk_control->cb.set_eject_state(eject))
349-
_len = strlcpy(
350-
msg,
351-
eject
352-
? msg_hash_to_str(MSG_DISK_EJECTED)
353-
: msg_hash_to_str(MSG_DISK_CLOSED),
354-
sizeof(msg));
349+
_len = strlcpy(msg,
350+
eject ? msg_hash_to_str(MSG_DISK_EJECTED) : msg_hash_to_str(MSG_DISK_CLOSED),
351+
sizeof(msg));
355352
else
356353
{
357354
err = true;
358-
_len = strlcpy(
359-
msg,
360-
eject
361-
? msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_EJECT)
362-
: msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_CLOSE),
363-
sizeof(msg));
355+
_len = strlcpy(msg,
356+
eject ? msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_EJECT) : msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_CLOSE),
357+
sizeof(msg));
364358
}
365359

366360
if (_len > 0)
@@ -398,9 +392,9 @@ bool disk_control_set_eject_state(
398392
/**
399393
* disk_control_set_index:
400394
*
401-
* Sets currently selected disk index
402-
*
403-
* NOTE: Will fail if disk is not currently ejected
395+
* Sets currently selected disk index.
396+
* Does silent eject and delayed insert with
397+
* 'runloop_st->pending_disk_control_insert' if tray is closed.
404398
**/
405399
bool disk_control_set_index(
406400
disk_control_interface_t *disk_control,
@@ -414,17 +408,26 @@ bool disk_control_set_index(
414408

415409
msg[0] = '\0';
416410

417-
if (!disk_control)
418-
return false;
411+
if ( !disk_control
412+
|| !disk_control->cb.get_eject_state
413+
|| !disk_control->cb.get_num_images
414+
|| !disk_control->cb.get_image_index
415+
|| !disk_control->cb.set_image_index)
416+
return err;
419417

420-
if ( !disk_control->cb.get_eject_state
421-
|| !disk_control->cb.get_num_images
422-
|| !disk_control->cb.set_image_index)
423-
return false;
418+
/* Do nothing if the desired disc is already in */
419+
if (disk_control->cb.get_image_index() == index)
420+
return !err;
424421

425-
/* Ensure that disk is currently ejected */
422+
/* Do delayed disk insert if changing while not ejected */
426423
if (!disk_control->cb.get_eject_state())
427-
return false;
424+
{
425+
runloop_state_t *runloop_st = runloop_state_get_ptr();
426+
427+
if ( runloop_st
428+
&& disk_control_set_eject_state(disk_control, true, false))
429+
runloop_st->pending_disk_control_insert = 100;
430+
}
428431

429432
/* Get current number of disk images */
430433
num_images = disk_control->cb.get_num_images();
@@ -466,7 +469,6 @@ bool disk_control_set_index(
466469
&& disk_control->cb.get_image_path)
467470
{
468471
char new_image_path[PATH_MAX_LENGTH] = {0};
469-
/* Get current image index + path */
470472
unsigned new_image_index = disk_control->cb.get_image_index();
471473
bool image_path_valid = disk_control->cb.get_image_path(
472474
new_image_index, new_image_path, sizeof(new_image_path));
@@ -618,22 +620,22 @@ bool disk_control_append_image(
618620

619621
if ((new_index = disk_control->cb.get_num_images()) < 1)
620622
goto error;
621-
new_index--;
622623

624+
new_index--;
623625
info.path = image_path;
624-
if (!disk_control->cb.replace_image_index(new_index, &info))
625-
goto error;
626626

627-
/* Set new index */
628-
if (!disk_control_set_index(disk_control, new_index, false))
627+
if (!disk_control->cb.replace_image_index(new_index, &info))
629628
goto error;
630629

631-
/* If tray was initially closed, insert disk
632-
* (i.e. leave system in the state we found it) */
630+
/* If tray was initially closed, insert disk */
633631
if ( !initial_disk_ejected
634632
&& !disk_control_set_eject_state(disk_control, false, false))
635633
goto error;
636634

635+
/* Set new index */
636+
if (!disk_control_set_index(disk_control, new_index, false))
637+
goto error;
638+
637639
/* Display log */
638640
_len = strlcpy(msg, msg_hash_to_str(MSG_APPENDED_DISK), sizeof(msg) - 3);
639641
msg[ _len] = ':';
@@ -658,11 +660,7 @@ bool disk_control_append_image(
658660
* NOTE: If this fails then it's game over -
659661
* just display the error notification and
660662
* hope for the best... */
661-
if (!disk_control->cb.get_eject_state())
662-
disk_control_set_eject_state(disk_control, true, false);
663663
disk_control_set_index(disk_control, initial_index, false);
664-
if (!initial_disk_ejected)
665-
disk_control_set_eject_state(disk_control, false, false);
666664

667665
_len = strlcpy(msg,
668666
msg_hash_to_str(MSG_FAILED_TO_APPEND_DISK), sizeof(msg) - 3);
@@ -672,7 +670,7 @@ bool disk_control_append_image(
672670
_len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
673671

674672
runloop_msg_queue_push(msg, _len, 2, 180, true, NULL,
675-
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_WARNING);
673+
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_ERROR);
676674

677675
return false;
678676
}

intl/msg_hash_us.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,15 +4050,15 @@ MSG_HASH(
40504050
)
40514051
MSG_HASH(
40524052
MENU_ENUM_SUBLABEL_INPUT_META_DISK_NEXT,
4053-
"Increments the currently selected disc index. Virtual disc tray must be open."
4053+
"Increments the currently selected disc index and does delayed insert if virtual disc tray is closed."
40544054
)
40554055
MSG_HASH(
40564056
MENU_ENUM_LABEL_VALUE_INPUT_META_DISK_PREV,
40574057
"Previous Disc"
40584058
)
40594059
MSG_HASH(
40604060
MENU_ENUM_SUBLABEL_INPUT_META_DISK_PREV,
4061-
"Decrements the currently selected disc index. Virtual disc tray must be open."
4061+
"Decrements the currently selected disc index and does delayed insert if virtual disc tray is closed."
40624062
)
40634063

40644064
MSG_HASH(
@@ -10084,41 +10084,42 @@ MSG_HASH(
1008410084

1008510085
/* Quick Menu > Disc Control */
1008610086

10087+
MSG_HASH(
10088+
MENU_ENUM_LABEL_VALUE_DISK_INDEX,
10089+
"Current Disc Index"
10090+
)
10091+
MSG_HASH(
10092+
MENU_ENUM_SUBLABEL_DISK_INDEX,
10093+
"Choose current disc from list of available images. Virtual disc tray can stay closed."
10094+
)
1008710095
MSG_HASH(
1008810096
MENU_ENUM_LABEL_VALUE_DISK_TRAY_EJECT,
1008910097
"Eject Disc"
1009010098
)
1009110099
MSG_HASH(
1009210100
MENU_ENUM_SUBLABEL_DISK_TRAY_EJECT,
10093-
"Open virtual disc tray and remove currently loaded disc. If 'Pause Content When Menu Is Active' is enabled, some cores may not register changes unless content is resumed for a few seconds after each disc control action."
10101+
"Open virtual disc tray."
1009410102
)
1009510103
MSG_HASH(
1009610104
MENU_ENUM_LABEL_VALUE_DISK_TRAY_INSERT,
1009710105
"Insert Disc"
1009810106
)
1009910107
MSG_HASH(
1010010108
MENU_ENUM_SUBLABEL_DISK_TRAY_INSERT,
10101-
"Insert disc corresponding to 'Current Disc Index' and close virtual disc tray. If 'Pause Content When Menu Is Active' is enabled, some cores may not register changes unless content is resumed for a few seconds after each disc control action."
10109+
"Close virtual disc tray."
1010210110
)
1010310111
MSG_HASH(
1010410112
MENU_ENUM_LABEL_VALUE_DISK_IMAGE_APPEND,
1010510113
"Load New Disc"
1010610114
)
1010710115
MSG_HASH(
1010810116
MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND,
10109-
"Eject current disc, select a new disc from the filesystem then insert it and close the virtual disc tray.\nNOTE: 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."
10117+
"Select a new disc from the filesystem and append it in the index list.\nNOTE: This is a legacy feature. It is instead recommended to use M3U playlists for multi-disc titles."
1011010118
)
10119+
/* deprecated */
1011110120
MSG_HASH(
1011210121
MENU_ENUM_SUBLABEL_DISK_IMAGE_APPEND_TRAY_OPEN,
10113-
"Select a new disc from the filesystem and insert it without closing the virtual disc tray.\nNOTE: 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."
10114-
)
10115-
MSG_HASH(
10116-
MENU_ENUM_LABEL_VALUE_DISK_INDEX,
10117-
"Current Disc Index"
10118-
)
10119-
MSG_HASH(
10120-
MENU_ENUM_SUBLABEL_DISK_INDEX,
10121-
"Choose current disc from list of available images. Disc will be loaded when 'Insert Disc' is selected."
10122+
""
1012210123
)
1012310124

1012410125
/* Quick Menu > Shaders */

menu/cbs/menu_cbs_ok.c

Lines changed: 43 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7518,16 +7518,33 @@ static int action_ok_push_dropdown_item_manual_content_scan_core_name(
75187518
static int action_ok_push_dropdown_item_disk_index(const char *path,
75197519
const char *label, unsigned type, size_t idx, size_t entry_idx)
75207520
{
7521-
struct menu_state *menu_st = menu_state_get_ptr();
7522-
unsigned disk_index = (unsigned)idx;
7521+
unsigned disk_index = (unsigned)idx;
7522+
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
7523+
settings_t *settings = config_get_ptr();
7524+
bool menu_insert_disk_resume = settings->bools.menu_insert_disk_resume;
7525+
bool disk_ejected = false;
7526+
7527+
if (!settings || !sys_info)
7528+
return -1;
7529+
7530+
#ifdef HAVE_AUDIOMIXER
7531+
if (settings->bools.audio_enable_menu && settings->bools.audio_enable_menu_ok)
7532+
audio_driver_mixer_play_menu_sound(AUDIO_MIXER_SYSTEM_SLOT_OK);
7533+
#endif
7534+
7535+
/* Get disk eject state *before* toggling drive status */
7536+
if (sys_info)
7537+
disk_ejected = disk_control_get_eject_state(&sys_info->disk_control);
75237538

75247539
command_event(CMD_EVENT_DISK_INDEX, &disk_index);
75257540

7526-
/* When choosing a disk, menu selection should
7527-
* automatically be reset to the 'insert disk'
7528-
* option */
7529-
menu_entries_pop_stack(NULL, 0, 1);
7530-
menu_st->selection_ptr = 0;
7541+
/* If disk is now inserted and user has enabled
7542+
* 'menu_insert_disk_resume', resume running content */
7543+
if (!disk_ejected && menu_insert_disk_resume)
7544+
generic_action_ok_command(CMD_EVENT_RESUME);
7545+
7546+
/* In all cases, return to the disk options menu */
7547+
menu_entries_flush_stack(msg_hash_to_str(MENU_ENUM_LABEL_DISK_OPTIONS), 0);
75317548

75327549
return 0;
75337550
}
@@ -8208,52 +8225,30 @@ static int action_ok_input_description_kbd_dropdown_box_list(
82088225
static int action_ok_disk_cycle_tray_status(const char *path,
82098226
const char *label, unsigned type, size_t idx, size_t entry_idx)
82108227
{
8211-
bool disk_ejected = false;
8212-
bool print_log = false;
8213-
struct menu_state *menu_st = menu_state_get_ptr();
8214-
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
8215-
settings_t *settings = config_get_ptr();
8216-
#ifdef HAVE_AUDIOMIXER
8217-
bool audio_enable_menu = settings->bools.audio_enable_menu;
8218-
bool audio_enable_menu_ok = settings->bools.audio_enable_menu_ok;
8219-
#endif
8220-
bool menu_insert_disk_resume = settings->bools.menu_insert_disk_resume;
8228+
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
8229+
settings_t *settings = config_get_ptr();
8230+
bool menu_insert_disk_resume = settings->bools.menu_insert_disk_resume;
8231+
bool verbosity = false;
82218232

8222-
if (!settings)
8233+
if (!settings || !sys_info)
82238234
return -1;
82248235

82258236
#ifdef HAVE_AUDIOMIXER
8226-
if (audio_enable_menu && audio_enable_menu_ok)
8237+
if (settings->bools.audio_enable_menu && settings->bools.audio_enable_menu_ok)
82278238
audio_driver_mixer_play_menu_sound(AUDIO_MIXER_SYSTEM_SLOT_OK);
82288239
#endif
82298240

8230-
/* Get disk eject state *before* toggling drive status */
8231-
if (sys_info)
8232-
disk_ejected = disk_control_get_eject_state(&sys_info->disk_control);
8233-
82348241
/* Only want to display a notification if we are
82358242
* going to resume content immediately after
82368243
* inserting a disk (i.e. if quick menu remains
82378244
* open, there is sufficient visual feedback
82388245
* without a notification) */
8239-
print_log = menu_insert_disk_resume && disk_ejected;
8246+
verbosity = menu_insert_disk_resume;
82408247

8241-
if (!command_event(CMD_EVENT_DISK_EJECT_TOGGLE, &print_log))
8248+
if (!command_event(CMD_EVENT_DISK_EJECT_TOGGLE, &verbosity))
82428249
return -1;
82438250

8244-
/* If we reach this point, then tray toggle
8245-
* was successful */
8246-
disk_ejected = !disk_ejected;
8247-
8248-
/* If disk is now ejected, menu selection should
8249-
* automatically increment to the 'current disk
8250-
* index' option */
8251-
if (disk_ejected)
8252-
menu_st->selection_ptr = 1;
8253-
8254-
/* If disk is now inserted and user has enabled
8255-
* 'menu_insert_disk_resume', resume running content */
8256-
if (!disk_ejected && menu_insert_disk_resume)
8251+
if (menu_insert_disk_resume)
82578252
generic_action_ok_command(CMD_EVENT_RESUME);
82588253

82598254
return 0;
@@ -8265,19 +8260,15 @@ static int action_ok_disk_image_append(const char *path,
82658260
rarch_system_info_t *sys_info = &runloop_state_get_ptr()->system;
82668261
struct menu_state *menu_st = menu_state_get_ptr();
82678262
menu_handle_t *menu = menu_st->driver_data;
8268-
const char *menu_path = NULL;
82698263
settings_t *settings = config_get_ptr();
8270-
#ifdef HAVE_AUDIOMIXER
8271-
bool audio_enable_menu = settings->bools.audio_enable_menu;
8272-
bool audio_enable_menu_ok = settings->bools.audio_enable_menu_ok;
8273-
#endif
82748264
bool menu_insert_disk_resume = settings->bools.menu_insert_disk_resume;
8265+
const char *menu_path = NULL;
82758266

8276-
if (!menu)
8267+
if (!menu || !settings || !sys_info)
82778268
return -1;
82788269

82798270
#ifdef HAVE_AUDIOMIXER
8280-
if (audio_enable_menu && audio_enable_menu_ok)
8271+
if (settings->bools.audio_enable_menu && settings->bools.audio_enable_menu_ok)
82818272
audio_driver_mixer_play_menu_sound(AUDIO_MIXER_SYSTEM_SLOT_OK);
82828273
#endif
82838274

@@ -8288,9 +8279,9 @@ static int action_ok_disk_image_append(const char *path,
82888279
if (!string_is_empty(menu_path))
82898280
{
82908281
char image_path[PATH_MAX_LENGTH];
8291-
bool is_dir = (entry_idx == FILE_TYPE_USE_DIRECTORY
8292-
&& string_is_equal(label,
8293-
msg_hash_to_str(MENU_ENUM_LABEL_USE_THIS_DIRECTORY)));
8282+
bool is_dir = entry_idx == FILE_TYPE_USE_DIRECTORY
8283+
&& string_is_equal(label, msg_hash_to_str(MENU_ENUM_LABEL_USE_THIS_DIRECTORY));
8284+
82948285
if (is_dir)
82958286
{
82968287
size_t past_slash;
@@ -8304,22 +8295,17 @@ static int action_ok_disk_image_append(const char *path,
83048295
menu_path, path, sizeof(image_path));
83058296
else
83068297
strlcpy(image_path, menu_path, sizeof(image_path));
8298+
83078299
/* Append image */
83088300
command_event(CMD_EVENT_DISK_APPEND_IMAGE, image_path);
83098301
}
83108302

8303+
if (menu_insert_disk_resume && !disk_control_get_eject_state(&sys_info->disk_control))
8304+
generic_action_ok_command(CMD_EVENT_RESUME);
8305+
83118306
/* In all cases, return to the disk options menu */
83128307
menu_entries_flush_stack(msg_hash_to_str(MENU_ENUM_LABEL_DISK_OPTIONS), 0);
83138308

8314-
/* > If disk tray is open, reset menu selection to
8315-
* the 'insert disk' option
8316-
* > If disk try is closed and user has enabled
8317-
* 'menu_insert_disk_resume', resume running content */
8318-
if (sys_info && disk_control_get_eject_state(&sys_info->disk_control))
8319-
menu_st->selection_ptr = 0;
8320-
else if (menu_insert_disk_resume)
8321-
generic_action_ok_command(CMD_EVENT_RESUME);
8322-
83238309
return 0;
83248310
}
83258311

0 commit comments

Comments
 (0)