mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 07:43:31 -07:00
Added UI options to set the file exists handling
The setting the exporter uses to handle existing export files has been made configurable in both the CLI and the GUI (instead of being hardcoded): - A prev-export option has been added to all CLI export commands, which sets the file exists handling for the respective command. - A Previous Export option has been added to the GUI settings, which sets the file exists handling that's used for exports.
This commit is contained in:
parent
5251ae0e95
commit
ad33600e70
|
|
@ -114,6 +114,12 @@ public abstract class ExportCommandBase : DiscordCommandBase
|
|||
init => field = value is not null ? Path.GetFullPath(value) : null;
|
||||
}
|
||||
|
||||
[CommandOption(
|
||||
"prev-export",
|
||||
Description = "What the exporter should do if the channel had already been exported."
|
||||
)]
|
||||
public FileExistsHandling FileExistsHandling { get; init; } = FileExistsHandling.Abort;
|
||||
|
||||
[Obsolete("This option doesn't do anything. Kept for backwards compatibility.")]
|
||||
[CommandOption(
|
||||
"dateformat",
|
||||
|
|
@ -265,6 +271,7 @@ public abstract class ExportCommandBase : DiscordCommandBase
|
|||
ExportFormat,
|
||||
After,
|
||||
Before,
|
||||
FileExistsHandling,
|
||||
PartitionLimit,
|
||||
MessageFilter,
|
||||
ShouldFormatMarkdown,
|
||||
|
|
|
|||
|
|
@ -32,10 +32,8 @@ public class ChannelExporter(DiscordClient discord)
|
|||
// TODO: Maybe add a way to search for old files after a username change
|
||||
if (File.Exists(request.OutputFilePath))
|
||||
{
|
||||
// TODO: Add a way for the user to choose the setting
|
||||
var choice = FileExistsHandling.Abort;
|
||||
|
||||
switch (choice)
|
||||
// TODO: Maybe add an "Ask" option in the future
|
||||
switch (request.FileExistsHandling)
|
||||
{
|
||||
case FileExistsHandling.Abort:
|
||||
Console.WriteLine("Channel aborted");
|
||||
|
|
@ -69,7 +67,7 @@ public class ChannelExporter(DiscordClient discord)
|
|||
break;
|
||||
default:
|
||||
throw new InvalidOperationException(
|
||||
$"Unknown FileExistsHandling value '{choice}'."
|
||||
$"Unknown FileExistsHandling value '{request.FileExistsHandling}'."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ public partial class ExportRequest
|
|||
|
||||
public Snowflake? Before { get; }
|
||||
|
||||
public FileExistsHandling FileExistsHandling { get; }
|
||||
|
||||
public Snowflake? LastPriorMessage { get; set; }
|
||||
|
||||
public PartitionLimit PartitionLimit { get; }
|
||||
|
|
@ -56,6 +58,7 @@ public partial class ExportRequest
|
|||
ExportFormat format,
|
||||
Snowflake? after,
|
||||
Snowflake? before,
|
||||
FileExistsHandling fileExistsHandling,
|
||||
PartitionLimit partitionLimit,
|
||||
MessageFilter messageFilter,
|
||||
bool shouldFormatMarkdown,
|
||||
|
|
@ -70,6 +73,7 @@ public partial class ExportRequest
|
|||
Format = format;
|
||||
After = after;
|
||||
Before = before;
|
||||
FileExistsHandling = fileExistsHandling;
|
||||
PartitionLimit = partitionLimit;
|
||||
MessageFilter = messageFilter;
|
||||
ShouldFormatMarkdown = shouldFormatMarkdown;
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ public partial class SettingsService()
|
|||
[ObservableProperty]
|
||||
public partial ThreadInclusionMode ThreadInclusionMode { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial FileExistsHandling FileExistsHandling { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
public partial string? Locale { get; set; }
|
||||
|
||||
|
|
|
|||
|
|
@ -270,6 +270,7 @@ public partial class DashboardViewModel : ViewModelBase
|
|||
dialog.SelectedFormat,
|
||||
dialog.After?.Pipe(timestamp => Snowflake.FromDate(timestamp, true)),
|
||||
dialog.Before?.Pipe(timestamp => Snowflake.FromDate(timestamp)),
|
||||
_settingsService.FileExistsHandling,
|
||||
dialog.PartitionLimit,
|
||||
dialog.MessageFilter,
|
||||
dialog.ShouldFormatMarkdown,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
using DiscordChatExporter.Core.Exporting;
|
||||
using DiscordChatExporter.Core.Utils.Extensions;
|
||||
using DiscordChatExporter.Gui.Framework;
|
||||
using DiscordChatExporter.Gui.Models;
|
||||
|
|
@ -61,6 +62,15 @@ public class SettingsViewModel : DialogViewModelBase
|
|||
set => _settingsService.ThreadInclusionMode = value;
|
||||
}
|
||||
|
||||
public IReadOnlyList<FileExistsHandling> AvailableFileExistHandlingOptions { get; } =
|
||||
Enum.GetValues<FileExistsHandling>();
|
||||
|
||||
public FileExistsHandling FileExistsHandling
|
||||
{
|
||||
get => _settingsService.FileExistsHandling;
|
||||
set => _settingsService.FileExistsHandling = value;
|
||||
}
|
||||
|
||||
// These items have to be non-nullable because Avalonia ComboBox doesn't allow a null value to be selected
|
||||
public IReadOnlyList<string> AvailableLocales { get; } =
|
||||
[
|
||||
|
|
|
|||
|
|
@ -131,6 +131,19 @@
|
|||
Value="{Binding ParallelLimit}" />
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
|
||||
<!-- File Exists Handling -->
|
||||
<DockPanel
|
||||
Margin="16,8"
|
||||
LastChildFill="False"
|
||||
ToolTip.Tip="What the exporter should do if the channel had already been exported">
|
||||
<TextBlock DockPanel.Dock="Left" Text="Previous Export" />
|
||||
<ComboBox
|
||||
Width="150"
|
||||
DockPanel.Dock="Right"
|
||||
ItemsSource="{Binding AvailableFileExistHandlingOptions}"
|
||||
SelectedItem="{Binding FileExistsHandling}" />
|
||||
</DockPanel>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
|
|
|
|||
Loading…
Reference in a new issue