2012-10-24 15:17:01 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2016-01-10 03:06:50 +00:00
|
|
|
* Copyright (C) 2011-2016 - Daniel De Matteis
|
2015-10-14 03:12:01 +00:00
|
|
|
*
|
2012-10-24 15:17:01 +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/>.
|
|
|
|
*/
|
2016-02-15 20:49:29 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
2012-10-24 15:17:01 +00:00
|
|
|
#include <stdlib.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
#include <sys/types.h>
|
2012-10-24 15:17:01 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
#include <errno.h>
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2013-04-11 20:35:15 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
#ifdef _XBOX
|
2012-10-24 15:17:01 +00:00
|
|
|
#include <xtl.h>
|
|
|
|
#define setmode _setmode
|
|
|
|
#define INVALID_FILE_ATTRIBUTES -1
|
2013-04-11 20:35:15 +00:00
|
|
|
#else
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
2012-10-24 15:17:01 +00:00
|
|
|
#endif
|
|
|
|
|
2016-02-15 20:49:29 +00:00
|
|
|
#include <boolean.h>
|
|
|
|
|
|
|
|
#include <encodings/utf.h>
|
2015-06-25 09:02:01 +00:00
|
|
|
#include <compat/strl.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
#include <compat/posix_string.h>
|
2015-06-25 09:02:01 +00:00
|
|
|
#include <file/file_path.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-03-20 15:14:40 +00:00
|
|
|
#include <file/archive_file.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
#endif
|
2016-01-19 21:39:48 +00:00
|
|
|
#include <string/stdstring.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
|
|
|
|
#include <retro_miscellaneous.h>
|
2016-03-20 15:29:14 +00:00
|
|
|
#include <streams/file_stream.h>
|
2015-09-21 23:45:16 +00:00
|
|
|
#include <retro_stat.h>
|
2016-02-15 00:22:28 +00:00
|
|
|
#include <retro_assert.h>
|
2015-06-25 09:02:01 +00:00
|
|
|
|
2016-03-20 13:53:54 +00:00
|
|
|
#include <lists/string_list.h>
|
2016-02-15 20:49:29 +00:00
|
|
|
#include <string/stdstring.h>
|
|
|
|
|
2016-03-22 02:13:33 +00:00
|
|
|
#include "defaults.h"
|
2015-07-01 22:47:00 +00:00
|
|
|
#include "msg_hash.h"
|
2015-06-25 09:02:01 +00:00
|
|
|
#include "content.h"
|
|
|
|
#include "general.h"
|
|
|
|
#include "dynamic.h"
|
|
|
|
#include "movie.h"
|
|
|
|
#include "patch.h"
|
|
|
|
#include "system.h"
|
2016-02-15 00:22:28 +00:00
|
|
|
#include "retroarch.h"
|
|
|
|
#include "command_event.h"
|
2016-01-27 05:46:59 +00:00
|
|
|
#include "libretro_version_1.h"
|
2015-11-23 11:03:38 +00:00
|
|
|
#include "verbosity.h"
|
2015-10-27 17:50:41 +00:00
|
|
|
|
2016-02-15 20:49:29 +00:00
|
|
|
#ifdef HAVE_7ZIP
|
|
|
|
#include "deps/7zip/7z.h"
|
|
|
|
#include "deps/7zip/7zAlloc.h"
|
|
|
|
#include "deps/7zip/7zCrc.h"
|
|
|
|
#include "deps/7zip/7zFile.h"
|
|
|
|
#endif
|
|
|
|
|
2016-02-15 03:04:14 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
#include "menu/menu_driver.h"
|
|
|
|
#endif
|
|
|
|
|
2015-10-27 17:50:41 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
2015-10-14 03:12:01 +00:00
|
|
|
#include "cheevos.h"
|
2015-10-27 17:50:41 +00:00
|
|
|
#endif
|
2015-06-25 09:02:01 +00:00
|
|
|
|
2016-02-15 00:22:28 +00:00
|
|
|
#define MAX_ARGS 32
|
|
|
|
|
2015-12-07 06:13:18 +00:00
|
|
|
struct sram_block
|
|
|
|
{
|
|
|
|
unsigned type;
|
|
|
|
void *data;
|
|
|
|
size_t size;
|
|
|
|
};
|
|
|
|
|
2016-02-15 20:49:29 +00:00
|
|
|
#ifdef HAVE_COMPRESSION
|
|
|
|
|
|
|
|
#ifdef HAVE_7ZIP
|
|
|
|
static bool utf16_to_char(uint8_t **utf_data,
|
|
|
|
size_t *dest_len, const uint16_t *in)
|
|
|
|
{
|
|
|
|
unsigned len = 0;
|
|
|
|
|
|
|
|
while (in[len] != '\0')
|
|
|
|
len++;
|
|
|
|
|
|
|
|
utf16_conv_utf8(NULL, dest_len, in, len);
|
|
|
|
*dest_len += 1;
|
|
|
|
*utf_data = (uint8_t*)malloc(*dest_len);
|
|
|
|
if (*utf_data == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return utf16_conv_utf8(*utf_data, dest_len, in, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool utf16_to_char_string(const uint16_t *in, char *s, size_t len)
|
|
|
|
{
|
|
|
|
size_t dest_len = 0;
|
|
|
|
uint8_t *utf16_data = NULL;
|
|
|
|
bool ret = utf16_to_char(&utf16_data, &dest_len, in);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
utf16_data[dest_len] = 0;
|
|
|
|
strlcpy(s, (const char*)utf16_data, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(utf16_data);
|
|
|
|
utf16_data = NULL;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the relative path (needle) from a 7z archive
|
|
|
|
* (path) and allocate a buf for it to write it in.
|
|
|
|
* If optional_outfile is set, extract to that instead
|
|
|
|
* and don't allocate buffer.
|
|
|
|
*/
|
|
|
|
static int content_7zip_file_read(
|
|
|
|
const char *path,
|
|
|
|
const char *needle, void **buf,
|
|
|
|
const char *optional_outfile)
|
|
|
|
{
|
|
|
|
CFileInStream archiveStream;
|
|
|
|
CLookToRead lookStream;
|
|
|
|
CSzArEx db;
|
|
|
|
ISzAlloc allocImp;
|
|
|
|
ISzAlloc allocTempImp;
|
|
|
|
uint8_t *output = 0;
|
|
|
|
long outsize = -1;
|
|
|
|
|
|
|
|
/*These are the allocation routines.
|
|
|
|
* Currently using the non-standard 7zip choices. */
|
|
|
|
allocImp.Alloc = SzAlloc;
|
|
|
|
allocImp.Free = SzFree;
|
|
|
|
allocTempImp.Alloc = SzAllocTemp;
|
|
|
|
allocTempImp.Free = SzFreeTemp;
|
|
|
|
|
|
|
|
if (InFile_Open(&archiveStream.file, path))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not open %s as 7z archive\n.", path);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInStream_CreateVTable(&archiveStream);
|
|
|
|
LookToRead_CreateVTable(&lookStream, False);
|
|
|
|
lookStream.realStream = &archiveStream.s;
|
|
|
|
LookToRead_Init(&lookStream);
|
|
|
|
CrcGenerateTable();
|
|
|
|
SzArEx_Init(&db);
|
|
|
|
|
|
|
|
if (SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp) == SZ_OK)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
bool file_found = false;
|
|
|
|
uint16_t *temp = NULL;
|
|
|
|
size_t temp_size = 0;
|
|
|
|
uint32_t block_index = 0xFFFFFFFF;
|
|
|
|
SRes res = SZ_OK;
|
|
|
|
|
|
|
|
for (i = 0; i < db.db.NumFiles; i++)
|
|
|
|
{
|
|
|
|
size_t len;
|
|
|
|
char infile[PATH_MAX_LENGTH];
|
|
|
|
size_t offset = 0;
|
|
|
|
size_t outSizeProcessed = 0;
|
|
|
|
const CSzFileItem *f = db.db.Files + i;
|
|
|
|
|
|
|
|
/* We skip over everything which is not a directory.
|
|
|
|
* FIXME: Why continue then if f->IsDir is true?*/
|
|
|
|
if (f->IsDir)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = SzArEx_GetFileNameUtf16(&db, i, NULL);
|
|
|
|
|
|
|
|
if (len > temp_size)
|
|
|
|
{
|
|
|
|
free(temp);
|
|
|
|
temp_size = len;
|
|
|
|
temp = (uint16_t *)malloc(temp_size * sizeof(temp[0]));
|
|
|
|
|
|
|
|
if (temp == 0)
|
|
|
|
{
|
|
|
|
res = SZ_ERROR_MEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SzArEx_GetFileNameUtf16(&db, i, temp);
|
|
|
|
res = utf16_to_char_string(temp, infile, sizeof(infile))
|
|
|
|
? SZ_OK : SZ_ERROR_FAIL;
|
|
|
|
|
|
|
|
if (string_is_equal(infile, needle))
|
|
|
|
{
|
|
|
|
size_t output_size = 0;
|
|
|
|
|
|
|
|
RARCH_LOG_OUTPUT("Opened archive %s. Now trying to extract %s\n",
|
|
|
|
path, needle);
|
|
|
|
|
|
|
|
/* C LZMA SDK does not support chunked extraction - see here:
|
|
|
|
* sourceforge.net/p/sevenzip/discussion/45798/thread/6fb59aaf/
|
|
|
|
* */
|
|
|
|
file_found = true;
|
|
|
|
res = SzArEx_Extract(&db, &lookStream.s, i, &block_index,
|
|
|
|
&output, &output_size, &offset, &outSizeProcessed,
|
|
|
|
&allocImp, &allocTempImp);
|
|
|
|
|
|
|
|
if (res != SZ_OK)
|
|
|
|
break; /* This goes to the error section. */
|
|
|
|
|
|
|
|
outsize = outSizeProcessed;
|
|
|
|
|
|
|
|
if (optional_outfile != NULL)
|
|
|
|
{
|
|
|
|
const void *ptr = (const void*)(output + offset);
|
|
|
|
|
|
|
|
if (!retro_write_file(optional_outfile, ptr, outsize))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not open outfilepath %s.\n",
|
|
|
|
optional_outfile);
|
|
|
|
res = SZ_OK;
|
|
|
|
file_found = true;
|
|
|
|
outsize = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*We could either use the 7Zip allocated buffer,
|
|
|
|
* or create our own and use it.
|
|
|
|
* We would however need to realloc anyways, because RetroArch
|
|
|
|
* expects a \0 at the end, therefore we allocate new,
|
|
|
|
* copy and free the old one. */
|
|
|
|
*buf = malloc(outsize + 1);
|
|
|
|
((char*)(*buf))[outsize] = '\0';
|
|
|
|
memcpy(*buf,output + offset,outsize);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(temp);
|
|
|
|
IAlloc_Free(&allocImp, output);
|
|
|
|
|
|
|
|
if (!(file_found && res == SZ_OK))
|
|
|
|
{
|
|
|
|
/* Error handling */
|
|
|
|
if (!file_found)
|
|
|
|
RARCH_ERR("File %s not found in %s\n", needle, path);
|
|
|
|
|
|
|
|
RARCH_ERR("Failed to open compressed file inside 7zip archive.\n");
|
|
|
|
|
|
|
|
outsize = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SzArEx_Free(&db, &allocImp);
|
|
|
|
File_Close(&archiveStream.file);
|
|
|
|
|
|
|
|
return outsize;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct string_list *compressed_7zip_file_list_new(
|
|
|
|
const char *path, const char* ext)
|
|
|
|
{
|
|
|
|
CFileInStream archiveStream;
|
|
|
|
CLookToRead lookStream;
|
|
|
|
CSzArEx db;
|
|
|
|
ISzAlloc allocImp;
|
|
|
|
ISzAlloc allocTempImp;
|
|
|
|
size_t temp_size = 0;
|
|
|
|
struct string_list *list = NULL;
|
|
|
|
|
|
|
|
/* These are the allocation routines - currently using
|
|
|
|
* the non-standard 7zip choices. */
|
|
|
|
allocImp.Alloc = SzAlloc;
|
|
|
|
allocImp.Free = SzFree;
|
|
|
|
allocTempImp.Alloc = SzAllocTemp;
|
|
|
|
allocTempImp.Free = SzFreeTemp;
|
|
|
|
|
|
|
|
if (InFile_Open(&archiveStream.file, path))
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not open %s as 7z archive.\n",path);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
list = string_list_new();
|
|
|
|
|
|
|
|
if (!list)
|
|
|
|
{
|
|
|
|
File_Close(&archiveStream.file);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
FileInStream_CreateVTable(&archiveStream);
|
|
|
|
LookToRead_CreateVTable(&lookStream, False);
|
|
|
|
lookStream.realStream = &archiveStream.s;
|
|
|
|
LookToRead_Init(&lookStream);
|
|
|
|
CrcGenerateTable();
|
|
|
|
SzArEx_Init(&db);
|
|
|
|
|
|
|
|
if (SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp) == SZ_OK)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
|
|
|
struct string_list *ext_list = ext ? string_split(ext, "|"): NULL;
|
|
|
|
SRes res = SZ_OK;
|
|
|
|
uint16_t *temp = NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < db.db.NumFiles; i++)
|
|
|
|
{
|
|
|
|
union string_list_elem_attr attr;
|
|
|
|
char infile[PATH_MAX_LENGTH];
|
|
|
|
const char *file_ext = NULL;
|
|
|
|
size_t len = 0;
|
|
|
|
bool supported_by_core = false;
|
|
|
|
const CSzFileItem *f = db.db.Files + i;
|
|
|
|
|
|
|
|
/* we skip over everything, which is a directory. */
|
|
|
|
if (f->IsDir)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
len = SzArEx_GetFileNameUtf16(&db, i, NULL);
|
|
|
|
|
|
|
|
if (len > temp_size)
|
|
|
|
{
|
|
|
|
free(temp);
|
|
|
|
temp_size = len;
|
|
|
|
temp = (uint16_t *)malloc(temp_size * sizeof(temp[0]));
|
|
|
|
|
|
|
|
if (temp == 0)
|
|
|
|
{
|
|
|
|
res = SZ_ERROR_MEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SzArEx_GetFileNameUtf16(&db, i, temp);
|
|
|
|
res = utf16_to_char_string(temp, infile, sizeof(infile))
|
|
|
|
? SZ_OK : SZ_ERROR_FAIL;
|
|
|
|
file_ext = path_get_extension(infile);
|
|
|
|
|
|
|
|
if (string_list_find_elem_prefix(ext_list, ".", file_ext))
|
|
|
|
supported_by_core = true;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently we only support files without subdirs in the archives.
|
|
|
|
* Folders are not supported (differences between win and lin.
|
|
|
|
* Archives within archives should imho never be supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!supported_by_core)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
attr.i = RARCH_COMPRESSED_FILE_IN_ARCHIVE;
|
|
|
|
|
|
|
|
if (!string_list_append(list, infile, attr))
|
|
|
|
{
|
|
|
|
res = SZ_ERROR_MEM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_free(ext_list);
|
|
|
|
free(temp);
|
|
|
|
|
|
|
|
if (res != SZ_OK)
|
|
|
|
{
|
|
|
|
/* Error handling */
|
|
|
|
RARCH_ERR("Failed to open compressed_file: \"%s\"\n", path);
|
|
|
|
|
|
|
|
string_list_free(list);
|
|
|
|
list = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SzArEx_Free(&db, &allocImp);
|
|
|
|
File_Close(&archiveStream.file);
|
|
|
|
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
struct decomp_state
|
|
|
|
{
|
|
|
|
char *opt_file;
|
|
|
|
char *needle;
|
|
|
|
void **buf;
|
|
|
|
size_t size;
|
|
|
|
bool found;
|
|
|
|
};
|
|
|
|
|
2016-02-26 14:41:28 +00:00
|
|
|
static bool content_zip_file_decompressed_handle(
|
|
|
|
file_archive_file_handle_t *handle,
|
2016-02-15 20:49:29 +00:00
|
|
|
const uint8_t *cdata, uint32_t csize,
|
|
|
|
uint32_t size, uint32_t crc32)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
handle->backend = file_archive_get_default_file_backend();
|
|
|
|
|
|
|
|
if (!handle->backend)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
if (!handle->backend->stream_decompress_data_to_file_init(
|
|
|
|
handle, cdata, csize, size))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
do{
|
|
|
|
ret = handle->backend->stream_decompress_data_to_file_iterate(
|
|
|
|
handle->stream);
|
|
|
|
}while(ret == 0);
|
|
|
|
|
|
|
|
handle->real_checksum = handle->backend->stream_crc_calculate(0,
|
|
|
|
handle->data, size);
|
|
|
|
|
|
|
|
if (handle->real_checksum != crc32)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Inflated checksum did not match CRC32!\n");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle->stream)
|
|
|
|
free(handle->stream);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error:
|
|
|
|
if (handle->stream)
|
|
|
|
free(handle->stream);
|
|
|
|
if (handle->data)
|
|
|
|
free(handle->data);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Extract the relative path (needle) from a
|
|
|
|
* ZIP archive (path) and allocate a buffer for it to write it in.
|
|
|
|
*
|
|
|
|
* optional_outfile if not NULL will be used to extract the file to.
|
|
|
|
* buf will be 0 then.
|
|
|
|
*/
|
|
|
|
|
2016-02-15 22:50:46 +00:00
|
|
|
static int content_zip_file_decompressed(
|
|
|
|
const char *name, const char *valid_exts,
|
|
|
|
const uint8_t *cdata, unsigned cmode,
|
|
|
|
uint32_t csize, uint32_t size,
|
|
|
|
uint32_t crc32, void *userdata)
|
2016-02-15 20:49:29 +00:00
|
|
|
{
|
|
|
|
struct decomp_state *st = (struct decomp_state*)userdata;
|
|
|
|
|
|
|
|
/* Ignore directories. */
|
|
|
|
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
RARCH_LOG("[deflate] Path: %s, CRC32: 0x%x\n", name, crc32);
|
|
|
|
|
|
|
|
if (strstr(name, st->needle))
|
|
|
|
{
|
|
|
|
bool goto_error = false;
|
|
|
|
file_archive_file_handle_t handle = {0};
|
|
|
|
|
|
|
|
st->found = true;
|
|
|
|
|
|
|
|
if (content_zip_file_decompressed_handle(&handle,
|
|
|
|
cdata, csize, size, crc32))
|
|
|
|
{
|
|
|
|
if (st->opt_file != 0)
|
|
|
|
{
|
|
|
|
/* Called in case core has need_fullpath enabled. */
|
|
|
|
char *buf = (char*)malloc(size);
|
|
|
|
|
|
|
|
if (buf)
|
|
|
|
{
|
2016-02-16 04:42:45 +00:00
|
|
|
RARCH_LOG("Extracting file : %s\n", st->opt_file);
|
2016-02-15 20:49:29 +00:00
|
|
|
memcpy(buf, handle.data, size);
|
|
|
|
if (!retro_write_file(st->opt_file, buf, size))
|
|
|
|
goto_error = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(buf);
|
|
|
|
|
|
|
|
st->size = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Called in case core has need_fullpath disabled.
|
|
|
|
* Will copy decompressed content directly into
|
|
|
|
* RetroArch's ROM buffer. */
|
|
|
|
*st->buf = malloc(size);
|
|
|
|
memcpy(*st->buf, handle.data, size);
|
|
|
|
|
|
|
|
st->size = size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handle.data)
|
|
|
|
free(handle.data);
|
|
|
|
|
|
|
|
if (goto_error)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int content_zip_file_read(
|
|
|
|
const char *path,
|
|
|
|
const char *needle, void **buf,
|
|
|
|
const char* optional_outfile)
|
|
|
|
{
|
|
|
|
file_archive_transfer_t zlib;
|
|
|
|
struct decomp_state st;
|
|
|
|
bool returnerr = true;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
zlib.type = ZLIB_TRANSFER_INIT;
|
|
|
|
|
|
|
|
st.needle = NULL;
|
|
|
|
st.opt_file = NULL;
|
|
|
|
st.found = false;
|
|
|
|
st.buf = buf;
|
|
|
|
|
|
|
|
if (needle)
|
|
|
|
st.needle = strdup(needle);
|
|
|
|
if (optional_outfile)
|
|
|
|
st.opt_file = strdup(optional_outfile);
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ret = file_archive_parse_file_iterate(&zlib, &returnerr, path,
|
|
|
|
"", content_zip_file_decompressed, &st);
|
|
|
|
if (!returnerr)
|
|
|
|
break;
|
|
|
|
}while(ret == 0 && !st.found);
|
|
|
|
|
|
|
|
file_archive_parse_file_iterate_stop(&zlib);
|
|
|
|
|
|
|
|
if (st.opt_file)
|
|
|
|
free(st.opt_file);
|
|
|
|
if (st.needle)
|
|
|
|
free(st.needle);
|
|
|
|
|
|
|
|
if (!st.found)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return st.size;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_COMPRESSION
|
|
|
|
/* Generic compressed file loader.
|
|
|
|
* Extracts to buf, unless optional_filename != 0
|
|
|
|
* Then extracts to optional_filename and leaves buf alone.
|
|
|
|
*/
|
2016-02-15 20:51:30 +00:00
|
|
|
static int content_file_compressed_read(
|
|
|
|
const char * path, void **buf,
|
2016-02-15 20:49:29 +00:00
|
|
|
const char* optional_filename, ssize_t *length)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
const char* file_ext = NULL;
|
|
|
|
struct string_list *str_list = string_split(path, "#");
|
|
|
|
|
|
|
|
/* Safety check.
|
|
|
|
* If optional_filename and optional_filename
|
|
|
|
* exists, we simply return 0,
|
|
|
|
* hoping that optional_filename is the
|
|
|
|
* same as requested.
|
|
|
|
*/
|
|
|
|
if (optional_filename && path_file_exists(optional_filename))
|
|
|
|
{
|
|
|
|
*length = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We assure that there is something after the '#' symbol.
|
|
|
|
*
|
|
|
|
* This error condition happens for example, when
|
|
|
|
* path = /path/to/file.7z, or
|
|
|
|
* path = /path/to/file.7z#
|
|
|
|
*/
|
|
|
|
if (str_list->size <= 1)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
#if defined(HAVE_7ZIP) || defined(HAVE_ZLIB)
|
|
|
|
file_ext = path_get_extension(str_list->elems[0].data);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_7ZIP
|
|
|
|
if (string_is_equal_noncase(file_ext, "7z"))
|
|
|
|
{
|
|
|
|
*length = content_7zip_file_read(str_list->elems[0].data,
|
|
|
|
str_list->elems[1].data, buf, optional_filename);
|
|
|
|
if (*length != -1)
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
if (string_is_equal_noncase(file_ext, "zip"))
|
|
|
|
{
|
|
|
|
*length = content_zip_file_read(str_list->elems[0].data,
|
|
|
|
str_list->elems[1].data, buf, optional_filename);
|
|
|
|
if (*length != -1)
|
|
|
|
ret = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
string_list_free(str_list);
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("Could not extract string and substring from "
|
|
|
|
": %s.\n", path);
|
|
|
|
string_list_free(str_list);
|
|
|
|
*length = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* content_file_read:
|
|
|
|
* @path : path to file.
|
|
|
|
* @buf : buffer to allocate and read the contents of the
|
|
|
|
* file into. Needs to be freed manually.
|
|
|
|
* @length : Number of items read, -1 on error.
|
|
|
|
*
|
|
|
|
* Read the contents of a file into @buf. Will call content_file_compressed_read
|
|
|
|
* if path contains a compressed file, otherwise will call retro_read_file().
|
|
|
|
*
|
|
|
|
* Returns: 1 if file read, 0 on error.
|
|
|
|
*/
|
2016-02-15 20:51:30 +00:00
|
|
|
static int content_file_read(const char *path, void **buf, ssize_t *length)
|
2016-02-15 20:49:29 +00:00
|
|
|
{
|
|
|
|
#ifdef HAVE_COMPRESSION
|
|
|
|
if (path_contains_compressed_file(path))
|
|
|
|
{
|
|
|
|
if (content_file_compressed_read(path, buf, NULL, length))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return retro_read_file(path, buf, length);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct string_list *compressed_file_list_new(const char *path,
|
|
|
|
const char* ext)
|
|
|
|
{
|
|
|
|
#if defined(HAVE_ZLIB) || defined(HAVE_7ZIP)
|
|
|
|
const char* file_ext = path_get_extension(path);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_7ZIP
|
|
|
|
if (string_is_equal_noncase(file_ext, "7z"))
|
|
|
|
return compressed_7zip_file_list_new(path,ext);
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
if (string_is_equal_noncase(file_ext, "zip"))
|
|
|
|
return file_archive_get_file_list(path, ext);
|
|
|
|
#endif
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-02-15 00:22:28 +00:00
|
|
|
static void check_defaults_dir_create_dir(const char *path)
|
|
|
|
{
|
|
|
|
if (path_is_directory(path))
|
|
|
|
return;
|
|
|
|
path_mkdir(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void check_defaults_dirs(void)
|
|
|
|
{
|
|
|
|
if (*g_defaults.dir.core_assets)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.core_assets);
|
|
|
|
if (*g_defaults.dir.remap)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.remap);
|
|
|
|
if (*g_defaults.dir.screenshot)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.screenshot);
|
|
|
|
if (*g_defaults.dir.core)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.core);
|
|
|
|
if (*g_defaults.dir.autoconfig)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.autoconfig);
|
|
|
|
if (*g_defaults.dir.audio_filter)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.audio_filter);
|
|
|
|
if (*g_defaults.dir.video_filter)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.video_filter);
|
|
|
|
if (*g_defaults.dir.assets)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.assets);
|
|
|
|
if (*g_defaults.dir.playlist)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.playlist);
|
|
|
|
if (*g_defaults.dir.core)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.core);
|
|
|
|
if (*g_defaults.dir.core_info)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.core_info);
|
|
|
|
if (*g_defaults.dir.overlay)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.overlay);
|
|
|
|
if (*g_defaults.dir.port)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.port);
|
|
|
|
if (*g_defaults.dir.shader)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.shader);
|
|
|
|
if (*g_defaults.dir.savestate)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.savestate);
|
|
|
|
if (*g_defaults.dir.sram)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.sram);
|
|
|
|
if (*g_defaults.dir.system)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.system);
|
|
|
|
if (*g_defaults.dir.resampler)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.resampler);
|
|
|
|
if (*g_defaults.dir.menu_config)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.menu_config);
|
|
|
|
if (*g_defaults.dir.content_history)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.content_history);
|
|
|
|
if (*g_defaults.dir.cache)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.cache);
|
|
|
|
if (*g_defaults.dir.database)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.database);
|
|
|
|
if (*g_defaults.dir.cursor)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.cursor);
|
|
|
|
if (*g_defaults.dir.cheats)
|
|
|
|
check_defaults_dir_create_dir(g_defaults.dir.cheats);
|
|
|
|
}
|
|
|
|
|
2016-02-15 02:56:10 +00:00
|
|
|
void content_push_to_history_playlist(bool do_push,
|
|
|
|
const char *path, void *data)
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
struct retro_system_info *info = (struct retro_system_info*)data;
|
|
|
|
|
|
|
|
/* If the history list is not enabled, early return. */
|
|
|
|
if (!settings->history_list_enable)
|
|
|
|
return;
|
|
|
|
if (!g_defaults.history)
|
|
|
|
return;
|
|
|
|
if (!do_push)
|
|
|
|
return;
|
|
|
|
|
|
|
|
content_playlist_push(g_defaults.history,
|
|
|
|
path,
|
|
|
|
NULL,
|
|
|
|
settings->libretro,
|
|
|
|
info->library_name,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2016-02-15 00:22:28 +00:00
|
|
|
/**
|
2016-02-15 00:34:15 +00:00
|
|
|
* content_load_init_wrap:
|
2016-02-15 00:22:28 +00:00
|
|
|
* @args : Input arguments.
|
|
|
|
* @argc : Count of arguments.
|
|
|
|
* @argv : Arguments.
|
|
|
|
*
|
|
|
|
* Generates an @argc and @argv pair based on @args
|
|
|
|
* of type rarch_main_wrap.
|
|
|
|
**/
|
2016-02-15 00:34:15 +00:00
|
|
|
static void content_load_init_wrap(
|
2016-02-15 00:22:28 +00:00
|
|
|
const struct rarch_main_wrap *args,
|
|
|
|
int *argc, char **argv)
|
|
|
|
{
|
|
|
|
#ifdef HAVE_FILE_LOGGER
|
|
|
|
int i;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
*argc = 0;
|
|
|
|
argv[(*argc)++] = strdup("retroarch");
|
|
|
|
|
|
|
|
if (!args->no_content)
|
|
|
|
{
|
|
|
|
if (args->content_path)
|
|
|
|
{
|
|
|
|
RARCH_LOG("Using content: %s.\n", args->content_path);
|
|
|
|
argv[(*argc)++] = strdup(args->content_path);
|
|
|
|
}
|
|
|
|
#ifdef HAVE_MENU
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_LOG("No content, starting dummy core.\n");
|
|
|
|
argv[(*argc)++] = strdup("--menu");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args->sram_path)
|
|
|
|
{
|
|
|
|
argv[(*argc)++] = strdup("-s");
|
|
|
|
argv[(*argc)++] = strdup(args->sram_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args->state_path)
|
|
|
|
{
|
|
|
|
argv[(*argc)++] = strdup("-S");
|
|
|
|
argv[(*argc)++] = strdup(args->state_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args->config_path)
|
|
|
|
{
|
|
|
|
argv[(*argc)++] = strdup("-c");
|
|
|
|
argv[(*argc)++] = strdup(args->config_path);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_DYNAMIC
|
|
|
|
if (args->libretro_path)
|
|
|
|
{
|
|
|
|
argv[(*argc)++] = strdup("-L");
|
|
|
|
argv[(*argc)++] = strdup(args->libretro_path);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (args->verbose)
|
|
|
|
argv[(*argc)++] = strdup("-v");
|
|
|
|
|
|
|
|
#ifdef HAVE_FILE_LOGGER
|
|
|
|
for (i = 0; i < *argc; i++)
|
|
|
|
RARCH_LOG("arg #%d: %s\n", i, argv[i]);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* content_load:
|
|
|
|
*
|
|
|
|
* Loads content file and starts up RetroArch.
|
|
|
|
* If no content file can be loaded, will start up RetroArch
|
|
|
|
* as-is.
|
|
|
|
*
|
|
|
|
* Returns: false (0) if rarch_main_init failed, otherwise true (1).
|
|
|
|
**/
|
2016-02-16 04:34:33 +00:00
|
|
|
static bool content_load(content_ctx_info_t *info)
|
2016-02-15 00:22:28 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
bool retval = true;
|
|
|
|
int rarch_argc = 0;
|
|
|
|
char *rarch_argv[MAX_ARGS] = {NULL};
|
|
|
|
char *argv_copy [MAX_ARGS] = {NULL};
|
2016-02-16 04:34:33 +00:00
|
|
|
char **rarch_argv_ptr = (char**)info->argv;
|
|
|
|
int *rarch_argc_ptr = (int*)&info->argc;
|
2016-02-15 00:22:28 +00:00
|
|
|
struct rarch_main_wrap *wrap_args = (struct rarch_main_wrap*)
|
|
|
|
calloc(1, sizeof(*wrap_args));
|
|
|
|
|
|
|
|
if (!wrap_args)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
retro_assert(wrap_args);
|
|
|
|
|
2016-02-16 04:34:33 +00:00
|
|
|
if (info->environ_get)
|
|
|
|
info->environ_get(rarch_argc_ptr,
|
|
|
|
rarch_argv_ptr, info->args, wrap_args);
|
2016-02-15 00:22:28 +00:00
|
|
|
|
|
|
|
if (wrap_args->touched)
|
|
|
|
{
|
2016-02-15 00:34:15 +00:00
|
|
|
content_load_init_wrap(wrap_args, &rarch_argc, rarch_argv);
|
2016-02-15 00:22:28 +00:00
|
|
|
memcpy(argv_copy, rarch_argv, sizeof(rarch_argv));
|
|
|
|
rarch_argv_ptr = (char**)rarch_argv;
|
|
|
|
rarch_argc_ptr = (int*)&rarch_argc;
|
|
|
|
}
|
|
|
|
|
|
|
|
rarch_ctl(RARCH_CTL_MAIN_DEINIT, NULL);
|
|
|
|
|
|
|
|
wrap_args->argc = *rarch_argc_ptr;
|
|
|
|
wrap_args->argv = rarch_argv_ptr;
|
|
|
|
|
|
|
|
if (!rarch_ctl(RARCH_CTL_MAIN_INIT, wrap_args))
|
|
|
|
{
|
|
|
|
retval = false;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
2016-02-15 03:04:14 +00:00
|
|
|
#ifdef HAVE_MENU
|
|
|
|
menu_driver_ctl(RARCH_MENU_CTL_SHADER_MANAGER_INIT, NULL);
|
|
|
|
#endif
|
|
|
|
event_cmd_ctl(EVENT_CMD_HISTORY_INIT, NULL);
|
2016-02-15 00:22:28 +00:00
|
|
|
event_cmd_ctl(EVENT_CMD_RESUME, NULL);
|
2016-02-15 03:04:14 +00:00
|
|
|
event_cmd_ctl(EVENT_CMD_VIDEO_SET_ASPECT_RATIO, NULL);
|
2016-02-15 00:22:28 +00:00
|
|
|
|
|
|
|
check_defaults_dirs();
|
|
|
|
|
|
|
|
frontend_driver_process_args(rarch_argc_ptr, rarch_argv_ptr);
|
2016-02-15 03:04:14 +00:00
|
|
|
frontend_driver_content_loaded();
|
2016-02-15 00:22:28 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
for (i = 0; i < ARRAY_SIZE(argv_copy); i++)
|
|
|
|
free(argv_copy[i]);
|
|
|
|
free(wrap_args);
|
|
|
|
return retval;
|
|
|
|
}
|
2015-11-30 18:09:12 +00:00
|
|
|
|
2015-01-08 02:58:14 +00:00
|
|
|
/**
|
|
|
|
* read_content_file:
|
|
|
|
* @path : buffer of the content file.
|
|
|
|
* @buf : size of the content file.
|
2015-02-16 02:31:37 +00:00
|
|
|
* @length : size of the content file that has been read from.
|
2015-01-08 02:58:14 +00:00
|
|
|
*
|
2015-03-18 03:54:34 +00:00
|
|
|
* Read the content file. If read into memory, also performs soft patching
|
2015-01-08 02:58:14 +00:00
|
|
|
* (see patch_content function) in case soft patching has not been
|
|
|
|
* blocked by the enduser.
|
|
|
|
*
|
2015-02-16 02:31:37 +00:00
|
|
|
* Returns: true if successful, false on error.
|
2015-01-08 02:58:14 +00:00
|
|
|
**/
|
2015-03-18 03:54:34 +00:00
|
|
|
static bool read_content_file(unsigned i, const char *path, void **buf,
|
2015-02-16 02:46:27 +00:00
|
|
|
ssize_t *length)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-22 15:09:48 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2016-02-15 22:49:23 +00:00
|
|
|
content_stream_t stream_info;
|
2016-01-22 15:09:48 +00:00
|
|
|
uint32_t *content_crc_ptr = NULL;
|
|
|
|
#endif
|
|
|
|
uint8_t *ret_buf = NULL;
|
|
|
|
global_t *global = global_get_ptr();
|
2014-11-24 05:21:52 +00:00
|
|
|
|
2016-02-16 04:18:39 +00:00
|
|
|
RARCH_LOG("%s: %s.\n",
|
|
|
|
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
|
|
|
|
if (!content_file_read(path, (void**) &ret_buf, length))
|
|
|
|
return false;
|
2014-09-02 15:05:15 +00:00
|
|
|
|
2015-06-15 00:00:17 +00:00
|
|
|
if (*length < 0)
|
2015-02-16 02:31:37 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2015-03-18 03:54:34 +00:00
|
|
|
if (i != 0)
|
|
|
|
return true;
|
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
/* Attempt to apply a patch. */
|
2015-07-27 15:18:10 +00:00
|
|
|
if (!global->patch.block_patch)
|
2015-02-16 02:31:37 +00:00
|
|
|
patch_content(&ret_buf, length);
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2015-04-19 14:59:11 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2016-01-22 15:09:48 +00:00
|
|
|
content_ctl(CONTENT_CTL_GET_CRC, &content_crc_ptr);
|
2016-02-15 22:49:23 +00:00
|
|
|
|
|
|
|
stream_info.a = 0;
|
|
|
|
stream_info.b = ret_buf;
|
|
|
|
stream_info.c = *length;
|
|
|
|
|
|
|
|
content_ctl(CONTENT_CTL_STREAM_CRC_CALCULATE, &stream_info);
|
|
|
|
|
|
|
|
*content_crc_ptr = stream_info.crc;
|
|
|
|
|
2016-01-22 15:09:48 +00:00
|
|
|
|
|
|
|
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)*content_crc_ptr);
|
2015-04-19 14:59:11 +00:00
|
|
|
#endif
|
2012-10-24 15:17:01 +00:00
|
|
|
*buf = ret_buf;
|
2015-02-16 02:31:37 +00:00
|
|
|
|
|
|
|
return true;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-09 14:33:58 +00:00
|
|
|
/**
|
|
|
|
* dump_to_file_desperate:
|
|
|
|
* @data : pointer to data buffer.
|
|
|
|
* @size : size of @data.
|
|
|
|
* @type : type of file to be saved.
|
|
|
|
*
|
|
|
|
* Attempt to save valuable RAM data somewhere.
|
|
|
|
**/
|
2016-01-26 23:06:06 +00:00
|
|
|
static bool dump_to_file_desperate(const void *data,
|
2014-09-02 03:10:54 +00:00
|
|
|
size_t size, unsigned type)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-12-31 17:51:29 +00:00
|
|
|
time_t time_;
|
2015-12-07 06:13:18 +00:00
|
|
|
char timebuf[256];
|
2016-01-18 23:47:27 +00:00
|
|
|
char path[PATH_MAX_LENGTH];
|
2012-10-24 15:17:01 +00:00
|
|
|
#if defined(_WIN32) && !defined(_XBOX)
|
|
|
|
const char *base = getenv("APPDATA");
|
|
|
|
#elif defined(__CELLOS_LV2__) || defined(_XBOX)
|
|
|
|
const char *base = NULL;
|
|
|
|
#else
|
|
|
|
const char *base = getenv("HOME");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!base)
|
2016-01-26 23:06:06 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2014-04-04 12:58:42 +00:00
|
|
|
snprintf(path, sizeof(path), "%s/RetroArch-recovery-%u", base, type);
|
2012-10-24 15:17:01 +00:00
|
|
|
|
|
|
|
time(&time_);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_));
|
|
|
|
strlcat(path, timebuf, sizeof(path));
|
|
|
|
|
2016-01-26 23:06:06 +00:00
|
|
|
if (!retro_write_file(path, data, size))
|
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-26 23:06:06 +00:00
|
|
|
RARCH_WARN("Succeeded in saving RAM data to \"%s\".\n", path);
|
|
|
|
return true;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 02:58:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* save_state:
|
2015-01-08 13:41:50 +00:00
|
|
|
* @path : path of saved state that shall be written to.
|
2015-01-08 02:58:14 +00:00
|
|
|
*
|
|
|
|
* Save a state from memory to disk.
|
|
|
|
*
|
|
|
|
* Returns: true if successful, false otherwise.
|
|
|
|
**/
|
2016-01-19 21:33:37 +00:00
|
|
|
static bool content_save_state(const char *path)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-27 06:17:53 +00:00
|
|
|
retro_ctx_serialize_info_t serial_info;
|
2016-01-27 05:46:59 +00:00
|
|
|
retro_ctx_size_info_t info;
|
2015-06-12 15:00:37 +00:00
|
|
|
bool ret = false;
|
|
|
|
void *data = NULL;
|
2016-01-27 05:46:59 +00:00
|
|
|
|
|
|
|
core_ctl(CORE_CTL_RETRO_SERIALIZE_SIZE, &info);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2015-07-01 22:47:00 +00:00
|
|
|
RARCH_LOG("%s: \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_SAVING_STATE),
|
|
|
|
path);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2016-01-27 05:46:59 +00:00
|
|
|
if (info.size == 0)
|
2012-10-24 15:17:01 +00:00
|
|
|
return false;
|
|
|
|
|
2016-01-27 05:46:59 +00:00
|
|
|
data = malloc(info.size);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
if (!data)
|
|
|
|
return false;
|
|
|
|
|
2015-10-14 03:12:01 +00:00
|
|
|
RARCH_LOG("%s: %d %s.\n",
|
2015-07-01 22:47:00 +00:00
|
|
|
msg_hash_to_str(MSG_STATE_SIZE),
|
2016-01-27 05:46:59 +00:00
|
|
|
(int)info.size,
|
2015-07-01 22:54:10 +00:00
|
|
|
msg_hash_to_str(MSG_BYTES));
|
2016-01-27 06:17:53 +00:00
|
|
|
|
|
|
|
serial_info.data = data;
|
|
|
|
serial_info.size = info.size;
|
|
|
|
ret = core_ctl(CORE_CTL_RETRO_SERIALIZE, &serial_info);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
if (ret)
|
2016-01-27 05:46:59 +00:00
|
|
|
ret = retro_write_file(path, data, info.size);
|
2016-01-19 16:24:42 +00:00
|
|
|
else
|
|
|
|
{
|
2015-10-14 03:12:01 +00:00
|
|
|
RARCH_ERR("%s \"%s\".\n",
|
2015-07-01 22:47:00 +00:00
|
|
|
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
|
|
|
|
path);
|
2016-01-19 16:24:42 +00:00
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
|
|
|
|
free(data);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2012-10-24 15:17:01 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-01-08 02:58:14 +00:00
|
|
|
/**
|
2016-01-19 21:33:37 +00:00
|
|
|
* content_load_state:
|
2015-01-08 02:59:10 +00:00
|
|
|
* @path : path that state will be loaded from.
|
2015-01-08 02:58:14 +00:00
|
|
|
*
|
|
|
|
* Load a state from disk to memory.
|
|
|
|
*
|
|
|
|
* Returns: true if successful, false otherwise.
|
|
|
|
**/
|
2016-01-19 21:33:37 +00:00
|
|
|
static bool content_load_state(const char *path)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2013-10-19 17:39:38 +00:00
|
|
|
unsigned i;
|
2015-03-20 19:43:22 +00:00
|
|
|
ssize_t size;
|
2016-01-27 06:17:53 +00:00
|
|
|
retro_ctx_serialize_info_t serial_info;
|
2015-03-22 06:37:25 +00:00
|
|
|
unsigned num_blocks = 0;
|
|
|
|
void *buf = NULL;
|
2014-12-31 17:51:29 +00:00
|
|
|
struct sram_block *blocks = NULL;
|
2015-03-22 06:37:25 +00:00
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
global_t *global = global_get_ptr();
|
2016-01-30 02:59:30 +00:00
|
|
|
bool ret = retro_read_file(path, &buf, &size);
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2015-07-01 22:47:00 +00:00
|
|
|
RARCH_LOG("%s: \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_LOADING_STATE),
|
|
|
|
path);
|
2013-10-19 17:39:38 +00:00
|
|
|
|
2015-02-16 02:31:37 +00:00
|
|
|
if (!ret || size < 0)
|
2016-01-21 01:41:29 +00:00
|
|
|
goto error;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2015-07-01 22:54:10 +00:00
|
|
|
RARCH_LOG("%s: %u %s.\n",
|
2015-07-01 22:47:00 +00:00
|
|
|
msg_hash_to_str(MSG_STATE_SIZE),
|
2015-07-01 22:54:10 +00:00
|
|
|
(unsigned)size,
|
|
|
|
msg_hash_to_str(MSG_BYTES));
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2015-03-21 03:43:18 +00:00
|
|
|
if (settings->block_sram_overwrite && global->savefiles
|
|
|
|
&& global->savefiles->size)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-07-01 22:54:10 +00:00
|
|
|
RARCH_LOG("%s.\n",
|
|
|
|
msg_hash_to_str(MSG_BLOCKING_SRAM_OVERWRITE));
|
2014-09-02 03:10:54 +00:00
|
|
|
blocks = (struct sram_block*)
|
2015-03-21 03:43:18 +00:00
|
|
|
calloc(global->savefiles->size, sizeof(*blocks));
|
2014-09-02 03:10:54 +00:00
|
|
|
|
2014-04-04 13:35:46 +00:00
|
|
|
if (blocks)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-03-21 03:43:18 +00:00
|
|
|
num_blocks = global->savefiles->size;
|
2014-04-04 13:35:46 +00:00
|
|
|
for (i = 0; i < num_blocks; i++)
|
2015-03-21 03:43:18 +00:00
|
|
|
blocks[i].type = global->savefiles->elems[i].attr.i;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-28 01:58:53 +00:00
|
|
|
|
2014-04-04 13:35:46 +00:00
|
|
|
for (i = 0; i < num_blocks; i++)
|
2016-01-28 01:58:53 +00:00
|
|
|
{
|
|
|
|
retro_ctx_memory_info_t mem_info;
|
|
|
|
|
|
|
|
mem_info.id = blocks[i].type;
|
|
|
|
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
|
|
|
|
|
|
|
|
blocks[i].size = mem_info.size;
|
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2014-04-04 13:35:46 +00:00
|
|
|
for (i = 0; i < num_blocks; i++)
|
|
|
|
if (blocks[i].size)
|
|
|
|
blocks[i].data = malloc(blocks[i].size);
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
/* Backup current SRAM which is overwritten by unserialize. */
|
2014-04-04 13:35:46 +00:00
|
|
|
for (i = 0; i < num_blocks; i++)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-04-04 13:35:46 +00:00
|
|
|
if (blocks[i].data)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-28 01:58:53 +00:00
|
|
|
retro_ctx_memory_info_t mem_info;
|
|
|
|
const void *ptr = NULL;
|
|
|
|
|
|
|
|
mem_info.id = blocks[i].type;
|
|
|
|
|
|
|
|
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
|
|
|
|
|
|
|
|
ptr = mem_info.data;
|
2012-10-24 15:17:01 +00:00
|
|
|
if (ptr)
|
2014-04-04 13:35:46 +00:00
|
|
|
memcpy(blocks[i].data, ptr, blocks[i].size);
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-27 06:17:53 +00:00
|
|
|
serial_info.data_const = buf;
|
|
|
|
serial_info.size = size;
|
|
|
|
ret = core_ctl(CORE_CTL_RETRO_UNSERIALIZE, &serial_info);
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2014-09-02 03:10:54 +00:00
|
|
|
/* Flush back. */
|
2014-04-04 13:35:46 +00:00
|
|
|
for (i = 0; i < num_blocks; i++)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-04-04 13:35:46 +00:00
|
|
|
if (blocks[i].data)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-28 01:58:53 +00:00
|
|
|
retro_ctx_memory_info_t mem_info;
|
|
|
|
void *ptr = NULL;
|
|
|
|
|
|
|
|
mem_info.id = blocks[i].type;
|
|
|
|
|
|
|
|
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
|
|
|
|
|
|
|
|
ptr = mem_info.data;
|
2012-10-24 15:17:01 +00:00
|
|
|
if (ptr)
|
2014-04-04 13:35:46 +00:00
|
|
|
memcpy(ptr, blocks[i].data, blocks[i].size);
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-04 13:35:46 +00:00
|
|
|
for (i = 0; i < num_blocks; i++)
|
|
|
|
free(blocks[i].data);
|
|
|
|
free(blocks);
|
2014-10-13 17:48:50 +00:00
|
|
|
free(buf);
|
2016-01-27 07:50:23 +00:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
return true;
|
2016-01-21 01:41:29 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("%s \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE),
|
|
|
|
path);
|
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 13:41:50 +00:00
|
|
|
/**
|
|
|
|
* load_ram_file:
|
|
|
|
* @path : path of RAM state that will be loaded from.
|
|
|
|
* @type : type of memory
|
|
|
|
*
|
|
|
|
* Load a RAM state from disk to memory.
|
|
|
|
*/
|
2016-02-03 14:25:37 +00:00
|
|
|
static bool load_ram_file(void *data)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-02-16 02:46:27 +00:00
|
|
|
ssize_t rc;
|
2016-01-27 08:31:31 +00:00
|
|
|
retro_ctx_memory_info_t mem_info;
|
2016-02-03 14:25:37 +00:00
|
|
|
void *buf = NULL;
|
|
|
|
ram_type_t *ram = (ram_type_t*)data;
|
|
|
|
|
|
|
|
if (!ram)
|
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-28 01:53:43 +00:00
|
|
|
mem_info.id = ram->type;
|
2016-01-27 08:31:31 +00:00
|
|
|
|
|
|
|
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
|
|
|
|
|
|
|
|
if (mem_info.size == 0 || !mem_info.data)
|
2016-01-25 06:15:05 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-30 02:59:30 +00:00
|
|
|
if (!retro_read_file(ram->path, &buf, &rc))
|
2016-01-25 06:15:05 +00:00
|
|
|
return false;
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2013-10-13 15:28:17 +00:00
|
|
|
if (rc > 0)
|
|
|
|
{
|
2016-01-27 08:31:31 +00:00
|
|
|
if (rc > (ssize_t)mem_info.size)
|
2013-10-13 15:28:17 +00:00
|
|
|
{
|
2016-01-26 04:48:31 +00:00
|
|
|
RARCH_WARN("SRAM is larger than implementation expects, "
|
|
|
|
"doing partial load (truncating %u %s %s %u).\n",
|
2015-07-01 22:54:10 +00:00
|
|
|
(unsigned)rc,
|
|
|
|
msg_hash_to_str(MSG_BYTES),
|
|
|
|
msg_hash_to_str(MSG_TO),
|
2016-01-27 08:31:31 +00:00
|
|
|
(unsigned)mem_info.size);
|
|
|
|
rc = mem_info.size;
|
2013-10-13 15:28:17 +00:00
|
|
|
}
|
2016-01-27 08:31:31 +00:00
|
|
|
memcpy(mem_info.data, buf, rc);
|
2013-10-13 15:28:17 +00:00
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2015-01-08 13:41:50 +00:00
|
|
|
if (buf)
|
|
|
|
free(buf);
|
2016-01-25 06:15:05 +00:00
|
|
|
|
|
|
|
return true;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 13:41:50 +00:00
|
|
|
/**
|
|
|
|
* save_ram_file:
|
|
|
|
* @path : path of RAM state that shall be written to.
|
|
|
|
* @type : type of memory
|
|
|
|
*
|
|
|
|
* Save a RAM state from memory to disk.
|
|
|
|
*
|
|
|
|
*/
|
2016-01-25 06:15:05 +00:00
|
|
|
static bool save_ram_file(ram_type_t *ram)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-27 08:29:18 +00:00
|
|
|
retro_ctx_memory_info_t mem_info;
|
|
|
|
|
2016-01-28 01:53:43 +00:00
|
|
|
mem_info.id = ram->type;
|
2016-01-27 08:29:18 +00:00
|
|
|
|
|
|
|
core_ctl(CORE_CTL_RETRO_GET_MEMORY, &mem_info);
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-27 08:29:18 +00:00
|
|
|
if (!mem_info.data || mem_info.size == 0)
|
2016-01-25 06:15:05 +00:00
|
|
|
return false;
|
2015-01-08 13:41:50 +00:00
|
|
|
|
2016-01-27 08:29:18 +00:00
|
|
|
if (!retro_write_file(ram->path, mem_info.data, mem_info.size))
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2015-07-01 22:47:00 +00:00
|
|
|
RARCH_ERR("%s.\n",
|
|
|
|
msg_hash_to_str(MSG_FAILED_TO_SAVE_SRAM));
|
2015-01-16 01:01:05 +00:00
|
|
|
RARCH_WARN("Attempting to recover ...\n");
|
2016-01-26 23:06:06 +00:00
|
|
|
|
|
|
|
/* In case the file could not be written to,
|
|
|
|
* the fallback function 'dump_to_file_desperate'
|
|
|
|
* will be called. */
|
2016-01-27 08:29:18 +00:00
|
|
|
if (!dump_to_file_desperate(mem_info.data, mem_info.size, ram->type))
|
2016-01-26 23:06:06 +00:00
|
|
|
{
|
|
|
|
RARCH_WARN("Failed ... Cannot recover save file.\n");
|
|
|
|
}
|
2016-01-25 06:15:05 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
2015-01-08 13:41:50 +00:00
|
|
|
|
2015-07-01 22:54:10 +00:00
|
|
|
RARCH_LOG("%s \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_SAVED_SUCCESSFULLY_TO),
|
2016-01-25 06:15:05 +00:00
|
|
|
ram->path);
|
|
|
|
|
|
|
|
return true;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 23:38:34 +00:00
|
|
|
/* Load the content into memory. */
|
2016-01-19 16:42:14 +00:00
|
|
|
static bool load_content_into_memory(
|
2016-01-19 16:41:14 +00:00
|
|
|
struct retro_game_info *info,
|
|
|
|
unsigned i,
|
|
|
|
const char *path)
|
2015-02-16 05:44:29 +00:00
|
|
|
{
|
|
|
|
ssize_t len;
|
2015-05-10 03:46:46 +00:00
|
|
|
bool ret = false;
|
|
|
|
|
|
|
|
if (i == 0)
|
2016-01-19 16:41:14 +00:00
|
|
|
{
|
|
|
|
/* First content file is significant, attempt to do patching,
|
|
|
|
* CRC checking, etc. */
|
2015-05-10 03:46:46 +00:00
|
|
|
ret = read_content_file(i, path, (void**)&info->data, &len);
|
2016-01-19 16:41:14 +00:00
|
|
|
}
|
2015-05-10 03:46:46 +00:00
|
|
|
else
|
2016-02-15 20:40:54 +00:00
|
|
|
ret = content_file_read(path, (void**)&info->data, &len);
|
2015-02-16 05:44:29 +00:00
|
|
|
|
|
|
|
if (!ret || len < 0)
|
2016-01-19 16:41:14 +00:00
|
|
|
goto error;
|
2015-02-16 05:44:29 +00:00
|
|
|
|
|
|
|
info->size = len;
|
|
|
|
|
|
|
|
return true;
|
2016-01-19 16:41:14 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
RARCH_ERR("%s \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
|
|
|
|
path);
|
|
|
|
return false;
|
2015-02-16 05:44:29 +00:00
|
|
|
}
|
|
|
|
|
2016-01-18 23:34:43 +00:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-01-19 16:43:37 +00:00
|
|
|
static bool load_content_from_compressed_archive(
|
2016-01-19 21:17:54 +00:00
|
|
|
struct string_list *temporary_content,
|
2015-02-16 05:44:29 +00:00
|
|
|
struct retro_game_info *info, unsigned i,
|
|
|
|
struct string_list* additional_path_allocs,
|
|
|
|
bool need_fullpath, const char *path)
|
|
|
|
{
|
|
|
|
union string_list_elem_attr attributes;
|
2016-01-26 07:21:44 +00:00
|
|
|
char new_path[PATH_MAX_LENGTH];
|
2016-01-18 23:47:27 +00:00
|
|
|
char new_basedir[PATH_MAX_LENGTH];
|
2016-03-01 06:20:16 +00:00
|
|
|
ssize_t new_path_len = 0;
|
2015-06-12 15:00:37 +00:00
|
|
|
bool ret = false;
|
|
|
|
settings_t *settings = config_get_ptr();
|
2015-12-10 21:30:25 +00:00
|
|
|
rarch_system_info_t *sys_info= NULL;
|
2016-01-18 23:34:43 +00:00
|
|
|
|
2015-12-10 21:30:25 +00:00
|
|
|
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &sys_info);
|
2015-02-16 05:44:29 +00:00
|
|
|
|
2015-06-25 10:36:55 +00:00
|
|
|
if (sys_info && sys_info->info.block_extract)
|
2015-02-16 05:44:29 +00:00
|
|
|
return true;
|
2015-11-30 18:09:12 +00:00
|
|
|
if (!need_fullpath || !path_contains_compressed_file(path))
|
2015-02-16 05:44:29 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
RARCH_LOG("Compressed file in case of need_fullpath."
|
2016-01-26 05:49:35 +00:00
|
|
|
" Now extracting to temporary directory.\n");
|
2015-02-16 05:44:29 +00:00
|
|
|
|
2015-10-26 23:48:35 +00:00
|
|
|
strlcpy(new_basedir, settings->cache_directory,
|
2015-02-16 05:44:29 +00:00
|
|
|
sizeof(new_basedir));
|
|
|
|
|
2016-01-19 21:39:48 +00:00
|
|
|
if (string_is_empty(new_basedir) || !path_is_directory(new_basedir))
|
2015-02-16 05:44:29 +00:00
|
|
|
{
|
2015-10-26 23:48:35 +00:00
|
|
|
RARCH_WARN("Tried extracting to cache directory, but "
|
|
|
|
"cache directory was not set or found. "
|
|
|
|
"Setting cache directory to directory "
|
2015-02-16 05:44:29 +00:00
|
|
|
"derived by basename...\n");
|
|
|
|
fill_pathname_basedir(new_basedir, path,
|
|
|
|
sizeof(new_basedir));
|
|
|
|
}
|
|
|
|
|
|
|
|
attributes.i = 0;
|
|
|
|
fill_pathname_join(new_path, new_basedir,
|
2016-01-26 07:21:44 +00:00
|
|
|
path_basename(path), sizeof(new_path));
|
2015-02-16 05:44:29 +00:00
|
|
|
|
2016-02-15 20:40:54 +00:00
|
|
|
ret = content_file_compressed_read(path, NULL, new_path, &new_path_len);
|
2015-02-16 05:44:29 +00:00
|
|
|
|
2016-01-26 05:49:35 +00:00
|
|
|
if (!ret || new_path_len < 0)
|
2015-02-16 05:44:29 +00:00
|
|
|
{
|
2015-07-01 22:54:10 +00:00
|
|
|
RARCH_ERR("%s \"%s\".\n",
|
|
|
|
msg_hash_to_str(MSG_COULD_NOT_READ_CONTENT_FILE),
|
|
|
|
path);
|
2015-02-16 05:44:29 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-26 05:49:35 +00:00
|
|
|
RARCH_LOG("New path is: [%s]\n", new_path);
|
|
|
|
|
|
|
|
string_list_append(additional_path_allocs, new_path, attributes);
|
2016-01-19 16:14:57 +00:00
|
|
|
info[i].path =
|
|
|
|
additional_path_allocs->elems[additional_path_allocs->size -1 ].data;
|
|
|
|
|
2016-01-24 04:28:26 +00:00
|
|
|
if (!string_list_append(temporary_content, new_path, attributes))
|
2016-01-19 16:14:57 +00:00
|
|
|
return false;
|
2015-02-16 05:44:29 +00:00
|
|
|
|
2015-02-16 15:49:05 +00:00
|
|
|
return true;
|
2015-02-16 05:44:29 +00:00
|
|
|
}
|
2016-01-18 23:34:43 +00:00
|
|
|
#endif
|
2015-02-16 05:44:29 +00:00
|
|
|
|
2015-01-08 02:58:14 +00:00
|
|
|
/**
|
|
|
|
* load_content:
|
|
|
|
* @special : subsystem of content to be loaded. Can be NULL.
|
2015-10-14 03:12:01 +00:00
|
|
|
* content :
|
2015-01-08 02:58:14 +00:00
|
|
|
*
|
|
|
|
* Load content file (for libretro core).
|
|
|
|
*
|
|
|
|
* Returns : true if successful, otherwise false.
|
|
|
|
**/
|
2016-01-19 00:22:37 +00:00
|
|
|
static bool load_content(
|
2016-01-19 21:17:54 +00:00
|
|
|
struct string_list *temporary_content,
|
2016-01-19 00:22:37 +00:00
|
|
|
struct retro_game_info *info,
|
|
|
|
const struct string_list *content,
|
|
|
|
const struct retro_subsystem_info *special,
|
|
|
|
struct string_list* additional_path_allocs
|
|
|
|
)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2014-04-04 12:58:42 +00:00
|
|
|
unsigned i;
|
2016-01-27 08:13:26 +00:00
|
|
|
retro_ctx_load_content_info_t load_info;
|
2014-09-02 03:10:54 +00:00
|
|
|
|
2016-01-19 00:22:37 +00:00
|
|
|
if (!info || !additional_path_allocs)
|
2012-10-24 15:17:01 +00:00
|
|
|
return false;
|
2016-01-19 00:14:17 +00:00
|
|
|
|
2014-07-28 17:45:00 +00:00
|
|
|
for (i = 0; i < content->size; i++)
|
2014-04-04 12:58:42 +00:00
|
|
|
{
|
2015-03-22 06:37:25 +00:00
|
|
|
int attr = content->elems[i].attr.i;
|
2014-12-31 17:51:29 +00:00
|
|
|
bool need_fullpath = attr & 2;
|
2014-08-13 06:52:13 +00:00
|
|
|
bool require_content = attr & 4;
|
2016-01-26 07:21:44 +00:00
|
|
|
const char *path = content->elems[i].data;
|
2013-01-21 20:01:12 +00:00
|
|
|
|
2016-02-16 04:18:39 +00:00
|
|
|
if (require_content && string_is_empty(path))
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-26 04:48:31 +00:00
|
|
|
RARCH_LOG("libretro core requires content, "
|
|
|
|
"but nothing was provided.\n");
|
2016-01-19 00:22:37 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 05:44:29 +00:00
|
|
|
info[i].path = NULL;
|
2015-10-14 03:12:01 +00:00
|
|
|
|
2016-01-26 07:21:44 +00:00
|
|
|
if (*path)
|
|
|
|
info[i].path = path;
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2016-01-26 07:21:44 +00:00
|
|
|
if (!need_fullpath && !string_is_empty(path))
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-26 07:21:44 +00:00
|
|
|
if (!load_content_into_memory(&info[i], i, path))
|
2016-01-19 00:22:37 +00:00
|
|
|
return false;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
2014-04-04 12:58:42 +00:00
|
|
|
else
|
2014-09-12 15:06:28 +00:00
|
|
|
{
|
2015-02-16 15:49:05 +00:00
|
|
|
RARCH_LOG("Content loading skipped. Implementation will"
|
|
|
|
" load it on its own.\n");
|
|
|
|
|
2016-01-18 23:34:43 +00:00
|
|
|
#ifdef HAVE_COMPRESSION
|
2016-01-19 21:17:54 +00:00
|
|
|
if (!load_content_from_compressed_archive(
|
|
|
|
temporary_content,
|
|
|
|
&info[i], i,
|
2016-01-26 07:21:44 +00:00
|
|
|
additional_path_allocs, need_fullpath, path))
|
2016-01-19 00:22:37 +00:00
|
|
|
return false;
|
2016-01-18 23:34:43 +00:00
|
|
|
#endif
|
2014-09-12 15:06:28 +00:00
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-01-27 08:13:26 +00:00
|
|
|
load_info.content = content;
|
|
|
|
load_info.special = special;
|
|
|
|
load_info.info = info;
|
2016-01-27 07:48:19 +00:00
|
|
|
|
2016-01-27 08:13:26 +00:00
|
|
|
if (!core_ctl(CORE_CTL_RETRO_LOAD_GAME, &load_info))
|
2016-01-27 07:48:19 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_CONTENT));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-11-06 19:32:40 +00:00
|
|
|
#ifdef HAVE_CHEEVOS
|
2016-01-27 07:48:19 +00:00
|
|
|
if (!special)
|
|
|
|
{
|
2016-02-13 05:06:51 +00:00
|
|
|
const void *load_data = NULL;
|
|
|
|
|
2016-02-13 05:13:46 +00:00
|
|
|
cheevos_ctl(CHEEVOS_CTL_SET_CHEATS, NULL);
|
2016-02-13 05:06:51 +00:00
|
|
|
|
|
|
|
if (*content->elems[0].data)
|
|
|
|
load_data = info;
|
|
|
|
cheevos_ctl(CHEEVOS_CTL_LOAD, (void*)load_data);
|
2015-10-14 03:12:01 +00:00
|
|
|
}
|
2016-01-27 07:48:19 +00:00
|
|
|
#endif
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-27 07:48:19 +00:00
|
|
|
return true;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 03:07:34 +00:00
|
|
|
static const struct retro_subsystem_info *init_content_file_subsystem(
|
|
|
|
bool *ret, rarch_system_info_t *system)
|
2016-01-18 23:16:49 +00:00
|
|
|
{
|
|
|
|
global_t *global = global_get_ptr();
|
2016-02-13 03:07:34 +00:00
|
|
|
const struct retro_subsystem_info *special =
|
2016-03-04 18:29:22 +00:00
|
|
|
libretro_find_subsystem_info(system->subsystem.data,
|
|
|
|
system->subsystem.size, global->subsystem);
|
2016-01-18 23:16:49 +00:00
|
|
|
|
|
|
|
if (!special)
|
|
|
|
{
|
|
|
|
RARCH_ERR(
|
|
|
|
"Failed to find subsystem \"%s\" in libretro implementation.\n",
|
|
|
|
global->subsystem);
|
2016-02-13 03:07:34 +00:00
|
|
|
goto error;
|
2016-01-18 23:16:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (special->num_roms && !global->subsystem_fullpaths)
|
|
|
|
{
|
2016-01-26 04:48:31 +00:00
|
|
|
RARCH_ERR("libretro core requires special content, "
|
|
|
|
"but none were provided.\n");
|
2016-02-13 03:07:34 +00:00
|
|
|
goto error;
|
2016-01-18 23:16:49 +00:00
|
|
|
}
|
|
|
|
else if (special->num_roms && special->num_roms
|
|
|
|
!= global->subsystem_fullpaths->size)
|
|
|
|
{
|
2016-01-26 04:48:31 +00:00
|
|
|
RARCH_ERR("libretro core requires %u content files for "
|
|
|
|
"subsystem \"%s\", but %u content files were provided.\n",
|
2016-01-18 23:16:49 +00:00
|
|
|
special->num_roms, special->desc,
|
|
|
|
(unsigned)global->subsystem_fullpaths->size);
|
2016-02-13 03:07:34 +00:00
|
|
|
goto error;
|
2016-01-18 23:16:49 +00:00
|
|
|
}
|
|
|
|
else if (!special->num_roms && global->subsystem_fullpaths
|
|
|
|
&& global->subsystem_fullpaths->size)
|
|
|
|
{
|
2016-01-26 04:48:31 +00:00
|
|
|
RARCH_ERR("libretro core takes no content for subsystem \"%s\", "
|
|
|
|
"but %u content files were provided.\n",
|
2016-01-18 23:16:49 +00:00
|
|
|
special->desc,
|
|
|
|
(unsigned)global->subsystem_fullpaths->size);
|
2016-02-13 03:07:34 +00:00
|
|
|
goto error;
|
2016-01-18 23:16:49 +00:00
|
|
|
}
|
|
|
|
|
2016-02-13 03:07:34 +00:00
|
|
|
*ret = true;
|
|
|
|
return special;
|
|
|
|
|
|
|
|
error:
|
|
|
|
*ret = false;
|
|
|
|
return NULL;
|
2016-01-18 23:16:49 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 00:30:28 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2016-01-18 23:26:12 +00:00
|
|
|
static bool init_content_file_extract(
|
2016-01-19 21:17:54 +00:00
|
|
|
struct string_list *temporary_content,
|
2016-01-18 23:26:12 +00:00
|
|
|
struct string_list *content,
|
|
|
|
rarch_system_info_t *system,
|
|
|
|
const struct retro_subsystem_info *special,
|
|
|
|
union string_list_elem_attr *attr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
|
|
|
for (i = 0; i < content->size; i++)
|
|
|
|
{
|
|
|
|
const char *ext = NULL;
|
2016-01-19 16:34:47 +00:00
|
|
|
const char *valid_ext = system->info.valid_extensions;
|
2016-01-18 23:26:12 +00:00
|
|
|
|
|
|
|
/* Block extract check. */
|
|
|
|
if (content->elems[i].attr.i & 1)
|
|
|
|
continue;
|
|
|
|
|
2016-01-19 16:34:47 +00:00
|
|
|
ext = path_get_extension(content->elems[i].data);
|
|
|
|
|
|
|
|
if (special)
|
|
|
|
valid_ext = special->roms[i].valid_extensions;
|
2016-01-18 23:26:12 +00:00
|
|
|
|
|
|
|
if (!ext)
|
|
|
|
continue;
|
|
|
|
|
2016-01-20 16:34:19 +00:00
|
|
|
if (string_is_equal_noncase(ext, "zip"))
|
2016-01-18 23:26:12 +00:00
|
|
|
{
|
2016-01-24 04:41:41 +00:00
|
|
|
char new_path[PATH_MAX_LENGTH];
|
2016-01-18 23:50:15 +00:00
|
|
|
char temp_content[PATH_MAX_LENGTH];
|
2016-01-18 23:26:12 +00:00
|
|
|
|
|
|
|
strlcpy(temp_content, content->elems[i].data,
|
|
|
|
sizeof(temp_content));
|
|
|
|
|
2016-01-24 06:42:46 +00:00
|
|
|
if (!file_archive_extract_first_content_file(temp_content,
|
2016-01-18 23:26:12 +00:00
|
|
|
sizeof(temp_content), valid_ext,
|
|
|
|
*settings->cache_directory ?
|
2016-01-24 04:41:41 +00:00
|
|
|
settings->cache_directory : NULL,
|
|
|
|
new_path, sizeof(new_path)))
|
2016-01-18 23:26:12 +00:00
|
|
|
{
|
|
|
|
RARCH_ERR("Failed to extract content from zipped file: %s.\n",
|
|
|
|
temp_content);
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-19 16:14:57 +00:00
|
|
|
|
2016-01-24 04:41:41 +00:00
|
|
|
string_list_set(content, i, new_path);
|
2016-01-24 04:34:17 +00:00
|
|
|
if (!string_list_append(temporary_content,
|
2016-01-24 04:41:41 +00:00
|
|
|
new_path, *attr))
|
2016-01-19 16:14:57 +00:00
|
|
|
return false;
|
2016-01-18 23:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2016-01-19 00:30:28 +00:00
|
|
|
#endif
|
2016-01-18 23:26:12 +00:00
|
|
|
|
2016-01-19 16:29:25 +00:00
|
|
|
static bool init_content_file_set_attribs(
|
2016-01-19 21:17:54 +00:00
|
|
|
struct string_list *temporary_content,
|
2016-01-18 23:34:43 +00:00
|
|
|
struct string_list *content,
|
|
|
|
rarch_system_info_t *system,
|
2016-01-19 16:33:06 +00:00
|
|
|
const struct retro_subsystem_info *special)
|
2016-01-18 23:34:43 +00:00
|
|
|
{
|
2016-01-19 16:33:06 +00:00
|
|
|
union string_list_elem_attr attr;
|
2016-01-19 16:29:25 +00:00
|
|
|
global_t *global = global_get_ptr();
|
2016-01-19 16:33:06 +00:00
|
|
|
|
|
|
|
attr.i = 0;
|
2016-01-18 23:34:43 +00:00
|
|
|
|
|
|
|
if (*global->subsystem)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < global->subsystem_fullpaths->size; i++)
|
|
|
|
{
|
2016-01-19 16:33:06 +00:00
|
|
|
attr.i = special->roms[i].block_extract;
|
|
|
|
attr.i |= special->roms[i].need_fullpath << 1;
|
|
|
|
attr.i |= special->roms[i].required << 2;
|
2016-01-19 16:29:25 +00:00
|
|
|
|
2016-01-18 23:34:43 +00:00
|
|
|
string_list_append(content,
|
2016-01-19 16:33:06 +00:00
|
|
|
global->subsystem_fullpaths->elems[i].data, attr);
|
2016-01-18 23:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
settings_t *settings = config_get_ptr();
|
|
|
|
|
2016-01-19 16:33:06 +00:00
|
|
|
attr.i = system->info.block_extract;
|
|
|
|
attr.i |= system->info.need_fullpath << 1;
|
2016-03-02 05:20:36 +00:00
|
|
|
attr.i |= (!content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)) << 2;
|
2016-01-19 16:27:02 +00:00
|
|
|
|
2016-01-19 22:15:19 +00:00
|
|
|
if (content_ctl(CONTENT_CTL_DOES_NOT_NEED_CONTENT, NULL)
|
2016-01-21 02:49:06 +00:00
|
|
|
&& settings->set_supports_no_game_enable)
|
2016-01-19 16:33:06 +00:00
|
|
|
string_list_append(content, "", attr);
|
2016-01-19 16:27:02 +00:00
|
|
|
else
|
|
|
|
{
|
2016-01-19 16:29:25 +00:00
|
|
|
char *fullpath = NULL;
|
2016-01-19 16:27:02 +00:00
|
|
|
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
|
|
|
|
|
2016-01-19 16:33:06 +00:00
|
|
|
string_list_append(content, fullpath, attr);
|
2016-01-19 16:27:02 +00:00
|
|
|
}
|
2016-01-18 23:34:43 +00:00
|
|
|
}
|
2016-01-19 16:29:25 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ZLIB
|
|
|
|
/* Try to extract all content we're going to load if appropriate. */
|
2016-01-26 04:48:31 +00:00
|
|
|
if (!init_content_file_extract(temporary_content,
|
|
|
|
content, system, special, &attr))
|
2016-01-19 16:29:25 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
|
|
|
return true;
|
2016-01-18 23:34:43 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 13:41:50 +00:00
|
|
|
/**
|
2016-01-19 21:15:00 +00:00
|
|
|
* content_init_file:
|
2015-01-08 13:41:50 +00:00
|
|
|
*
|
|
|
|
* Initializes and loads a content file for the currently
|
|
|
|
* selected libretro core.
|
|
|
|
*
|
|
|
|
* Returns : true if successful, otherwise false.
|
|
|
|
**/
|
2016-01-19 21:17:54 +00:00
|
|
|
static bool content_init_file(struct string_list *temporary_content)
|
2012-10-24 15:17:01 +00:00
|
|
|
{
|
2016-01-19 00:22:37 +00:00
|
|
|
unsigned i;
|
|
|
|
struct retro_game_info *info = NULL;
|
|
|
|
bool ret = false;
|
|
|
|
struct string_list* additional_path_allocs = NULL;
|
2015-03-22 06:37:25 +00:00
|
|
|
struct string_list *content = NULL;
|
2014-12-31 17:51:29 +00:00
|
|
|
const struct retro_subsystem_info *special = NULL;
|
2015-12-10 21:30:25 +00:00
|
|
|
rarch_system_info_t *system = NULL;
|
2015-11-30 18:09:12 +00:00
|
|
|
global_t *global = global_get_ptr();
|
2015-01-08 13:41:50 +00:00
|
|
|
|
2015-12-10 21:30:25 +00:00
|
|
|
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
|
|
|
|
|
2015-03-21 03:43:18 +00:00
|
|
|
if (*global->subsystem)
|
2016-02-13 03:07:34 +00:00
|
|
|
{
|
|
|
|
special = init_content_file_subsystem(&ret, system);
|
|
|
|
if (!ret)
|
2015-01-08 13:41:50 +00:00
|
|
|
goto error;
|
2016-02-13 03:07:34 +00:00
|
|
|
}
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2014-12-31 17:51:29 +00:00
|
|
|
content = string_list_new();
|
2014-12-15 16:13:08 +00:00
|
|
|
|
2014-07-28 17:45:00 +00:00
|
|
|
if (!content)
|
2015-01-08 13:41:50 +00:00
|
|
|
goto error;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-19 21:17:54 +00:00
|
|
|
if (!init_content_file_set_attribs(temporary_content,
|
|
|
|
content, system, special))
|
2016-01-18 23:26:12 +00:00
|
|
|
goto error;
|
2012-10-24 15:17:01 +00:00
|
|
|
|
2016-01-19 00:22:37 +00:00
|
|
|
info = (struct retro_game_info*)
|
|
|
|
calloc(content->size, sizeof(*info));
|
|
|
|
additional_path_allocs = string_list_new();
|
|
|
|
|
2016-01-19 21:17:54 +00:00
|
|
|
ret = load_content(temporary_content,
|
|
|
|
info, content, special, additional_path_allocs);
|
|
|
|
|
2016-01-19 00:22:37 +00:00
|
|
|
for (i = 0; i < content->size; i++)
|
|
|
|
free((void*)info[i].data);
|
|
|
|
|
|
|
|
string_list_free(additional_path_allocs);
|
|
|
|
if (info)
|
|
|
|
free(info);
|
2014-12-31 17:51:29 +00:00
|
|
|
|
2016-01-18 23:26:12 +00:00
|
|
|
error:
|
|
|
|
if (content)
|
|
|
|
string_list_free(content);
|
2016-01-19 21:52:31 +00:00
|
|
|
return ret;
|
2012-10-24 15:17:01 +00:00
|
|
|
}
|
2015-11-30 18:09:12 +00:00
|
|
|
|
2016-01-19 21:12:25 +00:00
|
|
|
bool content_ctl(enum content_ctl_state state, void *data)
|
2015-11-30 18:09:12 +00:00
|
|
|
{
|
|
|
|
unsigned i;
|
2016-02-15 22:49:23 +00:00
|
|
|
static const struct file_archive_file_backend *stream_backend = NULL;
|
|
|
|
static struct string_list *temporary_content = NULL;
|
|
|
|
static bool content_is_inited = false;
|
|
|
|
static bool core_does_not_need_content = false;
|
|
|
|
static uint32_t content_crc = 0;
|
2015-11-30 18:09:12 +00:00
|
|
|
|
2016-01-19 21:12:25 +00:00
|
|
|
switch(state)
|
2015-11-30 18:09:12 +00:00
|
|
|
{
|
2016-01-25 06:15:05 +00:00
|
|
|
case CONTENT_CTL_LOAD_RAM_FILE:
|
2016-02-03 14:25:37 +00:00
|
|
|
return load_ram_file(data);
|
2016-01-25 06:15:05 +00:00
|
|
|
case CONTENT_CTL_SAVE_RAM_FILE:
|
|
|
|
{
|
|
|
|
ram_type_t *ram = (ram_type_t*)data;
|
|
|
|
if (!ram)
|
|
|
|
return false;
|
|
|
|
save_ram_file(ram);
|
|
|
|
}
|
|
|
|
break;
|
2016-01-19 22:15:19 +00:00
|
|
|
case CONTENT_CTL_DOES_NOT_NEED_CONTENT:
|
|
|
|
return core_does_not_need_content;
|
|
|
|
case CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT:
|
|
|
|
core_does_not_need_content = true;
|
|
|
|
break;
|
2016-03-02 05:20:36 +00:00
|
|
|
case CONTENT_CTL_UNSET_DOES_NOT_NEED_CONTENT:
|
|
|
|
core_does_not_need_content = false;
|
|
|
|
break;
|
2016-01-22 15:09:48 +00:00
|
|
|
case CONTENT_CTL_GET_CRC:
|
|
|
|
{
|
|
|
|
uint32_t **content_crc_ptr = (uint32_t**)data;
|
|
|
|
if (!content_crc_ptr)
|
|
|
|
return false;
|
|
|
|
*content_crc_ptr = &content_crc;
|
|
|
|
}
|
2016-01-22 19:27:42 +00:00
|
|
|
break;
|
2016-01-19 21:33:37 +00:00
|
|
|
case CONTENT_CTL_LOAD_STATE:
|
|
|
|
{
|
|
|
|
const char *path = (const char*)data;
|
|
|
|
if (!path)
|
|
|
|
return false;
|
|
|
|
return content_load_state(path);
|
|
|
|
}
|
|
|
|
case CONTENT_CTL_SAVE_STATE:
|
|
|
|
{
|
|
|
|
const char *path = (const char*)data;
|
|
|
|
if (!path)
|
|
|
|
return false;
|
|
|
|
return content_save_state(path);
|
|
|
|
}
|
2016-01-19 21:57:18 +00:00
|
|
|
case CONTENT_CTL_IS_INITED:
|
|
|
|
return content_is_inited;
|
|
|
|
case CONTENT_CTL_DEINIT:
|
|
|
|
content_ctl(CONTENT_CTL_TEMPORARY_FREE, NULL);
|
2016-01-22 15:09:48 +00:00
|
|
|
content_crc = 0;
|
2016-01-19 22:15:19 +00:00
|
|
|
content_is_inited = false;
|
|
|
|
core_does_not_need_content = false;
|
|
|
|
break;
|
2016-01-19 21:15:00 +00:00
|
|
|
case CONTENT_CTL_INIT:
|
2016-01-19 21:57:18 +00:00
|
|
|
content_is_inited = false;
|
2016-01-24 04:28:26 +00:00
|
|
|
temporary_content = string_list_new();
|
|
|
|
if (!temporary_content)
|
|
|
|
return false;
|
2016-01-19 21:57:18 +00:00
|
|
|
if (content_init_file(temporary_content))
|
2016-01-19 21:52:31 +00:00
|
|
|
{
|
2016-01-19 21:57:18 +00:00
|
|
|
content_is_inited = true;
|
|
|
|
return true;
|
2016-01-19 21:52:31 +00:00
|
|
|
}
|
2016-01-27 01:40:11 +00:00
|
|
|
content_ctl(CONTENT_CTL_DEINIT, NULL);
|
|
|
|
return false;
|
2016-01-19 21:12:25 +00:00
|
|
|
case CONTENT_CTL_TEMPORARY_FREE:
|
|
|
|
if (!temporary_content)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i = 0; i < temporary_content->size; i++)
|
|
|
|
{
|
|
|
|
const char *path = temporary_content->elems[i].data;
|
|
|
|
|
|
|
|
RARCH_LOG("%s: %s.\n",
|
|
|
|
msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path);
|
|
|
|
if (remove(path) < 0)
|
|
|
|
RARCH_ERR("%s: %s.\n",
|
|
|
|
msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE),
|
|
|
|
path);
|
|
|
|
}
|
|
|
|
string_list_free(temporary_content);
|
|
|
|
|
|
|
|
temporary_content = NULL;
|
|
|
|
break;
|
2016-02-15 22:49:23 +00:00
|
|
|
case CONTENT_CTL_STREAM_INIT:
|
2016-02-23 21:05:32 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2016-02-15 22:49:23 +00:00
|
|
|
if (!stream_backend)
|
|
|
|
stream_backend = file_archive_get_default_file_backend();
|
2016-02-23 21:05:32 +00:00
|
|
|
#endif
|
2016-02-15 22:49:23 +00:00
|
|
|
break;
|
|
|
|
case CONTENT_CTL_STREAM_CRC_CALCULATE:
|
|
|
|
{
|
|
|
|
content_stream_t *stream = NULL;
|
|
|
|
content_ctl(CONTENT_CTL_STREAM_INIT, NULL);
|
|
|
|
|
|
|
|
stream = (content_stream_t*)data;
|
2016-03-13 14:30:30 +00:00
|
|
|
#ifdef HAVE_ZLIB
|
2016-02-15 22:49:23 +00:00
|
|
|
stream->crc = stream_backend->stream_crc_calculate(
|
|
|
|
stream->a, stream->b, stream->c);
|
2016-03-13 14:30:30 +00:00
|
|
|
#endif
|
2016-02-15 22:49:23 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-02-16 04:34:33 +00:00
|
|
|
case CONTENT_CTL_LOAD:
|
|
|
|
return content_load((content_ctx_info_t*)data);
|
2016-01-19 21:12:25 +00:00
|
|
|
case CONTENT_CTL_NONE:
|
|
|
|
default:
|
|
|
|
break;
|
2015-11-30 18:09:12 +00:00
|
|
|
}
|
|
|
|
|
2016-01-19 21:12:25 +00:00
|
|
|
return true;
|
2015-11-30 18:09:12 +00:00
|
|
|
}
|