playlist.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. /* RetroArch - A frontend for libretro.
  2. * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
  3. * Copyright (C) 2011-2017 - Daniel De Matteis
  4. * Copyright (C) 2016-2019 - Brad Parker
  5. *
  6. * RetroArch is free software: you can redistribute it and/or modify it under the terms
  7. * of the GNU General Public License as published by the Free Software Found-
  8. * ation, either version 3 of the License, or (at your option) any later version.
  9. *
  10. * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  11. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  12. * PURPOSE. See the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with RetroArch.
  15. * If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef _PLAYLIST_H__
  18. #define _PLAYLIST_H__
  19. #include <stddef.h>
  20. #include <retro_common_api.h>
  21. #include <boolean.h>
  22. #include <lists/string_list.h>
  23. #include "core_info.h"
  24. RETRO_BEGIN_DECLS
  25. /* Default maximum playlist size */
  26. #define COLLECTION_SIZE 0x7FFFFFFF
  27. typedef struct content_playlist playlist_t;
  28. enum playlist_runtime_status
  29. {
  30. PLAYLIST_RUNTIME_UNKNOWN = 0,
  31. PLAYLIST_RUNTIME_MISSING,
  32. PLAYLIST_RUNTIME_VALID
  33. };
  34. enum playlist_file_mode
  35. {
  36. PLAYLIST_LOAD = 0,
  37. PLAYLIST_SAVE
  38. };
  39. enum playlist_label_display_mode
  40. {
  41. LABEL_DISPLAY_MODE_DEFAULT = 0,
  42. LABEL_DISPLAY_MODE_REMOVE_PARENTHESES,
  43. LABEL_DISPLAY_MODE_REMOVE_BRACKETS,
  44. LABEL_DISPLAY_MODE_REMOVE_PARENTHESES_AND_BRACKETS,
  45. LABEL_DISPLAY_MODE_KEEP_REGION,
  46. LABEL_DISPLAY_MODE_KEEP_DISC_INDEX,
  47. LABEL_DISPLAY_MODE_KEEP_REGION_AND_DISC_INDEX
  48. };
  49. enum playlist_thumbnail_mode
  50. {
  51. PLAYLIST_THUMBNAIL_MODE_DEFAULT = 0,
  52. PLAYLIST_THUMBNAIL_MODE_OFF,
  53. PLAYLIST_THUMBNAIL_MODE_SCREENSHOTS,
  54. PLAYLIST_THUMBNAIL_MODE_TITLE_SCREENS,
  55. PLAYLIST_THUMBNAIL_MODE_BOXARTS
  56. };
  57. enum playlist_sort_mode
  58. {
  59. PLAYLIST_SORT_MODE_DEFAULT = 0,
  60. PLAYLIST_SORT_MODE_ALPHABETICAL,
  61. PLAYLIST_SORT_MODE_OFF
  62. };
  63. /* TODO/FIXME - since gfx_thumbnail_path.h has now
  64. * been divorced from the menu code, perhaps jdgleaver
  65. * can refactor this? */
  66. /* Note: We already have a left/right enum defined
  67. * in gfx_thumbnail_path.h - but we can't include
  68. * menu code here, so have to make a 'duplicate'... */
  69. enum playlist_thumbnail_id
  70. {
  71. PLAYLIST_THUMBNAIL_RIGHT = 0,
  72. PLAYLIST_THUMBNAIL_LEFT
  73. };
  74. /* Holds all parameters required to uniquely
  75. * identify a playlist content path */
  76. typedef struct
  77. {
  78. char *real_path;
  79. char *archive_path;
  80. uint32_t real_path_hash;
  81. uint32_t archive_path_hash;
  82. bool is_archive;
  83. bool is_in_archive;
  84. } playlist_path_id_t;
  85. struct playlist_entry
  86. {
  87. char *path;
  88. char *label;
  89. char *core_path;
  90. char *core_name;
  91. char *db_name;
  92. char *crc32;
  93. char *subsystem_ident;
  94. char *subsystem_name;
  95. char *runtime_str;
  96. char *last_played_str;
  97. struct string_list *subsystem_roms;
  98. playlist_path_id_t *path_id;
  99. unsigned entry_slot;
  100. unsigned runtime_hours;
  101. unsigned runtime_minutes;
  102. unsigned runtime_seconds;
  103. /* Note: due to platform dependence, have to record
  104. * timestamp as either a string or independent integer
  105. * values. The latter is more verbose, but more efficient. */
  106. unsigned last_played_year;
  107. unsigned last_played_month;
  108. unsigned last_played_day;
  109. unsigned last_played_hour;
  110. unsigned last_played_minute;
  111. unsigned last_played_second;
  112. enum playlist_runtime_status runtime_status;
  113. };
  114. /* Holds all configuration parameters required
  115. * when initialising/saving playlists */
  116. typedef struct
  117. {
  118. size_t capacity;
  119. bool old_format;
  120. bool compress;
  121. bool fuzzy_archive_match;
  122. bool autofix_paths;
  123. char path[PATH_MAX_LENGTH];
  124. char base_content_directory[PATH_MAX_LENGTH];
  125. } playlist_config_t;
  126. /* Convenience function: copies specified playlist
  127. * path to specified playlist configuration object */
  128. void playlist_config_set_path(playlist_config_t *config, const char *path);
  129. /* Convenience function: copies base content directory
  130. * path to specified playlist configuration object */
  131. void playlist_config_set_base_content_directory(playlist_config_t* config, const char* path);
  132. /* Creates a copy of the specified playlist configuration.
  133. * Returns false in the event of an error */
  134. bool playlist_config_copy(const playlist_config_t *src, playlist_config_t *dst);
  135. /* Returns internal playlist configuration object
  136. * of specified playlist.
  137. * Returns NULL it the event of an error. */
  138. playlist_config_t *playlist_get_config(playlist_t *playlist);
  139. /**
  140. * playlist_init:
  141. * @config : Playlist configuration object.
  142. *
  143. * Creates and initializes a playlist.
  144. *
  145. * Returns: handle to new playlist if successful, otherwise NULL
  146. **/
  147. playlist_t *playlist_init(const playlist_config_t *config);
  148. /**
  149. * playlist_free:
  150. * @playlist : Playlist handle.
  151. *
  152. * Frees playlist handle.
  153. */
  154. void playlist_free(playlist_t *playlist);
  155. /**
  156. * playlist_clear:
  157. * @playlist : Playlist handle.
  158. *
  159. * Clears all playlist entries in playlist.
  160. **/
  161. void playlist_clear(playlist_t *playlist);
  162. /**
  163. * playlist_size:
  164. * @playlist : Playlist handle.
  165. *
  166. * Gets size of playlist.
  167. * Returns: size of playlist.
  168. **/
  169. size_t playlist_size(playlist_t *playlist);
  170. /**
  171. * playlist_capacity:
  172. * @playlist : Playlist handle.
  173. *
  174. * Gets maximum capacity of playlist.
  175. * Returns: maximum capacity of playlist.
  176. **/
  177. size_t playlist_capacity(playlist_t *playlist);
  178. /**
  179. * playlist_get_index:
  180. * @playlist : Playlist handle.
  181. * @idx : Index of playlist entry.
  182. *
  183. * Gets values of playlist index:
  184. **/
  185. void playlist_get_index(playlist_t *playlist,
  186. size_t idx,
  187. const struct playlist_entry **entry);
  188. /**
  189. * playlist_delete_index:
  190. * @playlist : Playlist handle.
  191. * @idx : Index of playlist entry.
  192. *
  193. * Deletes the entry at index:
  194. **/
  195. void playlist_delete_index(playlist_t *playlist,
  196. size_t idx);
  197. /**
  198. * playlist_delete_by_path:
  199. * @playlist : Playlist handle.
  200. * @search_path : Content path.
  201. *
  202. * Deletes all entries with content path
  203. * matching 'search_path'
  204. **/
  205. void playlist_delete_by_path(playlist_t *playlist,
  206. const char *search_path);
  207. /**
  208. * playlist_resolve_path:
  209. * @mode : PLAYLIST_LOAD or PLAYLIST_SAVE
  210. * @is_core : Set true if path to be resolved is a core file
  211. * @path : The path to be modified
  212. *
  213. * Resolves the path of an item, such as the content path or path to the core, to a format
  214. * appropriate for saving or loading depending on the @mode parameter
  215. *
  216. * Can be platform specific. File paths for saving can be abbreviated to avoid saving absolute
  217. * paths, as the base directory (home or application dir) may change after each subsequent
  218. * install (iOS)
  219. **/
  220. void playlist_resolve_path(enum playlist_file_mode mode,
  221. bool is_core, char *path, size_t len);
  222. /**
  223. * playlist_content_path_is_valid:
  224. * @path : Content path
  225. *
  226. * Checks whether specified playlist content path
  227. * refers to an existent file. Handles all playlist
  228. * content path 'types' (i.e. can validate paths
  229. * referencing files inside archives).
  230. *
  231. * Returns true if file referenced by content
  232. * path exists on the host filesystem.
  233. **/
  234. bool playlist_content_path_is_valid(const char *path);
  235. /**
  236. * playlist_push:
  237. * @playlist : Playlist handle.
  238. *
  239. * Push entry to top of playlist.
  240. **/
  241. bool playlist_push(playlist_t *playlist,
  242. const struct playlist_entry *entry);
  243. bool playlist_push_runtime(playlist_t *playlist,
  244. const struct playlist_entry *entry);
  245. void playlist_update(playlist_t *playlist, size_t idx,
  246. const struct playlist_entry *update_entry);
  247. /* Note: register_update determines whether the internal
  248. * 'playlist->modified' flag is set when updating runtime
  249. * values. Since these are normally set temporarily (for
  250. * display purposes), we do not always want this function
  251. * to trigger a re-write of the playlist file. */
  252. void playlist_update_runtime(playlist_t *playlist, size_t idx,
  253. const struct playlist_entry *update_entry,
  254. bool register_update);
  255. void playlist_get_index_by_path(playlist_t *playlist,
  256. const char *search_path,
  257. const struct playlist_entry **entry);
  258. bool playlist_entry_exists(playlist_t *playlist,
  259. const char *path);
  260. char *playlist_get_conf_path(playlist_t *playlist);
  261. uint32_t playlist_get_size(playlist_t *playlist);
  262. void playlist_write_file(playlist_t *playlist);
  263. void playlist_write_runtime_file(playlist_t *playlist);
  264. void playlist_qsort(playlist_t *playlist);
  265. void playlist_free_cached(void);
  266. playlist_t *playlist_get_cached(void);
  267. /* If current on-disk playlist file referenced
  268. * by 'config->path' does not match requested
  269. * 'old format' or 'compression' state, file will
  270. * be updated automatically
  271. * > Since this function is called whenever a
  272. * playlist is browsed via the menu, this is
  273. * a simple method for ensuring that files
  274. * are always kept synced with user settings */
  275. bool playlist_init_cached(const playlist_config_t *config);
  276. void command_playlist_push_write(
  277. playlist_t *playlist,
  278. const struct playlist_entry *entry);
  279. void command_playlist_update_write(
  280. playlist_t *playlist,
  281. size_t idx,
  282. const struct playlist_entry *entry);
  283. /* Returns true if specified playlist index matches
  284. * specified content/core paths */
  285. bool playlist_index_is_valid(playlist_t *playlist, size_t idx,
  286. const char *path, const char *core_path);
  287. /* Returns true if specified playlist entries have
  288. * identical content and core paths */
  289. bool playlist_entries_are_equal(
  290. const struct playlist_entry *entry_a,
  291. const struct playlist_entry *entry_b,
  292. const playlist_config_t *config);
  293. /* Returns true if entries at specified indices
  294. * of specified playlist have identical content
  295. * and core paths */
  296. bool playlist_index_entries_are_equal(
  297. playlist_t *playlist, size_t idx_a, size_t idx_b);
  298. void playlist_get_crc32(playlist_t *playlist, size_t idx,
  299. const char **crc32);
  300. /* If db_name is empty, 'returns' playlist file basename */
  301. void playlist_get_db_name(playlist_t *playlist, size_t idx,
  302. const char **db_name);
  303. const char *playlist_get_default_core_path(playlist_t *playlist);
  304. const char *playlist_get_default_core_name(playlist_t *playlist);
  305. enum playlist_label_display_mode playlist_get_label_display_mode(playlist_t *playlist);
  306. enum playlist_thumbnail_mode playlist_get_thumbnail_mode(
  307. playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id);
  308. enum playlist_sort_mode playlist_get_sort_mode(playlist_t *playlist);
  309. const char *playlist_get_scan_content_dir(playlist_t *playlist);
  310. const char *playlist_get_scan_file_exts(playlist_t *playlist);
  311. const char *playlist_get_scan_dat_file_path(playlist_t *playlist);
  312. bool playlist_get_scan_search_recursively(playlist_t *playlist);
  313. bool playlist_get_scan_search_archives(playlist_t *playlist);
  314. bool playlist_get_scan_filter_dat_content(playlist_t *playlist);
  315. bool playlist_scan_refresh_enabled(playlist_t *playlist);
  316. void playlist_set_default_core_path(playlist_t *playlist, const char *core_path);
  317. void playlist_set_default_core_name(playlist_t *playlist, const char *core_name);
  318. void playlist_set_label_display_mode(playlist_t *playlist, enum playlist_label_display_mode label_display_mode);
  319. void playlist_set_thumbnail_mode(
  320. playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id, enum playlist_thumbnail_mode thumbnail_mode);
  321. void playlist_set_sort_mode(playlist_t *playlist, enum playlist_sort_mode sort_mode);
  322. void playlist_set_scan_content_dir(playlist_t *playlist, const char *content_dir);
  323. void playlist_set_scan_file_exts(playlist_t *playlist, const char *file_exts);
  324. void playlist_set_scan_dat_file_path(playlist_t *playlist, const char *dat_file_path);
  325. void playlist_set_scan_search_recursively(playlist_t *playlist, bool search_recursively);
  326. void playlist_set_scan_search_archives(playlist_t *playlist, bool search_archives);
  327. void playlist_set_scan_filter_dat_content(playlist_t *playlist, bool filter_dat_content);
  328. /* Returns true if specified entry has a valid
  329. * core association (i.e. a non-empty string
  330. * other than DETECT) */
  331. bool playlist_entry_has_core(const struct playlist_entry *entry);
  332. /* Fetches core info object corresponding to the
  333. * currently associated core of the specified
  334. * playlist entry.
  335. * Returns NULL if entry does not have a valid
  336. * core association */
  337. core_info_t *playlist_entry_get_core_info(const struct playlist_entry* entry);
  338. /* Fetches core info object corresponding to the
  339. * currently associated default core of the
  340. * specified playlist.
  341. * Returns NULL if playlist does not have a valid
  342. * default core association */
  343. core_info_t *playlist_get_default_core_info(playlist_t* playlist);
  344. void playlist_set_cached_external(playlist_t* pl);
  345. RETRO_END_DECLS
  346. #endif