From 844c185f87eae47a25ce86e2977d60bc9c57476d Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 23 Mar 2014 12:50:33 +0000 Subject: WinGui: Restore rolled back tabbing fix + added a check for illegal characters to the destination text box. Add to Queue will now prevent items from begin added with illegal characters also. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6129 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 + win/CS/HandBrakeWPF/Helpers/FileHelper.cs | 56 ++++++++++++++++++++++ .../HandBrakeWPF/Properties/Resources.Designer.cs | 9 ++++ win/CS/HandBrakeWPF/Properties/Resources.resx | 3 ++ .../ViewModels/Interfaces/IMainViewModel.cs | 5 +- win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 40 ++++++++++++---- win/CS/HandBrakeWPF/Views/MainView.xaml | 6 ++- 7 files changed, 110 insertions(+), 10 deletions(-) create mode 100644 win/CS/HandBrakeWPF/Helpers/FileHelper.cs (limited to 'win/CS') diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 865b75462..adad1827a 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -133,6 +133,7 @@ + diff --git a/win/CS/HandBrakeWPF/Helpers/FileHelper.cs b/win/CS/HandBrakeWPF/Helpers/FileHelper.cs new file mode 100644 index 000000000..7a882de0b --- /dev/null +++ b/win/CS/HandBrakeWPF/Helpers/FileHelper.cs @@ -0,0 +1,56 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Helper methods for dealing with files. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Helpers +{ + using System; + using System.IO; + + /// + /// Helper methods for dealing with files. + /// + public class FileHelper + { + /// + /// The file path has invalid chars. + /// + /// + /// The path. + /// + /// + /// The . + /// + public static bool FilePathHasInvalidChars(string path) + { + bool result = false; + if (!string.IsNullOrEmpty(path)) + { + try + { + 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) + { + return true; + } + + } + catch (ArgumentException) + { + result = true; + } + } + + return result; + } + } +} diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index 41358be1c..384cfbc01 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -409,6 +409,15 @@ namespace HandBrakeWPF.Properties { } } + /// + /// Looks up a localized string similar to The entered destination contained illegal characters. You must fix the path and filename before continuing.. + /// + public static string Main_InvalidDestination { + get { + return ResourceManager.GetString("Main_InvalidDestination", resourceCulture); + } + } + /// /// Looks up a localized string similar to , Pending Jobs {5}. /// diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index 2491360d3..ec7809d9e 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -504,4 +504,7 @@ Do you wish to proceed? You must first set the destination path for the output file before adding to the queue. + + The entered destination contained illegal characters. You must fix the path and filename before continuing. + \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs index 0d176b7b7..e08d2d9ff 100644 --- a/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs @@ -39,7 +39,10 @@ namespace HandBrakeWPF.ViewModels.Interfaces /// /// Add the current task to the queue. /// - void AddToQueue(); + /// + /// True if added, false if error + /// + bool AddToQueue(); /// /// File Scan diff --git a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs index 08f009bd4..3a3efc972 100644 --- a/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs @@ -643,7 +643,17 @@ namespace HandBrakeWPF.ViewModels if (!string.IsNullOrEmpty(this.CurrentTask.Destination)) { - switch (Path.GetExtension(this.CurrentTask.Destination)) + string ext = string.Empty; + try + { + ext = Path.GetExtension(this.CurrentTask.Destination); + } + catch (ArgumentException) + { + this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); + } + + switch (ext) { case ".mkv": this.SelectedOutputFormat = OutputFormat.Mkv; @@ -1151,18 +1161,29 @@ namespace HandBrakeWPF.ViewModels /// /// Add the current task to the queue. /// - public void AddToQueue() + /// + /// True if added, false if error. + /// + public bool AddToQueue() { if (this.ScannedSource == null || string.IsNullOrEmpty(this.ScannedSource.ScanPath) || this.ScannedSource.Titles.Count == 0) { this.errorService.ShowMessageBox(Resources.Main_ScanSourceFirst, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); - return; + return false; } if (string.IsNullOrEmpty(this.CurrentTask.Destination)) { this.errorService.ShowMessageBox(Resources.Main_SetDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); - return; + return false; + } + + // Sanity check the filename + if (!string.IsNullOrEmpty(this.Destination) && FileHelper.FilePathHasInvalidChars(this.Destination)) + { + this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error); + this.NotifyOfPropertyChange(() => this.Destination); + return false; } QueueTask task = new QueueTask(new EncodeTask(this.CurrentTask), HBConfigurationFactory.Create()); @@ -1180,6 +1201,8 @@ namespace HandBrakeWPF.ViewModels { this.ProgramStatusLabel = string.Format(Resources.Main_XEncodesPending, this.queueProcessor.Count); } + + return true; } /// @@ -1325,10 +1348,11 @@ namespace HandBrakeWPF.ViewModels } // Create the Queue Task and Start Processing - QueueTask task = new QueueTask(new EncodeTask(this.CurrentTask), HBConfigurationFactory.Create()); - this.queueProcessor.Add(task); - this.queueProcessor.Start(UserSettingService.GetUserSetting(UserSettingConstants.ClearCompletedFromQueue)); - this.IsEncoding = true; + if (this.AddToQueue()) + { + this.queueProcessor.Start(UserSettingService.GetUserSetting(UserSettingConstants.ClearCompletedFromQueue)); + this.IsEncoding = true; + } } /// diff --git a/win/CS/HandBrakeWPF/Views/MainView.xaml b/win/CS/HandBrakeWPF/Views/MainView.xaml index 2d8f613d9..727a3b36f 100644 --- a/win/CS/HandBrakeWPF/Views/MainView.xaml +++ b/win/CS/HandBrakeWPF/Views/MainView.xaml @@ -22,6 +22,8 @@ + +