Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow customizing file collision handling in the the settings #1199

Merged
merged 4 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions TwitchDownloaderWPF/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@
<setting name="PreferredQuality" serializeAs="String">
<value />
</setting>
<setting name="FileCollisionBehavior" serializeAs="String">
<value>0</value>
</setting>
</TwitchDownloaderWPF.Properties.Settings>
</userSettings>
</configuration>
10 changes: 10 additions & 0 deletions TwitchDownloaderWPF/Models/CollisionBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TwitchDownloaderWPF.Models
{
internal enum CollisionBehavior
{
Prompt,
Overwrite,
Rename,
Cancel
}
}
12 changes: 12 additions & 0 deletions TwitchDownloaderWPF/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions TwitchDownloaderWPF/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@
<Setting Name="PreferredQuality" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="FileCollisionBehavior" Type="System.Int32" Scope="User">
<Value Profile="(Default)">0</Value>
</Setting>
</Settings>
</SettingsFile>

36 changes: 16 additions & 20 deletions TwitchDownloaderWPF/Services/FileCollisionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
};
}
Expand Down
54 changes: 54 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.es.resx
Original file line number Diff line number Diff line change
Expand Up @@ -983,4 +983,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -982,4 +982,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.it.resx
Original file line number Diff line number Diff line change
Expand Up @@ -983,4 +983,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -981,4 +981,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.pl.resx
Original file line number Diff line number Diff line change
Expand Up @@ -982,4 +982,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.pt-br.resx
Original file line number Diff line number Diff line change
Expand Up @@ -985,4 +985,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -981,4 +981,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
18 changes: 18 additions & 0 deletions TwitchDownloaderWPF/Translations/Strings.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -982,4 +982,22 @@
<data name="FilenameParameterGameTooltip" xml:space="preserve">
<value>The display name of the primary game/category in the video/clip/chat.</value>
</data>
<data name="FileCollisionBehavior" xml:space="preserve">
<value>File Collision Behavior</value>
</data>
<data name="FileCollisionBehaviorTooltip" xml:space="preserve">
<value>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.</value>
</data>
<data name="FileCollisionBehaviorAsk" xml:space="preserve">
<value>Ask</value>
</data>
<data name="FileCollisionBehaviorOverwrite" xml:space="preserve">
<value>Overwrite</value>
</data>
<data name="FileCollisionBehaviorRename" xml:space="preserve">
<value>Rename</value>
</data>
<data name="FileCollisionBehaviorCancel" xml:space="preserve">
<value>Cancel</value>
</data>
</root>
Loading
Loading