Initial AmiReel application
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
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");
|
||||
}
|
||||
Reference in New Issue
Block a user