2020-01-22 17:07:50 +00:00
|
|
|
/* Copyright (C) 2010-2020 The RetroArch team
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------------------------------------------
|
|
|
|
* The following license statement only applies to this file (disk_control_interface.c).
|
|
|
|
* ---------------------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge,
|
|
|
|
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
|
|
|
|
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
|
|
|
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
|
|
|
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string/stdstring.h>
|
|
|
|
#include <file/file_path.h>
|
|
|
|
|
|
|
|
#include "paths.h"
|
2023-01-08 08:05:46 +00:00
|
|
|
#include "retroarch.h"
|
2020-01-22 17:07:50 +00:00
|
|
|
#include "verbosity.h"
|
|
|
|
#include "msg_hash.h"
|
|
|
|
|
|
|
|
#include "disk_control_interface.h"
|
|
|
|
|
2021-11-25 06:15:37 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
|
|
|
#include "cheevos/cheevos.h"
|
|
|
|
#endif
|
|
|
|
|
2020-01-22 17:07:50 +00:00
|
|
|
/*****************/
|
|
|
|
/* Configuration */
|
|
|
|
/*****************/
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_reset_callback:
|
|
|
|
*
|
|
|
|
* Sets all disk interface callback functions
|
|
|
|
* to NULL
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
static void disk_control_reset_callback(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
|
|
|
if (!disk_control)
|
|
|
|
return;
|
|
|
|
|
2020-05-29 10:46:18 +00:00
|
|
|
memset(&disk_control->cb, 0,
|
|
|
|
sizeof(struct retro_disk_control_ext_callback));
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_callback:
|
|
|
|
*
|
|
|
|
* Set v0 disk interface callback functions
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
void disk_control_set_callback(
|
|
|
|
disk_control_interface_t *disk_control,
|
|
|
|
const struct retro_disk_control_callback *cb)
|
|
|
|
{
|
|
|
|
if (!disk_control)
|
|
|
|
return;
|
|
|
|
|
|
|
|
disk_control_reset_callback(disk_control);
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
disk_control->cb.set_eject_state = cb->set_eject_state;
|
|
|
|
disk_control->cb.get_eject_state = cb->get_eject_state;
|
|
|
|
disk_control->cb.get_image_index = cb->get_image_index;
|
|
|
|
disk_control->cb.set_image_index = cb->set_image_index;
|
|
|
|
disk_control->cb.get_num_images = cb->get_num_images;
|
|
|
|
disk_control->cb.replace_image_index = cb->replace_image_index;
|
|
|
|
disk_control->cb.add_image_index = cb->add_image_index;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_ext_callback:
|
|
|
|
*
|
|
|
|
* Set v1+ disk interface callback functions
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
void disk_control_set_ext_callback(
|
|
|
|
disk_control_interface_t *disk_control,
|
|
|
|
const struct retro_disk_control_ext_callback *cb)
|
|
|
|
{
|
|
|
|
if (!disk_control)
|
|
|
|
return;
|
|
|
|
|
|
|
|
disk_control_reset_callback(disk_control);
|
|
|
|
|
|
|
|
if (!cb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
disk_control->cb.set_eject_state = cb->set_eject_state;
|
|
|
|
disk_control->cb.get_eject_state = cb->get_eject_state;
|
|
|
|
disk_control->cb.get_image_index = cb->get_image_index;
|
|
|
|
disk_control->cb.set_image_index = cb->set_image_index;
|
|
|
|
disk_control->cb.get_num_images = cb->get_num_images;
|
|
|
|
disk_control->cb.replace_image_index = cb->replace_image_index;
|
|
|
|
disk_control->cb.add_image_index = cb->add_image_index;
|
|
|
|
|
|
|
|
disk_control->cb.set_initial_image = cb->set_initial_image;
|
|
|
|
disk_control->cb.get_image_path = cb->get_image_path;
|
|
|
|
disk_control->cb.get_image_label = cb->get_image_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**********/
|
|
|
|
/* Status */
|
|
|
|
/**********/
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_enabled:
|
|
|
|
*
|
|
|
|
* Leaf function.
|
|
|
|
*
|
|
|
|
* @return true if core supports basic disk control functionality
|
2020-01-22 17:07:50 +00:00
|
|
|
* - set_eject_state
|
|
|
|
* - get_eject_state
|
|
|
|
* - get_image_index
|
|
|
|
* - set_image_index
|
2022-08-01 13:46:08 +00:00
|
|
|
* - get_num_images
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_enabled(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( disk_control
|
|
|
|
&& disk_control->cb.set_eject_state
|
|
|
|
&& disk_control->cb.get_eject_state
|
|
|
|
&& disk_control->cb.get_image_index
|
|
|
|
&& disk_control->cb.set_image_index
|
|
|
|
&& disk_control->cb.get_num_images)
|
2020-01-22 17:07:50 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_append_enabled:
|
|
|
|
*
|
|
|
|
* Leaf function.
|
|
|
|
*
|
|
|
|
* @return true if core supports disk append functionality
|
2020-01-22 17:07:50 +00:00
|
|
|
* - replace_image_index
|
2022-08-01 13:46:08 +00:00
|
|
|
* - add_image_index
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_append_enabled(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2022-08-01 13:46:08 +00:00
|
|
|
if ( disk_control
|
2023-08-15 23:14:50 +00:00
|
|
|
&& disk_control->cb.replace_image_index
|
2022-08-01 13:46:08 +00:00
|
|
|
&& disk_control->cb.add_image_index)
|
2020-01-22 17:07:50 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_image_label_enabled:
|
|
|
|
*
|
|
|
|
* Leaf function.
|
|
|
|
*
|
2023-08-15 23:14:50 +00:00
|
|
|
* @return true if core supports image labels
|
2022-08-01 13:46:08 +00:00
|
|
|
* - get_image_label
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_image_label_enabled(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2022-08-01 13:46:08 +00:00
|
|
|
return disk_control && disk_control->cb.get_image_label;
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_initial_image_enabled:
|
|
|
|
*
|
|
|
|
* Leaf function.
|
|
|
|
*
|
|
|
|
* @return true if core supports setting initial disk index
|
2020-01-22 17:07:50 +00:00
|
|
|
* - set_initial_image
|
2022-08-01 13:46:08 +00:00
|
|
|
* - get_image_path
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_initial_image_enabled(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( disk_control
|
2022-08-01 13:46:08 +00:00
|
|
|
&& disk_control->cb.set_initial_image
|
|
|
|
&& disk_control->cb.get_image_path)
|
2020-01-22 17:07:50 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
/* Getters */
|
|
|
|
/***********/
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_get_eject_state:
|
|
|
|
*
|
|
|
|
* @return true if disk is currently ejected
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_get_eject_state(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2020-02-23 05:34:41 +00:00
|
|
|
if (!disk_control || !disk_control->cb.get_eject_state)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
return disk_control->cb.get_eject_state();
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_get_num_images:
|
|
|
|
*
|
|
|
|
* @return number of disk images registered by the core
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
unsigned disk_control_get_num_images(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2020-02-23 05:34:41 +00:00
|
|
|
if (!disk_control || !disk_control->cb.get_num_images)
|
2020-01-22 17:07:50 +00:00
|
|
|
return 0;
|
|
|
|
return disk_control->cb.get_num_images();
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_get_image_index:
|
|
|
|
*
|
|
|
|
* @return currently selected disk image index
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
unsigned disk_control_get_image_index(
|
|
|
|
disk_control_interface_t *disk_control)
|
|
|
|
{
|
2020-02-23 05:34:41 +00:00
|
|
|
if (!disk_control || !disk_control->cb.get_image_index)
|
2020-01-22 17:07:50 +00:00
|
|
|
return 0;
|
|
|
|
return disk_control->cb.get_image_index();
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_get_image_label:
|
|
|
|
*
|
|
|
|
* Fetches core-provided disk image label
|
2020-01-22 17:07:50 +00:00
|
|
|
* (label is set to an empty string if core
|
2022-08-01 13:46:08 +00:00
|
|
|
* does not support image labels)
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
void disk_control_get_image_label(
|
|
|
|
disk_control_interface_t *disk_control,
|
|
|
|
unsigned index, char *label, size_t len)
|
|
|
|
{
|
|
|
|
if (!label || len < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!disk_control)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!disk_control->cb.get_image_label)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!disk_control->cb.get_image_label(index, label, len))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
error:
|
|
|
|
label[0] = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********/
|
|
|
|
/* Setters */
|
|
|
|
/***********/
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_get_index_set_msg:
|
|
|
|
*
|
|
|
|
* Generates an appropriate log/notification message
|
|
|
|
* for a disk index change event
|
|
|
|
**/
|
2020-02-04 15:45:00 +00:00
|
|
|
static void disk_control_get_index_set_msg(
|
|
|
|
disk_control_interface_t *disk_control,
|
|
|
|
unsigned num_images, unsigned index, bool success,
|
|
|
|
unsigned *msg_duration, char *msg, size_t len)
|
|
|
|
{
|
|
|
|
bool has_label = false;
|
2020-05-23 01:11:35 +00:00
|
|
|
char image_label[128];
|
2020-02-04 15:45:00 +00:00
|
|
|
|
|
|
|
image_label[0] = '\0';
|
|
|
|
|
|
|
|
if (!disk_control || !msg_duration || !msg || len < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Attempt to get image label */
|
|
|
|
if (index < num_images)
|
|
|
|
{
|
|
|
|
disk_control_get_image_label(
|
|
|
|
disk_control, index, image_label, sizeof(image_label));
|
|
|
|
has_label = !string_is_empty(image_label);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get message duration
|
|
|
|
* > Default is 60
|
|
|
|
* > If a label is shown, then increase duration by 50%
|
|
|
|
* > For errors, duration is always 180 */
|
|
|
|
*msg_duration = success ?
|
|
|
|
(has_label ? 90 : 60) :
|
|
|
|
180;
|
|
|
|
|
|
|
|
/* Check whether image was inserted or removed */
|
|
|
|
if (index < num_images)
|
|
|
|
{
|
2022-09-01 02:17:07 +00:00
|
|
|
size_t _len = strlcpy(msg,
|
2023-08-15 23:14:50 +00:00
|
|
|
success
|
2022-09-01 02:17:07 +00:00
|
|
|
? msg_hash_to_str(MSG_SETTING_DISK_IN_TRAY)
|
|
|
|
: msg_hash_to_str(MSG_FAILED_TO_SET_DISK), len);
|
2020-02-04 15:45:00 +00:00
|
|
|
if (has_label)
|
|
|
|
snprintf(
|
2022-09-01 02:17:07 +00:00
|
|
|
msg + _len, len - _len, ": %u/%u - %s",
|
2020-02-04 15:45:00 +00:00
|
|
|
index + 1, num_images, image_label);
|
|
|
|
else
|
|
|
|
snprintf(
|
2022-09-01 02:17:07 +00:00
|
|
|
msg + _len, len - _len, ": %u/%u",
|
2020-02-04 15:45:00 +00:00
|
|
|
index + 1, num_images);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
strlcpy(
|
|
|
|
msg,
|
2023-08-15 23:14:50 +00:00
|
|
|
success
|
2022-09-01 02:17:07 +00:00
|
|
|
? msg_hash_to_str(MSG_REMOVED_DISK_FROM_TRAY)
|
|
|
|
: msg_hash_to_str(MSG_FAILED_TO_REMOVE_DISK_FROM_TRAY),
|
2020-02-04 15:45:00 +00:00
|
|
|
len);
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_eject_state:
|
|
|
|
*
|
|
|
|
* Sets the eject state of the virtual disk tray
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_set_eject_state(
|
|
|
|
disk_control_interface_t *disk_control,
|
2020-03-05 17:29:48 +00:00
|
|
|
bool eject, bool verbosity)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
|
|
|
bool error = false;
|
|
|
|
char msg[128];
|
|
|
|
|
|
|
|
msg[0] = '\0';
|
|
|
|
|
2020-02-23 05:34:41 +00:00
|
|
|
if (!disk_control || !disk_control->cb.set_eject_state)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Set eject state */
|
|
|
|
if (disk_control->cb.set_eject_state(eject))
|
2022-09-01 02:17:07 +00:00
|
|
|
strlcpy(
|
|
|
|
msg,
|
2023-08-15 23:14:50 +00:00
|
|
|
eject
|
2022-09-01 02:17:07 +00:00
|
|
|
? msg_hash_to_str(MSG_DISK_EJECTED)
|
|
|
|
: msg_hash_to_str(MSG_DISK_CLOSED),
|
|
|
|
sizeof(msg));
|
2020-01-22 17:07:50 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
error = true;
|
2022-09-01 02:17:07 +00:00
|
|
|
strlcpy(
|
|
|
|
msg,
|
2023-08-15 23:14:50 +00:00
|
|
|
eject
|
2022-09-01 02:17:07 +00:00
|
|
|
? msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_EJECT)
|
|
|
|
: msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_CLOSE),
|
|
|
|
sizeof(msg));
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!string_is_empty(msg))
|
|
|
|
{
|
|
|
|
if (error)
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_ERR("[Disc]: %s\n", msg);
|
2020-01-22 17:07:50 +00:00
|
|
|
else
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_LOG("[Disc]: %s\n", msg);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
|
|
|
/* Errors should always be displayed */
|
2020-03-05 17:29:48 +00:00
|
|
|
if (verbosity || error)
|
2020-01-22 17:07:50 +00:00
|
|
|
runloop_msg_queue_push(
|
|
|
|
msg, 1, error ? 180 : 60,
|
|
|
|
true, NULL,
|
|
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
|
|
}
|
|
|
|
|
2021-11-25 06:15:37 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
|
|
|
if (!error && !eject)
|
2022-05-04 02:46:47 +00:00
|
|
|
{
|
|
|
|
if (disk_control->cb.get_image_index && disk_control->cb.get_image_path)
|
|
|
|
{
|
|
|
|
char image_path[PATH_MAX_LENGTH] = "";
|
|
|
|
unsigned image_index = disk_control->cb.get_image_index();
|
|
|
|
|
|
|
|
if (disk_control->cb.get_image_path(image_index, image_path, sizeof(image_path)))
|
|
|
|
rcheevos_change_disc(image_path, false);
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 06:15:37 +00:00
|
|
|
#endif
|
|
|
|
|
2020-01-22 17:07:50 +00:00
|
|
|
return !error;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_index:
|
|
|
|
*
|
|
|
|
* Sets currently selected disk index
|
|
|
|
*
|
|
|
|
* NOTE: Will fail if disk is not currently ejected
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_set_index(
|
|
|
|
disk_control_interface_t *disk_control,
|
2020-03-05 17:29:48 +00:00
|
|
|
unsigned index, bool verbosity)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
2020-02-04 15:45:00 +00:00
|
|
|
bool error = false;
|
|
|
|
unsigned num_images = 0;
|
|
|
|
unsigned msg_duration = 0;
|
2024-09-09 14:18:32 +00:00
|
|
|
char msg[128];
|
2020-01-22 17:07:50 +00:00
|
|
|
|
|
|
|
msg[0] = '\0';
|
|
|
|
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.get_eject_state
|
|
|
|
|| !disk_control->cb.get_num_images
|
|
|
|
|| !disk_control->cb.set_image_index)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Ensure that disk is currently ejected */
|
|
|
|
if (!disk_control->cb.get_eject_state())
|
|
|
|
return false;
|
|
|
|
|
2020-02-04 15:45:00 +00:00
|
|
|
/* Get current number of disk images */
|
2020-01-22 17:07:50 +00:00
|
|
|
num_images = disk_control->cb.get_num_images();
|
|
|
|
|
2020-02-04 15:45:00 +00:00
|
|
|
/* Perform 'set index' action */
|
|
|
|
error = !disk_control->cb.set_image_index(index);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2020-02-04 15:45:00 +00:00
|
|
|
/* Get log/notification message */
|
|
|
|
disk_control_get_index_set_msg(
|
|
|
|
disk_control, num_images, index, !error,
|
|
|
|
&msg_duration, msg, sizeof(msg));
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2020-02-04 15:45:00 +00:00
|
|
|
/* Output log/notification message */
|
2020-01-22 17:07:50 +00:00
|
|
|
if (!string_is_empty(msg))
|
|
|
|
{
|
|
|
|
if (error)
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_ERR("[Disc]: %s\n", msg);
|
2020-01-22 17:07:50 +00:00
|
|
|
else
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_LOG("[Disc]: %s\n", msg);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
|
|
|
/* Errors should always be displayed */
|
2020-03-05 17:29:48 +00:00
|
|
|
if (verbosity || error)
|
2020-01-22 17:07:50 +00:00
|
|
|
runloop_msg_queue_push(
|
2020-02-04 15:45:00 +00:00
|
|
|
msg, 1, msg_duration,
|
2020-01-22 17:07:50 +00:00
|
|
|
true, NULL,
|
2021-11-09 22:12:57 +00:00
|
|
|
MESSAGE_QUEUE_ICON_DEFAULT,
|
|
|
|
MESSAGE_QUEUE_CATEGORY_INFO);
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If operation was successful, update disk
|
|
|
|
* index record (if enabled) */
|
|
|
|
if (!error && disk_control->record_enabled)
|
|
|
|
{
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( disk_control->cb.get_image_index
|
|
|
|
&& disk_control->cb.get_image_path)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
2022-09-01 02:17:07 +00:00
|
|
|
char new_image_path[PATH_MAX_LENGTH] = {0};
|
2020-01-22 17:07:50 +00:00
|
|
|
/* Get current image index + path */
|
2022-09-01 02:17:07 +00:00
|
|
|
unsigned new_image_index = disk_control->cb.get_image_index();
|
|
|
|
bool image_path_valid = disk_control->cb.get_image_path(
|
2020-01-22 17:07:50 +00:00
|
|
|
new_image_index, new_image_path, sizeof(new_image_path));
|
|
|
|
|
|
|
|
if (image_path_valid)
|
|
|
|
disk_index_file_set(
|
|
|
|
&disk_control->index_record,
|
|
|
|
new_image_index, new_image_path);
|
|
|
|
else
|
|
|
|
disk_index_file_set(
|
|
|
|
&disk_control->index_record, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return !error;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_index_next:
|
|
|
|
*
|
|
|
|
* Increments selected disk index
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_set_index_next(
|
|
|
|
disk_control_interface_t *disk_control,
|
2020-03-05 17:29:48 +00:00
|
|
|
bool verbosity)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
|
|
|
unsigned num_images = 0;
|
|
|
|
unsigned image_index = 0;
|
|
|
|
bool disk_next_enable = false;
|
|
|
|
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.get_num_images
|
|
|
|
|| !disk_control->cb.get_image_index)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
num_images = disk_control->cb.get_num_images();
|
|
|
|
image_index = disk_control->cb.get_image_index();
|
2022-08-01 13:46:08 +00:00
|
|
|
|
2020-01-22 17:07:50 +00:00
|
|
|
/* Would seem more sensible to check (num_images > 1)
|
|
|
|
* here, but seems we need to be able to cycle the
|
|
|
|
* same image for legacy reasons... */
|
|
|
|
disk_next_enable = (num_images > 0) && (num_images != UINT_MAX);
|
|
|
|
|
|
|
|
if (!disk_next_enable)
|
|
|
|
{
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_ERR("[Disc]: %s\n", msg_hash_to_str(MSG_GOT_INVALID_DISK_INDEX));
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image_index < (num_images - 1))
|
|
|
|
image_index++;
|
|
|
|
|
2020-03-05 17:29:48 +00:00
|
|
|
return disk_control_set_index(disk_control, image_index, verbosity);
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_index_prev:
|
|
|
|
*
|
|
|
|
* Decrements selected disk index
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_set_index_prev(
|
|
|
|
disk_control_interface_t *disk_control,
|
2020-03-05 17:29:48 +00:00
|
|
|
bool verbosity)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
|
|
|
unsigned num_images = 0;
|
|
|
|
unsigned image_index = 0;
|
|
|
|
bool disk_prev_enable = false;
|
|
|
|
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.get_num_images
|
|
|
|
|| !disk_control->cb.get_image_index)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
num_images = disk_control->cb.get_num_images();
|
|
|
|
image_index = disk_control->cb.get_image_index();
|
2020-01-22 17:07:50 +00:00
|
|
|
/* Would seem more sensible to check (num_images > 1)
|
|
|
|
* here, but seems we need to be able to cycle the
|
|
|
|
* same image for legacy reasons... */
|
|
|
|
disk_prev_enable = (num_images > 0);
|
|
|
|
|
|
|
|
if (!disk_prev_enable)
|
|
|
|
{
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_ERR("[Disc]: %s\n", msg_hash_to_str(MSG_GOT_INVALID_DISK_INDEX));
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (image_index > 0)
|
|
|
|
image_index--;
|
|
|
|
|
2020-03-05 17:29:48 +00:00
|
|
|
return disk_control_set_index(disk_control, image_index, verbosity);
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_append_image:
|
|
|
|
*
|
|
|
|
* Appends specified image file to disk image list
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_append_image(
|
|
|
|
disk_control_interface_t *disk_control,
|
|
|
|
const char *image_path)
|
|
|
|
{
|
2022-09-01 02:17:07 +00:00
|
|
|
size_t _len;
|
2020-06-17 10:41:50 +00:00
|
|
|
bool initial_disk_ejected = false;
|
2020-01-22 17:07:50 +00:00
|
|
|
unsigned initial_index = 0;
|
|
|
|
unsigned new_index = 0;
|
|
|
|
const char *image_filename = NULL;
|
|
|
|
struct retro_game_info info = {0};
|
|
|
|
char msg[128];
|
|
|
|
|
|
|
|
/* Sanity check. If any of these fail then a
|
|
|
|
* frontend error has occurred - we will not
|
|
|
|
* deal with that here */
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.get_image_index
|
|
|
|
|| !disk_control->cb.get_num_images
|
|
|
|
|| !disk_control->cb.add_image_index
|
|
|
|
|| !disk_control->cb.replace_image_index
|
|
|
|
|| !disk_control->cb.get_eject_state)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (string_is_empty(image_path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
image_filename = path_basename(image_path);
|
|
|
|
|
|
|
|
if (string_is_empty(image_filename))
|
|
|
|
return false;
|
|
|
|
|
2020-06-17 10:41:50 +00:00
|
|
|
/* Get initial disk eject state */
|
|
|
|
initial_disk_ejected = disk_control_get_eject_state(disk_control);
|
|
|
|
|
2020-01-22 17:07:50 +00:00
|
|
|
/* Cache initial image index */
|
2022-08-01 13:46:08 +00:00
|
|
|
initial_index = disk_control->cb.get_image_index();
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2020-06-17 10:41:50 +00:00
|
|
|
/* If tray is currently closed, eject disk */
|
|
|
|
if (!initial_disk_ejected &&
|
|
|
|
!disk_control_set_eject_state(disk_control, true, false))
|
2020-01-22 17:07:50 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Append image */
|
|
|
|
if (!disk_control->cb.add_image_index())
|
|
|
|
goto error;
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
if ((new_index = disk_control->cb.get_num_images()) < 1)
|
2020-01-22 17:07:50 +00:00
|
|
|
goto error;
|
|
|
|
new_index--;
|
|
|
|
|
|
|
|
info.path = image_path;
|
|
|
|
if (!disk_control->cb.replace_image_index(new_index, &info))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Set new index */
|
|
|
|
if (!disk_control_set_index(disk_control, new_index, false))
|
|
|
|
goto error;
|
|
|
|
|
2020-06-17 10:41:50 +00:00
|
|
|
/* If tray was initially closed, insert disk
|
|
|
|
* (i.e. leave system in the state we found it) */
|
2022-08-01 13:46:08 +00:00
|
|
|
if ( !initial_disk_ejected
|
|
|
|
&& !disk_control_set_eject_state(disk_control, false, false))
|
2020-01-22 17:07:50 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Display log */
|
2022-09-01 02:17:07 +00:00
|
|
|
_len = strlcpy(msg, msg_hash_to_str(MSG_APPENDED_DISK), sizeof(msg));
|
2023-06-20 14:33:55 +00:00
|
|
|
msg[ _len] = ':';
|
|
|
|
msg[++_len] = ' ';
|
|
|
|
msg[++_len] = '\0';
|
|
|
|
strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_LOG("[Disc]: %s\n", msg);
|
2020-01-22 17:07:50 +00:00
|
|
|
/* This message should always be displayed, since
|
|
|
|
* the menu itself does not provide sufficient
|
|
|
|
* visual feedback */
|
2022-09-01 02:17:07 +00:00
|
|
|
runloop_msg_queue_push(msg, 0, 120, true, NULL,
|
2020-01-22 17:07:50 +00:00
|
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
/* If we reach this point then everything is
|
|
|
|
* broken and the disk control interface is
|
|
|
|
* in an undefined state. Try to restore some
|
|
|
|
* sanity by reinserting the original disk...
|
|
|
|
* NOTE: If this fails then it's game over -
|
|
|
|
* just display the error notification and
|
|
|
|
* hope for the best... */
|
|
|
|
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);
|
2020-06-17 10:41:50 +00:00
|
|
|
if (!initial_disk_ejected)
|
|
|
|
disk_control_set_eject_state(disk_control, false, false);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2022-09-01 02:17:07 +00:00
|
|
|
_len = strlcpy(msg,
|
|
|
|
msg_hash_to_str(MSG_FAILED_TO_APPEND_DISK), sizeof(msg));
|
2023-06-20 14:33:55 +00:00
|
|
|
msg[ _len] = ':';
|
|
|
|
msg[++_len] = ' ';
|
|
|
|
msg[++_len] = '\0';
|
|
|
|
strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
|
|
|
runloop_msg_queue_push(
|
|
|
|
msg, 0, 180,
|
|
|
|
true, NULL,
|
|
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*****************************/
|
|
|
|
/* 'Initial index' functions */
|
|
|
|
/*****************************/
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_set_initial_index:
|
|
|
|
*
|
|
|
|
* Attempts to set current core's initial disk index.
|
2020-01-22 17:07:50 +00:00
|
|
|
* > disk_control->record_enabled will be set to
|
|
|
|
* 'false' if core does not support initial
|
|
|
|
* index functionality
|
|
|
|
* > disk_control->index_record will be loaded
|
|
|
|
* from file (if an existing record is found)
|
|
|
|
* NOTE: Must be called immediately before
|
2022-08-01 13:46:08 +00:00
|
|
|
* loading content
|
|
|
|
**/
|
2020-01-22 17:07:50 +00:00
|
|
|
bool disk_control_set_initial_index(
|
|
|
|
disk_control_interface_t *disk_control,
|
|
|
|
const char *content_path,
|
|
|
|
const char *dir_savefile)
|
|
|
|
{
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (string_is_empty(content_path))
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Check that 'initial index' functionality is enabled */
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.set_initial_image
|
|
|
|
|| !disk_control->cb.get_num_images
|
|
|
|
|| !disk_control->cb.get_image_index
|
|
|
|
|| !disk_control->cb.get_image_path)
|
2020-01-22 17:07:50 +00:00
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* Attempt to initialise disk index record (reading
|
|
|
|
* from disk, if file exists) */
|
|
|
|
disk_control->record_enabled = disk_index_file_init(
|
|
|
|
&disk_control->index_record,
|
|
|
|
content_path, dir_savefile);
|
|
|
|
|
|
|
|
/* If record is enabled and initial index is *not*
|
|
|
|
* zero, notify current core */
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( disk_control->record_enabled
|
|
|
|
&& (disk_control->index_record.image_index != 0))
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.set_initial_image(
|
2020-01-22 17:07:50 +00:00
|
|
|
disk_control->index_record.image_index,
|
|
|
|
disk_control->index_record.image_path))
|
|
|
|
{
|
|
|
|
/* Note: We don't bother with an on-screen
|
|
|
|
* notification at this stage, since an error
|
|
|
|
* here may not matter (have to wait until
|
|
|
|
* disk index is verified) */
|
|
|
|
RARCH_ERR(
|
2021-12-17 17:04:24 +00:00
|
|
|
"[Disc]: Failed to set initial disk index: [%u] %s\n",
|
2020-01-22 17:07:50 +00:00
|
|
|
disk_control->index_record.image_index,
|
|
|
|
disk_control->index_record.image_path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
disk_control->record_enabled = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_verify_initial_index:
|
|
|
|
*
|
|
|
|
* Checks that initial index has been set correctly
|
2020-01-22 17:07:50 +00:00
|
|
|
* and provides user notification.
|
|
|
|
* > Sets disk_control->initial_num_images if
|
|
|
|
* if functionality is supported by core
|
|
|
|
* NOTE: Must be called immediately after
|
2022-08-01 13:46:08 +00:00
|
|
|
* loading content
|
|
|
|
**/
|
2020-07-17 11:50:28 +00:00
|
|
|
bool disk_control_verify_initial_index(
|
|
|
|
disk_control_interface_t *disk_control,
|
2024-02-04 19:58:16 +00:00
|
|
|
bool verbosity,
|
|
|
|
bool enabled)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
|
|
|
bool success = false;
|
|
|
|
unsigned image_index = 0;
|
|
|
|
char image_path[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
image_path[0] = '\0';
|
|
|
|
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If index record is disabled, can return immediately */
|
2024-02-04 19:58:16 +00:00
|
|
|
if (!disk_control->record_enabled && enabled)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Check that 'initial index' functionality is enabled */
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( !disk_control->cb.set_initial_image
|
|
|
|
|| !disk_control->cb.get_num_images
|
|
|
|
|| !disk_control->cb.get_image_index
|
|
|
|
|| !disk_control->cb.get_image_path)
|
2020-01-22 17:07:50 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Cache initial number of images
|
|
|
|
* (required for error checking when saving
|
|
|
|
* disk index file) */
|
|
|
|
disk_control->initial_num_images =
|
|
|
|
disk_control->cb.get_num_images();
|
|
|
|
|
|
|
|
/* Get current image index + path */
|
|
|
|
image_index = disk_control->cb.get_image_index();
|
|
|
|
|
|
|
|
if (disk_control->cb.get_image_path(
|
|
|
|
image_index, image_path, sizeof(image_path)))
|
|
|
|
{
|
|
|
|
/* Check whether index + path match set
|
|
|
|
* values
|
|
|
|
* > Note that if set index was zero and
|
|
|
|
* set path was empty, we ignore the path
|
|
|
|
* read here (since this corresponds to a
|
|
|
|
* 'first run', where no existing disk index
|
|
|
|
* file was present) */
|
2023-08-15 23:14:50 +00:00
|
|
|
if ( (image_index == disk_control->index_record.image_index)
|
|
|
|
&& (string_is_equal(image_path, disk_control->index_record.image_path)
|
|
|
|
|| ((disk_control->index_record.image_index == 0)
|
|
|
|
&& string_is_empty(disk_control->index_record.image_path))))
|
2020-01-22 17:07:50 +00:00
|
|
|
success = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If current disk is incorrect, notify user */
|
2024-02-04 19:58:16 +00:00
|
|
|
if (!success && enabled)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR(
|
2024-02-04 19:58:16 +00:00
|
|
|
"[Disc]: Failed to set initial disc index:\n> Expected"
|
2022-08-01 13:46:08 +00:00
|
|
|
" [%u] %s\n> Detected [%u] %s\n",
|
2020-01-22 17:07:50 +00:00
|
|
|
disk_control->index_record.image_index + 1,
|
|
|
|
disk_control->index_record.image_path,
|
|
|
|
image_index + 1,
|
|
|
|
image_path);
|
|
|
|
|
2020-07-17 11:50:28 +00:00
|
|
|
/* Ignore 'verbosity' setting - errors should
|
|
|
|
* always be displayed */
|
2020-01-22 17:07:50 +00:00
|
|
|
runloop_msg_queue_push(
|
|
|
|
msg_hash_to_str(MSG_FAILED_TO_SET_INITIAL_DISK),
|
|
|
|
0, 60,
|
|
|
|
true, NULL,
|
|
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
|
|
|
|
|
|
|
/* Since a failure here typically means that the
|
|
|
|
* original M3U content file has been altered,
|
|
|
|
* any existing disk index record file will be
|
|
|
|
* invalid. We therefore 'reset' and save the disk
|
|
|
|
* index record to prevent a repeat of the error on
|
|
|
|
* the next run */
|
|
|
|
disk_index_file_set(&disk_control->index_record, 0, NULL);
|
|
|
|
disk_index_file_save(&disk_control->index_record);
|
|
|
|
}
|
2024-02-04 19:58:16 +00:00
|
|
|
|
2020-01-22 17:07:50 +00:00
|
|
|
/* If current disk is correct and recorded image
|
|
|
|
* path is empty (i.e. first run), need to register
|
|
|
|
* current image path */
|
|
|
|
else if (string_is_empty(disk_control->index_record.image_path))
|
|
|
|
disk_index_file_set(
|
|
|
|
&disk_control->index_record, image_index, image_path);
|
|
|
|
|
|
|
|
/* Regardless of success/failure, notify user of
|
|
|
|
* current disk index *if* more than one disk
|
|
|
|
* is available */
|
|
|
|
if (disk_control->initial_num_images > 1)
|
|
|
|
{
|
2020-02-04 15:45:00 +00:00
|
|
|
unsigned msg_duration = 0;
|
2024-09-09 14:18:32 +00:00
|
|
|
char msg[128];
|
2020-01-22 17:07:50 +00:00
|
|
|
|
|
|
|
msg[0] = '\0';
|
|
|
|
|
2020-02-04 15:45:00 +00:00
|
|
|
disk_control_get_index_set_msg(
|
|
|
|
disk_control, disk_control->initial_num_images, image_index, true,
|
|
|
|
&msg_duration, msg, sizeof(msg));
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2021-12-17 17:04:24 +00:00
|
|
|
RARCH_LOG("[Disc]: %s\n", msg);
|
2020-01-22 17:07:50 +00:00
|
|
|
|
2020-03-05 12:23:14 +00:00
|
|
|
/* Note: Do not flush message queue here, since
|
|
|
|
* it is likely other notifications will be
|
|
|
|
* generated before setting the disk index, and
|
|
|
|
* we do not want to 'overwrite' them */
|
2020-07-17 11:50:28 +00:00
|
|
|
if (verbosity)
|
|
|
|
runloop_msg_queue_push(
|
|
|
|
msg,
|
|
|
|
0, msg_duration,
|
|
|
|
false, NULL,
|
|
|
|
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
|
2021-11-25 06:15:37 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CHEEVOS
|
|
|
|
if (image_index > 0)
|
|
|
|
rcheevos_change_disc(disk_control->index_record.image_path, true);
|
|
|
|
#endif
|
2020-01-22 17:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
2022-08-01 13:46:08 +00:00
|
|
|
/**
|
|
|
|
* disk_control_save_image_index:
|
|
|
|
*
|
|
|
|
* Saves current disk index to file, if supported
|
|
|
|
* by current core
|
|
|
|
**/
|
2020-07-17 11:50:28 +00:00
|
|
|
bool disk_control_save_image_index(
|
|
|
|
disk_control_interface_t *disk_control)
|
2020-01-22 17:07:50 +00:00
|
|
|
{
|
|
|
|
if (!disk_control)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If index record is disabled, can return immediately */
|
|
|
|
if (!disk_control->record_enabled)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If core started with less than two disks,
|
|
|
|
* then a disk index record is unnecessary */
|
|
|
|
if (disk_control->initial_num_images < 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* If current index is greater than initial
|
|
|
|
* number of disks then user has appended a
|
|
|
|
* disk and it is currently active. This setup
|
|
|
|
* *cannot* be restored, so cancel the file save */
|
|
|
|
if (disk_control->index_record.image_index >=
|
|
|
|
disk_control->initial_num_images)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Save record */
|
|
|
|
return disk_index_file_save(&disk_control->index_record);
|
|
|
|
}
|