mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-03-31 09:33:03 -06:00
Introduce StartOptions class for settings path resolution
Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
parent
68af1500c7
commit
d9f93c4b6a
|
|
@ -1,6 +1,4 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using Cogwheel;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using DiscordChatExporter.Core.Discord;
|
||||
|
|
@ -12,7 +10,8 @@ using DiscordChatExporter.Gui.Models;
|
|||
namespace DiscordChatExporter.Gui.Services;
|
||||
|
||||
[ObservableObject]
|
||||
public partial class SettingsService() : SettingsBase(GetFilePath(), SerializerContext.Default)
|
||||
public partial class SettingsService()
|
||||
: SettingsBase(StartOptions.Current.SettingsPath, SerializerContext.Default)
|
||||
{
|
||||
[ObservableProperty]
|
||||
public partial bool IsUkraineSupportMessageEnabled { get; set; } = true;
|
||||
|
|
@ -86,17 +85,6 @@ public partial class SettingsService() : SettingsBase(GetFilePath(), SerializerC
|
|||
}
|
||||
}
|
||||
|
||||
public partial class SettingsService
|
||||
{
|
||||
private static string GetFilePath() =>
|
||||
Environment.GetEnvironmentVariable("DISCORDCHATEXPORTER_SETTINGS_PATH") is { } path
|
||||
&& !string.IsNullOrWhiteSpace(path)
|
||||
? Path.EndsInDirectorySeparator(path) || Directory.Exists(path)
|
||||
? Path.Combine(path, "Settings.dat")
|
||||
: path
|
||||
: Path.Combine(AppContext.BaseDirectory, "Settings.dat");
|
||||
}
|
||||
|
||||
public partial class SettingsService
|
||||
{
|
||||
[JsonSerializable(typeof(SettingsService))]
|
||||
|
|
|
|||
24
DiscordChatExporter.Gui/StartOptions.cs
Normal file
24
DiscordChatExporter.Gui/StartOptions.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace DiscordChatExporter.Gui;
|
||||
|
||||
public partial class StartOptions
|
||||
{
|
||||
public required string SettingsPath { get; init; }
|
||||
}
|
||||
|
||||
public partial class StartOptions
|
||||
{
|
||||
public static StartOptions Current { get; } =
|
||||
new()
|
||||
{
|
||||
SettingsPath =
|
||||
Environment.GetEnvironmentVariable("DISCORDCHATEXPORTER_SETTINGS_PATH") is { } path
|
||||
&& !string.IsNullOrWhiteSpace(path)
|
||||
? Path.EndsInDirectorySeparator(path) || Directory.Exists(path)
|
||||
? Path.Combine(path, "Settings.dat")
|
||||
: path
|
||||
: Path.Combine(AppContext.BaseDirectory, "Settings.dat"),
|
||||
};
|
||||
}
|
||||
Loading…
Reference in a new issue