-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsManager.cs
More file actions
35 lines (30 loc) · 1.07 KB
/
Copy pathSettingsManager.cs
File metadata and controls
35 lines (30 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.IO;
using System.Text.Json;
namespace MiniMacro
{
internal static class SettingsManager
{
private static readonly string FilePath = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"MiniMacro", "settings.json");
internal static AppSettings Current { get; private set; } = new AppSettings();
internal static void Reset() => Current = new AppSettings();
internal static void Load()
{
try
{
if (File.Exists(FilePath))
Current = JsonSerializer.Deserialize<AppSettings>(File.ReadAllText(FilePath))
?? new AppSettings();
}
catch { Current = new AppSettings(); }
}
internal static void Save()
{
Directory.CreateDirectory(Path.GetDirectoryName(FilePath)!);
File.WriteAllText(FilePath, JsonSerializer.Serialize(Current,
new JsonSerializerOptions { WriteIndented = true }));
}
}
}