From bedc107bb1dc68b4aa9ef6e1265fc6a0cd20ec65 Mon Sep 17 00:00:00 2001 From: Tiberiu Chibici Date: Sat, 16 Aug 2014 14:02:18 +0300 Subject: [PATCH] Fixed validation of inputs in create project dialog --- RainmeterStudio.Core/Utils/PathHelper.cs | 18 ++++++++++++++++++ .../UI/Dialogs/CreateProjectDialog.xaml.cs | 8 ++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/RainmeterStudio.Core/Utils/PathHelper.cs b/RainmeterStudio.Core/Utils/PathHelper.cs index 0323365a..0322815a 100644 --- a/RainmeterStudio.Core/Utils/PathHelper.cs +++ b/RainmeterStudio.Core/Utils/PathHelper.cs @@ -21,5 +21,23 @@ namespace RainmeterStudio.Core.Utils return true; } + + /// + /// Validates a file name + /// + /// Name of file + /// + public static bool IsFileNameValid(string name) + { + // No name is not a valid name + if (String.IsNullOrEmpty(name)) + return false; + + // Check for invalid characters + if (Path.GetInvalidFileNameChars().Intersect(name).Any()) + return false; + + return true; + } } } diff --git a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs index edde29b8..b2d50d9f 100644 --- a/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs +++ b/RainmeterStudio/UI/Dialogs/CreateProjectDialog.xaml.cs @@ -113,9 +113,7 @@ namespace RainmeterStudio.UI.Dialogs // Populate controls listTemplates.ItemsSource = projectController.ProjectTemplates.OrderBy(x => x.DisplayText); - textLocation.ItemsSource = GetRecentLocations().OrderBy(x => x); - textLocation.Text = GetLocation(); Validate(); @@ -145,8 +143,10 @@ namespace RainmeterStudio.UI.Dialogs private void Validate() { bool res = true; - res &= (listTemplates.SelectedItem != null); - + res &= (listTemplates.SelectedItem != null); + res &= PathHelper.IsFileNameValid(textName.Text); + res &= PathHelper.IsPathValid(textLocation.Text); + buttonCreate.IsEnabled = res; }