2015-05-05 17:58:37 +02:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-01-10 04:06:50 +01:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-05-05 17:58:37 +02:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2015-12-07 11:54:58 -03:00
|
|
|
#include <errno.h>
|
2015-07-08 21:35:24 +02:00
|
|
|
#include <file/nbio.h>
|
|
|
|
#include <formats/image.h>
|
2015-06-14 17:11:48 +02:00
|
|
|
#include <compat/strl.h>
|
2015-09-01 11:59:27 +02:00
|
|
|
#include <retro_assert.h>
|
2015-05-05 17:58:37 +02:00
|
|
|
#include <retro_miscellaneous.h>
|
2016-03-20 14:53:54 +01:00
|
|
|
#include <lists/string_list.h>
|
2015-06-14 17:11:48 +02:00
|
|
|
#include <rhash.h>
|
2015-05-05 17:58:37 +02:00
|
|
|
|
2016-02-09 17:12:39 +01:00
|
|
|
#include "tasks_internal.h"
|
2015-11-23 12:03:38 +01:00
|
|
|
#include "../verbosity.h"
|
2015-05-05 17:58:37 +02:00
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_file_transfer_iterate_transfer(nbio_handle_t *nbio)
|
2015-05-05 17:58:37 +02:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
nbio->pos_increment = 5;
|
|
|
|
|
|
|
|
if (nbio->is_finished)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < nbio->pos_increment; i++)
|
|
|
|
{
|
|
|
|
if (nbio_iterate(nbio->handle))
|
2015-05-23 17:16:19 +02:00
|
|
|
return -1;
|
2015-05-05 17:58:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 10:19:53 +02:00
|
|
|
static int task_file_transfer_iterate_parse(nbio_handle_t *nbio)
|
2015-05-05 17:58:37 +02:00
|
|
|
{
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nbio->cb)
|
2015-09-28 18:12:02 +02:00
|
|
|
{
|
|
|
|
int len = 0;
|
2016-05-18 17:32:39 +02:00
|
|
|
if (nbio->cb(nbio, len) == -1)
|
|
|
|
return -1;
|
2015-09-28 18:12:02 +02:00
|
|
|
}
|
2015-05-05 17:58:37 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-27 18:14:47 +02:00
|
|
|
void task_file_load_handler(retro_task_t *task)
|
2015-05-05 17:58:37 +02:00
|
|
|
{
|
2015-11-23 00:17:27 -03:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
2015-05-05 17:58:37 +02:00
|
|
|
|
|
|
|
switch (nbio->status)
|
|
|
|
{
|
|
|
|
case NBIO_STATUS_TRANSFER_PARSE:
|
2016-05-18 17:32:39 +02:00
|
|
|
if (task_file_transfer_iterate_parse(nbio) == -1)
|
2016-05-18 17:37:43 +02:00
|
|
|
task->cancelled = true;
|
2015-05-05 17:58:37 +02:00
|
|
|
nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE;
|
|
|
|
break;
|
2015-05-23 17:16:19 +02:00
|
|
|
case NBIO_STATUS_TRANSFER:
|
2016-05-13 10:19:53 +02:00
|
|
|
if (task_file_transfer_iterate_transfer(nbio) == -1)
|
2015-05-23 17:16:19 +02:00
|
|
|
nbio->status = NBIO_STATUS_TRANSFER_PARSE;
|
|
|
|
break;
|
2015-05-05 17:58:37 +02:00
|
|
|
case NBIO_STATUS_TRANSFER_PARSE_FREE:
|
|
|
|
case NBIO_STATUS_POLL:
|
2015-05-23 17:16:19 +02:00
|
|
|
default:
|
2015-05-05 17:58:37 +02:00
|
|
|
break;
|
|
|
|
}
|
2015-07-08 20:04:16 +02:00
|
|
|
|
2016-05-18 23:14:07 +02:00
|
|
|
switch (nbio->image_type)
|
2015-11-23 00:17:27 -03:00
|
|
|
{
|
2016-05-18 23:14:07 +02:00
|
|
|
case IMAGE_TYPE_PNG:
|
|
|
|
case IMAGE_TYPE_JPEG:
|
|
|
|
case IMAGE_TYPE_TGA:
|
|
|
|
case IMAGE_TYPE_BMP:
|
2016-05-27 18:14:47 +02:00
|
|
|
if (!task_image_load_handler(task))
|
2016-05-23 22:41:24 +02:00
|
|
|
task->finished = true;
|
2016-05-18 23:14:07 +02:00
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
if (nbio->is_finished)
|
2016-05-23 22:41:24 +02:00
|
|
|
task->finished = true;
|
2016-05-18 23:14:07 +02:00
|
|
|
break;
|
2016-02-10 05:41:53 +01:00
|
|
|
}
|
2015-11-24 22:17:38 -03:00
|
|
|
|
|
|
|
if (task->cancelled)
|
|
|
|
{
|
|
|
|
task->error = strdup("Task canceled.");
|
2016-05-23 22:41:24 +02:00
|
|
|
task->finished = true;
|
2015-11-24 22:17:38 -03:00
|
|
|
}
|
2015-07-08 20:04:16 +02:00
|
|
|
}
|