Files
RetroArch/playlist.h
Davey HughesandLibretroAdmin 08e5b72a88 Scan from the command line: exit status, Manual Scan options, playlist refresh (#19977)
* file_path: stop at the end of the path after '~'

fill_pathname_expand_special() skipped two characters after a leading
'~' or ':', so a bare "~" read past its NUL and "~x" lost the x. It
now skips the prefix and a slash after it, if there is one.

* scan: hand the callback user data and what the scan did

task_push_dbscan() and task_push_manual_content_scan() take user data
for their callback, and the callback's task_data is now a
task_dbscan_result_t: how many entries the scan added, how many its
playlists already held, and how many files matched nothing. A file is
counted by what became of it, so an archive that is expanded is not
counted as unmatched, and a loose scan's unmatched files count as
added. Callers pass NULL for now.

* scan: say in the result when a scan failed

A scan that ends before it runs (bad setup, no valid content, a DAT
that will not load) or ends with a task error now sets the result's
failed flag. A database folder that is missing or unset is treated as
an empty one, so it reports the same "no database" error instead of
finishing as if it had scanned.

* scan: count the files a scan could not read

A file whose scan fails (an unreadable file, a failed lookup) was in
no count. The result now carries an errors count for them. They do
not fail the scan.

* scan: print --scan errors on stderr and totals on stdout

A command-line scan now ends with a totals line on stdout, or with the
reason it failed on stderr. A file it could not read is listed on
stderr. The ++/==/?? marks are coloured only when their stream is a
terminal, so pipes and redirected output get plain text; on Windows
redirected output keeps its marks instead of losing them to
WriteConsole.

* scan: the manual scan finder skips a finished task

A finished scan stays in the task queue while its callback runs, and
the finder that refuses a second scan for the same playlist still
matched it, so a scan pushed from that callback was refused.

* retroarch: run every --scan, then exit with what the scans did

Each --scan is collected while the command line is parsed and run in
turn once it is done, so later options and further --scan flags are
no longer dropped. A path is expanded and made absolute first; one
that does not exist, or a scan that cannot start, is reported on
stderr and the next path still runs. --scan with --cloudsync or
--command is refused.

Without --menu the exit status is 1 if any scan failed, else 0 if any
added an entry, else 2, and a content path given with the scans is
ignored, with a line on stderr. With --menu each finished scan starts
the next, as a second scan is refused while one runs.

* manual_content_scan: clear the database name a refresh did not save

A playlist with no saved database name left the name buffer
uninitialised, and the refresh compared it against every installed
database, so whatever was on the stack could pick a database the
playlist never named.

* scan: Skip Database References names the scan's one playlist

The option was meant to put the playlist's name in each entry's
db_name, even for a database match (#18641), for users who build
their own thumbnail sets. When the scan picks the playlists, db_name
also picks the playlist an entry goes to, so with the option on every
match went to one playlist named after the content folder.

It now applies only when the scan writes one playlist, and gives
that playlist's name, a loose scan's unmatched entries included. With
the target on <Automatic>, or Fully Automatic with the option left on
from a Custom scan, matches go to their databases' playlists as with
it off; the entries of a custom playlist look their thumbnails up
under its name, not the folder's.

* scan: name the scanned folder in the start line

The "Scanning content" line, in the log and in --scan's output, has
named the database folder since the manual scan and the database scan
were merged (2fdf736d51); before, it named the path being scanned. It
names the content folder again.

* manual_content_scan: reset, scan overrides and their apply

The command line's scan options need each scan to start from the
defaults and to lay their values over them, or over a playlist's saved
settings. Add a reset, a record of those options and a function that
applies it through the existing setters: a core named by path, file
name or display name, a database, a playlist, the database check or a
DAT, extensions and the switches, stopping with a reason at the first
that does not resolve.

A core path is normalised before it is compared. A core's file name
matches in the case given first, then ignoring case, on every
platform; a display name matches exactly. Given another database, a
playlist named after its database keeps that name as a custom one, so
a refresh still writes the same playlist.

The core setter's copy step becomes its own function, so a core found
by path or file name can be set. Nothing calls the new functions yet.

* scan: run --scan items through one chain

The --scan paths ran through a loop in retroarch.c, and with --menu
through a second chain of their own. The scan options and playlist
refreshes to come need one runner for every item, from the command
line and from the menu.

task_push_dbscan_chain() runs a list of items one task at a time: a
prep task lists the databases, then each step is pushed from the last
task's callback on the main thread, so nothing waits and nothing
locks. An item that fails is reported and the run goes on; a
cancelled task ends it. retroarch.c builds the items in the first
argument pass and hands them to the chain; without --menu it waits
for the chain's end and exits as before.

Running out of memory prints "out of memory" on stderr: for an item's
path the item fails, and for the chain itself nothing runs, which
without --menu exits 1.

The chain also prints a scan's override errors, and the warnings for
an option that needs one playlist or does nothing for a single file,
which the scan options of the next commit can trigger.

* retroarch: Manual Scan options for --scan

--scan-playlist, --scan-database, --scan-match, --scan-dat, --scan-core,
--scan-exts and the five switches set the Manual Scan settings of the
--scan before them; a --scan without any stays Fully Automatic.

Values are checked in the first pass, so an option before any --scan,
an empty or bad value, or one too long for its setting ends the run
with its reason on stderr and status 1, before the config loads and
before anything is scanned. Cores, databases and DAT files are
resolved when their scan runs, and one that does not resolve fails
only that scan.

* scan: refresh playlists in the chain

A refresh item rescans one playlist with its saved scan settings, as
the menu's Refresh Playlist does, with the item's scan options laid
over them and written back by the scan. A refresh-all item does the
same for every playlist in the playlist folder that has saved
settings, in the order Manage Playlists lists them, histories and
favorites left out.

A refresh item names its playlist by name or by a path in the playlist
folder. A bare "name.lpl" is the playlist folder's file, and an
absolute path is normalised before it is checked against the folder.
The name is looked up in the folder's listing on every platform, the
exact name first, then ignoring case, since macOS and FAT/exFAT cards
ignore case; the refresh then takes the file's own name, so a
database's playlist stays one. Two or more playlists that match only
in other cases fail the item.

The playlist folder walk and each playlist load run in prep tasks: on
the worker with a threaded queue, under the shared I/O window without
one, each pushed from the previous step's callback. A playlist whose
saved content folder is gone is skipped rather than failed. A listing
that runs out of memory fails the refresh-all; a playlist folder that
is missing or cannot be read lists nothing, and the refresh-all ends
with "no playlists with saved scan settings". A refresh's start line
names its content folder; its totals and failure lines name the
playlist.

* retroarch: --scan-refresh and --scan-refresh-all

--scan-refresh=NAME|PATH rescans a playlist with its saved scan
settings, as the menu's Refresh Playlist does, and --scan-refresh-all
rescans every playlist that has them. Both are items of the same run
as --scan: the scan options after one are laid over the saved
settings and written back, and the exit status follows the same rule.

--scan-playlist after a refresh is refused, so a refresh always
updates its own playlist, and an empty --scan-refresh is refused as
the other empty values are. Like --scan, the refresh options cannot be
combined with --cloudsync or --command; the error names whichever of
the three comes first on the command line.

* menu: Refresh All Playlists

Manage Playlists gets Refresh All Playlists as its first entry when it
lists any playlist, so an empty list still says there are no entries.
It rescans every playlist that has saved scan settings, with those
settings, through the same chain as --scan-refresh-all, and ends with
one notification saying how many playlists were refreshed, skipped
(content folder gone) and failed.

While a content scan runs it is refused with a new message; a refused
scan had none. Other languages come through Crowdin.

While a scan chain runs (Refresh All, or a command-line scan with
--menu), Start Scan, a playlist's Refresh, Scan Directory and Scan
File are refused with the same message, as they would run with the
settings the chain last loaded. task_push_dbscan() returns false then
too, which covers the companion and the iOS caller.

* docs: --scan, refresh and the Manual Scan options in the man page

--help lists the options but not what a script needs: the order the
scans run in, the exit status and what the options set. The man page
now has them, next to --cloudsync, and CHANGES.md has the entry.

* scan chain: writes from workers reach the playlist cache by note

A playlist written by a task - the chain's prep parse, a scan, a
playlist-manager task, whatever thread it runs on - leaves a note on a
lock-free stack instead of reading the cached playlist; the main
thread applies the notes when it next decides whether the cache may
stand in, so no worker reads playlist_cached while the main thread
frees or installs it. Without threads or pointer atomics a write
applies at once.

The chain's prep tasks set their handlers by name, and
thread_read_audit.py fails on a handler set from a
retro_task_handler_t parameter, which would hide every handler passed
in. The chain puts the Manual Scan settings it found back when it
ends, and is no longer running when its done callback runs, so that
callback may start another. task_push_dbscan() says why it refuses,
so the menu and the companions show the same reason, and the
companions' status line takes it from companion_core. --scan and
--scan-refresh set the verbosity override, so a config with logging
off cannot detach the console the totals go to, and refuse a path too
long for the chain's buffers. The Refresh All notification passes the
length written, and fill_pathname_expand_special() stops at the end of
a buffer shorter than the home or application directory.

Lanes: playlist_parity_test writes the cached file from a worker,
once at the same size and then while the main thread reuses and frees
the cache; database_scan_test checks the refusal message, the restored
settings and a done callback that starts the next chain;
fill_pathname_test expands into a buffer shorter than the home
directory.

* playlist: header-only parse for the scan chain's prep

The prep task needs a playlist's saved scan settings and nothing else,
yet parsed every entry and, through autofix, could write the file back
from a worker. playlist_parse_begin_header() stops at "items", rebases
the scan record in memory when the base content directory moved, and
marks the playlist so playlist_write_file() refuses it.

Lane: playlist_parity_test header_only (entries skipped, scan dir
rebased, file bytes untouched, old format).

* scan chain: ask the file system nothing on the main thread

The chain's steps ran on the main thread between its tasks and stat'd
and realpath'd there: a --scan path's resolve and stat, a
--scan-refresh path's two realpaths, the content folder's stat, the
saved and override DATs' stat and size, an override core path's
realpath.  On a network share each of those can stall a frame.

- manual_content_scan_fs_read() reads them on any thread, touching
  nothing but its arguments; the _fs variants of the content-folder,
  playlist and override setters take its answers instead of asking.
  The plain setters pass NULL and behave as before, so the menu is
  unchanged.
- A --scan path gets its own prep task (dbscan_path_handler); a
  --scan-refresh resolves its path inside the load task, and the load
  reads the folder, the saved DAT and the overrides' paths once the
  header is parsed.  The worker gets copies of the item's strings.
- The prep's state is freed in one place.

Lane: database_scan_test "fs off main": six items that each stop
before their scan, on a threaded queue, with path_stat, path_is_valid,
path_is_directory, path_get_size and path_resolve_realpath wrapped:
no call on the main thread.

Not moved: the scan task's own push still stats the content folder
and the DAT (manual_content_scan_get_task_config), shared with the
menu.

* samples: the scan chain's lanes hold on Windows and without realpath

From a native Windows run of both tests:

- database_scan_test "fs off main" refreshed f_gone.lpl through
  "pl/../pl/", which only a realpath folds; the sample builds without
  RARCH_INTERNAL, where path_resolve_realpath() folds nothing, so the
  item was rightly not in the playlist folder.  It names the playlist
  by its plain path now, which the check still realpaths on the
  worker.
- "another case, a database's playlist" read the system name type
  after the chain ended, and the chain puts the Manual Scan settings
  back then.  The item callback records each scan's type instead.
- playlist_parity_test's header lane expected "/moved/snes"; autofix
  converts the suffix to the local form, "/moved\snes" on Windows.
- The worker lane's stress read required a core name of every read.
  Windows replaces the file with MoveFileExW, and an open that meets
  the replace fails: that read is an empty playlist, which has none.

---------

Co-authored-by: LibretroAdmin <[email protected]>
2026-11-04 19:34:05 +01:00

589 lines
22 KiB
C

/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2017 - Daniel De Matteis
* Copyright (C) 2016-2019 - Brad Parker
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _PLAYLIST_H__
#define _PLAYLIST_H__
#include <stdint.h>
#include <boolean.h>
#include <stddef.h>
#include <retro_common_api.h>
#include <retro_miscellaneous.h>
#include <lists/string_list.h>
#include "core_info.h"
/* Default maximum playlist size */
#define COLLECTION_SIZE 0x7FFFFFFF
RETRO_BEGIN_DECLS
enum playlist_runtime_status
{
PLAYLIST_RUNTIME_UNKNOWN = 0,
PLAYLIST_RUNTIME_MISSING,
PLAYLIST_RUNTIME_VALID
};
enum playlist_file_mode
{
PLAYLIST_LOAD = 0,
PLAYLIST_SAVE
};
enum playlist_label_display_mode
{
LABEL_DISPLAY_MODE_DEFAULT = 0,
LABEL_DISPLAY_MODE_REMOVE_PARENTHESES,
LABEL_DISPLAY_MODE_REMOVE_BRACKETS,
LABEL_DISPLAY_MODE_REMOVE_PARENTHESES_AND_BRACKETS,
LABEL_DISPLAY_MODE_KEEP_REGION,
LABEL_DISPLAY_MODE_KEEP_DISC_INDEX,
LABEL_DISPLAY_MODE_KEEP_REGION_AND_DISC_INDEX
};
enum playlist_thumbnail_mode
{
PLAYLIST_THUMBNAIL_MODE_DEFAULT = 0,
PLAYLIST_THUMBNAIL_MODE_OFF,
PLAYLIST_THUMBNAIL_MODE_SCREENSHOTS,
PLAYLIST_THUMBNAIL_MODE_TITLE_SCREENS,
PLAYLIST_THUMBNAIL_MODE_BOXARTS,
PLAYLIST_THUMBNAIL_MODE_LOGOS,
PLAYLIST_THUMBNAIL_MODE_LAST
};
enum playlist_thumbnail_match_mode
{
PLAYLIST_THUMBNAIL_MATCH_MODE_DEFAULT = 0,
PLAYLIST_THUMBNAIL_MATCH_MODE_WITH_LABEL = PLAYLIST_THUMBNAIL_MATCH_MODE_DEFAULT,
PLAYLIST_THUMBNAIL_MATCH_MODE_WITH_FILENAME
};
enum playlist_sort_mode
{
PLAYLIST_SORT_MODE_DEFAULT = 0,
PLAYLIST_SORT_MODE_ALPHABETICAL,
PLAYLIST_SORT_MODE_OFF
};
/* Note: We already have a left/right enum defined
* in gfx_thumbnail_path.h - but we can't include
* menu code here, so have to make a 'duplicate'... */
enum playlist_thumbnail_id
{
PLAYLIST_THUMBNAIL_RIGHT = 0,
PLAYLIST_THUMBNAIL_LEFT,
PLAYLIST_THUMBNAIL_ICON
};
enum playlist_thumbnail_name_flags
{
PLAYLIST_THUMBNAIL_FLAG_INVALID = 0,
PLAYLIST_THUMBNAIL_FLAG_FULL_NAME = (1 << 0),
PLAYLIST_THUMBNAIL_FLAG_STD_NAME = (1 << 1),
PLAYLIST_THUMBNAIL_FLAG_SHORT_NAME = (1 << 2),
PLAYLIST_THUMBNAIL_FLAG_NONE = (1 << 3)
};
typedef struct content_playlist playlist_t;
/* Holds all parameters required to uniquely
* identify a playlist content path */
typedef struct
{
char *real_path;
char *archive_path;
uint32_t real_path_hash;
uint32_t archive_path_hash;
bool is_archive;
bool is_in_archive;
} playlist_path_id_t;
struct playlist_entry
{
char *path;
char *label;
char *core_path;
char *core_name;
char *db_name;
char *crc32;
char *subsystem_ident;
char *subsystem_name;
char *runtime_str;
char *last_played_str;
struct string_list *subsystem_roms;
playlist_path_id_t *path_id;
/* Note: due to platform dependence, have to record
* timestamp as either a string or independent integer
* values. The latter is more verbose, but more efficient.
*
* Packed: a playlist holds one of these per item and each of
* these nine values is a handful of bits, so they ride in three
* words rather than nine. That is 24 bytes off every entry, which
* on a large playlist is hundreds of kilobytes. The hour count
* gets 20 bits, which is 119 years of play; the rest are what a
* calendar and a clock allow. Reach them through the accessors
* below rather than the words. */
uint32_t runtime; /* hours:20 | minutes:6 | seconds:6 */
uint32_t last_played_ymd; /* year:16 | month:4 | day:5 */
uint32_t last_played_hms; /* hour:5 | minute:6 | second:6 */
/* Packed, for the same reason as the timestamps above: the slot
* index is a subsystem content slot, the runtime status has three
* values and the thumbnail flags are five bits. */
uint32_t attr; /* slot:16 | status:3 | thumbs:5 */
};
#define PLAYLIST_ENTRY_SLOT(e) ((e)->attr & 0xffffu)
#define PLAYLIST_RUNTIME_STATUS(e) \
((enum playlist_runtime_status)(((e)->attr >> 16) & 0x7u))
#define PLAYLIST_THUMBNAIL_FLAGS(e) ((int)(((e)->attr >> 19) & 0x1fu))
#define PLAYLIST_SET_ENTRY_SLOT(e, v) \
((e)->attr = ((e)->attr & ~0xffffu) | ((uint32_t)(v) & 0xffffu))
#define PLAYLIST_SET_RUNTIME_STATUS(e, v) \
((e)->attr = ((e)->attr & ~(0x7u << 16)) \
| (((uint32_t)(v) & 0x7u) << 16))
#define PLAYLIST_SET_THUMBNAIL_FLAGS(e, v) \
((e)->attr = ((e)->attr & ~(0x1fu << 19)) \
| (((uint32_t)(v) & 0x1fu) << 19))
#define PLAYLIST_OR_THUMBNAIL_FLAGS(e, v) \
PLAYLIST_SET_THUMBNAIL_FLAGS((e), PLAYLIST_THUMBNAIL_FLAGS(e) | (int)(v))
#define PLAYLIST_RUNTIME_HOURS(e) ((e)->runtime >> 12)
#define PLAYLIST_RUNTIME_MINUTES(e) (((e)->runtime >> 6) & 0x3fu)
#define PLAYLIST_RUNTIME_SECONDS(e) ((e)->runtime & 0x3fu)
#define PLAYLIST_SET_RUNTIME_HOURS(e, v) \
((e)->runtime = ((e)->runtime & 0xfffu) | (((uint32_t)(v) & 0xfffffu) << 12))
#define PLAYLIST_SET_RUNTIME_MINUTES(e, v) \
((e)->runtime = ((e)->runtime & ~0xfc0u) | (((uint32_t)(v) & 0x3fu) << 6))
#define PLAYLIST_SET_RUNTIME_SECONDS(e, v) \
((e)->runtime = ((e)->runtime & ~0x3fu) | ((uint32_t)(v) & 0x3fu))
#define PLAYLIST_LAST_PLAYED_YEAR(e) ((e)->last_played_ymd >> 9)
#define PLAYLIST_LAST_PLAYED_MONTH(e) (((e)->last_played_ymd >> 5) & 0xfu)
#define PLAYLIST_LAST_PLAYED_DAY(e) ((e)->last_played_ymd & 0x1fu)
#define PLAYLIST_SET_LAST_PLAYED_YEAR(e, v) \
((e)->last_played_ymd = ((e)->last_played_ymd & 0x1ffu) \
| (((uint32_t)(v) & 0xffffu) << 9))
#define PLAYLIST_SET_LAST_PLAYED_MONTH(e, v) \
((e)->last_played_ymd = ((e)->last_played_ymd & ~0x1e0u) \
| (((uint32_t)(v) & 0xfu) << 5))
#define PLAYLIST_SET_LAST_PLAYED_DAY(e, v) \
((e)->last_played_ymd = ((e)->last_played_ymd & ~0x1fu) \
| ((uint32_t)(v) & 0x1fu))
#define PLAYLIST_LAST_PLAYED_HOUR(e) ((e)->last_played_hms >> 12)
#define PLAYLIST_LAST_PLAYED_MINUTE(e) (((e)->last_played_hms >> 6) & 0x3fu)
#define PLAYLIST_LAST_PLAYED_SECOND(e) ((e)->last_played_hms & 0x3fu)
#define PLAYLIST_SET_LAST_PLAYED_HOUR(e, v) \
((e)->last_played_hms = ((e)->last_played_hms & 0xfffu) \
| (((uint32_t)(v) & 0x1fu) << 12))
#define PLAYLIST_SET_LAST_PLAYED_MINUTE(e, v) \
((e)->last_played_hms = ((e)->last_played_hms & ~0xfc0u) \
| (((uint32_t)(v) & 0x3fu) << 6))
#define PLAYLIST_SET_LAST_PLAYED_SECOND(e, v) \
((e)->last_played_hms = ((e)->last_played_hms & ~0x3fu) \
| ((uint32_t)(v) & 0x3fu))
/* Holds all configuration parameters required
* when initialising/saving playlists */
typedef struct
{
size_t capacity;
bool old_format;
bool compress;
bool fuzzy_archive_match;
bool autofix_paths;
char path[PATH_MAX_LENGTH];
char base_content_directory[DIR_MAX_LENGTH];
} playlist_config_t;
/* Convenience function: copies specified playlist
* path to specified playlist configuration object */
size_t playlist_config_set_path(playlist_config_t *config, const char *path);
/* Convenience function: copies base content directory
* path to specified playlist configuration object */
size_t playlist_config_set_base_content_directory(playlist_config_t* config, const char* path);
/* Creates a copy of the specified playlist configuration.
* Returns false in the event of an error */
bool playlist_config_copy(const playlist_config_t *src, playlist_config_t *dst);
/* Returns internal playlist configuration object
* of specified playlist.
* Returns NULL it the event of an error. */
playlist_config_t *playlist_get_config(playlist_t *playlist);
/**
* playlist_init:
* @config : Playlist configuration object.
*
* Creates and initializes a playlist.
*
* Returns: handle to new playlist if successful, otherwise NULL
**/
playlist_t *playlist_init(const playlist_config_t *config);
/* Resumable playlist parse.
*
* playlist_parse_begin() opens and sniffs the playlist file and
* returns a parse handle (NULL only on allocation failure; a missing
* or unreadable file resolves - as it always has - to an empty
* playlist at the first step). playlist_parse_step() advances the
* parse, consulting @budget_cb between batches of work when
* non-NULL: it returns 1 when the playlist is complete, 0 when the
* budget ran out mid-parse (call again), and -1 on a failed parse.
* With a NULL @budget_cb the step runs to completion -
* playlist_init() is exactly begin + one unbudgeted step + end, so
* the blocking and budgeted paths cannot drift apart.
* playlist_parse_end() returns the finished playlist (or NULL after
* a failure) and frees the handle; playlist_parse_abort() abandons a
* parse at any point, releasing everything. */
typedef struct playlist_parse playlist_parse_t;
playlist_parse_t *playlist_parse_begin(const playlist_config_t *config);
/* The same, for what comes ahead of the entries only - the defaults
* and the scan record, which the writer puts before them - as a
* playlist with no entries that playlist_write_file() never writes.
* The scan record's paths move to the configured base content
* directory as a full read's autofix would move them, in memory. */
playlist_parse_t *playlist_parse_begin_header(const playlist_config_t *config);
int playlist_parse_step(playlist_parse_t *p,
bool (*budget_cb)(void *), void *budget_ud);
playlist_t *playlist_parse_end(playlist_parse_t *p);
void playlist_parse_abort(playlist_parse_t *p);
/* Deferred variant of playlist_init_cached(): same contract, spread
* over budgeted steps. playlist_init_cached_deferred() returns 1
* when the requested playlist is cached and ready (cache hit, or the
* parse completed within budget), 0 while a parse is pending, -1 on
* failure. While pending, playlist_init_cached_continue() advances
* the parse (it never touches the global cache, so a worker task may
* drive it; 1 means the parse finished and
* playlist_init_cached_finish() - main thread - must install it).
* playlist_init_cached_defer_abort() abandons any pending parse. */
int playlist_init_cached_deferred(const playlist_config_t *config,
bool (*budget_cb)(void *), void *budget_ud);
bool playlist_init_cached_pending(void);
int playlist_init_cached_continue(bool (*budget_cb)(void *), void *budget_ud);
int playlist_init_cached_finish(void);
void playlist_init_cached_defer_abort(void);
/**
* playlist_free:
* @playlist : Playlist handle.
*
* Frees playlist handle.
*/
void playlist_free(playlist_t *playlist);
/**
* playlist_clear:
* @playlist : Playlist handle.
*
* Clears all playlist entries in playlist.
**/
void playlist_clear(playlist_t *playlist);
/**
* playlist_size:
* @playlist : Playlist handle.
*
* Gets size of playlist.
* Returns: size of playlist.
**/
size_t playlist_size(playlist_t *playlist);
/**
* playlist_capacity:
* @playlist : Playlist handle.
*
* Gets maximum capacity of playlist.
* Returns: maximum capacity of playlist.
**/
size_t playlist_capacity(playlist_t *playlist);
/**
* playlist_get_index:
* @playlist : Playlist handle.
* @idx : Index of playlist entry.
*
* Gets values of playlist index:
**/
void playlist_get_index(playlist_t *playlist,
size_t idx,
const struct playlist_entry **entry);
/**
* playlist_delete_index:
* @playlist : Playlist handle.
* @idx : Index of playlist entry.
*
* Deletes the entry at index:
**/
void playlist_delete_index(playlist_t *playlist,
size_t idx);
/**
* playlist_delete_by_path:
* @playlist : Playlist handle.
* @search_path : Content path.
*
* Deletes all entries with content path
* matching 'search_path'
**/
void playlist_delete_by_path(playlist_t *playlist,
const char *search_path);
/**
* playlist_resolve_path:
* @mode : PLAYLIST_LOAD or PLAYLIST_SAVE
* @is_core : Set true if path to be resolved is a core file
* @path : The path to be modified
*
* Resolves the path of an item, such as the content path or path to the core, to a format
* appropriate for saving or loading depending on the @mode parameter
*
* Can be platform specific. File paths for saving can be abbreviated to avoid saving absolute
* paths, as the base directory (home or application dir) may change after each subsequent
* install (iOS)
**/
void playlist_resolve_path(enum playlist_file_mode mode,
bool is_core, char *path, size_t len);
/**
* playlist_content_path_is_valid:
* @path : Content path
*
* Checks whether specified playlist content path
* refers to an existent file. Handles all playlist
* content path 'types' (i.e. can validate paths
* referencing files inside archives).
*
* Returns true if file referenced by content
* path exists on the host filesystem.
**/
bool playlist_content_path_is_valid(const char *path);
/**
* playlist_push:
* @playlist : Playlist handle.
*
* Push entry to top of playlist.
**/
bool playlist_push(playlist_t *playlist,
const struct playlist_entry *entry);
/**
* playlist_push_unchecked:
*
* Appends @entry at the front of @playlist WITHOUT searching for an
* existing matching entry. The caller must have already proven the
* entry's content path absent (via playlist_entry_exists() or a
* playlist_dedup_t index); pushing a path that is present creates a
* duplicate. Applies the same validation, capacity and eviction
* rules as playlist_push().
**/
bool playlist_push_unchecked(playlist_t *playlist,
const struct playlist_entry *entry);
bool playlist_push_runtime(playlist_t *playlist,
const struct playlist_entry *entry);
void playlist_update(playlist_t *playlist, size_t idx,
const struct playlist_entry *update_entry);
/* Note: register_update determines whether the internal
* 'playlist->modified' flag is set when updating runtime
* values. Since these are normally set temporarily (for
* display purposes), we do not always want this function
* to trigger a re-write of the playlist file. */
void playlist_update_runtime(playlist_t *playlist, size_t idx,
const struct playlist_entry *update_entry,
bool register_update);
void playlist_update_thumbnail_name_flag(playlist_t *playlist, size_t idx,
enum playlist_thumbnail_name_flags thumbnail_flags);
enum playlist_thumbnail_name_flags playlist_get_next_thumbnail_name_flag(playlist_t *playlist, size_t idx);
enum playlist_thumbnail_name_flags playlist_get_curr_thumbnail_name_flag(playlist_t *playlist, size_t idx);
void playlist_get_index_by_path(playlist_t *playlist,
const char *search_path,
const struct playlist_entry **entry);
bool playlist_entry_exists(playlist_t *playlist,
const char *path);
/* Content path dedup index: answers playlist_entry_exists() queries
* in O(1) expected time for repeated probes against the same
* playlist. Verified candidates go through the same matching rules
* as the linear scan (including fuzzy archive matching), so answers
* are identical; internal allocation failure degrades the index to
* the linear scan transparently. The index owns all of its state
* and may be freed before or after the playlist. */
typedef struct playlist_dedup playlist_dedup_t;
playlist_dedup_t *playlist_dedup_init(void);
/**
* playlist_dedup_seed_step:
*
* Indexes @playlist's current entries, resuming from where the
* previous call stopped. When @budget_cb is non-NULL it is
* consulted between entries and seeding yields (returning false)
* once it reports the budget exhausted; at least one entry is
* seeded per call. Returns true when seeding has completed.
**/
bool playlist_dedup_seed_step(playlist_dedup_t *dedup,
playlist_t *playlist,
bool (*budget_cb)(void *userdata), void *userdata);
/**
* playlist_dedup_check_add:
*
* Returns what playlist_entry_exists(@playlist, @path) would
* return. When @will_add is true and the path was absent, the
* path is recorded in the index so that subsequent queries see it;
* the caller is expected to push the corresponding entry.
**/
bool playlist_dedup_check_add(playlist_dedup_t *dedup,
playlist_t *playlist, const char *path, bool will_add);
void playlist_dedup_free(playlist_dedup_t *dedup);
char *playlist_get_conf_path(playlist_t *playlist);
uint32_t playlist_get_size(playlist_t *playlist);
void playlist_write_file(playlist_t *playlist);
void playlist_write_runtime_file(playlist_t *playlist);
void playlist_qsort(playlist_t *playlist);
void playlist_free_cached(void);
playlist_t *playlist_get_cached(void);
/* If current on-disk playlist file referenced
* by 'config->path' does not match requested
* 'old format' or 'compression' state, file will
* be updated automatically
* > Since this function is called whenever a
* playlist is browsed via the menu, this is
* a simple method for ensuring that files
* are always kept synced with user settings */
bool playlist_init_cached(const playlist_config_t *config);
void command_playlist_push_write(
playlist_t *playlist,
const struct playlist_entry *entry);
void command_playlist_update_write(
playlist_t *playlist,
size_t idx,
const struct playlist_entry *entry);
/* Returns true if specified playlist index matches
* specified content/core paths */
bool playlist_index_is_valid(playlist_t *playlist, size_t idx,
const char *path, const char *core_path);
/* Returns true if specified playlist entries have
* identical content and core paths */
bool playlist_entries_are_equal(
const struct playlist_entry *entry_a,
const struct playlist_entry *entry_b,
const playlist_config_t *config);
/* Returns true if entries at specified indices
* of specified playlist have identical content
* and core paths */
bool playlist_index_entries_are_equal(
playlist_t *playlist, size_t idx_a, size_t idx_b);
void playlist_get_crc32(playlist_t *playlist, size_t idx,
const char **crc32);
/* If db_name is empty, 'returns' playlist file basename */
void playlist_get_db_name(playlist_t *playlist, size_t idx,
const char **db_name);
const char *playlist_get_default_core_path(playlist_t *playlist);
const char *playlist_get_default_core_name(playlist_t *playlist);
enum playlist_label_display_mode playlist_get_label_display_mode(playlist_t *playlist);
enum playlist_thumbnail_mode playlist_get_thumbnail_mode(
playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id);
bool playlist_thumbnail_match_with_filename(playlist_t *playlist);
enum playlist_sort_mode playlist_get_sort_mode(playlist_t *playlist);
const char *playlist_get_scan_content_dir(playlist_t *playlist);
const char *playlist_get_scan_file_exts(playlist_t *playlist);
const char *playlist_get_scan_dat_file_path(playlist_t *playlist);
const char *playlist_get_scan_database_name(playlist_t *playlist);
bool playlist_get_scan_search_recursively(playlist_t *playlist);
bool playlist_get_scan_search_archives(playlist_t *playlist);
bool playlist_get_scan_filter_dat_content(playlist_t *playlist);
bool playlist_get_scan_omit_db_ref(playlist_t *playlist);
bool playlist_get_scan_overwrite_playlist(playlist_t *playlist);
int playlist_get_scan_db_usage(playlist_t *playlist);
bool playlist_scan_refresh_enabled(playlist_t *playlist);
void playlist_set_default_core_path(playlist_t *playlist, const char *core_path);
void playlist_set_default_core_name(playlist_t *playlist, const char *core_name);
void playlist_set_label_display_mode(playlist_t *playlist, enum playlist_label_display_mode label_display_mode);
void playlist_set_thumbnail_mode(
playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id, enum playlist_thumbnail_mode thumbnail_mode);
void playlist_set_sort_mode(playlist_t *playlist, enum playlist_sort_mode sort_mode);
void playlist_set_scan_content_dir(playlist_t *playlist, const char *content_dir);
void playlist_set_scan_file_exts(playlist_t *playlist, const char *file_exts);
void playlist_set_scan_dat_file_path(playlist_t *playlist, const char *dat_file_path);
void playlist_set_scan_database_name(playlist_t *playlist, const char *database_name);
void playlist_set_scan_search_recursively(playlist_t *playlist, bool search_recursively);
void playlist_set_scan_search_archives(playlist_t *playlist, bool search_archives);
void playlist_set_scan_filter_dat_content(playlist_t *playlist, bool filter_dat_content);
void playlist_set_scan_omit_db_ref(playlist_t *playlist, bool omit_db_ref);
void playlist_set_scan_overwrite_playlist(playlist_t *playlist, bool overwrite_playlist);
void playlist_set_scan_db_usage(playlist_t *playlist, int db_usage);
/* Returns true if specified entry has a valid
* core association (i.e. a non-empty string
* other than DETECT) */
bool playlist_entry_has_core(const struct playlist_entry *entry);
/* Fetches core info object corresponding to the
* currently associated core of the specified
* playlist entry.
* Returns NULL if entry does not have a valid
* core association */
core_info_t *playlist_entry_get_core_info(const struct playlist_entry* entry);
/* Fetches core info object corresponding to the
* currently associated default core of the
* specified playlist.
* Returns NULL if playlist does not have a valid
* default core association */
core_info_t *playlist_get_default_core_info(playlist_t* playlist);
void playlist_set_cached_external(playlist_t* pl);
RETRO_END_DECLS
#endif