-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppSettings.cs
More file actions
47 lines (41 loc) · 1.33 KB
/
AppSettings.cs
File metadata and controls
47 lines (41 loc) · 1.33 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
using System;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;
namespace AudioSwitcher;
public class AppSettings
{
public string DeviceA { get; set; } = "";
public string DeviceB { get; set; } = "";
public uint HotkeyModifiers { get; set; } = HotkeyManager.MOD_CONTROL | HotkeyManager.MOD_ALT;
public uint HotkeyKey { get; set; } = (uint)Keys.S;
public bool StartWithWindows { get; set; } = false;
private static readonly string SettingsDir = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
"AudioSwitcher");
private static readonly string SettingsPath = Path.Combine(SettingsDir, "settings.json");
public static AppSettings Load()
{
try
{
if (File.Exists(SettingsPath))
{
string json = File.ReadAllText(SettingsPath);
return JsonSerializer.Deserialize<AppSettings>(json) ?? new();
}
}
catch { }
return new();
}
public void Save()
{
try
{
Directory.CreateDirectory(SettingsDir);
string json = JsonSerializer.Serialize(this,
new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(SettingsPath, json);
}
catch { }
}
}