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