mirror of
https://github.com/libretro/RetroArch
synced 2025-04-04 22:20:25 +00:00
(playlist.c) Cleanups
This commit is contained in:
parent
cf909b799b
commit
d54097f3e1
116
playlist.c
116
playlist.c
@ -314,9 +314,9 @@ static bool playlist_path_equal(const char *real_path,
|
|||||||
char entry_real_path[PATH_MAX_LENGTH];
|
char entry_real_path[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (string_is_empty(real_path) ||
|
if ( string_is_empty(real_path)
|
||||||
string_is_empty(entry_path) ||
|
|| string_is_empty(entry_path)
|
||||||
!config)
|
|| !config)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Get entry 'real' path */
|
/* Get entry 'real' path */
|
||||||
@ -403,9 +403,7 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id,
|
|||||||
struct playlist_entry *entry, const playlist_config_t *config)
|
struct playlist_entry *entry, const playlist_config_t *config)
|
||||||
{
|
{
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (!path_id ||
|
if (!path_id || !entry || !config)
|
||||||
!entry ||
|
|
||||||
!config)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Check whether entry contains a path ID cache */
|
/* Check whether entry contains a path ID cache */
|
||||||
@ -416,13 +414,12 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure we have valid real_path strings */
|
/* Ensure we have valid real_path strings */
|
||||||
if (string_is_empty(path_id->real_path) ||
|
if ( string_is_empty(path_id->real_path)
|
||||||
string_is_empty(entry->path_id->real_path))
|
|| string_is_empty(entry->path_id->real_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* First pass comparison */
|
/* First pass comparison */
|
||||||
if (path_id->real_path_hash ==
|
if (path_id->real_path_hash == entry->path_id->real_path_hash)
|
||||||
entry->path_id->real_path_hash)
|
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Handle case-insensitive operating systems*/
|
/* Handle case-insensitive operating systems*/
|
||||||
@ -461,12 +458,11 @@ static bool playlist_path_matches_entry(playlist_path_id_t *path_id,
|
|||||||
{
|
{
|
||||||
/* Ensure we have valid parent archive path
|
/* Ensure we have valid parent archive path
|
||||||
* strings */
|
* strings */
|
||||||
if (string_is_empty(path_id->archive_path) ||
|
if ( string_is_empty(path_id->archive_path)
|
||||||
string_is_empty(entry->path_id->archive_path))
|
|| string_is_empty(entry->path_id->archive_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (path_id->archive_path_hash ==
|
if (path_id->archive_path_hash == entry->path_id->archive_path_hash)
|
||||||
entry->path_id->archive_path_hash)
|
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
/* Handle case-insensitive operating systems*/
|
/* Handle case-insensitive operating systems*/
|
||||||
@ -499,13 +495,14 @@ static bool playlist_core_path_equal(const char *real_core_path, const char *ent
|
|||||||
char entry_real_core_path[PATH_MAX_LENGTH];
|
char entry_real_core_path[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
/* Sanity check */
|
/* Sanity check */
|
||||||
if (string_is_empty(real_core_path) || string_is_empty(entry_core_path))
|
if ( string_is_empty(real_core_path)
|
||||||
|
|| string_is_empty(entry_core_path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Get entry 'real' core path */
|
/* Get entry 'real' core path */
|
||||||
strlcpy(entry_real_core_path, entry_core_path, sizeof(entry_real_core_path));
|
strlcpy(entry_real_core_path, entry_core_path, sizeof(entry_real_core_path));
|
||||||
if (!string_is_equal(entry_real_core_path, FILE_PATH_DETECT) &&
|
if ( !string_is_equal(entry_real_core_path, FILE_PATH_DETECT)
|
||||||
!string_is_equal(entry_real_core_path, FILE_PATH_BUILTIN))
|
&& !string_is_equal(entry_real_core_path, FILE_PATH_BUILTIN))
|
||||||
playlist_resolve_path(PLAYLIST_SAVE, true, entry_real_core_path,
|
playlist_resolve_path(PLAYLIST_SAVE, true, entry_real_core_path,
|
||||||
sizeof(entry_real_core_path));
|
sizeof(entry_real_core_path));
|
||||||
|
|
||||||
@ -521,8 +518,8 @@ static bool playlist_core_path_equal(const char *real_core_path, const char *ent
|
|||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (config->autofix_paths &&
|
if ( config->autofix_paths
|
||||||
core_info_core_file_id_is_equal(real_core_path, entry_core_path))
|
&& core_info_core_file_id_is_equal(real_core_path, entry_core_path))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@ -951,8 +948,8 @@ bool playlist_push_runtime(playlist_t *playlist,
|
|||||||
|
|
||||||
/* Get 'real' core path */
|
/* Get 'real' core path */
|
||||||
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
||||||
if (!string_is_equal(real_core_path, FILE_PATH_DETECT) &&
|
if ( !string_is_equal(real_core_path, FILE_PATH_DETECT)
|
||||||
!string_is_equal(real_core_path, FILE_PATH_BUILTIN))
|
&& !string_is_equal(real_core_path, FILE_PATH_BUILTIN))
|
||||||
playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path,
|
playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path,
|
||||||
sizeof(real_core_path));
|
sizeof(real_core_path));
|
||||||
|
|
||||||
@ -966,8 +963,8 @@ bool playlist_push_runtime(playlist_t *playlist,
|
|||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
struct playlist_entry tmp;
|
struct playlist_entry tmp;
|
||||||
bool equal_path = (string_is_empty(path_id->real_path) &&
|
bool equal_path = (string_is_empty(path_id->real_path)
|
||||||
string_is_empty(playlist->entries[i].path));
|
&& string_is_empty(playlist->entries[i].path));
|
||||||
|
|
||||||
equal_path = equal_path || playlist_path_matches_entry(
|
equal_path = equal_path || playlist_path_matches_entry(
|
||||||
path_id, &playlist->entries[i], &playlist->config);
|
path_id, &playlist->entries[i], &playlist->config);
|
||||||
@ -1226,8 +1223,8 @@ bool playlist_push(playlist_t *playlist,
|
|||||||
|
|
||||||
/* Get 'real' core path */
|
/* Get 'real' core path */
|
||||||
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
||||||
if (!string_is_equal(real_core_path, FILE_PATH_DETECT) &&
|
if ( !string_is_equal(real_core_path, FILE_PATH_DETECT)
|
||||||
!string_is_equal(real_core_path, FILE_PATH_BUILTIN))
|
&& !string_is_equal(real_core_path, FILE_PATH_BUILTIN))
|
||||||
playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path,
|
playlist_resolve_path(PLAYLIST_SAVE, true, real_core_path,
|
||||||
sizeof(real_core_path));
|
sizeof(real_core_path));
|
||||||
|
|
||||||
@ -1256,8 +1253,8 @@ bool playlist_push(playlist_t *playlist,
|
|||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
struct playlist_entry tmp;
|
struct playlist_entry tmp;
|
||||||
bool equal_path = (string_is_empty(path_id->real_path) &&
|
bool equal_path = (string_is_empty(path_id->real_path)
|
||||||
string_is_empty(playlist->entries[i].path));
|
&& string_is_empty(playlist->entries[i].path));
|
||||||
|
|
||||||
equal_path = equal_path || playlist_path_matches_entry(
|
equal_path = equal_path || playlist_path_matches_entry(
|
||||||
path_id, &playlist->entries[i], &playlist->config);
|
path_id, &playlist->entries[i], &playlist->config);
|
||||||
@ -2182,9 +2179,11 @@ static bool JSONEndObjectHandler(void *context)
|
|||||||
{
|
{
|
||||||
JSONContext *pCtx = (JSONContext *)context;
|
JSONContext *pCtx = (JSONContext *)context;
|
||||||
|
|
||||||
if (pCtx->in_items && pCtx->object_depth == 2)
|
if ( pCtx->in_items
|
||||||
|
&& pCtx->object_depth == 2)
|
||||||
{
|
{
|
||||||
if ((pCtx->array_depth == 1) && !pCtx->capacity_exceeded)
|
if ( (pCtx->array_depth == 1)
|
||||||
|
&& !pCtx->capacity_exceeded)
|
||||||
RBUF_RESIZE(pCtx->playlist->entries,
|
RBUF_RESIZE(pCtx->playlist->entries,
|
||||||
RBUF_LEN(pCtx->playlist->entries) + 1);
|
RBUF_LEN(pCtx->playlist->entries) + 1);
|
||||||
}
|
}
|
||||||
@ -2293,10 +2292,10 @@ static bool JSONBoolHandler(void *context, bool value)
|
|||||||
{
|
{
|
||||||
JSONContext *pCtx = (JSONContext *)context;
|
JSONContext *pCtx = (JSONContext *)context;
|
||||||
|
|
||||||
if (!pCtx->in_items &&
|
if ( !pCtx->in_items
|
||||||
(pCtx->object_depth == 1) &&
|
&& (pCtx->object_depth == 1)
|
||||||
(pCtx->array_depth == 0) &&
|
&& (pCtx->array_depth == 0)
|
||||||
pCtx->current_meta_bool_val)
|
&& pCtx->current_meta_bool_val)
|
||||||
*pCtx->current_meta_bool_val = value;
|
*pCtx->current_meta_bool_val = value;
|
||||||
|
|
||||||
pCtx->current_meta_bool_val = NULL;
|
pCtx->current_meta_bool_val = NULL;
|
||||||
@ -2313,11 +2312,9 @@ static bool JSONObjectMemberHandler(void *context, const char *pValue, size_t le
|
|||||||
{
|
{
|
||||||
if (pCtx->array_depth == 1)
|
if (pCtx->array_depth == 1)
|
||||||
{
|
{
|
||||||
|
/* Something went wrong */
|
||||||
if (pCtx->current_string_val)
|
if (pCtx->current_string_val)
|
||||||
{
|
|
||||||
/* something went wrong */
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
|
|
||||||
if (length && !pCtx->capacity_exceeded)
|
if (length && !pCtx->capacity_exceeded)
|
||||||
{
|
{
|
||||||
@ -2652,8 +2649,8 @@ static bool playlist_read_file(playlist_t *playlist)
|
|||||||
|
|
||||||
/* > Populate default core path/name, if required
|
/* > Populate default core path/name, if required
|
||||||
* (if one is empty, the other should be ignored) */
|
* (if one is empty, the other should be ignored) */
|
||||||
if (!string_is_empty(default_core_path) &&
|
if ( !string_is_empty(default_core_path)
|
||||||
!string_is_empty(default_core_name))
|
&& !string_is_empty(default_core_name))
|
||||||
{
|
{
|
||||||
playlist->default_core_path = strdup(default_core_path);
|
playlist->default_core_path = strdup(default_core_path);
|
||||||
playlist->default_core_name = strdup(default_core_name);
|
playlist->default_core_name = strdup(default_core_name);
|
||||||
@ -2871,8 +2868,10 @@ playlist_t *playlist_init(const playlist_config_t *config)
|
|||||||
|
|
||||||
tmp_entry_path[0] = '\0';
|
tmp_entry_path[0] = '\0';
|
||||||
path_replace_base_path_and_convert_to_local_file_system(
|
path_replace_base_path_and_convert_to_local_file_system(
|
||||||
tmp_entry_path, subsystem_rom_path,
|
tmp_entry_path,
|
||||||
playlist->base_content_directory, playlist->config.base_content_directory,
|
subsystem_rom_path,
|
||||||
|
playlist->base_content_directory,
|
||||||
|
playlist->config.base_content_directory,
|
||||||
sizeof(tmp_entry_path));
|
sizeof(tmp_entry_path));
|
||||||
string_list_append(subsystem_roms_new_paths, tmp_entry_path, attributes);
|
string_list_append(subsystem_roms_new_paths, tmp_entry_path, attributes);
|
||||||
}
|
}
|
||||||
@ -2887,8 +2886,10 @@ playlist_t *playlist_init(const playlist_config_t *config)
|
|||||||
{
|
{
|
||||||
tmp_entry_path[0] = '\0';
|
tmp_entry_path[0] = '\0';
|
||||||
path_replace_base_path_and_convert_to_local_file_system(
|
path_replace_base_path_and_convert_to_local_file_system(
|
||||||
tmp_entry_path, playlist->scan_record.content_dir,
|
tmp_entry_path,
|
||||||
playlist->base_content_directory, playlist->config.base_content_directory,
|
playlist->scan_record.content_dir,
|
||||||
|
playlist->base_content_directory,
|
||||||
|
playlist->config.base_content_directory,
|
||||||
sizeof(tmp_entry_path));
|
sizeof(tmp_entry_path));
|
||||||
|
|
||||||
free(playlist->scan_record.content_dir);
|
free(playlist->scan_record.content_dir);
|
||||||
@ -2900,8 +2901,10 @@ playlist_t *playlist_init(const playlist_config_t *config)
|
|||||||
{
|
{
|
||||||
tmp_entry_path[0] = '\0';
|
tmp_entry_path[0] = '\0';
|
||||||
path_replace_base_path_and_convert_to_local_file_system(
|
path_replace_base_path_and_convert_to_local_file_system(
|
||||||
tmp_entry_path, playlist->scan_record.dat_file_path,
|
tmp_entry_path,
|
||||||
playlist->base_content_directory, playlist->config.base_content_directory,
|
playlist->scan_record.dat_file_path,
|
||||||
|
playlist->base_content_directory,
|
||||||
|
playlist->config.base_content_directory,
|
||||||
sizeof(tmp_entry_path));
|
sizeof(tmp_entry_path));
|
||||||
|
|
||||||
free(playlist->scan_record.dat_file_path);
|
free(playlist->scan_record.dat_file_path);
|
||||||
@ -2953,7 +2956,8 @@ static int playlist_qsort_func(const struct playlist_entry *a,
|
|||||||
if (!string_is_empty(a->path))
|
if (!string_is_empty(a->path))
|
||||||
fill_pathname(a_fallback_label,
|
fill_pathname(a_fallback_label,
|
||||||
path_basename_nocompression(a->path),
|
path_basename_nocompression(a->path),
|
||||||
"", PATH_MAX_LENGTH * sizeof(char));
|
"",
|
||||||
|
PATH_MAX_LENGTH * sizeof(char));
|
||||||
/* If filename is also empty, use core name
|
/* If filename is also empty, use core name
|
||||||
* instead -> this matches the behaviour of
|
* instead -> this matches the behaviour of
|
||||||
* menu_displaylist_parse_playlist() */
|
* menu_displaylist_parse_playlist() */
|
||||||
@ -2975,7 +2979,8 @@ static int playlist_qsort_func(const struct playlist_entry *a,
|
|||||||
|
|
||||||
if (!string_is_empty(b->path))
|
if (!string_is_empty(b->path))
|
||||||
fill_pathname(b_fallback_label,
|
fill_pathname(b_fallback_label,
|
||||||
path_basename_nocompression(b->path), "",
|
path_basename_nocompression(b->path),
|
||||||
|
"",
|
||||||
PATH_MAX_LENGTH * sizeof(char));
|
PATH_MAX_LENGTH * sizeof(char));
|
||||||
else if (!string_is_empty(b->core_name))
|
else if (!string_is_empty(b->core_name))
|
||||||
strlcpy(b_fallback_label, b->core_name, PATH_MAX_LENGTH * sizeof(char));
|
strlcpy(b_fallback_label, b->core_name, PATH_MAX_LENGTH * sizeof(char));
|
||||||
@ -3009,9 +3014,9 @@ void playlist_qsort(playlist_t *playlist)
|
|||||||
{
|
{
|
||||||
/* Avoid inadvertent sorting if 'sort mode'
|
/* Avoid inadvertent sorting if 'sort mode'
|
||||||
* has been set explicitly to PLAYLIST_SORT_MODE_OFF */
|
* has been set explicitly to PLAYLIST_SORT_MODE_OFF */
|
||||||
if (!playlist ||
|
if ( !playlist
|
||||||
(playlist->sort_mode == PLAYLIST_SORT_MODE_OFF) ||
|
|| !playlist->entries
|
||||||
!playlist->entries)
|
|| (playlist->sort_mode == PLAYLIST_SORT_MODE_OFF))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
qsort(playlist->entries, RBUF_LEN(playlist->entries),
|
qsort(playlist->entries, RBUF_LEN(playlist->entries),
|
||||||
@ -3054,8 +3059,9 @@ bool playlist_index_is_valid(playlist_t *playlist, size_t idx,
|
|||||||
if (idx >= RBUF_LEN(playlist->entries))
|
if (idx >= RBUF_LEN(playlist->entries))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return playlist_path_equal(path, playlist->entries[idx].path, &playlist->config) &&
|
return playlist_path_equal(path, playlist->entries[idx].path, &playlist->config)
|
||||||
string_is_equal(path_basename_nocompression(playlist->entries[idx].core_path), path_basename_nocompression(core_path));
|
&& string_is_equal(path_basename_nocompression(playlist->entries[idx].core_path),
|
||||||
|
path_basename_nocompression(core_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool playlist_entries_are_equal(
|
bool playlist_entries_are_equal(
|
||||||
@ -3093,8 +3099,8 @@ bool playlist_entries_are_equal(
|
|||||||
if (!string_is_empty(entry_a->core_path))
|
if (!string_is_empty(entry_a->core_path))
|
||||||
{
|
{
|
||||||
strlcpy(real_core_path_a, entry_a->core_path, sizeof(real_core_path_a));
|
strlcpy(real_core_path_a, entry_a->core_path, sizeof(real_core_path_a));
|
||||||
if (!string_is_equal(real_core_path_a, FILE_PATH_DETECT) &&
|
if ( !string_is_equal(real_core_path_a, FILE_PATH_DETECT)
|
||||||
!string_is_equal(real_core_path_a, FILE_PATH_BUILTIN))
|
&& !string_is_equal(real_core_path_a, FILE_PATH_BUILTIN))
|
||||||
playlist_resolve_path(PLAYLIST_SAVE, true,
|
playlist_resolve_path(PLAYLIST_SAVE, true,
|
||||||
real_core_path_a, sizeof(real_core_path_a));
|
real_core_path_a, sizeof(real_core_path_a));
|
||||||
}
|
}
|
||||||
@ -3278,8 +3284,8 @@ void playlist_set_default_core_path(playlist_t *playlist,
|
|||||||
|
|
||||||
/* Get 'real' core path */
|
/* Get 'real' core path */
|
||||||
strlcpy(real_core_path, core_path, sizeof(real_core_path));
|
strlcpy(real_core_path, core_path, sizeof(real_core_path));
|
||||||
if (!string_is_equal(real_core_path, FILE_PATH_DETECT) &&
|
if ( !string_is_equal(real_core_path, FILE_PATH_DETECT)
|
||||||
!string_is_equal(real_core_path, FILE_PATH_BUILTIN))
|
&& !string_is_equal(real_core_path, FILE_PATH_BUILTIN))
|
||||||
playlist_resolve_path(PLAYLIST_SAVE, true,
|
playlist_resolve_path(PLAYLIST_SAVE, true,
|
||||||
real_core_path, sizeof(real_core_path));
|
real_core_path, sizeof(real_core_path));
|
||||||
|
|
||||||
|
@ -71,10 +71,6 @@ enum playlist_sort_mode
|
|||||||
PLAYLIST_SORT_MODE_OFF
|
PLAYLIST_SORT_MODE_OFF
|
||||||
};
|
};
|
||||||
|
|
||||||
/* TODO/FIXME - since gfx_thumbnail_path.h has now
|
|
||||||
* been divorced from the menu code, perhaps jdgleaver
|
|
||||||
* can refactor this? */
|
|
||||||
|
|
||||||
/* Note: We already have a left/right enum defined
|
/* Note: We already have a left/right enum defined
|
||||||
* in gfx_thumbnail_path.h - but we can't include
|
* in gfx_thumbnail_path.h - but we can't include
|
||||||
* menu code here, so have to make a 'duplicate'... */
|
* menu code here, so have to make a 'duplicate'... */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user