Repository navigation
Expand file tree
/
Copy pathConfigManager.cs
More file actions
58 lines (47 loc) · 1.93 KB
/
Copy pathConfigManager.cs
File metadata and controls
58 lines (47 loc) · 1.93 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
using System.Configuration;
using System.Drawing;
namespace VRCDebug
{
public static class ConfigManager
{
public static bool LoadIsNightMode()
{
EnsureConfigValueExists("IsNightMode", "true");
bool.TryParse(ConfigurationManager.AppSettings["IsNightMode"], out bool isNightMode);
return isNightMode;
}
public static void SaveIsNightMode(bool isNightMode)
{
UpdateAppSettings("IsNightMode", isNightMode.ToString());
}
public static Size LoadWindowSize()
{
EnsureConfigValueExists("WindowWidth", "1216");
EnsureConfigValueExists("WindowHeight", "606");
int.TryParse(ConfigurationManager.AppSettings["WindowWidth"], out int width);
int.TryParse(ConfigurationManager.AppSettings["WindowHeight"], out int height);
return new Size(width, height);
}
public static void SaveWindowSize(int width, int height)
{
UpdateAppSettings("WindowWidth", width.ToString());
UpdateAppSettings("WindowHeight", height.ToString());
}
// If a checked value doesn't exist already, create it
private static void EnsureConfigValueExists(string key, string defaultValue)
{
if (ConfigurationManager.AppSettings[key] == null)
UpdateAppSettings(key, defaultValue);
}
private static void UpdateAppSettings(string key, string value)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (config.AppSettings.Settings[key] == null)
config.AppSettings.Settings.Add(key, value);
else
config.AppSettings.Settings[key].Value = value;
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
}
}