1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
|
/* 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"
#include "retroarch.h"
#include "verbosity.h"
#include "msg_hash.h"
#include "disk_control_interface.h"
#ifdef HAVE_CHEEVOS
#include "cheevos/cheevos.h"
#endif
/*****************/
/* Configuration */
/*****************/
/**
* disk_control_reset_callback:
*
* Sets all disk interface callback functions
* to NULL
**/
static void disk_control_reset_callback(
disk_control_interface_t *disk_control)
{
if (!disk_control)
return;
memset(&disk_control->cb, 0,
sizeof(struct retro_disk_control_ext_callback));
}
/**
* disk_control_set_callback:
*
* Set v0 disk interface callback functions
**/
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;
}
/**
* disk_control_set_ext_callback:
*
* Set v1+ disk interface callback functions
**/
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 */
/**********/
/**
* disk_control_enabled:
*
* Leaf function.
*
* @return true if core supports basic disk control functionality
* - set_eject_state
* - get_eject_state
* - get_image_index
* - set_image_index
* - get_num_images
**/
bool disk_control_enabled(
disk_control_interface_t *disk_control)
{
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)
return true;
return false;
}
/**
* disk_control_append_enabled:
*
* Leaf function.
*
* @return true if core supports disk append functionality
* - replace_image_index
* - add_image_index
**/
bool disk_control_append_enabled(
disk_control_interface_t *disk_control)
{
if ( disk_control
&& disk_control->cb.replace_image_index
&& disk_control->cb.add_image_index)
return true;
return false;
}
/**
* disk_control_image_label_enabled:
*
* Leaf function.
*
* @return true if core supports image labels
* - get_image_label
**/
bool disk_control_image_label_enabled(
disk_control_interface_t *disk_control)
{
return disk_control && disk_control->cb.get_image_label;
}
/**
* disk_control_initial_image_enabled:
*
* Leaf function.
*
* @return true if core supports setting initial disk index
* - set_initial_image
* - get_image_path
**/
bool disk_control_initial_image_enabled(
disk_control_interface_t *disk_control)
{
if ( disk_control
&& disk_control->cb.set_initial_image
&& disk_control->cb.get_image_path)
return true;
return false;
}
/***********/
/* Getters */
/***********/
/**
* disk_control_get_eject_state:
*
* @return true if disk is currently ejected
**/
bool disk_control_get_eject_state(
disk_control_interface_t *disk_control)
{
if (!disk_control || !disk_control->cb.get_eject_state)
return false;
return disk_control->cb.get_eject_state();
}
/**
* disk_control_get_num_images:
*
* @return number of disk images registered by the core
**/
unsigned disk_control_get_num_images(
disk_control_interface_t *disk_control)
{
if (!disk_control || !disk_control->cb.get_num_images)
return 0;
return disk_control->cb.get_num_images();
}
/**
* disk_control_get_image_index:
*
* @return currently selected disk image index
**/
unsigned disk_control_get_image_index(
disk_control_interface_t *disk_control)
{
if (!disk_control || !disk_control->cb.get_image_index)
return 0;
return disk_control->cb.get_image_index();
}
/**
* disk_control_get_image_label:
*
* Fetches core-provided disk image label
* (label is set to an empty string if core
* does not support image labels)
**/
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 */
/***********/
/**
* disk_control_get_index_set_msg:
*
* Generates an appropriate log/notification message
* for a disk index change event
**/
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;
char image_label[128];
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)
{
size_t _len = strlcpy(msg,
success
? msg_hash_to_str(MSG_SETTING_DISK_IN_TRAY)
: msg_hash_to_str(MSG_FAILED_TO_SET_DISK), len);
if (has_label)
snprintf(
msg + _len, len - _len, ": %u/%u - %s",
index + 1, num_images, image_label);
else
snprintf(
msg + _len, len - _len, ": %u/%u",
index + 1, num_images);
}
else
strlcpy(
msg,
success
? msg_hash_to_str(MSG_REMOVED_DISK_FROM_TRAY)
: msg_hash_to_str(MSG_FAILED_TO_REMOVE_DISK_FROM_TRAY),
len);
}
/**
* disk_control_set_eject_state:
*
* Sets the eject state of the virtual disk tray
**/
bool disk_control_set_eject_state(
disk_control_interface_t *disk_control,
bool eject, bool verbosity)
{
bool error = false;
char msg[128];
size_t _len;
if (!disk_control || !disk_control->cb.set_eject_state)
return false;
/* Set eject state */
if (disk_control->cb.set_eject_state(eject))
_len = strlcpy(
msg,
eject
? msg_hash_to_str(MSG_DISK_EJECTED)
: msg_hash_to_str(MSG_DISK_CLOSED),
sizeof(msg));
else
{
error = true;
_len = strlcpy(
msg,
eject
? msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_EJECT)
: msg_hash_to_str(MSG_VIRTUAL_DISK_TRAY_CLOSE),
sizeof(msg));
}
if (_len > 0)
{
if (error)
RARCH_ERR("[Disc]: %s\n", msg);
else
RARCH_LOG("[Disc]: %s\n", msg);
/* Errors should always be displayed */
if (verbosity || error)
runloop_msg_queue_push(
msg, _len, 1, error ? 180 : 60, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
#ifdef HAVE_CHEEVOS
if (!error && !eject)
{
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);
}
}
#endif
return !error;
}
/**
* disk_control_set_index:
*
* Sets currently selected disk index
*
* NOTE: Will fail if disk is not currently ejected
**/
bool disk_control_set_index(
disk_control_interface_t *disk_control,
unsigned index, bool verbosity)
{
bool error = false;
unsigned num_images = 0;
unsigned msg_duration = 0;
char msg[128];
msg[0] = '\0';
if (!disk_control)
return false;
if ( !disk_control->cb.get_eject_state
|| !disk_control->cb.get_num_images
|| !disk_control->cb.set_image_index)
return false;
/* Ensure that disk is currently ejected */
if (!disk_control->cb.get_eject_state())
return false;
/* Get current number of disk images */
num_images = disk_control->cb.get_num_images();
/* Perform 'set index' action */
error = !disk_control->cb.set_image_index(index);
/* Get log/notification message */
disk_control_get_index_set_msg(
disk_control, num_images, index, !error,
&msg_duration, msg, sizeof(msg));
/* Output log/notification message */
if (!string_is_empty(msg))
{
if (error)
RARCH_ERR("[Disc]: %s\n", msg);
else
RARCH_LOG("[Disc]: %s\n", msg);
/* Errors should always be displayed */
if (verbosity || error)
runloop_msg_queue_push(msg, strlen(msg), 1, msg_duration, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
/* If operation was successful, update disk
* index record (if enabled) */
if (!error && disk_control->record_enabled)
{
if ( disk_control->cb.get_image_index
&& disk_control->cb.get_image_path)
{
char new_image_path[PATH_MAX_LENGTH] = {0};
/* Get current image index + path */
unsigned new_image_index = disk_control->cb.get_image_index();
bool image_path_valid = disk_control->cb.get_image_path(
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;
}
/**
* disk_control_set_index_next:
*
* Increments selected disk index
**/
bool disk_control_set_index_next(
disk_control_interface_t *disk_control,
bool verbosity)
{
unsigned num_images = 0;
unsigned image_index = 0;
bool disk_next_enable = false;
if (!disk_control)
return false;
if ( !disk_control->cb.get_num_images
|| !disk_control->cb.get_image_index)
return false;
num_images = disk_control->cb.get_num_images();
image_index = disk_control->cb.get_image_index();
/* 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)
{
RARCH_ERR("[Disc]: %s\n", msg_hash_to_str(MSG_GOT_INVALID_DISK_INDEX));
return false;
}
if (image_index < (num_images - 1))
image_index++;
return disk_control_set_index(disk_control, image_index, verbosity);
}
/**
* disk_control_set_index_prev:
*
* Decrements selected disk index
**/
bool disk_control_set_index_prev(
disk_control_interface_t *disk_control,
bool verbosity)
{
unsigned num_images = 0;
unsigned image_index = 0;
bool disk_prev_enable = false;
if (!disk_control)
return false;
if ( !disk_control->cb.get_num_images
|| !disk_control->cb.get_image_index)
return false;
num_images = disk_control->cb.get_num_images();
image_index = disk_control->cb.get_image_index();
/* 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)
{
RARCH_ERR("[Disc]: %s\n", msg_hash_to_str(MSG_GOT_INVALID_DISK_INDEX));
return false;
}
if (image_index > 0)
image_index--;
return disk_control_set_index(disk_control, image_index, verbosity);
}
/**
* disk_control_append_image:
*
* Appends specified image file to disk image list
**/
bool disk_control_append_image(
disk_control_interface_t *disk_control,
const char *image_path)
{
size_t _len;
bool initial_disk_ejected = false;
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;
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)
return false;
if (string_is_empty(image_path))
return false;
image_filename = path_basename(image_path);
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();
/* If tray is currently closed, eject disk */
if (!initial_disk_ejected &&
!disk_control_set_eject_state(disk_control, true, false))
goto error;
/* Append image */
if (!disk_control->cb.add_image_index())
goto error;
if ((new_index = disk_control->cb.get_num_images()) < 1)
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;
/* 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 */
_len = strlcpy(msg, msg_hash_to_str(MSG_APPENDED_DISK), sizeof(msg));
msg[ _len] = ':';
msg[++_len] = ' ';
msg[++_len] = '\0';
_len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
RARCH_LOG("[Disc]: %s\n", msg);
/* This message should always be displayed, since
* the menu itself does not provide sufficient
* visual feedback */
runloop_msg_queue_push(msg, _len, 0, 120, true, NULL,
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);
if (!initial_disk_ejected)
disk_control_set_eject_state(disk_control, false, false);
_len = strlcpy(msg,
msg_hash_to_str(MSG_FAILED_TO_APPEND_DISK), sizeof(msg));
msg[ _len] = ':';
msg[++_len] = ' ';
msg[++_len] = '\0';
_len += strlcpy(msg + _len, image_filename, sizeof(msg) - _len);
runloop_msg_queue_push(msg, _len, 0, 180, true, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
return false;
}
/*****************************/
/* 'Initial index' functions */
/*****************************/
/**
* disk_control_set_initial_index:
*
* Attempts to set current core's initial disk index.
* > 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
* loading content
**/
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 */
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)
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 */
if ( disk_control->record_enabled
&& (disk_control->index_record.image_index != 0))
{
if ( !disk_control->cb.set_initial_image(
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(
"[Disc]: Failed to set initial disk index: [%u] %s\n",
disk_control->index_record.image_index,
disk_control->index_record.image_path);
return false;
}
}
return true;
error:
disk_control->record_enabled = false;
return false;
}
/**
* disk_control_verify_initial_index:
*
* Checks that initial index has been set correctly
* and provides user notification.
* > Sets disk_control->initial_num_images if
* if functionality is supported by core
* NOTE: Must be called immediately after
* loading content
**/
bool disk_control_verify_initial_index(
disk_control_interface_t *disk_control,
bool verbosity,
bool enabled)
{
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 */
if (!disk_control->record_enabled && enabled)
return false;
/* Check that 'initial index' functionality is enabled */
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)
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) */
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))))
success = true;
}
/* If current disk is incorrect, notify user */
if (!success && enabled)
{
const char *_msg = msg_hash_to_str(MSG_FAILED_TO_SET_INITIAL_DISK);
RARCH_ERR(
"[Disc]: Failed to set initial disc index:\n> Expected"
" [%u] %s\n> Detected [%u] %s\n",
disk_control->index_record.image_index + 1,
disk_control->index_record.image_path,
image_index + 1,
image_path);
/* Ignore 'verbosity' setting - errors should
* always be displayed */
runloop_msg_queue_push(_msg, strlen(_msg), 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);
}
/* 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)
{
unsigned msg_duration = 0;
char msg[128];
msg[0] = '\0';
disk_control_get_index_set_msg(
disk_control, disk_control->initial_num_images, image_index, true,
&msg_duration, msg, sizeof(msg));
RARCH_LOG("[Disc]: %s\n", msg);
/* 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 */
if (verbosity)
runloop_msg_queue_push(
msg, strlen(msg), 0, msg_duration, false, NULL,
MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
#ifdef HAVE_CHEEVOS
if (image_index > 0)
rcheevos_change_disc(disk_control->index_record.image_path, true);
#endif
}
return success;
}
/**
* disk_control_save_image_index:
*
* Saves current disk index to file, if supported
* by current core
**/
bool disk_control_save_image_index(
disk_control_interface_t *disk_control)
{
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);
}
|