Add support for ZIP extraction to temporary folders.

This commit is contained in:
Themaister 2014-04-04 17:33:19 +02:00
parent 9f5a714615
commit 2280e28737
6 changed files with 23 additions and 5 deletions

3
file.c
View File

@ -462,7 +462,8 @@ bool init_rom_file(void)
{
char temporary_rom[PATH_MAX];
strlcpy(temporary_rom, roms->elems[i].data, sizeof(temporary_rom));
if (!zlib_extract_first_rom(temporary_rom, sizeof(temporary_rom), valid_ext))
if (!zlib_extract_first_rom(temporary_rom, sizeof(temporary_rom), valid_ext,
*g_settings.extraction_directory ? g_settings.extraction_directory : NULL))
{
RARCH_ERR("Failed to extract ROM from zipped file: %s.\n", temporary_rom);
string_list_free(roms);

View File

@ -308,6 +308,7 @@ end:
struct zip_extract_userdata
{
char *zip_path;
const char *extraction_directory;
size_t zip_path_size;
struct string_list *ext;
bool found_rom;
@ -323,8 +324,13 @@ static bool zip_extract_cb(const char *name, const uint8_t *cdata, unsigned cmod
if (ext && string_list_find_elem(data->ext, ext))
{
char new_path[PATH_MAX];
fill_pathname_resolve_relative(new_path, data->zip_path,
path_basename(name), sizeof(new_path));
if (data->extraction_directory)
fill_pathname_join(new_path, data->extraction_directory,
path_basename(name), sizeof(new_path));
else
fill_pathname_resolve_relative(new_path, data->zip_path,
path_basename(name), sizeof(new_path));
switch (cmode)
{
@ -350,7 +356,8 @@ static bool zip_extract_cb(const char *name, const uint8_t *cdata, unsigned cmod
return true;
}
bool zlib_extract_first_rom(char *zip_path, size_t zip_path_size, const char *valid_exts)
bool zlib_extract_first_rom(char *zip_path, size_t zip_path_size, const char *valid_exts,
const char *extraction_directory)
{
bool ret;
struct zip_extract_userdata userdata = {0};
@ -369,6 +376,7 @@ bool zlib_extract_first_rom(char *zip_path, size_t zip_path_size, const char *va
userdata.zip_path = zip_path;
userdata.zip_path_size = zip_path_size;
userdata.extraction_directory = extraction_directory;
userdata.ext = list;
if (!zlib_parse_file(zip_path, zip_extract_cb, &userdata))

View File

@ -30,7 +30,7 @@ typedef bool (*zlib_file_cb)(const char *name,
bool zlib_parse_file(const char *file, zlib_file_cb file_cb, void *userdata);
// Built with zlib_parse_file.
bool zlib_extract_first_rom(char *zip_path, size_t zip_path_size, const char *valid_exts);
bool zlib_extract_first_rom(char *zip_path, size_t zip_path_size, const char *valid_exts, const char *extraction_dir);
struct string_list *zlib_get_file_list(const char *path);
bool zlib_inflate_data_to_file(const char *path, const uint8_t *data,

View File

@ -286,6 +286,8 @@ struct settings
char screenshot_directory[PATH_MAX];
char system_directory[PATH_MAX];
char extraction_directory[PATH_MAX];
bool rewind_enable;
size_t rewind_buffer_size;
unsigned rewind_granularity;

View File

@ -8,6 +8,10 @@
# This will be overridden by explicit command line options.
# savestate_directory =
# If set to a directory, ROMs which are temporarily extracted
# will be extracted to this directory.
# extraction_directory =
# Automatically saves a savestate at the end of RetroArch's lifetime.
# The path is $SRAM_PATH.auto.
# RetroArch will automatically load any savestate with this path on startup if savestate_auto_load is set.

View File

@ -376,6 +376,7 @@ void config_set_defaults(void)
*g_settings.cheat_settings_path = '\0';
*g_settings.screenshot_directory = '\0';
*g_settings.system_directory = '\0';
*g_settings.extraction_directory = '\0';
*g_settings.input.autoconfig_dir = '\0';
*g_settings.input.overlay = '\0';
*g_settings.content_directory = '\0';
@ -929,6 +930,7 @@ bool config_load_file(const char *path, bool set_defaults)
}
}
CONFIG_GET_PATH(extraction_directory, "extraction_directory");
CONFIG_GET_PATH(content_directory, "content_directory");
if (!strcmp(g_settings.content_directory, "default"))
*g_settings.content_directory = '\0';
@ -1276,6 +1278,7 @@ bool config_save_file(const char *path)
config_set_int(conf, "audio_out_rate", g_settings.audio.out_rate);
config_set_path(conf, "system_directory", *g_settings.system_directory ? g_settings.system_directory : "default");
config_set_path(conf, "extraction_directory", g_settings.extraction_directory);
config_set_string(conf, "audio_resampler", g_settings.audio.resampler);
config_set_path(conf, "savefile_directory", *g_extern.savefile_dir ? g_extern.savefile_dir : "default");
config_set_path(conf, "savestate_directory", *g_extern.savestate_dir ? g_extern.savestate_dir : "default");