]> granicus.if.org Git - handbrake/commitdiff
WinGui: Restore rolled back tabbing fix + added a check for illegal characters to...
authorsr55 <sr55.hb@outlook.com>
Sun, 23 Mar 2014 12:50:33 +0000 (12:50 +0000)
committersr55 <sr55.hb@outlook.com>
Sun, 23 Mar 2014 12:50:33 +0000 (12:50 +0000)
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@6129 b64f7644-9d1e-0410-96f1-a4d463321fa5

win/CS/HandBrakeWPF/HandBrakeWPF.csproj
win/CS/HandBrakeWPF/Helpers/FileHelper.cs [new file with mode: 0644]
win/CS/HandBrakeWPF/Properties/Resources.Designer.cs
win/CS/HandBrakeWPF/Properties/Resources.resx
win/CS/HandBrakeWPF/ViewModels/Interfaces/IMainViewModel.cs
win/CS/HandBrakeWPF/ViewModels/MainViewModel.cs
win/CS/HandBrakeWPF/Views/MainView.xaml

index 865b754621bcafc664efc14f96ecf1d1150f462b..adad1827a2bb0229a32ab57a2d4dcbc719a5abf9 100644 (file)
     <Compile Include="Converters\Audio\AudioBehaviourConverter.cs" />\r
     <Compile Include="Converters\Subtitles\SubtitleBehaviourConverter.cs" />\r
     <Compile Include="Converters\Video\ScalingConverter.cs" />\r
+    <Compile Include="Helpers\FileHelper.cs" />\r
     <Compile Include="Model\ScanMode.cs" />\r
     <Compile Include="Factories\HBConfigurationFactory.cs" />\r
     <Compile Include="Services\Interfaces\IUserSettingService.cs" />\r
