RetroArch/core_info.c

2454 lines
72 KiB
C
Raw Normal View History

/* 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-02-22 21:31:54 +00:00
* Copyright (C) 2016-2019 - Brad Parker
2016-10-10 08:49:09 +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/>.
*/
2016-09-08 04:07:43 +00:00
#include <compat/strl.h>
#include <string/stdstring.h>
#include <file/config_file.h>
2014-10-21 22:23:06 +00:00
#include <file/file_path.h>
#include <streams/file_stream.h>
#include <lists/dir_list.h>
#include <file/archive_file.h>
2015-09-04 19:11:00 +00:00
2016-09-08 04:07:43 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
2016-01-20 03:07:24 +00:00
#include "retroarch.h"
2016-11-28 01:24:23 +00:00
#include "core_info.h"
2018-04-09 20:20:51 +00:00
#include "file_path_special.h"
#if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
#include "uwp/uwp_func.h"
#endif
#if defined(ANDROID)
#include "play_feature_delivery/play_feature_delivery.h"
#endif
2021-05-04 14:01:17 +00:00
#define CORE_INFO_CACHE_FILE_NAME ".cache"
typedef struct
{
char **current_string_val;
struct string_list **current_string_list_val;
uint32_t *current_entry_uint_val;
bool *current_entry_bool_val;
bool to_core_file_id;
bool to_firmware;
core_info_t *core_info;
core_info_cache_list_t *core_info_cache_list;
unsigned array_depth;
unsigned object_depth;
} CCJSONContext;
enum compare_op
{
2020-02-16 19:27:22 +00:00
COMPARE_OP_EQUAL = 0,
COMPARE_OP_NOT_EQUAL,
COMPARE_OP_LESS,
COMPARE_OP_LESS_EQUAL,
COMPARE_OP_GREATER,
COMPARE_OP_GREATER_EQUAL
};
static uint32_t core_info_hash_string(const char *str)
{
unsigned char c;
uint32_t hash = (uint32_t)0x811c9dc5;
while ((c = (unsigned char)*(str++)) != '\0')
hash = ((hash * (uint32_t)0x01000193) ^ (uint32_t)c);
return (hash ? hash : 1);
}
static bool core_info_get_file_id(const char *core_filename,
char *core_file_id, size_t len)
{
char *last_underscore = NULL;
if (string_is_empty(core_filename))
return false;
/* Core file 'id' is filename without extension
* or platform-specific suffix */
/* > Remove extension */
strlcpy(core_file_id, core_filename, len);
path_remove_extension(core_file_id);
/* > Remove suffix */
last_underscore = (char*)strrchr(core_file_id, '_');
if (!string_is_empty(last_underscore) &&
!string_is_equal(last_underscore, "_libretro"))
*last_underscore = '\0';
return !string_is_empty(core_file_id);
}
static core_info_t *core_info_find_internal(
core_info_list_t *list,
const char *core_path)
{
char core_file_id[256];
uint32_t hash;
size_t i;
core_file_id[0] = '\0';
if (!list ||
string_is_empty(core_path) ||
!core_info_get_file_id(path_basename_nocompression(core_path),
core_file_id, sizeof(core_file_id)))
return NULL;
hash = core_info_hash_string(core_file_id);
for (i = 0; i < list->count; i++)
{
core_info_t *info = &list->list[i];
if ((info->core_file_id.hash == hash) &&
string_is_equal(info->core_file_id.str, core_file_id))
return info;
}
return NULL;
}
static void core_info_resolve_firmware(
core_info_t *info, config_file_t *conf)
{
unsigned i;
unsigned firmware_count = 0;
core_info_firmware_t *firmware = NULL;
if (!config_get_uint(conf, "firmware_count", &firmware_count))
return;
firmware = (core_info_firmware_t*)calloc(firmware_count, sizeof(*firmware));
if (!firmware)
return;
for (i = 0; i < firmware_count; i++)
{
char path_key[64];
char desc_key[64];
char opt_key[64];
struct config_entry_list *entry = NULL;
bool tmp_bool = false;
path_key[0] = '\0';
desc_key[0] = '\0';
opt_key[0] = '\0';
snprintf(path_key, sizeof(path_key), "firmware%u_path", i);
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", i);
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", i);
entry = config_get_entry(conf, path_key);
if (entry && !string_is_empty(entry->value))
{
firmware[i].path = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, desc_key);
if (entry && !string_is_empty(entry->value))
{
firmware[i].desc = entry->value;
entry->value = NULL;
}
if (config_get_bool(conf, opt_key , &tmp_bool))
firmware[i].optional = tmp_bool;
}
info->firmware_count = firmware_count;
info->firmware = firmware;
}
static config_file_t *core_info_get_config_file(
const char *core_file_id,
const char *info_dir)
{
char info_path[PATH_MAX_LENGTH];
info_path[0] = '\0';
if (string_is_empty(info_dir))
strlcpy(info_path, core_file_id, sizeof(info_path));
else
fill_pathname_join(info_path, info_dir, core_file_id,
sizeof(info_path));
strlcat(info_path, ".info", sizeof(info_path));
return config_file_new_from_path_to_string(info_path);
}
static void core_info_parse_config_file(
core_info_list_t *list, core_info_t *info,
config_file_t *conf)
{
struct config_entry_list *entry = NULL;
bool tmp_bool = false;
entry = config_get_entry(conf, "display_name");
if (entry && !string_is_empty(entry->value))
{
info->display_name = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, "display_version");
if (entry && !string_is_empty(entry->value))
{
info->display_version = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, "corename");
if (entry && !string_is_empty(entry->value))
{
info->core_name = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, "systemname");
if (entry && !string_is_empty(entry->value))
{
info->systemname = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, "systemid");
if (entry && !string_is_empty(entry->value))
{
info->system_id = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, "manufacturer");
if (entry && !string_is_empty(entry->value))
{
info->system_manufacturer = entry->value;
entry->value = NULL;
}
entry = config_get_entry(conf, "supported_extensions");
if (entry && !string_is_empty(entry->value))
{
info->supported_extensions = entry->value;
entry->value = NULL;
info->supported_extensions_list =
string_split(info->supported_extensions, "|");
}
entry = config_get_entry(conf, "authors");
if (entry && !string_is_empty(entry->value))
{
info->authors = entry->value;
entry->value = NULL;
info->authors_list =
string_split(info->authors, "|");
}
entry = config_get_entry(conf, "permissions");
if (entry && !string_is_empty(entry->value))
{
info->permissions = entry->value;
entry->value = NULL;
info->permissions_list =
string_split(info->permissions, "|");
}
entry = config_get_entry(conf, "license");
if (entry && !string_is_empty(entry->value))
{
info->licenses = entry->value;
entry->value = NULL;
info->licenses_list =
string_split(info->licenses, "|");
}
entry = config_get_entry(conf, "categories");
if (entry && !string_is_empty(entry->value))
{
info->categories = entry->value;
entry->value = NULL;
info->categories_list =
string_split(info->categories, "|");
}
entry = config_get_entry(conf, "database");
if (entry && !string_is_empty(entry->value))
{
info->databases = entry->value;
entry->value = NULL;
info->databases_list =
string_split(info->databases, "|");
}
entry = config_get_entry(conf, "notes");
if (entry && !string_is_empty(entry->value))
{
info->notes = entry->value;
entry->value = NULL;
info->note_list =
string_split(info->notes, "|");
}
entry = config_get_entry(conf, "required_hw_api");
if (entry && !string_is_empty(entry->value))
{
info->required_hw_api = entry->value;
entry->value = NULL;
info->required_hw_api_list =
string_split(info->required_hw_api, "|");
}
entry = config_get_entry(conf, "description");
if (entry && !string_is_empty(entry->value))
{
info->description = entry->value;
entry->value = NULL;
}
if (config_get_bool(conf, "supports_no_game",
&tmp_bool))
info->supports_no_game = tmp_bool;
if (config_get_bool(conf, "database_match_archive_member",
&tmp_bool))
info->database_match_archive_member = tmp_bool;
if (config_get_bool(conf, "is_experimental",
&tmp_bool))
info->is_experimental = tmp_bool;
core_info_resolve_firmware(info, conf);
info->has_info = true;
list->info_count++;
}
2014-09-02 03:10:54 +00:00
static void core_info_list_resolve_all_extensions(
core_info_list_t *core_info_list)
{
size_t i = 0;
size_t all_ext_len = 0;
char *all_ext = NULL;
2015-01-09 14:33:58 +00:00
for (i = 0; i < core_info_list->count; i++)
{
if (core_info_list->list[i].supported_extensions)
all_ext_len +=
(strlen(core_info_list->list[i].supported_extensions) + 2);
}
all_ext_len += STRLEN_CONST("7z|") + STRLEN_CONST("zip|");
all_ext = (char*)calloc(1, all_ext_len);
if (!all_ext)
return;
core_info_list->all_ext = all_ext;
for (i = 0; i < core_info_list->count; i++)
{
if (!core_info_list->list[i].supported_extensions)
continue;
2015-01-12 03:19:57 +00:00
strlcat(core_info_list->all_ext,
core_info_list->list[i].supported_extensions, all_ext_len);
strlcat(core_info_list->all_ext, "|", all_ext_len);
}
#ifdef HAVE_7ZIP
strlcat(core_info_list->all_ext, "7z|", all_ext_len);
#endif
#ifdef HAVE_ZLIB
strlcat(core_info_list->all_ext, "zip|", all_ext_len);
#endif
}
2021-05-04 14:01:17 +00:00
static void core_info_free(core_info_t* info)
{
size_t i;
free(info->path);
free(info->core_name);
free(info->systemname);
free(info->system_id);
free(info->system_manufacturer);
free(info->display_name);
free(info->display_version);
free(info->supported_extensions);
free(info->authors);
free(info->permissions);
free(info->licenses);
free(info->categories);
free(info->databases);
free(info->notes);
free(info->required_hw_api);
free(info->description);
string_list_free(info->supported_extensions_list);
string_list_free(info->authors_list);
string_list_free(info->note_list);
string_list_free(info->permissions_list);
string_list_free(info->licenses_list);
string_list_free(info->categories_list);
string_list_free(info->databases_list);
string_list_free(info->required_hw_api_list);
for (i = 0; i < info->firmware_count; i++)
{
free(info->firmware[i].path);
free(info->firmware[i].desc);
}
free(info->firmware);
free(info->core_file_id.str);
}
2016-02-07 11:51:45 +00:00
static void core_info_list_free(core_info_list_t *core_info_list)
{
2021-05-04 14:01:17 +00:00
size_t i;
2016-02-07 11:51:45 +00:00
if (!core_info_list)
return;
for (i = 0; i < core_info_list->count; i++)
{
core_info_t *info = (core_info_t*)&core_info_list->list[i];
2021-05-04 14:01:17 +00:00
core_info_free(info);
2016-02-07 11:51:45 +00:00
}
free(core_info_list->all_ext);
2016-02-07 11:51:45 +00:00
free(core_info_list->list);
free(core_info_list);
}
2021-05-04 14:01:17 +00:00
static void core_info_cache_list_free(core_info_cache_list_t *core_info_cache_list)
{
size_t i;
if (!core_info_cache_list)
return;
for (i = 0; i < core_info_cache_list->length; i++)
{
core_info_t* info = (core_info_t*)&core_info_cache_list->items[i];
core_info_free(info);
}
free(core_info_cache_list->items);
free(core_info_cache_list);
}
static core_info_list_t *core_info_list_new(const char *path,
const char *libretro_info_dir,
const char *exts,
bool dir_show_hidden_files)
{
size_t i;
2021-05-04 14:01:17 +00:00
struct string_list contents = {0};
core_info_t *core_info = NULL;
core_info_list_t *core_info_list = NULL;
core_info_cache_list_t *core_info_cache_list = NULL;
const char *info_dir = libretro_info_dir;
bool ok = false;
string_list_initialize(&contents);
ok = dir_list_append(&contents, path, exts,
false, dir_show_hidden_files, false, false);
#if defined(__WINRT__) || defined(WINAPI_FAMILY) && WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP
{
/* UWP: browse the optional packages for additional cores */
struct string_list core_packages = {0};
if (string_list_initialize(&core_packages))
{
uwp_fill_installed_core_packages(&core_packages);
for (i = 0; i < core_packages.size; i++)
dir_list_append(&contents, core_packages.elems[i].data, exts,
false, dir_show_hidden_files, false, false);
string_list_deinitialize(&core_packages);
}
}
#else
/* Keep the old 'directory not found' behaviour */
if (!ok)
goto error;
#endif
core_info_list = (core_info_list_t*)malloc(sizeof(*core_info_list));
if (!core_info_list)
goto error;
core_info_list->list = NULL;
core_info_list->count = 0;
core_info_list->info_count = 0;
core_info_list->all_ext = NULL;
2020-06-29 18:14:14 +00:00
core_info = (core_info_t*)calloc(contents.size, sizeof(*core_info));
2020-06-29 18:14:14 +00:00
if (!core_info)
2019-04-28 03:15:21 +00:00
{
core_info_list_free(core_info_list);
goto error;
2019-04-28 03:15:21 +00:00
}
core_info_list->list = core_info;
core_info_list->count = contents.size;
2021-05-04 14:01:17 +00:00
#ifdef _3DS
core_info_cache_list = core_info_read_cache_file(libretro_info_dir);
if (!core_info_cache_list)
goto error;
#endif
for (i = 0; i < contents.size; i++)
{
core_info_t *info = &core_info[i];
2021-05-04 14:01:17 +00:00
core_info_t *info_cache = NULL;
const char *base_path = contents.elems[i].data;
const char *core_filename = NULL;
config_file_t *conf = NULL;
char core_file_id[256];
core_file_id[0] = '\0';
if (string_is_empty(base_path) ||
!(core_filename = path_basename_nocompression(base_path)) ||
!core_info_get_file_id(core_filename, core_file_id,
sizeof(core_file_id)))
continue;
2021-05-04 14:01:17 +00:00
info_cache = core_info_get_cache(core_info_cache_list, core_file_id);
if (info_cache)
{
core_info_copy(info_cache, info);
continue;
}
/* Cache core path */
info->path = strdup(base_path);
2020-05-27 16:00:47 +00:00
/* Get core lock status */
info->is_locked = core_info_get_core_lock(info->path, false);
2017-01-13 17:35:20 +00:00
/* Cache core file 'id' */
info->core_file_id.str = strdup(core_file_id);
info->core_file_id.hash = core_info_hash_string(core_file_id);
/* Parse core info file */
conf = core_info_get_config_file(core_file_id, info_dir);
if (conf)
{
core_info_parse_config_file(core_info_list, info, conf);
config_file_free(conf);
}
/* Get fallback display name, if required */
if (!info->display_name)
info->display_name = strdup(core_filename);
2021-05-04 14:01:17 +00:00
info->is_installed = true;
#ifdef _3DS
core_info_add_cache(core_info_cache_list, info);
core_info_cache_list->refresh = true;
#endif
}
#ifdef _3DS
core_info_check_uninstalled(core_info_cache_list);
if (core_info_cache_list->refresh) {
core_info_write_cache_file(core_info_cache_list, libretro_info_dir);
}
2021-05-04 14:01:17 +00:00
core_info_cache_list_free(core_info_cache_list);
#endif
2020-09-05 17:37:18 +00:00
core_info_list_resolve_all_extensions(core_info_list);
2013-10-05 15:07:56 +00:00
string_list_deinitialize(&contents);
return core_info_list;
error:
string_list_deinitialize(&contents);
return NULL;
}
/* Shallow-copies internal state.
*
* Data in *info is invalidated when the
* core_info_list is freed. */
bool core_info_list_get_info(core_info_list_t *core_info_list,
core_info_t *out_info, const char *core_path)
{
core_info_t *info = core_info_find_internal(
core_info_list, core_path);
if (!out_info)
return false;
memset(out_info, 0, sizeof(*out_info));
if (info)
{
*out_info = *info;
return true;
}
return false;
}
2019-08-10 02:34:15 +00:00
#ifdef HAVE_COMPRESSION
static bool core_info_does_support_any_file(const core_info_t *core,
2014-09-02 03:10:54 +00:00
const struct string_list *list)
{
size_t i;
if (!list || !core || !core->supported_extensions_list)
return false;
for (i = 0; i < list->size; i++)
2014-09-02 03:10:54 +00:00
if (string_list_find_elem_prefix(core->supported_extensions_list,
".", path_get_extension(list->elems[i].data)))
return true;
return false;
}
2019-08-10 02:34:15 +00:00
#endif
static bool core_info_does_support_file(
const core_info_t *core, const char *path)
2013-06-26 00:57:19 +00:00
{
2016-12-14 12:47:22 +00:00
if (!core || !core->supported_extensions_list)
2013-06-26 00:57:19 +00:00
return false;
2016-12-14 12:47:22 +00:00
if (string_is_empty(path))
return false;
2014-09-02 03:10:54 +00:00
return string_list_find_elem_prefix(
core->supported_extensions_list, ".", path_get_extension(path));
2013-06-26 00:57:19 +00:00
}
/* qsort_r() is not in standard C, sadly. */
static int core_info_qsort_cmp(const void *a_, const void *b_)
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
const core_info_t *a = (const core_info_t*)a_;
const core_info_t *b = (const core_info_t*)b_;
int support_a = core_info_does_support_file(a,
p_coreinfo->tmp_path);
int support_b = core_info_does_support_file(b,
p_coreinfo->tmp_path);
2019-08-10 02:34:15 +00:00
#ifdef HAVE_COMPRESSION
support_a = support_a ||
core_info_does_support_any_file(a, p_coreinfo->tmp_list);
2019-08-10 02:34:15 +00:00
support_b = support_b ||
core_info_does_support_any_file(b, p_coreinfo->tmp_list);
2019-08-10 02:34:15 +00:00
#endif
if (support_a != support_b)
return support_b - support_a;
return strcasecmp(a->display_name, b->display_name);
2013-10-05 15:07:56 +00:00
}
2016-05-09 16:11:17 +00:00
static bool core_info_list_update_missing_firmware_internal(
core_info_list_t *core_info_list,
const char *core_path,
const char *systemdir,
bool *set_missing_bios)
2014-03-03 06:02:29 +00:00
{
size_t i;
char path[PATH_MAX_LENGTH];
2017-09-09 19:55:35 +00:00
core_info_t *info = NULL;
2014-08-02 12:01:35 +00:00
if (!core_info_list)
return false;
2014-03-03 06:02:29 +00:00
info = core_info_find_internal(core_info_list, core_path);
2016-02-07 18:02:09 +00:00
if (!info)
return false;
2016-12-14 10:47:04 +00:00
path[0] = '\0';
2014-03-03 06:02:29 +00:00
for (i = 0; i < info->firmware_count; i++)
{
2016-12-14 10:47:04 +00:00
if (string_is_empty(info->firmware[i].path))
2015-01-11 06:37:02 +00:00
continue;
fill_pathname_join(path, systemdir,
info->firmware[i].path, sizeof(path));
info->firmware[i].missing = !path_is_valid(path);
if (info->firmware[i].missing && !info->firmware[i].optional)
*set_missing_bios = true;
2014-03-03 06:02:29 +00:00
}
return true;
2014-03-03 06:02:29 +00:00
}
void core_info_free_current_core(core_info_state_t *p_coreinfo)
2016-05-09 16:11:17 +00:00
{
if (p_coreinfo->current)
free(p_coreinfo->current);
p_coreinfo->current = NULL;
2016-05-09 16:11:17 +00:00
}
bool core_info_init_current_core(void)
2016-02-07 01:18:26 +00:00
{
2020-06-29 01:46:27 +00:00
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
core_info_t *current = (core_info_t*)
malloc(sizeof(*current));
if (!current)
2016-05-09 16:11:17 +00:00
return false;
current->has_info = false;
2020-06-29 01:46:27 +00:00
current->supports_no_game = false;
current->database_match_archive_member = false;
current->is_experimental = false;
current->is_locked = false;
current->firmware_count = 0;
current->path = NULL;
current->display_name = NULL;
current->display_version = NULL;
current->core_name = NULL;
current->system_manufacturer = NULL;
current->systemname = NULL;
current->system_id = NULL;
current->supported_extensions = NULL;
current->authors = NULL;
current->permissions = NULL;
current->licenses = NULL;
current->categories = NULL;
current->databases = NULL;
current->notes = NULL;
current->required_hw_api = NULL;
current->description = NULL;
current->categories_list = NULL;
current->databases_list = NULL;
current->note_list = NULL;
current->supported_extensions_list = NULL;
current->authors_list = NULL;
current->permissions_list = NULL;
current->licenses_list = NULL;
current->required_hw_api_list = NULL;
current->firmware = NULL;
current->core_file_id.str = NULL;
current->core_file_id.hash = 0;
2020-06-29 01:46:27 +00:00
p_coreinfo->current = current;
2016-05-09 16:11:17 +00:00
return true;
}
2016-02-07 01:24:08 +00:00
2016-05-09 16:11:17 +00:00
bool core_info_get_current_core(core_info_t **core)
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
2016-05-09 16:11:17 +00:00
if (!core)
return false;
*core = p_coreinfo->current;
2016-05-09 16:11:17 +00:00
return true;
}
void core_info_deinit_list(void)
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
if (p_coreinfo->curr_list)
core_info_list_free(p_coreinfo->curr_list);
p_coreinfo->curr_list = NULL;
2016-05-09 16:11:17 +00:00
}
bool core_info_init_list(const char *path_info, const char *dir_cores,
const char *exts, bool dir_show_hidden_files)
2016-05-09 16:11:17 +00:00
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
if (!(p_coreinfo->curr_list = core_info_list_new(dir_cores,
!string_is_empty(path_info) ? path_info : dir_cores,
exts,
dir_show_hidden_files)))
2016-05-09 16:11:17 +00:00
return false;
return true;
}
bool core_info_get_list(core_info_list_t **core)
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
2016-05-09 16:11:17 +00:00
if (!core)
return false;
*core = p_coreinfo->curr_list;
2016-05-09 16:11:17 +00:00
return true;
}
/* Returns number of installed cores */
size_t core_info_count(void)
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
if (!p_coreinfo || !p_coreinfo->curr_list)
return 0;
return p_coreinfo->curr_list->count;
}
bool core_info_list_update_missing_firmware(core_info_ctx_firmware_t *info,
bool *set_missing_bios)
2016-05-09 16:11:17 +00:00
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
2016-05-09 16:11:17 +00:00
if (!info)
return false;
return core_info_list_update_missing_firmware_internal(
p_coreinfo->curr_list,
info->path, info->directory.system,
set_missing_bios);
2016-05-09 16:11:17 +00:00
}
bool core_info_load(const char *core_path,
core_info_state_t *p_coreinfo)
2016-05-09 16:11:17 +00:00
{
core_info_t *core_info = NULL;
2016-05-09 16:11:17 +00:00
if (!p_coreinfo->current)
core_info_init_current_core();
2016-05-09 16:11:17 +00:00
core_info_get_current_core(&core_info);
if (!p_coreinfo->curr_list)
2016-05-09 16:11:17 +00:00
return false;
if (!core_info_list_get_info(p_coreinfo->curr_list,
core_info, core_path))
2016-05-09 16:11:17 +00:00
return false;
return true;
}
bool core_info_find(const char *core_path,
core_info_t **core_info)
2016-05-09 16:11:17 +00:00
{
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
core_info_t *info = NULL;
if (!core_info || !p_coreinfo->curr_list)
2016-05-09 16:11:17 +00:00
return false;
info = core_info_find_internal(p_coreinfo->curr_list, core_path);
if (!info)
2016-05-09 16:11:17 +00:00
return false;
*core_info = info;
2016-05-09 16:11:17 +00:00
return true;
}
core_info_t *core_info_get(core_info_list_t *list, size_t i)
{
core_info_t *info = NULL;
if (!list || (i >= list->count))
2016-05-09 16:11:17 +00:00
return NULL;
info = (core_info_t*)&list->list[i];
if (!info || !info->path)
return NULL;
return info;
}
void core_info_list_get_supported_cores(core_info_list_t *core_info_list,
const char *path, const core_info_t **infos, size_t *num_infos)
{
2016-09-19 01:54:57 +00:00
size_t i;
size_t supported = 0;
2019-08-10 02:34:15 +00:00
#ifdef HAVE_COMPRESSION
struct string_list *list = NULL;
2019-08-10 02:34:15 +00:00
#endif
core_info_state_t *p_coreinfo = coreinfo_get_ptr();
2016-05-09 16:11:17 +00:00
if (!core_info_list)
return;
p_coreinfo->tmp_path = path;
2016-05-09 16:11:17 +00:00
#ifdef HAVE_COMPRESSION
if (path_is_compressed_file(path))
2016-05-09 16:11:17 +00:00
list = file_archive_get_file_list(path, NULL);
p_coreinfo->tmp_list = list;
2016-05-09 16:11:17 +00:00
#endif
2016-10-10 08:49:09 +00:00
/* Let supported core come first in list so we can return
2016-05-09 16:11:17 +00:00
* a pointer to them. */
qsort(core_info_list->list, core_info_list->count,
sizeof(core_info_t), core_info_qsort_cmp);
for (i = 0; i < core_info_list->count; i++, supported++)
{
const core_info_t *core = &core_info_list->list[i];
if (core_info_does_support_file(core, path))
continue;
#ifdef HAVE_COMPRESSION
2016-05-09 16:11:17 +00:00
if (core_info_does_support_any_file(core, list))
continue;
#endif
break;
}
2019-08-10 02:34:15 +00:00
#ifdef HAVE_COMPRESSION
2016-05-09 16:11:17 +00:00
if (list)
string_list_free(list);
2019-08-10 02:34:15 +00:00
#endif
2016-05-09 16:11:17 +00:00
*infos = core_info_list->list;
*num_infos = supported;
}
/*
* Matches core A and B file IDs
*
* e.g.:
* snes9x_libretro.dll and snes9x_libretro_android.so are matched
2021-04-20 17:46:11 +00:00
* snes9x__2005_libretro.dll and snes9x_libretro_android.so are
* NOT matched
*/
bool core_info_core_file_id_is_equal(const char *core_path_a,
const char *core_path_b)
{
char core_file_id_a[256];
char core_file_id_b[256];
core_file_id_a[0] = '\0';
core_file_id_b[0] = '\0';
if (string_is_empty(core_path_a) ||
string_is_empty(core_path_b) ||
!core_info_get_file_id(path_basename_nocompression(core_path_a),
core_file_id_a, sizeof(core_file_id_a)) ||
!core_info_get_file_id(path_basename_nocompression(core_path_b),
core_file_id_b, sizeof(core_file_id_b)))
return false;
return string_is_equal(core_file_id_a, core_file_id_b);
2016-05-09 16:11:17 +00:00
}
bool core_info_database_match_archive_member(const char *database_path)
{
char *database = NULL;
2021-04-20 17:46:11 +00:00
const char *new_path = path_basename_nocompression(database_path);
core_info_state_t *p_coreinfo = NULL;
if (string_is_empty(new_path))
return false;
2021-04-20 17:46:11 +00:00
if (!(database = strdup(new_path)))
return false;
path_remove_extension(database);
2021-04-20 17:46:11 +00:00
p_coreinfo = coreinfo_get_ptr();
if (p_coreinfo->curr_list)
{
size_t i;
for (i = 0; i < p_coreinfo->curr_list->count; i++)
{
const core_info_t *info = &p_coreinfo->curr_list->list[i];
if (!info->database_match_archive_member)
continue;
if (!string_list_find_elem(info->databases_list, database))
continue;
free(database);
return true;
}
}
2021-04-20 17:46:11 +00:00
free(database);
return false;
}
2019-08-10 02:34:15 +00:00
bool core_info_database_supports_content_path(
const char *database_path, const char *path)
{
char *database = NULL;
const char *new_path = path_basename(database_path);
2021-04-20 17:46:11 +00:00
core_info_state_t *p_coreinfo = NULL;
if (string_is_empty(new_path))
return false;
2021-04-20 17:46:11 +00:00
if (!(database = strdup(new_path)))
return false;
path_remove_extension(database);
2021-04-20 17:46:11 +00:00
p_coreinfo = coreinfo_get_ptr();
if (p_coreinfo->curr_list)
{
size_t i;
2017-02-28 10:16:05 +00:00
for (i = 0; i < p_coreinfo->curr_list->count; i++)
{
const core_info_t *info = &p_coreinfo->curr_list->list[i];
if (!string_list_find_elem(info->supported_extensions_list,
path_get_extension(path)))
2016-12-14 00:16:10 +00:00
continue;
if (!string_list_find_elem(info->databases_list, database))
continue;
2016-12-14 00:16:10 +00:00
free(database);
return true;
}
}
2021-04-20 17:46:11 +00:00
free(database);
return false;
}
2016-05-09 16:11:17 +00:00
bool core_info_list_get_display_name(core_info_list_t *core_info_list,
const char *core_path, char *s, size_t len)
2016-05-09 16:11:17 +00:00
{
core_info_t *info = core_info_find_internal(
core_info_list, core_path);
2016-05-09 16:11:17 +00:00
if (s &&
info &&
!string_is_empty(info->display_name))
2016-02-07 01:18:26 +00:00
{
strlcpy(s, info->display_name, len);
return true;
2016-02-07 01:18:26 +00:00
}
2016-05-09 16:11:17 +00:00
return false;
}
2020-05-27 16:00:47 +00:00
/* Returns core_info parameters required for
* core updater tasks, read from specified file.
* Returned core_updater_info_t object must be
* freed using core_info_free_core_updater_info().
* Returns NULL if 'path' is invalid. */
core_updater_info_t *core_info_get_core_updater_info(const char *info_path)
2020-05-27 16:00:47 +00:00
{
struct config_entry_list
*entry = NULL;
2020-05-27 16:00:47 +00:00
bool tmp_bool = false;
core_updater_info_t *info = NULL;
config_file_t *conf = NULL;
if (string_is_empty(info_path))
2020-05-27 16:00:47 +00:00
return NULL;
/* Read config file */
conf = config_file_new_from_path_to_string(info_path);
2020-05-27 16:00:47 +00:00
if (!conf)
return NULL;
/* Create info struct */
info = (core_updater_info_t*)malloc(sizeof(*info));
2020-05-27 16:00:47 +00:00
if (!info)
return NULL;
info->is_experimental = false;
info->display_name = NULL;
info->description = NULL;
info->licenses = NULL;
2020-05-27 16:00:47 +00:00
/* Fetch required parameters */
/* > is_experimental */
if (config_get_bool(conf, "is_experimental", &tmp_bool))
info->is_experimental = tmp_bool;
2020-05-27 16:00:47 +00:00
/* > display_name */
2020-08-26 00:17:37 +00:00
entry = config_get_entry(conf, "display_name");
2020-05-27 16:00:47 +00:00
if (entry && !string_is_empty(entry->value))
{
info->display_name = entry->value;
entry->value = NULL;
}
2020-05-27 16:00:47 +00:00
/* > description */
2020-08-26 00:17:37 +00:00
entry = config_get_entry(conf, "description");
2020-05-27 16:00:47 +00:00
if (entry && !string_is_empty(entry->value))
{
info->description = entry->value;
entry->value = NULL;
}
2020-05-27 16:00:47 +00:00
/* > licenses */
2020-08-26 00:17:37 +00:00
entry = config_get_entry(conf, "license");
2020-05-27 16:00:47 +00:00
if (entry && !string_is_empty(entry->value))
{
info->licenses = entry->value;
entry->value = NULL;
}
2020-05-27 16:00:47 +00:00
/* Clean up */
config_file_free(conf);
return info;
}
void core_info_free_core_updater_info(core_updater_info_t *info)
{
if (!info)
return;
if (info->display_name)
free(info->display_name);
if (info->description)
free(info->description);
if (info->licenses)
free(info->licenses);
free(info);
info = NULL;
}
static int core_info_qsort_func_path(const core_info_t *a,
const core_info_t *b)
{
if (!a || !b)
return 0;
if (string_is_empty(a->path) || string_is_empty(b->path))
return 0;
return strcasecmp(a->path, b->path);
}
static int core_info_qsort_func_display_name(const core_info_t *a,
const core_info_t *b)
{
if (!a || !b)
return 0;
if (string_is_empty(a->display_name) || string_is_empty(b->display_name))
return 0;
return strcasecmp(a->display_name, b->display_name);
}
static int core_info_qsort_func_core_name(const core_info_t *a,
const core_info_t *b)
{
if (!a || !b)
return 0;
if (string_is_empty(a->core_name) || string_is_empty(b->core_name))
return 0;
return strcasecmp(a->core_name, b->core_name);
}
static int core_info_qsort_func_system_name(const core_info_t *a,
const core_info_t *b)
{
if (!a || !b)
return 0;
if (string_is_empty(a->systemname) || string_is_empty(b->systemname))
return 0;
return strcasecmp(a->systemname, b->systemname);
}
2019-08-10 02:34:15 +00:00
void core_info_qsort(core_info_list_t *core_info_list,
enum core_info_list_qsort_type qsort_type)
{
if (!core_info_list)
return;
if (core_info_list->count < 2)
return;
switch (qsort_type)
{
case CORE_INFO_LIST_SORT_PATH:
2019-08-10 02:34:15 +00:00
qsort(core_info_list->list,
core_info_list->count,
sizeof(core_info_t),
(int (*)(const void *, const void *))
core_info_qsort_func_path);
break;
case CORE_INFO_LIST_SORT_DISPLAY_NAME:
2019-08-10 02:34:15 +00:00
qsort(core_info_list->list,
core_info_list->count,
sizeof(core_info_t),
(int (*)(const void *, const void *))
core_info_qsort_func_display_name);
break;
case CORE_INFO_LIST_SORT_CORE_NAME:
2019-08-10 02:34:15 +00:00
qsort(core_info_list->list,
core_info_list->count,
sizeof(core_info_t),
(int (*)(const void *, const void *))
core_info_qsort_func_core_name);
break;
case CORE_INFO_LIST_SORT_SYSTEM_NAME:
2019-08-10 02:34:15 +00:00
qsort(core_info_list->list,
core_info_list->count,
sizeof(core_info_t),
(int (*)(const void *, const void *))
core_info_qsort_func_system_name);
break;
default:
return;
}
}
static bool core_info_compare_api_version(int sys_major, int sys_minor, int major, int minor, enum compare_op op)
{
switch (op)
{
case COMPARE_OP_EQUAL:
if (sys_major == major && sys_minor == minor)
return true;
break;
case COMPARE_OP_NOT_EQUAL:
if (!(sys_major == major && sys_minor == minor))
return true;
break;
case COMPARE_OP_LESS:
if (sys_major < major || (sys_major == major && sys_minor < minor))
return true;
break;
case COMPARE_OP_LESS_EQUAL:
if (sys_major < major || (sys_major == major && sys_minor <= minor))
return true;
break;
case COMPARE_OP_GREATER:
if (sys_major > major || (sys_major == major && sys_minor > minor))
return true;
break;
case COMPARE_OP_GREATER_EQUAL:
if (sys_major > major || (sys_major == major && sys_minor >= minor))
return true;
break;
default:
break;
}
return false;
}
bool core_info_hw_api_supported(core_info_t *info)
{
2019-07-29 20:30:53 +00:00
#ifdef RARCH_INTERNAL
unsigned i;
enum gfx_ctx_api sys_api;
int sys_api_version_major = 0;
int sys_api_version_minor = 0;
const char *sys_api_version_str = video_driver_get_gpu_api_version_string();
gfx_ctx_flags_t sys_flags = video_driver_get_flags_wrapper();
enum api_parse_state
{
STATE_API_NAME,
STATE_API_COMPARE_OP,
STATE_API_VERSION
};
if (!info || !info->required_hw_api_list || info->required_hw_api_list->size == 0)
return true;
sys_api = video_context_driver_get_api();
for (i = 0; i < info->required_hw_api_list->size; i++)
{
char api_str[32] = {0};
char version[16] = {0};
char major_str[16] = {0};
char minor_str[16] = {0};
const char *cur_api = info->required_hw_api_list->elems[i].data;
int api_pos = 0;
int major_str_pos = 0;
int minor_str_pos = 0;
int major = 0;
int minor = 0;
unsigned cur_api_len = 0;
unsigned j = 0;
bool found_major = false;
bool found_minor = false;
enum compare_op op = COMPARE_OP_GREATER_EQUAL;
enum api_parse_state state = STATE_API_NAME;
if (string_is_empty(cur_api))
continue;
2019-09-14 15:15:30 +00:00
cur_api_len = (int)strlen(cur_api);
for (j = 0; j < cur_api_len; j++)
{
if (cur_api[j] == ' ')
continue;
switch (state)
{
case STATE_API_NAME:
{
if ( ISUPPER((unsigned char)cur_api[j]) ||
ISLOWER((unsigned char)cur_api[j]))
api_str[api_pos++] = cur_api[j];
else
{
j--;
state = STATE_API_COMPARE_OP;
break;
}
break;
}
case STATE_API_COMPARE_OP:
{
if (j < cur_api_len - 1 && !(cur_api[j] >= '0' && cur_api[j] <= '9'))
{
if (cur_api[j] == '=' && cur_api[j + 1] == '=')
{
op = COMPARE_OP_EQUAL;
j++;
}
else if (cur_api[j] == '=')
op = COMPARE_OP_EQUAL;
else if (cur_api[j] == '!' && cur_api[j + 1] == '=')
{
op = COMPARE_OP_NOT_EQUAL;
j++;
}
else if (cur_api[j] == '<' && cur_api[j + 1] == '=')
{
op = COMPARE_OP_LESS_EQUAL;
j++;
}
else if (cur_api[j] == '>' && cur_api[j + 1] == '=')
{
op = COMPARE_OP_GREATER_EQUAL;
j++;
}
else if (cur_api[j] == '<')
op = COMPARE_OP_LESS;
else if (cur_api[j] == '>')
op = COMPARE_OP_GREATER;
}
state = STATE_API_VERSION;
break;
}
case STATE_API_VERSION:
{
if ( !found_minor
&& cur_api[j] >= '0'
&& cur_api[j] <= '9'
&& cur_api[j] != '.')
{
found_major = true;
if (major_str_pos < sizeof(major_str) - 1)
major_str[major_str_pos++] = cur_api[j];
}
else if (
found_major
&& found_minor
&& cur_api[j] >= '0'
&& cur_api[j] <= '9')
{
if (minor_str_pos < sizeof(minor_str) - 1)
minor_str[minor_str_pos++] = cur_api[j];
}
else if (cur_api[j] == '.')
found_minor = true;
break;
}
default:
break;
}
}
sscanf(major_str, "%d", &major);
sscanf(minor_str, "%d", &minor);
snprintf(version, sizeof(version), "%d.%d", major, minor);
#if 0
printf("Major: %d\n", major);
printf("Minor: %d\n", minor);
printf("API: %s\n", api_str);
printf("Version: %s\n", version);
fflush(stdout);
#endif
if ((string_is_equal_noncase(api_str, "opengl") && sys_api == GFX_CTX_OPENGL_API) ||
(string_is_equal_noncase(api_str, "openglcompat") && sys_api == GFX_CTX_OPENGL_API) ||
(string_is_equal_noncase(api_str, "openglcompatibility") && sys_api == GFX_CTX_OPENGL_API))
{
/* system is running a core context while compat is requested */
if (sys_flags.flags & (1 << GFX_CTX_FLAGS_GL_CORE_CONTEXT))
return false;
sscanf(sys_api_version_str, "%d.%d", &sys_api_version_major, &sys_api_version_minor);
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "openglcore") && sys_api == GFX_CTX_OPENGL_API)
{
sscanf(sys_api_version_str, "%d.%d", &sys_api_version_major, &sys_api_version_minor);
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "opengles") && sys_api == GFX_CTX_OPENGL_ES_API)
{
sscanf(sys_api_version_str, "OpenGL ES %d.%d", &sys_api_version_major, &sys_api_version_minor);
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "direct3d8") && sys_api == GFX_CTX_DIRECT3D8_API)
{
sys_api_version_major = 8;
sys_api_version_minor = 0;
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "direct3d9") && sys_api == GFX_CTX_DIRECT3D9_API)
{
sys_api_version_major = 9;
sys_api_version_minor = 0;
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "direct3d10") && sys_api == GFX_CTX_DIRECT3D10_API)
{
sys_api_version_major = 10;
sys_api_version_minor = 0;
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "direct3d11") && sys_api == GFX_CTX_DIRECT3D11_API)
{
sys_api_version_major = 11;
sys_api_version_minor = 0;
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "direct3d12") && sys_api == GFX_CTX_DIRECT3D12_API)
{
sys_api_version_major = 12;
sys_api_version_minor = 0;
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "vulkan") && sys_api == GFX_CTX_VULKAN_API)
{
sscanf(sys_api_version_str, "%d.%d", &sys_api_version_major, &sys_api_version_minor);
2020-07-26 06:22:04 +00:00
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
else if (string_is_equal_noncase(api_str, "metal") && sys_api == GFX_CTX_METAL_API)
{
sscanf(sys_api_version_str, "%d.%d", &sys_api_version_major, &sys_api_version_minor);
if (core_info_compare_api_version(sys_api_version_major, sys_api_version_minor, major, minor, op))
return true;
}
}
return false;
2019-07-29 20:30:53 +00:00
#else
return true;
#endif
}
/* Sets 'locked' status of specified core
* > Returns true if successful
* > Like all functions that access the cached
* core info list this is *not* thread safe */
bool core_info_set_core_lock(const char *core_path, bool lock)
{
core_info_t *core_info = NULL;
bool lock_file_exists = false;
2020-08-26 18:22:56 +00:00
char lock_file_path[PATH_MAX_LENGTH];
2020-08-27 10:10:14 +00:00
lock_file_path[0] = '\0';
#if defined(ANDROID)
/* Play Store builds do not support
* core locking */
if (play_feature_delivery_enabled())
return false;
#endif
if (string_is_empty(core_path))
2020-08-26 18:22:56 +00:00
return false;
/* Search for specified core */
if (!core_info_find(core_path, &core_info))
2020-08-26 18:22:56 +00:00
return false;
if (string_is_empty(core_info->path))
2020-08-26 18:22:56 +00:00
return false;
/* Get lock file path */
strlcpy(lock_file_path, core_info->path,
2020-08-26 18:22:56 +00:00
sizeof(lock_file_path));
strlcat(lock_file_path, FILE_PATH_LOCK_EXTENSION,
sizeof(lock_file_path));
/* Check whether lock file exists */
lock_file_exists = path_is_valid(lock_file_path);
/* Create or delete lock file, as required */
if (lock && !lock_file_exists)
{
2020-08-26 18:22:56 +00:00
RFILE *lock_file = filestream_open(
lock_file_path,
RETRO_VFS_FILE_ACCESS_WRITE,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!lock_file)
2020-08-26 18:22:56 +00:00
return false;
/* We have to write something - just output
* a single character */
if (filestream_putc(lock_file, 0) != 0)
2020-08-26 18:22:56 +00:00
{
filestream_close(lock_file);
return false;
}
filestream_close(lock_file);
}
else if (!lock && lock_file_exists)
if (filestream_delete(lock_file_path) != 0)
2020-08-26 18:22:56 +00:00
return false;
/* File operations were successful - update
* core info entry */
core_info->is_locked = lock;
return true;
}
/* Fetches 'locked' status of specified core
* > If 'validate_path' is 'true', will search
* cached core info list for a corresponding
* 'sanitised' core file path. This is *not*
* thread safe
* > If 'validate_path' is 'false', performs a
* direct filesystem check. This *is* thread
* safe, but validity of specified core path
* must be checked externally */
bool core_info_get_core_lock(const char *core_path, bool validate_path)
{
core_info_t *core_info = NULL;
const char *core_file_path = NULL;
bool is_locked = false;
char lock_file_path[PATH_MAX_LENGTH];
2020-08-27 10:10:14 +00:00
lock_file_path[0] = '\0';
#if defined(ANDROID)
/* Play Store builds do not support
* core locking */
if (play_feature_delivery_enabled())
return false;
#endif
if (string_is_empty(core_path))
2020-08-26 18:22:56 +00:00
return false;
/* Check whether core path is to be validated */
if (validate_path)
{
if (core_info_find(core_path, &core_info))
core_file_path = core_info->path;
}
else
core_file_path = core_path;
/* A core cannot be locked if it does not exist... */
if (string_is_empty(core_file_path) ||
!path_is_valid(core_file_path))
2020-08-26 18:22:56 +00:00
return false;
/* Get lock file path */
2020-08-26 18:22:56 +00:00
strlcpy(lock_file_path, core_file_path,
sizeof(lock_file_path));
strlcat(lock_file_path, FILE_PATH_LOCK_EXTENSION,
sizeof(lock_file_path));
/* Check whether lock file exists */
is_locked = path_is_valid(lock_file_path);
/* If core path has been validated (and a
* core info object is available), ensure
* that core info 'is_locked' field is
* up to date */
if (validate_path && core_info)
core_info->is_locked = is_locked;
return is_locked;
}
2021-05-04 14:01:17 +00:00
core_info_t *core_info_get_cache(core_info_cache_list_t *list, char *core_file_id)
{
size_t i;
core_info_t *info = NULL;
if (!list | !core_file_id)
return NULL;
for (i = 0; i < list->length; i++)
{
core_info_t *temp = (core_info_t*)&list->items[i];
if (!temp)
continue;
if (string_is_equal(temp->core_file_id.str, core_file_id))
{
temp->is_installed = true;
info = temp;
break;
}
}
return info;
}
void core_info_add_cache(core_info_cache_list_t *list, core_info_t *info)
{
if (!info->core_file_id.str)
return;
if (list->length >= list->capacity)
{
size_t prev_capacity = list->capacity;
list->capacity = list->capacity * 2;
list->items = (core_info_t*)realloc(list->items, list->capacity * sizeof(core_info_t));
memset(&list->items[prev_capacity], 0, (list->capacity - prev_capacity) * sizeof(core_info_t));
}
core_info_t *cache = &list->items[list->length];
core_info_copy(info, cache);
list->length++;
}
static bool CCJSONObjectMemberHandler(void *context, const char *pValue, size_t length)
{
CCJSONContext *pCtx = (CCJSONContext *)context;
if ((pCtx->object_depth == 2) && (pCtx->array_depth == 1) && length)
{
pCtx->current_string_val = NULL;
pCtx->current_string_list_val = NULL;
pCtx->current_entry_uint_val = NULL;
pCtx->current_entry_bool_val = NULL;
pCtx->to_core_file_id = false;
pCtx->to_firmware = false;
switch (pValue[0])
{
case 'a':
if (string_is_equal(pValue, "authors"))
{
pCtx->current_string_val = &pCtx->core_info->authors;
pCtx->current_string_list_val = &pCtx->core_info->authors_list;
}
break;
case 'c':
if (string_is_equal(pValue, "categories"))
{
pCtx->current_string_val = &pCtx->core_info->categories;
pCtx->current_string_list_val = &pCtx->core_info->categories_list;
}
else if (string_is_equal(pValue, "core_name"))
pCtx->current_string_val = &pCtx->core_info->core_name;
else if (string_is_equal(pValue, "core_file_id"))
pCtx->to_core_file_id = true;
break;
case 'd':
if (string_is_equal(pValue, "display_name"))
pCtx->current_string_val = &pCtx->core_info->display_name;
else if (string_is_equal(pValue, "display_version"))
pCtx->current_string_val = &pCtx->core_info->display_version;
else if (string_is_equal(pValue, "databases"))
{
pCtx->current_string_val = &pCtx->core_info->databases;
pCtx->current_string_list_val = &pCtx->core_info->databases_list;
}
else if (string_is_equal(pValue, "description"))
pCtx->current_string_val = &pCtx->core_info->description;
else if (string_is_equal(pValue, "database_match_archive_member"))
pCtx->current_entry_bool_val = &pCtx->core_info->database_match_archive_member;
break;
case 'f':
if (string_is_equal(pValue, "firmware"))
pCtx->to_firmware = true;
break;
case 'h':
if (string_is_equal(pValue, "has_info"))
pCtx->current_entry_bool_val = &pCtx->core_info->has_info;
break;
case 'l':
if (string_is_equal(pValue, "licenses"))
{
pCtx->current_string_val = &pCtx->core_info->licenses;
pCtx->current_string_list_val = &pCtx->core_info->licenses_list;
}
else if (string_is_equal(pValue, "is_experimental"))
pCtx->current_entry_bool_val = &pCtx->core_info->is_experimental;
else if (string_is_equal(pValue, "is_locked"))
pCtx->current_entry_bool_val = &pCtx->core_info->is_locked;
break;
case 'n':
if (string_is_equal(pValue, "notes"))
{
pCtx->current_string_val = &pCtx->core_info->notes;
pCtx->current_string_list_val = &pCtx->core_info->note_list;
}
break;
case 'p':
if (string_is_equal(pValue, "path"))
pCtx->current_string_val = &pCtx->core_info->path;
else if (string_is_equal(pValue, "permissions"))
{
pCtx->current_string_val = &pCtx->core_info->permissions;
pCtx->current_string_list_val = &pCtx->core_info->permissions_list;
}
break;
case 'r':
if (string_is_equal(pValue, "required_hw_api"))
{
pCtx->current_string_val = &pCtx->core_info->required_hw_api;
pCtx->current_string_list_val = &pCtx->core_info->required_hw_api_list;
}
break;
case 's':
if (string_is_equal(pValue, "system_manufacturer"))
pCtx->current_string_val = &pCtx->core_info->system_manufacturer;
else if (string_is_equal(pValue, "systemname"))
pCtx->current_string_val = &pCtx->core_info->systemname;
else if (string_is_equal(pValue, "system_id"))
pCtx->current_string_val = &pCtx->core_info->system_id;
else if (string_is_equal(pValue, "supported_extensions"))
{
pCtx->current_string_val = &pCtx->core_info->supported_extensions;
pCtx->current_string_list_val = &pCtx->core_info->supported_extensions_list;
}
else if (string_is_equal(pValue, "supports_no_game"))
pCtx->current_entry_bool_val = &pCtx->core_info->supports_no_game;
break;
}
}
else if ((pCtx->object_depth == 3) && (pCtx->array_depth == 1) && length)
{
if (pCtx->to_core_file_id)
{
if (string_is_equal(pValue, "str"))
pCtx->current_string_val = &pCtx->core_info->core_file_id.str;
else if (string_is_equal(pValue, "hash"))
pCtx->current_entry_uint_val = &pCtx->core_info->core_file_id.hash;
}
}
else if ((pCtx->object_depth == 3) && (pCtx->array_depth == 2) && length)
{
if (pCtx->to_firmware)
{
if (string_is_equal(pValue, "path"))
pCtx->current_string_val = &pCtx->core_info->firmware[pCtx->core_info->firmware_count - 1].path;
else if (string_is_equal(pValue, "desc"))
pCtx->current_string_val = &pCtx->core_info->firmware[pCtx->core_info->firmware_count - 1].desc;
else if (string_is_equal(pValue, "missing"))
pCtx->current_entry_bool_val = &pCtx->core_info->firmware[pCtx->core_info->firmware_count - 1].missing;
else if (string_is_equal(pValue, "optional"))
pCtx->current_entry_bool_val = &pCtx->core_info->firmware[pCtx->core_info->firmware_count - 1].optional;
}
}
return true;
}
static bool CCJSONStringHandler(void *context, const char *pValue, size_t length)
{
CCJSONContext *pCtx = (CCJSONContext*)context;
if (pCtx->current_string_val)
{
*pCtx->current_string_val = strdup(pValue);
if (pCtx->current_string_list_val)
{
*pCtx->current_string_list_val = string_split(*pCtx->current_string_val, "|");
}
}
return true;
}
static bool CCJSONNumberHandler(void *context, const char *pValue, size_t length)
{
CCJSONContext *pCtx = (CCJSONContext*)context;
if (pCtx->current_entry_uint_val)
*pCtx->current_entry_uint_val = (unsigned)strtoul(pValue, NULL, 10);
return true;
}
static bool CCJSONBoolHandler(void *context, bool value)
{
CCJSONContext *pCtx = (CCJSONContext *)context;
if (pCtx->current_entry_bool_val)
*pCtx->current_entry_bool_val = value;
return true;
}
static bool CCJSONStartObjectHandler(void *context)
{
CCJSONContext *pCtx = (CCJSONContext*)context;
pCtx->object_depth++;
if ((pCtx->object_depth == 1) && (pCtx->array_depth == 0))
{
pCtx->core_info_cache_list = new_core_info_cache_list();
if (!pCtx->core_info_cache_list)
return false;
}
else if ((pCtx->object_depth == 2) && (pCtx->array_depth == 1))
{
pCtx->core_info = (core_info_t *)calloc(1, sizeof(core_info_t));
if (!pCtx->core_info)
return false;
}
else if ((pCtx->object_depth == 3) && (pCtx->array_depth == 2))
{
if (pCtx->to_firmware)
{
pCtx->core_info->firmware_count++;
pCtx->core_info->firmware = (core_info_firmware_t *)realloc(pCtx->core_info->firmware, pCtx->core_info->firmware_count * sizeof(core_info_firmware_t));
}
}
return true;
}
static bool CCJSONEndObjectHandler(void *context)
{
CCJSONContext *pCtx = (CCJSONContext*)context;
if ((pCtx->object_depth == 2) && (pCtx->array_depth == 1))
{
core_info_add_cache(pCtx->core_info_cache_list, pCtx->core_info);
core_info_free(pCtx->core_info);
}
else if ((pCtx->object_depth == 3) && (pCtx->array_depth == 1))
{
if (pCtx->to_core_file_id)
pCtx->to_core_file_id = false;
}
retro_assert(pCtx->object_depth > 0);
pCtx->object_depth--;
return true;
}
static bool CCJSONStartArrayHandler(void *context)
{
CCJSONContext *pCtx = (CCJSONContext*)context;
pCtx->array_depth++;
return true;
}
static bool CCJSONEndArrayHandler(void *context)
{
CCJSONContext *pCtx = (CCJSONContext*)context;
if ((pCtx->object_depth == 2) && (pCtx->array_depth == 2))
{
if (pCtx->to_firmware)
pCtx->to_firmware = false;
}
retro_assert(pCtx->array_depth > 0);
pCtx->array_depth--;
return true;
}
core_info_cache_list_t *core_info_read_cache_file(const char *info_dir)
{
core_info_cache_list_t *core_info_cache_list;
char file_path[PATH_MAX_LENGTH];
core_info_cache_list = NULL;
file_path[0] = '\0';
fill_pathname_join(file_path, info_dir, CORE_INFO_CACHE_FILE_NAME, sizeof(file_path));
#if defined(HAVE_ZLIB)
/* Always use RZIP interface when reading playlists
* > this will automatically handle uncompressed
* data */
intfstream_t *file = intfstream_open_rzip_file(
file_path,
RETRO_VFS_FILE_ACCESS_READ);
#else
intfstream_t *file = intfstream_open_file(
playlist->config.path,
RETRO_VFS_FILE_ACCESS_READ,
RETRO_VFS_FILE_ACCESS_HINT_NONE);
#endif
if (file) {
rjson_t *parser;
CCJSONContext context = { 0 };
parser = rjson_open_stream(file);
if (!parser)
{
RARCH_ERR("Failed to create JSON parser\n");
goto end;
}
rjson_set_options(parser,
RJSON_OPTION_ALLOW_UTF8BOM
| RJSON_OPTION_ALLOW_COMMENTS
| RJSON_OPTION_ALLOW_UNESCAPED_CONTROL_CHARACTERS
| RJSON_OPTION_REPLACE_INVALID_ENCODING);
if (rjson_parse(parser, &context,
CCJSONObjectMemberHandler,
CCJSONStringHandler,
CCJSONNumberHandler,
CCJSONStartObjectHandler,
CCJSONEndObjectHandler,
CCJSONStartArrayHandler,
CCJSONEndArrayHandler,
CCJSONBoolHandler,
NULL) // null
!= RJSON_DONE)
{
RARCH_WARN("Error parsing chunk:\n---snip---\n%.*s\n---snip---\n",
rjson_get_source_context_len(parser),
rjson_get_source_context_buf(parser));
RARCH_WARN("Error: Invalid JSON at line %d, column %d - %s.\n",
(int)rjson_get_source_line(parser),
(int)rjson_get_source_column(parser),
(*rjson_get_error(parser) ? rjson_get_error(parser) : "format error"));
}
core_info_cache_list = context.core_info_cache_list;
rjson_free(parser);
}
else
{
core_info_cache_list = new_core_info_cache_list();
}
end:
intfstream_close(file);
free(file);
return core_info_cache_list;
}
core_info_cache_list_t *new_core_info_cache_list(void)
{
const int default_cache_capacity = 8;
core_info_cache_list_t *core_info_cache_list;
core_info_cache_list = (core_info_cache_list_t *)malloc(sizeof(*core_info_cache_list));
if (!core_info_cache_list)
return NULL;
core_info_cache_list->items = (core_info_t *)calloc(default_cache_capacity, sizeof(core_info_t));
if (!core_info_cache_list->items)
{
core_info_cache_list_free(core_info_cache_list);
return NULL;
}
core_info_cache_list->length = 0;
core_info_cache_list->capacity = default_cache_capacity;
core_info_cache_list->refresh = false;
return core_info_cache_list;
}
void core_info_write_cache_file(core_info_cache_list_t *list, const char *info_dir)
{
size_t i, j;
intfstream_t *file = NULL;
rjsonwriter_t *writer;
char file_path[PATH_MAX_LENGTH];
file_path[0] = '\0';
fill_pathname_join(file_path, info_dir, CORE_INFO_CACHE_FILE_NAME, sizeof(file_path));
file = intfstream_open_file(file_path, RETRO_VFS_FILE_ACCESS_WRITE, RETRO_VFS_FILE_ACCESS_HINT_NONE);
if (!file)
{
RARCH_ERR("Failed to write to core info cache file: %s\n", file_path);
return;
}
writer = rjsonwriter_open_stream(file);
if (!writer)
{
RARCH_ERR("Failed to create JSON writer\n");
goto end;
}
rjsonwriter_add_start_object(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 2);
rjsonwriter_add_string(writer, "version");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, "1.0");
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 2);
rjsonwriter_add_string(writer, "items");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_start_array(writer);
rjsonwriter_add_newline(writer);
for (i = 0; i < list->length; i++)
{
core_info_t* info = &list->items[i];
if (!info->is_installed)
continue;
if (i > 0)
{
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
}
rjsonwriter_add_spaces(writer, 4);
rjsonwriter_add_start_object(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "path");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->path);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "display_name");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->display_name);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "display_version");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->display_version);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "core_name");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->core_name);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "system_manufacturer");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->system_manufacturer);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "systemname");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->systemname);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "system_id");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->system_id);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "supported_extensions");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->supported_extensions);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "authors");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->authors);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "permissions");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->permissions);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "licenses");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->licenses);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "categories");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->categories);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "databases");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->databases);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "notes");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->notes);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "required_hw_api");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->required_hw_api);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "description");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->description);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
if (info->firmware_count)
{
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "firmware");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_start_array(writer);
rjsonwriter_add_newline(writer);
for (j = 0; j < info->firmware_count; j++)
{
rjsonwriter_add_spaces(writer, 8);
rjsonwriter_add_start_object(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 10);
rjsonwriter_add_string(writer, "path");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->firmware[j].path);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 10);
rjsonwriter_add_string(writer, "desc");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->firmware[j].desc);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 10);
rjsonwriter_add_string(writer, "missing");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->firmware[j].missing);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 10);
rjsonwriter_add_string(writer, "optional");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->firmware[j].optional);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 8);
rjsonwriter_add_end_object(writer);
if (j < info->firmware_count - 1)
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
}
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_end_array(writer);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
}
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "core_file_id");
rjsonwriter_add_colon(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_start_object(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 8);
rjsonwriter_add_string(writer, "str");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_string(writer, info->core_file_id.str);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 8);
rjsonwriter_add_string(writer, "hash");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_unsigned(writer, info->core_file_id.hash);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_end_object(writer);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "firmware_count");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_unsigned(writer, info->firmware_count);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "has_info");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->has_info);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "supports_no_game");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->supports_no_game);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "database_match_archive_member");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->database_match_archive_member);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "is_experimental");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->is_experimental);
rjsonwriter_add_comma(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 6);
rjsonwriter_add_string(writer, "is_locked");
rjsonwriter_add_colon(writer);
rjsonwriter_add_space(writer);
rjsonwriter_add_bool(writer, info->is_locked);
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 4);
rjsonwriter_add_end_object(writer);
}
rjsonwriter_add_newline(writer);
rjsonwriter_add_spaces(writer, 2);
rjsonwriter_add_end_array(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_add_end_object(writer);
rjsonwriter_add_newline(writer);
rjsonwriter_free(writer);
RARCH_LOG("[CoreInfo]: Written to cache file: %s\n", file_path);
end:
intfstream_close(file);
free(file);
list->refresh = false;
}
void core_info_copy(core_info_t *src, core_info_t *dst)
{
size_t i;
dst->path = src->path ? strdup(src->path) : NULL;
dst->display_name = src->display_name ? strdup(src->display_name) : NULL;
dst->display_version = src->display_version ? strdup(src->display_version) : NULL;
dst->core_name = src->core_name ? strdup(src->core_name) : NULL;
dst->system_manufacturer = src->system_manufacturer ? strdup(src->system_manufacturer) : NULL;
dst->systemname = src->systemname ? strdup(src->systemname) : NULL;
dst->system_id = src->system_id ? strdup(src->system_id) : NULL;
dst->supported_extensions = src->supported_extensions ? strdup(src->supported_extensions) : NULL;
dst->authors = src->authors ? strdup(src->authors) : NULL;
dst->permissions = src->permissions ? strdup(src->permissions) : NULL;
dst->licenses = src->licenses ? strdup(src->licenses) : NULL;
dst->categories = src->categories ? strdup(src->categories) : NULL;
dst->databases = src->databases ? strdup(src->databases) : NULL;
dst->notes = src->notes ? strdup(src->notes) : NULL;
dst->required_hw_api = src->required_hw_api ? strdup(src->required_hw_api) : NULL;
dst->description = src->description ? strdup(src->description) : NULL;
dst->categories_list = src->categories_list ? string_list_clone(src->categories_list) : NULL;
dst->databases_list = src->databases_list ? string_list_clone(src->databases_list) : NULL;
dst->note_list = src->note_list ? string_list_clone(src->note_list) : NULL;
dst->supported_extensions_list = src->supported_extensions_list ? string_list_clone(src->supported_extensions_list) : NULL;
dst->authors_list = src->authors_list ? string_list_clone(src->authors_list) : NULL;
dst->permissions_list = src->permissions_list ? string_list_clone(src->permissions_list) : NULL;
dst->licenses_list = src->licenses_list ? string_list_clone(src->licenses_list) : NULL;
dst->required_hw_api_list = src->required_hw_api_list ? string_list_clone(src->required_hw_api_list) : NULL;
if (src->firmware_count)
{
dst->firmware = (core_info_firmware_t*)calloc(src->firmware_count, sizeof(core_info_firmware_t));
if (!dst->firmware)
return;
for (i = 0; i < src->firmware_count; i++)
{
dst->firmware[i].path = src->firmware[i].path ? strdup(src->firmware[i].path) : NULL;
dst->firmware[i].desc = src->firmware[i].desc ? strdup(src->firmware[i].desc) : NULL;
dst->firmware[i].missing = src->firmware[i].missing;
dst->firmware[i].optional = src->firmware[i].optional;
}
}
dst->core_file_id.str = src->core_file_id.str ? strdup(src->core_file_id.str) : NULL;
dst->core_file_id.hash = src->core_file_id.hash;
dst->firmware_count = src->firmware_count;
dst->has_info = src->has_info;
dst->supports_no_game = src->supports_no_game;
dst->database_match_archive_member = src->database_match_archive_member;
dst->is_experimental = src->is_experimental;
dst->is_locked = src->is_locked;
dst->is_installed = src->is_installed;
}
void core_info_check_uninstalled(core_info_cache_list_t *list)
{
size_t i;
if (!list)
return;
for (i = 0; i < list->length; i++)
{
core_info_t *info = (core_info_t *)&list->items[i];
if (!info)
continue;
if (!info->is_installed)
{
list->refresh = true;
return;
}
}
}