mirror of
https://github.com/libretro/RetroArch
synced 2025-02-09 00:40:09 +00:00
(tasks) Add progress metter and task titles
This commit is contained in:
parent
87fb007ebc
commit
7e156584ba
@ -1172,13 +1172,6 @@ static int action_ok_download_generic(const char *path,
|
|||||||
transf->type_hash = menu_hash_calculate(type_msg);
|
transf->type_hash = menu_hash_calculate(type_msg);
|
||||||
strlcpy(transf->path, path, sizeof(transf->path));
|
strlcpy(transf->path, path, sizeof(transf->path));
|
||||||
|
|
||||||
snprintf(s2, sizeof(s2),
|
|
||||||
"%s %s.",
|
|
||||||
menu_hash_to_str(MENU_LABEL_VALUE_STARTING_DOWNLOAD),
|
|
||||||
path);
|
|
||||||
|
|
||||||
menu_display_msg_queue_push(s2, 1, 90, true);
|
|
||||||
|
|
||||||
rarch_task_push_http_transfer(s3, type_msg, cb_generic_download, transf);
|
rarch_task_push_http_transfer(s3, type_msg, cb_generic_download, transf);
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -110,28 +110,14 @@ static int cb_http_conn_default(void *data_, size_t len)
|
|||||||
* Returns: 0 when finished, -1 when we should continue
|
* Returns: 0 when finished, -1 when we should continue
|
||||||
* with the transfer on the next frame.
|
* with the transfer on the next frame.
|
||||||
**/
|
**/
|
||||||
static int rarch_main_data_http_iterate_transfer(void *data)
|
static int rarch_main_data_http_iterate_transfer(rarch_task_t *task)
|
||||||
{
|
{
|
||||||
http_handle_t *http = (http_handle_t*)data;
|
http_handle_t *http = (http_handle_t*)task->state;
|
||||||
size_t pos = 0, tot = 0;
|
size_t pos = 0, tot = 0;
|
||||||
|
|
||||||
if (!net_http_update(http->handle, &pos, &tot))
|
if (!net_http_update(http->handle, &pos, &tot))
|
||||||
{
|
{
|
||||||
int percent = 0;
|
task->progress = tot == 0 ? -1 : (pos * 100 / tot);
|
||||||
|
|
||||||
if(tot != 0)
|
|
||||||
percent = (unsigned long long)pos * 100
|
|
||||||
/ (unsigned long long)tot;
|
|
||||||
|
|
||||||
if (percent > 0)
|
|
||||||
{
|
|
||||||
char tmp[PATH_MAX_LENGTH];
|
|
||||||
snprintf(tmp, sizeof(tmp), "%s: %d%%",
|
|
||||||
msg_hash_to_str(MSG_DOWNLOAD_PROGRESS),
|
|
||||||
percent);
|
|
||||||
data_runloop_osd_msg(tmp, sizeof(tmp));
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +140,7 @@ static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
|||||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
||||||
break;
|
break;
|
||||||
case HTTP_STATUS_TRANSFER:
|
case HTTP_STATUS_TRANSFER:
|
||||||
if (!rarch_main_data_http_iterate_transfer(http))
|
if (!rarch_main_data_http_iterate_transfer(task))
|
||||||
goto task_finished;
|
goto task_finished;
|
||||||
break;
|
break;
|
||||||
case HTTP_STATUS_TRANSFER_PARSE:
|
case HTTP_STATUS_TRANSFER_PARSE:
|
||||||
@ -212,6 +198,7 @@ bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task
|
|||||||
rarch_task_t *t;
|
rarch_task_t *t;
|
||||||
http_handle_t *http;
|
http_handle_t *http;
|
||||||
struct http_connection_t *conn;
|
struct http_connection_t *conn;
|
||||||
|
char tmp[PATH_MAX_LENGTH];
|
||||||
|
|
||||||
if (!url || !*url)
|
if (!url || !*url)
|
||||||
return false;
|
return false;
|
||||||
@ -235,6 +222,10 @@ bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task
|
|||||||
t->state = http;
|
t->state = http;
|
||||||
t->callback = cb;
|
t->callback = cb;
|
||||||
t->user_data = user_data;
|
t->user_data = user_data;
|
||||||
|
t->progress = -1;
|
||||||
|
|
||||||
|
snprintf(tmp, sizeof(tmp), "Downloading '%s'", path_basename(url));
|
||||||
|
t->title = strdup(tmp);
|
||||||
|
|
||||||
rarch_task_push(t);
|
rarch_task_push(t);
|
||||||
|
|
||||||
|
@ -63,10 +63,34 @@ static void rarch_task_internal_gather(void)
|
|||||||
if (task->error)
|
if (task->error)
|
||||||
free(task->error);
|
free(task->error);
|
||||||
|
|
||||||
|
if (task->title)
|
||||||
|
free(task->title);
|
||||||
|
|
||||||
free(task);
|
free(task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void push_task_progress(rarch_task_t *task)
|
||||||
|
{
|
||||||
|
if (task->title)
|
||||||
|
{
|
||||||
|
if (task->finished)
|
||||||
|
{
|
||||||
|
if (task->error)
|
||||||
|
rarch_main_msg_queue_pushf(1, 60, true, "Failed: %s", task->title);
|
||||||
|
else
|
||||||
|
rarch_main_msg_queue_pushf(1, 60, true, "100%%: %s", task->title);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (task->progress >= 0 && task->progress <= 100)
|
||||||
|
rarch_main_msg_queue_pushf(1, 10, true, "%i%%: %s", task->progress, task->title);
|
||||||
|
else
|
||||||
|
rarch_main_msg_queue_pushf(1, 10, true, "%s...", task->title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void regular_push_running(rarch_task_t *task)
|
static void regular_push_running(rarch_task_t *task)
|
||||||
{
|
{
|
||||||
task_queue_put(&tasks_running, task);
|
task_queue_put(&tasks_running, task);
|
||||||
@ -78,8 +102,6 @@ static void regular_gather(void)
|
|||||||
rarch_task_t *queue = NULL;
|
rarch_task_t *queue = NULL;
|
||||||
rarch_task_t *next = NULL;
|
rarch_task_t *next = NULL;
|
||||||
|
|
||||||
/* mimics threaded_gather() for compatibility, a faster implementation
|
|
||||||
* can be written for systems without HAVE_THREADS if necessary. */
|
|
||||||
while ((task = task_queue_get(&tasks_running)) != NULL)
|
while ((task = task_queue_get(&tasks_running)) != NULL)
|
||||||
{
|
{
|
||||||
task->next = queue;
|
task->next = queue;
|
||||||
@ -91,6 +113,8 @@ static void regular_gather(void)
|
|||||||
next = task->next;
|
next = task->next;
|
||||||
task->handler(task);
|
task->handler(task);
|
||||||
|
|
||||||
|
push_task_progress(task);
|
||||||
|
|
||||||
if (task->finished)
|
if (task->finished)
|
||||||
task_queue_put(&tasks_finished, task);
|
task_queue_put(&tasks_finished, task);
|
||||||
else
|
else
|
||||||
@ -148,6 +172,13 @@ static void threaded_push_running(rarch_task_t *task)
|
|||||||
|
|
||||||
static void threaded_gather(void)
|
static void threaded_gather(void)
|
||||||
{
|
{
|
||||||
|
rarch_task_t *task;
|
||||||
|
slock_lock(running_lock);
|
||||||
|
for (task = tasks_running.front; task; task = task->next)
|
||||||
|
push_task_progress(task);
|
||||||
|
|
||||||
|
slock_unlock(running_lock);
|
||||||
|
|
||||||
slock_lock(finished_lock);
|
slock_lock(finished_lock);
|
||||||
rarch_task_internal_gather();
|
rarch_task_internal_gather();
|
||||||
slock_unlock(finished_lock);
|
slock_unlock(finished_lock);
|
||||||
|
@ -55,6 +55,10 @@ struct rarch_task {
|
|||||||
/* created by task handler; destroyed by main loop (after calling the callback) */
|
/* created by task handler; destroyed by main loop (after calling the callback) */
|
||||||
char *error;
|
char *error;
|
||||||
|
|
||||||
|
/* -1 = unmettered, 0-100 progress value */
|
||||||
|
char progress;
|
||||||
|
char *title; /* handler can modify but will be free()d automatically if non-null */
|
||||||
|
|
||||||
/* don't touch this. */
|
/* don't touch this. */
|
||||||
rarch_task_t *next;
|
rarch_task_t *next;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user