2013-06-24 11:52:14 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2013-2015 - Jason Fetters
|
2013-06-24 11:52:14 +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/>.
|
|
|
|
*/
|
|
|
|
|
2014-10-21 22:23:06 +00:00
|
|
|
#include <file/file_path.h>
|
2016-02-05 12:57:08 +00:00
|
|
|
#include <file/dir_list.h>
|
2016-01-24 06:29:11 +00:00
|
|
|
#include <file/file_archive.h>
|
2016-02-07 12:10:04 +00:00
|
|
|
#include <compat/strl.h>
|
2015-09-04 19:11:00 +00:00
|
|
|
|
2016-01-20 03:07:24 +00:00
|
|
|
#include <string/stdstring.h>
|
|
|
|
|
2015-12-11 12:56:00 +00:00
|
|
|
#include "core_info.h"
|
2016-02-07 12:10:04 +00:00
|
|
|
#include "configuration.h"
|
2015-05-24 02:39:16 +00:00
|
|
|
#include "dir_list_special.h"
|
2014-08-02 12:04:43 +00:00
|
|
|
#include "config.def.h"
|
2013-06-24 01:18:23 +00:00
|
|
|
|
2013-10-05 16:33:22 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2014-08-02 12:04:43 +00:00
|
|
|
#include "config.h"
|
2013-10-05 16:33:22 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-07 01:53:00 +00:00
|
|
|
static const char *core_info_tmp_path = NULL;
|
|
|
|
static const struct string_list *core_info_tmp_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)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
|
|
|
size_t i, all_ext_len = 0;
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2014-06-01 00:29:19 +00:00
|
|
|
if (!core_info_list)
|
|
|
|
return;
|
|
|
|
|
2013-11-21 22:48:31 +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)
|
|
|
|
all_ext_len +=
|
|
|
|
(strlen(core_info_list->list[i].supported_extensions) + 2);
|
2013-11-21 22:48:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (all_ext_len)
|
|
|
|
core_info_list->all_ext = (char*)calloc(1, all_ext_len);
|
|
|
|
|
2015-02-05 17:34:31 +00:00
|
|
|
if (!core_info_list->all_ext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < core_info_list->count; i++)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
2015-02-05 17:34:31 +00:00
|
|
|
if (!core_info_list->list[i].supported_extensions)
|
|
|
|
continue;
|
2015-01-12 03:19:57 +00:00
|
|
|
|
2015-02-05 17:34:31 +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);
|
2013-11-21 22:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-21 22:48:31 +00:00
|
|
|
{
|
2013-11-24 01:08:20 +00:00
|
|
|
size_t i;
|
|
|
|
unsigned c;
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2014-06-01 00:29:19 +00:00
|
|
|
if (!core_info_list)
|
|
|
|
return;
|
2014-03-03 09:11:07 +00:00
|
|
|
|
2013-11-22 16:43:49 +00:00
|
|
|
for (i = 0; i < core_info_list->count; i++)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
2015-12-06 19:44:21 +00:00
|
|
|
unsigned count = 0;
|
|
|
|
core_info_t *info = (core_info_t*)&core_info_list->list[i];
|
2015-12-10 13:05:56 +00:00
|
|
|
config_file_t *config = (config_file_t*)info->config_data;
|
2013-11-21 22:48:31 +00:00
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (!info || !config)
|
2013-11-21 22:48:31 +00:00
|
|
|
continue;
|
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (!config_get_uint(config, "firmware_count", &count))
|
2013-11-21 22:48:31 +00:00
|
|
|
continue;
|
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
info->firmware = (core_info_firmware_t*)
|
|
|
|
calloc(count, sizeof(*info->firmware));
|
|
|
|
|
2013-11-21 22:48:31 +00:00
|
|
|
if (!info->firmware)
|
|
|
|
continue;
|
2014-03-03 09:11:07 +00:00
|
|
|
|
2013-11-22 16:43:49 +00:00
|
|
|
for (c = 0; c < count; c++)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
2015-06-13 01:06:11 +00:00
|
|
|
char path_key[64] = {0};
|
|
|
|
char desc_key[64] = {0};
|
|
|
|
char opt_key[64] = {0};
|
2014-03-04 08:34:34 +00:00
|
|
|
|
2013-11-21 22:48:31 +00:00
|
|
|
snprintf(path_key, sizeof(path_key), "firmware%u_path", c);
|
|
|
|
snprintf(desc_key, sizeof(desc_key), "firmware%u_desc", c);
|
2014-03-04 08:34:34 +00:00
|
|
|
snprintf(opt_key, sizeof(opt_key), "firmware%u_opt", c);
|
2013-11-21 22:48:31 +00:00
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
config_get_string(config, path_key, &info->firmware[c].path);
|
|
|
|
config_get_string(config, desc_key, &info->firmware[c].desc);
|
|
|
|
config_get_bool(config, opt_key , &info->firmware[c].optional);
|
2013-11-21 22:48:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (info->supported_extensions_list)
|
|
|
|
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);
|
|
|
|
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-02-07 18:01:17 +00:00
|
|
|
static config_file_t *core_info_list_iterate(
|
|
|
|
struct string_list *contents, size_t i)
|
2016-02-07 17:32:56 +00:00
|
|
|
{
|
|
|
|
char info_path_base[PATH_MAX_LENGTH];
|
|
|
|
char info_path[PATH_MAX_LENGTH];
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
if (!contents->elems[i].data)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fill_pathname_base(info_path_base, contents->elems[i].data,
|
|
|
|
sizeof(info_path_base));
|
|
|
|
path_remove_extension(info_path_base);
|
|
|
|
|
|
|
|
#if defined(RARCH_MOBILE) || (defined(RARCH_CONSOLE) && !defined(PSP))
|
|
|
|
char *substr = strrchr(info_path_base, '_');
|
|
|
|
if (substr)
|
|
|
|
*substr = '\0';
|
|
|
|
#endif
|
|
|
|
|
|
|
|
strlcat(info_path_base, ".info", sizeof(info_path_base));
|
|
|
|
|
|
|
|
fill_pathname_join(info_path, (*settings->libretro_info_path) ?
|
|
|
|
settings->libretro_info_path : settings->libretro_directory,
|
|
|
|
info_path_base, sizeof(info_path));
|
|
|
|
|
|
|
|
return config_file_new(info_path);
|
|
|
|
}
|
|
|
|
|
2015-05-26 04:28:16 +00:00
|
|
|
void core_info_get_name(const char *path, char *s, size_t len)
|
|
|
|
{
|
|
|
|
size_t i;
|
2016-02-07 18:01:17 +00:00
|
|
|
core_info_t *core_info = NULL;
|
2015-05-26 04:28:16 +00:00
|
|
|
core_info_list_t *core_info_list = NULL;
|
2016-02-07 18:01:17 +00:00
|
|
|
struct string_list *contents = dir_list_new_special(
|
2016-02-07 00:15:10 +00:00
|
|
|
NULL, DIR_LIST_CORES, NULL);
|
2015-05-26 04:28:16 +00:00
|
|
|
|
|
|
|
if (!contents)
|
2015-05-26 07:06:02 +00:00
|
|
|
return;
|
2015-05-26 04:28:16 +00:00
|
|
|
|
|
|
|
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-02-07 15:03:53 +00:00
|
|
|
core_info_list->list = core_info;
|
|
|
|
core_info_list->count = 0;
|
2015-05-26 04:28:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < contents->size; i++)
|
|
|
|
{
|
2016-02-07 17:32:56 +00:00
|
|
|
config_file_t *conf = NULL;
|
2015-05-26 04:28:16 +00:00
|
|
|
|
2016-02-07 17:32:56 +00:00
|
|
|
if (!string_is_equal(contents->elems[i].data, path))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
conf = core_info_list_iterate(contents, i);
|
2015-05-26 04:28:16 +00:00
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (conf)
|
|
|
|
{
|
|
|
|
config_get_string(conf, "corename",
|
2015-05-26 04:28:16 +00:00
|
|
|
&core_info[i].core_name);
|
2015-12-06 19:44:21 +00:00
|
|
|
core_info[i].config_data = (void*)conf;
|
|
|
|
}
|
2015-05-26 04:28:16 +00:00
|
|
|
|
2016-02-07 17:32:56 +00:00
|
|
|
core_info[i].path = strdup(contents->elems[i].data);
|
|
|
|
|
2015-05-26 04:28:16 +00:00
|
|
|
strlcpy(s, core_info[i].core_name, len);
|
|
|
|
}
|
|
|
|
|
2016-02-07 15:03:53 +00:00
|
|
|
for (i = 0; i < contents->size; i++)
|
|
|
|
{
|
|
|
|
config_file_t *conf = (config_file_t*)
|
|
|
|
core_info_list->list[i].config_data;
|
|
|
|
core_info_list->count += !!conf;
|
|
|
|
}
|
|
|
|
|
2015-05-26 04:28:16 +00:00
|
|
|
error:
|
|
|
|
if (contents)
|
|
|
|
dir_list_free(contents);
|
|
|
|
contents = NULL;
|
|
|
|
core_info_list_free(core_info_list);
|
|
|
|
}
|
|
|
|
|
2016-02-07 17:27:27 +00:00
|
|
|
|
2016-02-07 11:51:45 +00:00
|
|
|
static core_info_list_t *core_info_list_new(void)
|
2013-06-24 01:18:23 +00:00
|
|
|
{
|
2013-11-21 22:48:31 +00:00
|
|
|
size_t i;
|
2016-02-07 18:01:17 +00:00
|
|
|
core_info_t *core_info = NULL;
|
2013-10-05 11:37:38 +00:00
|
|
|
core_info_list_t *core_info_list = NULL;
|
2016-02-07 18:01:17 +00:00
|
|
|
struct string_list *contents =
|
2016-02-07 00:15:10 +00:00
|
|
|
dir_list_new_special(NULL, DIR_LIST_CORES, NULL);
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2013-06-26 00:57:19 +00:00
|
|
|
if (!contents)
|
2013-06-24 01:18:23 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-10-05 11:37:38 +00:00
|
|
|
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;
|
2013-06-24 01:18:23 +00:00
|
|
|
|
2016-02-07 17:19:58 +00:00
|
|
|
core_info_list->list = core_info;
|
|
|
|
core_info_list->count = 0;
|
2013-06-24 01:18:23 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < contents->size; i++)
|
2013-06-24 01:18:23 +00:00
|
|
|
{
|
2016-02-07 17:27:27 +00:00
|
|
|
config_file_t *conf = core_info_list_iterate(contents, i);
|
2013-06-24 11:52:14 +00:00
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (conf)
|
2013-06-24 01:18:23 +00:00
|
|
|
{
|
2014-03-03 09:11:07 +00:00
|
|
|
unsigned count = 0;
|
2016-02-07 17:27:27 +00:00
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
config_get_string(conf, "display_name",
|
2014-09-02 03:10:54 +00:00
|
|
|
&core_info[i].display_name);
|
2015-12-06 19:44:21 +00:00
|
|
|
config_get_string(conf, "corename",
|
2014-12-15 00:59:32 +00:00
|
|
|
&core_info[i].core_name);
|
2015-12-06 19:44:21 +00:00
|
|
|
config_get_string(conf, "systemname",
|
2014-09-02 03:10:54 +00:00
|
|
|
&core_info[i].systemname);
|
2015-12-06 19:44:21 +00:00
|
|
|
config_get_string(conf, "manufacturer",
|
2014-12-15 00:59:32 +00:00
|
|
|
&core_info[i].system_manufacturer);
|
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;
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "supported_extensions",
|
2014-09-02 03:10:54 +00:00
|
|
|
&core_info[i].supported_extensions) &&
|
2013-06-26 01:04:16 +00:00
|
|
|
core_info[i].supported_extensions)
|
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
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "authors",
|
2014-09-02 03:10:54 +00:00
|
|
|
&core_info[i].authors) &&
|
2013-11-07 23:30:00 +00:00
|
|
|
core_info[i].authors)
|
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
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "permissions",
|
2014-09-02 03:10:54 +00:00
|
|
|
&core_info[i].permissions) &&
|
2013-12-14 18:29:14 +00:00
|
|
|
core_info[i].permissions)
|
2014-09-02 03:10:54 +00:00
|
|
|
core_info[i].permissions_list =
|
|
|
|
string_split(core_info[i].permissions, "|");
|
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "license",
|
2014-09-08 18:18:36 +00:00
|
|
|
&core_info[i].licenses) &&
|
|
|
|
core_info[i].licenses)
|
|
|
|
core_info[i].licenses_list =
|
|
|
|
string_split(core_info[i].licenses, "|");
|
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "categories",
|
2014-12-14 19:51:53 +00:00
|
|
|
&core_info[i].categories) &&
|
|
|
|
core_info[i].categories)
|
|
|
|
core_info[i].categories_list =
|
|
|
|
string_split(core_info[i].categories, "|");
|
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "database",
|
2015-01-25 07:21:02 +00:00
|
|
|
&core_info[i].databases) &&
|
|
|
|
core_info[i].databases)
|
|
|
|
core_info[i].databases_list =
|
|
|
|
string_split(core_info[i].databases, "|");
|
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
if (config_get_string(conf, "notes",
|
2014-09-02 03:10:54 +00:00
|
|
|
&core_info[i].notes) &&
|
2014-03-03 05:22:28 +00:00
|
|
|
core_info[i].notes)
|
2014-03-03 09:11:07 +00:00
|
|
|
core_info[i].note_list = string_split(core_info[i].notes, "|");
|
2014-09-09 23:49:51 +00:00
|
|
|
|
2015-12-06 19:44:21 +00:00
|
|
|
config_get_bool(conf, "supports_no_game",
|
2014-09-09 23:49:51 +00:00
|
|
|
&core_info[i].supports_no_game);
|
2015-12-06 19:44:21 +00:00
|
|
|
|
|
|
|
core_info[i].config_data = conf;
|
2013-06-24 01:18:23 +00:00
|
|
|
}
|
2013-06-26 00:57:19 +00:00
|
|
|
|
2016-02-07 17:27:27 +00:00
|
|
|
core_info[i].path = strdup(contents->elems[i].data);
|
|
|
|
|
2013-06-26 00:57:19 +00:00
|
|
|
if (!core_info[i].display_name)
|
2016-02-07 00:15:10 +00:00
|
|
|
core_info[i].display_name =
|
|
|
|
strdup(path_basename(core_info[i].path));
|
2013-06-24 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
2016-02-07 17:19:58 +00:00
|
|
|
for (i = 0; i < contents->size; i++)
|
|
|
|
{
|
|
|
|
config_file_t *conf = (config_file_t*)
|
|
|
|
core_info_list->list[i].config_data;
|
|
|
|
core_info_list->count += !!conf;
|
|
|
|
}
|
|
|
|
|
2013-11-21 22:48:31 +00:00
|
|
|
core_info_list_resolve_all_extensions(core_info_list);
|
|
|
|
core_info_list_resolve_all_firmware(core_info_list);
|
2013-10-05 15:07:56 +00:00
|
|
|
|
2013-06-26 00:57:19 +00:00
|
|
|
dir_list_free(contents);
|
2013-06-24 01:18:23 +00:00
|
|
|
return core_info_list;
|
2013-10-05 11:37:38 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
if (contents)
|
|
|
|
dir_list_free(contents);
|
2013-10-05 11:48:08 +00:00
|
|
|
core_info_list_free(core_info_list);
|
2013-10-05 11:37:38 +00:00
|
|
|
return NULL;
|
2013-06-24 01:18:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
bool core_info_list_get_display_name(core_info_list_t *core_info_list,
|
2016-02-07 11:55:21 +00:00
|
|
|
const char *path, char *s, size_t len)
|
2013-10-06 10:27:08 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
size_t i;
|
2015-01-09 14:33:58 +00:00
|
|
|
|
2014-06-01 00:29:19 +00:00
|
|
|
if (!core_info_list)
|
|
|
|
return false;
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < core_info_list->count; i++)
|
2013-10-06 10:27:08 +00:00
|
|
|
{
|
|
|
|
const core_info_t *info = &core_info_list->list[i];
|
2016-01-20 03:07:24 +00:00
|
|
|
if (string_is_equal(path_basename(info->path), path_basename(path))
|
2014-09-02 03:10:54 +00:00
|
|
|
&& info->display_name)
|
2013-10-06 10:27:08 +00:00
|
|
|
{
|
2016-02-07 11:55:21 +00:00
|
|
|
strlcpy(s, info->display_name, len);
|
2013-10-06 10:27:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-07-04 16:57:04 +00:00
|
|
|
bool core_info_get_display_name(const char *path, char *s, size_t len)
|
|
|
|
{
|
|
|
|
char *core_name = NULL;
|
2015-07-12 08:18:24 +00:00
|
|
|
char *display_name = NULL;
|
2015-07-04 16:57:04 +00:00
|
|
|
config_file_t *conf = NULL;
|
|
|
|
|
|
|
|
if (!path_file_exists(path))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
conf = config_file_new(path);
|
|
|
|
|
|
|
|
if (!conf)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
config_get_string(conf, "corename",
|
|
|
|
&core_name);
|
|
|
|
|
2015-07-12 08:18:24 +00:00
|
|
|
config_get_string(conf, "display_name",
|
|
|
|
&display_name);
|
2015-07-12 08:15:42 +00:00
|
|
|
|
2015-07-04 16:57:04 +00:00
|
|
|
config_file_free(conf);
|
|
|
|
|
|
|
|
if (!core_name)
|
|
|
|
goto error;
|
|
|
|
if (!conf)
|
2015-07-09 18:16:30 +00:00
|
|
|
goto error;
|
2015-07-04 16:57:04 +00:00
|
|
|
|
2015-07-12 08:22:11 +00:00
|
|
|
snprintf(s, len,"%s",display_name);
|
2015-07-04 16:57:04 +00:00
|
|
|
|
2015-07-09 18:16:30 +00:00
|
|
|
free(core_name);
|
2015-07-12 19:14:41 +00:00
|
|
|
free(display_name);
|
2015-07-09 18:16:30 +00:00
|
|
|
|
2015-07-04 16:57:04 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
2015-07-09 18:16:30 +00:00
|
|
|
if (core_name)
|
|
|
|
free(core_name);
|
2015-07-04 16:57:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-07 16:34:22 +00:00
|
|
|
/* Shallow-copies internal state.
|
|
|
|
*
|
|
|
|
* 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)
|
2014-03-02 13:07:07 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2014-03-02 13:07:07 +00:00
|
|
|
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-02-07 00:15:10 +00:00
|
|
|
if (string_is_equal(path_basename(info->path),
|
|
|
|
path_basename(path)))
|
2014-03-02 13:07:07 +00:00
|
|
|
{
|
|
|
|
*out_info = *info;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-07 11:59:50 +00:00
|
|
|
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)
|
2013-10-05 16:33:22 +00:00
|
|
|
{
|
2013-10-22 13:08:17 +00:00
|
|
|
size_t i;
|
2013-10-05 16:33:22 +00:00
|
|
|
if (!list || !core || !core->supported_extensions_list)
|
|
|
|
return false;
|
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
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)))
|
2013-10-05 16:33:22 +00:00
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-07 11:53:45 +00:00
|
|
|
static bool core_info_does_support_file(
|
|
|
|
const core_info_t *core, const char *path)
|
2013-06-26 00:57:19 +00:00
|
|
|
{
|
2013-06-26 01:04:16 +00:00
|
|
|
if (!path || !core || !core->supported_extensions_list)
|
2013-06-26 00:57:19 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-12-12 19:25:57 +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-02-07 00:15:10 +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);
|
|
|
|
int support_b =
|
|
|
|
core_info_does_support_any_file(b, core_info_tmp_list)
|
|
|
|
|| core_info_does_support_file(b, core_info_tmp_path);
|
2014-12-12 19:25:57 +00:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
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)
|
2013-10-05 15:07:56 +00:00
|
|
|
{
|
2016-02-07 16:35:52 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2015-01-09 14:33:58 +00:00
|
|
|
struct string_list *list = NULL;
|
2016-02-07 16:35:52 +00:00
|
|
|
#endif
|
2015-01-09 14:33:58 +00:00
|
|
|
size_t supported = 0, i;
|
|
|
|
|
2014-06-01 00:29:19 +00:00
|
|
|
if (!core_info_list)
|
|
|
|
return;
|
|
|
|
|
2013-10-05 15:07:56 +00:00
|
|
|
core_info_tmp_path = path;
|
2013-10-05 16:33:22 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB
|
2016-01-20 16:34:19 +00:00
|
|
|
if (string_is_equal_noncase(path_get_extension(path), "zip"))
|
2016-01-24 06:42:46 +00:00
|
|
|
list = file_archive_get_file_list(path, NULL);
|
2013-10-05 16:33:22 +00:00
|
|
|
core_info_tmp_list = list;
|
|
|
|
#endif
|
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
/* Let supported core come first in list so we can return
|
|
|
|
* a pointer to them. */
|
|
|
|
qsort(core_info_list->list, core_info_list->count,
|
|
|
|
sizeof(core_info_t), core_info_qsort_cmp);
|
2013-10-05 15:07:56 +00:00
|
|
|
|
2013-10-22 13:08:17 +00:00
|
|
|
for (i = 0; i < core_info_list->count; i++, supported++)
|
2013-10-05 15:07:56 +00:00
|
|
|
{
|
2013-10-05 16:33:22 +00:00
|
|
|
const core_info_t *core = &core_info_list->list[i];
|
2015-01-09 14:33:58 +00:00
|
|
|
|
|
|
|
if (!core)
|
|
|
|
continue;
|
|
|
|
|
2015-01-12 03:19:57 +00:00
|
|
|
if (core_info_does_support_file(core, path))
|
|
|
|
continue;
|
|
|
|
|
2013-10-08 20:45:08 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2015-01-12 03:19:57 +00:00
|
|
|
if (core_info_does_support_any_file(core, list))
|
|
|
|
continue;
|
2013-10-08 20:45:08 +00:00
|
|
|
#endif
|
2015-01-12 03:19:57 +00:00
|
|
|
|
|
|
|
break;
|
2013-10-05 15:07:56 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 16:33:22 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
if (list)
|
|
|
|
string_list_free(list);
|
|
|
|
#endif
|
|
|
|
|
2016-02-07 16:35:52 +00:00
|
|
|
*infos = core_info_list->list;
|
2013-10-05 15:07:56 +00:00
|
|
|
*num_infos = supported;
|
|
|
|
}
|
|
|
|
|
2016-02-07 16:39:10 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-02-07 01:53:00 +00:00
|
|
|
static core_info_t *core_info_find(core_info_list_t *list,
|
2014-09-02 03:10:54 +00:00
|
|
|
const char *core)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
2013-11-22 16:43:49 +00:00
|
|
|
size_t i;
|
2014-06-01 00:29:19 +00:00
|
|
|
|
2013-11-22 16:43:49 +00:00
|
|
|
for (i = 0; i < list->count; i++)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
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-02-07 16:39:10 +00:00
|
|
|
if (!info)
|
2015-01-11 06:37:02 +00:00
|
|
|
continue;
|
2016-01-20 03:07:24 +00:00
|
|
|
if (string_is_equal(info->path, core))
|
2013-11-21 22:48:31 +00:00
|
|
|
return info;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-07 15:19:02 +00:00
|
|
|
static bool core_info_list_update_missing_firmware(
|
2016-02-07 00:15:10 +00:00
|
|
|
core_info_list_t *core_info_list,
|
2014-03-03 06:02:29 +00:00
|
|
|
const char *core, const char *systemdir)
|
|
|
|
{
|
|
|
|
size_t i;
|
2015-06-13 01:06:11 +00:00
|
|
|
char path[PATH_MAX_LENGTH] = {0};
|
|
|
|
core_info_t *info = NULL;
|
2014-08-02 12:01:35 +00:00
|
|
|
|
|
|
|
if (!core_info_list || !core)
|
2016-02-07 15:19:02 +00:00
|
|
|
return false;
|
2014-03-03 06:02:29 +00:00
|
|
|
|
2015-10-31 16:44:42 +00:00
|
|
|
if (!(info = core_info_find(core_info_list, core)))
|
2016-02-07 15:19:02 +00:00
|
|
|
return false;
|
2014-03-03 06:02:29 +00:00
|
|
|
|
|
|
|
for (i = 0; i < info->firmware_count; i++)
|
|
|
|
{
|
2015-01-11 06:37:02 +00:00
|
|
|
if (!info->firmware[i].path)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fill_pathname_join(path, systemdir,
|
|
|
|
info->firmware[i].path, sizeof(path));
|
|
|
|
info->firmware[i].missing = !path_file_exists(path);
|
2014-03-03 06:02:29 +00:00
|
|
|
}
|
2016-02-07 15:19:02 +00:00
|
|
|
|
|
|
|
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(
|
2016-02-07 00:15:10 +00:00
|
|
|
core_info_list_t *core_info_list,
|
2013-11-21 22:48:31 +00:00
|
|
|
const char *core, const char *systemdir,
|
|
|
|
const core_info_firmware_t **firmware, size_t *num_firmware)
|
|
|
|
{
|
2013-11-22 16:43:49 +00:00
|
|
|
size_t i;
|
2015-06-13 01:06:11 +00:00
|
|
|
char path[PATH_MAX_LENGTH] = {0};
|
|
|
|
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;
|
2013-11-22 16:43:49 +00:00
|
|
|
|
2015-11-20 07:42:33 +00:00
|
|
|
*firmware = NULL;
|
2013-11-21 22:48:31 +00:00
|
|
|
*num_firmware = 0;
|
|
|
|
|
2015-10-31 16:44:42 +00:00
|
|
|
if (!(info = core_info_find(core_info_list, core)))
|
2013-11-21 22:48:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
*firmware = info->firmware;
|
|
|
|
|
2014-03-03 06:57:18 +00:00
|
|
|
for (i = 1; i < info->firmware_count; i++)
|
2013-11-21 22:48:31 +00:00
|
|
|
{
|
2016-02-07 00:15:10 +00:00
|
|
|
fill_pathname_join(path, systemdir,
|
|
|
|
info->firmware[i].path, sizeof(path));
|
2013-11-21 22:48:31 +00:00
|
|
|
info->firmware[i].missing = !path_file_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);
|
2013-11-21 22:48:31 +00:00
|
|
|
}
|
2016-02-07 11:51:45 +00:00
|
|
|
#endif
|
2016-02-07 01:18:26 +00:00
|
|
|
|
|
|
|
bool core_info_ctl(enum core_info_state state, void *data)
|
|
|
|
{
|
2016-02-07 01:37:57 +00:00
|
|
|
static core_info_t *core_info_current = NULL;
|
2016-02-07 01:24:08 +00:00
|
|
|
static core_info_list_t *core_info_curr_list = NULL;
|
|
|
|
|
2016-02-07 01:18:26 +00:00
|
|
|
switch (state)
|
|
|
|
{
|
2016-02-07 01:37:57 +00:00
|
|
|
case CORE_INFO_CTL_CURRENT_CORE_FREE:
|
|
|
|
if (core_info_current)
|
|
|
|
free(core_info_current);
|
|
|
|
core_info_current = NULL;
|
2016-02-07 01:50:16 +00:00
|
|
|
break;
|
2016-02-07 01:37:57 +00:00
|
|
|
case CORE_INFO_CTL_CURRENT_CORE_INIT:
|
|
|
|
core_info_current = (core_info_t*)calloc(1, sizeof(core_info_t));
|
|
|
|
if (!core_info_current)
|
|
|
|
return false;
|
2016-02-07 01:50:16 +00:00
|
|
|
break;
|
2016-02-07 01:37:57 +00:00
|
|
|
case CORE_INFO_CTL_CURRENT_CORE_GET:
|
|
|
|
{
|
|
|
|
core_info_t **core = (core_info_t**)data;
|
|
|
|
if (!core)
|
|
|
|
return false;
|
|
|
|
*core = core_info_current;
|
|
|
|
}
|
2016-02-07 01:50:16 +00:00
|
|
|
break;
|
2016-02-07 01:24:08 +00:00
|
|
|
case CORE_INFO_CTL_LIST_DEINIT:
|
|
|
|
if (core_info_curr_list)
|
|
|
|
core_info_list_free(core_info_curr_list);
|
|
|
|
core_info_curr_list = NULL;
|
2016-02-07 01:50:16 +00:00
|
|
|
break;
|
2016-02-07 01:24:08 +00:00
|
|
|
case CORE_INFO_CTL_LIST_INIT:
|
|
|
|
core_info_curr_list = core_info_list_new();
|
2016-02-07 01:50:16 +00:00
|
|
|
break;
|
2016-02-07 01:24:08 +00:00
|
|
|
case CORE_INFO_CTL_LIST_GET:
|
|
|
|
{
|
|
|
|
core_info_list_t **core = (core_info_list_t**)data;
|
|
|
|
if (!core)
|
|
|
|
return false;
|
|
|
|
*core = core_info_curr_list;
|
|
|
|
}
|
2016-02-07 01:50:16 +00:00
|
|
|
break;
|
2016-02-07 15:19:02 +00:00
|
|
|
case CORE_INFO_CTL_LIST_UPDATE_MISSING_FIRMWARE:
|
|
|
|
{
|
|
|
|
core_info_ctx_firmware_t *info = (core_info_ctx_firmware_t*)data;
|
|
|
|
if (!info)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return core_info_list_update_missing_firmware(core_info_curr_list,
|
|
|
|
info->path, info->system_directory);
|
|
|
|
}
|
|
|
|
break;
|
2016-02-07 01:50:16 +00:00
|
|
|
case CORE_INFO_CTL_FIND:
|
|
|
|
{
|
|
|
|
core_info_ctx_find_t *info = (core_info_ctx_find_t*)data;
|
2016-02-07 01:53:00 +00:00
|
|
|
if (!info || !core_info_curr_list)
|
2016-02-07 01:50:16 +00:00
|
|
|
return false;
|
2016-02-07 16:40:42 +00:00
|
|
|
info->inf = core_info_find(core_info_curr_list, info->path);
|
|
|
|
if (!info->inf)
|
2016-02-07 01:50:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-07 16:26:10 +00:00
|
|
|
case CORE_INFO_CTL_LOAD:
|
|
|
|
{
|
|
|
|
core_info_t *core_info = NULL;
|
|
|
|
core_info_ctx_find_t *info = (core_info_ctx_find_t*)data;
|
|
|
|
|
|
|
|
if (!info)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
core_info_ctl(CORE_INFO_CTL_CURRENT_CORE_GET, &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;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-07 01:18:26 +00:00
|
|
|
case CORE_INFO_CTL_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|