From: sr55 Date: Sat, 14 Jan 2017 21:52:18 +0000 (+0000) Subject: WinGui: Fix erroneous path and filename handling. #515 X-Git-Tag: 1.0.2~14 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eea54192e0e14c1c11d2e3eaac3f8691a432d262;p=handbrake WinGui: Fix erroneous path and filename handling. #515 --- diff --git a/win/CS/HandBrakeWPF/Helpers/FileHelper.cs b/win/CS/HandBrakeWPF/Helpers/FileHelper.cs index e9017f8b5..f9d98e0a5 100644 --- a/win/CS/HandBrakeWPF/Helpers/FileHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/FileHelper.cs @@ -36,9 +36,17 @@ namespace HandBrakeWPF.Helpers string file = Path.GetFileNameWithoutExtension(path); string directory = Path.GetDirectoryName(path); - // TODO this may not be necessary. - if ((!string.IsNullOrEmpty(directory) && directory.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidPathChars()) != -1) || - file.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidFileNameChars()) != -1) + if (path.Split(':').Length - 1 > 1) + { + return true; + } + + if (!string.IsNullOrEmpty(file) && file.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidPathChars()) != -1) + { + return true; + } + + if (!string.IsNullOrEmpty(directory) && directory.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidPathChars()) != -1) { return true; } diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 4dab47e0d..3454a5cbb 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -709,14 +709,16 @@ namespace HandBrakeWPF.ViewModels try { ext = Path.GetExtension(value); + if (FileHelper.FilePathHasInvalidChars(value) || string.IsNullOrEmpty(ext)) + { + this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); + return; + } } catch (ArgumentException) { - this.errorService.ShowMessageBox( - Resources.Main_InvalidDestination, - Resources.Error, - MessageBoxButton.OK, - MessageBoxImage.Error); + this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); + return; } this.CurrentTask.Destination = value;