Add partition by file size (#497)

This commit is contained in:
Andrew Kolos
2021-04-12 06:50:32 -04:00
committed by GitHub
parent ad3655396f
commit eb89ea5b40
23 changed files with 331 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
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;
@@ -46,6 +47,11 @@ 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 bool ShouldDownloadMedia { get; set; }
@@ -67,6 +73,8 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
SelectedFormat = _settingsService.LastExportFormat;
PartitionLimit = _settingsService.LastPartitionLimit;
ShouldDownloadMedia = _settingsService.LastShouldDownloadMedia;
SelectedPartitionFormat = _settingsService.LastPartitionFormat;
}
public void Confirm()
@@ -74,6 +82,7 @@ namespace DiscordChatExporter.Gui.ViewModels.Dialogs
// Persist preferences
_settingsService.LastExportFormat = SelectedFormat;
_settingsService.LastPartitionLimit = PartitionLimit;
_settingsService.LastPartitionFormat = SelectedPartitionFormat;
_settingsService.LastShouldDownloadMedia = ShouldDownloadMedia;
// If single channel - prompt file path

View File

@@ -8,6 +8,7 @@ using DiscordChatExporter.Core.Discord.Data;
using DiscordChatExporter.Core.Exceptions;
using DiscordChatExporter.Core.Exporting;
using DiscordChatExporter.Core.Utils.Extensions;
using DiscordChatExporter.Gui.Internal;
using DiscordChatExporter.Gui.Services;
using DiscordChatExporter.Gui.Utils;
using DiscordChatExporter.Gui.ViewModels.Dialogs;
@@ -213,7 +214,7 @@ namespace DiscordChatExporter.Gui.ViewModels
dialog.SelectedFormat,
dialog.After?.Pipe(Snowflake.FromDate),
dialog.Before?.Pipe(Snowflake.FromDate),
dialog.PartitionLimit,
CreatePartitioner(),
dialog.ShouldDownloadMedia,
_settingsService.ShouldReuseMedia,
_settingsService.DateFormat
@@ -236,6 +237,19 @@ 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()
};
}
}
}
}