diff --git a/configuration.c b/configuration.c index 79f490bfafd..bcbb4ded047 100644 --- a/configuration.c +++ b/configuration.c @@ -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); diff --git a/configuration.h b/configuration.h index 7e491941b87..2ec8fd8e433 100644 --- a/configuration.h +++ b/configuration.h @@ -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 diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index a4d340a8777..2a936e87f5a 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -13997,6 +13997,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." diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 1a61a1da629..4eadc1dfed5 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -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, diff --git a/msg_hash.h b/msg_hash.h index e9127065e3e..7382c8a2c46 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -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,