1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 12:15:49 +00:00
RetroArch/core_info.c

960 lines
24 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
* Copyright (C) 2016-2017 - 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>
2014-10-21 22:23:06 +00:00
#include <file/file_path.h>
#include <lists/dir_list.h>
#include <file/archive_file.h>
#include <streams/file_stream.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
2017-05-11 07:11:46 +00:00
#include "retroarch.h"
2016-11-28 01:24:23 +00:00
#include "verbosity.h"
2016-09-08 04:07:43 +00:00
#include "config.def.h"
#include "core_info.h"
2016-02-07 12:10:04 +00:00
#include "configuration.h"
2018-04-09 20:20:51 +00:00
#include "file_path_special.h"
2016-03-20 16:28:24 +00:00
#include "list_special.h"
2016-05-09 16:11:17 +00:00
static const char *core_info_tmp_path = NULL;
static const struct string_list *core_info_tmp_list = NULL;
2016-05-09 16:11:17 +00:00
static core_info_t *core_info_current = NULL;
static core_info_list_t *core_info_curr_list = NULL;
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++)
{
2015-01-12 03:19:57 +00:00
if (core_info_list->list[i].supported_extensions)
2016-10-10 08:49:09 +00:00
all_ext_len +=
2015-01-12 03:19:57 +00:00
(strlen(core_info_list->list[i].supported_extensions) + 2);
}
all_ext_len += strlen("7z|") + strlen("zip|");
if (all_ext_len)
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
}
2014-09-02 03:10:54 +00:00
static void core_info_list_resolve_all_firmware(
core_info_list_t *core_info_list)
{
2013-11-24 01:08:20 +00:00
size_t i;
unsigned c;
2015-01-09 14:33:58 +00:00
for (i = 0; i < core_info_list->count; i++)
{
unsigned count = 0;
core_info_firmware_t *firmware = NULL;
core_info_t *info = (core_info_t*)&core_info_list->list[i];
config_file_t *config = (config_file_t*)info->config_data;
2016-12-14 10:47:04 +00:00
if (!config || !config_get_uint(config, "firmware_count", &count))
continue;
firmware = (core_info_firmware_t*)calloc(count, sizeof(*firmware));
2014-09-02 03:10:54 +00:00
if (!firmware)
continue;
2014-03-03 09:11:07 +00:00
info->firmware = firmware;
for (c = 0; c < count; c++)
{
2016-12-14 10:47:04 +00:00
char path_key[64];
char desc_key[64];
char opt_key[64];
bool tmp_bool = false;
char *tmp = NULL;
path_key[0] = desc_key[0] = opt_key[0] = '\0';
2014-03-04 08:34:34 +00:00
snprintf(path_key, sizeof(path_key), "firmware%u_path", c);
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c);
2016-06-20 02:23:00 +00:00
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c);
if (config_get_string(config, path_key, &tmp) && !string_is_empty(tmp))
{
info->firmware[c].path = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(config, desc_key, &tmp) && !string_is_empty(tmp))
{
info->firmware[c].desc = strdup(tmp);
free(tmp);
tmp = NULL;
}
2017-01-13 17:24:24 +00:00
if (tmp)
free(tmp);
tmp = NULL;
if (config_get_bool(config, opt_key , &tmp_bool))
info->firmware[c].optional = tmp_bool;
}
}
}
2016-02-07 11:51:45 +00:00
static void core_info_list_free(core_info_list_t *core_info_list)
{
size_t i, j;
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];
free(info->path);
free(info->core_name);
free(info->systemname);
free(info->system_manufacturer);
free(info->display_name);
free(info->supported_extensions);
free(info->authors);
free(info->permissions);
free(info->licenses);
free(info->categories);
free(info->databases);
free(info->notes);
2016-12-14 15:10:48 +00:00
string_list_free(info->supported_extensions_list);
2016-02-07 11:51:45 +00:00
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);
config_file_free((config_file_t*)info->config_data);
for (j = 0; j < info->firmware_count; j++)
{
free(info->firmware[j].path);
free(info->firmware[j].desc);
}
free(info->firmware);
}
free(core_info_list->all_ext);
free(core_info_list->list);
free(core_info_list);
}
2016-12-13 23:55:05 +00:00
static bool core_info_list_iterate(
char *s, size_t len,
const char *path_basedir,
2016-02-07 18:01:17 +00:00
struct string_list *contents, size_t i)
{
2017-09-09 19:55:35 +00:00
size_t info_path_base_size = PATH_MAX_LENGTH * sizeof(char);
2018-02-02 20:48:55 +00:00
char *info_path_base = NULL;
2017-09-09 19:55:35 +00:00
char *substr = NULL;
2018-02-02 20:48:55 +00:00
const char *current_path = contents ? contents->elems[i].data : NULL;
2018-02-02 20:48:55 +00:00
(void)substr;
if (!current_path)
return false;
info_path_base = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
2016-12-14 10:47:04 +00:00
info_path_base[0] = '\0';
2017-09-09 19:55:35 +00:00
fill_pathname_base_noext(info_path_base,
current_path,
2017-09-09 19:55:35 +00:00
info_path_base_size);
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP) && !defined(_3DS) && !defined(VITA) && !defined(HW_WUP))
2016-12-14 10:47:04 +00:00
substr = strrchr(info_path_base, '_');
if (substr)
*substr = '\0';
#endif
2016-06-28 06:57:01 +00:00
strlcat(info_path_base,
file_path_str(FILE_PATH_CORE_INFO_EXTENSION),
2017-09-09 19:55:35 +00:00
info_path_base_size);
2016-12-13 23:55:05 +00:00
fill_pathname_join(s,
path_basedir,
2016-12-13 23:55:05 +00:00
info_path_base, len);
2017-09-09 19:55:35 +00:00
free(info_path_base);
2016-12-13 23:55:05 +00:00
return true;
}
2016-12-14 10:47:04 +00:00
static core_info_list_t *core_info_list_new(const char *path)
{
size_t i;
2016-02-07 18:01:17 +00:00
core_info_t *core_info = NULL;
core_info_list_t *core_info_list = NULL;
2016-12-14 10:47:04 +00:00
struct string_list *contents = dir_list_new_special(
path, DIR_LIST_CORES, NULL);
settings_t *settings = config_get_ptr();
const char *path_basedir = !string_is_empty(settings->paths.path_libretro_info) ?
settings->paths.path_libretro_info : settings->paths.directory_libretro;
2015-01-09 14:33:58 +00:00
2013-06-26 00:57:19 +00:00
if (!contents)
return NULL;
core_info_list = (core_info_list_t*)calloc(1, sizeof(*core_info_list));
if (!core_info_list)
goto error;
core_info = (core_info_t*)calloc(contents->size, sizeof(*core_info));
if (!core_info)
goto error;
2016-12-14 00:16:10 +00:00
core_info_list->list = core_info;
core_info_list->count = contents->size;
for (i = 0; i < contents->size; i++)
{
2017-09-09 19:55:35 +00:00
size_t info_path_size = PATH_MAX_LENGTH * sizeof(char);
char *info_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
2017-09-09 19:55:35 +00:00
info_path[0] = '\0';
2016-12-13 23:55:05 +00:00
if (
2017-09-09 19:55:35 +00:00
core_info_list_iterate(info_path, info_path_size,
path_basedir, contents, i)
2016-12-13 23:55:05 +00:00
&& path_is_valid(info_path))
{
char *tmp = NULL;
2016-12-13 23:55:05 +00:00
bool tmp_bool = false;
unsigned count = 0;
config_file_t *conf = config_file_new(info_path);
2016-02-07 17:27:27 +00:00
2017-09-09 19:55:35 +00:00
free(info_path);
2016-12-14 11:55:12 +00:00
if (!conf)
continue;
if (config_get_string(conf, "display_name", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].display_name = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "corename", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].core_name = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "systemname", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].systemname = strdup(tmp);
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "manufacturer", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].system_manufacturer = strdup(tmp);
free(tmp);
tmp = NULL;
}
2015-12-06 19:44:21 +00:00
config_get_uint(conf, "firmware_count", &count);
2014-03-03 09:11:07 +00:00
core_info[i].firmware_count = count;
if (config_get_string(conf, "supported_extensions", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].supported_extensions = strdup(tmp);
2014-09-02 03:10:54 +00:00
core_info[i].supported_extensions_list =
string_split(core_info[i].supported_extensions, "|");
2013-11-07 23:30:00 +00:00
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "authors", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].authors = strdup(tmp);
2014-09-02 03:10:54 +00:00
core_info[i].authors_list =
string_split(core_info[i].authors, "|");
2013-12-14 18:29:14 +00:00
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "permissions", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].permissions = strdup(tmp);
2014-09-02 03:10:54 +00:00
core_info[i].permissions_list =
string_split(core_info[i].permissions, "|");
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "license", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].licenses = strdup(tmp);
2014-09-08 18:18:36 +00:00
core_info[i].licenses_list =
string_split(core_info[i].licenses, "|");
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "categories", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].categories = strdup(tmp);
core_info[i].categories_list =
string_split(core_info[i].categories, "|");
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "database", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].databases = strdup(tmp);
2015-01-25 07:21:02 +00:00
core_info[i].databases_list =
string_split(core_info[i].databases, "|");
free(tmp);
tmp = NULL;
}
if (config_get_string(conf, "notes", &tmp)
2017-09-09 19:55:35 +00:00
&& !string_is_empty(tmp))
{
core_info[i].notes = strdup(tmp);
2014-03-03 09:11:07 +00:00
core_info[i].note_list = string_split(core_info[i].notes, "|");
free(tmp);
tmp = NULL;
}
2017-01-13 17:35:20 +00:00
if (tmp)
free(tmp);
tmp = NULL;
2016-06-02 21:00:11 +00:00
if (config_get_bool(conf, "supports_no_game",
&tmp_bool))
core_info[i].supports_no_game = tmp_bool;
2015-12-06 19:44:21 +00:00
if (config_get_bool(conf, "database_match_archive_member",
&tmp_bool))
core_info[i].database_match_archive_member = tmp_bool;
2015-12-06 19:44:21 +00:00
core_info[i].config_data = conf;
}
2017-09-09 19:55:35 +00:00
else
free(info_path);
2013-06-26 00:57:19 +00:00
if (!string_is_empty(contents->elems[i].data))
core_info[i].path = strdup(contents->elems[i].data);
2016-02-07 17:27:27 +00:00
2013-06-26 00:57:19 +00:00
if (!core_info[i].display_name)
2016-10-10 08:49:09 +00:00
core_info[i].display_name =
strdup(path_basename(core_info[i].path));
}
if (core_info_list)
2017-09-29 20:03:26 +00:00
{
core_info_list_resolve_all_extensions(core_info_list);
core_info_list_resolve_all_firmware(core_info_list);
2017-09-29 20:03:26 +00:00
}
2013-10-05 15:07:56 +00:00
2013-06-26 00:57:19 +00:00
dir_list_free(contents);
return core_info_list;
error:
if (contents)
dir_list_free(contents);
core_info_list_free(core_info_list);
return NULL;
}
2016-10-10 08:49:09 +00:00
/* Shallow-copies internal state.
2016-02-07 16:34:22 +00:00
*
* Data in *info is invalidated when the
* core_info_list is freed. */
static bool core_info_list_get_info(core_info_list_t *core_info_list,
2014-09-02 03:10:54 +00:00
core_info_t *out_info, const char *path)
{
size_t i;
2014-06-01 00:29:19 +00:00
if (!core_info_list || !out_info)
2014-06-01 00:16:48 +00:00
return false;
memset(out_info, 0, sizeof(*out_info));
for (i = 0; i < core_info_list->count; i++)
{
const core_info_t *info = &core_info_list->list[i];
2016-01-20 03:07:24 +00:00
2016-10-10 08:49:09 +00:00
if (string_is_equal(path_basename(info->path),
path_basename(path)))
{
*out_info = *info;
return true;
}
}
return false;
}
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;
}
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_)
{
const core_info_t *a = (const core_info_t*)a_;
const core_info_t *b = (const core_info_t*)b_;
2016-10-10 08:49:09 +00:00
int support_a =
core_info_does_support_any_file(a, core_info_tmp_list)
|| core_info_does_support_file(a, core_info_tmp_path);
2016-10-10 08:49:09 +00:00
int support_b =
core_info_does_support_any_file(b, core_info_tmp_list)
|| core_info_does_support_file(b, core_info_tmp_path);
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 core_info_t *core_info_find_internal(
core_info_list_t *list,
2014-09-02 03:10:54 +00:00
const char *core)
{
size_t i;
2014-06-01 00:29:19 +00:00
for (i = 0; i < list->count; i++)
{
2016-02-07 16:39:10 +00:00
core_info_t *info = core_info_get(list, i);
2015-01-11 06:37:02 +00:00
2016-12-14 12:47:22 +00:00
if (!info || !info->path)
2015-01-11 06:37:02 +00:00
continue;
2016-01-20 03:07:24 +00:00
if (string_is_equal(info->path, core))
return info;
}
return NULL;
}
2016-05-09 16:11:17 +00:00
static bool core_info_list_update_missing_firmware_internal(
core_info_list_t *core_info_list,
2016-05-09 16:11:17 +00:00
const char *core,
const char *systemdir)
2014-03-03 06:02:29 +00:00
{
size_t i;
2017-09-09 19:55:35 +00:00
core_info_t *info = NULL;
char *path = NULL;
2017-09-09 19:55:35 +00:00
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
2014-08-02 12:01:35 +00:00
if (!core_info_list || !core)
return false;
2014-03-03 06:02:29 +00:00
info = core_info_find_internal(core_info_list, core);
2016-02-07 18:02:09 +00:00
if (!info)
return false;
2016-12-14 10:47:04 +00:00
path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
path[0] = '\0';
2017-05-15 03:06:23 +00:00
rarch_ctl(RARCH_CTL_UNSET_MISSING_BIOS, NULL);
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,
2017-09-09 19:55:35 +00:00
info->firmware[i].path, path_size);
info->firmware[i].missing = !filestream_exists(path);
if (info->firmware[i].missing && !info->firmware[i].optional)
{
2017-05-15 03:06:23 +00:00
rarch_ctl(RARCH_CTL_SET_MISSING_BIOS, NULL);
RARCH_WARN("Firmware missing: %s\n", info->firmware[i].path);
}
2014-03-03 06:02:29 +00:00
}
2017-09-09 19:55:35 +00:00
free(path);
return true;
2014-03-03 06:02:29 +00:00
}
2016-02-07 11:51:45 +00:00
#if 0
static int core_info_firmware_cmp(const void *a_, const void *b_)
{
const core_info_firmware_t *a = (const core_info_firmware_t*)a_;
const core_info_firmware_t *b = (const core_info_firmware_t*)b_;
int order = b->missing - a->missing;
if (order)
return order;
return strcasecmp(a->path, b->path);
}
/* Non-reentrant, does not allocate. Returns pointer to internal state. */
static void core_info_list_get_missing_firmware(
core_info_list_t *core_info_list,
const char *core, const char *systemdir,
const core_info_firmware_t **firmware, size_t *num_firmware)
{
size_t i;
2016-12-14 10:47:04 +00:00
char path[PATH_MAX_LENGTH];
2015-06-13 01:06:11 +00:00
core_info_t *info = NULL;
2014-08-02 12:01:35 +00:00
if (!core_info_list || !core)
2014-06-01 00:29:19 +00:00
return;
2016-12-14 10:47:04 +00:00
path[0] = '\0';
2015-11-20 07:42:33 +00:00
*firmware = NULL;
*num_firmware = 0;
2016-12-14 15:10:48 +00:00
info = core_info_find_internal(core_info_list, core);
2016-12-14 15:10:48 +00:00
if (!info)
return;
*firmware = info->firmware;
for (i = 1; i < info->firmware_count; i++)
{
fill_pathname_join(path, systemdir,
info->firmware[i].path, sizeof(path));
info->firmware[i].missing = !filestream_exists(path);
*num_firmware += info->firmware[i].missing;
}
2014-09-02 03:10:54 +00:00
qsort(info->firmware, info->firmware_count, sizeof(*info->firmware),
core_info_firmware_cmp);
}
2016-02-07 11:51:45 +00:00
#endif
2016-02-07 01:18:26 +00:00
2016-05-09 16:11:17 +00:00
void core_info_free_current_core(void)
{
if (core_info_current)
free(core_info_current);
core_info_current = NULL;
}
bool core_info_init_current_core(void)
2016-02-07 01:18:26 +00:00
{
2016-05-09 16:11:17 +00:00
core_info_current = (core_info_t*)calloc(1, sizeof(core_info_t));
if (!core_info_current)
return false;
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)
{
if (!core)
return false;
*core = core_info_current;
return true;
}
void core_info_deinit_list(void)
{
if (core_info_curr_list)
core_info_list_free(core_info_curr_list);
core_info_curr_list = NULL;
}
bool core_info_init_list(void)
{
2016-12-14 10:47:04 +00:00
settings_t *settings = config_get_ptr();
if (settings)
2017-04-28 22:39:29 +00:00
core_info_curr_list = core_info_list_new(settings->paths.directory_libretro);
2016-05-09 16:11:17 +00:00
if (!core_info_curr_list)
return false;
return true;
}
bool core_info_get_list(core_info_list_t **core)
{
if (!core)
return false;
*core = core_info_curr_list;
return true;
}
bool core_info_list_update_missing_firmware(core_info_ctx_firmware_t *info)
{
if (!info)
return false;
return core_info_list_update_missing_firmware_internal(
core_info_curr_list,
info->path, info->directory.system);
}
bool core_info_load(core_info_ctx_find_t *info)
{
core_info_t *core_info = NULL;
if (!info)
return false;
core_info_get_current_core(&core_info);
if (!core_info_curr_list)
return false;
if (!core_info_list_get_info(core_info_curr_list,
core_info, info->path))
return false;
return true;
}
2016-07-09 19:50:20 +00:00
bool core_info_find(core_info_ctx_find_t *info, const char *core_path)
2016-05-09 16:11:17 +00:00
{
if (!info || !core_info_curr_list)
return false;
2016-07-09 19:50:20 +00:00
info->inf = core_info_find_internal(core_info_curr_list, core_path);
2016-05-09 16:11:17 +00:00
if (!info->inf)
return false;
return true;
}
core_info_t *core_info_get(core_info_list_t *list, size_t i)
{
core_info_t *info = NULL;
if (!list)
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;
2016-05-09 16:11:17 +00:00
struct string_list *list = NULL;
2016-09-19 01:54:57 +00:00
size_t supported = 0;
2016-05-09 16:11:17 +00:00
if (!core_info_list)
return;
core_info_tmp_path = path;
#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);
core_info_tmp_list = list;
#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;
}
if (list)
string_list_free(list);
*infos = core_info_list->list;
*num_infos = supported;
}
void core_info_get_name(const char *path, char *s, size_t len)
{
size_t i;
2016-07-20 00:57:25 +00:00
settings_t *settings = config_get_ptr();
2016-12-14 00:08:32 +00:00
struct string_list *contents = dir_list_new_special(
2017-04-28 22:39:29 +00:00
settings->paths.directory_libretro,
2016-07-20 00:57:25 +00:00
DIR_LIST_CORES, NULL);
const char *path_basedir = !string_is_empty(settings->paths.path_libretro_info) ?
settings->paths.path_libretro_info : settings->paths.directory_libretro;
2016-05-09 16:11:17 +00:00
if (!contents)
return;
for (i = 0; i < contents->size; i++)
{
2017-09-09 19:55:35 +00:00
size_t path_size = PATH_MAX_LENGTH * sizeof(char);
char *info_path = NULL;
2016-12-14 00:07:48 +00:00
config_file_t *conf = NULL;
char *new_core_name = NULL;
const char *current_path = contents->elems[i].data;
2016-12-13 23:55:05 +00:00
if (!string_is_equal(current_path, path))
2016-05-09 16:11:17 +00:00
continue;
info_path = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
info_path[0] = '\0';
2016-10-10 08:49:09 +00:00
2016-12-14 00:07:48 +00:00
if (!core_info_list_iterate(info_path,
path_size, path_basedir, contents, i)
2016-12-13 23:55:05 +00:00
&& path_is_valid(info_path))
2017-09-09 19:55:35 +00:00
{
free(info_path);
2016-12-14 00:07:48 +00:00
continue;
2017-09-09 19:55:35 +00:00
}
2016-12-13 23:55:05 +00:00
2016-12-14 00:07:48 +00:00
conf = config_file_new(info_path);
2016-05-09 16:11:17 +00:00
2016-12-14 11:55:12 +00:00
if (!conf)
2017-09-09 19:55:35 +00:00
{
free(info_path);
2016-12-14 11:55:12 +00:00
continue;
2017-09-09 19:55:35 +00:00
}
2016-12-14 11:55:12 +00:00
if (config_get_string(conf, "corename",
&new_core_name))
{
strlcpy(s, new_core_name, len);
free(new_core_name);
}
2016-05-09 16:11:17 +00:00
2016-12-14 00:07:48 +00:00
config_file_free(conf);
2017-09-09 19:55:35 +00:00
free(info_path);
2016-12-14 00:07:48 +00:00
break;
2016-05-09 16:11:17 +00:00
}
if (contents)
dir_list_free(contents);
contents = NULL;
}
size_t core_info_list_num_info_files(core_info_list_t *core_info_list)
{
size_t i, num = 0;
if (!core_info_list)
return 0;
for (i = 0; i < core_info_list->count; i++)
{
config_file_t *conf = (config_file_t*)
core_info_list->list[i].config_data;
num += !!conf;
}
return num;
}
bool core_info_database_match_archive_member(const char *database_path)
{
char *database = NULL;
const char *new_path = path_basename(database_path);
if (string_is_empty(new_path))
return false;
database = strdup(new_path);
if (string_is_empty(database))
goto error;
path_remove_extension(database);
if (core_info_curr_list)
{
size_t i;
for (i = 0; i < core_info_curr_list->count; i++)
{
const core_info_t *info = &core_info_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;
}
}
error:
if (database)
free(database);
return false;
}
bool core_info_database_supports_content_path(const char *database_path, const char *path)
{
2016-12-14 00:16:10 +00:00
char *database = NULL;
const char *new_path = path_basename(database_path);
if (string_is_empty(new_path))
return false;
database = strdup(new_path);
if (string_is_empty(database))
2017-09-10 22:12:26 +00:00
goto error;
path_remove_extension(database);
if (core_info_curr_list)
{
size_t i;
2017-02-28 10:16:05 +00:00
for (i = 0; i < core_info_curr_list->count; i++)
{
const core_info_t *info = &core_info_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;
}
}
2017-09-10 22:12:26 +00:00
error:
if (database)
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 *path, char *s, size_t len)
{
size_t i;
if (!core_info_list)
return false;
for (i = 0; i < core_info_list->count; i++)
2016-02-07 01:18:26 +00:00
{
2016-05-09 16:11:17 +00:00
const core_info_t *info = &core_info_list->list[i];
2016-12-14 00:23:08 +00:00
if (!string_is_equal(path_basename(info->path), path_basename(path)))
continue;
if (!info->display_name)
continue;
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;
}
bool core_info_get_display_name(const char *path, char *s, size_t len)
{
2016-12-14 00:23:08 +00:00
bool ret = true;
char *tmp = NULL;
2016-12-14 00:23:08 +00:00
config_file_t *conf = config_file_new(path);
2016-05-09 16:11:17 +00:00
if (!conf)
2016-12-14 00:23:08 +00:00
{
ret = false;
2016-05-09 16:11:17 +00:00
goto error;
2016-12-14 00:23:08 +00:00
}
2016-05-09 16:11:17 +00:00
if (config_get_string(conf, "display_name", &tmp))
{
2017-01-25 01:39:52 +00:00
strlcpy(s, tmp, len);
free(tmp);
}
2016-05-09 16:11:17 +00:00
error:
2016-05-24 20:12:41 +00:00
config_file_free(conf);
2016-12-14 00:23:08 +00:00
return ret;
2016-02-07 01:18:26 +00:00
}