-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserSettings.cs
More file actions
64 lines (56 loc) · 1.87 KB
/
UserSettings.cs
File metadata and controls
64 lines (56 loc) · 1.87 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
53
54
55
56
57
58
59
60
61
62
63
64
using System.IO;
using System.Text.Json;
namespace CFRezManager;
public sealed class UserSettings
{
private static readonly JsonSerializerOptions JsonOptions = new()
{
WriteIndented = true
};
public string Language { get; set; } = "zh";
public string LastDirectory { get; set; } = string.Empty;
public string LastRezDirectory { get; set; } = string.Empty;
public string LastPackDirectory { get; set; } = string.Empty;
public string LastOutputDirectory { get; set; } = string.Empty;
public string LastSaveDirectory { get; set; } = string.Empty;
public double ViewSize { get; set; } = 72;
public double AudioPreviewVolume { get; set; } = 0.8;
public string AudioPreviewRepeatMode { get; set; } = "Directory";
public static string SettingsPath => Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"CFRezManager",
"settings.json");
public static UserSettings Load()
{
try
{
if (!File.Exists(SettingsPath))
{
return new UserSettings();
}
string json = File.ReadAllText(SettingsPath);
return JsonSerializer.Deserialize<UserSettings>(json, JsonOptions) ?? new UserSettings();
}
catch
{
return new UserSettings();
}
}
public void Save()
{
try
{
string? directory = Path.GetDirectoryName(SettingsPath);
if (!string.IsNullOrEmpty(directory))
{
Directory.CreateDirectory(directory);
}
string json = JsonSerializer.Serialize(this, JsonOptions);
File.WriteAllText(SettingsPath, json);
}
catch
{
// Settings are a convenience only; the app should keep working if they cannot be written.
}
}
}