Start reducing dependency on settings struct

This commit is contained in:
twinaphex 2020-01-02 17:41:52 +01:00
parent 19406af87f
commit 05d71ebb67
7 changed files with 76 additions and 42 deletions

View File

@ -26,7 +26,6 @@
#include <net/net_http.h>
#include <retro_miscellaneous.h>
#include "configuration.h"
#include "file_path_special.h"
#include "core_info.h"
@ -400,14 +399,14 @@ static bool core_updater_list_set_crc(
* associated paths to the specified core
* updater list entry */
static bool core_updater_list_set_paths(
core_updater_list_entry_t *entry, const char *filename_str)
core_updater_list_entry_t *entry,
const char *path_dir_libretro,
const char *path_libretro_info,
const char *network_buildbot_url,
const char *filename_str)
{
settings_t *settings = config_get_ptr();
char *last_underscore = NULL;
char *tmp_url = NULL;
const char *path_dir_libretro = NULL;
const char *path_libretro_info = NULL;
const char *network_buildbot_url = NULL;
char remote_core_path[PATH_MAX_LENGTH];
char local_core_path[PATH_MAX_LENGTH];
char local_info_path[PATH_MAX_LENGTH];
@ -419,13 +418,9 @@ static bool core_updater_list_set_paths(
local_info_path[0] = '\0';
display_name[0] = '\0';
if (!entry || string_is_empty(filename_str) || !settings)
if (!entry || string_is_empty(filename_str))
return false;
path_dir_libretro = settings->paths.directory_libretro;
path_libretro_info = settings->paths.path_libretro_info;
network_buildbot_url = settings->paths.network_buildbot_url;
if (string_is_empty(path_dir_libretro) ||
string_is_empty(path_libretro_info) ||
string_is_empty(network_buildbot_url))
@ -600,6 +595,9 @@ static bool core_updater_list_push_entry(
* core updater list */
static void core_updater_list_add_entry(
core_updater_list_t *core_list,
const char *path_dir_libretro,
const char *path_libretro_info,
const char *network_buildbot_url,
struct string_list *network_core_entry_list)
{
const char *date_str = NULL;
@ -638,7 +636,12 @@ static void core_updater_list_add_entry(
if (!core_updater_list_set_crc(&entry, crc_str))
goto error;
if (!core_updater_list_set_paths(&entry, filename_str))
if (!core_updater_list_set_paths(
&entry,
path_dir_libretro,
path_libretro_info,
network_buildbot_url,
filename_str))
goto error;
/* Add entry to list */
@ -700,7 +703,11 @@ static void core_updater_list_qsort(core_updater_list_t *core_list)
* core_updater_list_t object.
* Returns false in the event of an error. */
bool core_updater_list_parse_network_data(
core_updater_list_t *core_list, const char *data, size_t len)
core_updater_list_t *core_list,
const char *path_dir_libretro,
const char *path_libretro_info,
const char *network_buildbot_url,
const char *data, size_t len)
{
struct string_list *network_core_list = NULL;
struct string_list *network_core_entry_list = NULL;
@ -752,7 +759,11 @@ bool core_updater_list_parse_network_data(
/* Parse listings info and add to core updater
* list */
core_updater_list_add_entry(
core_list, network_core_entry_list);
core_list,
path_dir_libretro,
path_libretro_info,
network_buildbot_url,
network_core_entry_list);
/* Clean up */
string_list_free(network_core_entry_list);

View File

@ -136,7 +136,11 @@ bool core_updater_list_get_core(
* core_updater_list_t object.
* Returns false in the event of an error. */
bool core_updater_list_parse_network_data(
core_updater_list_t *core_list, const char *data, size_t len);
core_updater_list_t *core_list,
const char *path_dir_libretro,
const char *path_libretro_info,
const char *network_buildbot_url,
const char *data, size_t len);
RETRO_END_DECLS

View File

@ -3168,7 +3168,10 @@ static unsigned menu_displaylist_parse_content_information(
!settings->bools.content_runtime_log_aggregate))
{
runtime_log_t *runtime_log = runtime_log_init(
content_path, core_path,
content_path,
core_path,
settings->paths.directory_runtime_log,
settings->paths.directory_playlist,
(settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE));
if (runtime_log)

View File

@ -5603,9 +5603,15 @@ static bool event_init_content(void)
static void update_runtime_log(bool log_per_core)
{
settings_t *settings = config_get_ptr();
/* Initialise runtime log file */
runtime_log_t *runtime_log = runtime_log_init(
runtime_content_path, runtime_core_path, log_per_core);
runtime_content_path,
runtime_core_path,
settings->paths.directory_runtime_log,
settings->paths.directory_playlist,
log_per_core);
if (!runtime_log)
return;

View File

@ -264,8 +264,12 @@ end:
/* Initialise runtime log, loading current parameters
* if log file exists. Returned object must be free()'d.
* Returns NULL if content_path and/or core_path are invalid */
runtime_log_t *runtime_log_init(const char *content_path,
const char *core_path, bool log_per_core)
runtime_log_t *runtime_log_init(
const char *content_path,
const char *core_path,
const char *dir_runtime_log,
const char *dir_playlist,
bool log_per_core)
{
unsigned i;
char content_name[PATH_MAX_LENGTH];
@ -273,7 +277,6 @@ runtime_log_t *runtime_log_init(const char *content_path,
char log_file_dir[PATH_MAX_LENGTH];
char log_file_path[PATH_MAX_LENGTH];
char tmp_buf[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
core_info_list_t *core_info = NULL;
runtime_log_t *runtime_log = NULL;
const char *core_path_basename = NULL;
@ -284,12 +287,8 @@ runtime_log_t *runtime_log_init(const char *content_path,
log_file_path[0] = '\0';
tmp_buf[0] = '\0';
/* Error checking */
if (!settings)
return NULL;
if ( string_is_empty(settings->paths.directory_runtime_log) &&
string_is_empty(settings->paths.directory_playlist))
if ( string_is_empty(dir_runtime_log) &&
string_is_empty(dir_playlist))
{
RARCH_ERR("Runtime log directory is undefined - cannot save"
" runtime log files.\n");
@ -334,19 +333,18 @@ runtime_log_t *runtime_log_init(const char *content_path,
return NULL;
/* Get runtime log directory */
if (string_is_empty(settings->paths.directory_runtime_log))
if (string_is_empty(dir_runtime_log))
{
/* If 'custom' runtime log path is undefined,
* use default 'playlists/logs' directory... */
fill_pathname_join(
tmp_buf,
settings->paths.directory_playlist,
dir_playlist,
"logs",
sizeof(tmp_buf));
}
else
strlcpy(tmp_buf,
settings->paths.directory_runtime_log, sizeof(tmp_buf));
strlcpy(tmp_buf, dir_runtime_log, sizeof(tmp_buf));
if (string_is_empty(tmp_buf))
return NULL;
@ -694,15 +692,11 @@ static void last_played_strftime(runtime_log_t *runtime_log, char *str, size_t l
void runtime_log_get_last_played_str(runtime_log_t *runtime_log,
char *str, size_t len, enum playlist_sublabel_last_played_style_type timedate_style)
{
settings_t *settings = config_get_ptr();
int n = 0;
char tmp[64];
tmp[0] = '\0';
if (!settings)
return;
if (runtime_log)
{
/* Handle 12-hour clock options
@ -949,13 +943,14 @@ void runtime_log_convert_usec2hms(retro_time_t usec,
* contents of associated log file */
void runtime_update_playlist(playlist_t *playlist, size_t idx)
{
char runtime_str[64];
char last_played_str[64];
enum playlist_sublabel_last_played_style_type
timedate_style = PLAYLIST_LAST_PLAYED_STYLE_YMD_HMS;
settings_t *settings = config_get_ptr();
runtime_log_t *runtime_log = NULL;
const struct playlist_entry *entry = NULL;
struct playlist_entry update_entry = {0};
enum playlist_sublabel_last_played_style_type timedate_style;
char runtime_str[64];
char last_played_str[64];
/* Sanity check */
if (!playlist || !settings)
@ -971,9 +966,8 @@ void runtime_update_playlist(playlist_t *playlist, size_t idx)
/* Get current last played formatting type
* > Have to include a 'HAVE_MENU' check here... */
#ifdef HAVE_MENU
timedate_style = (enum playlist_sublabel_last_played_style_type)settings->uints.playlist_sublabel_last_played_style;
#else
timedate_style = PLAYLIST_LAST_PLAYED_STYLE_YMD_HMS;
timedate_style = (enum playlist_sublabel_last_played_style_type)
settings->uints.playlist_sublabel_last_played_style;
#endif
/* 'Attach' runtime/last played strings */
@ -986,7 +980,11 @@ void runtime_update_playlist(playlist_t *playlist, size_t idx)
playlist_get_index(playlist, idx, &entry);
/* Attempt to open log file */
runtime_log = runtime_log_init(entry->path, entry->core_path,
runtime_log = runtime_log_init(
entry->path,
entry->core_path,
settings->paths.directory_runtime_log,
settings->paths.directory_playlist,
(settings->uints.playlist_sublabel_runtime_type == PLAYLIST_RUNTIME_PER_CORE));
if (runtime_log)
@ -1015,6 +1013,7 @@ void runtime_update_playlist(playlist_t *playlist, size_t idx)
free(runtime_log);
}
#ifdef HAVE_MENU
/* Ozone requires runtime/last played strings to be
* populated even when no runtime is recorded */
if (string_is_equal(settings->arrays.menu_driver, "ozone"))
@ -1025,6 +1024,7 @@ void runtime_update_playlist(playlist_t *playlist, size_t idx)
runtime_log_get_last_played_str(NULL, last_played_str, sizeof(last_played_str), timedate_style);
}
}
#endif
/* Update playlist */
playlist_update_runtime(playlist, idx, &update_entry, false);

View File

@ -63,7 +63,12 @@ typedef struct
/* Initialise runtime log, loading current parameters
* if log file exists. Returned object must be free()'d.
* Returns NULL if content_path and/or core_path are invalid */
runtime_log_t *runtime_log_init(const char *content_path, const char *core_path, bool log_per_core);
runtime_log_t *runtime_log_init(
const char *content_path,
const char *core_path,
const char *dir_runtime_log,
const char *dir_playlist,
bool log_per_core);
/* Setters */

View File

@ -295,10 +295,15 @@ static void task_core_updater_get_list_handler(retro_task_t *task)
break;
case CORE_UPDATER_LIST_END:
{
settings_t *settings = config_get_ptr();
/* Parse HTTP transfer data */
if (list_handle->http_data)
core_updater_list_parse_network_data(
list_handle->core_list,
settings->paths.directory_libretro,
settings->paths.path_libretro_info,
settings->paths.network_buildbot_url,
list_handle->http_data->data,
list_handle->http_data->len);