diff --git a/command_event.c b/command_event.c index ad5a002a27..a91fd2cd0d 100644 --- a/command_event.c +++ b/command_event.c @@ -90,29 +90,6 @@ static void event_init_remote(void) } #endif -/** - * event_free_temporary_content: - * - * Frees temporary content handle. - **/ -static void event_free_temporary_content(void) -{ - unsigned i; - global_t *global = global_get_ptr(); - - for (i = 0; i < global->temporary_content->size; i++) - { - const char *path = global->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(global->temporary_content); -} #if defined(HAVE_THREADS) static void event_init_autosave(void) @@ -1695,12 +1672,7 @@ case EVENT_CMD_REMOTE_INIT: #endif break; case EVENT_CMD_TEMPORARY_CONTENT_DEINIT: - if (!global) - break; - - if (global->temporary_content) - event_free_temporary_content(); - global->temporary_content = NULL; + content_temporary_free(); break; case EVENT_CMD_SUBSYSTEM_FULLPATHS_DEINIT: if (!global) diff --git a/content.c b/content.c index 8ed7f0aab3..a86d984fd9 100644 --- a/content.c +++ b/content.c @@ -50,6 +50,8 @@ #include "cheevos.h" #endif +static struct string_list *temporary_content; + /** * read_content_file: * @path : buffer of the content file. @@ -393,16 +395,11 @@ static bool load_content_need_fullpath( char new_basedir[PATH_MAX_LENGTH] = {0}; bool ret = false; settings_t *settings = config_get_ptr(); - global_t *global = global_get_ptr(); rarch_system_info_t *sys_info= rarch_system_info_get_ptr(); if (sys_info && sys_info->info.block_extract) return true; - - if (!need_fullpath) - return true; - - if (!path_contains_compressed_file(path)) + if (!need_fullpath || !path_contains_compressed_file(path)) return true; RARCH_LOG("Compressed file in case of need_fullpath." @@ -441,12 +438,12 @@ static bool load_content_need_fullpath( additional_path_allocs->elems [additional_path_allocs->size -1 ].data; - /* global->temporary_content is initialized in init_content_file + /* temporary_content is initialized in init_content_file * The following part takes care of cleanup of the unzipped files * after exit. */ - retro_assert(global->temporary_content != NULL); - string_list_append(global->temporary_content, + retro_assert(temporary_content != NULL); + string_list_append(temporary_content, new_path, attributes); #endif @@ -559,11 +556,10 @@ bool init_content_file(void) const struct retro_subsystem_info *special = NULL; settings_t *settings = config_get_ptr(); rarch_system_info_t *system = rarch_system_info_get_ptr(); - global_t *global = global_get_ptr(); + global_t *global = global_get_ptr(); + temporary_content = string_list_new(); - global->temporary_content = string_list_new(); - - if (!global->temporary_content) + if (!temporary_content) goto error; if (*global->subsystem) @@ -649,23 +645,23 @@ bool init_content_file(void) if (ext && !strcasecmp(ext, "zip")) { - char temporary_content[PATH_MAX_LENGTH] = {0}; + char temp_content[PATH_MAX_LENGTH] = {0}; - strlcpy(temporary_content, content->elems[i].data, - sizeof(temporary_content)); + strlcpy(temp_content, content->elems[i].data, + sizeof(temp_content)); - if (!zlib_extract_first_content_file(temporary_content, - sizeof(temporary_content), valid_ext, + if (!zlib_extract_first_content_file(temp_content, + sizeof(temp_content), valid_ext, *settings->cache_directory ? settings->cache_directory : NULL)) { RARCH_ERR("Failed to extract content from zipped file: %s.\n", - temporary_content); + temp_content); goto error; } - string_list_set(content, i, temporary_content); - string_list_append(global->temporary_content, - temporary_content, attr); + string_list_set(content, i, temp_content); + string_list_append(temporary_content, + temp_content, attr); } } #endif @@ -680,3 +676,31 @@ error: string_list_free(content); return ret; } + +/** + * 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; +} diff --git a/content.h b/content.h index d878dd0b54..92a798c0c9 100644 --- a/content.h +++ b/content.h @@ -83,6 +83,8 @@ void save_ram_file(const char *path, int type); **/ bool init_content_file(void); +void content_temporary_free(void); + #ifdef __cplusplus } #endif diff --git a/runloop.h b/runloop.h index 5e94b5be57..2526b1629f 100644 --- a/runloop.h +++ b/runloop.h @@ -125,8 +125,6 @@ typedef struct global bool perfcnt_enable; bool force_fullscreen; - struct string_list *temporary_content; - struct { core_info_list_t *list;