From aea96d5eba1adf29e83638cdf4730b34a6c190d6 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Wed, 6 Apr 2022 19:00:19 +0300 Subject: [PATCH] Cleanup --- .../Exporting/MediaDownloader.cs | 4 ++-- .../ViewModels/Components/DashboardViewModel.cs | 15 +++++++-------- .../ViewModels/Dialogs/ExportSetupViewModel.cs | 10 ++++------ 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/DiscordChatExporter.Core/Exporting/MediaDownloader.cs b/DiscordChatExporter.Core/Exporting/MediaDownloader.cs index 946e227..b648489 100644 --- a/DiscordChatExporter.Core/Exporting/MediaDownloader.cs +++ b/DiscordChatExporter.Core/Exporting/MediaDownloader.cs @@ -103,7 +103,7 @@ internal partial class MediaDownloader // Otherwise, use the original file name but inject the hash in the middle var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName); var fileExtension = Path.GetExtension(fileName); - + // Probably not a file extension, just a dot in a long file name // https://github.com/Tyrrrz/DiscordChatExporter/issues/708 if (fileExtension.Length > 41) @@ -114,4 +114,4 @@ internal partial class MediaDownloader return PathEx.EscapeFileName(fileNameWithoutExtension.Truncate(42) + '-' + urlHash + fileExtension); } -} +} \ No newline at end of file diff --git a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs index 330cdcb..3e97520 100644 --- a/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Components/DashboardViewModel.cs @@ -25,7 +25,7 @@ public class DashboardViewModel : PropertyChangedBase private readonly IEventAggregator _eventAggregator; private readonly DialogManager _dialogManager; private readonly SettingsService _settingsService; - + private readonly AutoResetProgressMuxer _progressMuxer; private DiscordClient? _discord; @@ -49,7 +49,7 @@ public class DashboardViewModel : PropertyChangedBase : null; public IReadOnlyList? SelectedChannels { get; set; } - + public DashboardViewModel( IViewModelFactory viewModelFactory, IEventAggregator eventAggregator, @@ -60,9 +60,9 @@ public class DashboardViewModel : PropertyChangedBase _eventAggregator = eventAggregator; _dialogManager = dialogManager; _settingsService = settingsService; - + _progressMuxer = Progress.CreateMuxer().WithAutoReset(); - + this.Bind(o => o.IsBusy, (_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate)); Progress.Bind(o => o.Current, (_, _) => NotifyOfPropertyChange(() => IsProgressIndeterminate)); } @@ -74,7 +74,7 @@ public class DashboardViewModel : PropertyChangedBase Token = _settingsService.LastToken; } } - + public async void ShowSettings() { var dialog = _viewModelFactory.CreateSettingsViewModel(); @@ -90,7 +90,7 @@ public class DashboardViewModel : PropertyChangedBase { IsBusy = true; var progress = _progressMuxer.CreateInput(); - + try { var token = Token?.Trim('"', ' '); @@ -136,8 +136,7 @@ public class DashboardViewModel : PropertyChangedBase !IsBusy && _discord is not null && SelectedGuild is not null && - SelectedChannels is not null && - SelectedChannels.Any(); + SelectedChannels?.Any() is true; public async void ExportChannels() { diff --git a/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs b/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs index 2071b88..896374f 100644 --- a/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs +++ b/DiscordChatExporter.Gui/ViewModels/Dialogs/ExportSetupViewModel.cs @@ -21,12 +21,11 @@ public class ExportSetupViewModel : DialogScreen public IReadOnlyList? Channels { get; set; } - public bool IsSingleChannel => Channels is null || Channels.Count == 1; + public bool IsSingleChannel => Channels?.Count == 1; public string? OutputPath { get; set; } - public IReadOnlyList AvailableFormats => - Enum.GetValues(typeof(ExportFormat)).Cast().ToArray(); + public IReadOnlyList AvailableFormats { get; } = Enum.GetValues(); public ExportFormat SelectedFormat { get; set; } @@ -96,12 +95,11 @@ public class ExportSetupViewModel : DialogScreen _settingsService.LastShouldDownloadMedia = ShouldDownloadMedia; // If single channel - prompt file path - if (Channels is not null && IsSingleChannel) + if (IsSingleChannel) { - var channel = Channels.Single(); var defaultFileName = ExportRequest.GetDefaultOutputFileName( Guild!, - channel, + Channels!.Single(), SelectedFormat, After?.Pipe(Snowflake.FromDate), Before?.Pipe(Snowflake.FromDate)