2015-05-05 15:58:37 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-05-05 15:58:37 +00: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 14:54:58 +00:00
|
|
|
#include <errno.h>
|
2015-07-08 19:35:24 +00:00
|
|
|
#include <file/nbio.h>
|
|
|
|
#include <formats/image.h>
|
2015-06-14 15:11:48 +00:00
|
|
|
#include <compat/strl.h>
|
2015-09-01 09:59:27 +00:00
|
|
|
#include <retro_assert.h>
|
2015-05-05 15:58:37 +00:00
|
|
|
#include <retro_miscellaneous.h>
|
2016-03-20 13:53:54 +00:00
|
|
|
#include <lists/string_list.h>
|
2015-06-14 15:11:48 +00:00
|
|
|
#include <rhash.h>
|
2015-05-05 15:58:37 +00:00
|
|
|
|
2016-02-09 16:12:39 +00:00
|
|
|
#include "tasks_internal.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "../verbosity.h"
|
2015-05-05 15:58:37 +00:00
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_file_transfer_iterate_transfer(nbio_handle_t *nbio)
|
2015-05-05 15:58:37 +00: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 15:16:19 +00:00
|
|
|
return -1;
|
2015-05-05 15:58:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-13 08:19:53 +00:00
|
|
|
static int task_file_transfer_iterate_parse(nbio_handle_t *nbio)
|
2015-05-05 15:58:37 +00:00
|
|
|
{
|
|
|
|
if (!nbio)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (nbio->cb)
|
2015-09-28 16:12:02 +00:00
|
|
|
{
|
|
|
|
int len = 0;
|
2016-05-18 15:32:39 +00:00
|
|
|
if (nbio->cb(nbio, len) == -1)
|
|
|
|
return -1;
|
2015-09-28 16:12:02 +00:00
|
|
|
}
|
2015-05-05 15:58:37 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-05-10 05:54:47 +00:00
|
|
|
void rarch_task_file_load_handler(retro_task_t *task)
|
2015-05-05 15:58:37 +00:00
|
|
|
{
|
2015-11-23 03:17:27 +00:00
|
|
|
nbio_handle_t *nbio = (nbio_handle_t*)task->state;
|
2015-05-05 15:58:37 +00:00
|
|
|
|
|
|
|
switch (nbio->status)
|
|
|
|
{
|
|
|
|
case NBIO_STATUS_TRANSFER_PARSE:
|
2016-05-18 15:32:39 +00:00
|
|
|
if (task_file_transfer_iterate_parse(nbio) == -1)
|
2016-05-18 15:37:43 +00:00
|
|
|
task->cancelled = true;
|
2015-05-05 15:58:37 +00:00
|
|
|
nbio->status = NBIO_STATUS_TRANSFER_PARSE_FREE;
|
|
|
|
break;
|
2015-05-23 15:16:19 +00:00
|
|
|
case NBIO_STATUS_TRANSFER:
|
2016-05-13 08:19:53 +00:00
|
|
|
if (task_file_transfer_iterate_transfer(nbio) == -1)
|
2015-05-23 15:16:19 +00:00
|
|
|
nbio->status = NBIO_STATUS_TRANSFER_PARSE;
|
|
|
|
break;
|
2015-05-05 15:58:37 +00:00
|
|
|
case NBIO_STATUS_TRANSFER_PARSE_FREE:
|
|
|
|
case NBIO_STATUS_POLL:
|
2015-05-23 15:16:19 +00:00
|
|
|
default:
|
2015-05-05 15:58:37 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-07-08 18:04:16 +00:00
|
|
|
|
2016-05-13 13:00:44 +00:00
|
|
|
if (nbio->image)
|
2015-11-23 03:17:27 +00:00
|
|
|
{
|
2016-05-10 05:54:47 +00:00
|
|
|
if (!rarch_task_image_load_handler(task))
|
2015-11-23 03:17:27 +00:00
|
|
|
goto task_finished;
|
2016-02-10 04:41:53 +00:00
|
|
|
}
|
|
|
|
else
|
2015-11-23 23:41:01 +00:00
|
|
|
if (nbio->is_finished)
|
|
|
|
goto task_finished;
|
2015-11-23 03:17:27 +00:00
|
|
|
|
2015-11-25 01:17:38 +00:00
|
|
|
|
|
|
|
if (task->cancelled)
|
|
|
|
{
|
|
|
|
task->error = strdup("Task canceled.");
|
|
|
|
goto task_finished;
|
|
|
|
}
|
|
|
|
|
2015-11-23 03:17:27 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
task_finished:
|
|
|
|
task->finished = true;
|
|
|
|
|
|
|
|
nbio_free(nbio->handle);
|
|
|
|
nbio->handle = NULL;
|
|
|
|
nbio->is_finished = false;
|
|
|
|
free(nbio);
|
2015-07-08 18:04:16 +00:00
|
|
|
}
|