(task_content.c) Move global variables to struct

This commit is contained in:
twinaphex 2020-03-12 06:45:17 +01:00
parent 0611581b28
commit f13a4b10ee

View file

@ -120,7 +120,7 @@ typedef struct content_information_ctx content_information_ctx_t;
#ifdef HAVE_CDROM #ifdef HAVE_CDROM
enum cdrom_dump_state enum cdrom_dump_state
{ {
DUMP_STATE_TOC_PENDING, DUMP_STATE_TOC_PENDING = 0,
DUMP_STATE_WRITE_CUE, DUMP_STATE_WRITE_CUE,
DUMP_STATE_NEXT_TRACK, DUMP_STATE_NEXT_TRACK,
DUMP_STATE_READ_TRACK DUMP_STATE_READ_TRACK
@ -128,33 +128,43 @@ enum cdrom_dump_state
typedef struct typedef struct
{ {
RFILE *file; bool next;
RFILE *output_file; enum cdrom_dump_state state;
libretro_vfs_implementation_file *stream;
const cdrom_toc_t *toc;
char cdrom_path[64];
char drive_letter[2];
char title[512];
unsigned char cur_track; unsigned char cur_track;
int64_t cur_track_bytes; int64_t cur_track_bytes;
int64_t track_written_bytes; int64_t track_written_bytes;
int64_t disc_total_bytes; int64_t disc_total_bytes;
int64_t disc_read_bytes; int64_t disc_read_bytes;
bool next; char drive_letter[2];
enum cdrom_dump_state state; char cdrom_path[64];
char title[512];
const cdrom_toc_t *toc;
RFILE *file;
RFILE *output_file;
libretro_vfs_implementation_file *stream;
} task_cdrom_dump_state_t; } task_cdrom_dump_state_t;
#endif #endif
struct content_stream struct content_stream
{ {
uint32_t a;
const uint8_t *b; const uint8_t *b;
size_t c; size_t c;
uint32_t a;
uint32_t crc; uint32_t crc;
}; };
struct content_information_ctx struct content_information_ctx
{ {
bool is_ips_pref;
bool is_bps_pref;
bool is_ups_pref;
bool block_extract;
bool need_fullpath;
bool set_supports_no_game_enable;
bool patch_is_blocked;
bool bios_is_missing;
bool check_firmware_before_loading;
struct struct
{ {
struct retro_subsystem_info *data; struct retro_subsystem_info *data;
@ -169,38 +179,33 @@ struct content_information_ctx
char *directory_cache; char *directory_cache;
char *directory_system; char *directory_system;
bool is_ips_pref;
bool is_bps_pref;
bool is_ups_pref;
bool block_extract;
bool need_fullpath;
bool set_supports_no_game_enable;
bool patch_is_blocked;
bool bios_is_missing;
bool check_firmware_before_loading;
struct string_list *temporary_content; struct string_list *temporary_content;
}; };
static struct string_list *temporary_content = NULL;
static bool _launched_from_cli = true; static bool _launched_from_cli = true;
static bool _content_is_inited = false;
static bool core_does_not_need_content = false;
static uint32_t content_rom_crc = 0;
static bool pending_subsystem_init = false; typedef struct content_state
static int pending_subsystem_rom_num = 0; {
static int pending_subsystem_id = 0; bool is_inited;
static unsigned pending_subsystem_rom_id = 0; bool core_does_not_need_content;
bool pending_subsystem_init;
bool pending_rom_crc;
static bool pending_content_rom_crc = false; int pending_subsystem_rom_num;
static char pending_content_rom_crc_path[PATH_MAX_LENGTH] = {0}; int pending_subsystem_id;
unsigned pending_subsystem_rom_id;
uint32_t rom_crc;
static char pending_subsystem_ident[255]; char companion_ui_crc32[32];
static char *pending_subsystem_roms[RARCH_MAX_SUBSYSTEM_ROMS]; char pending_subsystem_ident[255];
char pending_rom_crc_path[PATH_MAX_LENGTH];
char companion_ui_db_name[PATH_MAX_LENGTH];
char *pending_subsystem_roms[RARCH_MAX_SUBSYSTEM_ROMS];
static char companion_ui_db_name[PATH_MAX_LENGTH] = {0}; struct string_list *temporary_content;
static char companion_ui_crc32[32] = {0}; } content_state_t;
static content_state_t content_st = {};
#ifdef HAVE_CDROM #ifdef HAVE_CDROM
static void task_cdrom_dump_handler(retro_task_t *task) static void task_cdrom_dump_handler(retro_task_t *task)
@ -213,15 +218,11 @@ static void task_cdrom_dump_handler(retro_task_t *task)
if (task_get_progress(task) == 100) if (task_get_progress(task) == 100)
{ {
if (state->file) if (state->file)
{
filestream_close(state->file); filestream_close(state->file);
state->file = NULL;
}
if (state->output_file) if (state->output_file)
{
filestream_close(state->output_file); filestream_close(state->output_file);
state->file = NULL; state->file = NULL;
} state->output_file = NULL;
task_set_finished(task, true); task_set_finished(task, true);
@ -581,6 +582,7 @@ static bool content_load(content_ctx_info_t *info)
char **rarch_argv_ptr = (char**)info->argv; char **rarch_argv_ptr = (char**)info->argv;
int *rarch_argc_ptr = (int*)&info->argc; int *rarch_argc_ptr = (int*)&info->argc;
struct rarch_main_wrap *wrap_args = NULL; struct rarch_main_wrap *wrap_args = NULL;
content_state_t *p_content = (content_state_t*)&content_st;
if (!(wrap_args = (struct rarch_main_wrap*) if (!(wrap_args = (struct rarch_main_wrap*)
calloc(1, sizeof(*wrap_args)))) calloc(1, sizeof(*wrap_args))))
@ -613,7 +615,7 @@ static bool content_load(content_ctx_info_t *info)
return false; return false;
} }
if (pending_subsystem_init) if (p_content->pending_subsystem_init)
{ {
command_event(CMD_EVENT_CORE_INIT, NULL); command_event(CMD_EVENT_CORE_INIT, NULL);
content_clear_subsystem(); content_clear_subsystem();
@ -656,7 +658,8 @@ static bool load_content_into_memory(
unsigned i, const char *path, void **buf, unsigned i, const char *path, void **buf,
int64_t *length) int64_t *length)
{ {
uint8_t *ret_buf = NULL; uint8_t *ret_buf = NULL;
content_state_t *p_content = (content_state_t*)&content_st;
RARCH_LOG("%s: %s.\n", RARCH_LOG("%s: %s.\n",
msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path); msg_hash_to_str(MSG_LOADING_CONTENT_FILE), path);
@ -693,18 +696,18 @@ static bool load_content_into_memory(
if (has_patch) if (has_patch)
{ {
content_rom_crc = encoding_crc32(0, ret_buf, (size_t)*length); p_content->rom_crc = encoding_crc32(0, ret_buf, (size_t)*length);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)content_rom_crc); RARCH_LOG("CRC32: 0x%x .\n", (unsigned)p_content->rom_crc);
} }
else else
{ {
pending_content_rom_crc = true; p_content->pending_rom_crc = true;
strlcpy(pending_content_rom_crc_path, strlcpy(p_content->pending_rom_crc_path,
path, sizeof(pending_content_rom_crc_path)); path, sizeof(p_content->pending_rom_crc_path));
} }
} }
else else
content_rom_crc = 0; p_content->rom_crc = 0;
} }
*buf = ret_buf; *buf = ret_buf;
@ -898,6 +901,7 @@ static bool content_file_load(
#ifdef __WINRT__ #ifdef __WINRT__
rarch_system_info_t *system = runloop_get_system_info(); rarch_system_info_t *system = runloop_get_system_info();
#endif #endif
content_state_t *p_content = (content_state_t*)&content_st;
for (i = 0; i < content->size; i++) for (i = 0; i < content->size; i++)
{ {
@ -1042,9 +1046,9 @@ static bool content_file_load(
RARCH_LOG("%s\n", msg_hash_to_str( RARCH_LOG("%s\n", msg_hash_to_str(
MSG_CONTENT_LOADING_SKIPPED_IMPLEMENTATION_WILL_DO_IT)); MSG_CONTENT_LOADING_SKIPPED_IMPLEMENTATION_WILL_DO_IT));
pending_content_rom_crc = true; p_content->pending_rom_crc = true;
strlcpy(pending_content_rom_crc_path, strlcpy(p_content->pending_rom_crc_path,
path, sizeof(pending_content_rom_crc_path)); path, sizeof(p_content->pending_rom_crc_path));
} }
} }
@ -1300,8 +1304,9 @@ static void task_push_to_history_list(
bool launched_from_cli, bool launched_from_cli,
bool launched_from_companion_ui) bool launched_from_companion_ui)
{ {
bool contentless = false; bool contentless = false;
bool is_inited = false; bool is_inited = false;
content_state_t *p_content = (content_state_t*)&content_st;
content_get_status(&contentless, &is_inited); content_get_status(&contentless, &is_inited);
@ -1382,11 +1387,11 @@ static void task_push_to_history_list(
{ {
/* Database name + checksum are supplied /* Database name + checksum are supplied
* by the companion UI itself */ * by the companion UI itself */
if (!string_is_empty(companion_ui_crc32)) if (!string_is_empty(p_content->companion_ui_crc32))
crc32 = companion_ui_crc32; crc32 = p_content->companion_ui_crc32;
if (!string_is_empty(companion_ui_db_name)) if (!string_is_empty(p_content->companion_ui_db_name))
db_name = companion_ui_db_name; db_name = p_content->companion_ui_db_name;
} }
#ifdef HAVE_MENU #ifdef HAVE_MENU
else else
@ -2094,19 +2099,22 @@ bool task_push_load_content_with_new_core_from_companion_ui(
retro_task_callback_t cb, retro_task_callback_t cb,
void *user_data) void *user_data)
{ {
global_t *global = global_get_ptr(); global_t *global = global_get_ptr();
content_state_t *p_content = (content_state_t*)&content_st;
path_set(RARCH_PATH_CONTENT, fullpath); path_set(RARCH_PATH_CONTENT, fullpath);
path_set(RARCH_PATH_CORE, core_path); path_set(RARCH_PATH_CORE, core_path);
companion_ui_db_name[0] = '\0'; p_content->companion_ui_db_name[0] = '\0';
companion_ui_crc32[0] = '\0'; p_content->companion_ui_crc32[0] = '\0';
if (!string_is_empty(db_name)) if (!string_is_empty(db_name))
strlcpy(companion_ui_db_name, db_name, sizeof(companion_ui_db_name)); strlcpy(p_content->companion_ui_db_name,
db_name, sizeof(p_content->companion_ui_db_name));
if (!string_is_empty(crc32)) if (!string_is_empty(crc32))
strlcpy(companion_ui_crc32, crc32, sizeof(companion_ui_crc32)); strlcpy(p_content->companion_ui_crc32,
crc32, sizeof(p_content->companion_ui_crc32));
#ifdef HAVE_DYNAMIC #ifdef HAVE_DYNAMIC
command_event(CMD_EVENT_LOAD_CORE, NULL); command_event(CMD_EVENT_LOAD_CORE, NULL);
@ -2184,12 +2192,14 @@ bool task_push_load_content_with_current_core_from_companion_ui(
retro_task_callback_t cb, retro_task_callback_t cb,
void *user_data) void *user_data)
{ {
content_state_t *p_content = (content_state_t*)&content_st;
path_set(RARCH_PATH_CONTENT, fullpath); path_set(RARCH_PATH_CONTENT, fullpath);
/* TODO/FIXME: Enable setting of these values /* TODO/FIXME: Enable setting of these values
* via function arguments */ * via function arguments */
companion_ui_db_name[0] = '\0'; p_content->companion_ui_db_name[0] = '\0';
companion_ui_crc32[0] = '\0'; p_content->companion_ui_crc32[0] = '\0';
/* Load content /* Load content
* > TODO/FIXME: Set loading_from_companion_ui 'false' for * > TODO/FIXME: Set loading_from_companion_ui 'false' for
@ -2239,7 +2249,9 @@ bool task_push_load_subsystem_with_core_from_menu(
retro_task_callback_t cb, retro_task_callback_t cb,
void *user_data) void *user_data)
{ {
pending_subsystem_init = true; content_state_t *p_content = (content_state_t*)&content_st;
p_content->pending_subsystem_init = true;
/* Load content */ /* Load content */
if (!task_load_content_callback(content_info, true, false, false)) if (!task_load_content_callback(content_info, true, false, false))
@ -2261,24 +2273,27 @@ void content_get_status(
bool *contentless, bool *contentless,
bool *is_inited) bool *is_inited)
{ {
*contentless = core_does_not_need_content; content_state_t *p_content = (content_state_t*)&content_st;
*is_inited = _content_is_inited;
*contentless = p_content->core_does_not_need_content;
*is_inited = p_content->is_inited;
} }
/* Clears the pending subsystem rom buffer*/ /* Clears the pending subsystem rom buffer*/
void content_clear_subsystem(void) void content_clear_subsystem(void)
{ {
unsigned i; unsigned i;
content_state_t *p_content = (content_state_t*)&content_st;
pending_subsystem_rom_id = 0; p_content->pending_subsystem_rom_id = 0;
pending_subsystem_init = false; p_content->pending_subsystem_init = false;
for (i = 0; i < RARCH_MAX_SUBSYSTEM_ROMS; i++) for (i = 0; i < RARCH_MAX_SUBSYSTEM_ROMS; i++)
{ {
if (pending_subsystem_roms[i]) if (p_content->pending_subsystem_roms[i])
{ {
free(pending_subsystem_roms[i]); free(p_content->pending_subsystem_roms[i]);
pending_subsystem_roms[i] = NULL; p_content->pending_subsystem_roms[i] = NULL;
} }
} }
} }
@ -2292,14 +2307,16 @@ bool content_launched_from_cli(void)
/* Get the current subsystem */ /* Get the current subsystem */
int content_get_subsystem(void) int content_get_subsystem(void)
{ {
return pending_subsystem_id; content_state_t *p_content = (content_state_t*)&content_st;
return p_content->pending_subsystem_id;
} }
/* Set the current subsystem*/ /* Set the current subsystem*/
void content_set_subsystem(unsigned idx) void content_set_subsystem(unsigned idx)
{ {
rarch_system_info_t *system = runloop_get_system_info();
const struct retro_subsystem_info *subsystem; const struct retro_subsystem_info *subsystem;
rarch_system_info_t *system = runloop_get_system_info();
content_state_t *p_content = (content_state_t*)&content_st;
/* Core fully loaded, use the subsystem data */ /* Core fully loaded, use the subsystem data */
if (system->subsystem.data) if (system->subsystem.data)
@ -2308,18 +2325,20 @@ void content_set_subsystem(unsigned idx)
else else
subsystem = subsystem_data + idx; subsystem = subsystem_data + idx;
pending_subsystem_id = idx; p_content->pending_subsystem_id = idx;
if (subsystem && subsystem_current_count > 0) if (subsystem && subsystem_current_count > 0)
{ {
strlcpy(pending_subsystem_ident, strlcpy(p_content->pending_subsystem_ident,
subsystem->ident, sizeof(pending_subsystem_ident)); subsystem->ident, sizeof(p_content->pending_subsystem_ident));
pending_subsystem_rom_num = subsystem->num_roms; p_content->pending_subsystem_rom_num = subsystem->num_roms;
} }
RARCH_LOG("[subsystem] settings current subsytem to: %d(%s) roms: %d\n", RARCH_LOG("[subsystem] settings current subsytem to: %d(%s) roms: %d\n",
pending_subsystem_id, pending_subsystem_ident, pending_subsystem_rom_num); p_content->pending_subsystem_id,
p_content->pending_subsystem_ident,
p_content->pending_subsystem_rom_num);
} }
/* Sets the subsystem by name */ /* Sets the subsystem by name */
@ -2376,63 +2395,77 @@ void content_get_subsystem_friendly_name(const char* subsystem_name, char* subsy
/* Add a rom to the subsystem rom buffer */ /* Add a rom to the subsystem rom buffer */
void content_add_subsystem(const char* path) void content_add_subsystem(const char* path)
{ {
size_t pending_size = PATH_MAX_LENGTH * sizeof(char); content_state_t *p_content = (content_state_t*)&content_st;
pending_subsystem_roms[pending_subsystem_rom_id] = (char*)malloc(pending_size); size_t pending_size = PATH_MAX_LENGTH * sizeof(char);
p_content->pending_subsystem_roms[p_content->pending_subsystem_rom_id] = (char*)malloc(pending_size);
strlcpy(pending_subsystem_roms[pending_subsystem_rom_id], path, pending_size); strlcpy(p_content->pending_subsystem_roms[
RARCH_LOG("[subsystem] subsystem id: %d subsystem ident: %s rom id: %d, rom path: %s\n", p_content->pending_subsystem_rom_id],
pending_subsystem_id, pending_subsystem_ident, pending_subsystem_rom_id, path, pending_size);
pending_subsystem_roms[pending_subsystem_rom_id]); RARCH_LOG("[subsystem] subsystem id: %d subsystem ident:"
pending_subsystem_rom_id++; " %s rom id: %d, rom path: %s\n",
p_content->pending_subsystem_id,
p_content->pending_subsystem_ident,
p_content->pending_subsystem_rom_id,
p_content->pending_subsystem_roms[
p_content->pending_subsystem_rom_id]);
p_content->pending_subsystem_rom_id++;
} }
/* Get the current subsystem rom id */ /* Get the current subsystem rom id */
unsigned content_get_subsystem_rom_id(void) unsigned content_get_subsystem_rom_id(void)
{ {
return pending_subsystem_rom_id; content_state_t *p_content = (content_state_t*)&content_st;
return p_content->pending_subsystem_rom_id;
} }
void content_set_does_not_need_content(void) void content_set_does_not_need_content(void)
{ {
core_does_not_need_content = true; content_state_t *p_content = (content_state_t*)&content_st;
p_content->core_does_not_need_content = true;
} }
void content_unset_does_not_need_content(void) void content_unset_does_not_need_content(void)
{ {
core_does_not_need_content = false; content_state_t *p_content = (content_state_t*)&content_st;
p_content->core_does_not_need_content = false;
} }
uint32_t content_get_crc(void) uint32_t content_get_crc(void)
{ {
if (pending_content_rom_crc) content_state_t *p_content = (content_state_t*)&content_st;
if (p_content->pending_rom_crc)
{ {
pending_content_rom_crc = false; p_content->pending_rom_crc = false;
content_rom_crc = file_crc32(0, p_content->rom_crc = file_crc32(0,
(const char*)pending_content_rom_crc_path); (const char*)p_content->pending_rom_crc_path);
RARCH_LOG("CRC32: 0x%x .\n", (unsigned)content_rom_crc); RARCH_LOG("CRC32: 0x%x .\n", (unsigned)p_content->rom_crc);
} }
return content_rom_crc; return p_content->rom_crc;
} }
char* content_get_subsystem_rom(unsigned index) char* content_get_subsystem_rom(unsigned index)
{ {
return pending_subsystem_roms[index]; content_state_t *p_content = (content_state_t*)&content_st;
return p_content->pending_subsystem_roms[index];
} }
bool content_is_inited(void) bool content_is_inited(void)
{ {
return _content_is_inited; content_state_t *p_content = (content_state_t*)&content_st;
return p_content->is_inited;
} }
void content_deinit(void) void content_deinit(void)
{ {
unsigned i; unsigned i;
content_state_t *p_content = (content_state_t*)&content_st;
if (temporary_content) if (p_content->temporary_content)
{ {
for (i = 0; i < temporary_content->size; i++) for (i = 0; i < p_content->temporary_content->size; i++)
{ {
const char *path = temporary_content->elems[i].data; const char *path = p_content->temporary_content->elems[i].data;
RARCH_LOG("%s: %s.\n", RARCH_LOG("%s: %s.\n",
msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path); msg_hash_to_str(MSG_REMOVING_TEMPORARY_CONTENT_FILE), path);
@ -2441,24 +2474,26 @@ void content_deinit(void)
msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE), msg_hash_to_str(MSG_FAILED_TO_REMOVE_TEMPORARY_FILE),
path); path);
} }
string_list_free(temporary_content); string_list_free(p_content->temporary_content);
} }
temporary_content = NULL; p_content->temporary_content = NULL;
content_rom_crc = 0; p_content->rom_crc = 0;
_content_is_inited = false; p_content->is_inited = false;
core_does_not_need_content = false; p_content->core_does_not_need_content = false;
pending_content_rom_crc = false; p_content->pending_rom_crc = false;
} }
/* Set environment variables before a subsystem load */ /* Set environment variables before a subsystem load */
void content_set_subsystem_info(void) void content_set_subsystem_info(void)
{ {
if (!pending_subsystem_init) content_state_t *p_content = (content_state_t*)&content_st;
if (!p_content->pending_subsystem_init)
return; return;
path_set(RARCH_PATH_SUBSYSTEM, pending_subsystem_ident); path_set(RARCH_PATH_SUBSYSTEM, p_content->pending_subsystem_ident);
path_set_special(pending_subsystem_roms, pending_subsystem_rom_num); path_set_special(p_content->pending_subsystem_roms,
p_content->pending_subsystem_rom_num);
} }
/* Initializes and loads a content file for the currently /* Initializes and loads a content file for the currently
@ -2466,6 +2501,7 @@ void content_set_subsystem_info(void)
bool content_init(void) bool content_init(void)
{ {
content_information_ctx_t content_ctx; content_information_ctx_t content_ctx;
content_state_t *p_content = (content_state_t*)&content_st;
bool ret = true; bool ret = true;
char *error_string = NULL; char *error_string = NULL;
@ -2478,14 +2514,14 @@ bool content_init(void)
const char *path_dir_system = settings->paths.directory_system; const char *path_dir_system = settings->paths.directory_system;
const char *path_dir_cache = settings->paths.directory_cache; const char *path_dir_cache = settings->paths.directory_cache;
temporary_content = string_list_new(); p_content->temporary_content = string_list_new();
content_ctx.check_firmware_before_loading = check_firmware_before_loading; content_ctx.check_firmware_before_loading = check_firmware_before_loading;
content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL); content_ctx.patch_is_blocked = rarch_ctl(RARCH_CTL_IS_PATCH_BLOCKED, NULL);
content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL); content_ctx.is_ips_pref = rarch_ctl(RARCH_CTL_IS_IPS_PREF, NULL);
content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL); content_ctx.is_bps_pref = rarch_ctl(RARCH_CTL_IS_BPS_PREF, NULL);
content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL); content_ctx.is_ups_pref = rarch_ctl(RARCH_CTL_IS_UPS_PREF, NULL);
content_ctx.temporary_content = temporary_content; content_ctx.temporary_content = p_content->temporary_content;
content_ctx.directory_system = NULL; content_ctx.directory_system = NULL;
content_ctx.directory_cache = NULL; content_ctx.directory_cache = NULL;
content_ctx.name_ips = NULL; content_ctx.name_ips = NULL;
@ -2529,10 +2565,10 @@ bool content_init(void)
content_ctx.subsystem.size = sys_info->subsystem.size; content_ctx.subsystem.size = sys_info->subsystem.size;
} }
_content_is_inited = true; p_content->is_inited = true;
content = string_list_new(); content = string_list_new();
if ( !temporary_content if ( !p_content->temporary_content
|| !content_file_init(&content_ctx, content, &error_string)) || !content_file_init(&content_ctx, content, &error_string))
{ {
content_deinit(); content_deinit();