From 4bcb917819f8a8c6c2bd91f57b9c98794d498c2a Mon Sep 17 00:00:00 2001 From: Scrub <72096833+ScrubN@users.noreply.github.com> Date: Wed, 28 Aug 2024 18:02:07 -0400 Subject: [PATCH] Allow customizing file collision handling in the the settings (#1199) * Create setting for configuring default file collision behavior * Use setting to determine default collision behavior * Add translations * Wording --- TwitchDownloaderWPF/App.config | 3 ++ .../Models/CollisionBehavior.cs | 10 ++++ .../Properties/Settings.Designer.cs | 12 +++++ .../Properties/Settings.settings | 3 ++ .../Services/FileCollisionService.cs | 36 ++++++------- .../Translations/Strings.Designer.cs | 54 +++++++++++++++++++ .../Translations/Strings.es.resx | 18 +++++++ .../Translations/Strings.fr.resx | 18 +++++++ .../Translations/Strings.it.resx | 18 +++++++ .../Translations/Strings.ja.resx | 18 +++++++ .../Translations/Strings.pl.resx | 18 +++++++ .../Translations/Strings.pt-br.resx | 18 +++++++ TwitchDownloaderWPF/Translations/Strings.resx | 18 +++++++ .../Translations/Strings.ru.resx | 18 +++++++ .../Translations/Strings.tr.resx | 18 +++++++ .../Translations/Strings.uk.resx | 18 +++++++ .../Translations/Strings.zh-cn.resx | 18 +++++++ TwitchDownloaderWPF/WindowSettings.xaml | 37 ++++++++++++- TwitchDownloaderWPF/WindowSettings.xaml.cs | 20 +++++++ 19 files changed, 352 insertions(+), 21 deletions(-) create mode 100644 TwitchDownloaderWPF/Models/CollisionBehavior.cs diff --git a/TwitchDownloaderWPF/App.config b/TwitchDownloaderWPF/App.config index e16ebc9c..5b56a280 100644 --- a/TwitchDownloaderWPF/App.config +++ b/TwitchDownloaderWPF/App.config @@ -244,6 +244,9 @@ + + 0 + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Models/CollisionBehavior.cs b/TwitchDownloaderWPF/Models/CollisionBehavior.cs new file mode 100644 index 00000000..b4af7b81 --- /dev/null +++ b/TwitchDownloaderWPF/Models/CollisionBehavior.cs @@ -0,0 +1,10 @@ +namespace TwitchDownloaderWPF.Models +{ + internal enum CollisionBehavior + { + Prompt, + Overwrite, + Rename, + Cancel + } +} \ No newline at end of file diff --git a/TwitchDownloaderWPF/Properties/Settings.Designer.cs b/TwitchDownloaderWPF/Properties/Settings.Designer.cs index 0f0c6b35..215ca8cc 100644 --- a/TwitchDownloaderWPF/Properties/Settings.Designer.cs +++ b/TwitchDownloaderWPF/Properties/Settings.Designer.cs @@ -969,5 +969,17 @@ public string PreferredQuality { this["PreferredQuality"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("0")] + public int FileCollisionBehavior { + get { + return ((int)(this["FileCollisionBehavior"])); + } + set { + this["FileCollisionBehavior"] = value; + } + } } } diff --git a/TwitchDownloaderWPF/Properties/Settings.settings b/TwitchDownloaderWPF/Properties/Settings.settings index 15564aee..abb426bb 100644 --- a/TwitchDownloaderWPF/Properties/Settings.settings +++ b/TwitchDownloaderWPF/Properties/Settings.settings @@ -239,6 +239,9 @@ + + 0 + diff --git a/TwitchDownloaderWPF/Services/FileCollisionService.cs b/TwitchDownloaderWPF/Services/FileCollisionService.cs index 0d26d54b..520d9e26 100644 --- a/TwitchDownloaderWPF/Services/FileCollisionService.cs +++ b/TwitchDownloaderWPF/Services/FileCollisionService.cs @@ -4,40 +4,36 @@ using System.Windows; using Ookii.Dialogs.Wpf; using TwitchDownloaderCore.Tools; +using TwitchDownloaderWPF.Models; +using TwitchDownloaderWPF.Properties; namespace TwitchDownloaderWPF.Services { public static class FileCollisionService { - private enum CollisionCommand - { - Prompt, - Overwrite, - Rename, - Cancel - } - - private static CollisionCommand _collisionCommand = CollisionCommand.Prompt; + private static CollisionBehavior? _sessionCollisionBehavior; [return: MaybeNull] public static FileInfo HandleCollisionCallback(FileInfo fileInfo, Window owner) { - if (_collisionCommand is not CollisionCommand.Prompt) + var collisionBehavior = _sessionCollisionBehavior ?? (CollisionBehavior)Settings.Default.FileCollisionBehavior; + + if (collisionBehavior is not CollisionBehavior.Prompt) { - return GetResult(fileInfo, _collisionCommand); + return GetResult(fileInfo, collisionBehavior); } var result = ShowDialog(fileInfo, owner, out var rememberChoice); if (rememberChoice) { - _collisionCommand = result; + _sessionCollisionBehavior = result; } return GetResult(fileInfo, result); } - private static CollisionCommand ShowDialog(FileInfo fileInfo, Window owner, out bool rememberChoice) + private static CollisionBehavior ShowDialog(FileInfo fileInfo, Window owner, out bool rememberChoice) { using var dialog = new TaskDialog(); dialog.WindowTitle = Translations.Strings.TitleFileAlreadyExists; @@ -70,26 +66,26 @@ private static CollisionCommand ShowDialog(FileInfo fileInfo, Window owner, out rememberChoice = dialog.IsVerificationChecked; if (buttonResult == overwriteButton) - return CollisionCommand.Overwrite; + return CollisionBehavior.Overwrite; if (buttonResult == renameButton) - return CollisionCommand.Rename; + return CollisionBehavior.Rename; if (buttonResult == cancelButton) - return CollisionCommand.Cancel; + return CollisionBehavior.Cancel; // This should never happen throw new ArgumentOutOfRangeException(); } [return: MaybeNull] - private static FileInfo GetResult(FileInfo fileInfo, CollisionCommand command) + private static FileInfo GetResult(FileInfo fileInfo, CollisionBehavior command) { return command switch { - CollisionCommand.Overwrite => fileInfo, - CollisionCommand.Rename => FilenameService.GetNonCollidingName(fileInfo), - CollisionCommand.Cancel => null, + CollisionBehavior.Overwrite => fileInfo, + CollisionBehavior.Rename => FilenameService.GetNonCollidingName(fileInfo), + CollisionBehavior.Cancel => null, _ => throw new ArgumentOutOfRangeException(nameof(command), command, null) }; } diff --git a/TwitchDownloaderWPF/Translations/Strings.Designer.cs b/TwitchDownloaderWPF/Translations/Strings.Designer.cs index 0cdf2a03..33119a62 100644 --- a/TwitchDownloaderWPF/Translations/Strings.Designer.cs +++ b/TwitchDownloaderWPF/Translations/Strings.Designer.cs @@ -968,6 +968,60 @@ public static string FileAlreadyExistsRenameDescription { } } + /// + /// Looks up a localized string similar to File Collision Behavior. + /// + public static string FileCollisionBehavior { + get { + return ResourceManager.GetString("FileCollisionBehavior", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Ask. + /// + public static string FileCollisionBehaviorAsk { + get { + return ResourceManager.GetString("FileCollisionBehaviorAsk", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Cancel. + /// + public static string FileCollisionBehaviorCancel { + get { + return ResourceManager.GetString("FileCollisionBehaviorCancel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Overwrite. + /// + public static string FileCollisionBehaviorOverwrite { + get { + return ResourceManager.GetString("FileCollisionBehaviorOverwrite", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Rename. + /// + public static string FileCollisionBehaviorRename { + get { + return ResourceManager.GetString("FileCollisionBehaviorRename", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it.. + /// + public static string FileCollisionBehaviorTooltip { + get { + return ResourceManager.GetString("FileCollisionBehaviorTooltip", resourceCulture); + } + } + /// /// Looks up a localized string similar to The display name of the channel which owns the video/clip/chat.. /// diff --git a/TwitchDownloaderWPF/Translations/Strings.es.resx b/TwitchDownloaderWPF/Translations/Strings.es.resx index 76d4435a..fbc7add9 100644 --- a/TwitchDownloaderWPF/Translations/Strings.es.resx +++ b/TwitchDownloaderWPF/Translations/Strings.es.resx @@ -983,4 +983,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + diff --git a/TwitchDownloaderWPF/Translations/Strings.fr.resx b/TwitchDownloaderWPF/Translations/Strings.fr.resx index 62fe5311..4d3e41a1 100644 --- a/TwitchDownloaderWPF/Translations/Strings.fr.resx +++ b/TwitchDownloaderWPF/Translations/Strings.fr.resx @@ -982,4 +982,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.it.resx b/TwitchDownloaderWPF/Translations/Strings.it.resx index 12090831..ebd21332 100644 --- a/TwitchDownloaderWPF/Translations/Strings.it.resx +++ b/TwitchDownloaderWPF/Translations/Strings.it.resx @@ -983,4 +983,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + diff --git a/TwitchDownloaderWPF/Translations/Strings.ja.resx b/TwitchDownloaderWPF/Translations/Strings.ja.resx index a189c11f..986da9b5 100644 --- a/TwitchDownloaderWPF/Translations/Strings.ja.resx +++ b/TwitchDownloaderWPF/Translations/Strings.ja.resx @@ -981,4 +981,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.pl.resx b/TwitchDownloaderWPF/Translations/Strings.pl.resx index b16dde91..ff2d6bb1 100644 --- a/TwitchDownloaderWPF/Translations/Strings.pl.resx +++ b/TwitchDownloaderWPF/Translations/Strings.pl.resx @@ -982,4 +982,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.pt-br.resx b/TwitchDownloaderWPF/Translations/Strings.pt-br.resx index aed41fe5..761004d4 100644 --- a/TwitchDownloaderWPF/Translations/Strings.pt-br.resx +++ b/TwitchDownloaderWPF/Translations/Strings.pt-br.resx @@ -985,4 +985,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.resx b/TwitchDownloaderWPF/Translations/Strings.resx index d757bd1e..20a48f4b 100644 --- a/TwitchDownloaderWPF/Translations/Strings.resx +++ b/TwitchDownloaderWPF/Translations/Strings.resx @@ -981,4 +981,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.ru.resx b/TwitchDownloaderWPF/Translations/Strings.ru.resx index 45e28e77..c4b6ae16 100644 --- a/TwitchDownloaderWPF/Translations/Strings.ru.resx +++ b/TwitchDownloaderWPF/Translations/Strings.ru.resx @@ -982,4 +982,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.tr.resx b/TwitchDownloaderWPF/Translations/Strings.tr.resx index 0281f9e8..d54f7a12 100644 --- a/TwitchDownloaderWPF/Translations/Strings.tr.resx +++ b/TwitchDownloaderWPF/Translations/Strings.tr.resx @@ -983,4 +983,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + \ No newline at end of file diff --git a/TwitchDownloaderWPF/Translations/Strings.uk.resx b/TwitchDownloaderWPF/Translations/Strings.uk.resx index 5c714a07..68f46d76 100644 --- a/TwitchDownloaderWPF/Translations/Strings.uk.resx +++ b/TwitchDownloaderWPF/Translations/Strings.uk.resx @@ -982,4 +982,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + diff --git a/TwitchDownloaderWPF/Translations/Strings.zh-cn.resx b/TwitchDownloaderWPF/Translations/Strings.zh-cn.resx index 4d67682f..3fd7adff 100644 --- a/TwitchDownloaderWPF/Translations/Strings.zh-cn.resx +++ b/TwitchDownloaderWPF/Translations/Strings.zh-cn.resx @@ -984,4 +984,22 @@ The display name of the primary game/category in the video/clip/chat. + + File Collision Behavior + + + The default handling for file collisions in the task queue. If a choice has already been remembered for the current session, an application restart will be required to override it. + + + Ask + + + Overwrite + + + Rename + + + Cancel + diff --git a/TwitchDownloaderWPF/WindowSettings.xaml b/TwitchDownloaderWPF/WindowSettings.xaml index d2b06501..f1341d41 100644 --- a/TwitchDownloaderWPF/WindowSettings.xaml +++ b/TwitchDownloaderWPF/WindowSettings.xaml @@ -4,6 +4,7 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:TwitchDownloaderWPF" + xmlns:model="clr-namespace:TwitchDownloaderWPF.Models" xmlns:behave="clr-namespace:TwitchDownloaderWPF.Behaviors" xmlns:lex="http://wpflocalizeextension.codeplex.com" lex:LocalizeDictionary.DesignCulture="" @@ -12,7 +13,7 @@ xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:fa="http://schemas.fontawesome.com/icons/" mc:Ignorable="d" - Title="{lex:Loc TitleGlobalSettings}" MinWidth="400" MinHeight="500" Width="500" Height="592" SizeToContent="Height" Initialized="Window_Initialized" Closing="Window_Closing" SourceInitialized="Window_OnSourceInitialized" Background="{DynamicResource AppBackground}"> + Title="{lex:Loc TitleGlobalSettings}" MinWidth="450" MinHeight="600" Width="500" Height="600" SizeToContent="Height" Initialized="Window_Initialized" Closing="Window_Closing" SourceInitialized="Window_OnSourceInitialized" Background="{DynamicResource AppBackground}">