2013-04-27 22:15:59 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2017-03-22 02:09:18 +00:00
|
|
|
* Copyright (C) 2011-2017 - Daniel De Matteis
|
2019-04-12 16:50:27 +00:00
|
|
|
* Copyright (C) 2016-2019 - Brad Parker
|
2017-12-12 07:55:31 +00:00
|
|
|
*
|
2013-04-27 22:15:59 +00:00
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2019-07-17 20:34:17 +00:00
|
|
|
#include <ctype.h>
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2017-12-11 11:15:00 +00:00
|
|
|
#include <libretro.h>
|
2015-06-29 22:38:10 +00:00
|
|
|
#include <boolean.h>
|
2019-01-12 18:46:28 +00:00
|
|
|
#include <retro_assert.h>
|
2015-06-29 22:38:10 +00:00
|
|
|
#include <compat/posix_string.h>
|
2016-01-20 03:07:24 +00:00
|
|
|
#include <string/stdstring.h>
|
2017-12-11 11:57:53 +00:00
|
|
|
#include <streams/interface_stream.h>
|
2016-06-02 22:12:58 +00:00
|
|
|
#include <streams/file_stream.h>
|
2016-07-23 00:53:48 +00:00
|
|
|
#include <file/file_path.h>
|
2019-04-11 04:09:13 +00:00
|
|
|
#include <lists/string_list.h>
|
2019-01-09 22:13:13 +00:00
|
|
|
#include <formats/jsonsax_full.h>
|
2015-06-29 22:38:10 +00:00
|
|
|
|
|
|
|
#include "playlist.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "verbosity.h"
|
2019-01-09 22:13:13 +00:00
|
|
|
#include "configuration.h"
|
2019-03-09 13:48:06 +00:00
|
|
|
#include "file_path_special.h"
|
2015-06-29 22:38:10 +00:00
|
|
|
|
2016-01-23 18:39:18 +00:00
|
|
|
#ifndef PLAYLIST_ENTRIES
|
|
|
|
#define PLAYLIST_ENTRIES 6
|
|
|
|
#endif
|
|
|
|
|
2017-07-01 01:38:36 +00:00
|
|
|
struct content_playlist
|
|
|
|
{
|
2017-09-29 03:13:10 +00:00
|
|
|
bool modified;
|
2017-07-01 01:38:36 +00:00
|
|
|
size_t size;
|
|
|
|
size_t cap;
|
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
enum playlist_label_display_mode label_display_mode;
|
|
|
|
enum playlist_thumbnail_mode right_thumbnail_mode;
|
|
|
|
enum playlist_thumbnail_mode left_thumbnail_mode;
|
|
|
|
|
2017-07-01 01:38:36 +00:00
|
|
|
char *conf_path;
|
2019-06-26 16:40:00 +00:00
|
|
|
char *default_core_path;
|
|
|
|
char *default_core_name;
|
2017-09-29 03:13:10 +00:00
|
|
|
struct playlist_entry *entries;
|
2017-07-01 01:38:36 +00:00
|
|
|
};
|
2019-01-09 22:13:13 +00:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
JSON_Parser parser;
|
|
|
|
JSON_Writer writer;
|
|
|
|
RFILE *file;
|
|
|
|
playlist_t *playlist;
|
|
|
|
struct playlist_entry *current_entry;
|
|
|
|
unsigned array_depth;
|
|
|
|
unsigned object_depth;
|
2019-01-12 18:46:28 +00:00
|
|
|
char **current_entry_val;
|
2019-02-12 05:32:01 +00:00
|
|
|
int *current_entry_int_val;
|
|
|
|
unsigned *current_entry_uint_val;
|
2019-04-11 04:09:13 +00:00
|
|
|
struct string_list **current_entry_string_list_val;
|
2019-01-12 18:46:28 +00:00
|
|
|
char *current_meta_string;
|
2019-06-26 16:40:00 +00:00
|
|
|
char **current_meta_val;
|
2019-08-27 16:10:35 +00:00
|
|
|
enum playlist_label_display_mode *current_meta_label_display_mode_val;
|
|
|
|
enum playlist_thumbnail_mode *current_meta_thumbnail_mode_val;
|
2019-04-11 04:09:13 +00:00
|
|
|
char *current_items_string;
|
2019-01-12 18:46:28 +00:00
|
|
|
bool in_items;
|
2019-04-11 04:09:13 +00:00
|
|
|
bool in_subsystem_roms;
|
2019-07-30 16:11:43 +00:00
|
|
|
bool capacity_exceeded;
|
2019-01-09 22:13:13 +00:00
|
|
|
} JSONContext;
|
|
|
|
|
2018-04-10 15:40:29 +00:00
|
|
|
static playlist_t *playlist_cached = NULL;
|
2017-07-01 01:38:36 +00:00
|
|
|
|
2016-08-28 16:47:34 +00:00
|
|
|
typedef int (playlist_sort_fun_t)(
|
|
|
|
const struct playlist_entry *a,
|
|
|
|
const struct playlist_entry *b);
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
/**
|
|
|
|
* playlist_path_equal:
|
|
|
|
* @real_path : 'Real' search path, generated by path_resolve_realpath()
|
|
|
|
* @entry_path : Existing playlist entry 'path' value
|
|
|
|
*
|
|
|
|
* Returns 'true' if real_path matches entry_path
|
|
|
|
* (Taking into account relative paths, case insensitive
|
|
|
|
* filesystems, 'incomplete' archive paths)
|
|
|
|
**/
|
|
|
|
static bool playlist_path_equal(const char *real_path, const char *entry_path)
|
|
|
|
{
|
|
|
|
bool real_path_is_compressed;
|
|
|
|
bool entry_real_path_is_compressed;
|
|
|
|
char entry_real_path[PATH_MAX_LENGTH];
|
2019-05-21 20:38:50 +00:00
|
|
|
#ifdef RARCH_INTERNAL
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
#endif
|
2019-05-02 08:56:04 +00:00
|
|
|
|
|
|
|
entry_real_path[0] = '\0';
|
|
|
|
|
|
|
|
/* Sanity check */
|
2019-05-21 20:38:50 +00:00
|
|
|
if (string_is_empty(real_path) || string_is_empty(entry_path))
|
2019-05-02 08:56:04 +00:00
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Get entry 'real' path */
|
|
|
|
strlcpy(entry_real_path, entry_path, sizeof(entry_real_path));
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(entry_real_path, sizeof(entry_real_path), true);
|
2019-05-02 08:56:04 +00:00
|
|
|
|
|
|
|
if (string_is_empty(entry_real_path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* First pass comparison */
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* Handle case-insensitive operating systems*/
|
|
|
|
if (string_is_equal_noncase(real_path, entry_real_path))
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
if (string_is_equal(real_path, entry_real_path))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
2019-05-21 20:38:50 +00:00
|
|
|
#ifdef RARCH_INTERNAL
|
2019-05-02 08:56:04 +00:00
|
|
|
/* If fuzzy matching is disabled, we can give up now */
|
2019-05-21 20:38:50 +00:00
|
|
|
if (!settings || !settings->bools.playlist_fuzzy_archive_match)
|
2019-05-02 08:56:04 +00:00
|
|
|
return false;
|
2019-05-21 20:38:50 +00:00
|
|
|
#endif
|
2019-05-02 08:56:04 +00:00
|
|
|
|
|
|
|
/* If we reach this point, we have to work
|
|
|
|
* harder...
|
|
|
|
* Need to handle a rather awkward archive file
|
|
|
|
* case where:
|
|
|
|
* - playlist path contains a properly formatted
|
|
|
|
* [archive_path][delimiter][rom_file]
|
|
|
|
* - search path is just [archive_path]
|
|
|
|
* ...or vice versa.
|
|
|
|
* This pretty much always happens when a playlist
|
|
|
|
* is generated via scan content (which handles the
|
|
|
|
* archive paths correctly), but the user subsequently
|
|
|
|
* loads an archive file via the command line or some
|
|
|
|
* external launcher (where the [delimiter][rom_file]
|
|
|
|
* part is almost always omitted) */
|
|
|
|
real_path_is_compressed = path_is_compressed_file(real_path);
|
|
|
|
entry_real_path_is_compressed = path_is_compressed_file(entry_real_path);
|
|
|
|
|
|
|
|
if ((real_path_is_compressed && !entry_real_path_is_compressed) ||
|
|
|
|
(!real_path_is_compressed && entry_real_path_is_compressed))
|
|
|
|
{
|
|
|
|
const char *compressed_path_a = real_path_is_compressed ? real_path : entry_real_path;
|
|
|
|
const char *full_path = real_path_is_compressed ? entry_real_path : real_path;
|
|
|
|
const char *delim = path_get_archive_delim(full_path);
|
|
|
|
|
|
|
|
if (delim)
|
|
|
|
{
|
|
|
|
char compressed_path_b[PATH_MAX_LENGTH] = {0};
|
2019-06-22 11:44:10 +00:00
|
|
|
unsigned len = (unsigned)(1 + delim - full_path);
|
2019-05-02 08:56:04 +00:00
|
|
|
|
|
|
|
strlcpy(compressed_path_b, full_path,
|
|
|
|
(len < PATH_MAX_LENGTH ? len : PATH_MAX_LENGTH) * sizeof(char));
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* Handle case-insensitive operating systems*/
|
|
|
|
if (string_is_equal_noncase(compressed_path_a, compressed_path_b))
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
if (string_is_equal(compressed_path_a, compressed_path_b))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* playlist_core_path_equal:
|
|
|
|
* @real_core_path : 'Real' search path, generated by path_resolve_realpath()
|
|
|
|
* @entry_core_path : Existing playlist entry 'core path' value
|
|
|
|
*
|
|
|
|
* Returns 'true' if real_core_path matches entry_core_path
|
|
|
|
* (Taking into account relative paths, case insensitive
|
|
|
|
* filesystems)
|
|
|
|
**/
|
|
|
|
static bool playlist_core_path_equal(const char *real_core_path, const char *entry_core_path)
|
|
|
|
{
|
|
|
|
char entry_real_core_path[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
entry_real_core_path[0] = '\0';
|
|
|
|
|
|
|
|
/* Sanity check */
|
|
|
|
if (string_is_empty(real_core_path) || string_is_empty(entry_core_path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Get entry 'real' core path */
|
|
|
|
strlcpy(entry_real_core_path, entry_core_path, sizeof(entry_real_core_path));
|
2019-05-05 11:46:06 +00:00
|
|
|
if (!string_is_equal(entry_real_core_path, file_path_str(FILE_PATH_DETECT)))
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(entry_real_core_path, sizeof(entry_real_core_path), true);
|
2019-05-02 08:56:04 +00:00
|
|
|
|
|
|
|
if (string_is_empty(entry_real_core_path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
/* Handle case-insensitive operating systems*/
|
|
|
|
if (string_is_equal_noncase(real_core_path, entry_real_core_path))
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
if (string_is_equal(real_core_path, entry_real_core_path))
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-07-01 01:38:36 +00:00
|
|
|
uint32_t playlist_get_size(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return 0;
|
|
|
|
return (uint32_t)playlist->size;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *playlist_get_conf_path(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return NULL;
|
|
|
|
return playlist->conf_path;
|
|
|
|
}
|
|
|
|
|
2015-01-16 19:19:21 +00:00
|
|
|
/**
|
2016-05-16 07:07:44 +00:00
|
|
|
* playlist_get_index:
|
2016-05-06 18:20:16 +00:00
|
|
|
* @playlist : Playlist handle.
|
2015-01-16 19:19:21 +00:00
|
|
|
* @idx : Index of playlist entry.
|
|
|
|
* @path : Path of playlist entry.
|
|
|
|
* @core_path : Core path of playlist entry.
|
|
|
|
* @core_name : Core name of playlist entry.
|
2017-12-12 07:55:31 +00:00
|
|
|
*
|
|
|
|
* Gets values of playlist index:
|
2015-01-16 19:19:21 +00:00
|
|
|
**/
|
2016-05-16 07:07:44 +00:00
|
|
|
void playlist_get_index(playlist_t *playlist,
|
2014-10-20 17:22:33 +00:00
|
|
|
size_t idx,
|
2019-04-12 16:50:27 +00:00
|
|
|
const struct playlist_entry **entry)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2019-04-12 16:50:27 +00:00
|
|
|
if (!playlist || !entry)
|
2014-06-01 00:16:48 +00:00
|
|
|
return;
|
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
*entry = &playlist->entries[idx];
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:11:43 +00:00
|
|
|
/**
|
|
|
|
* playlist_free_entry:
|
|
|
|
* @entry : Playlist entry handle.
|
|
|
|
*
|
|
|
|
* Frees playlist entry.
|
|
|
|
**/
|
|
|
|
static void playlist_free_entry(struct playlist_entry *entry)
|
|
|
|
{
|
|
|
|
if (!entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (entry->path != NULL)
|
|
|
|
free(entry->path);
|
|
|
|
if (entry->label != NULL)
|
|
|
|
free(entry->label);
|
|
|
|
if (entry->core_path != NULL)
|
|
|
|
free(entry->core_path);
|
|
|
|
if (entry->core_name != NULL)
|
|
|
|
free(entry->core_name);
|
|
|
|
if (entry->db_name != NULL)
|
|
|
|
free(entry->db_name);
|
|
|
|
if (entry->crc32 != NULL)
|
|
|
|
free(entry->crc32);
|
|
|
|
if (entry->subsystem_ident != NULL)
|
|
|
|
free(entry->subsystem_ident);
|
|
|
|
if (entry->subsystem_name != NULL)
|
|
|
|
free(entry->subsystem_name);
|
2019-09-10 15:13:25 +00:00
|
|
|
if (entry->runtime_str != NULL)
|
|
|
|
free(entry->runtime_str);
|
|
|
|
if (entry->last_played_str != NULL)
|
|
|
|
free(entry->last_played_str);
|
2019-07-30 16:11:43 +00:00
|
|
|
if (entry->subsystem_roms != NULL)
|
|
|
|
string_list_free(entry->subsystem_roms);
|
|
|
|
|
|
|
|
entry->path = NULL;
|
|
|
|
entry->label = NULL;
|
|
|
|
entry->core_path = NULL;
|
|
|
|
entry->core_name = NULL;
|
|
|
|
entry->db_name = NULL;
|
|
|
|
entry->crc32 = NULL;
|
|
|
|
entry->subsystem_ident = NULL;
|
|
|
|
entry->subsystem_name = NULL;
|
2019-09-10 15:13:25 +00:00
|
|
|
entry->runtime_str = NULL;
|
|
|
|
entry->last_played_str = NULL;
|
2019-07-30 16:11:43 +00:00
|
|
|
entry->subsystem_roms = NULL;
|
|
|
|
entry->runtime_status = PLAYLIST_RUNTIME_UNKNOWN;
|
|
|
|
entry->runtime_hours = 0;
|
|
|
|
entry->runtime_minutes = 0;
|
|
|
|
entry->runtime_seconds = 0;
|
|
|
|
entry->last_played_year = 0;
|
|
|
|
entry->last_played_month = 0;
|
|
|
|
entry->last_played_day = 0;
|
|
|
|
entry->last_played_hour = 0;
|
|
|
|
entry->last_played_minute = 0;
|
|
|
|
entry->last_played_second = 0;
|
|
|
|
}
|
|
|
|
|
2016-08-28 23:17:02 +00:00
|
|
|
/**
|
|
|
|
* playlist_delete_index:
|
|
|
|
* @playlist : Playlist handle.
|
|
|
|
* @idx : Index of playlist entry.
|
2017-12-12 07:55:31 +00:00
|
|
|
*
|
|
|
|
* Delete the entry at the index:
|
2016-08-28 23:17:02 +00:00
|
|
|
**/
|
|
|
|
void playlist_delete_index(playlist_t *playlist,
|
|
|
|
size_t idx)
|
|
|
|
{
|
2019-07-30 16:11:43 +00:00
|
|
|
struct playlist_entry *entry_to_delete = NULL;
|
|
|
|
|
2016-08-28 23:17:02 +00:00
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
2019-07-30 16:11:43 +00:00
|
|
|
if (idx >= playlist->size)
|
|
|
|
return;
|
|
|
|
|
2019-01-09 04:08:58 +00:00
|
|
|
playlist->size = playlist->size - 1;
|
|
|
|
|
2019-07-30 16:11:43 +00:00
|
|
|
/* Free unwanted entry */
|
|
|
|
entry_to_delete = (struct playlist_entry *)(playlist->entries + idx);
|
|
|
|
if (entry_to_delete)
|
|
|
|
playlist_free_entry(entry_to_delete);
|
|
|
|
|
|
|
|
/* Shift remaining entries to fill the gap */
|
2016-08-28 23:38:46 +00:00
|
|
|
memmove(playlist->entries + idx, playlist->entries + idx + 1,
|
|
|
|
(playlist->size - idx) * sizeof(struct playlist_entry));
|
2016-08-28 23:17:02 +00:00
|
|
|
|
2017-04-23 10:54:13 +00:00
|
|
|
playlist->modified = true;
|
2016-08-28 23:17:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
void playlist_get_index_by_path(playlist_t *playlist,
|
2015-02-03 03:12:32 +00:00
|
|
|
const char *search_path,
|
2019-04-12 16:50:27 +00:00
|
|
|
const struct playlist_entry **entry)
|
2015-02-03 03:12:32 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2019-05-02 08:56:04 +00:00
|
|
|
char real_search_path[PATH_MAX_LENGTH];
|
2019-04-12 16:50:27 +00:00
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
real_search_path[0] = '\0';
|
|
|
|
|
|
|
|
if (!playlist || !entry || string_is_empty(search_path))
|
2015-02-03 03:12:32 +00:00
|
|
|
return;
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
/* Get 'real' search path */
|
|
|
|
strlcpy(real_search_path, search_path, sizeof(real_search_path));
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(real_search_path, sizeof(real_search_path), true);
|
2019-05-02 08:56:04 +00:00
|
|
|
|
2015-02-03 03:12:32 +00:00
|
|
|
for (i = 0; i < playlist->size; i++)
|
|
|
|
{
|
2019-05-02 08:56:04 +00:00
|
|
|
if (!playlist_path_equal(real_search_path, playlist->entries[i].path))
|
2015-02-03 03:12:32 +00:00
|
|
|
continue;
|
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
*entry = &playlist->entries[i];
|
|
|
|
|
2015-02-03 03:12:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
bool playlist_entry_exists(playlist_t *playlist,
|
2016-01-26 20:21:01 +00:00
|
|
|
const char *path,
|
|
|
|
const char *crc32)
|
|
|
|
{
|
|
|
|
size_t i;
|
2019-05-02 08:56:04 +00:00
|
|
|
char real_search_path[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
real_search_path[0] = '\0';
|
|
|
|
|
|
|
|
if (!playlist || string_is_empty(path))
|
2016-01-26 20:21:01 +00:00
|
|
|
return false;
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
/* Get 'real' search path */
|
|
|
|
strlcpy(real_search_path, path, sizeof(real_search_path));
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(real_search_path, sizeof(real_search_path), true);
|
2019-05-02 08:56:04 +00:00
|
|
|
|
2016-01-26 20:21:01 +00:00
|
|
|
for (i = 0; i < playlist->size; i++)
|
2019-05-02 08:56:04 +00:00
|
|
|
if (playlist_path_equal(real_search_path, playlist->entries[i].path))
|
2016-01-26 20:21:01 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
void playlist_update(playlist_t *playlist, size_t idx,
|
2019-04-12 16:50:27 +00:00
|
|
|
const struct playlist_entry *update_entry)
|
2015-05-26 04:28:16 +00:00
|
|
|
{
|
2016-08-28 16:47:34 +00:00
|
|
|
struct playlist_entry *entry = NULL;
|
2016-09-29 08:16:48 +00:00
|
|
|
|
|
|
|
if (!playlist || idx > playlist->size)
|
2015-05-26 04:28:16 +00:00
|
|
|
return;
|
|
|
|
|
2016-05-24 02:26:24 +00:00
|
|
|
entry = &playlist->entries[idx];
|
2016-06-17 03:37:46 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (update_entry->path && (update_entry->path != entry->path))
|
2016-08-28 16:47:34 +00:00
|
|
|
{
|
2017-05-29 18:36:18 +00:00
|
|
|
if (entry->path != NULL)
|
|
|
|
free(entry->path);
|
2019-04-12 16:50:27 +00:00
|
|
|
entry->path = strdup(update_entry->path);
|
2017-04-23 10:25:54 +00:00
|
|
|
playlist->modified = true;
|
2016-06-17 03:37:46 +00:00
|
|
|
}
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (update_entry->label && (update_entry->label != entry->label))
|
2016-08-28 16:47:34 +00:00
|
|
|
{
|
2017-05-29 18:36:18 +00:00
|
|
|
if (entry->label != NULL)
|
|
|
|
free(entry->label);
|
2019-04-12 16:50:27 +00:00
|
|
|
entry->label = strdup(update_entry->label);
|
2017-04-23 10:25:54 +00:00
|
|
|
playlist->modified = true;
|
2016-06-17 03:37:46 +00:00
|
|
|
}
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (update_entry->core_path && (update_entry->core_path != entry->core_path))
|
2016-08-28 16:47:34 +00:00
|
|
|
{
|
2017-05-29 18:36:18 +00:00
|
|
|
if (entry->core_path != NULL)
|
|
|
|
free(entry->core_path);
|
|
|
|
entry->core_path = NULL;
|
2019-04-12 16:50:27 +00:00
|
|
|
entry->core_path = strdup(update_entry->core_path);
|
2017-04-23 10:25:54 +00:00
|
|
|
playlist->modified = true;
|
2016-06-17 03:37:46 +00:00
|
|
|
}
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (update_entry->core_name && (update_entry->core_name != entry->core_name))
|
2016-08-28 16:47:34 +00:00
|
|
|
{
|
2017-05-29 18:36:18 +00:00
|
|
|
if (entry->core_name != NULL)
|
|
|
|
free(entry->core_name);
|
2019-04-12 16:50:27 +00:00
|
|
|
entry->core_name = strdup(update_entry->core_name);
|
2017-04-23 10:25:54 +00:00
|
|
|
playlist->modified = true;
|
2016-06-17 03:37:46 +00:00
|
|
|
}
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (update_entry->db_name && (update_entry->db_name != entry->db_name))
|
2016-08-28 16:47:34 +00:00
|
|
|
{
|
2017-05-29 18:36:18 +00:00
|
|
|
if (entry->db_name != NULL)
|
|
|
|
free(entry->db_name);
|
2019-04-12 16:50:27 +00:00
|
|
|
entry->db_name = strdup(update_entry->db_name);
|
2017-04-23 10:25:54 +00:00
|
|
|
playlist->modified = true;
|
2016-06-17 03:37:46 +00:00
|
|
|
}
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (update_entry->crc32 && (update_entry->crc32 != entry->crc32))
|
2016-08-28 16:47:34 +00:00
|
|
|
{
|
2017-05-29 18:36:18 +00:00
|
|
|
if (entry->crc32 != NULL)
|
|
|
|
free(entry->crc32);
|
2019-04-12 16:50:27 +00:00
|
|
|
entry->crc32 = strdup(update_entry->crc32);
|
2017-04-23 10:25:54 +00:00
|
|
|
playlist->modified = true;
|
2016-06-17 03:37:46 +00:00
|
|
|
}
|
2015-05-26 04:28:16 +00:00
|
|
|
}
|
|
|
|
|
2019-02-12 05:32:01 +00:00
|
|
|
void playlist_update_runtime(playlist_t *playlist, size_t idx,
|
2019-05-09 13:24:06 +00:00
|
|
|
const struct playlist_entry *update_entry,
|
2019-03-01 14:06:40 +00:00
|
|
|
bool register_update)
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
|
|
|
struct playlist_entry *entry = NULL;
|
|
|
|
|
|
|
|
if (!playlist || idx > playlist->size)
|
|
|
|
return;
|
|
|
|
|
|
|
|
entry = &playlist->entries[idx];
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->path && (update_entry->path != entry->path))
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
|
|
|
if (entry->path != NULL)
|
|
|
|
free(entry->path);
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->path = NULL;
|
|
|
|
entry->path = strdup(update_entry->path);
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->core_path && (update_entry->core_path != entry->core_path))
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
|
|
|
if (entry->core_path != NULL)
|
|
|
|
free(entry->core_path);
|
|
|
|
entry->core_path = NULL;
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->core_path = strdup(update_entry->core_path);
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->runtime_status != entry->runtime_status)
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->runtime_status = update_entry->runtime_status;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->runtime_hours != entry->runtime_hours)
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->runtime_hours = update_entry->runtime_hours;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->runtime_minutes != entry->runtime_minutes)
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->runtime_minutes = update_entry->runtime_minutes;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->runtime_seconds != entry->runtime_seconds)
|
2019-03-01 14:06:40 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->runtime_seconds = update_entry->runtime_seconds;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->last_played_year != entry->last_played_year)
|
2019-03-01 14:06:40 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->last_played_year = update_entry->last_played_year;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->last_played_month != entry->last_played_month)
|
2019-03-01 14:06:40 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->last_played_month = update_entry->last_played_month;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->last_played_day != entry->last_played_day)
|
2019-03-01 14:06:40 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->last_played_day = update_entry->last_played_day;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->last_played_hour != entry->last_played_hour)
|
2019-03-01 14:06:40 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->last_played_hour = update_entry->last_played_hour;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (update_entry->last_played_minute != entry->last_played_minute)
|
2019-03-01 14:06:40 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
entry->last_played_minute = update_entry->last_played_minute;
|
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_entry->last_played_second != entry->last_played_second)
|
|
|
|
{
|
|
|
|
entry->last_played_second = update_entry->last_played_second;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->modified = playlist->modified || register_update;
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
2019-09-10 15:13:25 +00:00
|
|
|
|
|
|
|
if (update_entry->runtime_str && (update_entry->runtime_str != entry->runtime_str))
|
|
|
|
{
|
|
|
|
if (entry->runtime_str != NULL)
|
|
|
|
free(entry->runtime_str);
|
|
|
|
entry->runtime_str = NULL;
|
|
|
|
entry->runtime_str = strdup(update_entry->runtime_str);
|
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_entry->last_played_str && (update_entry->last_played_str != entry->last_played_str))
|
|
|
|
{
|
|
|
|
if (entry->last_played_str != NULL)
|
|
|
|
free(entry->last_played_str);
|
|
|
|
entry->last_played_str = NULL;
|
|
|
|
entry->last_played_str = strdup(update_entry->last_played_str);
|
|
|
|
playlist->modified = playlist->modified || register_update;
|
|
|
|
}
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool playlist_push_runtime(playlist_t *playlist,
|
2019-05-09 13:24:06 +00:00
|
|
|
const struct playlist_entry *entry)
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2019-05-02 08:56:04 +00:00
|
|
|
char real_path[PATH_MAX_LENGTH];
|
|
|
|
char real_core_path[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
real_path[0] = '\0';
|
|
|
|
real_core_path[0] = '\0';
|
2019-02-12 05:32:01 +00:00
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (!playlist || !entry)
|
2019-05-02 08:56:04 +00:00
|
|
|
return false;
|
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (string_is_empty(entry->core_path))
|
2019-02-12 05:32:01 +00:00
|
|
|
{
|
2019-05-02 08:56:04 +00:00
|
|
|
RARCH_ERR("cannot push NULL or empty core path into the playlist.\n");
|
2019-02-12 05:32:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
/* Get 'real' path */
|
2019-05-09 13:24:06 +00:00
|
|
|
if (!string_is_empty(entry->path))
|
2019-05-02 08:56:04 +00:00
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
strlcpy(real_path, entry->path, sizeof(real_path));
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(real_path, sizeof(real_path), true);
|
2019-05-02 08:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get 'real' core path */
|
2019-05-09 13:24:06 +00:00
|
|
|
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
2019-05-05 11:46:06 +00:00
|
|
|
if (!string_is_equal(real_core_path, file_path_str(FILE_PATH_DETECT)))
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(real_core_path, sizeof(real_core_path), true);
|
2019-02-12 05:32:01 +00:00
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
if (string_is_empty(real_core_path))
|
|
|
|
{
|
|
|
|
RARCH_ERR("cannot push NULL or empty core path into the playlist.\n");
|
2019-02-12 05:32:01 +00:00
|
|
|
return false;
|
2019-05-02 08:56:04 +00:00
|
|
|
}
|
2019-02-12 05:32:01 +00:00
|
|
|
|
|
|
|
for (i = 0; i < playlist->size; i++)
|
|
|
|
{
|
|
|
|
struct playlist_entry tmp;
|
2019-04-27 03:35:16 +00:00
|
|
|
const char *entry_path = playlist->entries[i].path;
|
2019-05-02 08:56:04 +00:00
|
|
|
bool equal_path =
|
|
|
|
(string_is_empty(real_path) && string_is_empty(entry_path)) ||
|
|
|
|
playlist_path_equal(real_path, entry_path);
|
2019-02-12 05:32:01 +00:00
|
|
|
|
|
|
|
/* Core name can have changed while still being the same core.
|
|
|
|
* Differentiate based on the core path only. */
|
|
|
|
if (!equal_path)
|
|
|
|
continue;
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
if (!playlist_core_path_equal(real_core_path, playlist->entries[i].core_path))
|
2019-02-12 05:32:01 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* If top entry, we don't want to push a new entry since
|
|
|
|
* the top and the entry to be pushed are the same. */
|
|
|
|
if (i == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Seen it before, bump to top. */
|
|
|
|
tmp = playlist->entries[i];
|
|
|
|
memmove(playlist->entries + 1, playlist->entries,
|
|
|
|
i * sizeof(struct playlist_entry));
|
|
|
|
playlist->entries[0] = tmp;
|
|
|
|
|
|
|
|
goto success;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playlist->size == playlist->cap)
|
|
|
|
{
|
2019-05-09 13:24:06 +00:00
|
|
|
struct playlist_entry *last_entry = &playlist->entries[playlist->cap - 1];
|
2019-02-12 05:32:01 +00:00
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
if (last_entry)
|
|
|
|
playlist_free_entry(last_entry);
|
2019-02-12 05:32:01 +00:00
|
|
|
playlist->size--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (playlist->entries)
|
|
|
|
{
|
|
|
|
memmove(playlist->entries + 1, playlist->entries,
|
|
|
|
(playlist->cap - 1) * sizeof(struct playlist_entry));
|
|
|
|
|
|
|
|
playlist->entries[0].path = NULL;
|
|
|
|
playlist->entries[0].core_path = NULL;
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
if (!string_is_empty(real_path))
|
|
|
|
playlist->entries[0].path = strdup(real_path);
|
|
|
|
if (!string_is_empty(real_core_path))
|
|
|
|
playlist->entries[0].core_path = strdup(real_core_path);
|
2019-02-12 05:32:01 +00:00
|
|
|
|
2019-05-09 13:24:06 +00:00
|
|
|
playlist->entries[0].runtime_status = entry->runtime_status;
|
|
|
|
playlist->entries[0].runtime_hours = entry->runtime_hours;
|
|
|
|
playlist->entries[0].runtime_minutes = entry->runtime_minutes;
|
|
|
|
playlist->entries[0].runtime_seconds = entry->runtime_seconds;
|
|
|
|
playlist->entries[0].last_played_year = entry->last_played_year;
|
|
|
|
playlist->entries[0].last_played_month = entry->last_played_month;
|
|
|
|
playlist->entries[0].last_played_day = entry->last_played_day;
|
|
|
|
playlist->entries[0].last_played_hour = entry->last_played_hour;
|
|
|
|
playlist->entries[0].last_played_minute = entry->last_played_minute;
|
|
|
|
playlist->entries[0].last_played_second = entry->last_played_second;
|
2019-09-10 15:13:25 +00:00
|
|
|
|
|
|
|
playlist->entries[0].runtime_str = NULL;
|
|
|
|
playlist->entries[0].last_played_str = NULL;
|
|
|
|
|
|
|
|
if (!string_is_empty(entry->runtime_str))
|
|
|
|
playlist->entries[0].runtime_str = strdup(entry->runtime_str);
|
|
|
|
if (!string_is_empty(entry->last_played_str))
|
|
|
|
playlist->entries[0].last_played_str = strdup(entry->last_played_str);
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
playlist->size++;
|
|
|
|
|
|
|
|
success:
|
|
|
|
playlist->modified = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-07-18 19:15:13 +00:00
|
|
|
/**
|
|
|
|
* playlist_resolve_path:
|
|
|
|
* @mode : PLAYLIST_LOAD or PLAYLIST_SAVE
|
2019-07-21 10:54:37 +00:00
|
|
|
* @path : The path to be modified
|
2019-07-18 19:15:13 +00:00
|
|
|
*
|
|
|
|
* 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)
|
|
|
|
**/
|
2019-07-20 13:07:09 +00:00
|
|
|
void playlist_resolve_path(enum playlist_file_mode mode,
|
|
|
|
char *path, size_t size)
|
2019-07-18 19:15:13 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_COCOATOUCH
|
2019-07-21 10:54:37 +00:00
|
|
|
char tmp[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
if (mode == PLAYLIST_LOAD)
|
|
|
|
{
|
|
|
|
fill_pathname_expand_special(tmp, path, sizeof(tmp));
|
|
|
|
strlcpy(path, tmp, size);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* iOS needs to call realpath here since the call
|
2019-07-27 03:00:09 +00:00
|
|
|
* above fails due to possibly buffer related issues.
|
|
|
|
* Try to expand the path to ensure that it gets saved
|
|
|
|
* correctly. The path can be abbreviated if saving to
|
|
|
|
* a playlist from another playlist (ex: content history to favorites)
|
|
|
|
*/
|
|
|
|
char tmp2[PATH_MAX_LENGTH];
|
|
|
|
fill_pathname_expand_special(tmp, path, sizeof(tmp));
|
|
|
|
realpath(tmp, tmp2);
|
|
|
|
fill_pathname_abbreviate_special(path, tmp2, size);
|
2019-07-21 10:54:37 +00:00
|
|
|
}
|
2019-07-18 19:15:13 +00:00
|
|
|
#else
|
2019-07-21 10:54:37 +00:00
|
|
|
if (mode == PLAYLIST_LOAD)
|
|
|
|
return;
|
2019-07-20 13:07:09 +00:00
|
|
|
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(path, size, true);
|
2019-07-18 19:15:13 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-01-16 20:09:05 +00:00
|
|
|
/**
|
2016-05-16 07:07:44 +00:00
|
|
|
* playlist_push:
|
2015-01-17 02:48:59 +00:00
|
|
|
* @playlist : Playlist handle.
|
2015-01-16 20:09:05 +00:00
|
|
|
*
|
|
|
|
* Push entry to top of playlist.
|
|
|
|
**/
|
2016-07-30 19:27:40 +00:00
|
|
|
bool playlist_push(playlist_t *playlist,
|
2019-04-12 16:50:27 +00:00
|
|
|
const struct playlist_entry *entry)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
size_t i;
|
2019-05-02 08:56:04 +00:00
|
|
|
char real_path[PATH_MAX_LENGTH];
|
|
|
|
char real_core_path[PATH_MAX_LENGTH];
|
2019-04-12 16:50:27 +00:00
|
|
|
const char *core_name = entry->core_name;
|
2019-05-02 08:56:04 +00:00
|
|
|
bool entry_updated = false;
|
2014-06-01 00:16:48 +00:00
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
real_path[0] = '\0';
|
|
|
|
real_core_path[0] = '\0';
|
|
|
|
|
|
|
|
if (!playlist || !entry)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (string_is_empty(entry->core_path))
|
2015-03-22 22:17:29 +00:00
|
|
|
{
|
2019-05-02 08:56:04 +00:00
|
|
|
RARCH_ERR("cannot push NULL or empty core path into the playlist.\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get 'real' path */
|
|
|
|
if (!string_is_empty(entry->path))
|
|
|
|
{
|
|
|
|
strlcpy(real_path, entry->path, sizeof(real_path));
|
2019-07-18 19:15:13 +00:00
|
|
|
playlist_resolve_path(PLAYLIST_SAVE, real_path, sizeof(real_path));
|
2019-05-02 08:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get 'real' core path */
|
|
|
|
strlcpy(real_core_path, entry->core_path, sizeof(real_core_path));
|
2019-05-04 23:17:51 +00:00
|
|
|
if (!string_is_equal(real_core_path, file_path_str(FILE_PATH_DETECT)))
|
2019-07-18 19:15:13 +00:00
|
|
|
playlist_resolve_path(PLAYLIST_SAVE, real_core_path, sizeof(real_core_path));
|
2019-05-02 08:56:04 +00:00
|
|
|
|
|
|
|
if (string_is_empty(real_core_path))
|
|
|
|
{
|
|
|
|
RARCH_ERR("cannot push NULL or empty core path into the playlist.\n");
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-22 22:15:37 +00:00
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
if (string_is_empty(core_name))
|
|
|
|
{
|
|
|
|
static char base_path[255] = {0};
|
|
|
|
fill_pathname_base_noext(base_path, real_core_path, sizeof(base_path));
|
|
|
|
core_name = base_path;
|
|
|
|
|
|
|
|
if (string_is_empty(core_name))
|
2016-07-22 22:15:37 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("cannot push NULL or empty core name into the playlist.\n");
|
2016-07-30 19:27:40 +00:00
|
|
|
return false;
|
2016-07-22 22:15:37 +00:00
|
|
|
}
|
2015-03-22 22:17:29 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
for (i = 0; i < playlist->size; i++)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2016-08-28 16:47:34 +00:00
|
|
|
struct playlist_entry tmp;
|
2019-04-27 03:35:16 +00:00
|
|
|
const char *entry_path = playlist->entries[i].path;
|
2019-05-02 08:56:04 +00:00
|
|
|
bool equal_path =
|
|
|
|
(string_is_empty(real_path) && string_is_empty(entry_path)) ||
|
|
|
|
playlist_path_equal(real_path, entry_path);
|
2013-05-02 12:42:58 +00:00
|
|
|
|
2014-08-20 15:23:21 +00:00
|
|
|
/* Core name can have changed while still being the same core.
|
|
|
|
* Differentiate based on the core path only. */
|
2015-01-16 18:42:11 +00:00
|
|
|
if (!equal_path)
|
|
|
|
continue;
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
if (!playlist_core_path_equal(real_core_path, playlist->entries[i].core_path))
|
2015-01-16 18:42:11 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( !string_is_empty(entry->subsystem_ident)
|
|
|
|
&& !string_is_empty(playlist->entries[i].subsystem_ident)
|
2019-04-13 16:57:02 +00:00
|
|
|
&& !string_is_equal(playlist->entries[i].subsystem_ident, entry->subsystem_ident))
|
2019-04-11 04:09:13 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( string_is_empty(entry->subsystem_ident)
|
2019-04-13 16:57:02 +00:00
|
|
|
&& !string_is_empty(playlist->entries[i].subsystem_ident))
|
2019-04-11 04:09:13 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( !string_is_empty(entry->subsystem_ident)
|
2019-04-13 16:57:02 +00:00
|
|
|
&& string_is_empty(playlist->entries[i].subsystem_ident))
|
2019-04-11 04:09:13 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( !string_is_empty(entry->subsystem_name)
|
|
|
|
&& !string_is_empty(playlist->entries[i].subsystem_name)
|
2019-04-13 16:57:02 +00:00
|
|
|
&& !string_is_equal(playlist->entries[i].subsystem_name, entry->subsystem_name))
|
2019-04-12 16:50:27 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( string_is_empty(entry->subsystem_name)
|
2019-04-13 16:57:02 +00:00
|
|
|
&& !string_is_empty(playlist->entries[i].subsystem_name))
|
2019-04-12 16:50:27 +00:00
|
|
|
continue;
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( !string_is_empty(entry->subsystem_name)
|
2019-04-13 16:57:02 +00:00
|
|
|
&& string_is_empty(playlist->entries[i].subsystem_name))
|
2019-04-12 16:50:27 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (entry->subsystem_roms)
|
2019-04-11 04:09:13 +00:00
|
|
|
{
|
2019-04-20 03:53:17 +00:00
|
|
|
unsigned j;
|
2019-04-11 04:09:13 +00:00
|
|
|
const struct string_list *roms = playlist->entries[i].subsystem_roms;
|
2019-04-13 16:57:02 +00:00
|
|
|
bool unequal = false;
|
2019-04-11 04:09:13 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (entry->subsystem_roms->size != roms->size)
|
2019-04-11 04:09:13 +00:00
|
|
|
continue;
|
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
for (j = 0; j < entry->subsystem_roms->size; j++)
|
2019-04-11 04:09:13 +00:00
|
|
|
{
|
2019-05-02 08:56:04 +00:00
|
|
|
char real_rom_path[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
real_rom_path[0] = '\0';
|
|
|
|
|
|
|
|
if (!string_is_empty(entry->subsystem_roms->elems[j].data))
|
|
|
|
{
|
|
|
|
strlcpy(real_rom_path, entry->subsystem_roms->elems[j].data, sizeof(real_rom_path));
|
2019-07-21 10:54:37 +00:00
|
|
|
path_resolve_realpath(real_rom_path, sizeof(real_rom_path), true);
|
2019-05-02 08:56:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!playlist_path_equal(real_rom_path, roms->elems[j].data))
|
2019-04-11 04:09:13 +00:00
|
|
|
{
|
|
|
|
unequal = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unequal)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-05-02 08:56:04 +00:00
|
|
|
/* If content was previously loaded via file browser
|
|
|
|
* or command line, certain entry values will be missing.
|
|
|
|
* If we are now loading the same content from a playlist,
|
|
|
|
* fill in any blanks */
|
|
|
|
if ((playlist->entries[i].label == NULL) && !string_is_empty(entry->label))
|
|
|
|
{
|
|
|
|
playlist->entries[i].label = strdup(entry->label);
|
|
|
|
entry_updated = true;
|
|
|
|
}
|
|
|
|
if ((playlist->entries[i].crc32 == NULL) && !string_is_empty(entry->crc32))
|
|
|
|
{
|
|
|
|
playlist->entries[i].crc32 = strdup(entry->crc32);
|
|
|
|
entry_updated = true;
|
|
|
|
}
|
|
|
|
if ((playlist->entries[i].db_name == NULL) && !string_is_empty(entry->db_name))
|
|
|
|
{
|
|
|
|
playlist->entries[i].db_name = strdup(entry->db_name);
|
|
|
|
entry_updated = true;
|
|
|
|
}
|
|
|
|
|
2015-01-16 18:46:10 +00:00
|
|
|
/* If top entry, we don't want to push a new entry since
|
|
|
|
* the top and the entry to be pushed are the same. */
|
2015-01-16 18:42:11 +00:00
|
|
|
if (i == 0)
|
2019-05-02 08:56:04 +00:00
|
|
|
{
|
|
|
|
if (entry_updated)
|
|
|
|
goto success;
|
|
|
|
|
2016-07-30 19:27:40 +00:00
|
|
|
return false;
|
2019-05-02 08:56:04 +00:00
|
|
|
}
|
2015-01-16 18:42:11 +00:00
|
|
|
|
|
|
|
/* Seen it before, bump to top. */
|
|
|
|
tmp = playlist->entries[i];
|
|
|
|
memmove(playlist->entries + 1, playlist->entries,
|
2016-08-28 16:47:34 +00:00
|
|
|
i * sizeof(struct playlist_entry));
|
2015-01-16 18:42:11 +00:00
|
|
|
playlist->entries[0] = tmp;
|
|
|
|
|
2017-04-23 10:25:54 +00:00
|
|
|
goto success;
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
if (playlist->size == playlist->cap)
|
2013-04-27 23:35:31 +00:00
|
|
|
{
|
2019-07-18 17:11:30 +00:00
|
|
|
struct playlist_entry *last_entry =
|
2019-07-14 11:17:51 +00:00
|
|
|
&playlist->entries[playlist->cap - 1];
|
2016-09-29 07:36:24 +00:00
|
|
|
|
2019-07-14 11:17:51 +00:00
|
|
|
if (last_entry)
|
|
|
|
playlist_free_entry(last_entry);
|
2014-08-15 15:32:38 +00:00
|
|
|
playlist->size--;
|
2013-04-27 23:35:31 +00:00
|
|
|
}
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2017-10-11 20:49:13 +00:00
|
|
|
if (playlist->entries)
|
|
|
|
{
|
|
|
|
memmove(playlist->entries + 1, playlist->entries,
|
|
|
|
(playlist->cap - 1) * sizeof(struct playlist_entry));
|
|
|
|
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->entries[0].path = NULL;
|
|
|
|
playlist->entries[0].label = NULL;
|
|
|
|
playlist->entries[0].core_path = NULL;
|
|
|
|
playlist->entries[0].core_name = NULL;
|
|
|
|
playlist->entries[0].db_name = NULL;
|
|
|
|
playlist->entries[0].crc32 = NULL;
|
2019-04-11 04:09:13 +00:00
|
|
|
playlist->entries[0].subsystem_ident = NULL;
|
2019-04-12 16:50:27 +00:00
|
|
|
playlist->entries[0].subsystem_name = NULL;
|
2019-09-10 15:13:25 +00:00
|
|
|
playlist->entries[0].runtime_str = NULL;
|
|
|
|
playlist->entries[0].last_played_str = NULL;
|
2019-04-11 04:09:13 +00:00
|
|
|
playlist->entries[0].subsystem_roms = NULL;
|
2019-05-09 13:24:06 +00:00
|
|
|
playlist->entries[0].runtime_status = PLAYLIST_RUNTIME_UNKNOWN;
|
2019-03-01 14:06:40 +00:00
|
|
|
playlist->entries[0].runtime_hours = 0;
|
|
|
|
playlist->entries[0].runtime_minutes = 0;
|
|
|
|
playlist->entries[0].runtime_seconds = 0;
|
|
|
|
playlist->entries[0].last_played_year = 0;
|
|
|
|
playlist->entries[0].last_played_month = 0;
|
|
|
|
playlist->entries[0].last_played_day = 0;
|
|
|
|
playlist->entries[0].last_played_hour = 0;
|
|
|
|
playlist->entries[0].last_played_minute = 0;
|
|
|
|
playlist->entries[0].last_played_second = 0;
|
2019-05-02 08:56:04 +00:00
|
|
|
if (!string_is_empty(real_path))
|
|
|
|
playlist->entries[0].path = strdup(real_path);
|
2019-04-12 16:50:27 +00:00
|
|
|
if (!string_is_empty(entry->label))
|
2019-04-13 16:57:02 +00:00
|
|
|
playlist->entries[0].label = strdup(entry->label);
|
2019-05-02 08:56:04 +00:00
|
|
|
if (!string_is_empty(real_core_path))
|
|
|
|
playlist->entries[0].core_path = strdup(real_core_path);
|
2017-10-11 20:49:13 +00:00
|
|
|
if (!string_is_empty(core_name))
|
2019-04-13 16:57:02 +00:00
|
|
|
playlist->entries[0].core_name = strdup(core_name);
|
2019-04-12 16:50:27 +00:00
|
|
|
if (!string_is_empty(entry->db_name))
|
2019-04-13 16:57:02 +00:00
|
|
|
playlist->entries[0].db_name = strdup(entry->db_name);
|
2019-04-12 16:50:27 +00:00
|
|
|
if (!string_is_empty(entry->crc32))
|
2019-04-13 16:57:02 +00:00
|
|
|
playlist->entries[0].crc32 = strdup(entry->crc32);
|
2019-04-12 16:50:27 +00:00
|
|
|
if (!string_is_empty(entry->subsystem_ident))
|
|
|
|
playlist->entries[0].subsystem_ident = strdup(entry->subsystem_ident);
|
|
|
|
if (!string_is_empty(entry->subsystem_name))
|
2019-04-13 16:57:02 +00:00
|
|
|
playlist->entries[0].subsystem_name = strdup(entry->subsystem_name);
|
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (entry->subsystem_roms)
|
2019-04-11 04:09:13 +00:00
|
|
|
{
|
|
|
|
union string_list_elem_attr attributes = {0};
|
|
|
|
|
2019-04-13 16:57:02 +00:00
|
|
|
playlist->entries[0].subsystem_roms = string_list_new();
|
2019-04-11 04:09:13 +00:00
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
for (i = 0; i < entry->subsystem_roms->size; i++)
|
|
|
|
string_list_append(playlist->entries[0].subsystem_roms, entry->subsystem_roms->elems[i].data, attributes);
|
2019-04-11 04:09:13 +00:00
|
|
|
}
|
2017-10-11 20:49:13 +00:00
|
|
|
}
|
2016-06-01 03:34:15 +00:00
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
playlist->size++;
|
2016-07-30 19:27:40 +00:00
|
|
|
|
2017-04-23 10:25:54 +00:00
|
|
|
success:
|
|
|
|
playlist->modified = true;
|
|
|
|
|
2016-07-30 19:27:40 +00:00
|
|
|
return true;
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
static JSON_Writer_HandlerResult JSONOutputHandler(JSON_Writer writer, const char *pBytes, size_t length)
|
|
|
|
{
|
|
|
|
JSONContext *context = (JSONContext*)JSON_Writer_GetUserData(writer);
|
|
|
|
|
|
|
|
(void)writer; /* unused */
|
|
|
|
return filestream_write(context->file, pBytes, length) == length ? JSON_Writer_Continue : JSON_Writer_Abort;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void JSONLogError(JSONContext *pCtx)
|
|
|
|
{
|
|
|
|
if (pCtx->parser && JSON_Parser_GetError(pCtx->parser) != JSON_Error_AbortedByHandler)
|
|
|
|
{
|
2019-04-13 16:57:02 +00:00
|
|
|
JSON_Error error = JSON_Parser_GetError(pCtx->parser);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Location errorLocation = { 0, 0, 0 };
|
2019-04-13 16:57:02 +00:00
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
(void)JSON_Parser_GetErrorLocation(pCtx->parser, &errorLocation);
|
|
|
|
RARCH_WARN("Error: Invalid JSON at line %d, column %d (input byte %d) - %s.\n",
|
|
|
|
(int)errorLocation.line + 1,
|
|
|
|
(int)errorLocation.column + 1,
|
|
|
|
(int)errorLocation.byte,
|
|
|
|
JSON_ErrorString(error));
|
|
|
|
}
|
|
|
|
else if (pCtx->writer && JSON_Writer_GetError(pCtx->writer) != JSON_Error_AbortedByHandler)
|
|
|
|
{
|
|
|
|
RARCH_WARN("Error: could not write output - %s.\n", JSON_ErrorString(JSON_Writer_GetError(pCtx->writer)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-12 05:32:01 +00:00
|
|
|
void playlist_write_runtime_file(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
size_t i;
|
2019-03-11 17:33:24 +00:00
|
|
|
RFILE *file = NULL;
|
2019-02-12 05:32:01 +00:00
|
|
|
JSONContext context = {0};
|
|
|
|
|
|
|
|
if (!playlist || !playlist->modified)
|
|
|
|
return;
|
|
|
|
|
|
|
|
file = filestream_open(playlist->conf_path,
|
|
|
|
RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
|
|
|
|
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to write to playlist file: %s\n", playlist->conf_path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
context.writer = JSON_Writer_Create(NULL);
|
|
|
|
context.file = file;
|
|
|
|
|
|
|
|
if (!context.writer)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to create JSON writer\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSON_Writer_SetOutputEncoding(context.writer, JSON_UTF8);
|
|
|
|
JSON_Writer_SetOutputHandler(context.writer, &JSONOutputHandler);
|
|
|
|
JSON_Writer_SetUserData(context.writer, &context);
|
|
|
|
|
|
|
|
JSON_Writer_WriteStartObject(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "version",
|
|
|
|
STRLEN_CONST("version"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "1.0",
|
|
|
|
STRLEN_CONST("1.0"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "items",
|
|
|
|
STRLEN_CONST("items"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteStartArray(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
for (i = 0; i < playlist->size; i++)
|
|
|
|
{
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 4);
|
|
|
|
JSON_Writer_WriteStartObject(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "path",
|
|
|
|
STRLEN_CONST("path"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].path
|
|
|
|
? playlist->entries[i].path
|
2019-04-27 02:21:10 +00:00
|
|
|
: "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].path
|
|
|
|
? strlen(playlist->entries[i].path)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "core_path",
|
|
|
|
STRLEN_CONST("core_path"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, playlist->entries[i].core_path,
|
|
|
|
strlen(playlist->entries[i].core_path), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
{
|
|
|
|
char tmp[32] = {0};
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].runtime_hours);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "runtime_hours",
|
|
|
|
STRLEN_CONST("runtime_hours"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].runtime_minutes);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "runtime_minutes",
|
|
|
|
STRLEN_CONST("runtime_minutes"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].runtime_seconds);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "runtime_seconds",
|
|
|
|
STRLEN_CONST("runtime_seconds"), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].last_played_year);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "last_played_year",
|
|
|
|
STRLEN_CONST("last_played_year"), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].last_played_month);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "last_played_month",
|
|
|
|
STRLEN_CONST("last_played_month"), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].last_played_day);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "last_played_day",
|
|
|
|
STRLEN_CONST("last_played_day"), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp,
|
|
|
|
strlen(tmp), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].last_played_hour);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "last_played_hour",
|
|
|
|
STRLEN_CONST("last_played_hour"), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].last_played_minute);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "last_played_minute",
|
|
|
|
STRLEN_CONST("last_played_minute"), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp, strlen(tmp), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
memset(tmp, 0, sizeof(tmp));
|
|
|
|
|
|
|
|
snprintf(tmp, sizeof(tmp), "%u", playlist->entries[i].last_played_second);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "last_played_second",
|
|
|
|
STRLEN_CONST("last_played_second"), JSON_UTF8);
|
2019-03-01 14:06:40 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteNumber(context.writer, tmp,
|
|
|
|
strlen(tmp), JSON_UTF8);
|
2019-02-12 05:32:01 +00:00
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 4);
|
|
|
|
JSON_Writer_WriteEndObject(context.writer);
|
|
|
|
|
|
|
|
if (i < playlist->size - 1)
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
}
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
|
|
|
JSON_Writer_WriteEndArray(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteEndObject(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_Free(context.writer);
|
|
|
|
|
|
|
|
playlist->modified = false;
|
|
|
|
|
|
|
|
RARCH_LOG("Written to playlist file: %s\n", playlist->conf_path);
|
|
|
|
end:
|
|
|
|
filestream_close(file);
|
|
|
|
}
|
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
void playlist_write_file(playlist_t *playlist)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
size_t i;
|
2019-04-13 16:57:02 +00:00
|
|
|
RFILE *file = NULL;
|
2019-05-21 20:38:50 +00:00
|
|
|
#ifdef RARCH_INTERNAL
|
2019-01-09 22:13:13 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
2019-05-21 20:38:50 +00:00
|
|
|
#endif
|
2014-07-11 23:57:01 +00:00
|
|
|
|
2017-04-23 10:25:54 +00:00
|
|
|
if (!playlist || !playlist->modified)
|
2014-07-11 23:57:01 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-10 21:25:38 +00:00
|
|
|
file = filestream_open(playlist->conf_path,
|
2017-12-11 11:53:47 +00:00
|
|
|
RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
2014-07-11 23:57:01 +00:00
|
|
|
|
|
|
|
if (!file)
|
2016-07-22 08:15:33 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to write to playlist file: %s\n", playlist->conf_path);
|
2013-04-27 22:15:59 +00:00
|
|
|
return;
|
2016-07-22 08:15:33 +00:00
|
|
|
}
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2019-05-21 20:38:50 +00:00
|
|
|
#ifdef RARCH_INTERNAL
|
2019-01-09 22:13:13 +00:00
|
|
|
if (settings->bools.playlist_use_old_format)
|
|
|
|
{
|
|
|
|
for (i = 0; i < playlist->size; i++)
|
|
|
|
filestream_printf(file, "%s\n%s\n%s\n%s\n%s\n%s\n",
|
|
|
|
playlist->entries[i].path ? playlist->entries[i].path : "",
|
|
|
|
playlist->entries[i].label ? playlist->entries[i].label : "",
|
|
|
|
playlist->entries[i].core_path,
|
|
|
|
playlist->entries[i].core_name,
|
|
|
|
playlist->entries[i].crc32 ? playlist->entries[i].crc32 : "",
|
|
|
|
playlist->entries[i].db_name ? playlist->entries[i].db_name : ""
|
|
|
|
);
|
2019-06-27 11:36:58 +00:00
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
/* Add metadata lines
|
2019-06-27 11:36:58 +00:00
|
|
|
* (we add these at the end of the file to prevent
|
|
|
|
* breakage if the playlist is loaded with an older
|
|
|
|
* version of RetroArch */
|
2019-08-15 17:04:24 +00:00
|
|
|
filestream_printf(
|
|
|
|
file,
|
|
|
|
"default_core_path = \"%s\"\n"
|
|
|
|
"default_core_name = \"%s\"\n"
|
|
|
|
"label_display_mode = \"%d\"\n"
|
|
|
|
"thumbnail_mode = \"%d|%d\"\n",
|
|
|
|
playlist->default_core_path ? "" : playlist->default_core_path,
|
|
|
|
playlist->default_core_name ? "" : playlist->default_core_name,
|
|
|
|
playlist->label_display_mode,
|
|
|
|
playlist->right_thumbnail_mode, playlist->left_thumbnail_mode);
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
|
|
|
else
|
2019-05-21 20:38:50 +00:00
|
|
|
#endif
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-08-15 17:04:24 +00:00
|
|
|
char uint_str[4];
|
2019-01-09 22:13:13 +00:00
|
|
|
JSONContext context = {0};
|
2019-03-11 17:33:24 +00:00
|
|
|
context.writer = JSON_Writer_Create(NULL);
|
|
|
|
context.file = file;
|
2019-01-09 22:13:13 +00:00
|
|
|
|
|
|
|
if (!context.writer)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to create JSON writer\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
JSON_Writer_SetOutputEncoding(context.writer, JSON_UTF8);
|
|
|
|
JSON_Writer_SetOutputHandler(context.writer, &JSONOutputHandler);
|
|
|
|
JSON_Writer_SetUserData(context.writer, &context);
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteStartObject(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-06-26 16:40:00 +00:00
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "version",
|
|
|
|
STRLEN_CONST("version"), JSON_UTF8);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-07-18 19:13:14 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "1.2",
|
2019-08-15 17:04:24 +00:00
|
|
|
STRLEN_CONST("1.3"), JSON_UTF8);
|
2019-06-26 16:40:00 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
|
|
|
JSON_Writer_WriteString(context.writer, "default_core_path",
|
|
|
|
STRLEN_CONST("default_core_path"), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteString(context.writer,
|
|
|
|
playlist->default_core_path
|
|
|
|
? playlist->default_core_path
|
|
|
|
: "",
|
|
|
|
playlist->default_core_path
|
|
|
|
? strlen(playlist->default_core_path)
|
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-06-26 16:40:00 +00:00
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
|
|
|
JSON_Writer_WriteString(context.writer, "default_core_name",
|
|
|
|
STRLEN_CONST("default_core_name"), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteString(context.writer,
|
|
|
|
playlist->default_core_name
|
|
|
|
? playlist->default_core_name
|
|
|
|
: "",
|
|
|
|
playlist->default_core_name
|
|
|
|
? strlen(playlist->default_core_name)
|
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
uint_str[0] = '\0';
|
|
|
|
snprintf(uint_str, sizeof(uint_str), "%u", playlist->label_display_mode);
|
2019-07-18 19:13:14 +00:00
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
|
|
|
JSON_Writer_WriteString(context.writer, "label_display_mode",
|
|
|
|
STRLEN_CONST("label_display_mode"), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-08-15 17:04:24 +00:00
|
|
|
JSON_Writer_WriteNumber(context.writer, uint_str,
|
|
|
|
strlen(uint_str), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
uint_str[0] = '\0';
|
|
|
|
snprintf(uint_str, sizeof(uint_str), "%u", playlist->right_thumbnail_mode);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
|
|
|
JSON_Writer_WriteString(context.writer, "right_thumbnail_mode",
|
|
|
|
STRLEN_CONST("right_thumbnail_mode"), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, uint_str,
|
|
|
|
strlen(uint_str), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
uint_str[0] = '\0';
|
|
|
|
snprintf(uint_str, sizeof(uint_str), "%u", playlist->left_thumbnail_mode);
|
|
|
|
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
|
|
|
JSON_Writer_WriteString(context.writer, "left_thumbnail_mode",
|
|
|
|
STRLEN_CONST("left_thumbnail_mode"), JSON_UTF8);
|
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteNumber(context.writer, uint_str,
|
|
|
|
strlen(uint_str), JSON_UTF8);
|
2019-07-18 19:13:14 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "items",
|
|
|
|
STRLEN_CONST("items"), JSON_UTF8);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteStartArray(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
for (i = 0; i < playlist->size; i++)
|
|
|
|
{
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 4);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteStartObject(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "path",
|
|
|
|
STRLEN_CONST("path"), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].path
|
|
|
|
? playlist->entries[i].path
|
2019-04-27 02:21:10 +00:00
|
|
|
: "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].path
|
|
|
|
? strlen(playlist->entries[i].path)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "label",
|
|
|
|
STRLEN_CONST("label"), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].label
|
|
|
|
? playlist->entries[i].label
|
2019-04-27 02:21:10 +00:00
|
|
|
: "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].label
|
|
|
|
? strlen(playlist->entries[i].label)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "core_path",
|
|
|
|
STRLEN_CONST("core_path"), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
|
|
|
playlist->entries[i].core_path,
|
|
|
|
strlen(playlist->entries[i].core_path), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "core_name",
|
|
|
|
STRLEN_CONST("core_name"), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
|
|
|
playlist->entries[i].core_name,
|
|
|
|
strlen(playlist->entries[i].core_name), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "crc32",
|
|
|
|
STRLEN_CONST("crc32"), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, playlist->entries[i].crc32 ? playlist->entries[i].crc32 : "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].crc32
|
|
|
|
? strlen(playlist->entries[i].crc32)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "db_name",
|
|
|
|
STRLEN_CONST("db_name"), JSON_UTF8);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, playlist->entries[i].db_name ? playlist->entries[i].db_name : "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].db_name
|
|
|
|
? strlen(playlist->entries[i].db_name)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-04-11 04:09:13 +00:00
|
|
|
|
|
|
|
if (!string_is_empty(playlist->entries[i].subsystem_ident))
|
|
|
|
{
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "subsystem_ident",
|
|
|
|
STRLEN_CONST("subsystem_ident"), JSON_UTF8);
|
2019-04-11 04:09:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, playlist->entries[i].subsystem_ident ? playlist->entries[i].subsystem_ident : "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].subsystem_ident
|
|
|
|
? strlen(playlist->entries[i].subsystem_ident)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-04-11 04:09:13 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 16:50:27 +00:00
|
|
|
if (!string_is_empty(playlist->entries[i].subsystem_name))
|
|
|
|
{
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "subsystem_name",
|
|
|
|
STRLEN_CONST("subsystem_name"), JSON_UTF8);
|
2019-04-12 16:50:27 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].subsystem_name
|
|
|
|
? playlist->entries[i].subsystem_name
|
2019-04-27 02:21:10 +00:00
|
|
|
: "",
|
2019-07-18 17:11:30 +00:00
|
|
|
playlist->entries[i].subsystem_name
|
|
|
|
? strlen(playlist->entries[i].subsystem_name)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0, JSON_UTF8);
|
2019-04-12 16:50:27 +00:00
|
|
|
}
|
|
|
|
|
2019-07-18 17:11:30 +00:00
|
|
|
if ( playlist->entries[i].subsystem_roms &&
|
2019-04-27 02:21:10 +00:00
|
|
|
playlist->entries[i].subsystem_roms->size > 0)
|
2019-04-11 04:09:13 +00:00
|
|
|
{
|
2019-04-20 03:53:17 +00:00
|
|
|
unsigned j;
|
2019-04-11 04:09:13 +00:00
|
|
|
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer, "subsystem_roms",
|
|
|
|
STRLEN_CONST("subsystem_roms"), JSON_UTF8);
|
2019-04-11 04:09:13 +00:00
|
|
|
JSON_Writer_WriteColon(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 1);
|
|
|
|
JSON_Writer_WriteStartArray(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
|
|
|
for (j = 0; j < playlist->entries[i].subsystem_roms->size; j++)
|
|
|
|
{
|
|
|
|
const struct string_list *roms = playlist->entries[i].subsystem_roms;
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 8);
|
2019-04-27 02:21:10 +00:00
|
|
|
JSON_Writer_WriteString(context.writer,
|
2019-07-18 17:11:30 +00:00
|
|
|
!string_is_empty(roms->elems[j].data)
|
|
|
|
? roms->elems[j].data
|
2019-04-27 02:21:10 +00:00
|
|
|
: "",
|
2019-07-18 17:11:30 +00:00
|
|
|
!string_is_empty(roms->elems[j].data)
|
|
|
|
? strlen(roms->elems[j].data)
|
2019-04-27 02:21:10 +00:00
|
|
|
: 0,
|
|
|
|
JSON_UTF8);
|
2019-04-11 04:09:13 +00:00
|
|
|
|
|
|
|
if (j < playlist->entries[i].subsystem_roms->size - 1)
|
|
|
|
{
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
JSON_Writer_WriteSpace(context.writer, 6);
|
|
|
|
JSON_Writer_WriteEndArray(context.writer);
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 4);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteEndObject(context.writer);
|
|
|
|
|
|
|
|
if (i < playlist->size - 1)
|
|
|
|
JSON_Writer_WriteComma(context.writer);
|
|
|
|
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
|
|
|
}
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteSpace(context.writer, 2);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_WriteEndArray(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-12 18:46:28 +00:00
|
|
|
JSON_Writer_WriteEndObject(context.writer);
|
|
|
|
JSON_Writer_WriteNewLine(context.writer);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Writer_Free(context.writer);
|
|
|
|
}
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2017-04-23 10:54:13 +00:00
|
|
|
playlist->modified = false;
|
2017-11-25 23:02:28 +00:00
|
|
|
|
|
|
|
RARCH_LOG("Written to playlist file: %s\n", playlist->conf_path);
|
2019-01-09 22:13:13 +00:00
|
|
|
end:
|
2017-10-29 16:08:20 +00:00
|
|
|
filestream_close(file);
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 18:42:11 +00:00
|
|
|
/**
|
2016-05-16 07:07:44 +00:00
|
|
|
* playlist_free:
|
2016-05-06 18:20:16 +00:00
|
|
|
* @playlist : Playlist handle.
|
2015-01-16 18:42:11 +00:00
|
|
|
*
|
|
|
|
* Frees playlist handle.
|
|
|
|
*/
|
2016-05-16 07:07:44 +00:00
|
|
|
void playlist_free(playlist_t *playlist)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
size_t i;
|
2015-01-16 20:09:05 +00:00
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
if (!playlist)
|
2013-04-27 22:15:59 +00:00
|
|
|
return;
|
|
|
|
|
2017-07-01 02:37:32 +00:00
|
|
|
if (playlist->conf_path != NULL)
|
2015-06-09 20:05:21 +00:00
|
|
|
free(playlist->conf_path);
|
2015-06-09 20:06:20 +00:00
|
|
|
playlist->conf_path = NULL;
|
|
|
|
|
2019-06-26 16:40:00 +00:00
|
|
|
if (playlist->default_core_path != NULL)
|
|
|
|
free(playlist->default_core_path);
|
|
|
|
playlist->default_core_path = NULL;
|
|
|
|
|
|
|
|
if (playlist->default_core_name != NULL)
|
|
|
|
free(playlist->default_core_name);
|
|
|
|
playlist->default_core_name = NULL;
|
|
|
|
|
2017-08-19 02:08:51 +00:00
|
|
|
for (i = 0; i < playlist->size; i++)
|
2016-09-29 07:36:24 +00:00
|
|
|
{
|
|
|
|
struct playlist_entry *entry = &playlist->entries[i];
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
playlist_free_entry(entry);
|
|
|
|
}
|
2015-06-09 20:06:20 +00:00
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
free(playlist->entries);
|
2015-06-09 20:06:20 +00:00
|
|
|
playlist->entries = NULL;
|
2013-04-27 23:35:31 +00:00
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
free(playlist);
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 18:42:11 +00:00
|
|
|
/**
|
2016-05-16 07:07:44 +00:00
|
|
|
* playlist_clear:
|
2015-01-17 02:48:59 +00:00
|
|
|
* @playlist : Playlist handle.
|
2015-01-16 18:42:11 +00:00
|
|
|
*
|
|
|
|
* Clears all playlist entries in playlist.
|
|
|
|
**/
|
2016-05-16 07:07:44 +00:00
|
|
|
void playlist_clear(playlist_t *playlist)
|
2013-12-16 02:27:17 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
2014-08-15 15:32:38 +00:00
|
|
|
if (!playlist)
|
2014-06-01 00:16:48 +00:00
|
|
|
return;
|
|
|
|
|
2017-08-19 02:08:51 +00:00
|
|
|
for (i = 0; i < playlist->size; i++)
|
2016-09-29 07:36:24 +00:00
|
|
|
{
|
|
|
|
struct playlist_entry *entry = &playlist->entries[i];
|
|
|
|
|
|
|
|
if (entry)
|
|
|
|
playlist_free_entry(entry);
|
|
|
|
}
|
2014-08-15 15:32:38 +00:00
|
|
|
playlist->size = 0;
|
2013-12-16 02:27:17 +00:00
|
|
|
}
|
|
|
|
|
2015-01-16 19:19:21 +00:00
|
|
|
/**
|
2016-05-16 07:07:44 +00:00
|
|
|
* playlist_size:
|
2015-01-17 02:48:59 +00:00
|
|
|
* @playlist : Playlist handle.
|
2015-01-16 19:19:21 +00:00
|
|
|
*
|
|
|
|
* Gets size of playlist.
|
|
|
|
* Returns: size of playlist.
|
|
|
|
**/
|
2016-05-16 07:07:44 +00:00
|
|
|
size_t playlist_size(playlist_t *playlist)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2015-01-16 19:19:21 +00:00
|
|
|
if (!playlist)
|
|
|
|
return 0;
|
|
|
|
return playlist->size;
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2019-07-30 16:11:43 +00:00
|
|
|
/**
|
|
|
|
* playlist_capacity:
|
|
|
|
* @playlist : Playlist handle.
|
|
|
|
*
|
|
|
|
* Gets maximum capacity of playlist.
|
|
|
|
* Returns: maximum capacity of playlist.
|
|
|
|
**/
|
|
|
|
size_t playlist_capacity(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return 0;
|
|
|
|
return playlist->cap;
|
|
|
|
}
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
static JSON_Parser_HandlerResult JSONStartArrayHandler(JSON_Parser parser)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
|
|
|
|
pCtx->array_depth++;
|
|
|
|
|
|
|
|
if (pCtx->object_depth == 1)
|
|
|
|
{
|
|
|
|
if (string_is_equal(pCtx->current_meta_string, "items") && pCtx->array_depth == 1)
|
|
|
|
pCtx->in_items = true;
|
|
|
|
}
|
2019-04-11 04:09:13 +00:00
|
|
|
else if (pCtx->object_depth == 2)
|
|
|
|
{
|
|
|
|
if (pCtx->array_depth == 2)
|
|
|
|
if (string_is_equal(pCtx->current_items_string, "subsystem_roms"))
|
|
|
|
pCtx->in_subsystem_roms = true;
|
|
|
|
}
|
2019-01-12 18:46:28 +00:00
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSON_Parser_HandlerResult JSONEndArrayHandler(JSON_Parser parser)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
|
|
|
|
retro_assert(pCtx->array_depth > 0);
|
|
|
|
|
|
|
|
pCtx->array_depth--;
|
|
|
|
|
|
|
|
if (pCtx->object_depth == 1)
|
|
|
|
{
|
|
|
|
if (pCtx->in_items && string_is_equal(pCtx->current_meta_string, "items") && pCtx->array_depth == 0)
|
|
|
|
{
|
|
|
|
free(pCtx->current_meta_string);
|
|
|
|
pCtx->current_meta_string = NULL;
|
|
|
|
pCtx->in_items = false;
|
2019-04-11 04:09:13 +00:00
|
|
|
|
|
|
|
if (pCtx->current_items_string)
|
|
|
|
{
|
|
|
|
free(pCtx->current_items_string);
|
|
|
|
pCtx->current_items_string = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pCtx->object_depth == 2)
|
|
|
|
{
|
|
|
|
if (pCtx->in_subsystem_roms && string_is_equal(pCtx->current_items_string, "subsystem_roms") && pCtx->array_depth == 1)
|
2019-04-29 02:04:33 +00:00
|
|
|
{
|
2019-04-11 04:09:13 +00:00
|
|
|
pCtx->in_subsystem_roms = false;
|
2019-04-29 02:04:33 +00:00
|
|
|
}
|
2019-01-12 18:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
static JSON_Parser_HandlerResult JSONStartObjectHandler(JSON_Parser parser)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
|
|
|
|
pCtx->object_depth++;
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->in_items && pCtx->object_depth == 2)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-07-30 16:11:43 +00:00
|
|
|
if ((pCtx->array_depth == 1) && !pCtx->capacity_exceeded)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
|
|
|
if (pCtx->playlist->size < pCtx->playlist->cap)
|
|
|
|
pCtx->current_entry = &pCtx->playlist->entries[pCtx->playlist->size];
|
|
|
|
else
|
2019-07-30 16:11:43 +00:00
|
|
|
{
|
|
|
|
/* Hit max item limit.
|
|
|
|
* Note: We can't just abort here, since there may
|
|
|
|
* be more metadata to read at the end of the file... */
|
|
|
|
RARCH_WARN("JSON file contains more entries than current playlist capacity. Excess entries will be discarded.\n");
|
|
|
|
pCtx->capacity_exceeded = true;
|
|
|
|
pCtx->current_entry = NULL;
|
|
|
|
/* In addition, since we are discarding excess entries,
|
|
|
|
* the playlist must be flagged as being modified
|
|
|
|
* (i.e. the playlist is not the same as when it was
|
|
|
|
* last saved to disk...) */
|
|
|
|
pCtx->playlist->modified = true;
|
|
|
|
}
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSON_Parser_HandlerResult JSONEndObjectHandler(JSON_Parser parser)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->in_items && pCtx->object_depth == 2)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-07-30 16:11:43 +00:00
|
|
|
if ((pCtx->array_depth == 1) && !pCtx->capacity_exceeded)
|
2019-01-09 22:13:13 +00:00
|
|
|
pCtx->playlist->size++;
|
|
|
|
}
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
retro_assert(pCtx->object_depth > 0);
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
pCtx->object_depth--;
|
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
static JSON_Parser_HandlerResult JSONStringHandler(JSON_Parser parser, char *pValue, size_t length, JSON_StringAttributes attributes)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
(void)attributes; /* unused */
|
|
|
|
|
2019-04-11 04:09:13 +00:00
|
|
|
if (pCtx->in_items && pCtx->in_subsystem_roms && pCtx->object_depth == 2 && pCtx->array_depth == 2)
|
|
|
|
{
|
|
|
|
if (pCtx->current_entry_string_list_val && length && !string_is_empty(pValue))
|
|
|
|
{
|
|
|
|
union string_list_elem_attr attr = {0};
|
|
|
|
|
|
|
|
if (!*pCtx->current_entry_string_list_val)
|
|
|
|
*pCtx->current_entry_string_list_val = string_list_new();
|
|
|
|
|
|
|
|
string_list_append(*pCtx->current_entry_string_list_val, pValue, attr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pCtx->in_items && pCtx->object_depth == 2)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->array_depth == 1)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->current_entry_val && length && !string_is_empty(pValue))
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-02-12 05:32:01 +00:00
|
|
|
if (*pCtx->current_entry_val)
|
|
|
|
free(*pCtx->current_entry_val);
|
2019-01-12 18:46:28 +00:00
|
|
|
*pCtx->current_entry_val = strdup(pValue);
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* must be a value for an unknown member we aren't tracking, skip it */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-01-12 18:46:28 +00:00
|
|
|
else if (pCtx->object_depth == 1)
|
|
|
|
{
|
|
|
|
if (pCtx->array_depth == 0)
|
|
|
|
{
|
2019-06-26 16:40:00 +00:00
|
|
|
if (pCtx->current_meta_val && length && !string_is_empty(pValue))
|
2019-01-12 18:46:28 +00:00
|
|
|
{
|
|
|
|
/* handle any top-level playlist metadata here */
|
|
|
|
/*RARCH_LOG("found meta: %s = %s\n", pCtx->current_meta_string, pValue);*/
|
2019-01-09 22:13:13 +00:00
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
free(pCtx->current_meta_string);
|
2019-02-12 05:32:01 +00:00
|
|
|
pCtx->current_meta_string = NULL;
|
2019-06-26 16:40:00 +00:00
|
|
|
|
|
|
|
if (*pCtx->current_meta_val)
|
|
|
|
free(*pCtx->current_meta_val);
|
|
|
|
|
|
|
|
*pCtx->current_meta_val = strdup(pValue);
|
2019-01-12 18:46:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pCtx->current_entry_val = NULL;
|
2019-06-26 16:40:00 +00:00
|
|
|
pCtx->current_meta_val = NULL;
|
2019-01-09 22:13:13 +00:00
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
2019-02-12 05:32:01 +00:00
|
|
|
static JSON_Parser_HandlerResult JSONNumberHandler(JSON_Parser parser, char *pValue, size_t length, JSON_StringAttributes attributes)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
(void)attributes; /* unused */
|
|
|
|
|
|
|
|
if (pCtx->in_items && pCtx->object_depth == 2)
|
|
|
|
{
|
|
|
|
if (pCtx->array_depth == 1)
|
|
|
|
{
|
|
|
|
if (pCtx->current_entry_int_val && length && !string_is_empty(pValue))
|
2019-04-08 21:13:39 +00:00
|
|
|
*pCtx->current_entry_int_val = (int)strtoul(pValue, NULL, 10);
|
2019-02-12 05:32:01 +00:00
|
|
|
else if (pCtx->current_entry_uint_val && length && !string_is_empty(pValue))
|
2019-04-08 21:13:39 +00:00
|
|
|
*pCtx->current_entry_uint_val = (unsigned)strtoul(pValue, NULL, 10);
|
2019-02-12 05:32:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* must be a value for an unknown member we aren't tracking, skip it */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pCtx->object_depth == 1)
|
|
|
|
{
|
|
|
|
if (pCtx->array_depth == 0)
|
|
|
|
{
|
|
|
|
if (pCtx->current_meta_string && length && !string_is_empty(pValue))
|
|
|
|
{
|
|
|
|
/* handle any top-level playlist metadata here */
|
|
|
|
/*RARCH_LOG("found meta: %s = %s\n", pCtx->current_meta_string, pValue);*/
|
|
|
|
|
|
|
|
free(pCtx->current_meta_string);
|
|
|
|
pCtx->current_meta_string = NULL;
|
2019-07-18 19:13:14 +00:00
|
|
|
|
2019-08-27 16:10:35 +00:00
|
|
|
if (pCtx->current_meta_label_display_mode_val)
|
|
|
|
*pCtx->current_meta_label_display_mode_val = (enum playlist_label_display_mode)strtoul(pValue, NULL, 10);
|
|
|
|
else if (pCtx->current_meta_thumbnail_mode_val)
|
|
|
|
*pCtx->current_meta_thumbnail_mode_val = (enum playlist_thumbnail_mode)strtoul(pValue, NULL, 10);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* must be a value for an unknown member we aren't tracking, skip it */
|
|
|
|
}
|
2019-02-12 05:32:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-27 16:10:35 +00:00
|
|
|
pCtx->current_entry_int_val = NULL;
|
|
|
|
pCtx->current_entry_uint_val = NULL;
|
|
|
|
pCtx->current_meta_label_display_mode_val = NULL;
|
|
|
|
pCtx->current_meta_thumbnail_mode_val = NULL;
|
2019-02-12 05:32:01 +00:00
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
static JSON_Parser_HandlerResult JSONObjectMemberHandler(JSON_Parser parser, char *pValue, size_t length, JSON_StringAttributes attributes)
|
|
|
|
{
|
|
|
|
JSONContext *pCtx = (JSONContext*)JSON_Parser_GetUserData(parser);
|
|
|
|
(void)attributes; /* unused */
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->in_items && pCtx->object_depth == 2)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->array_depth == 1)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-01-12 18:46:28 +00:00
|
|
|
if (pCtx->current_entry_val)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
|
|
|
/* something went wrong */
|
|
|
|
RARCH_WARN("JSON parsing failed at line %d.\n", __LINE__);
|
|
|
|
return JSON_Parser_Abort;
|
|
|
|
}
|
|
|
|
|
2019-04-29 02:04:33 +00:00
|
|
|
if (length)
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-04-29 02:04:33 +00:00
|
|
|
if (!string_is_empty(pValue))
|
|
|
|
{
|
|
|
|
if (!string_is_empty(pCtx->current_items_string))
|
|
|
|
free(pCtx->current_items_string);
|
|
|
|
pCtx->current_items_string = strdup(pValue);
|
|
|
|
}
|
2019-04-11 04:09:13 +00:00
|
|
|
|
2019-07-30 16:11:43 +00:00
|
|
|
if (!pCtx->capacity_exceeded)
|
|
|
|
{
|
|
|
|
if (string_is_equal(pValue, "path"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->path;
|
|
|
|
else if (string_is_equal(pValue, "label"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->label;
|
|
|
|
else if (string_is_equal(pValue, "core_path"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->core_path;
|
|
|
|
else if (string_is_equal(pValue, "core_name"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->core_name;
|
|
|
|
else if (string_is_equal(pValue, "crc32"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->crc32;
|
|
|
|
else if (string_is_equal(pValue, "db_name"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->db_name;
|
|
|
|
else if (string_is_equal(pValue, "subsystem_ident"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->subsystem_ident;
|
|
|
|
else if (string_is_equal(pValue, "subsystem_name"))
|
|
|
|
pCtx->current_entry_val = &pCtx->current_entry->subsystem_name;
|
|
|
|
else if (string_is_equal(pValue, "subsystem_roms"))
|
|
|
|
pCtx->current_entry_string_list_val = &pCtx->current_entry->subsystem_roms;
|
|
|
|
else if (string_is_equal(pValue, "runtime_hours"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_hours;
|
|
|
|
else if (string_is_equal(pValue, "runtime_minutes"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_minutes;
|
|
|
|
else if (string_is_equal(pValue, "runtime_seconds"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->runtime_seconds;
|
|
|
|
else if (string_is_equal(pValue, "last_played_year"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_year;
|
|
|
|
else if (string_is_equal(pValue, "last_played_month"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_month;
|
|
|
|
else if (string_is_equal(pValue, "last_played_day"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_day;
|
|
|
|
else if (string_is_equal(pValue, "last_played_hour"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_hour;
|
|
|
|
else if (string_is_equal(pValue, "last_played_minute"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_minute;
|
|
|
|
else if (string_is_equal(pValue, "last_played_second"))
|
|
|
|
pCtx->current_entry_uint_val = &pCtx->current_entry->last_played_second;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ignore unknown members */
|
|
|
|
}
|
|
|
|
}
|
2019-01-12 18:46:28 +00:00
|
|
|
else
|
|
|
|
{
|
2019-07-30 16:11:43 +00:00
|
|
|
pCtx->current_entry_val = NULL;
|
|
|
|
pCtx->current_entry_uint_val = NULL;
|
|
|
|
pCtx->current_entry_string_list_val = NULL;
|
2019-01-12 18:46:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (pCtx->object_depth == 1)
|
|
|
|
{
|
|
|
|
if (pCtx->array_depth == 0)
|
|
|
|
{
|
2019-06-26 16:40:00 +00:00
|
|
|
if (pCtx->current_meta_val)
|
|
|
|
{
|
|
|
|
/* something went wrong */
|
|
|
|
RARCH_WARN("JSON parsing failed at line %d.\n", __LINE__);
|
|
|
|
return JSON_Parser_Abort;
|
|
|
|
}
|
|
|
|
|
2019-01-12 18:46:28 +00:00
|
|
|
if (length)
|
|
|
|
{
|
2019-02-12 05:32:01 +00:00
|
|
|
if (pCtx->current_meta_string)
|
|
|
|
free(pCtx->current_meta_string);
|
2019-01-12 18:46:28 +00:00
|
|
|
pCtx->current_meta_string = strdup(pValue);
|
2019-06-26 16:40:00 +00:00
|
|
|
|
|
|
|
if (string_is_equal(pValue, "default_core_path"))
|
|
|
|
pCtx->current_meta_val = &pCtx->playlist->default_core_path;
|
|
|
|
else if (string_is_equal(pValue, "default_core_name"))
|
|
|
|
pCtx->current_meta_val = &pCtx->playlist->default_core_name;
|
2019-07-18 19:13:14 +00:00
|
|
|
else if (string_is_equal(pValue, "label_display_mode"))
|
2019-08-27 16:10:35 +00:00
|
|
|
pCtx->current_meta_label_display_mode_val = &pCtx->playlist->label_display_mode;
|
2019-08-15 17:04:24 +00:00
|
|
|
else if (string_is_equal(pValue, "right_thumbnail_mode"))
|
2019-08-27 16:10:35 +00:00
|
|
|
pCtx->current_meta_thumbnail_mode_val = &pCtx->playlist->right_thumbnail_mode;
|
2019-08-15 17:04:24 +00:00
|
|
|
else if (string_is_equal(pValue, "left_thumbnail_mode"))
|
2019-08-27 16:10:35 +00:00
|
|
|
pCtx->current_meta_thumbnail_mode_val = &pCtx->playlist->left_thumbnail_mode;
|
2019-06-26 16:40:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ignore unknown members */
|
|
|
|
}
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return JSON_Parser_Continue;
|
|
|
|
}
|
|
|
|
|
2019-06-27 11:36:58 +00:00
|
|
|
static void get_old_format_metadata_value(
|
2019-06-27 12:05:46 +00:00
|
|
|
char *metadata_line, char *value, size_t len)
|
2019-06-27 11:36:58 +00:00
|
|
|
{
|
|
|
|
char *start = NULL;
|
|
|
|
char *end = NULL;
|
|
|
|
|
|
|
|
start = strchr(metadata_line, '\"');
|
|
|
|
|
|
|
|
if (!start)
|
|
|
|
return;
|
|
|
|
|
|
|
|
start++;
|
|
|
|
end = strchr(start, '\"');
|
|
|
|
|
|
|
|
if (!end)
|
|
|
|
return;
|
|
|
|
|
|
|
|
*end = '\0';
|
|
|
|
strlcpy(value, start, len);
|
|
|
|
}
|
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
static bool playlist_read_file(
|
|
|
|
playlist_t *playlist, const char *path)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2016-10-09 07:07:53 +00:00
|
|
|
unsigned i;
|
2019-01-09 22:13:13 +00:00
|
|
|
bool new_format = true;
|
|
|
|
RFILE *file = filestream_open(path,
|
|
|
|
RETRO_VFS_FILE_ACCESS_READ, RETRO_VFS_FILE_ACCESS_HINT_NONE);
|
2014-08-02 23:43:10 +00:00
|
|
|
|
2015-01-16 18:42:11 +00:00
|
|
|
/* If playlist file does not exist,
|
|
|
|
* create an empty playlist instead.
|
|
|
|
*/
|
2014-11-29 15:05:52 +00:00
|
|
|
if (!file)
|
|
|
|
return true;
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
/* Detect format of playlist */
|
|
|
|
{
|
2019-07-17 20:34:17 +00:00
|
|
|
int test_char;
|
2019-01-09 22:13:13 +00:00
|
|
|
|
2019-07-17 20:34:17 +00:00
|
|
|
/* Read file until we find the first printable non-whitespace
|
2019-07-04 15:43:59 +00:00
|
|
|
* ASCII character */
|
2019-07-17 20:34:17 +00:00
|
|
|
do
|
2019-01-19 00:03:25 +00:00
|
|
|
{
|
2019-07-04 15:43:59 +00:00
|
|
|
test_char = filestream_getc(file);
|
|
|
|
|
2019-07-17 20:34:17 +00:00
|
|
|
if (test_char == EOF) /* read error or end of file */
|
2019-07-04 15:43:59 +00:00
|
|
|
goto end;
|
2019-01-19 00:03:25 +00:00
|
|
|
}
|
2019-07-17 20:34:17 +00:00
|
|
|
while (!isgraph(test_char) || test_char > 0x7F);
|
2019-01-16 17:39:43 +00:00
|
|
|
|
2019-07-04 15:43:59 +00:00
|
|
|
if (test_char == '{')
|
2019-01-09 22:13:13 +00:00
|
|
|
{
|
2019-07-04 15:43:59 +00:00
|
|
|
/* New playlist format detected */
|
|
|
|
/*RARCH_LOG("New playlist format detected.\n");*/
|
|
|
|
new_format = true;
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-04 15:43:59 +00:00
|
|
|
/* old playlist format detected */
|
|
|
|
/*RARCH_LOG("Old playlist format detected.\n");*/
|
|
|
|
new_format = false;
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
2019-07-04 15:43:59 +00:00
|
|
|
|
|
|
|
/* Reset file to start */
|
|
|
|
filestream_seek(file, 0, SEEK_SET);
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
2017-12-11 11:57:53 +00:00
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
if (new_format)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2019-01-09 22:13:13 +00:00
|
|
|
JSONContext context = {0};
|
|
|
|
context.parser = JSON_Parser_Create(NULL);
|
|
|
|
context.file = file;
|
|
|
|
context.playlist = playlist;
|
|
|
|
|
|
|
|
if (!context.parser)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to create JSON parser\n");
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2019-04-13 16:57:02 +00:00
|
|
|
#if 0
|
|
|
|
JSON_Parser_SetTrackObjectMembers(context.parser, JSON_True);
|
|
|
|
#endif
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Parser_SetAllowBOM(context.parser, JSON_True);
|
|
|
|
JSON_Parser_SetAllowComments(context.parser, JSON_True);
|
|
|
|
JSON_Parser_SetAllowSpecialNumbers(context.parser, JSON_True);
|
|
|
|
JSON_Parser_SetAllowHexNumbers(context.parser, JSON_True);
|
|
|
|
JSON_Parser_SetAllowUnescapedControlCharacters(context.parser, JSON_True);
|
|
|
|
JSON_Parser_SetReplaceInvalidEncodingSequences(context.parser, JSON_True);
|
|
|
|
|
2019-04-13 16:57:02 +00:00
|
|
|
#if 0
|
|
|
|
JSON_Parser_SetNullHandler(context.parser, &JSONNullHandler);
|
|
|
|
JSON_Parser_SetBooleanHandler(context.parser, &JSONBooleanHandler);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Parser_SetSpecialNumberHandler(context.parser, &JSONSpecialNumberHandler);
|
2019-04-13 16:57:02 +00:00
|
|
|
JSON_Parser_SetArrayItemHandler(context.parser, &JSONArrayItemHandler);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
JSON_Parser_SetNumberHandler(context.parser, &JSONNumberHandler);
|
|
|
|
JSON_Parser_SetStringHandler(context.parser, &JSONStringHandler);
|
|
|
|
JSON_Parser_SetStartObjectHandler(context.parser, &JSONStartObjectHandler);
|
|
|
|
JSON_Parser_SetEndObjectHandler(context.parser, &JSONEndObjectHandler);
|
|
|
|
JSON_Parser_SetObjectMemberHandler(context.parser, &JSONObjectMemberHandler);
|
|
|
|
JSON_Parser_SetStartArrayHandler(context.parser, &JSONStartArrayHandler);
|
|
|
|
JSON_Parser_SetEndArrayHandler(context.parser, &JSONEndArrayHandler);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Parser_SetUserData(context.parser, &context);
|
|
|
|
|
|
|
|
while (!filestream_eof(file))
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2019-01-09 22:13:13 +00:00
|
|
|
char chunk[4096] = {0};
|
|
|
|
int64_t length = filestream_read(file, chunk, sizeof(chunk));
|
2015-01-16 18:42:11 +00:00
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
if (!length && !filestream_eof(file))
|
|
|
|
{
|
|
|
|
RARCH_WARN("Could not read JSON input.\n");
|
2019-07-22 13:42:48 +00:00
|
|
|
goto json_cleanup;
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
2013-06-09 19:59:48 +00:00
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
if (!JSON_Parser_Parse(context.parser, chunk, length, JSON_False))
|
|
|
|
{
|
2019-07-30 16:11:43 +00:00
|
|
|
/* Note: Chunk may not be null-terminated.
|
|
|
|
* It is therefore dangerous to print its contents.
|
|
|
|
* Setting a size limit here mitigates the issue, but
|
|
|
|
* in general this is not good practice...
|
|
|
|
* Addendum: RARCH_WARN() actually limits the printed
|
|
|
|
* buffer size anyway, so this warning message is most
|
|
|
|
* likely worthless... */
|
|
|
|
RARCH_WARN("Error parsing chunk:\n---snip---\n%.*s\n---snip---\n", 4096, chunk);
|
2019-01-09 22:13:13 +00:00
|
|
|
JSONLogError(&context);
|
2019-07-22 13:42:48 +00:00
|
|
|
goto json_cleanup;
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
if (!JSON_Parser_Parse(context.parser, NULL, 0, JSON_True))
|
|
|
|
{
|
|
|
|
RARCH_WARN("Error parsing JSON.\n");
|
|
|
|
JSONLogError(&context);
|
2019-07-22 13:42:48 +00:00
|
|
|
goto json_cleanup;
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
2013-06-09 19:59:48 +00:00
|
|
|
|
2019-07-22 13:42:48 +00:00
|
|
|
json_cleanup:
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
JSON_Parser_Free(context.parser);
|
2019-02-12 05:32:01 +00:00
|
|
|
|
|
|
|
if (context.current_meta_string)
|
|
|
|
free(context.current_meta_string);
|
2019-04-11 04:09:13 +00:00
|
|
|
|
|
|
|
if (context.current_items_string)
|
|
|
|
free(context.current_items_string);
|
2019-01-09 22:13:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-16 21:14:48 +00:00
|
|
|
char buf[PLAYLIST_ENTRIES][1024] = {{0}};
|
2019-06-27 11:36:58 +00:00
|
|
|
char metadata_line[1024];
|
|
|
|
char default_core_path[1024];
|
|
|
|
char default_core_name[1024];
|
2019-07-09 00:03:20 +00:00
|
|
|
char metadata_char;
|
2019-06-27 11:36:58 +00:00
|
|
|
size_t metadata_counter;
|
2019-01-09 22:13:13 +00:00
|
|
|
|
|
|
|
for (i = 0; i < PLAYLIST_ENTRIES; i++)
|
|
|
|
buf[i][0] = '\0';
|
2013-05-02 12:42:58 +00:00
|
|
|
|
2019-06-27 11:36:58 +00:00
|
|
|
metadata_line[0] = '\0';
|
|
|
|
default_core_path[0] = '\0';
|
|
|
|
default_core_name[0] = '\0';
|
2019-07-09 00:03:20 +00:00
|
|
|
metadata_char = 0;
|
2019-06-27 11:36:58 +00:00
|
|
|
metadata_counter = 0;
|
|
|
|
|
|
|
|
/* Attempt to read metadata lines at end of file */
|
|
|
|
filestream_seek(file, -1, SEEK_END);
|
|
|
|
if (filestream_error(file))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* > Exclude trailing newline */
|
|
|
|
metadata_char = filestream_getc(file);
|
|
|
|
|
|
|
|
while((metadata_char == '\n') ||
|
|
|
|
(metadata_char == '\r'))
|
|
|
|
{
|
|
|
|
filestream_seek(file, -2, SEEK_CUR);
|
|
|
|
if (filestream_error(file))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
metadata_char = filestream_getc(file);
|
|
|
|
}
|
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
/* Search backwards for the next four newlines */
|
|
|
|
while (metadata_counter < 4)
|
2019-06-27 11:36:58 +00:00
|
|
|
{
|
|
|
|
filestream_seek(file, -2, SEEK_CUR);
|
|
|
|
if (filestream_error(file))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
metadata_char = filestream_getc(file);
|
|
|
|
if (metadata_char == '\n')
|
|
|
|
metadata_counter++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* > Get default_core_path */
|
|
|
|
if (!filestream_gets(file, metadata_line, sizeof(metadata_line)))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (strncmp("default_core_path",
|
|
|
|
metadata_line,
|
|
|
|
STRLEN_CONST("default_core_path")) == 0)
|
|
|
|
get_old_format_metadata_value(
|
|
|
|
metadata_line, default_core_path, sizeof(default_core_path));
|
|
|
|
|
|
|
|
/* > Get default_core_name */
|
|
|
|
if (!filestream_gets(file, metadata_line, sizeof(metadata_line)))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (strncmp("default_core_name",
|
|
|
|
metadata_line,
|
|
|
|
STRLEN_CONST("default_core_name")) == 0)
|
|
|
|
get_old_format_metadata_value(
|
|
|
|
metadata_line, default_core_name, sizeof(default_core_name));
|
|
|
|
|
2019-07-18 19:13:14 +00:00
|
|
|
/* > Get label_display_mode */
|
|
|
|
if (!filestream_gets(file, metadata_line, sizeof(metadata_line)))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (strncmp("label_display_mode",
|
|
|
|
metadata_line,
|
|
|
|
STRLEN_CONST("label_display_mode")) == 0)
|
|
|
|
{
|
2019-08-15 17:04:24 +00:00
|
|
|
unsigned display_mode;
|
|
|
|
char display_mode_str[4] = {0};
|
2019-07-18 19:13:14 +00:00
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
get_old_format_metadata_value(
|
|
|
|
metadata_line, display_mode_str, sizeof(display_mode_str));
|
|
|
|
|
|
|
|
display_mode = string_to_unsigned(display_mode_str);
|
|
|
|
|
|
|
|
if (display_mode <= LABEL_DISPLAY_MODE_KEEP_REGION_AND_DISC_INDEX)
|
|
|
|
playlist->label_display_mode = (enum playlist_label_display_mode)display_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* > Get thumbnail modes */
|
|
|
|
if (!filestream_gets(file, metadata_line, sizeof(metadata_line)))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
if (strncmp("thumbnail_mode",
|
|
|
|
metadata_line,
|
|
|
|
STRLEN_CONST("thumbnail_mode")) == 0)
|
|
|
|
{
|
|
|
|
char thumbnail_mode_str[8] = {0};
|
|
|
|
struct string_list *thumbnail_modes = NULL;
|
|
|
|
|
|
|
|
get_old_format_metadata_value(
|
|
|
|
metadata_line, thumbnail_mode_str, sizeof(thumbnail_mode_str));
|
|
|
|
|
|
|
|
thumbnail_modes = string_split(thumbnail_mode_str, "|");
|
|
|
|
|
|
|
|
if (thumbnail_modes)
|
2019-07-18 19:13:14 +00:00
|
|
|
{
|
2019-08-15 17:04:24 +00:00
|
|
|
if (thumbnail_modes->size == 2)
|
|
|
|
{
|
|
|
|
unsigned thumbnail_mode;
|
|
|
|
|
|
|
|
/* Right thumbnail mode */
|
|
|
|
thumbnail_mode = string_to_unsigned(thumbnail_modes->elems[0].data);
|
|
|
|
if (thumbnail_mode <= PLAYLIST_THUMBNAIL_MODE_BOXARTS)
|
|
|
|
playlist->right_thumbnail_mode = (enum playlist_thumbnail_mode)thumbnail_mode;
|
|
|
|
|
|
|
|
/* Left thumbnail mode */
|
|
|
|
thumbnail_mode = string_to_unsigned(thumbnail_modes->elems[1].data);
|
|
|
|
if (thumbnail_mode <= PLAYLIST_THUMBNAIL_MODE_BOXARTS)
|
|
|
|
playlist->left_thumbnail_mode = (enum playlist_thumbnail_mode)thumbnail_mode;
|
|
|
|
}
|
2019-07-18 19:13:14 +00:00
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
string_list_free(thumbnail_modes);
|
2019-07-18 19:13:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
/* > Populate default core path/name, if required
|
|
|
|
* (if one is empty, the other should be ignored) */
|
2019-06-27 11:36:58 +00:00
|
|
|
if (!string_is_empty(default_core_path) &&
|
|
|
|
!string_is_empty(default_core_name))
|
|
|
|
{
|
|
|
|
playlist->default_core_path = strdup(default_core_path);
|
|
|
|
playlist->default_core_name = strdup(default_core_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read playlist entries */
|
|
|
|
filestream_seek(file, 0, SEEK_SET);
|
|
|
|
if (filestream_error(file))
|
|
|
|
goto end;
|
|
|
|
|
2019-01-09 22:13:13 +00:00
|
|
|
for (playlist->size = 0; playlist->size < playlist->cap; )
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
struct playlist_entry *entry = NULL;
|
|
|
|
for (i = 0; i < PLAYLIST_ENTRIES; i++)
|
|
|
|
{
|
|
|
|
char *last = NULL;
|
|
|
|
*buf[i] = '\0';
|
|
|
|
|
|
|
|
if (!filestream_gets(file, buf[i], sizeof(buf[i])))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
/* Read playlist entry and terminate string with NUL character
|
|
|
|
* regardless of Windows or Unix line endings
|
|
|
|
*/
|
2019-04-11 04:09:13 +00:00
|
|
|
if ((last = strrchr(buf[i], '\r')))
|
2019-01-09 22:13:13 +00:00
|
|
|
*last = '\0';
|
2019-04-11 04:09:13 +00:00
|
|
|
else if ((last = strrchr(buf[i], '\n')))
|
2019-01-09 22:13:13 +00:00
|
|
|
*last = '\0';
|
|
|
|
}
|
|
|
|
|
|
|
|
entry = &playlist->entries[playlist->size];
|
|
|
|
|
|
|
|
if (!*buf[2] || !*buf[3])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (*buf[0])
|
|
|
|
entry->path = strdup(buf[0]);
|
|
|
|
if (*buf[1])
|
|
|
|
entry->label = strdup(buf[1]);
|
|
|
|
|
|
|
|
entry->core_path = strdup(buf[2]);
|
|
|
|
entry->core_name = strdup(buf[3]);
|
|
|
|
if (*buf[4])
|
|
|
|
entry->crc32 = strdup(buf[4]);
|
|
|
|
if (*buf[5])
|
|
|
|
entry->db_name = strdup(buf[5]);
|
|
|
|
playlist->size++;
|
|
|
|
}
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
|
|
|
|
2013-06-09 19:59:48 +00:00
|
|
|
end:
|
2019-01-09 22:13:13 +00:00
|
|
|
filestream_close(file);
|
2013-04-27 22:15:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-10 15:40:29 +00:00
|
|
|
void playlist_free_cached(void)
|
|
|
|
{
|
|
|
|
playlist_free(playlist_cached);
|
|
|
|
playlist_cached = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
playlist_t *playlist_get_cached(void)
|
|
|
|
{
|
|
|
|
if (playlist_cached)
|
|
|
|
return playlist_cached;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool playlist_init_cached(const char *path, size_t size)
|
|
|
|
{
|
|
|
|
playlist_t *playlist = playlist_init(path, size);
|
|
|
|
if (!playlist)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
playlist_cached = playlist;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-16 18:42:11 +00:00
|
|
|
/**
|
2016-05-16 07:07:44 +00:00
|
|
|
* playlist_init:
|
2015-01-17 02:48:59 +00:00
|
|
|
* @path : Path to playlist contents file.
|
2015-01-16 18:42:11 +00:00
|
|
|
* @size : Maximum capacity of playlist size.
|
|
|
|
*
|
|
|
|
* Creates and initializes a playlist.
|
|
|
|
*
|
|
|
|
* Returns: handle to new playlist if successful, otherwise NULL
|
|
|
|
**/
|
2016-05-16 07:07:44 +00:00
|
|
|
playlist_t *playlist_init(const char *path, size_t size)
|
2013-04-27 22:15:59 +00:00
|
|
|
{
|
2016-12-25 00:46:32 +00:00
|
|
|
struct playlist_entry *entries = NULL;
|
2017-09-29 03:13:10 +00:00
|
|
|
playlist_t *playlist = (playlist_t*)malloc(sizeof(*playlist));
|
2014-08-15 15:32:38 +00:00
|
|
|
if (!playlist)
|
2013-04-27 22:15:59 +00:00
|
|
|
return NULL;
|
|
|
|
|
2016-12-25 00:46:32 +00:00
|
|
|
entries = (struct playlist_entry*)calloc(size, sizeof(*entries));
|
|
|
|
if (!entries)
|
|
|
|
{
|
|
|
|
free(playlist);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
playlist->modified = false;
|
|
|
|
playlist->size = 0;
|
|
|
|
playlist->cap = size;
|
|
|
|
playlist->conf_path = strdup(path);
|
|
|
|
playlist->default_core_name = NULL;
|
|
|
|
playlist->default_core_path = NULL;
|
|
|
|
playlist->entries = entries;
|
|
|
|
playlist->label_display_mode = LABEL_DISPLAY_MODE_DEFAULT;
|
|
|
|
playlist->right_thumbnail_mode = PLAYLIST_THUMBNAIL_MODE_DEFAULT;
|
|
|
|
playlist->left_thumbnail_mode = PLAYLIST_THUMBNAIL_MODE_DEFAULT;
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2016-05-16 07:07:44 +00:00
|
|
|
playlist_read_file(playlist, path);
|
2013-04-27 22:15:59 +00:00
|
|
|
|
2014-08-15 15:32:38 +00:00
|
|
|
return playlist;
|
2013-04-27 22:15:59 +00:00
|
|
|
}
|
2015-06-11 13:04:35 +00:00
|
|
|
|
2016-08-28 16:47:34 +00:00
|
|
|
static int playlist_qsort_func(const struct playlist_entry *a,
|
|
|
|
const struct playlist_entry *b)
|
|
|
|
{
|
2019-03-05 15:37:50 +00:00
|
|
|
char *a_str = NULL;
|
|
|
|
char *b_str = NULL;
|
|
|
|
char *a_fallback_label = NULL;
|
|
|
|
char *b_fallback_label = NULL;
|
|
|
|
int ret = 0;
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-03-05 15:37:50 +00:00
|
|
|
if (!a || !b)
|
|
|
|
goto end;
|
|
|
|
|
2019-04-13 16:57:02 +00:00
|
|
|
a_str = a->label;
|
|
|
|
b_str = b->label;
|
2019-03-05 15:37:50 +00:00
|
|
|
|
|
|
|
/* It is quite possible for playlist labels
|
|
|
|
* to be blank. If that is the case, have to use
|
|
|
|
* filename as a fallback (this is slow, but we
|
|
|
|
* have no other option...) */
|
|
|
|
if (string_is_empty(a_str))
|
|
|
|
{
|
|
|
|
if (string_is_empty(a->path))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
a_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char));
|
2019-04-11 04:09:13 +00:00
|
|
|
|
2019-03-05 15:37:50 +00:00
|
|
|
if (!a_fallback_label)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
fill_short_pathname_representation(a_fallback_label, a->path, PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
|
|
|
|
if (string_is_empty(a_fallback_label))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
a_str = a_fallback_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (string_is_empty(b_str))
|
|
|
|
{
|
|
|
|
if (string_is_empty(b->path))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
b_fallback_label = (char*)calloc(PATH_MAX_LENGTH, sizeof(char));
|
2019-04-11 04:09:13 +00:00
|
|
|
|
2019-03-05 15:37:50 +00:00
|
|
|
if (!b_fallback_label)
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
fill_short_pathname_representation(b_fallback_label, b->path, PATH_MAX_LENGTH * sizeof(char));
|
|
|
|
|
|
|
|
if (string_is_empty(b_fallback_label))
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
b_str = b_fallback_label;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = strcasecmp(a_str, b_str);
|
|
|
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
a_str = NULL;
|
|
|
|
b_str = NULL;
|
|
|
|
|
|
|
|
if (a_fallback_label)
|
|
|
|
{
|
|
|
|
free(a_fallback_label);
|
|
|
|
a_fallback_label = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (b_fallback_label)
|
|
|
|
{
|
|
|
|
free(b_fallback_label);
|
|
|
|
b_fallback_label = NULL;
|
|
|
|
}
|
2016-08-28 16:47:34 +00:00
|
|
|
|
2019-03-05 15:37:50 +00:00
|
|
|
return ret;
|
2016-08-28 16:47:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void playlist_qsort(playlist_t *playlist)
|
2015-06-11 13:04:35 +00:00
|
|
|
{
|
2016-03-21 18:52:33 +00:00
|
|
|
qsort(playlist->entries, playlist->size,
|
2016-08-28 16:47:34 +00:00
|
|
|
sizeof(struct playlist_entry),
|
|
|
|
(int (*)(const void *, const void *))playlist_qsort_func);
|
2015-06-11 13:04:35 +00:00
|
|
|
}
|
2019-01-20 00:57:24 +00:00
|
|
|
|
|
|
|
void command_playlist_push_write(
|
|
|
|
playlist_t *playlist,
|
2019-04-12 16:50:27 +00:00
|
|
|
const struct playlist_entry *entry)
|
2019-01-20 00:57:24 +00:00
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (playlist_push(
|
|
|
|
playlist,
|
2019-04-12 16:50:27 +00:00
|
|
|
entry
|
2019-01-20 00:57:24 +00:00
|
|
|
))
|
|
|
|
playlist_write_file(playlist);
|
|
|
|
}
|
|
|
|
|
|
|
|
void command_playlist_update_write(
|
|
|
|
playlist_t *plist,
|
|
|
|
size_t idx,
|
2019-04-12 16:50:27 +00:00
|
|
|
const struct playlist_entry *entry)
|
2019-01-20 00:57:24 +00:00
|
|
|
{
|
|
|
|
playlist_t *playlist = plist ? plist : playlist_get_cached();
|
|
|
|
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
playlist_update(
|
|
|
|
playlist,
|
|
|
|
idx,
|
2019-04-12 16:50:27 +00:00
|
|
|
entry);
|
2019-01-20 00:57:24 +00:00
|
|
|
|
|
|
|
playlist_write_file(playlist);
|
|
|
|
}
|
2019-03-09 13:48:06 +00:00
|
|
|
|
|
|
|
bool playlist_index_is_valid(playlist_t *playlist, size_t idx,
|
|
|
|
const char *path, const char *core_path)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (idx >= playlist->size)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return string_is_equal(playlist->entries[idx].path, path) &&
|
|
|
|
string_is_equal(path_basename(playlist->entries[idx].core_path), path_basename(core_path));
|
|
|
|
}
|
|
|
|
|
|
|
|
void playlist_get_crc32(playlist_t *playlist, size_t idx,
|
|
|
|
const char **crc32)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (crc32)
|
|
|
|
*crc32 = playlist->entries[idx].crc32;
|
|
|
|
}
|
|
|
|
|
|
|
|
void playlist_get_db_name(playlist_t *playlist, size_t idx,
|
|
|
|
const char **db_name)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (db_name)
|
|
|
|
{
|
|
|
|
if (!string_is_empty(playlist->entries[idx].db_name))
|
|
|
|
*db_name = playlist->entries[idx].db_name;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *conf_path_basename = path_basename(playlist->conf_path);
|
|
|
|
|
|
|
|
/* Only use file basename if this is a 'collection' playlist
|
|
|
|
* (i.e. ignore history/favourites) */
|
2019-04-13 16:57:02 +00:00
|
|
|
if (!string_is_empty(conf_path_basename) &&
|
|
|
|
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_FAVORITES)) &&
|
|
|
|
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_HISTORY)) &&
|
2019-03-09 13:48:06 +00:00
|
|
|
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_IMAGE_HISTORY)) &&
|
|
|
|
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_MUSIC_HISTORY)) &&
|
|
|
|
!string_is_equal(conf_path_basename, file_path_str(FILE_PATH_CONTENT_VIDEO_HISTORY)))
|
|
|
|
*db_name = conf_path_basename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 16:40:00 +00:00
|
|
|
|
|
|
|
char *playlist_get_default_core_path(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return NULL;
|
|
|
|
return playlist->default_core_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *playlist_get_default_core_name(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return NULL;
|
|
|
|
return playlist->default_core_name;
|
|
|
|
}
|
|
|
|
|
2019-08-15 17:04:24 +00:00
|
|
|
enum playlist_label_display_mode playlist_get_label_display_mode(playlist_t *playlist)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return LABEL_DISPLAY_MODE_DEFAULT;
|
|
|
|
return playlist->label_display_mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum playlist_thumbnail_mode playlist_get_thumbnail_mode(
|
|
|
|
playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return PLAYLIST_THUMBNAIL_MODE_DEFAULT;
|
|
|
|
|
|
|
|
if (thumbnail_id == PLAYLIST_THUMBNAIL_RIGHT)
|
|
|
|
return playlist->right_thumbnail_mode;
|
|
|
|
else if (thumbnail_id == PLAYLIST_THUMBNAIL_LEFT)
|
|
|
|
return playlist->left_thumbnail_mode;
|
|
|
|
|
|
|
|
/* Fallback */
|
|
|
|
return PLAYLIST_THUMBNAIL_MODE_DEFAULT;
|
|
|
|
}
|
|
|
|
|
2019-06-26 16:40:00 +00:00
|
|
|
void playlist_set_default_core_path(playlist_t *playlist, const char *core_path)
|
|
|
|
{
|
|
|
|
char real_core_path[PATH_MAX_LENGTH];
|
|
|
|
|
|
|
|
real_core_path[0] = '\0';
|
|
|
|
|
|
|
|
if (!playlist || string_is_empty(core_path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get 'real' core path */
|
|
|
|
strlcpy(real_core_path, core_path, sizeof(real_core_path));
|
|
|
|
if (!string_is_equal(real_core_path, file_path_str(FILE_PATH_DETECT)))
|
2019-07-18 19:15:13 +00:00
|
|
|
playlist_resolve_path(PLAYLIST_SAVE, real_core_path, sizeof(real_core_path));
|
2019-06-26 16:40:00 +00:00
|
|
|
|
|
|
|
if (string_is_empty(real_core_path))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!string_is_equal(playlist->default_core_path, real_core_path))
|
|
|
|
{
|
|
|
|
if (playlist->default_core_path)
|
|
|
|
free(playlist->default_core_path);
|
|
|
|
playlist->default_core_path = strdup(real_core_path);
|
|
|
|
playlist->modified = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void playlist_set_default_core_name(playlist_t *playlist, const char *core_name)
|
|
|
|
{
|
|
|
|
if (!playlist || string_is_empty(core_name))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!string_is_equal(playlist->default_core_name, core_name))
|
|
|
|
{
|
|
|
|
if (playlist->default_core_name)
|
|
|
|
free(playlist->default_core_name);
|
|
|
|
playlist->default_core_name = strdup(core_name);
|
|
|
|
playlist->modified = true;
|
|
|
|
}
|
|
|
|
}
|
2019-07-18 17:11:30 +00:00
|
|
|
|
|
|
|
void playlist_set_label_display_mode(playlist_t *playlist, enum playlist_label_display_mode label_display_mode)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (playlist->label_display_mode != label_display_mode) {
|
|
|
|
playlist->label_display_mode = label_display_mode;
|
|
|
|
playlist->modified = true;
|
|
|
|
}
|
|
|
|
}
|
2019-08-15 17:04:24 +00:00
|
|
|
|
|
|
|
void playlist_set_thumbnail_mode(
|
|
|
|
playlist_t *playlist, enum playlist_thumbnail_id thumbnail_id, enum playlist_thumbnail_mode thumbnail_mode)
|
|
|
|
{
|
|
|
|
if (!playlist)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (thumbnail_id == PLAYLIST_THUMBNAIL_RIGHT)
|
|
|
|
{
|
|
|
|
playlist->right_thumbnail_mode = thumbnail_mode;
|
|
|
|
playlist->modified = true;
|
|
|
|
}
|
|
|
|
else if (thumbnail_id == PLAYLIST_THUMBNAIL_LEFT)
|
|
|
|
{
|
|
|
|
playlist->left_thumbnail_mode = thumbnail_mode;
|
|
|
|
playlist->modified = true;
|
|
|
|
}
|
|
|
|
}
|