Files
AmiReel/Services/AppSettingsStore.cs
T
2026-08-11 10:43:27 +02:00

41 lines
1.3 KiB
C#

using System.IO;
using System.Text.Json;
using AmigaDB.VideoRenderer.Models;
namespace AmigaDB.VideoRenderer.Services;
public static class AppSettingsStore
{
private static readonly JsonSerializerOptions JsonOptions = new() { WriteIndented = true };
public static AppSettings Load()
{
string path = GetSettingsPath();
if (!File.Exists(path))
return AppSettings.Default(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
try
{
string json = File.ReadAllText(path);
return JsonSerializer.Deserialize<AppSettings>(json, JsonOptions)
?? AppSettings.Default(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
}
catch
{
return AppSettings.Default(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
}
}
public static void Save(AppSettings settings)
{
string path = GetSettingsPath();
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
string json = JsonSerializer.Serialize(settings, JsonOptions);
File.WriteAllText(path, json);
}
private static string GetSettingsPath() => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"AmiReel", "settings.json");
}