Add saved file name to autoconfig profile save message (#16267)

Autoconfig profile may be useful for e.g. submitting to autoconfig
repo. Construction of the filename is moved to a separate function
and reused for message.
This commit is contained in:
zoltanvb 2024-02-20 22:47:35 +01:00 committed by GitHub
parent 3cb79e38f0
commit 900c82bfe6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 84 additions and 25 deletions

View File

@ -4929,14 +4929,9 @@ static void input_config_save_keybinds_user_override(config_file_t *conf,
}
}
/**
* config_save_autoconf_profile:
* @device_name : Input device name
* @user : Controller number to save
* Writes a controller autoconf file to disk.
**/
bool config_save_autoconf_profile(const
char *device_name, unsigned user)
void config_get_autoconf_profile_filename(
const char *device_name, unsigned user,
char *buf, size_t len_buf)
{
static const char* invalid_filename_chars[] = {
/* https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names--fo */
@ -4945,12 +4940,7 @@ bool config_save_autoconf_profile(const
};
size_t len;
unsigned i;
char buf[PATH_MAX_LENGTH];
char autoconf_file[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
int32_t pid_user = 0;
int32_t vid_user = 0;
bool ret = false;
settings_t *settings = config_st;
const char *autoconf_dir = settings->paths.directory_autoconfig;
const char *joypad_driver_fallback = settings->arrays.input_joypad_driver;
@ -4993,15 +4983,66 @@ bool config_save_autoconf_profile(const
}
/* Generate autoconfig file path */
fill_pathname_join_special(buf, autoconf_dir, joypad_driver, sizeof(buf));
fill_pathname_join_special(buf, autoconf_dir, joypad_driver, len_buf);
if (path_is_directory(buf))
len = fill_pathname_join_special(autoconf_file, buf,
sanitised_name, sizeof(autoconf_file));
/* Driver specific autoconf dir may not exist, if autoconfs are not downloaded. */
if (!path_is_directory(buf))
{
len = strlcpy(buf, sanitised_name, len_buf);
}
else
len = fill_pathname_join_special(autoconf_file, autoconf_dir,
sanitised_name, sizeof(autoconf_file));
strlcpy(autoconf_file + len, ".cfg", sizeof(autoconf_file) - len);
{
len = fill_pathname_join_special(buf, joypad_driver, sanitised_name, len_buf);
}
strlcpy(buf + len, ".cfg", len_buf - len);
end:
if (sanitised_name)
free(sanitised_name);
}
/**
* config_save_autoconf_profile:
* @device_name : Input device name
* @user : Controller number to save
* Writes a controller autoconf file to disk.
**/
bool config_save_autoconf_profile(const
char *device_name, unsigned user)
{
size_t len;
unsigned i;
char buf[PATH_MAX_LENGTH];
char autoconf_file[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
int32_t pid_user = 0;
int32_t vid_user = 0;
bool ret = false;
settings_t *settings = config_st;
const char *autoconf_dir = settings->paths.directory_autoconfig;
const char *joypad_driver_fallback = settings->arrays.input_joypad_driver;
const char *joypad_driver = NULL;
if (string_is_empty(device_name))
goto end;
/* Get currently set joypad driver */
joypad_driver = input_config_get_device_joypad_driver(user);
if (string_is_empty(joypad_driver))
{
/* This cannot happen, but if we reach this
* point without a driver being set for the
* current input device then use the value
* from the settings struct as a fallback */
joypad_driver = joypad_driver_fallback;
if (string_is_empty(joypad_driver))
goto end;
}
/* Generate autoconfig file path */
config_get_autoconf_profile_filename(device_name, user, buf, sizeof(buf));
fill_pathname_join_special(autoconf_file, autoconf_dir, buf, sizeof(autoconf_file));
/* Open config file */
if ( !(conf = config_file_new_from_path_to_string(autoconf_file))
@ -5043,9 +5084,6 @@ bool config_save_autoconf_profile(const
ret = config_file_write(conf, autoconf_file, false);
end:
if (sanitised_name)
free(sanitised_name);
if (conf)
config_file_free(conf);

View File

@ -1209,6 +1209,16 @@ bool config_unload_override(void);
bool config_load_remap(const char *directory_input_remapping,
void *data);
/**
* config_get_autoconf_profile_filename:
* @device_name : Input device name
* @user : Controller number to save
* Fills buf with the autoconf profile file name (including driver dir if needed).
**/
void config_get_autoconf_profile_filename(
const char *device_name, unsigned user,
char *buf, size_t len_buf);
/**
* config_save_autoconf_profile:
* @device_name : Input device name

View File

@ -14001,6 +14001,10 @@ MSG_HASH(
MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY,
"Controller profile saved successfully."
)
MSG_HASH(
MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY_NAMED,
"Controller profile saved in Controller Profiles directory as\n\"%s\""
)
MSG_HASH(
MSG_AUTOSAVE_FAILED,
"Could not initialize autosave."

View File

@ -2528,9 +2528,15 @@ static int setting_action_ok_bind_all_save_autoconfig(
if (!string_is_empty(name) &&
config_save_autoconf_profile(name, index_offset))
{
char buf[PATH_MAX_LENGTH];
char msg[PATH_MAX_LENGTH];
config_get_autoconf_profile_filename(name, index_offset, buf, sizeof(buf));
snprintf(msg, sizeof(msg),msg_hash_to_str(MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY_NAMED),buf);
runloop_msg_queue_push(
msg_hash_to_str(MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY), 1, 100, true,
msg, 1, 180, true,
NULL, MESSAGE_QUEUE_ICON_DEFAULT, MESSAGE_QUEUE_CATEGORY_INFO);
}
else
runloop_msg_queue_push(
msg_hash_to_str(MSG_AUTOCONFIG_FILE_ERROR_SAVING), 1, 100, true,

View File

@ -350,6 +350,7 @@ enum msg_hash_enums
MSG_OVERRIDES_ERROR_SAVING,
MSG_OVERRIDES_ERROR_REMOVING,
MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY,
MSG_AUTOCONFIG_FILE_SAVED_SUCCESSFULLY_NAMED,
MSG_AUTOCONFIG_FILE_ERROR_SAVING,
MSG_FILE_ALREADY_EXISTS_SAVING_TO_BACKUP_BUFFER,
MSG_AUTOLOADING_SAVESTATE_FROM,