diff --git a/win/CS/HandBrakeWPF/Helpers/FileHelper.cs b/win/CS/HandBrakeWPF/Helpers/FileHelper.cs
new file mode 100644 (file)
index 0000000..7a882de
--- /dev/null
@@ -0,0 +1,56 @@
+// --------------------------------------------------------------------------------------------------------------------\r
+// <copyright file="FileHelper.cs" company="HandBrake Project (http://handbrake.fr)">\r
+//   This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.\r
+// </copyright>\r
+// <summary>\r
+//   Helper methods for dealing with files.\r
+// </summary>\r
+// --------------------------------------------------------------------------------------------------------------------\r
+\r
+namespace HandBrakeWPF.Helpers\r
+{\r
+    using System;\r
+    using System.IO;\r
+\r
+    /// <summary>\r
+    /// Helper methods for dealing with files.\r
+    /// </summary>\r
+    public class FileHelper\r
+    {\r
+        /// <summary>\r
+        /// The file path has invalid chars.\r
+        /// </summary>\r
+        /// <param name="path">\r
+        /// The path.\r
+        /// </param>\r
+        /// <returns>\r
+        /// The <see cref="bool"/>.\r
+        /// </returns>\r
+        public static bool FilePathHasInvalidChars(string path)\r
+        {\r
+            bool result = false;\r
+            if (!string.IsNullOrEmpty(path))\r
+            {\r
+                try\r
+                {\r
+                    string file = Path.GetFileNameWithoutExtension(path);\r
+                    string directory = Path.GetDirectoryName(path);\r
+\r
+                    // TODO this may not be necessary.\r
+                    if ((!string.IsNullOrEmpty(directory) && directory.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidPathChars()) != -1) ||\r
+                        file.Replace("\"", string.Empty).IndexOfAny(Path.GetInvalidFileNameChars()) != -1)\r
+                    {\r
+                        return true;\r
+                    }\r
+\r
+                }\r
+                catch (ArgumentException)\r
+                {\r
+                    result = true;\r
+                }\r
+            }\r
+\r
+            return result;\r
+        }\r
+    }\r
+}\r
index 41358be1cffa6cf5303902c0e5c4ce866509c10e..384cfbc014672e6f788fa0d5216b0845a0a72293 100644 (file)
@@ -409,6 +409,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to The entered destination contained illegal characters. You must fix the path and filename before continuing..\r
+        /// </summary>\r
+        public static string Main_InvalidDestination {\r
+            get {\r
+                return ResourceManager.GetString("Main_InvalidDestination", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to ,  Pending Jobs {5}.\r
         /// </summary>\r
index 2491360d335010ca1002d06e758380bf3cda819b..ec7809d9e97348b77146922b02b8b4bb74e46c9d 100644 (file)
@@ -504,4 +504,7 @@ Do you wish to proceed?</value>
   <data name="Main_SetDestination" xml:space="preserve">\r
     <value>You must first set the destination path for the output file before adding to the queue.</value>\r
   </data>\r
+  <data name="Main_InvalidDestination" xml:space="preserve">\r
+    <value>The entered destination contained illegal characters. You must fix the path and filename before continuing.</value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 0d176b7b7b33ec8dbd0f069cf09b6ca94185d21e..e08d2d9ffadf69eb0402b283d60919d2a2c615da 100644 (file)
@@ -39,7 +39,10 @@ namespace HandBrakeWPF.ViewModels.Interfaces
         /// <summary>\r
         /// Add the current task to the queue.\r
         /// </summary>\r
-        void AddToQueue();\r
+        /// <returns>\r
+        /// True if added, false if error\r
+        /// </returns>\r
+        bool AddToQueue();\r
 \r
         /// <summary>\r
         /// File Scan\r
index 08f009bd4896100a3fee73278c1627ee4eee7045..3a3efc97229e487e5432f8b31ed9d399349c9505 100644 (file)
@@ -643,7 +643,17 @@ namespace HandBrakeWPF.ViewModels
 \r
                     if (!string.IsNullOrEmpty(this.CurrentTask.Destination))\r
                     {\r
-                        switch (Path.GetExtension(this.CurrentTask.Destination))\r
+                        string ext = string.Empty;\r
+                        try\r
+                        {\r
+                            ext = Path.GetExtension(this.CurrentTask.Destination);\r
+                        }\r
+                        catch (ArgumentException)\r
+                        {\r
+                            this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+                        }\r
+\r
+                        switch (ext)\r
                         {\r
                             case ".mkv":\r
                                 this.SelectedOutputFormat = OutputFormat.Mkv;\r
@@ -1151,18 +1161,29 @@ namespace HandBrakeWPF.ViewModels
         /// <summary>\r
         /// Add the current task to the queue.\r
         /// </summary>\r
-        public void AddToQueue()\r
+        /// <returns>\r
+        /// True if added, false if error.\r
+        /// </returns>\r
+        public bool AddToQueue()\r
         {\r
             if (this.ScannedSource == null || string.IsNullOrEmpty(this.ScannedSource.ScanPath) || this.ScannedSource.Titles.Count == 0)\r
             {\r
                 this.errorService.ShowMessageBox(Resources.Main_ScanSourceFirst, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
-                return;\r
+                return false;\r
             }\r
 \r
             if (string.IsNullOrEmpty(this.CurrentTask.Destination))\r
             {\r
                 this.errorService.ShowMessageBox(Resources.Main_SetDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
-                return;\r
+                return false;\r
+            }\r
+\r
+            // Sanity check the filename\r
+            if (!string.IsNullOrEmpty(this.Destination) && FileHelper.FilePathHasInvalidChars(this.Destination))\r
+            {\r
+                this.errorService.ShowMessageBox(Resources.Main_InvalidDestination, Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);\r
+                this.NotifyOfPropertyChange(() => this.Destination);\r
+                return false;\r
             }\r
 \r
             QueueTask task = new QueueTask(new EncodeTask(this.CurrentTask), HBConfigurationFactory.Create());\r
@@ -1180,6 +1201,8 @@ namespace HandBrakeWPF.ViewModels
             {\r
                 this.ProgramStatusLabel = string.Format(Resources.Main_XEncodesPending, this.queueProcessor.Count);\r
             }\r
+\r
+            return true;\r
         }\r
 \r
         /// <summary>\r
@@ -1325,10 +1348,11 @@ namespace HandBrakeWPF.ViewModels
             }\r
 \r
             // Create the Queue Task and Start Processing\r
-            QueueTask task = new QueueTask(new EncodeTask(this.CurrentTask), HBConfigurationFactory.Create());\r
-            this.queueProcessor.Add(task);\r
-            this.queueProcessor.Start(UserSettingService.GetUserSetting<bool>(UserSettingConstants.ClearCompletedFromQueue));\r
-            this.IsEncoding = true;\r
+            if (this.AddToQueue())\r
+            {\r
+                this.queueProcessor.Start(UserSettingService.GetUserSetting<bool>(UserSettingConstants.ClearCompletedFromQueue));\r
+                this.IsEncoding = true;\r
+            }\r
         }\r
 \r
         /// <summary>\r
index 2d8f613d9534e6dc3d6df59d8de1043ffb4809b4..727a3b36f94188f842c4e99b15f551e72f8f39a0 100644 (file)
@@ -22,6 +22,8 @@
     </i:Interaction.Triggers>\r
 \r
     <UserControl.Resources>\r
+        <Converters:BooleanConverter x:Key="booleanConverter" />\r
+        \r
         <Style TargetType="Button">\r
             <Setter Property="FontWeight" Value="Bold" />\r
             <Setter Property="Padding" Value="5,1" />\r
                      SnapsToDevicePixels="False"\r
                      ToolBar.OverflowMode="Never"\r
                      ToolBarTray.IsLocked="True"\r
+                     KeyboardNavigation.TabNavigation="Continue"\r
                      >\r
 \r
                 <Button Name="SelectSource"\r
         </StackPanel>\r
 \r
         <!--  Main Body  -->\r
-        <Grid Grid.Row="1">\r
+        <Grid Grid.Row="1"  IsEnabled="{Binding ShowSourceSelection, Converter={StaticResource booleanConverter}, ConverterParameter=true}">\r
             <Grid.ColumnDefinitions>\r
                 <ColumnDefinition Width="*" MinWidth="700"/>\r
                 <ColumnDefinition Width="Auto" />\r
                              ToolBar.OverflowMode="Never" \r
                              ToolBarTray.IsLocked="True"\r
                              Loaded="ToolBarLoaded"\r
+                             KeyboardNavigation.TabNavigation="Continue"\r
                              >\r
                         <Button Micro:Message.Attach="[Event Click] = [Action PresetAdd]" >\r
                             <Button.Content>\r