1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-08 20:25:47 +00:00

add task_push_http_transfer_file

This commit is contained in:
Jamiras 2020-01-17 19:48:40 -07:00
parent 38b486eb6b
commit 7325147d83
7 changed files with 50 additions and 31 deletions

View File

@ -149,7 +149,7 @@ static bool discord_download_avatar(
strlcpy(transf->path, buf, sizeof(transf->path));
RARCH_LOG("[discord] downloading avatar from: %s\n", url_encoded);
task_push_http_transfer(url_encoded, true, NULL, cb_generic_download, transf);
task_push_http_transfer_file(url_encoded, true, NULL, cb_generic_download, transf);
return false;
}

View File

@ -3991,7 +3991,7 @@ static int generic_action_ok_network(const char *path,
strlcpy(transf->path, url_path, sizeof(transf->path));
net_http_urlencode_full(url_path_encoded, url_path, sizeof(url_path_encoded));
task_push_http_transfer(url_path_encoded, suppress_msg, url_label, callback, transf);
task_push_http_transfer_file(url_path_encoded, suppress_msg, url_label, callback, transf);
return generic_action_ok_displaylist_push(path, NULL,
label, type, idx, entry_idx, type_id2);
@ -4293,7 +4293,7 @@ static int action_ok_download_generic(const char *path,
else
net_http_urlencode_full(s3, s2, sizeof(s3));
task_push_http_transfer(s3, suppress_msg, msg_hash_to_str(enum_idx), cb, transf);
task_push_http_transfer_file(s3, suppress_msg, msg_hash_to_str(enum_idx), cb, transf);
#endif
return 0;
}

View File

@ -241,7 +241,7 @@ finish:
strlcpy(transf->path, parent_dir, sizeof(transf->path));
net_http_urlencode_full(parent_dir_encoded, parent_dir, PATH_MAX_LENGTH * sizeof(char));
task_push_http_transfer(parent_dir_encoded, true,
task_push_http_transfer_file(parent_dir_encoded, true,
"index_dirs", cb_net_generic_subdir, transf);
free(parent_dir);

View File

@ -260,7 +260,7 @@ static void task_core_updater_get_list_handler(retro_task_t *task)
transf->user_data = (void*)list_handle;
/* Push HTTP transfer task */
list_handle->http_task = (retro_task_t*)task_push_http_transfer(
list_handle->http_task = (retro_task_t*)task_push_http_transfer_file(
buildbot_url, true, NULL,
cb_http_task_core_updater_get_list, transf);
@ -288,7 +288,7 @@ static void task_core_updater_get_list_handler(retro_task_t *task)
task, task_get_progress(list_handle->http_task));
}
/* Wait for task_push_http_transfer()
/* Wait for task_push_http_transfer_file()
* callback to trigger */
if (list_handle->http_task_complete)
list_handle->status = CORE_UPDATER_LIST_END;
@ -626,7 +626,7 @@ static void task_core_updater_download_handler(retro_task_t *task)
transf->user_data = (void*)download_handle;
/* Push HTTP transfer task */
download_handle->http_task = (retro_task_t*)task_push_http_transfer(
download_handle->http_task = (retro_task_t*)task_push_http_transfer_file(
download_handle->remote_core_path, true, NULL,
cb_http_task_core_updater_download, transf);
@ -673,7 +673,7 @@ static void task_core_updater_download_handler(retro_task_t *task)
}
}
/* Wait for task_push_http_transfer()
/* Wait for task_push_http_transfer_file()
* callback to trigger */
if (download_handle->http_task_complete)
download_handle->status = CORE_UPDATER_DOWNLOAD_WAIT_DECOMPRESS;

View File

@ -77,6 +77,9 @@ typedef struct
void *user_data;
} file_transfer_t;
void* task_push_http_transfer_file(const char* url, bool mute, const char* type,
retro_task_callback_t cb, file_transfer_t* transfer_data);
RETRO_END_DECLS
#endif

View File

@ -250,13 +250,9 @@ static void* task_push_http_transfer_generic(
retro_task_callback_t cb, void *user_data)
{
task_finder_data_t find_data;
char tmp[255];
const char *s = NULL;
retro_task_t *t = NULL;
http_handle_t *http = NULL;
tmp[0] = '\0';
find_data.func = task_http_finder;
find_data.userdata = (void*)url;
@ -299,22 +295,6 @@ static void* task_push_http_transfer_generic(
t->user_data = user_data;
t->progress = -1;
if (user_data)
s = ((file_transfer_t*)user_data)->path;
else
s = url;
strlcpy(tmp,
msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp));
strlcat(tmp, " ", sizeof(tmp));
if (strstr(s, ".index"))
strlcat(tmp, msg_hash_to_str(MSG_INDEX_FILE), sizeof(tmp));
else
strlcat(tmp, s, sizeof(tmp));
t->title = strdup(tmp);
task_queue_push(t);
return t;
@ -334,11 +314,47 @@ void* task_push_http_transfer(const char *url, bool mute,
{
if (string_is_empty(url))
return NULL;
return task_push_http_transfer_generic(
net_http_connection_new(url, "GET", NULL),
url, mute, type, cb, user_data);
}
void* task_push_http_transfer_file(const char* url, bool mute,
const char* type,
retro_task_callback_t cb, file_transfer_t* transfer_data)
{
const char *s = NULL;
char tmp[255] = "";
retro_task_t *t = NULL;
if (string_is_empty(url))
return NULL;
t = task_push_http_transfer_generic(
net_http_connection_new(url, "GET", NULL),
url, mute, type, cb, transfer_data);
if (!t)
return NULL;
if (transfer_data)
s = transfer_data->path;
else
s = url;
strlcpy(tmp, msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp));
strlcat(tmp, " ", sizeof(tmp));
if (strstr(s, ".index"))
strlcat(tmp, msg_hash_to_str(MSG_INDEX_FILE), sizeof(tmp));
else
strlcat(tmp, s, sizeof(tmp));
t->title = strdup(tmp);
return t;
}
void* task_push_http_transfer_with_user_agent(const char *url, bool mute,
const char *type, const char* user_agent,
retro_task_callback_t cb, void *user_data)

View File

@ -269,7 +269,7 @@ static void download_pl_thumbnail(pl_thumb_handle_t *pl_thumb)
/* Note: We don't actually care if this fails since that
* just means the file is missing from the server, so it's
* not something we can handle here... */
pl_thumb->http_task = (retro_task_t*)task_push_http_transfer(
pl_thumb->http_task = (retro_task_t*)task_push_http_transfer_file(
url, true, NULL, cb_http_task_download_pl_thumbnail, transf);
/* ...if it does fail, however, we can immediately
@ -411,7 +411,7 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task)
if (!pl_thumb->http_task)
pl_thumb->http_task_complete = true;
/* > Wait for task_push_http_transfer()
/* > Wait for task_push_http_transfer_file()
* callback to trigger */
if (pl_thumb->http_task_complete)
pl_thumb->http_task = NULL;
@ -726,7 +726,7 @@ static void task_pl_entry_thumbnail_download_handler(retro_task_t *task)
if (!pl_thumb->http_task)
pl_thumb->http_task_complete = true;
/* > Wait for task_push_http_transfer()
/* > Wait for task_push_http_transfer_file()
* callback to trigger */
if (pl_thumb->http_task_complete)
pl_thumb->http_task = NULL;