From d8b136992e4d008514a5af862e48c4e2dc670e1d Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:11:15 -0400 Subject: [PATCH 1/4] Create setting for configuring default file collision behavior --- TwitchDownloaderWPF/App.config | 3 ++ .../Properties/Settings.Designer.cs | 12 +++++++ .../Properties/Settings.settings | 3 ++ TwitchDownloaderWPF/WindowSettings.xaml | 35 +++++++++++++++++++ TwitchDownloaderWPF/WindowSettings.xaml.cs | 20 +++++++++++ 5 files changed, 73 insertions(+) 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/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/WindowSettings.xaml b/TwitchDownloaderWPF/WindowSettings.xaml index d2b06501..7eded6f2 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="" @@ -61,6 +62,40 @@ (?): + + + + + + + + + + + + + + + Prompt + + + + + Overwrite + + + + + Rename + + + + + Cancel + + + + (?): diff --git a/TwitchDownloaderWPF/WindowSettings.xaml.cs b/TwitchDownloaderWPF/WindowSettings.xaml.cs index 930e0963..dd6d4b17 100644 --- a/TwitchDownloaderWPF/WindowSettings.xaml.cs +++ b/TwitchDownloaderWPF/WindowSettings.xaml.cs @@ -93,6 +93,17 @@ private void Window_Initialized(object sender, EventArgs e) ComboLogLevels.SelectedItems.Add(item); } } + + var currentCollisionBehavior = (CollisionBehavior)Settings.Default.FileCollisionBehavior; + for (var i = 0; i < ComboFileCollisionBehavior.Items.Count; i++) + { + var current = (ComboBoxItem)ComboFileCollisionBehavior.Items[i]!; + if (currentCollisionBehavior == (CollisionBehavior)current.Tag) + { + ComboFileCollisionBehavior.SelectedIndex = i; + break; + } + } } private void BtnClearCache_Click(object sender, RoutedEventArgs e) @@ -327,6 +338,15 @@ private void ComboLogLevels_OnSelectionChanged(object sender, SelectionChangedEv Settings.Default.LogLevels = newLogLevel; } + private void ComboFileCollisionBehavior_OnSelectionChanged(object sender, SelectionChangedEventArgs e) + { + if (!IsInitialized) + return; + + var behavior = (ComboBoxItem)ComboFileCollisionBehavior.SelectedItem; + Settings.Default.FileCollisionBehavior = (int)behavior.Tag; + } + private void FilenameParameter_MouseDown(object sender, MouseButtonEventArgs e) { if (!IsInitialized || sender is not Run { Text: var parameter }) From dde6935486e2101fae7a8e2937803b4d2567d4d7 Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:26:10 -0400 Subject: [PATCH 2/4] Use setting to determine default collision behavior --- .../Models/CollisionBehavior.cs | 10 ++++++ .../Services/FileCollisionService.cs | 36 +++++++++---------- 2 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 TwitchDownloaderWPF/Models/CollisionBehavior.cs 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/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) }; } From 6f62b67320b45fd145abc2ad58b95d29934106bf Mon Sep 17 00:00:00 2001 From: ScrubN <72096833+ScrubN@users.noreply.github.com> Date: Wed, 28 Aug 2024 17:37:01 -0400 Subject: [PATCH 3/4] Add translations --- .../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 | 16 +++--- 13 files changed, 260 insertions(+), 8 deletions(-) diff --git a/TwitchDownloaderWPF/Translations/Strings.Designer.cs b/TwitchDownloaderWPF/Translations/Strings.Designer.cs index 0cdf2a03..9fe8ca6a 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 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..b18da0f3 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 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..f1879942 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 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..a9ff89b6 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 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..99b3ea9c 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 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..64785e0b 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 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..6bfe2554 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 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..88211fc1 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 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..a58d634b 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 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..20da60a7 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 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..cd1790e1 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 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..bbc7d12d 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 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 7eded6f2..f1341d41 100644 --- a/TwitchDownloaderWPF/WindowSettings.xaml +++ b/TwitchDownloaderWPF/WindowSettings.xaml @@ -13,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}">