mirror of
https://github.com/libretro/RetroArch
synced 2025-03-29 22:20:21 +00:00
Merge pull request #2496 from heuripedes/master
Add generic task progress and titles
This commit is contained in:
commit
b5481d8b7c
@ -157,12 +157,8 @@ const char *msg_hash_to_str_es(uint32_t hash)
|
||||
return "Borrando archivo temporal de contenido";
|
||||
case MSG_LOADED_STATE_FROM_SLOT:
|
||||
return "Carga rápida desde la ranura";
|
||||
case MSG_DOWNLOAD_PROGRESS:
|
||||
return "Progreso de la descarga";
|
||||
case MSG_COULD_NOT_PROCESS_ZIP_FILE:
|
||||
return "No se ha podido procesar el archivo ZIP.";
|
||||
case MSG_DOWNLOAD_COMPLETE:
|
||||
return "Descarga completa";
|
||||
case MSG_SCANNING_OF_DIRECTORY_FINISHED:
|
||||
return "Escaneado de carpetas terminado";
|
||||
case MSG_SCANNING:
|
||||
@ -195,6 +191,10 @@ const char *msg_hash_to_str_es(uint32_t hash)
|
||||
return "Rebobinando.";
|
||||
case MSG_REWIND_REACHED_END:
|
||||
return "Se ha llegado al final del búfer de rebobinado.";
|
||||
case MSG_TASK_FAILED:
|
||||
return "Fracasado";
|
||||
case MSG_DOWNLOADING:
|
||||
return "Descargando";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -148,12 +148,8 @@ const char *msg_hash_to_str_pl(uint32_t hash)
|
||||
return "Usuwanie tymczasowego pliku treści";
|
||||
case MSG_LOADED_STATE_FROM_SLOT:
|
||||
return "Wczytano stan ze slotu";
|
||||
case MSG_DOWNLOAD_PROGRESS:
|
||||
return "Postęp pobierania";
|
||||
case MSG_COULD_NOT_PROCESS_ZIP_FILE:
|
||||
return "Nie udało się przetworzyć pliku ZIP.";
|
||||
case MSG_DOWNLOAD_COMPLETE:
|
||||
return "Zakończono pobieranie";
|
||||
case MSG_SCANNING_OF_DIRECTORY_FINISHED:
|
||||
return "Zakończono skanowanie katalogu";
|
||||
case MSG_SCANNING:
|
||||
|
@ -100,12 +100,8 @@ const char *msg_hash_to_str_pt(uint32_t hash)
|
||||
return "Removendo conteúdo temporário";
|
||||
case MSG_LOADED_STATE_FROM_SLOT:
|
||||
return "Estado carregado do slot";
|
||||
case MSG_DOWNLOAD_PROGRESS:
|
||||
return "Progresso do download";
|
||||
case MSG_COULD_NOT_PROCESS_ZIP_FILE:
|
||||
return "Incapaz de processar arquivo ZIP.";
|
||||
case MSG_DOWNLOAD_COMPLETE:
|
||||
return "Download concluído";
|
||||
case MSG_SCANNING_OF_DIRECTORY_FINISHED:
|
||||
return "Exame de diretório concluído";
|
||||
case MSG_SCANNING:
|
||||
@ -138,6 +134,12 @@ const char *msg_hash_to_str_pt(uint32_t hash)
|
||||
return "Retrocedendo.";
|
||||
case MSG_REWIND_REACHED_END:
|
||||
return "Final do buffer de retrocesso atingido.";
|
||||
case MSG_TASK_FAILED:
|
||||
return "Falhou";
|
||||
case MSG_DOWNLOADING:
|
||||
return "Baixando";
|
||||
case MSG_EXTRACTING:
|
||||
return "Extraindo";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -148,12 +148,8 @@ const char *msg_hash_to_str_us(uint32_t hash)
|
||||
return "Removing temporary content file";
|
||||
case MSG_LOADED_STATE_FROM_SLOT:
|
||||
return "Loaded state from slot";
|
||||
case MSG_DOWNLOAD_PROGRESS:
|
||||
return "Download progress";
|
||||
case MSG_COULD_NOT_PROCESS_ZIP_FILE:
|
||||
return "Could not process ZIP file.";
|
||||
case MSG_DOWNLOAD_COMPLETE:
|
||||
return "Download complete";
|
||||
case MSG_SCANNING_OF_DIRECTORY_FINISHED:
|
||||
return "Scanning of directory finished";
|
||||
case MSG_SCANNING:
|
||||
@ -186,6 +182,12 @@ const char *msg_hash_to_str_us(uint32_t hash)
|
||||
return "Rewinding.";
|
||||
case MSG_REWIND_REACHED_END:
|
||||
return "Reached end of rewind buffer.";
|
||||
case MSG_TASK_FAILED:
|
||||
return "Failed";
|
||||
case MSG_DOWNLOADING:
|
||||
return "Downloading";
|
||||
case MSG_EXTRACTING:
|
||||
return "Extracting";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -604,6 +604,15 @@ bool zlib_parse_file(const char *file, const char *valid_exts,
|
||||
return returnerr;
|
||||
}
|
||||
|
||||
int zlib_parse_file_progress(void *data)
|
||||
{
|
||||
/* FIXME: this estimate is pretty bad */
|
||||
zlib_transfer_t *state = (zlib_transfer_t*)data;
|
||||
const uint8_t *offset = state->data + read_le(state->directory + 42, 4);
|
||||
ptrdiff_t delta = offset - state->data - 46 - 22;
|
||||
return delta * 100 / state->zip_size;
|
||||
}
|
||||
|
||||
struct zip_extract_userdata
|
||||
{
|
||||
char *zip_path;
|
||||
|
@ -86,6 +86,8 @@ int zlib_parse_file_iterate(void *data, bool *returnerr,
|
||||
|
||||
void zlib_parse_file_iterate_stop(void *data);
|
||||
|
||||
int zlib_parse_file_progress(void *data);
|
||||
|
||||
/**
|
||||
* zlib_extract_first_content_file:
|
||||
* @zip_path : filename path to ZIP archive.
|
||||
|
@ -338,15 +338,10 @@ static void cb_decompressed(void *task_data, void *user_data, const char *err)
|
||||
|
||||
if (dec && !err)
|
||||
{
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
|
||||
if (type_hash == CB_CORE_UPDATER_DOWNLOAD)
|
||||
event_command(EVENT_CMD_CORE_INFO_INIT);
|
||||
else if (type_hash == CB_UPDATE_ASSETS)
|
||||
event_command(EVENT_CMD_REINIT);
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s extracted.", path_basename(dec->source_file));
|
||||
rarch_main_msg_queue_push(msg, 1, 90, true);
|
||||
}
|
||||
|
||||
if (err)
|
||||
@ -448,9 +443,6 @@ void cb_generic_download(void *task_data, void *user_data, const char *err)
|
||||
goto finish;
|
||||
}
|
||||
|
||||
rarch_main_msg_queue_pushf(1, 90, true, "%s: %s",
|
||||
msg_hash_to_str(MSG_DOWNLOAD_COMPLETE), transf->path);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
file_ext = path_get_extension(output_path);
|
||||
|
||||
@ -459,15 +451,8 @@ void cb_generic_download(void *task_data, void *user_data, const char *err)
|
||||
|
||||
if (!strcasecmp(file_ext, "zip"))
|
||||
{
|
||||
rarch_main_msg_queue_pushf(1, 90, true,
|
||||
"Decompressing %s...", path_basename(output_path));
|
||||
|
||||
if (!rarch_task_push_decompress(output_path, dir_path, NULL,
|
||||
cb_decompressed, (void*)(uintptr_t)transf->type_hash))
|
||||
{
|
||||
rarch_main_msg_queue_pushf(1, 90, true,
|
||||
"Decompression of %s failed.", path_basename(output_path));
|
||||
}
|
||||
rarch_task_push_decompress(output_path, dir_path, NULL,
|
||||
cb_decompressed, (void*)(uintptr_t)transf->type_hash);
|
||||
}
|
||||
#else
|
||||
if (transf->type_hash == CB_CORE_UPDATER_DOWNLOAD)
|
||||
@ -477,8 +462,6 @@ void cb_generic_download(void *task_data, void *user_data, const char *err)
|
||||
finish:
|
||||
if (err)
|
||||
{
|
||||
rarch_main_msg_queue_pushf(1, 90, true, "Download failed.");
|
||||
|
||||
RARCH_ERR("Download of '%s' failed: %s\n",
|
||||
(transf ? transf->path: "unknown"), err);
|
||||
}
|
||||
|
@ -1172,13 +1172,6 @@ static int action_ok_download_generic(const char *path,
|
||||
transf->type_hash = menu_hash_calculate(type_msg);
|
||||
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);
|
||||
#endif
|
||||
return 0;
|
||||
|
@ -101,9 +101,7 @@
|
||||
#define MSG_SCANNING 0x4c547516U
|
||||
#define MSG_SCANNING_OF_DIRECTORY_FINISHED 0x399632a7U
|
||||
|
||||
#define MSG_DOWNLOAD_COMPLETE 0x4b9c4f75U
|
||||
#define MSG_COULD_NOT_PROCESS_ZIP_FILE 0xc18c89bbU
|
||||
#define MSG_DOWNLOAD_PROGRESS 0x35ed9411U
|
||||
|
||||
#define MSG_LOADED_STATE_FROM_SLOT 0xadb48582U
|
||||
|
||||
@ -153,6 +151,10 @@
|
||||
|
||||
#define MSG_GOT_INVALID_DISK_INDEX 0xb138dd76U
|
||||
|
||||
#define MSG_TASK_FAILED 0xb23ed64aU
|
||||
#define MSG_DOWNLOADING 0x465305dbU
|
||||
#define MSG_EXTRACTING 0x25a4c19eU
|
||||
|
||||
const char *msg_hash_to_str(uint32_t hash);
|
||||
|
||||
const char *msg_hash_to_str_fr(uint32_t hash);
|
||||
|
@ -20,8 +20,6 @@
|
||||
|
||||
#include "tasks/tasks.h"
|
||||
|
||||
static char data_runloop_msg[PATH_MAX_LENGTH];
|
||||
|
||||
void rarch_main_data_deinit(void)
|
||||
{
|
||||
rarch_task_deinit();
|
||||
@ -29,12 +27,6 @@ void rarch_main_data_deinit(void)
|
||||
|
||||
void rarch_main_data_iterate(void)
|
||||
{
|
||||
if (data_runloop_msg[0] != '\0')
|
||||
{
|
||||
rarch_main_msg_queue_push(data_runloop_msg, 1, 10, true);
|
||||
data_runloop_msg[0] = '\0';
|
||||
}
|
||||
|
||||
rarch_task_check();
|
||||
}
|
||||
|
||||
@ -46,5 +38,5 @@ void rarch_main_data_clear_state(void)
|
||||
|
||||
void data_runloop_osd_msg(const char *msg, size_t len)
|
||||
{
|
||||
strlcpy(data_runloop_msg, msg, len);
|
||||
rarch_main_msg_queue_push(msg, 1, 10, true);
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "tasks.h"
|
||||
#include "../verbosity.h"
|
||||
#include "../msg_hash.h"
|
||||
|
||||
typedef struct {
|
||||
char *source_file;
|
||||
@ -80,6 +81,8 @@ static void rarch_task_decompress_handler(rarch_task_t *task)
|
||||
ret = zlib_parse_file_iterate(&dec->zlib, &returnerr, dec->source_file,
|
||||
dec->valid_ext, file_decompressed, dec);
|
||||
|
||||
task->progress = zlib_parse_file_progress(&dec->zlib);
|
||||
|
||||
if (task->cancelled || ret != 0)
|
||||
{
|
||||
task->error = dec->callback_error;
|
||||
@ -115,6 +118,7 @@ bool rarch_task_push_decompress(const char *source_file, const char *target_dir,
|
||||
{
|
||||
decompress_state_t *s;
|
||||
rarch_task_t *t;
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
|
||||
if (!target_dir || !target_dir[0] || !source_file || !source_file[0])
|
||||
{
|
||||
@ -148,6 +152,9 @@ bool rarch_task_push_decompress(const char *source_file, const char *target_dir,
|
||||
t->callback = cb;
|
||||
t->user_data = user_data;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s '%s'", msg_hash_to_str(MSG_EXTRACTING), path_basename(source_file));
|
||||
t->title = strdup(tmp);
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
return true;
|
||||
|
@ -110,28 +110,14 @@ static int cb_http_conn_default(void *data_, size_t len)
|
||||
* Returns: 0 when finished, -1 when we should continue
|
||||
* 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;
|
||||
|
||||
if (!net_http_update(http->handle, &pos, &tot))
|
||||
{
|
||||
int percent = 0;
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
task->progress = tot == 0 ? -1 : (pos * 100 / tot);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -154,7 +140,7 @@ static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER:
|
||||
if (!rarch_main_data_http_iterate_transfer(http))
|
||||
if (!rarch_main_data_http_iterate_transfer(task))
|
||||
goto task_finished;
|
||||
break;
|
||||
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;
|
||||
http_handle_t *http;
|
||||
struct http_connection_t *conn;
|
||||
char tmp[PATH_MAX_LENGTH];
|
||||
|
||||
if (!url || !*url)
|
||||
return false;
|
||||
@ -235,6 +222,10 @@ bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task
|
||||
t->state = http;
|
||||
t->callback = cb;
|
||||
t->user_data = user_data;
|
||||
t->progress = -1;
|
||||
|
||||
snprintf(tmp, sizeof(tmp), "%s '%s'", msg_hash_to_str(MSG_DOWNLOADING), path_basename(url));
|
||||
t->title = strdup(tmp);
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "../general.h"
|
||||
#include "../verbosity.h"
|
||||
#include "../msg_hash.h"
|
||||
#include "tasks.h"
|
||||
|
||||
#ifdef HAVE_THREADS
|
||||
@ -63,10 +64,35 @@ static void rarch_task_internal_gather(void)
|
||||
if (task->error)
|
||||
free(task->error);
|
||||
|
||||
if (task->title)
|
||||
free(task->title);
|
||||
|
||||
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, "%s: %s",
|
||||
msg_hash_to_str(MSG_TASK_FAILED), 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)
|
||||
{
|
||||
task_queue_put(&tasks_running, task);
|
||||
@ -78,8 +104,6 @@ static void regular_gather(void)
|
||||
rarch_task_t *queue = 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)
|
||||
{
|
||||
task->next = queue;
|
||||
@ -91,6 +115,8 @@ static void regular_gather(void)
|
||||
next = task->next;
|
||||
task->handler(task);
|
||||
|
||||
push_task_progress(task);
|
||||
|
||||
if (task->finished)
|
||||
task_queue_put(&tasks_finished, task);
|
||||
else
|
||||
@ -148,6 +174,13 @@ static void threaded_push_running(rarch_task_t *task)
|
||||
|
||||
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);
|
||||
rarch_task_internal_gather();
|
||||
slock_unlock(finished_lock);
|
||||
|
@ -55,6 +55,10 @@ struct rarch_task {
|
||||
/* created by task handler; destroyed by main loop (after calling the callback) */
|
||||
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. */
|
||||
rarch_task_t *next;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user