diff --git a/TwitchDownloaderCLI/Modes/DownloadChat.cs b/TwitchDownloaderCLI/Modes/DownloadChat.cs index c799ee01..fc709410 100644 --- a/TwitchDownloaderCLI/Modes/DownloadChat.cs +++ b/TwitchDownloaderCLI/Modes/DownloadChat.cs @@ -16,7 +16,7 @@ internal static void Download(ChatDownloadArgs inputOptions) { var progress = new CliTaskProgress(inputOptions.LogLevel); - var collisionHandler = new FileCollisionHandler(inputOptions); + var collisionHandler = new FileCollisionHandler(inputOptions, progress); var downloadOptions = GetDownloadOptions(inputOptions, collisionHandler, progress); var chatDownloader = new ChatDownloader(downloadOptions, progress); diff --git a/TwitchDownloaderCLI/Modes/DownloadClip.cs b/TwitchDownloaderCLI/Modes/DownloadClip.cs index 04da80e7..24c44c26 100644 --- a/TwitchDownloaderCLI/Modes/DownloadClip.cs +++ b/TwitchDownloaderCLI/Modes/DownloadClip.cs @@ -21,7 +21,7 @@ internal static void Download(ClipDownloadArgs inputOptions) FfmpegHandler.DetectFfmpeg(inputOptions.FfmpegPath, progress); } - var collisionHandler = new FileCollisionHandler(inputOptions); + var collisionHandler = new FileCollisionHandler(inputOptions, progress); var downloadOptions = GetDownloadOptions(inputOptions, collisionHandler, progress); var clipDownloader = new ClipDownloader(downloadOptions, progress); diff --git a/TwitchDownloaderCLI/Modes/DownloadVideo.cs b/TwitchDownloaderCLI/Modes/DownloadVideo.cs index 37f2d6dd..4ab857b8 100644 --- a/TwitchDownloaderCLI/Modes/DownloadVideo.cs +++ b/TwitchDownloaderCLI/Modes/DownloadVideo.cs @@ -19,7 +19,7 @@ internal static void Download(VideoDownloadArgs inputOptions) FfmpegHandler.DetectFfmpeg(inputOptions.FfmpegPath, progress); - var collisionHandler = new FileCollisionHandler(inputOptions); + var collisionHandler = new FileCollisionHandler(inputOptions, progress); var downloadOptions = GetDownloadOptions(inputOptions, collisionHandler, progress); var videoDownloader = new VideoDownloader(downloadOptions, progress); diff --git a/TwitchDownloaderCLI/Modes/MergeTs.cs b/TwitchDownloaderCLI/Modes/MergeTs.cs index 24e1f502..09fe9487 100644 --- a/TwitchDownloaderCLI/Modes/MergeTs.cs +++ b/TwitchDownloaderCLI/Modes/MergeTs.cs @@ -14,7 +14,7 @@ internal static void Merge(TsMergeArgs inputOptions) progress.LogInfo("The TS merger is experimental and is subject to change without notice in future releases."); - var collisionHandler = new FileCollisionHandler(inputOptions); + var collisionHandler = new FileCollisionHandler(inputOptions, progress); var mergeOptions = GetMergeOptions(inputOptions, collisionHandler); var tsMerger = new TsMerger(mergeOptions, progress); diff --git a/TwitchDownloaderCLI/Modes/RenderChat.cs b/TwitchDownloaderCLI/Modes/RenderChat.cs index 957f8878..35cf7c6c 100644 --- a/TwitchDownloaderCLI/Modes/RenderChat.cs +++ b/TwitchDownloaderCLI/Modes/RenderChat.cs @@ -19,7 +19,7 @@ internal static void Render(ChatRenderArgs inputOptions) FfmpegHandler.DetectFfmpeg(inputOptions.FfmpegPath, progress); - var collisionHandler = new FileCollisionHandler(inputOptions); + var collisionHandler = new FileCollisionHandler(inputOptions, progress); var renderOptions = GetRenderOptions(inputOptions, collisionHandler, progress); using var chatRenderer = new ChatRenderer(renderOptions, progress); diff --git a/TwitchDownloaderCLI/Modes/UpdateChat.cs b/TwitchDownloaderCLI/Modes/UpdateChat.cs index dd17007d..1949f391 100644 --- a/TwitchDownloaderCLI/Modes/UpdateChat.cs +++ b/TwitchDownloaderCLI/Modes/UpdateChat.cs @@ -16,7 +16,7 @@ internal static void Update(ChatUpdateArgs inputOptions) { var progress = new CliTaskProgress(inputOptions.LogLevel); - var collisionHandler = new FileCollisionHandler(inputOptions); + var collisionHandler = new FileCollisionHandler(inputOptions, progress); var updateOptions = GetUpdateOptions(inputOptions, collisionHandler, progress); var chatUpdater = new ChatUpdater(updateOptions, progress); diff --git a/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs b/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs index 770da3ab..0d6ab36a 100644 --- a/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs +++ b/TwitchDownloaderCLI/Tools/FileCollisionHandler.cs @@ -1,8 +1,8 @@ using System; -using System.Diagnostics.CodeAnalysis; using System.IO; using TwitchDownloaderCLI.Models; using TwitchDownloaderCLI.Modes.Arguments; +using TwitchDownloaderCore.Interfaces; using TwitchDownloaderCore.Tools; namespace TwitchDownloaderCLI.Tools @@ -10,28 +10,36 @@ namespace TwitchDownloaderCLI.Tools internal class FileCollisionHandler { private readonly IFileCollisionArgs _collisionArgs; + private readonly ITaskLogger _logger; - public FileCollisionHandler(IFileCollisionArgs collisionArgs) + public FileCollisionHandler(IFileCollisionArgs collisionArgs, ITaskLogger logger) { _collisionArgs = collisionArgs; + _logger = logger; } - [return: MaybeNull] public FileInfo HandleCollisionCallback(FileInfo fileInfo) { return _collisionArgs.OverwriteBehavior switch { OverwriteBehavior.Overwrite => fileInfo, - OverwriteBehavior.Exit => null, + OverwriteBehavior.Exit => Exit(fileInfo), OverwriteBehavior.Rename => FilenameService.GetNonCollidingName(fileInfo), OverwriteBehavior.Prompt => PromptUser(fileInfo), _ => throw new ArgumentOutOfRangeException(nameof(_collisionArgs.OverwriteBehavior), _collisionArgs.OverwriteBehavior, null) }; } - [return: MaybeNull] + private FileInfo Exit(FileInfo fileInfo) + { + _logger.LogInfo($"The file '{fileInfo.FullName}' already exists, exiting."); + Environment.Exit(1); + return null; + } + private static FileInfo PromptUser(FileInfo fileInfo) { + // Deliberate use of Console.WriteLine instead of logger. Do not change. Console.WriteLine($"The file '{fileInfo.FullName}' already exists."); while (true) @@ -43,7 +51,8 @@ private static FileInfo PromptUser(FileInfo fileInfo) case "o" or "overwrite": return fileInfo; case "e" or "exit": - return null; + Environment.Exit(1); + break; case "r" or "rename": return FilenameService.GetNonCollidingName(fileInfo); }