Skip to content

Commit

Permalink
Merge pull request #10716 from jdgleaver/core-updater-improvements
Browse files Browse the repository at this point in the history
Core updater improvements
  • Loading branch information
inactive123 authored May 27, 2020
2 parents 02bc3ee + 9f4a9e9 commit 2b10350
Show file tree
Hide file tree
Showing 18 changed files with 531 additions and 122 deletions.
7 changes: 5 additions & 2 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,13 @@ static const bool stdin_cmd_enable = false;

static const uint16_t network_remote_base_port = 55400;

#define DEFAULT_NETWORK_BUILDBOT_AUTO_EXTRACT_ARCHIVE true
#define DEFAULT_NETWORK_BUILDBOT_SHOW_EXPERIMENTAL_CORES false

#if defined(ANDROID) || defined(IOS)
static const bool network_on_demand_thumbnails = true;
#define DEFAULT_NETWORK_ON_DEMAND_THUMBNAILS true
#else
static const bool network_on_demand_thumbnails = false;
#define DEFAULT_NETWORK_ON_DEMAND_THUMBNAILS false
#endif

/* Number of entries that will be kept in content history playlist file. */
Expand Down
5 changes: 3 additions & 2 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
SETTING_BOOL("netplay_request_device_p14", &settings->bools.netplay_request_devices[13], true, false, false);
SETTING_BOOL("netplay_request_device_p15", &settings->bools.netplay_request_devices[14], true, false, false);
SETTING_BOOL("netplay_request_device_p16", &settings->bools.netplay_request_devices[15], true, false, false);
SETTING_BOOL("network_on_demand_thumbnails", &settings->bools.network_on_demand_thumbnails, true, network_on_demand_thumbnails, false);
SETTING_BOOL("network_on_demand_thumbnails", &settings->bools.network_on_demand_thumbnails, true, DEFAULT_NETWORK_ON_DEMAND_THUMBNAILS, false);
#endif
SETTING_BOOL("input_descriptor_label_show", &settings->bools.input_descriptor_label_show, true, input_descriptor_label_show, false);
SETTING_BOOL("input_descriptor_hide_unbound", &settings->bools.input_descriptor_hide_unbound, true, input_descriptor_hide_unbound, false);
Expand Down Expand Up @@ -1435,7 +1435,8 @@ static struct config_bool_setting *populate_settings_bool(settings_t *settings,
SETTING_BOOL("audio_fastforward_mute", &settings->bools.audio_fastforward_mute, true, DEFAULT_AUDIO_FASTFORWARD_MUTE, false);
SETTING_BOOL("location_allow", &settings->bools.location_allow, true, false, false);
SETTING_BOOL("video_font_enable", &settings->bools.video_font_enable, true, DEFAULT_FONT_ENABLE, false);
SETTING_BOOL("core_updater_auto_extract_archive", &settings->bools.network_buildbot_auto_extract_archive, true, true, false);
SETTING_BOOL("core_updater_auto_extract_archive", &settings->bools.network_buildbot_auto_extract_archive, true, DEFAULT_NETWORK_BUILDBOT_AUTO_EXTRACT_ARCHIVE, false);
SETTING_BOOL("core_updater_show_experimental_cores", &settings->bools.network_buildbot_show_experimental_cores, true, DEFAULT_NETWORK_BUILDBOT_SHOW_EXPERIMENTAL_CORES, false);
SETTING_BOOL("camera_allow", &settings->bools.camera_allow, true, false, false);
SETTING_BOOL("discord_allow", &settings->bools.discord_enable, true, false, false);
#if defined(VITA)
Expand Down
1 change: 1 addition & 0 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ typedef struct settings

/* Network */
bool network_buildbot_auto_extract_archive;
bool network_buildbot_show_experimental_cores;
bool network_on_demand_thumbnails;

/* UI */
Expand Down
107 changes: 107 additions & 0 deletions core_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ static void core_info_list_free(core_info_list_t *core_info_list)
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);
Expand Down Expand Up @@ -471,6 +472,14 @@ static core_info_list_t *core_info_list_new(const char *path,
tmp = NULL;
}

