-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.cs
More file actions
52 lines (45 loc) · 1.32 KB
/
Settings.cs
File metadata and controls
52 lines (45 loc) · 1.32 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
namespace LegacyConsolePackEditor;
internal sealed class Settings
{
private const string SettingsFileName = "settings.json";
public List<string> RecentPaths { get; set; } = new();
public string? LastTemplateZip { get; set; }
public string ThemeMode { get; set; } = "Dark";
public string AccentName { get; set; } = "Teal";
public static Settings Load()
{
try
{
string path = GetSettingsPath();
if (!File.Exists(path))
return new Settings();
string json = File.ReadAllText(path);
return JsonSerializer.Deserialize<Settings>(json) ?? new Settings();
}
catch
{
return new Settings();
}
}
public void Save()
{
try
{
string path = GetSettingsPath();
string json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(path, json);
}
catch
{
// best effort only
}
}
private static string GetSettingsPath()
{
return Path.Combine(AppContext.BaseDirectory, SettingsFileName);
}
}