Skip to content

Commit

Permalink
Config appendconfig + saving + logging (#14505)
Browse files Browse the repository at this point in the history
* Config override + logging cleanups

* 'config_save_on_exit' cleanup
  • Loading branch information
sonninnos committed Oct 12, 2022
1 parent 8b39654 commit 50ace05
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 56 deletions.
119 changes: 82 additions & 37 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,45 @@ static void video_driver_load_settings(global_t *global,
}
#endif

static void check_verbosity_settings(config_file_t *conf,
settings_t *settings)
{
unsigned tmp_uint = 0;
bool tmp_bool = false;

/* Make sure log_to_file is true if 'log-file' command line argument was used. */
if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_LOG_TO_FILE, NULL))
{
configuration_set_bool(settings, settings->bools.log_to_file, true);
}
else
{
/* Make sure current 'log_to_file' is effective */
if (config_get_bool(conf, "log_to_file", &tmp_bool))
configuration_set_bool(settings, settings->bools.log_to_file, tmp_bool);
}

/* Set frontend log level */
if (config_get_uint(conf, "frontend_log_level", &tmp_uint))
verbosity_set_log_level(tmp_uint);

/* Set verbosity according to config only if command line argument was not used. */
if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_VERBOSITY, NULL))
{
verbosity_enable();
}
else
{
if (config_get_bool(conf, "log_verbosity", &tmp_bool))
{
if (tmp_bool)
verbosity_enable();
else
verbosity_disable();
}
}
}

/**
* config_load:
* @path : path to be read from.
Expand Down Expand Up @@ -3310,6 +3349,17 @@ static bool config_load_file(global_t *global,
array_settings = populate_settings_array (settings, &array_settings_size);
path_settings = populate_settings_path (settings, &path_settings_size);

/* Initialize verbosity settings */
check_verbosity_settings(conf, settings);

if (!first_load)
{
if (!path)
RARCH_LOG("[Config]: Loading default config.\n");
else
RARCH_LOG("[Config]: Loading config: \"%s\".\n", path);
}

if (!path_is_empty(RARCH_PATH_CONFIG_APPEND))
{
/* Don't destroy append_config_path, store in temporary
Expand All @@ -3324,12 +3374,18 @@ static bool config_load_file(global_t *global,
{
bool result = config_append_file(conf, extra_path);

RARCH_LOG("[Config]: Appending config \"%s\".\n", extra_path);
if (!first_load)
{
RARCH_LOG("[Config]: Appending config: \"%s\".\n", extra_path);

if (!result)
RARCH_ERR("[Config]: Failed to append config \"%s\".\n", extra_path);
if (!result)
RARCH_ERR("[Config]: Failed to append config: \"%s\".\n", extra_path);
}
extra_path = strtok_r(NULL, "|", &save);
}

/* Re-check verbosity settings */
check_verbosity_settings(conf, settings);
}

#if 0
Expand Down Expand Up @@ -3367,28 +3423,6 @@ static bool config_load_file(global_t *global,
settings->bools.network_remote_enable_user[i], tmp_bool);
}
#endif
/* Set verbosity according to config only if the 'v' command line argument was not used
* or if it is not the first config load. */
if (config_get_bool(conf, "log_verbosity", &tmp_bool) &&
(!retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_VERBOSITY, NULL) ||
!first_load))
{
if (tmp_bool)
verbosity_enable();
else
verbosity_disable();
}
/* On first config load, make sure log_to_file is true if 'log-file' command line
* argument was used. */
if (retroarch_override_setting_is_set(RARCH_OVERRIDE_SETTING_LOG_TO_FILE, NULL) &&
first_load)
{
configuration_set_bool(settings,settings->bools.log_to_file,true);
}
if (config_get_uint(conf, "frontend_log_level", &tmp_uint))
{
verbosity_set_log_level(tmp_uint);
}

/* Integer settings */

Expand Down Expand Up @@ -3906,14 +3940,33 @@ bool config_load_override(void *data)
".cfg",
sizeof(core_path));

/* Prevent "--appendconfig" from being ignored */
if (!path_is_empty(RARCH_PATH_CONFIG_APPEND))
should_append = true;

