mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-21 05:28:39 +00:00
Add partition by file size (#497)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Gui.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Converters
|
||||
{
|
||||
[ValueConversion(typeof(ExportFormat), typeof(string))]
|
||||
public class PartitionFormatToStringConverter : IValueConverter
|
||||
{
|
||||
public static PartitionFormatToStringConverter Instance { get; } = new();
|
||||
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is PartitionFormat partitionFormatValue)
|
||||
return partitionFormatValue.GetDisplayName();
|
||||
|
||||
return default(string);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using DiscordChatExporter.Gui.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Converters
|
||||
{
|
||||
[ValueConversion(typeof(DateTimeOffset?), typeof(DateTime?))]
|
||||
public class PartitionFormatToTextBoxHintConverter : IValueConverter
|
||||
{
|
||||
public static PartitionFormatToTextBoxHintConverter Instance { get; } = new();
|
||||
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is PartitionFormat partitionFormat)
|
||||
return partitionFormat switch
|
||||
{
|
||||
PartitionFormat.FileSize => "MB per partition",
|
||||
PartitionFormat.MessageCount => "Messages per partition",
|
||||
_ => default(string)
|
||||
};
|
||||
|
||||
return default(DateTime?);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using DiscordChatExporter.Gui.Internal;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Converters
|
||||
{
|
||||
[ValueConversion(typeof(DateTimeOffset?), typeof(DateTime?))]
|
||||
public class PartitionFormatToTooltipConverter : IValueConverter
|
||||
{
|
||||
public static PartitionFormatToTextBoxHintConverter Instance { get; } = new();
|
||||
|
||||
public object? Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is PartitionFormat partitionFormat)
|
||||
return partitionFormat switch
|
||||
{
|
||||
PartitionFormat.FileSize => "Split output into partitions close to this file size",
|
||||
PartitionFormat.MessageCount => "Split output into partitions limited to this number of messages",
|
||||
_ => default(string)
|
||||
};
|
||||
|
||||
return default(DateTime?);
|
||||
}
|
||||
|
||||
public object? ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Gui.Internal;
|
||||
using Tyrrrz.Settings;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Services
|
||||
@@ -22,6 +23,8 @@ namespace DiscordChatExporter.Gui.Services
|
||||
|
||||
public ExportFormat LastExportFormat { get; set; } = ExportFormat.HtmlDark;
|
||||
|
||||
public PartitionFormat LastPartitionFormat { get; set; } = PartitionFormat.MessageCount;
|
||||
|
||||
public int? LastPartitionLimit { get; set; }
|
||||
|
||||
public bool LastShouldDownloadMedia { get; set; }
|
||||
|
||||
22
DiscordChatExporter.Gui/Utils/PartitionFormat.cs
Normal file
22
DiscordChatExporter.Gui/Utils/PartitionFormat.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace DiscordChatExporter.Gui.Internal
|
||||
{
|
||||
public enum PartitionFormat
|
||||
{
|
||||
MessageCount,
|
||||
FileSize,
|
||||
}
|
||||
|
||||
public static class PartitionFormatExtensions
|
||||
{
|
||||
public static string GetDisplayName(this PartitionFormat format) => format switch
|
||||
{
|
||||
PartitionFormat.MessageCount => "Message count",
|
||||
PartitionFormat.FileSize => "File size (MB)",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(format))
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,12 +126,43 @@
|
||||
</Grid>
|
||||
|
||||
<!-- Partitioning -->
|
||||
<TextBox
|
||||
Margin="16,8"
|
||||
materialDesign:HintAssist.Hint="Messages per partition"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
Text="{Binding PartitionLimit, TargetNullValue=''}"
|
||||
ToolTip="Split output into partitions limited to this number of messages" />
|
||||
<Grid Name="PartitioningGrid">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="1*" />
|
||||
<ColumnDefinition Width="1*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<ComboBox
|
||||
Name="PartitionFormatComboBox"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
Margin="16,8"
|
||||
materialDesign:HintAssist.Hint="Partition by"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
IsReadOnly="True"
|
||||
ItemsSource="{Binding AvailablePartitionFormats}"
|
||||
SelectedItem="{Binding SelectedPartitionFormat}">
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Converter={x:Static converters:PartitionFormatToStringConverter.Instance}}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
|
||||
<TextBox
|
||||
Name="PartitionTextBox"
|
||||
Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
Margin="16,8"
|
||||
materialDesign:HintAssist.Hint="{Binding SelectedPartitionFormat, Converter={x:Static converters:PartitionFormatToTooltipConverter.Instance}}"
|
||||
materialDesign:HintAssist.IsFloating="True"
|
||||
Text="{Binding PartitionLimit, TargetNullValue=''}"
|
||||
ToolTip="{Binding SelectedPartitionFormat, Converter={x:Static converters:PartitionFormatToTooltipConverter.Instance}}" />
|
||||
|
||||
</Grid>
|
||||
|
||||
<!-- Download media -->
|
||||
<Grid Margin="16,16" ToolTip="Download referenced media content (user avatars, attached files, embedded images, etc)">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DiscordChatExporter.Gui.Views.Dialogs
|
||||
namespace DiscordChatExporter.Gui.Views.Dialogs
|
||||
{
|
||||
public partial class ExportSetupView
|
||||
{
|
||||
@@ -7,4 +7,4 @@
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user