diff options
author | sr55 <[email protected]> | 2014-03-23 12:50:33 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2014-03-23 12:50:33 +0000 |
commit | 844c185f87eae47a25ce86e2977d60bc9c57476d (patch) | |
tree | 6950e538c9339f971b4b5649ccaedb042c7ae227 /win | |
parent | 39c74335105caafaaf7468958303671d623495e0 (diff) |
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
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrakeWPF/HandBrakeWPF.csproj | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/FileHelper.cs | 56 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.Designer.cs | 9 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/Resources.resx | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs | 5 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs | 40 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/MainView.xaml | 6 |
7 files changed, 110 insertions, 10 deletions
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 @@ <Compile Include="Converters\Audio\AudioBehaviourConverter.cs" />
<Compile Include="Converters\Subtitles\SubtitleBehaviourConverter.cs" />
<Compile Include="Converters\Video\ScalingConverter.cs" />
+ <Compile Include="Helpers\FileHelper.cs" />
<Compile Include="Model\ScanMode.cs" />
<Compile Include="Factories\HBConfigurationFactory.cs" />
<Compile Include="Services\Interfaces\IUserSettingService.cs" />
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 @@ +// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="FileHelper.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// Helper methods for dealing with files.
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Helpers
+{
+ using System;
+ using System.IO;
+
+ /// <summary>
+ /// Helper methods for dealing with files.
+ /// </summary>
+ public class FileHelper
+ {
+ /// <summary>
+ /// The file path has invalid chars.
+ /// </summary>
+ /// <param name="path">
+ /// The path.
+ /// </param>
+ /// <returns>
+ /// The <see cref="bool"/>.
+ /// </returns>
+ 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 @@ -410,6 +410,15 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to The entered destination contained illegal characters. You must fix the path and filename before continuing..
+ /// </summary>
+ public static string Main_InvalidDestination {
+ get {
+ return ResourceManager.GetString("Main_InvalidDestination", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to , Pending Jobs {5}.
/// </summary>
public static string Main_JobsPending_addon {
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?</value> <data name="Main_SetDestination" xml:space="preserve">
<value>You must first set the destination path for the output file before adding to the queue.</value>
</data>
+ <data name="Main_InvalidDestination" xml:space="preserve">
+ <value>The entered destination contained illegal characters. You must fix the path and filename before continuing.</value>
+ </data>
</root>
\ 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 /// <summary>
/// Add the current task to the queue.
/// </summary>
- void AddToQueue();
+ /// <returns>
+ /// True if added, false if error
+ /// </returns>
+ bool AddToQueue();
/// <summary>
/// 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 /// <summary>
/// Add the current task to the queue.
/// </summary>
- public void AddToQueue()
+ /// <returns>
+ /// True if added, false if error.
+ /// </returns>
+ 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;
}
/// <summary>
@@ -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<bool>(UserSettingConstants.ClearCompletedFromQueue));
- this.IsEncoding = true;
+ if (this.AddToQueue())
+ {
+ this.queueProcessor.Start(UserSettingService.GetUserSetting<bool>(UserSettingConstants.ClearCompletedFromQueue));
+ this.IsEncoding = true;
+ }
}
/// <summary>
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 @@ </i:Interaction.Triggers>
<UserControl.Resources>
+ <Converters:BooleanConverter x:Key="booleanConverter" />
+
<Style TargetType="Button">
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="Padding" Value="5,1" />
@@ -174,6 +176,7 @@ SnapsToDevicePixels="False"
ToolBar.OverflowMode="Never"
ToolBarTray.IsLocked="True"
+ KeyboardNavigation.TabNavigation="Continue"
>
<Button Name="SelectSource"
@@ -333,7 +336,7 @@ </StackPanel>
<!-- Main Body -->
- <Grid Grid.Row="1">
+ <Grid Grid.Row="1" IsEnabled="{Binding ShowSourceSelection, Converter={StaticResource booleanConverter}, ConverterParameter=true}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="700"/>
<ColumnDefinition Width="Auto" />
@@ -561,6 +564,7 @@ ToolBar.OverflowMode="Never"
ToolBarTray.IsLocked="True"
Loaded="ToolBarLoaded"
+ KeyboardNavigation.TabNavigation="Continue"
>
<Button Micro:Message.Attach="[Event Click] = [Action PresetAdd]" >
<Button.Content>
|