/* per-core overrides */
/* Create a new config file from core_path */
if (path_is_valid(core_path))
{
char tmp_path[PATH_MAX_LENGTH + 1];

RARCH_LOG("[Overrides]: Core-specific overrides found at \"%s\".\n",
core_path);

path_set(RARCH_PATH_CONFIG_APPEND, core_path);
if (should_append)
{
size_t _len = strlcpy(tmp_path,
path_get(RARCH_PATH_CONFIG_APPEND),
sizeof(tmp_path));
tmp_path[_len ] = '|';
tmp_path[_len+1] = '\0';
strlcat(tmp_path, core_path, sizeof(tmp_path));
RARCH_LOG("[Overrides]: Core-specific overrides stacking on top of previous overrides.\n");
}
else
strlcpy(tmp_path, core_path, sizeof(tmp_path));

path_set(RARCH_PATH_CONFIG_APPEND, tmp_path);

should_append = true;
}
Expand Down Expand Up @@ -4174,19 +4227,11 @@ bool config_load_remap(const char *directory_input_remapping,
static void config_parse_file(global_t *global)
{
const char *config_path = path_get(RARCH_PATH_CONFIG);
if (path_is_empty(RARCH_PATH_CONFIG))
{
RARCH_LOG("[Config]: Loading default config.\n");
}
else
RARCH_LOG("[Config]: Loading config from: \"%s\".\n", config_path);

if (!config_load_file(global, config_path, config_st))
{
if (!config_load_file(global, config_path, config_st))
{
RARCH_ERR("[Config]: Couldn't find config at path: \"%s\".\n",
config_path);
}
RARCH_ERR("[Config]: Config not found at: \"%s\".\n",
config_path);
}
}

Expand Down
26 changes: 13 additions & 13 deletions retroarch.c
Original file line number Diff line number Diff line change
Expand Up @@ -3687,8 +3687,6 @@ static void sdl_exit(void)
*
* Cleanly exit RetroArch.
*
* Also saves configuration files to disk,
* and (optionally) autosave state.
**/
void main_exit(void *args)
{
Expand All @@ -3698,13 +3696,9 @@ void main_exit(void *args)
struct menu_state *menu_st = menu_state_get_ptr();
#endif
settings_t *settings = config_get_ptr();
bool config_save_on_exit = settings->bools.config_save_on_exit;

video_driver_restore_cached(settings);

if (config_save_on_exit)
command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL);

#if defined(HAVE_GFX_WIDGETS)
/* Do not want display widgets to live any more. */
dispwidget_get_ptr()->flags &= ~DISPGFX_WIDGET_FLAG_PERSISTING;
Expand Down Expand Up @@ -6164,18 +6158,16 @@ void retroarch_fail(int error_code, const char *error)
longjmp(global->error_sjlj_context, error_code);
}

/*
* Also saves configuration files to disk,
* and (optionally) autosave state.
*/
bool retroarch_main_quit(void)
{
runloop_state_t *runloop_st = runloop_state_get_ptr();
video_driver_state_t*video_st = video_state_get_ptr();
settings_t *settings = config_get_ptr();
/*Save configs before quitting
*as for UWP depending on `OnSuspending` is not important as we can call it directly here
*specifically we need to get width,height which requires UI thread and it will not be available on exit
*/
bool config_save_on_exit = settings->bools.config_save_on_exit;
if (config_save_on_exit)
command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL);

#ifdef HAVE_PRESENCE
{
presence_userdata_t userdata;
Expand Down Expand Up @@ -6206,6 +6198,14 @@ bool retroarch_main_quit(void)

if (!(runloop_st->flags & RUNLOOP_FLAG_SHUTDOWN_INITIATED))
{
/* Save configs before quitting
* as for UWP depending on `OnSuspending` is not important as we can call it directly here
* specifically we need to get width,height which requires UI thread and it will not be available on exit
*/
bool config_save_on_exit = settings->bools.config_save_on_exit;
if (config_save_on_exit)
command_event(CMD_EVENT_MENU_SAVE_CURRENT_CONFIG, NULL);

command_event_save_auto_state(
settings->bools.savestate_auto_save,
runloop_st->current_core_type);
Expand Down
11 changes: 5 additions & 6 deletions runloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -6770,22 +6770,22 @@ MENU_ST_FLAG_IS_BINDING;
{
bool load_dummy_core = false;

runloop_st->flags &= ~RUNLOOP_FLAG_CORE_SHUTDOWN_INITIATED;
runloop_st->flags &= ~RUNLOOP_FLAG_CORE_SHUTDOWN_INITIATED;

/* Check whether dummy core should be loaded
* instead of exiting RetroArch completely
* (aborts shutdown if invoked) */
if (settings->bools.load_dummy_on_core_shutdown)
{
load_dummy_core = true;
runloop_st->flags &= ~RUNLOOP_FLAG_SHUTDOWN_INITIATED;
runloop_st->flags &= ~RUNLOOP_FLAG_SHUTDOWN_INITIATED;
}

/* Unload current core, and load dummy if
* required */
if (!command_event(CMD_EVENT_UNLOAD_CORE, &load_dummy_core))
{
runloop_st->flags |= RUNLOOP_FLAG_SHUTDOWN_INITIATED;
runloop_st->flags |= RUNLOOP_FLAG_SHUTDOWN_INITIATED;
quit_runloop = true;
}

Expand All @@ -6795,12 +6795,11 @@ MENU_ST_FLAG_IS_BINDING;
else
quit_runloop = true;

runloop_st->flags &= ~RUNLOOP_FLAG_CORE_RUNNING;
runloop_st->flags &= ~RUNLOOP_FLAG_CORE_RUNNING;

if (quit_runloop)
{
old_quit_key = quit_key;
retroarch_main_quit();
return RUNLOOP_STATE_QUIT;
}
}
Expand Down Expand Up @@ -7768,7 +7767,7 @@ RUNLOOP_FLAG_PAUSED) || (menu_pause_libretro && (menu_state_get_ptr()->flags & M
{
case RUNLOOP_STATE_QUIT:
runloop_st->frame_limit_last_time = 0.0;
runloop_st->flags &= ~RUNLOOP_FLAG_CORE_RUNNING;
runloop_st->flags &= ~RUNLOOP_FLAG_CORE_RUNNING;
command_event(CMD_EVENT_QUIT, NULL);
return -1;
case RUNLOOP_STATE_POLLED_AND_SLEEP:
Expand Down

0 comments on commit 50ace05

Please sign in to comment.