DiscordChatExporter/DiscordChatExporter.Gui/Services/SettingsService.cs
Kornelius Rohrschneider 90ed829375
Added existing export search
Previously, an existing export could only be detected if it existed at the current file target path.
However, if the name of the channel, the channel parent or the guild has changed or if the default file name formatting has changed, the existing export's file name would be different, and it could therefore not be detected.
Therefore, the option to explicitly search for the existing export in the target directory has been added.
If it's activated (and there's no existing export at the current file target path), all file names in the target directory will be compared to a regex that matches any file name the channel export (with the same date range) might have had in the past.
If several existing exports have been detected, an error is logged and the channel export is aborted. Otherwise, it continues as before (only additionally moving the existing export files to the to the new file paths if they should be appended).
Whether this new option is activated is currently hardcoded.
The enum FileExistsHandling has been renamed to ExportExistsHandling to clarify that the setting applies to existing exports in general.

If file names of a directory are needed, they are collected lazily and stored for future use in other channel exports to avoid unnecessary I/O operations.
2025-10-30 00:04:37 +01:00

93 lines
2.6 KiB
C#

using System;
using System.IO;
using System.Text.Json.Serialization;
using Cogwheel;
using CommunityToolkit.Mvvm.ComponentModel;
using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Exporting;
using DiscordChatExporter.Gui.Framework;
using DiscordChatExporter.Gui.Models;
namespace DiscordChatExporter.Gui.Services;
[ObservableObject]
public partial class SettingsService()
: SettingsBase(
Path.Combine(AppContext.BaseDirectory, "Settings.dat"),
SerializerContext.Default
)
{
[ObservableProperty]
public partial bool IsUkraineSupportMessageEnabled { get; set; } = true;
[ObservableProperty]
public partial ThemeVariant Theme { get; set; }
[ObservableProperty]
public partial bool IsAutoUpdateEnabled { get; set; } = true;
[ObservableProperty]
public partial bool IsTokenPersisted { get; set; } = true;
[ObservableProperty]
public partial RateLimitPreference RateLimitPreference { get; set; } =
RateLimitPreference.RespectAll;
[ObservableProperty]
public partial ThreadInclusionMode ThreadInclusionMode { get; set; }
[ObservableProperty]
public partial ExportExistsHandling ExportExistsHandling { get; set; }
[ObservableProperty]
public partial string? Locale { get; set; }
[ObservableProperty]
public partial bool IsUtcNormalizationEnabled { get; set; }
[ObservableProperty]
public partial int ParallelLimit { get; set; } = 1;
[ObservableProperty]
public partial string? LastToken { get; set; }
[ObservableProperty]
public partial ExportFormat LastExportFormat { get; set; } = ExportFormat.HtmlDark;
[ObservableProperty]
public partial string? LastPartitionLimitValue { get; set; }
[ObservableProperty]
public partial string? LastMessageFilterValue { get; set; }
[ObservableProperty]
public partial bool LastShouldFormatMarkdown { get; set; } = true;
[ObservableProperty]
public partial bool LastShouldDownloadAssets { get; set; }
[ObservableProperty]
public partial bool LastShouldReuseAssets { get; set; }
[ObservableProperty]
public partial string? LastAssetsDirPath { get; set; }
public override void Save()
{
// Clear the token if it's not supposed to be persisted
var lastToken = LastToken;
if (!IsTokenPersisted)
LastToken = null;
base.Save();
LastToken = lastToken;
}
}
public partial class SettingsService
{
[JsonSerializable(typeof(SettingsService))]
private partial class SerializerContext : JsonSerializerContext;
}