/** * main_exit_save_config: * * Saves configuration file to disk, and (optionally) * autosave state. **/ void main_exit_save_config(void) { settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); rarch_system_info_t *info = rarch_system_info_get_ptr(); if (settings->config_save_on_exit && *global->config_path) { /* restore original paths in case per-core organization is enabled */ if (settings->sort_savefiles_enable && orig_savefile_dir[0] != '\0') strlcpy(global->savefile_dir,orig_savefile_dir,sizeof(global->savefile_dir)); if (settings->sort_savestates_enable && orig_savestate_dir[0] != '\0') strlcpy(global->savestate_dir,orig_savestate_dir,sizeof(global->savestate_dir)); /* restore system directory if it was set to <content dir> */ if(settings->system_in_content_dir && !strcmp(info->info.library_name,"No Core")) settings->system_directory[0] = '\0'; /* Save last core-specific config to the default config location, * needed on consoles for core switching and reusing last good * config for new cores. */ config_save_file(global->config_path); /* Flush out the core specific config. */ if (*global->core_specific_config_path && settings->core_specific_config) config_save_file(global->core_specific_config_path); } event_command(EVENT_CMD_AUTOSAVE_STATE); }
/** * main_exit_save_config: * * Saves configuration file to disk, and (optionally) * autosave state. **/ void main_exit_save_config(void) { settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); if (settings->config_save_on_exit && *global->config_path) { /* restore original paths in case per-core organization is enabled */ if (settings->sort_savefiles_enable && orig_savefile_dir[0] != '\0') strlcpy(global->savefile_dir,orig_savefile_dir,sizeof(global->savefile_dir)); if (settings->sort_savestates_enable && orig_savestate_dir[0] != '\0') strlcpy(global->savestate_dir,orig_savestate_dir,sizeof(global->savestate_dir)); /* Save last core-specific config to the default config location, * needed on consoles for core switching and reusing last good * config for new cores. */ config_save_file(global->config_path); /* Flush out the core specific config. */ if (*global->core_specific_config_path && settings->core_specific_config) config_save_file(global->core_specific_config_path); } event_command(EVENT_CMD_AUTOSAVE_STATE); }
int main() { /* Initialize the configuration */ config_init(&cfg); /* Load the file */ printf("loading [test.cfg].."); if (!config_load_file(&cfg, "test.cfg")) printf("failed\n"); else { printf("ok\n"); /* Add setting "foo" */ printf("add setting \"foo\".."); config_setting_t *setting = config_setting_add(cfg.root,"foo",CONFIG_TYPE_INT); if (!setting) printf("failed\n"); else { config_setting_set_int(setting,1234); printf("ok\n"); /* Save to "testfoo.cfg" */ printf("saving [testfoo.cfg].."); config_save_file(&cfg, "testfoo.cfg"); printf("ok\n"); printf("Done!\n"); } } /* Free the configuration */ config_destroy(&cfg); return 0; }
/** * event_save_current_config: * * Saves current configuration file to disk, and (optionally) * autosave state. **/ void event_save_current_config(void) { settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); if (settings->config_save_on_exit && *global->path.config) { /* Save last core-specific config to the default config location, * needed on consoles for core switching and reusing last good * config for new cores. */ config_save_file(global->path.config); /* Flush out the core specific config. */ if (*global->path.core_specific_config && settings->core_specific_config) config_save_file(global->path.core_specific_config); } event_command(EVENT_CMD_AUTOSAVE_STATE); }
void config_load(void) { // Flush out per-core configs before loading a new config. if (*g_extern.core_specific_config_path && g_extern.config_save_on_exit && g_settings.core_specific_config) config_save_file(g_extern.core_specific_config_path); if (!g_extern.block_config_read) { config_set_defaults(); parse_config_file(); } // Per-core config handling. config_load_core_specific(); }
/** * event_save_current_config: * * Saves current configuration file to disk, and (optionally) * autosave state. **/ void event_save_current_config(void) { char msg[128]; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); bool ret = false; if (settings->config_save_on_exit && !string_is_empty(global->path.config)) { /* Save last core-specific config to the default config location, * needed on consoles for core switching and reusing last good * config for new cores. */ /* Flush out the core specific config. */ if (*global->path.core_specific_config && settings->core_specific_config) ret = config_save_file(global->path.core_specific_config); else ret = config_save_file(global->path.config); if (ret) { snprintf(msg, sizeof(msg), "Saved new config to \"%s\".", global->path.config); RARCH_LOG("%s\n", msg); } else { snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".", global->path.config); RARCH_ERR("%s\n", msg); } runloop_msg_queue_push(msg, 1, 180, true); } }
// this can be called from more tasks (gui, prop handler, menu), so it needs to be thread safe void config_save() { #ifdef CONFIG_CONFIG_FILE take_semaphore(config_save_sem, 0); update_disp_mode_bits_from_params(); char config_file[0x80]; snprintf(config_file, sizeof(config_file), "%smagic.cfg", get_config_dir()); config_save_file(config_file); config_menu_save_flags(); module_save_configs(); if (config_deleted) config_autosave = 1; /* this can be improved, because it's not doing a proper "undo" */ config_deleted = 0; give_semaphore(config_save_sem); #endif }
/* Quite intrusive and error prone. * Likely to have lots of small bugs. * Cleanly exit the main loop to ensure that all the tiny details * get set properly. * This should mitigate most of the smaller bugs. */ bool menu_replace_config(const char *path) { if (strcmp(path, g_extern.config_path) == 0) return false; if (g_settings.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); strlcpy(g_extern.config_path, path, sizeof(g_extern.config_path)); g_extern.block_config_read = false; *g_settings.libretro = '\0'; /* Load core in new config. */ rarch_main_command(RARCH_CMD_PREPARE_DUMMY); return true; }
bool rarch_replace_config(const char *path) { settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); /* If config file to be replaced is the same as the * current config file, exit. */ if (!strcmp(path, global->config_path)) return false; if (settings->config_save_on_exit && *global->config_path) config_save_file(global->config_path); strlcpy(global->config_path, path, sizeof(global->config_path)); global->block_config_read = false; *settings->libretro = '\0'; /* Load core in new config. */ event_command(EVENT_CMD_PREPARE_DUMMY); return true; }
// Quite intrusive and error prone. // Likely to have lots of small bugs. // Cleanly exit the main loop to ensure that all the tiny details get set properly. // This should mitigate most of the smaller bugs. bool menu_replace_config(void *data, const char *path) { rgui_handle_t *rgui; rgui = (rgui_handle_t*)data; if (strcmp(path, g_extern.config_path) == 0 || !rgui) return false; if (g_extern.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); strlcpy(g_extern.config_path, path, sizeof(g_extern.config_path)); g_extern.block_config_read = false; // Load dummy core. *g_extern.fullpath = '\0'; *g_settings.libretro = '\0'; // Load core in new config. g_extern.lifecycle_state |= (1ULL << MODE_LOAD_GAME); rgui->load_no_rom = false; return true; }
/** * event_save_core_config: * * Saves a new (core) configuration to a file. Filename is based * on heuristics to avoid typing. * * Returns: true (1) on success, otherwise false (0). **/ static bool event_save_core_config(void) { char config_dir[PATH_MAX_LENGTH] = {0}; char config_name[PATH_MAX_LENGTH] = {0}; char config_path[PATH_MAX_LENGTH] = {0}; char msg[128] = {0}; bool ret = false; bool found_path = false; bool overrides_active = false; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); *config_dir = '\0'; if (*settings->menu_config_directory) strlcpy(config_dir, settings->menu_config_directory, sizeof(config_dir)); else if (*global->path.config) /* Fallback */ fill_pathname_basedir(config_dir, global->path.config, sizeof(config_dir)); else { runloop_msg_queue_push(msg_hash_to_str(MSG_CONFIG_DIRECTORY_NOT_SET), 1, 180, true); RARCH_ERR("%s\n", msg_hash_to_str(MSG_CONFIG_DIRECTORY_NOT_SET)); return false; } /* Infer file name based on libretro core. */ if (*settings->libretro && path_file_exists(settings->libretro)) { unsigned i; /* In case of collision, find an alternative name. */ for (i = 0; i < 16; i++) { char tmp[64]; fill_pathname_base(config_name, settings->libretro, sizeof(config_name)); path_remove_extension(config_name); fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path)); if (i) snprintf(tmp, sizeof(tmp), "-%u.cfg", i); else strlcpy(tmp, ".cfg", sizeof(tmp)); snprintf(config_path, sizeof(config_path), "%s%s", config_path, tmp); if (!path_file_exists(config_path)) { found_path = true; break; } } } /* Fallback to system time... */ if (!found_path) { RARCH_WARN("Cannot infer new config path. Use current time.\n"); fill_dated_filename(config_name, "cfg", sizeof(config_name)); fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path)); } /* Overrides block config file saving, make it appear as overrides * weren't enabled for a manual save */ if (runloop_ctl(RUNLOOP_CTL_IS_OVERRIDES_ACTIVE, NULL)) { runloop_ctl(RUNLOOP_CTL_UNSET_OVERRIDES_ACTIVE, NULL); overrides_active = true; } if ((ret = config_save_file(config_path))) { strlcpy(global->path.config, config_path, sizeof(global->path.config)); snprintf(msg, sizeof(msg), "Saved new config to \"%s\".", config_path); RARCH_LOG("%s\n", msg); } else { snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".", config_path); RARCH_ERR("%s\n", msg); } runloop_msg_queue_push(msg, 1, 180, true); if (overrides_active) runloop_ctl(RUNLOOP_CTL_SET_OVERRIDES_ACTIVE, NULL); else runloop_ctl(RUNLOOP_CTL_UNSET_OVERRIDES_ACTIVE, NULL); return ret; }
// Save a new config to a file. Filename is based on heuristics to avoid typing. bool menu_save_new_config(void) { char config_dir[PATH_MAX]; *config_dir = '\0'; if (*g_settings.rgui_config_directory) strlcpy(config_dir, g_settings.rgui_config_directory, sizeof(config_dir)); else if (*g_extern.config_path) // Fallback fill_pathname_basedir(config_dir, g_extern.config_path, sizeof(config_dir)); else { const char *msg = "Config directory not set. Cannot save new config."; msg_queue_clear(g_extern.msg_queue); msg_queue_push(g_extern.msg_queue, msg, 1, 180); RARCH_ERR("%s\n", msg); return false; } bool found_path = false; char config_name[PATH_MAX]; char config_path[PATH_MAX]; if (*g_settings.libretro && path_file_exists(g_settings.libretro)) // Infer file name based on libretro core. { unsigned i; // In case of collision, find an alternative name. for (i = 0; i < 16; i++) { fill_pathname_base(config_name, g_settings.libretro, sizeof(config_name)); path_remove_extension(config_name); fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path)); char tmp[64]; *tmp = '\0'; if (i) snprintf(tmp, sizeof(tmp), "-%u.cfg", i); else strlcpy(tmp, ".cfg", sizeof(tmp)); strlcat(config_path, tmp, sizeof(config_path)); if (!path_file_exists(config_path)) { found_path = true; break; } } } // Fallback to system time ... if (!found_path) { RARCH_WARN("Cannot infer new config path. Use current time.\n"); fill_dated_filename(config_name, "cfg", sizeof(config_name)); fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path)); } char msg[512]; bool ret; if (config_save_file(config_path)) { strlcpy(g_extern.config_path, config_path, sizeof(g_extern.config_path)); snprintf(msg, sizeof(msg), "Saved new config to \"%s\".", config_path); RARCH_LOG("%s\n", msg); ret = true; } else { snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".", config_path); RARCH_ERR("%s\n", msg); ret = false; } msg_queue_clear(g_extern.msg_queue); msg_queue_push(g_extern.msg_queue, msg, 1, 180); return ret; }
/** * event_save_core_config: * * Saves a new (core) configuration to a file. Filename is based * on heuristics to avoid typing. * * Returns: true (1) on success, otherwise false (0). **/ static bool event_save_core_config(void) { char config_dir[PATH_MAX_LENGTH] = {0}; char config_name[PATH_MAX_LENGTH] = {0}; char config_path[PATH_MAX_LENGTH] = {0}; char msg[PATH_MAX_LENGTH] = {0}; bool ret = false; bool found_path = false; bool overrides_active = false; settings_t *settings = config_get_ptr(); global_t *global = global_get_ptr(); *config_dir = '\0'; if (*settings->menu_config_directory) strlcpy(config_dir, settings->menu_config_directory, sizeof(config_dir)); else if (*global->config_path) /* Fallback */ fill_pathname_basedir(config_dir, global->config_path, sizeof(config_dir)); else { const char *message = "Config directory not set. Cannot save new config."; rarch_main_msg_queue_push(message, 1, 180, true); RARCH_ERR("%s\n", message); return false; } /* Infer file name based on libretro core. */ if (*settings->libretro && path_file_exists(settings->libretro)) { unsigned i; /* In case of collision, find an alternative name. */ for (i = 0; i < 16; i++) { char tmp[64] = {0}; fill_pathname_base(config_name, settings->libretro, sizeof(config_name)); path_remove_extension(config_name); fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path)); *tmp = '\0'; if (i) snprintf(tmp, sizeof(tmp), "-%u.cfg", i); else strlcpy(tmp, ".cfg", sizeof(tmp)); strlcat(config_path, tmp, sizeof(config_path)); if (!path_file_exists(config_path)) { found_path = true; break; } } } /* Fallback to system time... */ if (!found_path) { RARCH_WARN("Cannot infer new config path. Use current time.\n"); fill_dated_filename(config_name, "cfg", sizeof(config_name)); fill_pathname_join(config_path, config_dir, config_name, sizeof(config_path)); } /* Overrides block config file saving, make it appear as overrides weren't enabled for a manual save */ if (global->overrides_active) { global->overrides_active = false; overrides_active = true; } if ((ret = config_save_file(config_path))) { strlcpy(global->config_path, config_path, sizeof(global->config_path)); snprintf(msg, sizeof(msg), "Saved new config to \"%s\".", config_path); RARCH_LOG("%s\n", msg); } else { snprintf(msg, sizeof(msg), "Failed saving config to \"%s\".", config_path); RARCH_ERR("%s\n", msg); } rarch_main_msg_queue_push(msg, 1, 180, true); global->overrides_active = overrides_active; return ret; }
int rarch_main(int argc, char *argv[]) { //Initialize bps #ifndef HAVE_BB10 bps_initialize(); rarch_main_clear_state(); strlcpy(g_settings.libretro, "app/native/lib", sizeof(g_settings.libretro)); #endif strlcpy(g_extern.config_path, "app/native/retroarch.cfg", sizeof(g_extern.config_path)); strlcpy(g_settings.video.shader_dir, "app/native/shaders_glsl", sizeof(g_settings.video.shader_dir)); config_load(); g_extern.verbose = true; menu_init(); g_extern.lifecycle_mode_state |= (1ULL << MODE_LOAD_GAME); #ifdef HAVE_BB10 if (!g_extern.libretro_dummy) menu_rom_history_push_current(); #endif for (;;) { if (g_extern.system.shutdown) break; else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME)) { load_menu_game_prepare(); // If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ... if (load_menu_game()) g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); else { #if defined(RARCH_CONSOLE) || defined(__BLACKBERRY_QNX__) g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); #else return 1; #endif } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT; while (!g_extern.system.shutdown && menu_iterate()); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else break; } g_extern.system.shutdown = false; menu_free(); if (g_extern.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); if (g_extern.main_is_init) rarch_main_deinit(); rarch_deinit_msg_queue(); #ifdef PERF_TEST rarch_perf_log(); #endif error: bps_shutdown(); return 0; }
bool rarch_ctl(enum rarch_ctl_state state, void *data) { driver_t *driver = driver_get_ptr(); global_t *global = global_get_ptr(); settings_t *settings = config_get_ptr(); rarch_system_info_t *system = rarch_system_info_get_ptr(); switch(state) { case RARCH_ACTION_STATE_REPLACE_CONFIG: { char *path = (char*)data; if (!path) return false; /* If config file to be replaced is the same as the * current config file, exit. */ if (!strcmp(path, global->path.config)) return false; if (settings->config_save_on_exit && *global->path.config) config_save_file(global->path.config); strlcpy(global->path.config, path, sizeof(global->path.config)); global->block_config_read = false; *settings->libretro = '\0'; /* Load core in new config. */ } event_command(EVENT_CMD_PREPARE_DUMMY); return true; case RARCH_ACTION_STATE_MENU_RUNNING: #ifdef HAVE_MENU menu_driver_toggle(true); #endif #ifdef HAVE_OVERLAY if (settings->input.overlay_hide_in_menu) event_command(EVENT_CMD_OVERLAY_DEINIT); #endif break; case RARCH_ACTION_STATE_LOAD_CONTENT: #ifdef HAVE_MENU /* If content loading fails, we go back to menu. */ if (!menu_load_content(CORE_TYPE_PLAIN)) rarch_ctl(RARCH_ACTION_STATE_MENU_RUNNING, NULL); #endif if (driver->frontend_ctx && driver->frontend_ctx->content_loaded) driver->frontend_ctx->content_loaded(); break; #ifdef HAVE_FFMPEG case RARCH_ACTION_STATE_LOAD_CONTENT_FFMPEG: #ifdef HAVE_MENU /* If content loading fails, we go back to menu. */ if (!menu_load_content(CORE_TYPE_FFMPEG)) rarch_ctl(RARCH_ACTION_STATE_MENU_RUNNING, NULL); #endif if (driver->frontend_ctx && driver->frontend_ctx->content_loaded) driver->frontend_ctx->content_loaded(); break; #endif case RARCH_ACTION_STATE_LOAD_CONTENT_IMAGEVIEWER: #ifdef HAVE_MENU /* If content loading fails, we go back to menu. */ if (!menu_load_content(CORE_TYPE_IMAGEVIEWER)) rarch_ctl(RARCH_ACTION_STATE_MENU_RUNNING, NULL); #endif if (driver->frontend_ctx && driver->frontend_ctx->content_loaded) driver->frontend_ctx->content_loaded(); break; case RARCH_ACTION_STATE_MENU_RUNNING_FINISHED: #ifdef HAVE_MENU menu_driver_toggle(false); #endif video_driver_set_texture_enable(false, false); #ifdef HAVE_OVERLAY if (settings && settings->input.overlay_hide_in_menu) event_command(EVENT_CMD_OVERLAY_INIT); #endif break; case RARCH_ACTION_STATE_QUIT: if (global) system->shutdown = true; rarch_ctl(RARCH_ACTION_STATE_MENU_RUNNING_FINISHED, NULL); break; case RARCH_ACTION_STATE_FORCE_QUIT: rarch_ctl(RARCH_ACTION_STATE_QUIT, NULL); break; case RARCH_ACTION_STATE_VALIDATE_CPU_FEATURES: { uint64_t cpu = retro_get_cpu_features(); (void)cpu; #ifdef __SSE__ if (!(cpu & RETRO_SIMD_SSE)) FAIL_CPU("SSE"); #endif #ifdef __SSE2__ if (!(cpu & RETRO_SIMD_SSE2)) FAIL_CPU("SSE2"); #endif #ifdef __AVX__ if (!(cpu & RETRO_SIMD_AVX)) FAIL_CPU("AVX"); #endif } break; case RARCH_ACTION_STATE_VERIFY_API_VERSION: RARCH_LOG("Version of libretro API: %u\n", core.retro_api_version()); RARCH_LOG("Compiled against API: %u\n", RETRO_API_VERSION); if (core.retro_api_version() != RETRO_API_VERSION) RARCH_WARN("%s\n", msg_hash_to_str(MSG_LIBRETRO_ABI_BREAK)); break; case RARCH_ACTION_STATE_FILL_PATHNAMES: rarch_init_savefile_paths(); strlcpy(global->bsv.movie_path, global->name.savefile, sizeof(global->bsv.movie_path)); if (!*global->name.base) return false; if (!*global->name.ups) fill_pathname_noext(global->name.ups, global->name.base, ".ups", sizeof(global->name.ups)); if (!*global->name.bps) fill_pathname_noext(global->name.bps, global->name.base, ".bps", sizeof(global->name.bps)); if (!*global->name.ips) fill_pathname_noext(global->name.ips, global->name.base, ".ips", sizeof(global->name.ips)); break; case RARCH_ACTION_STATE_NONE: default: return false; } return true; }
void* rarch_main_ios(void* args) { struct rarch_main_wrap* argdata = (struct rarch_main_wrap*)args; int init_ret = rarch_main_init_wrap(argdata); ios_free_main_wrap(argdata); if (init_ret) { rarch_main_clear_state(); dispatch_async_f(dispatch_get_main_queue(), (void*)1, ios_rarch_exited); return 0; } #ifdef HAVE_RGUI char* system_directory = ios_get_rarch_system_directory(); strlcpy(g_extern.savestate_dir, system_directory, sizeof(g_extern.savestate_dir)); strlcpy(g_extern.savefile_dir, system_directory, sizeof(g_extern.savefile_dir)); menu_init(); g_extern.lifecycle_mode_state |= 1ULL << MODE_GAME; // If we started a ROM directly from command line, // push it to ROM history. if (!g_extern.libretro_dummy) menu_rom_history_push_current(); for (;;) { if (g_extern.system.shutdown) break; else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME)) { load_menu_game_prepare(); // If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ... if (load_menu_game()) g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); else { #ifdef RARCH_CONSOLE g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); #else // This needs to be here to tell the GUI thread that the emulator loop has stopped, // the (void*)1 makes it display the 'Failed to load game' message. dispatch_async_f(dispatch_get_main_queue(), (void*)1, ios_rarch_exited); return 1; #endif } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()) process_events(); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT; while (!g_extern.system.shutdown && menu_iterate()) process_events(); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else break; } g_extern.system.shutdown = false; menu_free(); if (g_extern.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); if (g_extern.main_is_init) rarch_main_deinit(); free(system_directory); #else while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()); rarch_main_deinit(); #endif rarch_deinit_msg_queue(); #ifdef PERF_TEST rarch_perf_log(); #endif rarch_main_clear_state(); dispatch_async_f(dispatch_get_main_queue(), 0, ios_rarch_exited); return 0; }
static void *android_app_entry(void *data) { struct android_app* android_app = (struct android_app*)data; android_app->config = AConfiguration_new(); AConfiguration_fromAssetManager(android_app->config, android_app->activity->assetManager); print_cur_config(android_app); ALooper* looper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS); ALooper_addFd(looper, android_app->msgread, LOOPER_ID_MAIN, ALOOPER_EVENT_INPUT, NULL, NULL); android_app->looper = looper; pthread_mutex_lock(&android_app->mutex); android_app->running = 1; pthread_cond_broadcast(&android_app->cond); pthread_mutex_unlock(&android_app->mutex); memset(&g_android, 0, sizeof(g_android)); g_android = android_app; RARCH_LOG("Native Activity started.\n"); rarch_main_clear_state(); while (!android_app->window) { if (!android_run_events(android_app)) goto exit; } rarch_init_msg_queue(); if (!android_app_start_main(android_app)) { g_settings.input.overlay[0] = 0; // threaded video doesn't work right for just displaying one frame g_settings.video.threaded = false; init_drivers(); driver.video_poke->set_aspect_ratio(driver.video_data, ASPECT_RATIO_SQUARE); rarch_render_cached_frame(); sleep(2); goto exit; } if (!g_extern.libretro_dummy) menu_rom_history_push_current(); for (;;) { if (g_extern.system.shutdown) break; else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME)) { load_menu_game_prepare(); // If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ... if (load_menu_game()) g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); else { #ifdef RARCH_CONSOLE g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); #else return NULL; #endif } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { driver.input->poll(NULL); if (driver.video_poke->set_aspect_ratio) driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_start_func(); // Main loop while (rarch_main_iterate()); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_stop_func(); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT); while((input_key_pressed_func(RARCH_PAUSE_TOGGLE)) ? android_run_events(android_app) : menu_iterate()); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else break; } exit: android_app->activityState = APP_CMD_DEAD; RARCH_LOG("Deinitializing RetroArch...\n"); menu_free(); if (g_extern.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); if (g_extern.main_is_init) rarch_main_deinit(); rarch_deinit_msg_queue(); #ifdef PERF_TEST rarch_perf_log(); #endif rarch_main_clear_state(); RARCH_LOG("android_app_destroy!"); if (android_app->inputQueue != NULL) AInputQueue_detachLooper(android_app->inputQueue); AConfiguration_delete(android_app->config); // exit() here is nasty. // pthread_exit(NULL) or return NULL; causes hanging ... // Should probably called ANativeActivity_finsih(), but it's bugged, it will hang our app. exit(0); }
int main(int argc, char *argv[]) #endif { frontend_ctx = (frontend_ctx_driver_t*)frontend_ctx_init_first(); if (frontend_ctx && frontend_ctx->init) frontend_ctx->init(); rarch_main_clear_state(); #ifndef __APPLE__ rarch_get_environment(argc, argv); #endif #if !defined(RARCH_CONSOLE) #if defined(__APPLE__) struct rarch_main_wrap* argdata = (struct rarch_main_wrap*)args; int init_ret = rarch_main_init_wrap(argdata); apple_free_main_wrap(argdata); if (init_ret) { rarch_main_clear_state(); dispatch_async_f(dispatch_get_main_queue(), (void*)1, apple_rarch_exited); return 0; } #else rarch_init_msg_queue(); int init_ret; if ((init_ret = rarch_main_init(argc, argv))) return init_ret; #endif #endif #ifdef HAVE_MENU menu_init(); #ifndef __APPLE__ if (frontend_ctx && frontend_ctx->process_args) frontend_ctx->process_args(argc, argv); #endif #ifdef RARCH_CONSOLE g_extern.lifecycle_mode_state |= 1ULL << MODE_LOAD_GAME; #else g_extern.lifecycle_mode_state |= 1ULL << MODE_GAME; #endif #ifndef RARCH_CONSOLE // If we started a ROM directly from command line, // push it to ROM history. if (!g_extern.libretro_dummy) menu_rom_history_push_current(); #endif for (;;) { if (g_extern.system.shutdown) break; else if (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME)) { load_menu_game_prepare(); // If ROM load fails, we exit RetroArch. On console it might make more sense to go back to menu though ... if (load_menu_game()) g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); else { #if defined(RARCH_CONSOLE) || defined(__QNX__) g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); #else if (frontend_ctx && frontend_ctx->shutdown) frontend_ctx->shutdown(true); return 1; #endif } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_LOAD_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { #ifdef RARCH_CONSOLE driver.input->poll(NULL); #endif if (driver.video_poke->set_aspect_ratio) driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx); while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()) { if (frontend_ctx && frontend_ctx->process_events) frontend_ctx->process_events(); if (!(g_extern.lifecycle_mode_state & (1ULL << MODE_GAME))) break; } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= 1ULL << MODE_MENU_PREINIT; // Menu should always run with vsync on. video_set_nonblock_state_func(false); if (driver.audio_data) audio_stop_func(); while (!g_extern.system.shutdown && menu_iterate()) { if (frontend_ctx && frontend_ctx->process_events) frontend_ctx->process_events(); if (!(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU))) break; } driver_set_nonblock_state(driver.nonblock_state); if (driver.audio_data && !audio_start_func()) { RARCH_ERR("Failed to resume audio driver. Will continue without audio.\n"); g_extern.audio_active = false; } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else break; } g_extern.system.shutdown = false; menu_free(); if (g_extern.config_save_on_exit && *g_extern.config_path) config_save_file(g_extern.config_path); #ifdef GEKKO /* Per-core input config saving */ config_save_keybinds(g_extern.input_config_path); #endif #ifdef RARCH_CONSOLE global_uninit_drivers(); #endif #else while ((g_extern.is_paused && !g_extern.is_oneshot) ? rarch_main_idle_iterate() : rarch_main_iterate()); #endif rarch_main_deinit(); rarch_deinit_msg_queue(); #ifdef PERF_TEST rarch_perf_log(); #endif #if defined(HAVE_LOGGER) logger_shutdown(); #elif defined(HAVE_FILE_LOGGER) if (g_extern.log_file) fclose(g_extern.log_file); g_extern.log_file = NULL; #endif if (frontend_ctx && frontend_ctx->deinit) frontend_ctx->deinit(); if (g_extern.lifecycle_mode_state & (1ULL << MODE_EXITSPAWN) && frontend_ctx && frontend_ctx->exitspawn) frontend_ctx->exitspawn(); rarch_main_clear_state(); if (frontend_ctx && frontend_ctx->shutdown) frontend_ctx->shutdown(false); return 0; }
int rarch_main(int argc, char *argv[]) { system_init(); rarch_main_clear_state(); verbose_log_init(); get_environment_settings(argc, argv); config_load(); init_libretro_sym(); rarch_init_system_info(); global_init_drivers(); #ifdef HAVE_LIBRETRO_MANAGEMENT char core_exe_path[PATH_MAX]; char path_prefix[PATH_MAX]; const char *extension = DEFAULT_EXE_EXT; char slash; #if defined(_WIN32) slash = '\\'; #else slash = '/'; #endif snprintf(path_prefix, sizeof(path_prefix), "%s%c", default_paths.core_dir, slash); snprintf(core_exe_path, sizeof(core_exe_path), "%sCORE%s", path_prefix, extension); if (path_file_exists(core_exe_path)) { RARCH_LOG("core_exe_path: %s\n", core_exe_path); if (install_libretro_core(core_exe_path, path_prefix, extension)) { RARCH_LOG("New default libretro core saved to config file: %s.\n", g_settings.libretro); config_save_file(g_extern.config_path); } } #endif init_libretro_sym(); system_post_init(); menu_init(); system_process_args(argc, argv); begin_loop: if(g_extern.lifecycle_mode_state & (1ULL << MODE_GAME)) { driver.input->poll(NULL); if (driver.video_poke->set_aspect_ratio) driver.video_poke->set_aspect_ratio(driver.video_data, g_settings.video.aspect_ratio_idx); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_start_func(); while(rarch_main_iterate()); if (g_extern.lifecycle_mode_state & (1ULL << MODE_VIDEO_THROTTLE_ENABLE)) audio_stop_func(); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_GAME); } else if (g_extern.lifecycle_mode_state & (1ULL << MODE_INIT)) { if(g_extern.main_is_init) rarch_main_deinit(); struct rarch_main_wrap args = {0}; args.verbose = g_extern.verbose; args.sram_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_SRAM_DIR_ENABLE)) ? g_extern.console.main_wrap.default_sram_dir : NULL; args.state_path = (g_extern.lifecycle_mode_state & (1ULL << MODE_LOAD_GAME_STATE_DIR_ENABLE)) ? g_extern.console.main_wrap.default_savestate_dir : NULL; args.rom_path = g_extern.fullpath; args.libretro_path = g_settings.libretro; if (path_file_exists(g_extern.config_path)) args.config_path = g_extern.config_path; else args.config_path = NULL; if (rarch_main_init_wrap(&args) == 0) { RARCH_LOG("rarch_main_init succeeded.\n"); g_extern.lifecycle_mode_state |= (1ULL << MODE_GAME); } else { RARCH_ERR("rarch_main_init failed.\n"); g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU); menu_settings_msg(S_MSG_ROM_LOADING_ERROR, 180); } g_extern.lifecycle_mode_state &= ~(1ULL << MODE_INIT); } else if(g_extern.lifecycle_mode_state & (1ULL << MODE_MENU)) { g_extern.lifecycle_mode_state |= (1ULL << MODE_MENU_PREINIT); while (menu_iterate()); g_extern.lifecycle_mode_state &= ~(1ULL << MODE_MENU); } else goto begin_shutdown; goto begin_loop; begin_shutdown: config_save_file(g_extern.config_path); system_deinit_save(); if(g_extern.main_is_init) rarch_main_deinit(); menu_free(); global_uninit_drivers(); #ifdef PERF_TEST rarch_perf_log(); #endif system_deinit(); if (g_extern.lifecycle_mode_state & (1ULL << MODE_EXITSPAWN)) system_exitspawn(); return 1; }