if (config_get_string(conf, "description", &tmp))
{
if (!string_is_empty(tmp))
core_info[i].description = strdup(tmp);
free(tmp);
tmp = NULL;
}

if (tmp)
free(tmp);
tmp = NULL;
Expand All @@ -484,6 +493,10 @@ static core_info_list_t *core_info_list_new(const char *path,
if (config_get_bool(conf, "database_match_archive_member",
&tmp_bool))
core_info[i].database_match_archive_member = tmp_bool;

if (config_get_bool(conf, "is_experimental",
&tmp_bool))
core_info[i].is_experimental = tmp_bool;
}

core_info[i].config_data = conf;
Expand Down Expand Up @@ -1003,6 +1016,100 @@ bool core_info_get_display_name(const char *path, char *s, size_t len)
return true;
}

/* 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 *path)
{
char *tmp_str = NULL;
bool tmp_bool = false;
core_updater_info_t *info = NULL;
config_file_t *conf = NULL;

if (string_is_empty(path))
return NULL;

/* Read config file */
conf = config_file_new_from_path_to_string(path);

if (!conf)
return NULL;

/* Create info struct */
info = (core_updater_info_t*)calloc(1, sizeof(*info));

if (!info)
return NULL;

/* Fetch required parameters */

/* > is_experimental */
info->is_experimental = false;
if (config_get_bool(conf, "is_experimental", &tmp_bool))
info->is_experimental = tmp_bool;

/* > display_name */
info->display_name = NULL;
if (config_get_string(conf, "display_name", &tmp_str))
{
if (!string_is_empty(tmp_str))
info->display_name = tmp_str;
else
free(tmp_str);

tmp_str = NULL;
}

/* > description */
info->description = NULL;
if (config_get_string(conf, "description", &tmp_str))
{
if (!string_is_empty(tmp_str))
info->description = tmp_str;
else
free(tmp_str);

tmp_str = NULL;
}

/* > licenses */
info->licenses = NULL;
if (config_get_string(conf, "license", &tmp_str))
{
if (!string_is_empty(tmp_str))
info->licenses = tmp_str;
else
free(tmp_str);

tmp_str = NULL;
}

/* 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)
{
Expand Down
20 changes: 20 additions & 0 deletions core_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct
{
bool supports_no_game;
bool database_match_archive_member;
bool is_experimental;
size_t firmware_count;
char *path;
void *config_data;
Expand All @@ -56,6 +57,7 @@ typedef struct
char *databases;
char *notes;
char *required_hw_api;
char *description;
struct string_list *categories_list;
struct string_list *databases_list;
struct string_list *note_list;
Expand All @@ -68,6 +70,16 @@ typedef struct
void *userdata;
} core_info_t;

/* A subset of core_info parameters required for
* core updater tasks */
typedef struct
{
bool is_experimental;
char *display_name;
char *description;
char *licenses;
} core_updater_info_t;

