diff options
author | sr55 <[email protected]> | 2019-11-17 21:48:17 +0000 |
---|---|---|
committer | sr55 <[email protected]> | 2019-11-17 21:48:43 +0000 |
commit | 3a7fd5f66cb32cc0f97de43d5d8de37fe163459d (patch) | |
tree | d3969ebbab20610576078cc61a136e7d2e74f7d4 /win | |
parent | 604bc2499c456fb2cfd088b5014306f2c27d26c9 (diff) |
WinGui: Add a new option to autoname that mimic's an unintended behaviour of 1.2 "Always use the default path for each new name generated" #2434
Diffstat (limited to 'win')
-rw-r--r-- | win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs | 123 | ||||
-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/Properties/ResourcesTooltips.Designer.cs | 9 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx | 3 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/UserSettingConstants.cs | 1 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs | 19 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/Views/OptionsView.xaml | 14 | ||||
-rw-r--r-- | win/CS/HandBrakeWPF/defaultsettings.xml | 8 |
9 files changed, 126 insertions, 63 deletions
diff --git a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs index 23826a043..3baab2e54 100644 --- a/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs +++ b/win/CS/HandBrakeWPF/Helpers/AutoNameHelper.cs @@ -13,6 +13,7 @@ namespace HandBrakeWPF.Helpers using System.IO;
using System.Linq;
using System.Reflection;
+ using System.Runtime.CompilerServices;
using Caliburn.Micro;
@@ -47,27 +48,9 @@ namespace HandBrakeWPF.Helpers if (task.Title != 0)
{
- // Get the Source Name and remove any invalid characters
+ // Get the Source Name and remove any invalid characters and clean it per users options.
string sourceName = Path.GetInvalidFileNameChars().Aggregate(sourceOrLabelName, (current, character) => current.Replace(character.ToString(), string.Empty));
-
- // Remove Underscores
- if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore))
- {
- sourceName = sourceName.Replace("_", " ");
- }
-
- if (userSettingService.GetUserSetting<bool>(UserSettingConstants.RemovePunctuation))
- {
- sourceName = sourceName.Replace("-", string.Empty);
- sourceName = sourceName.Replace(",", string.Empty);
- sourceName = sourceName.Replace(".", string.Empty);
- }
-
- // Switch to "Title Case"
- if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameTitleCase))
- {
- sourceName = sourceName.ToTitleCase();
- }
+ sourceName = CleanupSourceName(sourceName, userSettingService);
// Get the Selected Title Number
string dvdTitle = task.Title.ToString();
@@ -81,32 +64,8 @@ namespace HandBrakeWPF.Helpers combinedChapterTag = chapterStart + "-" + chapterFinish;
}
- // Local method to check if we have a creation time in the meta data. If not, fall back to source file creation time.
- DateTime obtainCreateDateObject()
- {
- var rd = task.MetaData.ReleaseDate;
- if (DateTime.TryParse(rd, out var d))
- {
- return d;
- }
-
- try
- {
- return File.GetCreationTime(task.Source);
- }
- catch (Exception e)
- {
- if (e is UnauthorizedAccessException || e is PathTooLongException || e is NotSupportedException)
- {
- // Suspect the most likely concerns trying to grab the creation date in which we would want to swallow exception.
- return default(DateTime);
- }
-
- throw e;
- }
- }
-
- var creationDateTime = obtainCreateDateObject();
+ // Creation Date / Time
+ var creationDateTime = ObtainCreateDateObject(task);
string createDate = creationDateTime.Date.ToShortDateString().Replace('/', '-');
string createTime = creationDateTime.ToString("HH-mm");
@@ -148,6 +107,29 @@ namespace HandBrakeWPF.Helpers return true;
}
+ private static string CleanupSourceName(string sourceName, IUserSettingService userSettingService)
+ {
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameRemoveUnderscore))
+ {
+ sourceName = sourceName.Replace("_", " ");
+ }
+
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.RemovePunctuation))
+ {
+ sourceName = sourceName.Replace("-", string.Empty);
+ sourceName = sourceName.Replace(",", string.Empty);
+ sourceName = sourceName.Replace(".", string.Empty);
+ }
+
+ // Switch to "Title Case"
+ if (userSettingService.GetUserSetting<bool>(UserSettingConstants.AutoNameTitleCase))
+ {
+ sourceName = sourceName.ToTitleCase();
+ }
+
+ return sourceName;
+ }
+
private static string GenerateDestinationFileName(EncodeTask task, IUserSettingService userSettingService, string sourceName, string dvdTitle, string combinedChapterTag, string createDate, string createTime)
{
string destinationFilename;
@@ -214,29 +196,34 @@ namespace HandBrakeWPF.Helpers private static string GetAutonamePath(IUserSettingService userSettingService, EncodeTask task, string sourceName)
{
- string autoNamePath = string.Empty;
+ string autoNamePath = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim();
+
+ // If enabled, use the current Destination path.
+ if (!userSettingService.GetUserSetting<bool>(UserSettingConstants.AlwaysUseDefaultPath) && !string.IsNullOrEmpty(task.Destination))
+ {
+ string path = Path.GetDirectoryName(task.Destination);
+ if (!string.IsNullOrEmpty(path))
+ {
+ return path;
+ }
+ }
- // If there is an auto name path, use it...
+ // Handle {source_path}
if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().StartsWith("{source_path}") && !string.IsNullOrEmpty(task.Source))
{
string savedPath = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim().Replace("{source_path}\\", string.Empty).Replace("{source_path}", string.Empty);
-
- string directory = Directory.Exists(task.Source)
- ? task.Source
- : Path.GetDirectoryName(task.Source);
+ string directory = Directory.Exists(task.Source) ? task.Source : Path.GetDirectoryName(task.Source);
autoNamePath = Path.Combine(directory, savedPath);
}
- else
- {
- autoNamePath = userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Trim();
- }
+ // Handle {source}
if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Contains("{source}") && !string.IsNullOrEmpty(task.Source))
{
sourceName = Path.GetInvalidPathChars().Aggregate(sourceName, (current, character) => current.Replace(character.ToString(), string.Empty));
autoNamePath = autoNamePath.Replace("{source}", sourceName);
}
+ // Handle {source_folder_name}
if (userSettingService.GetUserSetting<string>(UserSettingConstants.AutoNamePath).Contains("{source_folder_name}") && !string.IsNullOrEmpty(task.Source))
{
// Second Case: We have a Path, with "{source_folder}" in it, therefore we need to replace it with the folder name from the source.
@@ -304,5 +291,29 @@ namespace HandBrakeWPF.Helpers return autoNamePath;
}
+
+ private static DateTime ObtainCreateDateObject(EncodeTask task)
+ {
+ var rd = task.MetaData.ReleaseDate;
+ if (DateTime.TryParse(rd, out var d))
+ {
+ return d;
+ }
+
+ try
+ {
+ return File.GetCreationTime(task.Source);
+ }
+ catch (Exception e)
+ {
+ if (e is UnauthorizedAccessException || e is PathTooLongException || e is NotSupportedException)
+ {
+ // Suspect the most likely concerns trying to grab the creation date in which we would want to swallow exception.
+ return default(DateTime);
+ }
+
+ throw e;
+ }
+ }
}
}
diff --git a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs index ccf4a541d..5d84b0c07 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/Resources.Designer.cs @@ -3326,6 +3326,15 @@ namespace HandBrakeWPF.Properties { } /// <summary> + /// Looks up a localized string similar to Always use the default path for each new name generated.. + /// </summary> + public static string OptionsView_AlwaysUseDefaultPath { + get { + return ResourceManager.GetString("OptionsView_AlwaysUseDefaultPath", resourceCulture); + } + } + + /// <summary> /// Looks up a localized string similar to < Back. /// </summary> public static string OptionsView_BackButton { diff --git a/win/CS/HandBrakeWPF/Properties/Resources.resx b/win/CS/HandBrakeWPF/Properties/Resources.resx index eb271f567..051d217b8 100644 --- a/win/CS/HandBrakeWPF/Properties/Resources.resx +++ b/win/CS/HandBrakeWPF/Properties/Resources.resx @@ -2172,4 +2172,7 @@ Where supported, any user presets will have been imported.</value> <data name="UpdateCheck_Weekly" xml:space="preserve">
<value>Weekly</value>
</data>
+ <data name="OptionsView_AlwaysUseDefaultPath" xml:space="preserve">
+ <value>Always use the default path for each new name generated.</value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs index cf331974e..d825c3251 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.Designer.cs @@ -464,6 +464,15 @@ namespace HandBrakeWPF.Properties { }
/// <summary>
+ /// Looks up a localized string similar to When enabled time the auto name generates a new filename, it will use the default path. When disabled, it will use the path in the destination box on the main window..
+ /// </summary>
+ public static string OptionsView_AlwaysUseDefaultPath {
+ get {
+ return ResourceManager.GetString("OptionsView_AlwaysUseDefaultPath", resourceCulture);
+ }
+ }
+
+ /// <summary>
/// Looks up a localized string similar to Anamorphic allows arbitrary storage dimensions while preserving the original aspect during playback.
///
///Off disables anamorphic. Video storage dimensions and display dimensions will be identical. Only useful for compatibility with certain legacy devices.
diff --git a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx index 5c8c2967a..e3e27fe0b 100644 --- a/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx +++ b/win/CS/HandBrakeWPF/Properties/ResourcesTooltips.resx @@ -461,4 +461,7 @@ Lapsharp's Sprite tune is useful for 1-/4-/8-/16-bit 2-dimensional games. Sprite <data name="MainView_StartPoint" xml:space="preserve">
<value>The start point for this range.</value>
</data>
+ <data name="OptionsView_AlwaysUseDefaultPath" xml:space="preserve">
+ <value>When enabled time the auto name generates a new filename, it will use the default path. When disabled, it will use the path in the destination box on the main window.</value>
+ </data>
</root>
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/UserSettingConstants.cs b/win/CS/HandBrakeWPF/UserSettingConstants.cs index 9c3abc470..2d69abee6 100644 --- a/win/CS/HandBrakeWPF/UserSettingConstants.cs +++ b/win/CS/HandBrakeWPF/UserSettingConstants.cs @@ -74,5 +74,6 @@ namespace HandBrakeWPF public const string WhenDonePerformActionImmediately = "WhenDonePerformActionImmediately";
public const string UseDarkTheme = "UseDarkTheme";
public const string PreviewRotationFlip = "PreviewRotationFlip";
+ public const string AlwaysUseDefaultPath = "AlwaysUseDefaultPath";
}
}
\ No newline at end of file diff --git a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs index 0be6a26a7..5513d37ed 100644 --- a/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/OptionsViewModel.cs @@ -107,6 +107,7 @@ namespace HandBrakeWPF.ViewModels private bool showPrePostFilenameBox;
private bool whenDonePerformActionImmediately;
private bool useDarkTheme;
+ private bool alwaysUseDefaultPath;
#endregion
@@ -688,6 +689,21 @@ namespace HandBrakeWPF.ViewModels }
}
+ public bool AlwaysUseDefaultPath
+ {
+ get => this.alwaysUseDefaultPath;
+ set
+ {
+ if (value == this.alwaysUseDefaultPath)
+ {
+ return;
+ }
+
+ this.alwaysUseDefaultPath = value;
+ this.NotifyOfPropertyChange(() => this.AlwaysUseDefaultPath);
+ }
+ }
+
#endregion
#region Preview
@@ -1476,6 +1492,8 @@ namespace HandBrakeWPF.ViewModels this.SelectedCollisionBehaviour = this.userSettingService.GetUserSetting<int>(UserSettingConstants.AutonameFileCollisionBehaviour);
this.PrePostFilenameText = this.userSettingService.GetUserSetting<string>(UserSettingConstants.AutonameFilePrePostString);
+ this.AlwaysUseDefaultPath = this.userSettingService.GetUserSetting<bool>(UserSettingConstants.AlwaysUseDefaultPath);
+
// #############################
// Picture Tab
// #############################
@@ -1621,6 +1639,7 @@ namespace HandBrakeWPF.ViewModels this.userSettingService.SetUserSetting(UserSettingConstants.FileOverwriteBehaviour, this.SelectedOverwriteBehaviour);
this.userSettingService.SetUserSetting(UserSettingConstants.AutonameFileCollisionBehaviour, this.SelectedCollisionBehaviour);
this.userSettingService.SetUserSetting(UserSettingConstants.AutonameFilePrePostString, this.PrePostFilenameText);
+ this.userSettingService.SetUserSetting(UserSettingConstants.AlwaysUseDefaultPath, this.AlwaysUseDefaultPath);
/* Previews */
this.userSettingService.SetUserSetting(UserSettingConstants.VLCPath, this.VLCPath);
diff --git a/win/CS/HandBrakeWPF/Views/OptionsView.xaml b/win/CS/HandBrakeWPF/Views/OptionsView.xaml index 9f489a574..ef383956e 100644 --- a/win/CS/HandBrakeWPF/Views/OptionsView.xaml +++ b/win/CS/HandBrakeWPF/Views/OptionsView.xaml @@ -167,6 +167,7 @@ <Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
+ <RowDefinition Height="Auto"/>
<RowDefinition Height="7"/>
<RowDefinition Height="Auto"/>
@@ -180,15 +181,15 @@ </Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Text="{x:Static Properties:Resources.Options_DefaultPath}" Grid.Column="0" Grid.Row="0" />
- <TextBox Name="autoNameOutputPath" Text="{Binding AutoNameDefaultPath}" Width="380" Grid.Column="1" Grid.Row="0"
- ToolTip="{x:Static Properties:Resources.Options_DefaultPathAdditionalParams}" HorizontalAlignment="Left" />
+ <TextBox Name="autoNameOutputPath" Text="{Binding AutoNameDefaultPath}" Width="380" Grid.Column="1" Grid.Row="0" ToolTip="{x:Static Properties:Resources.Options_DefaultPathAdditionalParams}" HorizontalAlignment="Left" />
<Button Content="{x:Static Properties:Resources.Browse}" Margin="5,0,0,0" Grid.Column="2" Grid.Row="0" cal:Message.Attach="[Event Click] = [Action BrowseAutoNamePath]" HorizontalAlignment="Left" />
<TextBlock Text="{x:Static Properties:Resources.OptionsView_PathOptions}" Grid.Row="1" Grid.Column="1" Grid.ColumnSpan="2" FontStyle="Italic" FontSize="11" TextWrapping="Wrap" />
+ <CheckBox IsChecked="{Binding AlwaysUseDefaultPath}" Content="{x:Static Properties:Resources.OptionsView_AlwaysUseDefaultPath}" ToolTip="{x:Static Properties:ResourcesTooltips.OptionsView_AlwaysUseDefaultPath}" Grid.Row="2" Grid.Column="1" />
+
- <TextBlock VerticalAlignment="Center" Text="{x:Static Properties:Resources.Options_Format}" Grid.Column="0" Grid.Row="3" Margin="0,5,0,0" />
- <TextBox Name="autoNameFormat" Text="{Binding AutonameFormat, UpdateSourceTrigger=PropertyChanged}" Width="380" Grid.Column="1" Grid.Row="3" Margin="0,0,0,0"
- ToolTip="{x:Static Properties:Resources.Options_AdditionalFormatOptions}" HorizontalAlignment="Left" />
- <TextBlock Text="{x:Static Properties:Resources.OptionsView_FormatOptions}" Grid.Row="4" Grid.Column="1" Grid.ColumnSpan="2" FontStyle="Italic" FontSize="11" TextWrapping="Wrap" />
+ <TextBlock VerticalAlignment="Center" Text="{x:Static Properties:Resources.Options_Format}" Grid.Column="0" Grid.Row="4" Margin="0,5,0,0" />
+ <TextBox Name="autoNameFormat" Text="{Binding AutonameFormat, UpdateSourceTrigger=PropertyChanged}" Width="380" Grid.Column="1" Grid.Row="4" Margin="0,0,0,0" ToolTip="{x:Static Properties:Resources.Options_AdditionalFormatOptions}" HorizontalAlignment="Left" />
+ <TextBlock Text="{x:Static Properties:Resources.OptionsView_FormatOptions}" Grid.Row="5" Grid.Column="1" Grid.ColumnSpan="2" FontStyle="Italic" FontSize="11" TextWrapping="Wrap" />
</Grid>
<StackPanel Orientation="Horizontal" Margin="0,15,0,0">
@@ -197,7 +198,6 @@ <TextBox Text="{Binding PrePostFilenameText, UpdateSourceTrigger=PropertyChanged}" Width="150" VerticalAlignment="Center" Visibility="{Binding ShowPrePostFilenameBox, Converter={StaticResource boolToVisConverter}}" HorizontalAlignment="Left" Margin="5,0,0,0" />
</StackPanel>
-
<StackPanel Orientation="Vertical" Margin="0,15,0,0">
<CheckBox Content="{x:Static Properties:Resources.Options_TitleCase}" IsChecked="{Binding ChangeToTitleCase}" />
<CheckBox Content="{x:Static Properties:Resources.Options_ReplaceUnderscores}" IsChecked="{Binding RemoveUnderscores}"/>
diff --git a/win/CS/HandBrakeWPF/defaultsettings.xml b/win/CS/HandBrakeWPF/defaultsettings.xml index 98e40d45e..c560f1df0 100644 --- a/win/CS/HandBrakeWPF/defaultsettings.xml +++ b/win/CS/HandBrakeWPF/defaultsettings.xml @@ -569,4 +569,12 @@ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">false</anyType>
</value>
</item>
+ <item>
+ <key>
+ <string>AlwaysUseDefaultPath</string>
+ </key>
+ <value>
+ <anyType xmlns:q1="http://www.w3.org/2001/XMLSchema" d4p1:type="q1:boolean" xmlns:d4p1="http://www.w3.org/2001/XMLSchema-instance">true</anyType>
+ </value>
+ </item>
</dictionary>
\ No newline at end of file |