mirror of
https://github.com/libretro/RetroArch
synced 2025-03-02 19:13:34 +00:00
cdrom: check if disc is inserted before trying to load or dump
This commit is contained in:
parent
75e512e22e
commit
980de11974
@ -9017,3 +9017,5 @@ MSG_HASH(MSG_DISC_DUMP_FAILED_TO_READ_FROM_DRIVE,
|
||||
"ドライブからの読み込みに失敗しました。ダンプが中止されました。")
|
||||
MSG_HASH(MSG_DISC_DUMP_FAILED_TO_WRITE_TO_DISK,
|
||||
"ディスクに書き込みに失敗しました。ダンプが中止されました。")
|
||||
MSG_HASH(MSG_NO_DISC_INSERTED,
|
||||
"ドライブにディスクが挿入されていません。")
|
||||
|
@ -8949,3 +8949,5 @@ MSG_HASH(MSG_DISC_DUMP_FAILED_TO_READ_FROM_DRIVE,
|
||||
"Failed to read from drive. Dump aborted.")
|
||||
MSG_HASH(MSG_DISC_DUMP_FAILED_TO_WRITE_TO_DISK,
|
||||
"Failed to write to disk. Dump aborted.")
|
||||
MSG_HASH(MSG_NO_DISC_INSERTED,
|
||||
"No disc is inserted in the drive.")
|
||||
|
@ -1377,6 +1377,32 @@ bool cdrom_is_media_inserted(const libretro_vfs_implementation_file *stream)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cdrom_drive_has_media(const char drive)
|
||||
{
|
||||
RFILE *file;
|
||||
char cdrom_path_bin[256];
|
||||
|
||||
cdrom_path_bin[0] = '\0';
|
||||
|
||||
cdrom_device_fillpath(cdrom_path_bin, sizeof(cdrom_path_bin), drive, 1, false);
|
||||
|
||||
file = filestream_open(cdrom_path_bin, RETRO_VFS_FILE_ACCESS_READ, 0);
|
||||
|
||||
if (file)
|
||||
{
|
||||
const libretro_vfs_implementation_file *stream = filestream_get_vfs_handle(file);
|
||||
bool has_media = false;
|
||||
|
||||
has_media = cdrom_is_media_inserted(stream);
|
||||
|
||||
filestream_close(file);
|
||||
|
||||
return has_media;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cdrom_set_read_cache(const libretro_vfs_implementation_file *stream, bool enabled)
|
||||
{
|
||||
/* MMC Command: MODE SENSE (10) and MODE SELECT (10) */
|
||||
|
@ -100,6 +100,8 @@ struct string_list* cdrom_get_available_drives(void);
|
||||
|
||||
bool cdrom_is_media_inserted(const libretro_vfs_implementation_file *stream);
|
||||
|
||||
bool cdrom_drive_has_media(const char drive);
|
||||
|
||||
void cdrom_get_current_config_core(const libretro_vfs_implementation_file *stream);
|
||||
|
||||
void cdrom_get_current_config_profiles(const libretro_vfs_implementation_file *stream);
|
||||
|
@ -2135,7 +2135,19 @@ static int action_ok_load_cdrom(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx)
|
||||
{
|
||||
#ifdef HAVE_CDROM
|
||||
struct retro_system_info *system = runloop_get_libretro_system_info();
|
||||
struct retro_system_info *system;
|
||||
|
||||
if (!cdrom_drive_has_media(label[0]))
|
||||
{
|
||||
runloop_msg_queue_push(
|
||||
msg_hash_to_str(MSG_NO_DISC_INSERTED),
|
||||
1, 100, true,
|
||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
system = runloop_get_libretro_system_info();
|
||||
|
||||
if (system && !string_is_empty(system->library_name))
|
||||
{
|
||||
@ -2173,6 +2185,8 @@ static int action_ok_load_cdrom(const char *path,
|
||||
msg_hash_to_str(MSG_LOAD_CORE_FIRST),
|
||||
1, 100, true,
|
||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
@ -2184,6 +2198,16 @@ static int action_ok_dump_cdrom(const char *path,
|
||||
if (string_is_empty(label))
|
||||
return -1;
|
||||
#ifdef HAVE_CDROM
|
||||
if (!cdrom_drive_has_media(label[0]))
|
||||
{
|
||||
runloop_msg_queue_push(
|
||||
msg_hash_to_str(MSG_NO_DISC_INSERTED),
|
||||
1, 100, true,
|
||||
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
task_push_cdrom_dump(label);
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -2440,6 +2440,7 @@ enum msg_hash_enums
|
||||
MSG_LOAD_CORE_FIRST,
|
||||
MSG_DISC_DUMP_FAILED_TO_READ_FROM_DRIVE,
|
||||
MSG_DISC_DUMP_FAILED_TO_WRITE_TO_DISK,
|
||||
MSG_NO_DISC_INSERTED,
|
||||
|
||||
MSG_LAST
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user