From 2280e287376094ec2657f3177f84c55af5c8dcd0 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 4 Apr 2014 17:33:19 +0200 Subject: [PATCH] Add support for ZIP extraction to temporary folders. --- file.c | 3 ++- file_extract.c | 14 +++++++++++--- file_extract.h | 2 +- general.h | 2 ++ retroarch.cfg | 4 ++++ settings.c | 3 +++ 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/file.c b/file.c index ea57169821..5f760d442e 100644 --- a/file.c +++ b/file.c @@ -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); diff --git a/file_extract.c b/file_extract.c index bd9c081aa9..48a660f02e 100644 --- a/file_extract.c +++ b/file_extract.c @@ -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)) diff --git a/file_extract.h b/file_extract.h index 4414a801dd..c23343489c 100644 --- a/file_extract.h +++ b/file_extract.h @@ -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, diff --git a/general.h b/general.h index 00068a77c8..31f2575dd2 100644 --- a/general.h +++ b/general.h @@ -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; diff --git a/retroarch.cfg b/retroarch.cfg index 0e64a20067..25ed6e8ee0 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -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. diff --git a/settings.c b/settings.c index c0f57ca986..3279fe5685 100644 --- a/settings.c +++ b/settings.c @@ -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");