core_backup.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* RetroArch - A frontend for libretro.
  2. * Copyright (C) 2011-2017 - Daniel De Matteis
  3. * Copyright (C) 2014-2017 - Jean-André Santoni
  4. * Copyright (C) 2016-2019 - Brad Parker
  5. * Copyright (C) 2019-2020 - James Leaver
  6. *
  7. * RetroArch is free software: you can redistribute it and/or modify it under the terms
  8. * of the GNU General Public License as published by the Free Software Found-
  9. * ation, either version 3 of the License, or (at your option) any later version.
  10. *
  11. * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  12. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  13. * PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with RetroArch.
  16. * If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef __CORE_BACKUP_H
  19. #define __CORE_BACKUP_H
  20. #include <retro_common_api.h>
  21. #include <libretro.h>
  22. #include <boolean.h>
  23. RETRO_BEGIN_DECLS
  24. /* Defines the various types of supported core backup
  25. * file. Allows us to handle manual core installs
  26. * (via downloaded/compiled dynamic libraries dropped
  27. * in the 'downloads' folder) using the same task
  28. * interface as 'managed'/archived backups */
  29. enum core_backup_type
  30. {
  31. CORE_BACKUP_TYPE_INVALID = 0,
  32. CORE_BACKUP_TYPE_ARCHIVE,
  33. CORE_BACKUP_TYPE_LIB
  34. };
  35. /* Used to distinguish manual and automatic
  36. * core backups */
  37. enum core_backup_mode
  38. {
  39. CORE_BACKUP_MODE_MANUAL = 0,
  40. CORE_BACKUP_MODE_AUTO
  41. };
  42. /* Note: These must be kept synchronised with
  43. * 'enum menu_timedate_date_separator_type' in
  44. * 'menu_defines.h' */
  45. enum core_backup_date_separator_type
  46. {
  47. CORE_BACKUP_DATE_SEPARATOR_HYPHEN = 0,
  48. CORE_BACKUP_DATE_SEPARATOR_SLASH,
  49. CORE_BACKUP_DATE_SEPARATOR_PERIOD,
  50. CORE_BACKUP_DATE_SEPARATOR_LAST
  51. };
  52. /* Holds all timestamp info for a core backup file */
  53. typedef struct
  54. {
  55. unsigned year;
  56. unsigned month;
  57. unsigned day;
  58. unsigned hour;
  59. unsigned minute;
  60. unsigned second;
  61. } core_backup_list_date_t;
  62. /* Holds all info related to a core backup file */
  63. typedef struct
  64. {
  65. char *backup_path;
  66. core_backup_list_date_t date; /* unsigned alignment */
  67. uint32_t crc;
  68. enum core_backup_mode backup_mode;
  69. } core_backup_list_entry_t;
  70. /* Prevent direct access to core_backup_list_t
  71. * members */
  72. typedef struct core_backup_list core_backup_list_t;
  73. /*********************/
  74. /* Utility Functions */
  75. /*********************/
  76. /* Generates a timestamped core backup file path from
  77. * the specified core path. Returns true if successful */
  78. bool core_backup_get_backup_path(
  79. const char *core_path, uint32_t crc, enum core_backup_mode backup_mode,
  80. const char *dir_core_assets, char *backup_path, size_t len);
  81. /* Returns detected type of specified core backup file */
  82. enum core_backup_type core_backup_get_backup_type(const char *backup_path);
  83. /* Fetches crc value of specified core backup file.
  84. * Returns true if successful */
  85. bool core_backup_get_backup_crc(char *backup_path, uint32_t *crc);
  86. /* Fetches core path associated with specified core
  87. * backup file. Returns detected type of backup
  88. * file - CORE_BACKUP_TYPE_INVALID indicates that
  89. * backup file cannot be restored/installed, or
  90. * arguments are otherwise invalid */
  91. enum core_backup_type core_backup_get_core_path(
  92. const char *backup_path, const char *dir_libretro,
  93. char *core_path, size_t len);
  94. /*************************/
  95. /* Backup List Functions */
  96. /*************************/
  97. /**************************************/
  98. /* Initialisation / De-Initialisation */
  99. /**************************************/
  100. /* Creates a new core backup list containing entries
  101. * for all existing backup files.
  102. * Returns a handle to a new core_backup_list_t object
  103. * on success, otherwise returns NULL. */
  104. core_backup_list_t *core_backup_list_init(
  105. const char *core_path, const char *dir_core_assets);
  106. /* Frees specified core backup list */
  107. void core_backup_list_free(core_backup_list_t *backup_list);
  108. /***********/
  109. /* Getters */
  110. /***********/
  111. /* Returns number of entries in core backup list */
  112. size_t core_backup_list_size(core_backup_list_t *backup_list);
  113. /* Returns number of entries of specified 'backup mode'
  114. * (manual or automatic) in core backup list */
  115. size_t core_backup_list_get_num_backups(
  116. core_backup_list_t *backup_list,
  117. enum core_backup_mode backup_mode);
  118. /* Fetches core backup list entry corresponding
  119. * to the specified entry index.
  120. * Returns false if index is invalid. */
  121. bool core_backup_list_get_index(
  122. core_backup_list_t *backup_list,
  123. size_t idx,
  124. const core_backup_list_entry_t **entry);
  125. /* Fetches core backup list entry corresponding
  126. * to the specified core crc checksum value.
  127. * Note that 'manual' and 'auto' backups are
  128. * considered independent - we only compare
  129. * crc values for the specified backup_mode.
  130. * Returns false if entry is not found. */
  131. bool core_backup_list_get_crc(
  132. core_backup_list_t *backup_list,
  133. uint32_t crc, enum core_backup_mode backup_mode,
  134. const core_backup_list_entry_t **entry);
  135. /* Fetches a string representation of a backup
  136. * list entry timestamp.
  137. * Returns false in the event of an error */
  138. bool core_backup_list_get_entry_timestamp_str(
  139. const core_backup_list_entry_t *entry,
  140. enum core_backup_date_separator_type date_separator,
  141. char *timestamp, size_t len);
  142. /* Fetches a string representation of a backup
  143. * list entry crc value.
  144. * Returns false in the event of an error */
  145. bool core_backup_list_get_entry_crc_str(
  146. const core_backup_list_entry_t *entry,
  147. char *crc, size_t len);
  148. RETRO_END_DECLS
  149. #endif