internal void SaveNewCustomControl() { bool isValid = true; string title = ResourceHelper.Get(StringKey.SaveControlConfiguration); string prompt = ResourceHelper.Get(StringKey.SaveControlsPreset); string controlName; string pathToFile; do { isValid = true; InputTextWindow inputBox = new InputTextWindow(title, prompt); inputBox.ViewModel.MaxCharLength = 24; bool?dialogResult = inputBox.ShowDialog(); if (!dialogResult.GetValueOrDefault(false)) { return; } controlName = inputBox.ViewModel.TextInput; if (string.IsNullOrEmpty(controlName)) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ControlNameIsEmpty), ResourceHelper.Get(StringKey.SaveError), MessageBoxButton.OK, MessageBoxImage.Error); continue; } if (Path.GetInvalidFileNameChars().Any(c => controlName.Contains(c))) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ControlNameContainsInvalidChars), ResourceHelper.Get(StringKey.SaveError), MessageBoxButton.OK, MessageBoxImage.Error); continue; } // construct path and check if already exists if name is valid if (isValid) { if (controlName.EndsWith(".cfg")) { controlName = controlName.Substring(0, controlName.Length - 4); } pathToFile = Path.Combine(Sys.PathToControlsFolder, $"{controlName}.cfg"); if (File.Exists(pathToFile)) { isValid = false; MessageDialogWindow.Show(ResourceHelper.Get(StringKey.ControlsWithThatNameAlreadyExist), ResourceHelper.Get(StringKey.SaveError), MessageBoxButton.OK, MessageBoxImage.Error); } } } while (!isValid); try { string pathToDefaultFile = Path.Combine(Sys.PathToControlsFolder, InGameConfigurationMap[_defaultControlNames[0]]); ControlMapper.CopyConfigurationFileAndSaveAsNew(pathToDefaultFile, $"{controlName}.cfg", LoadedConfiguration); InitInGameConfigOptions(); SelectedGameConfigOption = controlName; //StatusMessage = ResourceHelper.Get(StringKey.SuccessfullyCreatedCustomControls); } catch (Exception e) { Logger.Error(e); //StatusMessage = $"{ResourceHelper.Get(StringKey.FailedToCreateCustomControls)}: {e.Message}"; } }