move temporary_content to content.c

This commit is contained in:
twinaphex 2015-11-30 19:09:12 +01:00
parent df5c8168d1
commit 30ed8b750b
4 changed files with 49 additions and 53 deletions

View File

@ -90,29 +90,6 @@ static void event_init_remote(void)
} }
#endif #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) #if defined(HAVE_THREADS)
static void event_init_autosave(void) static void event_init_autosave(void)
@ -1695,12 +1672,7 @@ case EVENT_CMD_REMOTE_INIT:
#endif #endif
break; break;
case EVENT_CMD_TEMPORARY_CONTENT_DEINIT: case EVENT_CMD_TEMPORARY_CONTENT_DEINIT:
if (!global) content_temporary_free();
break;
if (global->temporary_content)
event_free_temporary_content();
global->temporary_content = NULL;
break; break;
case EVENT_CMD_SUBSYSTEM_FULLPATHS_DEINIT: case EVENT_CMD_SUBSYSTEM_FULLPATHS_DEINIT:
if (!global) if (!global)

View File

@ -50,6 +50,8 @@
#include "cheevos.h" #include "cheevos.h"
#endif #endif
static struct string_list *temporary_content;
/** /**
* read_content_file: * read_content_file:
* @path : buffer of the 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}; char new_basedir[PATH_MAX_LENGTH] = {0};
bool ret = false; bool ret = false;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
global_t *global = global_get_ptr();
rarch_system_info_t *sys_info= rarch_system_info_get_ptr(); rarch_system_info_t *sys_info= rarch_system_info_get_ptr();
if (sys_info && sys_info->info.block_extract) if (sys_info && sys_info->info.block_extract)
return true; return true;
if (!need_fullpath || !path_contains_compressed_file(path))
if (!need_fullpath)
return true;
if (!path_contains_compressed_file(path))
return true; return true;
RARCH_LOG("Compressed file in case of need_fullpath." 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->elems
[additional_path_allocs->size -1 ].data; [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 * The following part takes care of cleanup of the unzipped files
* after exit. * after exit.
*/ */
retro_assert(global->temporary_content != NULL); retro_assert(temporary_content != NULL);
string_list_append(global->temporary_content, string_list_append(temporary_content,
new_path, attributes); new_path, attributes);
#endif #endif
@ -559,11 +556,10 @@ bool init_content_file(void)
const struct retro_subsystem_info *special = NULL; const struct retro_subsystem_info *special = NULL;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
rarch_system_info_t *system = rarch_system_info_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 (!temporary_content)
if (!global->temporary_content)
goto error; goto error;
if (*global->subsystem) if (*global->subsystem)
@ -649,23 +645,23 @@ bool init_content_file(void)
if (ext && !strcasecmp(ext, "zip")) 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, strlcpy(temp_content, content->elems[i].data,
sizeof(temporary_content)); sizeof(temp_content));
if (!zlib_extract_first_content_file(temporary_content, if (!zlib_extract_first_content_file(temp_content,
sizeof(temporary_content), valid_ext, sizeof(temp_content), valid_ext,
*settings->cache_directory ? *settings->cache_directory ?
settings->cache_directory : NULL)) settings->cache_directory : NULL))
{ {
RARCH_ERR("Failed to extract content from zipped file: %s.\n", RARCH_ERR("Failed to extract content from zipped file: %s.\n",
temporary_content); temp_content);
goto error; goto error;
} }
string_list_set(content, i, temporary_content); string_list_set(content, i, temp_content);
string_list_append(global->temporary_content, string_list_append(temporary_content,
temporary_content, attr); temp_content, attr);
} }
} }
#endif #endif
@ -680,3 +676,31 @@ error:
string_list_free(content); string_list_free(content);
return ret; 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;
}

View File

@ -83,6 +83,8 @@ void save_ram_file(const char *path, int type);
**/ **/
bool init_content_file(void); bool init_content_file(void);
void content_temporary_free(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -125,8 +125,6 @@ typedef struct global
bool perfcnt_enable; bool perfcnt_enable;
bool force_fullscreen; bool force_fullscreen;
struct string_list *temporary_content;
struct struct
{ {
core_info_list_t *list; core_info_list_t *list;