This commit is contained in:
Tyrrrz
2021-04-16 23:09:08 +03:00
parent 2fea455c64
commit 511af1e35c
38 changed files with 173 additions and 377 deletions

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DiscordChatExporter.Gui.Internal;
using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Exporting;
@@ -47,12 +46,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
public DateTimeOffset? Before => BeforeDate?.Add(BeforeTime ?? TimeSpan.Zero);
public IReadOnlyList<PartitionFormat> AvailablePartitionFormats =>
Enum.GetValues(typeof(PartitionFormat)).Cast<PartitionFormat>().ToArray();
public PartitionFormat SelectedPartitionFormat { get; set; }
public int? PartitionLimit { get; set; }
public string? PartitionLimitValue { get; set; }
public bool ShouldDownloadMedia { get; set; }
@@ -61,7 +55,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
public bool IsAdvancedSectionDisplayedByDefault =>
After != default ||
Before != default ||
PartitionLimit != default ||
!string.IsNullOrWhiteSpace(PartitionLimitValue) ||
ShouldDownloadMedia != default;
public ExportSetupViewModel(DialogManager dialogManager, SettingsService settingsService)
@@ -71,18 +65,15 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
// Persist preferences
SelectedFormat = _settingsService.LastExportFormat;
PartitionLimit = _settingsService.LastPartitionLimit;
PartitionLimitValue = _settingsService.LastPartitionLimitValue;
ShouldDownloadMedia = _settingsService.LastShouldDownloadMedia;
SelectedPartitionFormat = _settingsService.LastPartitionFormat;
}
public void Confirm()
{
// Persist preferences
_settingsService.LastExportFormat = SelectedFormat;
_settingsService.LastPartitionLimit = PartitionLimit;
_settingsService.LastPartitionFormat = SelectedPartitionFormat;
_settingsService.LastPartitionLimitValue = PartitionLimitValue;
_settingsService.LastShouldDownloadMedia = ShouldDownloadMedia;
// If single channel - prompt file path

View File

@@ -7,8 +7,8 @@ using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Exceptions;
using DiscordChatExporter.Core.Exporting;
using DiscordChatExporter.Core.Exporting.Partitioning;
using DiscordChatExporter.Core.Utils.Extensions;
using DiscordChatExporter.Gui.Internal;
using DiscordChatExporter.Gui.Services;
using DiscordChatExporter.Gui.Utils;
using DiscordChatExporter.Gui.ViewModels.Dialogs;
@@ -65,18 +65,16 @@ namespace DiscordChatExporter.Gui.ViewModels
DisplayName = $"{App.Name} v{App.VersionString}";
// Update busy state when progress manager changes
ProgressManager.Bind(o => o.IsActive,
(sender, args) => IsBusy = ProgressManager.IsActive
ProgressManager.Bind(o => o.IsActive, (_, _) =>
IsBusy = ProgressManager.IsActive
);
ProgressManager.Bind(o => o.IsActive,
(sender, args) => IsProgressIndeterminate =
ProgressManager.IsActive && ProgressManager.Progress.IsEither(0, 1)
ProgressManager.Bind(o => o.IsActive, (_, _) =>
IsProgressIndeterminate = ProgressManager.IsActive && ProgressManager.Progress.IsEither(0, 1)
);
ProgressManager.Bind(o => o.Progress,
(sender, args) => IsProgressIndeterminate =
ProgressManager.IsActive && ProgressManager.Progress.IsEither(0, 1)
ProgressManager.Bind(o => o.Progress, (_, _) =>
IsProgressIndeterminate = ProgressManager.IsActive && ProgressManager.Progress.IsEither(0, 1)
);
}
@@ -207,6 +205,10 @@ namespace DiscordChatExporter.Gui.ViewModels
try
{
var partitionLimit = !string.IsNullOrWhiteSpace(dialog.PartitionLimitValue)
? PartitionLimit.Parse(dialog.PartitionLimitValue)
: NullPartitionLimit.Instance;
var request = new ExportRequest(
dialog.Guild!,
channel!,
@@ -214,7 +216,7 @@ namespace DiscordChatExporter.Gui.ViewModels
dialog.SelectedFormat,
dialog.After?.Pipe(Snowflake.FromDate),
dialog.Before?.Pipe(Snowflake.FromDate),
CreatePartitioner(),
partitionLimit,
dialog.ShouldDownloadMedia,
_settingsService.ShouldReuseMedia,
_settingsService.DateFormat
@@ -237,19 +239,6 @@ namespace DiscordChatExporter.Gui.ViewModels
// Notify of overall completion
if (successfulExportCount > 0)
Notifications.Enqueue($"Successfully exported {successfulExportCount} channel(s)");
IPartitioner CreatePartitioner()
{
var partitionFormat = dialog.SelectedPartitionFormat;
var partitionLimit = dialog.PartitionLimit;
return (partitionFormat, partitionLimit) switch
{
(PartitionFormat.MessageCount, int messageLimit) => new MessageCountPartitioner(messageLimit),
(PartitionFormat.FileSize, int fileSizeLimit) => new FileSizePartitioner(fileSizeLimit),
_ => new NullPartitioner()
};
}
}
}
}