typedef struct
{
core_info_t *list;
Expand Down Expand Up @@ -109,6 +121,14 @@ bool core_info_list_get_display_name(core_info_list_t *list,

bool core_info_get_display_name(const char *path, char *s, size_t len);

/* 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 *path);
void core_info_free_core_updater_info(core_updater_info_t *info);

void core_info_get_name(const char *path, char *s, size_t len,
const char *path_info, const char *dir_cores,
const char *exts, bool show_hidden_files,
Expand Down
120 changes: 103 additions & 17 deletions core_updater_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ static void core_updater_list_free_entry(core_updater_list_entry_t *entry)
free(entry->display_name);
entry->display_name = NULL;
}

if (entry->description)
{
free(entry->description);
entry->description = NULL;
}

if (entry->licenses_list)
{
string_list_free(entry->licenses_list);
entry->licenses_list = NULL;
}
}

/* Creates a new, empty core updater list.
Expand Down Expand Up @@ -410,13 +422,11 @@ static bool core_updater_list_set_paths(
char remote_core_path[PATH_MAX_LENGTH];
char local_core_path[PATH_MAX_LENGTH];
char local_info_path[PATH_MAX_LENGTH];
char display_name[255];
bool is_archive;

remote_core_path[0] = '\0';
local_core_path[0] = '\0';
local_info_path[0] = '\0';
display_name[0] = '\0';

if (!entry || string_is_empty(filename_str))
return false;
Expand Down Expand Up @@ -518,30 +528,95 @@ static bool core_updater_list_set_paths(

entry->local_info_path = strdup(local_info_path);

/* display_name
return true;
}

/* Reads info file associated with core and
* adds relevant information to updater list
* entry */
static bool core_updater_list_set_core_info(
core_updater_list_entry_t *entry,
const char *local_info_path,
const char *filename_str)
{
core_updater_info_t *core_info = NULL;

if (!entry ||
string_is_empty(local_info_path) ||
string_is_empty(filename_str))
return false;

/* Clear any existing core info */
if (entry->display_name)
{
free(entry->display_name);
entry->display_name = NULL;
}

if (entry->description)
{
free(entry->description);
entry->description = NULL;
}

if (entry->licenses_list)
{
/* Note: We can safely leave this as NULL if
* the core info file is invalid */
string_list_free(entry->licenses_list);
entry->licenses_list = NULL;
}

entry->is_experimental = false;

/* Read core info file
* > Note: It's a bit rubbish that we have to
* read the actual core info files here...
* Would be better to cache this globally
* (at present, we only cache info for
* *installed* cores...) */
if (path_is_valid(local_info_path))
if (!core_info_get_display_name(
local_info_path, display_name, sizeof(display_name)))
display_name[0] = '\0';
core_info = core_info_get_core_updater_info(local_info_path);

if (core_info)
{
/* display_name + is_experimental */
if (!string_is_empty(core_info->display_name))
{
entry->display_name = strdup(core_info->display_name);
entry->is_experimental = core_info->is_experimental;
}
else
{
/* If display name is blank, use core filename and
* assume core is experimental (i.e. all 'fit for consumption'
* cores must have a valid/complete core info file) */
entry->display_name = strdup(filename_str);
entry->is_experimental = true;
}

/* > If info file does not exist, just use
* core filename */
if (string_is_empty(display_name))
strlcpy(display_name, filename_str, sizeof(display_name));
/* description */
if (!string_is_empty(core_info->description))
entry->description = strdup(core_info->description);
else
entry->description = strdup("");

if (entry->display_name)
/* licenses_list */
if (!string_is_empty(core_info->licenses))
entry->licenses_list = string_split(core_info->licenses, "|");

/* Clean up */
core_info_free_core_updater_info(core_info);
}
else
{
free(entry->display_name);
entry->display_name = NULL;
/* If info file is missing, use core filename and
* assume core is experimental (i.e. all 'fit for consumption'
* cores must have a valid/complete core info file) */
entry->display_name = strdup(filename_str);
entry->is_experimental = true;
entry->description = strdup("");
}

entry->display_name = strdup(display_name);

return true;
}

Expand Down Expand Up @@ -576,10 +651,15 @@ static bool core_updater_list_push_entry(
list_entry->remote_core_path = entry->remote_core_path;
list_entry->local_core_path = entry->local_core_path;
list_entry->local_info_path = entry->local_info_path;

/* Assign core info */
list_entry->display_name = entry->display_name;
list_entry->description = entry->description;
list_entry->licenses_list = entry->licenses_list;
list_entry->is_experimental = entry->is_experimental;

/* Copy crc */
list_entry->crc = entry->crc;
list_entry->crc = entry->crc;

/* Copy date */
memcpy(&list_entry->date, &entry->date, sizeof(core_updater_list_date_t));
Expand Down Expand Up @@ -644,6 +724,12 @@ static void core_updater_list_add_entry(
filename_str))
goto error;

if (!core_updater_list_set_core_info(
&entry,
entry.local_info_path,
filename_str))
goto error;

/* Add entry to list */
if (!core_updater_list_push_entry(core_list, &entry))
goto error;
Expand Down
Loading

0 comments on commit 2b10350

Please sign in to comment.