-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.cs
More file actions
53 lines (46 loc) · 1.37 KB
/
Copy pathConfig.cs
File metadata and controls
53 lines (46 loc) · 1.37 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
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Windows.Forms;
namespace StealthNotes
{
public class Config
{
private string configFilePath;
private static string configFileName = "config.json";
public HashSet<string> DevicesToMute { get; set; }
public int MuteIntervalMs { get; set; }
public bool IgnoreModifierKeys { get; set; }
public bool StartMinimized { get; set; }
//public int RefreshDevicesIntervalMs { get; internal set; }
public Config()
{
configFilePath = Path.Combine(Application.LocalUserAppDataPath, configFileName);
}
public Config Load()
{
if (!File.Exists(configFilePath))
{
DevicesToMute = new HashSet<string>();
MuteIntervalMs = 20;
Save();
}
else
{
var json = File.ReadAllText(configFilePath);
var config = JsonSerializer.Deserialize<Config>(json);
DevicesToMute = config.DevicesToMute;
MuteIntervalMs = (config.MuteIntervalMs < 1 || config.MuteIntervalMs > 1000) ? 200 : config.MuteIntervalMs;
IgnoreModifierKeys = config.IgnoreModifierKeys;
StartMinimized = config.StartMinimized;
}
return this;
}
public void Save()
{
Directory.CreateDirectory(Application.LocalUserAppDataPath);
var json = JsonSerializer.Serialize(this, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(configFilePath, json);
}
}
}