RetroArch/content.c

710 lines
18 KiB
C
Raw Normal View History

/* 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
*
* 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 <stdlib.h>
#include <boolean.h>
#include <string.h>
#include <time.h>
2013-04-11 20:35:15 +00:00
#ifdef _WIN32
#ifdef _XBOX
#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
#endif
2015-06-25 09:02:01 +00:00
#include <compat/strl.h>
#include <file/file_path.h>
#include <file/file_extract.h>
2015-09-18 22:34:24 +00:00
#include <retro_file.h>
2015-09-21 23:45:16 +00:00
#include <retro_stat.h>
2015-06-25 09:02:01 +00:00
2015-07-01 22:47:00 +00:00
#include "msg_hash.h"
2015-06-25 09:02:01 +00:00
#include "content.h"
#include "file_ops.h"
#include "general.h"
#include "dynamic.h"
#include "movie.h"
#include "patch.h"
#include "system.h"
2015-11-23 11:03:38 +00:00
#include "verbosity.h"
#ifdef HAVE_CHEEVOS
#include "cheevos.h"
#endif
2015-06-25 09:02:01 +00:00
2015-12-07 06:13:18 +00:00
struct sram_block
{
unsigned type;
void *data;
size_t size;
};
2015-11-30 18:09:12 +00:00
static struct string_list *temporary_content;
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)
{
uint8_t *ret_buf = NULL;
2015-03-21 03:43:18 +00:00
global_t *global = global_get_ptr();
2015-07-02 12:08:04 +00:00
RARCH_LOG("%s: %s.\n",
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
2015-02-16 02:31:37 +00:00
if (!read_file(path, (void**) &ret_buf, length))
return false;
2014-09-02 15:05:15 +00:00
if (*length < 0)
2015-02-16 02:31:37 +00:00
return false;
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);
#ifdef HAVE_ZLIB
global->content_crc = zlib_crc32_calculate(ret_buf, *length);
2014-09-02 03:10:54 +00:00
2015-03-21 03:43:18 +00:00
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)global->content_crc);
#endif
*buf = ret_buf;
2015-02-16 02:31:37 +00:00
return true;
}
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.
**/
2014-09-02 03:10:54 +00:00
static void dump_to_file_desperate(const void *data,
size_t size, unsigned type)
{
time_t time_;
2015-12-07 06:13:18 +00:00
char timebuf[256];
2015-06-12 15:00:37 +00:00
char path[PATH_MAX_LENGTH] = {0};
#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)
goto error;
2014-04-04 12:58:42 +00:00
snprintf(path, sizeof(path), "%s/RetroArch-recovery-%u", base, type);
time(&time_);
strftime(timebuf, sizeof(timebuf), "%Y-%m-%d-%H-%M-%S", localtime(&time_));
strlcat(path, timebuf, sizeof(path));
2015-09-18 22:34:24 +00:00
if (retro_write_file(path, data, size))
RARCH_WARN("Succeeded in saving RAM data to \"%s\".\n", path);
else
goto error;
return;
error:
RARCH_WARN("Failed ... Cannot recover save file.\n");
}
2015-01-08 02:58:14 +00:00
/**
* save_state:
* @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.
**/
bool save_state(const char *path)
{
2015-06-12 15:00:37 +00:00
bool ret = false;
void *data = NULL;
size_t size = core.retro_serialize_size();
2015-07-01 22:47:00 +00:00
RARCH_LOG("%s: \"%s\".\n",
msg_hash_to_str(MSG_SAVING_STATE),
path);
if (size == 0)
return false;
data = malloc(size);
if (!data)
return false;
RARCH_LOG("%s: %d %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
(int)size,
msg_hash_to_str(MSG_BYTES));
ret = core.retro_serialize(data, size);
if (ret)
2015-09-18 22:34:24 +00:00
ret = retro_write_file(path, data, size);
if (!ret)
RARCH_ERR("%s \"%s\".\n",
2015-07-01 22:47:00 +00:00
msg_hash_to_str(MSG_FAILED_TO_SAVE_STATE_TO),
path);
free(data);
return ret;
}
2015-01-08 02:58:14 +00:00
/**
* 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.
**/
bool load_state(const char *path)
{
unsigned i;
2015-03-20 19:43:22 +00:00
ssize_t size;
2015-03-22 06:37:25 +00:00
unsigned num_blocks = 0;
void *buf = NULL;
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();
bool ret = read_file(path, &buf, &size);
2015-07-01 22:47:00 +00:00
RARCH_LOG("%s: \"%s\".\n",
msg_hash_to_str(MSG_LOADING_STATE),
path);
2015-02-16 02:31:37 +00:00
if (!ret || size < 0)
{
2015-07-01 22:54:10 +00:00
RARCH_ERR("%s \"%s\".\n",
msg_hash_to_str(MSG_FAILED_TO_LOAD_STATE),
path);
return false;
}
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));
2015-03-21 03:43:18 +00:00
if (settings->block_sram_overwrite && global->savefiles
&& global->savefiles->size)
{
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)
{
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;
}
}
2014-04-04 13:35:46 +00:00
for (i = 0; i < num_blocks; i++)
blocks[i].size = core.retro_get_memory_size(blocks[i].type);
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);
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++)
{
2014-04-04 13:35:46 +00:00
if (blocks[i].data)
{
const void *ptr = core.retro_get_memory_data(blocks[i].type);
if (ptr)
2014-04-04 13:35:46 +00:00
memcpy(blocks[i].data, ptr, blocks[i].size);
}
}
ret = core.retro_unserialize(buf, size);
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++)
{
2014-04-04 13:35:46 +00:00
if (blocks[i].data)
{
void *ptr = core.retro_get_memory_data(blocks[i].type);
if (ptr)
2014-04-04 13:35:46 +00:00
memcpy(ptr, blocks[i].data, blocks[i].size);
}
}
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);
return ret;
}
/**
* 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.
*/
void load_ram_file(const char *path, int type)
{
2015-02-16 02:46:27 +00:00
ssize_t rc;
2015-03-22 06:37:25 +00:00
bool ret = false;
2015-01-09 14:33:58 +00:00
void *buf = NULL;
size_t size = core.retro_get_memory_size(type);
void *data = core.retro_get_memory_data(type);
if (size == 0 || !data)
return;
2015-02-16 02:31:37 +00:00
ret = read_file(path, &buf, &rc);
if (!ret)
return;
if (rc > 0)
{
if (rc > (ssize_t)size)
{
2015-07-01 22:54:10 +00:00
RARCH_WARN("SRAM is larger than implementation expects, doing partial load (truncating %u %s %s %u).\n",
(unsigned)rc,
msg_hash_to_str(MSG_BYTES),
msg_hash_to_str(MSG_TO),
(unsigned)size);
rc = size;
}
memcpy(data, buf, rc);
}
if (buf)
free(buf);
}
/**
* 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.
*
* In case the file could not be written to, a fallback function
* 'dump_to_file_desperate' will be called.
*/
void save_ram_file(const char *path, int type)
{
size_t size = core.retro_get_memory_size(type);
void *data = core.retro_get_memory_data(type);
2015-12-07 06:13:18 +00:00
if (!data || size == 0)
return;
2015-09-18 22:34:24 +00:00
if (!retro_write_file(path, data, size))
{
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");
dump_to_file_desperate(data, size, type);
return;
}
2015-07-01 22:54:10 +00:00
RARCH_LOG("%s \"%s\".\n",
msg_hash_to_str(MSG_SAVED_SUCCESSFULLY_TO),
path);
}
2015-02-16 05:44:29 +00:00
static bool load_content_dont_need_fullpath(
struct retro_game_info *info, unsigned i, const char *path)
{
ssize_t len;
/* Load the content into memory. */
/* First content file is significant, attempt to do patching,
* CRC checking, etc. */
bool ret = false;
if (i == 0)
ret = read_content_file(i, path, (void**)&info->data, &len);
else
ret = read_file(path, (void**)&info->data, &len);
2015-02-16 05:44:29 +00:00
if (!ret || len < 0)
{
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;
}
info->size = len;
return true;
}
static bool load_content_need_fullpath(
struct retro_game_info *info, unsigned i,
struct string_list* additional_path_allocs,
bool need_fullpath, const char *path)
{
#ifdef HAVE_COMPRESSION
ssize_t len;
union string_list_elem_attr attributes;
2015-06-12 15:00:37 +00:00
char new_path[PATH_MAX_LENGTH] = {0};
char new_basedir[PATH_MAX_LENGTH] = {0};
bool ret = false;
settings_t *settings = config_get_ptr();
2015-12-10 21:30:25 +00:00
rarch_system_info_t *sys_info= NULL;
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &sys_info);
2015-02-16 05:44:29 +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."
"Now extracting to temporary directory.\n");
strlcpy(new_basedir, settings->cache_directory,
2015-02-16 05:44:29 +00:00
sizeof(new_basedir));
if ((!strcmp(new_basedir, "")) ||
!path_is_directory(new_basedir))
{
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,
path_basename(path), sizeof(new_path));
ret = read_compressed_file(path,NULL,new_path, &len);
if (!ret || len < 0)
{
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;
}
string_list_append(additional_path_allocs,new_path, attributes);
info[i].path =
additional_path_allocs->elems
[additional_path_allocs->size -1 ].data;
2015-11-30 18:09:12 +00:00
/* temporary_content is initialized in init_content_file
2015-02-16 05:44:29 +00:00
* The following part takes care of cleanup of the unzipped files
* after exit.
*/
2015-11-30 18:09:12 +00:00
retro_assert(temporary_content != NULL);
string_list_append(temporary_content,
2015-02-16 05:44:29 +00:00
new_path, attributes);
#endif
2015-02-16 15:49:05 +00:00
return true;
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.
* content :
2015-01-08 02:58:14 +00:00
*
* Load content file (for libretro core).
*
* Returns : true if successful, otherwise false.
**/
2014-09-02 03:10:54 +00:00
static bool load_content(const struct retro_subsystem_info *special,
const struct string_list *content)
{
2014-04-04 12:58:42 +00:00
unsigned i;
bool ret = true;
struct string_list* additional_path_allocs = string_list_new();
2014-09-02 03:10:54 +00:00
struct retro_game_info *info = (struct retro_game_info*)
calloc(content->size, sizeof(*info));
2014-04-04 12:58:42 +00:00
if (!info)
{
string_list_free(additional_path_allocs);
return false;
}
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
const char *path = content->elems[i].data;
int attr = content->elems[i].attr.i;
bool need_fullpath = attr & 2;
2014-08-13 06:52:13 +00:00
bool require_content = attr & 4;
2013-01-21 20:01:12 +00:00
2014-08-13 06:52:13 +00:00
if (require_content && !*path)
{
2014-07-28 18:08:37 +00:00
RARCH_LOG("libretro core requires content, but nothing was provided.\n");
2013-01-21 20:01:12 +00:00
ret = false;
goto end;
}
2015-02-16 05:44:29 +00:00
info[i].path = NULL;
2015-02-16 05:44:29 +00:00
if (*path)
info[i].path = path;
2014-09-02 03:10:54 +00:00
if (!need_fullpath && *path)
{
2015-02-16 05:44:29 +00:00
if (!load_content_dont_need_fullpath(&info[i], i, path))
2014-04-04 12:58:42 +00:00
goto end;
}
2014-04-04 12:58:42 +00:00
else
{
2015-02-16 15:49:05 +00:00
RARCH_LOG("Content loading skipped. Implementation will"
" load it on its own.\n");
if (!load_content_need_fullpath(&info[i], i,
additional_path_allocs, need_fullpath, path))
2015-02-16 05:44:29 +00:00
goto end;
}
}
2014-04-04 12:58:42 +00:00
if (special)
ret = core.retro_load_game_special(special->id, info, content->size);
else
{
ret = core.retro_load_game(*content->elems[0].data ? info : NULL);
2015-11-06 19:32:40 +00:00
#ifdef HAVE_CHEEVOS
/* Load the achievements into memory if the game has content. */
cheevos_set_cheats();
2015-11-06 19:32:40 +00:00
cheevos_load(*content->elems[0].data ? info : NULL);
#endif
}
if (!ret)
2015-07-01 22:54:10 +00:00
RARCH_ERR("%s.\n", msg_hash_to_str(MSG_FAILED_TO_LOAD_CONTENT));
end:
2014-07-28 17:45:00 +00:00
for (i = 0; i < content->size; i++)
2014-04-04 12:58:42 +00:00
free((void*)info[i].data);
string_list_free(additional_path_allocs);
if (info)
free(info);
return ret;
}
/**
* init_content_file:
*
* Initializes and loads a content file for the currently
* selected libretro core.
*
2015-03-21 03:43:18 +00:00
* global->content_is_init will be set to the return value
* on exit.
*
* Returns : true if successful, otherwise false.
**/
2014-08-13 06:52:13 +00:00
bool init_content_file(void)
{
2014-04-04 12:58:42 +00:00
unsigned i;
union string_list_elem_attr attr;
2015-03-22 06:37:25 +00:00
bool ret = false;
struct string_list *content = NULL;
const struct retro_subsystem_info *special = NULL;
2015-12-10 21:30:25 +00:00
rarch_system_info_t *system = NULL;
2015-03-22 06:37:25 +00:00
settings_t *settings = config_get_ptr();
2015-11-30 18:09:12 +00:00
global_t *global = global_get_ptr();
temporary_content = string_list_new();
2015-12-10 21:30:25 +00:00
runloop_ctl(RUNLOOP_CTL_SYSTEM_INFO_GET, &system);
2015-11-30 18:09:12 +00:00
if (!temporary_content)
goto error;
2015-03-21 03:43:18 +00:00
if (*global->subsystem)
2014-04-04 12:58:42 +00:00
{
special = libretro_find_subsystem_info(system->special,
system->num_special, global->subsystem);
2014-04-04 12:58:42 +00:00
if (!special)
{
2014-09-02 03:10:54 +00:00
RARCH_ERR(
"Failed to find subsystem \"%s\" in libretro implementation.\n",
2015-03-21 03:43:18 +00:00
global->subsystem);
goto error;
2014-04-04 12:58:42 +00:00
}
2015-03-21 03:43:18 +00:00
if (special->num_roms && !global->subsystem_fullpaths)
2014-04-04 12:58:42 +00:00
{
2014-07-28 18:01:27 +00:00
RARCH_ERR("libretro core requires special content, but none were provided.\n");
goto error;
2014-04-04 12:58:42 +00:00
}
else if (special->num_roms && special->num_roms
2015-03-21 03:43:18 +00:00
!= global->subsystem_fullpaths->size)
2014-04-04 12:58:42 +00:00
{
2014-09-02 03:10:54 +00:00
RARCH_ERR("libretro core requires %u content files for subsystem \"%s\", but %u content files were provided.\n",
special->num_roms, special->desc,
2015-03-21 03:43:18 +00:00
(unsigned)global->subsystem_fullpaths->size);
goto error;
2014-04-04 12:58:42 +00:00
}
2015-03-21 03:43:18 +00:00
else if (!special->num_roms && global->subsystem_fullpaths
&& global->subsystem_fullpaths->size)
2014-04-04 12:58:42 +00:00
{
2014-09-02 03:10:54 +00:00
RARCH_ERR("libretro core takes no content for subsystem \"%s\", but %u content files were provided.\n",
special->desc,
2015-03-21 03:43:18 +00:00
(unsigned)global->subsystem_fullpaths->size);
goto error;
2014-04-04 12:58:42 +00:00
}
}
content = string_list_new();
2014-12-15 16:13:08 +00:00
2014-04-14 10:09:04 +00:00
attr.i = 0;
2014-07-28 17:45:00 +00:00
if (!content)
goto error;
2015-03-21 03:43:18 +00:00
if (*global->subsystem)
2013-01-21 22:51:56 +00:00
{
2015-03-21 03:43:18 +00:00
for (i = 0; i < global->subsystem_fullpaths->size; i++)
2013-01-21 22:51:56 +00:00
{
2014-04-04 12:58:42 +00:00
attr.i = special->roms[i].block_extract;
attr.i |= special->roms[i].need_fullpath << 1;
attr.i |= special->roms[i].required << 2;
2014-09-02 03:10:54 +00:00
string_list_append(content,
2015-03-21 03:43:18 +00:00
global->subsystem_fullpaths->elems[i].data, attr);
2013-01-21 22:51:56 +00:00
}
}
2014-04-04 12:58:42 +00:00
else
{
char *fullpath = NULL;
2015-11-30 20:42:59 +00:00
runloop_ctl(RUNLOOP_CTL_GET_CONTENT_PATH, &fullpath);
attr.i = system->info.block_extract;
attr.i |= system->info.need_fullpath << 1;
attr.i |= (!system->no_content) << 2;
2014-09-02 03:10:54 +00:00
string_list_append(content,
(global->inited.core.no_content && settings->core.set_supports_no_game_enable) ? "" : fullpath, attr);
2014-04-04 12:58:42 +00:00
}
2013-01-21 22:51:56 +00:00
2014-04-04 12:58:42 +00:00
#ifdef HAVE_ZLIB
2014-09-02 03:10:54 +00:00
/* Try to extract all content we're going to load if appropriate. */
2014-07-28 17:45:00 +00:00
for (i = 0; i < content->size; i++)
{
2015-03-22 06:37:25 +00:00
const char *ext = NULL;
2015-01-09 14:33:58 +00:00
const char *valid_ext = NULL;
2014-09-02 03:10:54 +00:00
/* Block extract check. */
2014-07-28 17:45:00 +00:00
if (content->elems[i].attr.i & 1)
2014-04-04 12:58:42 +00:00
continue;
2015-01-16 01:01:05 +00:00
ext = path_get_extension(content->elems[i].data);
2015-01-09 14:33:58 +00:00
valid_ext = special ? special->roms[i].valid_extensions :
system->info.valid_extensions;
if (ext && !strcasecmp(ext, "zip"))
2014-04-04 12:58:42 +00:00
{
2015-11-30 18:09:12 +00:00
char temp_content[PATH_MAX_LENGTH] = {0};
2015-01-09 14:33:58 +00:00
2015-11-30 18:09:12 +00:00
strlcpy(temp_content, content->elems[i].data,
sizeof(temp_content));
2014-09-02 03:10:54 +00:00
2015-11-30 18:09:12 +00:00
if (!zlib_extract_first_content_file(temp_content,
sizeof(temp_content), valid_ext,
*settings->cache_directory ?
settings->cache_directory : NULL))
2014-04-04 12:58:42 +00:00
{
2014-09-02 03:10:54 +00:00
RARCH_ERR("Failed to extract content from zipped file: %s.\n",
2015-11-30 18:09:12 +00:00
temp_content);
goto error;
2014-04-04 12:58:42 +00:00
}
2015-11-30 18:09:12 +00:00
string_list_set(content, i, temp_content);
string_list_append(temporary_content,
temp_content, attr);
2014-04-04 12:58:42 +00:00
}
}
2014-04-04 12:58:42 +00:00
#endif
2014-09-02 03:10:54 +00:00
/* Set attr to need_fullpath as appropriate. */
ret = load_content(special, content);
error:
2015-07-27 15:18:10 +00:00
global->inited.content = (ret) ? true : false;
if (content)
string_list_free(content);
2014-04-04 12:58:42 +00:00
return ret;
}
2015-11-30 18:09:12 +00:00
/**
* content_free_temporary:
*
* Frees temporary content handle.
**/
void content_temporary_free(void)
{
unsigned i;
if (!temporary_content)
return;
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;
}