From 3fd40c03bf618f30994c8962afd3e61c33b24807 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 3 Feb 2020 07:37:05 +0100 Subject: [PATCH] (tasks/task_core_updater.c) get Rid of some settings dependencies --- menu/cbs/menu_cbs_ok.c | 8 +++-- tasks/task_core_updater.c | 74 +++++++++++++++++++++++---------------- tasks/tasks_internal.h | 5 +-- 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 3ef3ad1e85..aaa3f93311 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -4340,12 +4340,14 @@ static int action_ok_core_updater_download(const char *path, { #ifdef HAVE_NETWORKING core_updater_list_t *core_list = core_updater_list_get_cached(); + settings_t *settings = config_get_ptr(); if (!core_list) return menu_cbs_exit(); task_push_core_updater_download( - core_list, path, false, true); + core_list, path, false, true, + settings->paths.directory_libretro); #endif return 0; @@ -4355,11 +4357,13 @@ static int action_ok_core_updater_download(const char *path, static int action_ok_update_installed_cores(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { + settings_t *settings = config_get_ptr(); + /* Ensure networking is initialised */ generic_action_ok_command(CMD_EVENT_NETWORK_INIT); /* Push update task */ - task_push_update_installed_cores(); + task_push_update_installed_cores(settings->paths.directory_libretro); return 0; } diff --git a/tasks/task_core_updater.c b/tasks/task_core_updater.c index af84836c4a..b1e6b429a3 100644 --- a/tasks/task_core_updater.c +++ b/tasks/task_core_updater.c @@ -72,6 +72,7 @@ enum core_updater_download_status typedef struct core_updater_download_handle { + char *path_dir_libretro; char *remote_filename; char *remote_core_path; char *local_download_path; @@ -102,6 +103,7 @@ enum update_installed_cores_status typedef struct update_installed_cores_handle { + char *path_dir_libretro; core_updater_list_t* core_list; retro_task_t *list_task; retro_task_t *download_task; @@ -178,7 +180,8 @@ finish: free(transf); } -static void free_core_updater_list_handle(core_updater_list_handle_t *list_handle) +static void free_core_updater_list_handle( + core_updater_list_handle_t *list_handle) { if (!list_handle) return; @@ -560,6 +563,9 @@ static void free_core_updater_download_handle(core_updater_download_handle_t *do if (!download_handle) return; + if (download_handle->path_dir_libretro) + free(download_handle->path_dir_libretro); + if (download_handle->remote_filename) free(download_handle->remote_filename); @@ -780,12 +786,13 @@ static bool task_core_updater_download_finder(retro_task_t *task, void *user_dat } void *task_push_core_updater_download( - core_updater_list_t* core_list, const char *filename, bool mute, bool check_crc) + core_updater_list_t* core_list, + const char *filename, bool mute, bool check_crc, + const char *path_dir_libretro) { task_finder_data_t find_data; char task_title[PATH_MAX_LENGTH]; char local_download_path[PATH_MAX_LENGTH]; - settings_t *settings = config_get_ptr(); const core_updater_list_entry_t *list_entry = NULL; retro_task_t *task = NULL; core_updater_download_handle_t *download_handle = (core_updater_download_handle_t*) @@ -797,7 +804,6 @@ void *task_push_core_updater_download( /* Sanity check */ if (!core_list || string_is_empty(filename) || - !settings || !download_handle) goto error; @@ -816,16 +822,17 @@ void *task_push_core_updater_download( goto error; /* Get local file download path */ - if (string_is_empty(settings->paths.directory_libretro)) + if (string_is_empty(path_dir_libretro)) goto error; fill_pathname_join( local_download_path, - settings->paths.directory_libretro, + path_dir_libretro, list_entry->remote_filename, sizeof(local_download_path)); /* Configure handle */ + download_handle->path_dir_libretro = strdup(path_dir_libretro); download_handle->remote_filename = strdup(list_entry->remote_filename); download_handle->remote_core_path = strdup(list_entry->remote_core_path); download_handle->local_download_path = strdup(local_download_path); @@ -892,11 +899,15 @@ error: /* Update installed cores */ /**************************/ -static void free_update_installed_cores_handle(update_installed_cores_handle_t *update_installed_handle) +static void free_update_installed_cores_handle( + update_installed_cores_handle_t *update_installed_handle) { if (!update_installed_handle) return; + if (update_installed_handle->path_dir_libretro) + free(update_installed_handle->path_dir_libretro); + core_updater_list_free(update_installed_handle->core_list); free(update_installed_handle); @@ -921,21 +932,19 @@ static void task_update_installed_cores_handler(retro_task_t *task) switch (update_installed_handle->status) { case UPDATE_INSTALLED_CORES_BEGIN: - { - /* Request buildbot core list */ - update_installed_handle->list_task = (retro_task_t*) - task_push_get_core_updater_list( - update_installed_handle->core_list, - true, false); + /* Request buildbot core list */ + update_installed_handle->list_task = (retro_task_t*) + task_push_get_core_updater_list( + update_installed_handle->core_list, + true, false); - /* If push failed, go to end - * (error will message will be displayed when - * final task title is set) */ - if (!update_installed_handle->list_task) - update_installed_handle->status = UPDATE_INSTALLED_CORES_END; - else - update_installed_handle->status = UPDATE_INSTALLED_CORES_WAIT_LIST; - } + /* If push failed, go to end + * (error will message will be displayed when + * final task title is set) */ + if (!update_installed_handle->list_task) + update_installed_handle->status = UPDATE_INSTALLED_CORES_END; + else + update_installed_handle->status = UPDATE_INSTALLED_CORES_WAIT_LIST; break; case UPDATE_INSTALLED_CORES_WAIT_LIST: { @@ -1058,7 +1067,8 @@ static void task_update_installed_cores_handler(retro_task_t *task) task_push_core_updater_download( update_installed_handle->core_list, list_entry->remote_filename, - true, false); + true, false, + update_installed_handle->path_dir_libretro); /* Again, if an error occurred, just return to * UPDATE_INSTALLED_CORES_ITERATE state */ @@ -1168,7 +1178,7 @@ static bool task_update_installed_cores_finder(retro_task_t *task, void *user_da return false; } -void task_push_update_installed_cores(void) +void task_push_update_installed_cores(const char *path_dir_libretro) { task_finder_data_t find_data; retro_task_t *task = NULL; @@ -1181,14 +1191,16 @@ void task_push_update_installed_cores(void) goto error; /* Configure handle */ - update_installed_handle->core_list = core_updater_list_init(CORE_UPDATER_LIST_SIZE); - update_installed_handle->list_task = NULL; - update_installed_handle->download_task = NULL; - update_installed_handle->list_size = 0; - update_installed_handle->list_index = 0; - update_installed_handle->installed_index = 0; - update_installed_handle->num_updated = 0; - update_installed_handle->status = UPDATE_INSTALLED_CORES_BEGIN; + update_installed_handle->core_list = core_updater_list_init( + CORE_UPDATER_LIST_SIZE); + update_installed_handle->list_task = NULL; + update_installed_handle->download_task = NULL; + update_installed_handle->list_size = 0; + update_installed_handle->list_index = 0; + update_installed_handle->installed_index = 0; + update_installed_handle->num_updated = 0; + update_installed_handle->path_dir_libretro = strdup(path_dir_libretro); + update_installed_handle->status = UPDATE_INSTALLED_CORES_BEGIN; if (!update_installed_handle->core_list) goto error; diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index d7f4949cab..cd92d88d80 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -92,8 +92,9 @@ bool task_push_netplay_nat_traversal(void *nat_traversal_state, uint16_t port); void *task_push_get_core_updater_list( core_updater_list_t* core_list, bool mute, bool refresh_menu); void *task_push_core_updater_download( - core_updater_list_t* core_list, const char *filename, bool mute, bool check_crc); -void task_push_update_installed_cores(void); + core_updater_list_t* core_list, const char *filename, + bool mute, bool check_crc, const char *path_dir_libretro); +void task_push_update_installed_cores(const char *path_dir_libretro); #ifdef HAVE_MENU bool task_push_pl_thumbnail_download(const char *system, const char *playlist_path);