diff --git a/tasks/task_file_transfer.c b/tasks/task_file_transfer.c index 79fbc49ce7..51d75d39f0 100644 --- a/tasks/task_file_transfer.c +++ b/tasks/task_file_transfer.c @@ -23,7 +23,10 @@ #include <lists/string_list.h> #include <rhash.h> +#include <string/stdstring.h> + #include "tasks_internal.h" +#include "../file_path_special.h" #include "../verbosity.h" static int task_file_transfer_iterate_transfer(nbio_handle_t *nbio) @@ -68,6 +71,33 @@ void task_file_load_handler(retro_task_t *task) switch (nbio->status) { + case NBIO_STATUS_INIT: + if (nbio && !string_is_empty(nbio->path)) + { + const char *fullpath = nbio->path; + struct nbio_t *handle = nbio_open(fullpath, NBIO_READ); + if (handle) + { + nbio->handle = handle; + nbio->status = NBIO_STATUS_TRANSFER; + + if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION))) + nbio->image_type = IMAGE_TYPE_PNG; + else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION)) + || strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION))) + nbio->image_type = IMAGE_TYPE_JPEG; + else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION))) + nbio->image_type = IMAGE_TYPE_BMP; + else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION))) + nbio->image_type = IMAGE_TYPE_TGA; + + nbio_begin_read(handle); + return; + } + else + task_set_cancelled(task, true); + } + break; case NBIO_STATUS_TRANSFER_PARSE: if (task_file_transfer_iterate_parse(nbio) == -1) task_set_cancelled(task, true); diff --git a/tasks/task_image.c b/tasks/task_image.c index c59ae1f6ff..eb41976b49 100644 --- a/tasks/task_image.c +++ b/tasks/task_image.c @@ -330,7 +330,6 @@ bool task_push_image_load(const char *fullpath, { nbio_handle_t *nbio = NULL; retro_task_t *t = NULL; - struct nbio_t *handle = NULL; struct nbio_image_handle *image = NULL; bool supports_rgba = video_driver_supports_rgba(); @@ -345,11 +344,7 @@ bool task_push_image_load(const char *fullpath, if (!nbio) goto error; - handle = nbio_open(fullpath, NBIO_READ); - if (!handle) - goto error; - - nbio->handle = handle; + strlcpy(nbio->path, fullpath, sizeof(nbio->path)); if (supports_rgba) BIT32_SET(nbio->status_flags, NBIO_FLAG_IMAGE_SUPPORTS_RGBA); @@ -363,19 +358,8 @@ bool task_push_image_load(const char *fullpath, nbio->data = (struct nbio_image_handle*)image; nbio->is_finished = false; nbio->cb = &cb_nbio_image_menu_thumbnail; - nbio->status = NBIO_STATUS_TRANSFER; + nbio->status = NBIO_STATUS_INIT; - if (strstr(fullpath, file_path_str(FILE_PATH_PNG_EXTENSION))) - nbio->image_type = IMAGE_TYPE_PNG; - else if (strstr(fullpath, file_path_str(FILE_PATH_JPEG_EXTENSION)) - || strstr(fullpath, file_path_str(FILE_PATH_JPG_EXTENSION))) - nbio->image_type = IMAGE_TYPE_JPEG; - else if (strstr(fullpath, file_path_str(FILE_PATH_BMP_EXTENSION))) - nbio->image_type = IMAGE_TYPE_BMP; - else if (strstr(fullpath, file_path_str(FILE_PATH_TGA_EXTENSION))) - nbio->image_type = IMAGE_TYPE_TGA; - - nbio_begin_read(handle); t->state = nbio; t->handler = task_file_load_handler; @@ -388,7 +372,6 @@ bool task_push_image_load(const char *fullpath, return true; error: - nbio_free(handle); task_image_load_free(t); free(t); if (nbio) diff --git a/tasks/tasks_internal.h b/tasks/tasks_internal.h index 7a91723d8c..0eca647a0e 100644 --- a/tasks/tasks_internal.h +++ b/tasks/tasks_internal.h @@ -55,7 +55,8 @@ enum content_mode_load enum nbio_status_enum { - NBIO_STATUS_POLL = 0, + NBIO_STATUS_INIT = 0, + NBIO_STATUS_POLL, NBIO_STATUS_TRANSFER, NBIO_STATUS_TRANSFER_PARSE, NBIO_STATUS_TRANSFER_PARSE_FREE @@ -78,6 +79,7 @@ typedef struct nbio_handle msg_queue_t *msg_queue; unsigned status; uint32_t status_flags; + char path[4096]; } nbio_handle_t; typedef struct autoconfig_params