diff --git a/TwitchDownloaderCLI/Modes/CacheHandler.cs b/TwitchDownloaderCLI/Modes/CacheHandler.cs index 28953a68..f2f8122b 100644 --- a/TwitchDownloaderCLI/Modes/CacheHandler.cs +++ b/TwitchDownloaderCLI/Modes/CacheHandler.cs @@ -27,21 +27,15 @@ private static void PromptClearCache() Console.WriteLine("Are you sure you want to clear the cache? This should really only be done if the program isn't working correctly."); while (true) { - Console.Write("[Y]es / [N]o: "); + Console.Write("[Y] Yes / [N] No: "); var userInput = Console.ReadLine()!.Trim().ToLower(); switch (userInput) { - case "y": - case "ye": - case "yes": + case "y" or "yes": ClearTempCache(); return; - case "n": - case "no": + case "n" or "no": return; - default: - Console.Write("Invalid input. "); - continue; } } } diff --git a/TwitchDownloaderCLI/Modes/RenderChat.cs b/TwitchDownloaderCLI/Modes/RenderChat.cs index 75e8ba03..6ea11ac7 100644 --- a/TwitchDownloaderCLI/Modes/RenderChat.cs +++ b/TwitchDownloaderCLI/Modes/RenderChat.cs @@ -77,7 +77,7 @@ private static ChatRenderOptions GetRenderOptions(ChatRenderArgs inputOptions, I "twitter" or "twemoji" => EmojiVendor.TwitterTwemoji, "google" or "notocolor" => EmojiVendor.GoogleNotoColor, "system" or "none" => EmojiVendor.None, - _ => throw new NotSupportedException("Invalid emoji vendor. Valid values are: 'twitter' / 'twemoji', and 'google' / 'notocolor'") + _ => throw new NotSupportedException("Invalid emoji vendor. Valid values are: 'twitter' / 'twemoji', 'google' / 'notocolor', and 'system' / 'none'") }, SkipDriveWaiting = inputOptions.SkipDriveWaiting, EmoteScale = inputOptions.ScaleEmote, diff --git a/TwitchDownloaderCore/Extensions/ReadOnlySpanExtensions.cs b/TwitchDownloaderCore/Extensions/ReadOnlySpanExtensions.cs index 5b003864..ecaac41c 100644 --- a/TwitchDownloaderCore/Extensions/ReadOnlySpanExtensions.cs +++ b/TwitchDownloaderCore/Extensions/ReadOnlySpanExtensions.cs @@ -95,7 +95,7 @@ private static int FindCloseQuoteChar(ReadOnlySpan destination, int openQu public static int UnEscapedIndexOf(this ReadOnlySpan str, char character) { if (character is '\\' or '\'' or '\"') - throw new ArgumentOutOfRangeException("Escape characters are not supported.", nameof(character)); + throw new ArgumentOutOfRangeException(nameof(character), character, "Escape characters are not supported."); var firstIndex = str.IndexOf(character); if (firstIndex == -1) @@ -146,7 +146,7 @@ public static int UnEscapedIndexOfAny(this ReadOnlySpan str, ReadOnlySpan< const string ESCAPE_CHARS = @"\'"""; if (characters.IndexOfAny(ESCAPE_CHARS) != -1) - throw new ArgumentOutOfRangeException("Escape characters are not supported.", nameof(characters)); + throw new ArgumentOutOfRangeException(nameof(characters), characters.ToString(), "Escape characters are not supported."); var firstIndex = str.IndexOfAny(characters); if (firstIndex == -1) diff --git a/TwitchDownloaderWPF/TwitchTasks/ChatDownloadTask.cs b/TwitchDownloaderWPF/TwitchTasks/ChatDownloadTask.cs index 45e00a97..e7846026 100644 --- a/TwitchDownloaderWPF/TwitchTasks/ChatDownloadTask.cs +++ b/TwitchDownloaderWPF/TwitchTasks/ChatDownloadTask.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; @@ -17,24 +18,14 @@ class ChatDownloadTask : ITwitchTask public int Progress { get => _progress; - set - { - if (value == _progress) return; - _progress = value; - OnPropertyChanged(); - } + private set => SetField(ref _progress, value); } private TwitchTaskStatus _status = TwitchTaskStatus.Ready; public TwitchTaskStatus Status { get => _status; - private set - { - if (value == _status) return; - _status = value; - OnPropertyChanged(); - } + private set => SetField(ref _status, value); } public ChatDownloadOptions DownloadOptions { get; init; } @@ -46,12 +37,7 @@ private set public TwitchTaskException Exception { get => _exception; - private set - { - if (Equals(value, _exception)) return; - _exception = value; - OnPropertyChanged(); - } + private set => SetField(ref _exception, value); } public string OutputFile => DownloadOptions.Filename; @@ -60,12 +46,7 @@ private set public bool CanCancel { get => _canCancel; - private set - { - if (value == _canCancel) return; - _canCancel = value; - OnPropertyChanged(); - } + private set => SetField(ref _canCancel, value); } public event PropertyChangedEventHandler PropertyChanged; @@ -147,5 +128,13 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } } } diff --git a/TwitchDownloaderWPF/TwitchTasks/ChatRenderTask.cs b/TwitchDownloaderWPF/TwitchTasks/ChatRenderTask.cs index 26a70ba8..6bd991d3 100644 --- a/TwitchDownloaderWPF/TwitchTasks/ChatRenderTask.cs +++ b/TwitchDownloaderWPF/TwitchTasks/ChatRenderTask.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; @@ -17,24 +18,14 @@ class ChatRenderTask : ITwitchTask public int Progress { get => _progress; - set - { - if (value == _progress) return; - _progress = value; - OnPropertyChanged(); - } + private set => SetField(ref _progress, value); } private TwitchTaskStatus _status = TwitchTaskStatus.Ready; public TwitchTaskStatus Status { get => _status; - private set - { - if (value == _status) return; - _status = value; - OnPropertyChanged(); - } + private set => SetField(ref _status, value); } public ChatRenderOptions DownloadOptions { get; init; } @@ -46,12 +37,7 @@ private set public TwitchTaskException Exception { get => _exception; - private set - { - if (Equals(value, _exception)) return; - _exception = value; - OnPropertyChanged(); - } + private set => SetField(ref _exception, value); } public string OutputFile => DownloadOptions.OutputFile; @@ -60,12 +46,7 @@ private set public bool CanCancel { get => _canCancel; - private set - { - if (value == _canCancel) return; - _canCancel = value; - OnPropertyChanged(); - } + private set => SetField(ref _canCancel, value); } public event PropertyChangedEventHandler PropertyChanged; @@ -166,5 +147,13 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } } } diff --git a/TwitchDownloaderWPF/TwitchTasks/ChatUpdateTask.cs b/TwitchDownloaderWPF/TwitchTasks/ChatUpdateTask.cs index d523cbea..48648be6 100644 --- a/TwitchDownloaderWPF/TwitchTasks/ChatUpdateTask.cs +++ b/TwitchDownloaderWPF/TwitchTasks/ChatUpdateTask.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; @@ -17,24 +18,14 @@ class ChatUpdateTask : ITwitchTask public int Progress { get => _progress; - set - { - if (value == _progress) return; - _progress = value; - OnPropertyChanged(); - } + private set => SetField(ref _progress, value); } private TwitchTaskStatus _status = TwitchTaskStatus.Ready; public TwitchTaskStatus Status { get => _status; - private set - { - if (value == _status) return; - _status = value; - OnPropertyChanged(); - } + private set => SetField(ref _status, value); } public ChatUpdateOptions UpdateOptions { get; init; } @@ -46,12 +37,7 @@ private set public TwitchTaskException Exception { get => _exception; - private set - { - if (Equals(value, _exception)) return; - _exception = value; - OnPropertyChanged(); - } + private set => SetField(ref _exception, value); } public string OutputFile => UpdateOptions.OutputFile; @@ -60,12 +46,7 @@ private set public bool CanCancel { get => _canCancel; - private set - { - if (value == _canCancel) return; - _canCancel = value; - OnPropertyChanged(); - } + private set => SetField(ref _canCancel, value); } public event PropertyChangedEventHandler PropertyChanged; @@ -148,5 +129,13 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } } } diff --git a/TwitchDownloaderWPF/TwitchTasks/ClipDownloadTask.cs b/TwitchDownloaderWPF/TwitchTasks/ClipDownloadTask.cs index c8ddfbcc..b5ea1a73 100644 --- a/TwitchDownloaderWPF/TwitchTasks/ClipDownloadTask.cs +++ b/TwitchDownloaderWPF/TwitchTasks/ClipDownloadTask.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; @@ -17,24 +18,14 @@ class ClipDownloadTask : ITwitchTask public int Progress { get => _progress; - set - { - if (value == _progress) return; - _progress = value; - OnPropertyChanged(); - } + private set => SetField(ref _progress, value); } private TwitchTaskStatus _status = TwitchTaskStatus.Ready; public TwitchTaskStatus Status { get => _status; - private set - { - if (value == _status) return; - _status = value; - OnPropertyChanged(); - } + private set => SetField(ref _status, value); } public ClipDownloadOptions DownloadOptions { get; init; } @@ -46,12 +37,7 @@ private set public TwitchTaskException Exception { get => _exception; - private set - { - if (Equals(value, _exception)) return; - _exception = value; - OnPropertyChanged(); - } + private set => SetField(ref _exception, value); } public string OutputFile => DownloadOptions.Filename; @@ -60,12 +46,7 @@ private set public bool CanCancel { get => _canCancel; - private set - { - if (value == _canCancel) return; - _canCancel = value; - OnPropertyChanged(); - } + private set => SetField(ref _canCancel, value); } public event PropertyChangedEventHandler PropertyChanged; @@ -147,5 +128,13 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } } } diff --git a/TwitchDownloaderWPF/TwitchTasks/ITwitchTask.cs b/TwitchDownloaderWPF/TwitchTasks/ITwitchTask.cs index 6445ca35..118e90dc 100644 --- a/TwitchDownloaderWPF/TwitchTasks/ITwitchTask.cs +++ b/TwitchDownloaderWPF/TwitchTasks/ITwitchTask.cs @@ -18,7 +18,7 @@ public enum TwitchTaskStatus public interface ITwitchTask : INotifyPropertyChanged { TaskData Info { get; set; } - int Progress { get; set; } + int Progress { get; } TwitchTaskStatus Status { get; } CancellationTokenSource TokenSource { get; set; } ITwitchTask DependantTask { get; set; } diff --git a/TwitchDownloaderWPF/TwitchTasks/VodDownloadTask.cs b/TwitchDownloaderWPF/TwitchTasks/VodDownloadTask.cs index 3f0447e5..111693f0 100644 --- a/TwitchDownloaderWPF/TwitchTasks/VodDownloadTask.cs +++ b/TwitchDownloaderWPF/TwitchTasks/VodDownloadTask.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using System.Threading; @@ -17,24 +18,14 @@ class VodDownloadTask : ITwitchTask public int Progress { get => _progress; - set - { - if (value == _progress) return; - _progress = value; - OnPropertyChanged(); - } + private set => SetField(ref _progress, value); } private TwitchTaskStatus _status = TwitchTaskStatus.Ready; public TwitchTaskStatus Status { get => _status; - private set - { - if (value == _status) return; - _status = value; - OnPropertyChanged(); - } + private set => SetField(ref _status, value); } public VideoDownloadOptions DownloadOptions { get; init; } @@ -46,12 +37,7 @@ private set public TwitchTaskException Exception { get => _exception; - private set - { - if (Equals(value, _exception)) return; - _exception = value; - OnPropertyChanged(); - } + private set => SetField(ref _exception, value); } public string OutputFile => DownloadOptions.Filename; @@ -60,12 +46,7 @@ private set public bool CanCancel { get => _canCancel; - private set - { - if (value == _canCancel) return; - _canCancel = value; - OnPropertyChanged(); - } + private set => SetField(ref _canCancel, value); } public event PropertyChangedEventHandler PropertyChanged; @@ -147,5 +128,13 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } } } diff --git a/TwitchDownloaderWPF/WindowOldVideoCacheManager.xaml.cs b/TwitchDownloaderWPF/WindowOldVideoCacheManager.xaml.cs index 03d914c0..9ca8485f 100644 --- a/TwitchDownloaderWPF/WindowOldVideoCacheManager.xaml.cs +++ b/TwitchDownloaderWPF/WindowOldVideoCacheManager.xaml.cs @@ -122,12 +122,7 @@ public GridItem(DirectoryInfo directoryInfo) public bool ShouldDelete { get => _shouldDelete; - set - { - if (value == _shouldDelete) return; - _shouldDelete = value; - OnPropertyChanged(); - } + set => SetField(ref _shouldDelete, value); } public int Age { get; } @@ -139,12 +134,7 @@ public bool ShouldDelete public string Size { get => _size; - private set - { - if (value == _size) return; - _size = value; - OnPropertyChanged(); - } + private set => SetField(ref _size, value); } public event PropertyChangedEventHandler PropertyChanged; @@ -154,6 +144,14 @@ private void OnPropertyChanged([CallerMemberName] string propertyName = null) PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } + private bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) + { + if (EqualityComparer.Default.Equals(field, value)) return false; + field = value; + OnPropertyChanged(propertyName); + return true; + } + public long CalculateSize() { var sizeBytes = Directory.EnumerateFiles().Sum(file => file.Length);