void task_file_load_handler(retro_task_t *task) { nbio_handle_t *nbio = (nbio_handle_t*)task->state; if (nbio) { switch (nbio->status) { case NBIO_STATUS_INIT: if (nbio && !string_is_empty(nbio->path)) { struct nbio_t *handle = (struct nbio_t*)nbio_open(nbio->path, NBIO_READ); if (handle) { nbio->handle = handle; nbio->status = NBIO_STATUS_TRANSFER; nbio_begin_read(handle); return; } else task_set_cancelled(task, true); } break; case NBIO_STATUS_TRANSFER_PARSE: if (!nbio || task_file_transfer_iterate_parse(nbio) == -1) task_set_cancelled(task, true); nbio->status = NBIO_STATUS_TRANSFER_FINISHED; break; case NBIO_STATUS_TRANSFER: if (!nbio || task_file_transfer_iterate_transfer(nbio) == -1) nbio->status = NBIO_STATUS_TRANSFER_PARSE; break; case NBIO_STATUS_TRANSFER_FINISHED: break; } switch (nbio->type) { case NBIO_TYPE_PNG: case NBIO_TYPE_JPEG: case NBIO_TYPE_TGA: case NBIO_TYPE_BMP: if (!task_image_load_handler(task)) task_set_finished(task, true); break; case NBIO_TYPE_MP3: case NBIO_TYPE_FLAC: case NBIO_TYPE_OGG: case NBIO_TYPE_MOD: case NBIO_TYPE_WAV: if (!task_audio_mixer_load_handler(task)) task_set_finished(task, true); break; case NBIO_TYPE_NONE: default: if (nbio->is_finished) task_set_finished(task, true); break; } } if (task_get_cancelled(task)) { task_set_error(task, strdup("Task canceled.")); task_set_finished(task, true); } }
void task_file_load_handler(retro_task_t *task) { nbio_handle_t *nbio = (nbio_handle_t*)task->state; if (nbio) { 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); nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE; break; case NBIO_STATUS_TRANSFER: if (task_file_transfer_iterate_transfer(nbio) == -1) nbio->status = NBIO_STATUS_TRANSFER_PARSE; break; case NBIO_STATUS_TRANSFER_PARSE_FREE: case NBIO_STATUS_POLL: default: break; } switch (nbio->image_type) { case IMAGE_TYPE_PNG: case IMAGE_TYPE_JPEG: case IMAGE_TYPE_TGA: case IMAGE_TYPE_BMP: if (!task_image_load_handler(task)) task_set_finished(task, true); break; case 0: if (nbio->is_finished) task_set_finished(task, true); break; } } if (task_get_cancelled(task)) { task_set_error(task, strdup("Task canceled.")); task_set_finished(task, true); } }