]> granicus.if.org Git - handbrake/commitdiff
WinGui: Don't allow the user to enter invalid filename characters in the "File Format...
authorsr55 <sr55.hb@outlook.com>
Fri, 13 May 2016 18:11:16 +0000 (19:11 +0100)
committersr55 <sr55.hb@outlook.com>
Fri, 13 May 2016 18:11:16 +0000 (19:11 +0100)
win/CS/HandBrakeWPF/Properties/ResourcesUI.Designer.cs
win/CS/HandBrakeWPF/Properties/ResourcesUI.resx
win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs
win/CS/HandBrakeWPF/Views/OptionsView.xaml

index c67fddf27456f7814f5c55037e115c09d17cd08b..f39eed8f821b0989619f3895eeb51090965e3fdb 100644 (file)
@@ -1105,7 +1105,7 @@ namespace HandBrakeWPF.Properties {
         }\r
         \r
         /// <summary>\r
-        ///   Looks up a localized string similar to Format:.\r
+        ///   Looks up a localized string similar to File Format:.\r
         /// </summary>\r
         public static string Options_Format {\r
             get {\r
@@ -1410,6 +1410,15 @@ namespace HandBrakeWPF.Properties {
             }\r
         }\r
         \r
+        /// <summary>\r
+        ///   Looks up a localized string similar to The file format entered contained invalid characters. These have been removed. .\r
+        /// </summary>\r
+        public static string OptionsView_InvalidFileFormatChars {\r
+            get {\r
+                return ResourceManager.GetString("OptionsView_InvalidFileFormatChars", resourceCulture);\r
+            }\r
+        }\r
+        \r
         /// <summary>\r
         ///   Looks up a localized string similar to Anamorphic:.\r
         /// </summary>\r
index ef6cd111fd0b4b73b001821cfa601560c860e3da..5b6a8bad087ef69abc881dec00cf369656fe3130 100644 (file)
     <value>Disable LibDVDNav. (libdvdread will be used instead)</value>\r
   </data>\r
   <data name="Options_Format" xml:space="preserve">\r
-    <value>Format:</value>\r
+    <value>File Format:</value>\r
   </data>\r
   <data name="Options_General" xml:space="preserve">\r
     <value>General</value>\r
@@ -872,4 +872,7 @@ This will not affect your current settings in the Subtitle tab.</value>
   <data name="SubtitleView_SubtitleDefaultsDescription" xml:space="preserve">\r
     <value>Configure how the Subtitle Tracks are automatically selected and configured when you select a new title or source video.</value>\r
   </data>\r
+  <data name="OptionsView_InvalidFileFormatChars" xml:space="preserve">\r
+    <value>The file format entered contained invalid characters. These have been removed. </value>\r
+  </data>\r
 </root>
\ No newline at end of file
index 0b1b16df39e6d5f7bb346b70a29db01b6e9bc91b..b1962e48b7c0e68e1ad2c870f15b7c0dcbad927b 100644 (file)
@@ -15,6 +15,7 @@ namespace HandBrakeWPF.ViewModels
     using System.Globalization;\r
     using System.IO;\r
     using System.Linq;\r
+    using System.Text;\r
     using System.Windows;\r
 \r
     using Caliburn.Micro;\r
@@ -42,6 +43,8 @@ namespace HandBrakeWPF.ViewModels
 \r
         private readonly IUserSettingService userSettingService;\r
         private readonly IUpdateService updateService;\r
+        private readonly IErrorService errorService;\r
+\r
         private string arguments;\r
         private string autoNameDefaultPath;\r
         private bool automaticallyNameFiles;\r
@@ -106,11 +109,12 @@ namespace HandBrakeWPF.ViewModels
         /// <param name="aboutViewModel">\r
         /// The about View Model.\r
         /// </param>\r
-        public OptionsViewModel(IUserSettingService userSettingService, IUpdateService updateService, IAboutViewModel aboutViewModel)\r
+        public OptionsViewModel(IUserSettingService userSettingService, IUpdateService updateService, IAboutViewModel aboutViewModel, IErrorService errorService)\r
         {\r
             this.Title = "Options";\r
             this.userSettingService = userSettingService;\r
             this.updateService = updateService;\r
+            this.errorService = errorService;\r
             this.AboutViewModel = aboutViewModel;\r
             this.OnLoad();\r
 \r
@@ -390,7 +394,11 @@ namespace HandBrakeWPF.ViewModels
 \r
             set\r
             {\r
-                this.autonameFormat = value;\r
+                if (this.IsValidAutonameFormat(value, false))\r
+                {\r
+                    this.autonameFormat = value;   \r
+                } \r
+\r
                 this.NotifyOfPropertyChange("AutonameFormat");\r
             }\r
         }\r
@@ -1176,7 +1184,8 @@ namespace HandBrakeWPF.ViewModels
                 this.AutoNameDefaultPath = "Click 'Browse' to set the default location";\r
 \r
             // Store auto name format\r
-            this.AutonameFormat = this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) ?? string.Empty;\r
+            string anf = this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNameFormat) ?? string.Empty;\r
+            this.AutonameFormat = this.IsValidAutonameFormat(anf, true) ? anf : "{source}-{title}";\r
 \r
             // Use iPod/iTunes friendly .m4v extension for MP4 files.\r
             this.mp4ExtensionOptions.Clear();\r
@@ -1409,5 +1418,33 @@ namespace HandBrakeWPF.ViewModels
         {\r
             this.SelectedTab = tab;\r
         }\r
+\r
+        /// <summary>\r
+        /// Validate the Autoname Fileformat string\r
+        /// </summary>\r
+        /// <param name="input">The format string</param>\r
+        /// <param name="isSilent">Don't show an error dialog if true.</param>\r
+        /// <returns>True if valid</returns>\r
+        private bool IsValidAutonameFormat(string input, bool isSilent)\r
+        {\r
+            foreach (var characterToTest in input)\r
+            {\r
+                // we binary search for the character in the invalid set. This should be lightning fast.\r
+                if (Array.BinarySearch(Path.GetInvalidFileNameChars(), characterToTest) >= 0)\r
+                {\r
+                    if (!isSilent)\r
+                    {\r
+                        this.errorService.ShowMessageBox(\r
+                            ResourcesUI.OptionsView_InvalidFileFormatChars,\r
+                            Resources.Error,\r
+                            MessageBoxButton.OK,\r
+                            MessageBoxImage.Error);\r
+                    }\r
+                    return false;\r
+                }\r
+            }\r
+\r
+            return true;\r
+        }\r
     }\r
 }
\ No newline at end of file
index 4442b9c953bd1f55cfa762b777a9832c3489e5e0..0b966ba848a6b018507740bedded7f08c973c2be 100644 (file)
                                         cal:Message.Attach="[Event Click] = [Action BrowseAutoNamePath]" />\r
 \r
                                 <TextBlock VerticalAlignment="Center" Text="{x:Static Properties:ResourcesUI.Options_Format}"  Grid.Column="0" Grid.Row="1" Margin="0,5,0,0" />\r
-                                <TextBox Name="autoNameFormat" Text="{Binding AutonameFormat}" Width="380"  Grid.Column="1" Grid.Row="1"  Margin="0,5,0,0"\r
+                                <TextBox Name="autoNameFormat" Text="{Binding AutonameFormat, UpdateSourceTrigger=PropertyChanged}" Width="380"  Grid.Column="1" Grid.Row="1"  Margin="0,5,0,0"\r
                                          ToolTip="{x:Static Properties:Resources.Options_AdditionalFormatOptions}"  Style="{StaticResource LongToolTipHolder}" />\r
                             </Grid>\r
 \r