bool content_ctl(enum content_ctl_state state, void *data) { unsigned i; static const struct file_archive_file_backend *stream_backend = NULL; static struct string_list *temporary_content = NULL; static bool content_is_inited = false; static bool core_does_not_need_content = false; static uint32_t content_crc = 0; switch(state) { case CONTENT_CTL_LOAD_RAM_FILE: return load_ram_file(data); case CONTENT_CTL_SAVE_RAM_FILE: { ram_type_t *ram = (ram_type_t*)data; if (!ram) return false; save_ram_file(ram); } break; case CONTENT_CTL_DOES_NOT_NEED_CONTENT: return core_does_not_need_content; case CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT: core_does_not_need_content = true; break; case CONTENT_CTL_GET_CRC: { uint32_t **content_crc_ptr = (uint32_t**)data; if (!content_crc_ptr) return false; *content_crc_ptr = &content_crc; } break; case CONTENT_CTL_LOAD_STATE: { const char *path = (const char*)data; if (!path) return false; return content_load_state(path); } case CONTENT_CTL_SAVE_STATE: { const char *path = (const char*)data; if (!path) return false; return content_save_state(path); } case CONTENT_CTL_IS_INITED: return content_is_inited; case CONTENT_CTL_DEINIT: content_ctl(CONTENT_CTL_TEMPORARY_FREE, NULL); content_crc = 0; content_is_inited = false; core_does_not_need_content = false; break; case CONTENT_CTL_INIT: content_is_inited = false; temporary_content = string_list_new(); if (!temporary_content) return false; if (content_init_file(temporary_content)) { content_is_inited = true; return true; } content_ctl(CONTENT_CTL_DEINIT, NULL); return false; case CONTENT_CTL_TEMPORARY_FREE: if (!temporary_content) return false; 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; break; case CONTENT_CTL_STREAM_INIT: #ifdef HAVE_ZLIB if (!stream_backend) stream_backend = file_archive_get_default_file_backend(); #endif break; case CONTENT_CTL_STREAM_CRC_CALCULATE: { content_stream_t *stream = NULL; content_ctl(CONTENT_CTL_STREAM_INIT, NULL); stream = (content_stream_t*)data; stream->crc = stream_backend->stream_crc_calculate( stream->a, stream->b, stream->c); } break; case CONTENT_CTL_LOAD: return content_load((content_ctx_info_t*)data); case CONTENT_CTL_NONE: default: break; } return true; }
bool content_ctl(enum content_ctl_state state, void *data) { static const struct file_archive_file_backend *stream_backend = NULL; static struct string_list *temporary_content = NULL; static bool content_is_inited = false; static bool core_does_not_need_content = false; static uint32_t content_crc = 0; switch(state) { case CONTENT_CTL_LOAD_RAM_FILE: return load_ram_file(data); case CONTENT_CTL_SAVE_RAM_FILE: return save_ram_file((ram_type_t*)data); case CONTENT_CTL_DOES_NOT_NEED_CONTENT: return core_does_not_need_content; case CONTENT_CTL_SET_DOES_NOT_NEED_CONTENT: core_does_not_need_content = true; break; case CONTENT_CTL_UNSET_DOES_NOT_NEED_CONTENT: core_does_not_need_content = false; break; case CONTENT_CTL_GET_CRC: { uint32_t **content_crc_ptr = (uint32_t**)data; if (!content_crc_ptr) return false; *content_crc_ptr = &content_crc; } break; case CONTENT_CTL_LOAD_STATE: { const char *path = (const char*)data; if (!path) return false; return content_load_state(path); } case CONTENT_CTL_SAVE_STATE: { const char *path = (const char*)data; if (!path) return false; return content_save_state(path); } case CONTENT_CTL_IS_INITED: return content_is_inited; case CONTENT_CTL_DEINIT: content_ctl(CONTENT_CTL_TEMPORARY_FREE, NULL); content_crc = 0; content_is_inited = false; core_does_not_need_content = false; break; case CONTENT_CTL_INIT: content_is_inited = false; temporary_content = string_list_new(); if (!temporary_content) return false; if (content_file_init(temporary_content)) { content_is_inited = true; return true; } content_ctl(CONTENT_CTL_DEINIT, NULL); return false; case CONTENT_CTL_TEMPORARY_FREE: content_file_free(temporary_content); temporary_content = NULL; break; case CONTENT_CTL_STREAM_INIT: #ifdef HAVE_ZLIB if (!stream_backend) stream_backend = file_archive_get_default_file_backend(); #endif break; case CONTENT_CTL_STREAM_CRC_CALCULATE: { content_stream_t *stream = NULL; content_ctl(CONTENT_CTL_STREAM_INIT, NULL); stream = (content_stream_t*)data; #ifdef HAVE_ZLIB stream->crc = stream_backend->stream_crc_calculate( stream->a, stream->b, stream->c); #endif } break; case CONTENT_CTL_LOAD: return content_load((content_ctx_info_t*)data); case CONTENT_CTL_NONE: default: break; } return true; }