mirror of
https://github.com/libretro/RetroArch
synced 2025-03-02 19:13:34 +00:00
Allow saving new config files directly from RGUI.
The file name is inferred to avoid typing.
This commit is contained in:
parent
c403438440
commit
8238ba7d50
@ -944,3 +944,81 @@ bool menu_replace_config(const char *path)
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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_is_directory(g_settings.libretro) && path_file_exists(g_settings.libretro)) // Infer file name based on libretro core.
|
||||
{
|
||||
// In case of collision, find an alternative name.
|
||||
for (unsigned 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;
|
||||
}
|
||||
|
||||
|
||||
|
@ -130,6 +130,7 @@ typedef enum
|
||||
RGUI_SETTINGS_OPEN_HISTORY,
|
||||
RGUI_SETTINGS_CORE,
|
||||
RGUI_SETTINGS_CONFIG,
|
||||
RGUI_SETTINGS_SAVE_CONFIG,
|
||||
RGUI_SETTINGS_CORE_OPTIONS,
|
||||
RGUI_SETTINGS_AUDIO_OPTIONS,
|
||||
RGUI_SETTINGS_INPUT_OPTIONS,
|
||||
@ -298,6 +299,8 @@ void menu_rom_history_push_current(void);
|
||||
|
||||
bool menu_replace_config(const char *path);
|
||||
|
||||
bool menu_save_new_config(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -761,6 +761,7 @@ static void render_text(rgui_handle_t *rgui)
|
||||
case RGUI_SETTINGS_VIDEO_OPTIONS:
|
||||
case RGUI_SETTINGS_AUDIO_OPTIONS:
|
||||
case RGUI_SETTINGS_DISK_OPTIONS:
|
||||
case RGUI_SETTINGS_SAVE_CONFIG:
|
||||
#ifdef HAVE_SHADER_MANAGER
|
||||
case RGUI_SETTINGS_SHADER_OPTIONS:
|
||||
case RGUI_SETTINGS_SHADER_PRESET:
|
||||
@ -1124,6 +1125,10 @@ static int rgui_settings_toggle_setting(rgui_handle_t *rgui, unsigned setting, r
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case RGUI_SETTINGS_SAVE_CONFIG:
|
||||
if (action == RGUI_ACTION_OK)
|
||||
menu_save_new_config();
|
||||
break;
|
||||
#ifdef HAVE_OVERLAY
|
||||
case RGUI_SETTINGS_OVERLAY_PRESET:
|
||||
switch (action)
|
||||
@ -1510,6 +1515,7 @@ static void rgui_settings_populate_entries(rgui_handle_t *rgui)
|
||||
rgui_list_push(rgui->selection_buf, "Restart RetroArch", RGUI_SETTINGS_RESTART_EMULATOR, 0);
|
||||
#endif
|
||||
rgui_list_push(rgui->selection_buf, "RetroArch Config", RGUI_SETTINGS_CONFIG, 0);
|
||||
rgui_list_push(rgui->selection_buf, "Save New Config", RGUI_SETTINGS_SAVE_CONFIG, 0);
|
||||
rgui_list_push(rgui->selection_buf, "Quit RetroArch", RGUI_SETTINGS_QUIT_RARCH, 0);
|
||||
}
|
||||
|
||||
|
@ -1103,10 +1103,9 @@ bool config_save_file(const char *path)
|
||||
config_set_int(conf, cfg, g_settings.input.libretro_device[i]);
|
||||
}
|
||||
|
||||
config_file_write(conf, path);
|
||||
bool ret = config_file_write(conf, path);
|
||||
config_file_free(conf);
|
||||
|
||||
return true;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool config_save_keybinds(const char *path)
|
||||
|
Loading…
x
Reference in New Issue
Block a user