(tasks/task_core_updater.c) get Rid of some settings dependencies

This commit is contained in:
twinaphex 2020-02-03 07:37:05 +01:00
parent e5b236898f
commit 3fd40c03bf
3 changed files with 52 additions and 35 deletions

View File

@ -4340,12 +4340,14 @@ static int action_ok_core_updater_download(const char *path,
{ {
#ifdef HAVE_NETWORKING #ifdef HAVE_NETWORKING
core_updater_list_t *core_list = core_updater_list_get_cached(); core_updater_list_t *core_list = core_updater_list_get_cached();
settings_t *settings = config_get_ptr();
if (!core_list) if (!core_list)
return menu_cbs_exit(); return menu_cbs_exit();
task_push_core_updater_download( task_push_core_updater_download(
core_list, path, false, true); core_list, path, false, true,
settings->paths.directory_libretro);
#endif #endif
return 0; 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, static int action_ok_update_installed_cores(const char *path,
const char *label, unsigned type, size_t idx, size_t entry_idx) const char *label, unsigned type, size_t idx, size_t entry_idx)
{ {
settings_t *settings = config_get_ptr();
/* Ensure networking is initialised */ /* Ensure networking is initialised */
generic_action_ok_command(CMD_EVENT_NETWORK_INIT); generic_action_ok_command(CMD_EVENT_NETWORK_INIT);
/* Push update task */ /* Push update task */
task_push_update_installed_cores(); task_push_update_installed_cores(settings->paths.directory_libretro);
return 0; return 0;
} }

View File

@ -72,6 +72,7 @@ enum core_updater_download_status
typedef struct core_updater_download_handle typedef struct core_updater_download_handle
{ {
char *path_dir_libretro;
char *remote_filename; char *remote_filename;
char *remote_core_path; char *remote_core_path;
char *local_download_path; char *local_download_path;
@ -102,6 +103,7 @@ enum update_installed_cores_status
typedef struct update_installed_cores_handle typedef struct update_installed_cores_handle
{ {
char *path_dir_libretro;
core_updater_list_t* core_list; core_updater_list_t* core_list;
retro_task_t *list_task; retro_task_t *list_task;
retro_task_t *download_task; retro_task_t *download_task;
@ -178,7 +180,8 @@ finish:
free(transf); 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) if (!list_handle)
return; return;
@ -560,6 +563,9 @@ static void free_core_updater_download_handle(core_updater_download_handle_t *do
if (!download_handle) if (!download_handle)
return; return;
if (download_handle->path_dir_libretro)
free(download_handle->path_dir_libretro);
if (download_handle->remote_filename) if (download_handle->remote_filename)
free(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( 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; task_finder_data_t find_data;
char task_title[PATH_MAX_LENGTH]; char task_title[PATH_MAX_LENGTH];
char local_download_path[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; const core_updater_list_entry_t *list_entry = NULL;
retro_task_t *task = NULL; retro_task_t *task = NULL;
core_updater_download_handle_t *download_handle = (core_updater_download_handle_t*) core_updater_download_handle_t *download_handle = (core_updater_download_handle_t*)
@ -797,7 +804,6 @@ void *task_push_core_updater_download(
/* Sanity check */ /* Sanity check */
if (!core_list || if (!core_list ||
string_is_empty(filename) || string_is_empty(filename) ||
!settings ||
!download_handle) !download_handle)
goto error; goto error;
@ -816,16 +822,17 @@ void *task_push_core_updater_download(
goto error; goto error;
/* Get local file download path */ /* Get local file download path */
if (string_is_empty(settings->paths.directory_libretro)) if (string_is_empty(path_dir_libretro))
goto error; goto error;
fill_pathname_join( fill_pathname_join(
local_download_path, local_download_path,
settings->paths.directory_libretro, path_dir_libretro,
list_entry->remote_filename, list_entry->remote_filename,
sizeof(local_download_path)); sizeof(local_download_path));
/* Configure handle */ /* Configure handle */
download_handle->path_dir_libretro = strdup(path_dir_libretro);
download_handle->remote_filename = strdup(list_entry->remote_filename); download_handle->remote_filename = strdup(list_entry->remote_filename);
download_handle->remote_core_path = strdup(list_entry->remote_core_path); download_handle->remote_core_path = strdup(list_entry->remote_core_path);
download_handle->local_download_path = strdup(local_download_path); download_handle->local_download_path = strdup(local_download_path);
@ -892,11 +899,15 @@ error:
/* Update installed cores */ /* 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) if (!update_installed_handle)
return; return;
if (update_installed_handle->path_dir_libretro)
free(update_installed_handle->path_dir_libretro);
core_updater_list_free(update_installed_handle->core_list); core_updater_list_free(update_installed_handle->core_list);
free(update_installed_handle); free(update_installed_handle);
@ -921,21 +932,19 @@ static void task_update_installed_cores_handler(retro_task_t *task)
switch (update_installed_handle->status) switch (update_installed_handle->status)
{ {
case UPDATE_INSTALLED_CORES_BEGIN: case UPDATE_INSTALLED_CORES_BEGIN:
{ /* Request buildbot core list */
/* Request buildbot core list */ update_installed_handle->list_task = (retro_task_t*)
update_installed_handle->list_task = (retro_task_t*) task_push_get_core_updater_list(
task_push_get_core_updater_list( update_installed_handle->core_list,
update_installed_handle->core_list, true, false);
true, false);
/* If push failed, go to end /* If push failed, go to end
* (error will message will be displayed when * (error will message will be displayed when
* final task title is set) */ * final task title is set) */
if (!update_installed_handle->list_task) if (!update_installed_handle->list_task)
update_installed_handle->status = UPDATE_INSTALLED_CORES_END; update_installed_handle->status = UPDATE_INSTALLED_CORES_END;
else else
update_installed_handle->status = UPDATE_INSTALLED_CORES_WAIT_LIST; update_installed_handle->status = UPDATE_INSTALLED_CORES_WAIT_LIST;
}
break; break;
case UPDATE_INSTALLED_CORES_WAIT_LIST: 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( task_push_core_updater_download(
update_installed_handle->core_list, update_installed_handle->core_list,
list_entry->remote_filename, list_entry->remote_filename,
true, false); true, false,
update_installed_handle->path_dir_libretro);
/* Again, if an error occurred, just return to /* Again, if an error occurred, just return to
* UPDATE_INSTALLED_CORES_ITERATE state */ * 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; 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; task_finder_data_t find_data;
retro_task_t *task = NULL; retro_task_t *task = NULL;
@ -1181,14 +1191,16 @@ void task_push_update_installed_cores(void)
goto error; goto error;
/* Configure handle */ /* Configure handle */
update_installed_handle->core_list = core_updater_list_init(CORE_UPDATER_LIST_SIZE); update_installed_handle->core_list = core_updater_list_init(
update_installed_handle->list_task = NULL; CORE_UPDATER_LIST_SIZE);
update_installed_handle->download_task = NULL; update_installed_handle->list_task = NULL;
update_installed_handle->list_size = 0; update_installed_handle->download_task = NULL;
update_installed_handle->list_index = 0; update_installed_handle->list_size = 0;
update_installed_handle->installed_index = 0; update_installed_handle->list_index = 0;
update_installed_handle->num_updated = 0; update_installed_handle->installed_index = 0;
update_installed_handle->status = UPDATE_INSTALLED_CORES_BEGIN; 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) if (!update_installed_handle->core_list)
goto error; goto error;

View File

@ -92,8 +92,9 @@ bool task_push_netplay_nat_traversal(void *nat_traversal_state, uint16_t port);
void *task_push_get_core_updater_list( void *task_push_get_core_updater_list(
core_updater_list_t* core_list, bool mute, bool refresh_menu); core_updater_list_t* core_list, bool mute, bool refresh_menu);
void *task_push_core_updater_download( 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,
void task_push_update_installed_cores(void); bool mute, bool check_crc, const char *path_dir_libretro);
void task_push_update_installed_cores(const char *path_dir_libretro);
#ifdef HAVE_MENU #ifdef HAVE_MENU
bool task_push_pl_thumbnail_download(const char *system, const char *playlist_path); bool task_push_pl_thumbnail_download(const char *system, const char *playlist_path);