-
Notifications
You must be signed in to change notification settings - Fork 2
/
ApplicationSettings.cs
90 lines (82 loc) · 2.53 KB
/
ApplicationSettings.cs
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedWindowsAppearence
{
/// <summary>
/// Class that manages AWA's settings, saves all data to registry key: Computer\HKEY_CURRENT_USER\SOFTWARE\AWA
/// </summary>
public class ApplicationSettings
{
public bool ShowAllUI
{
get => GetShowAllUI();
set => SetShowAllUI(value);
}
public bool UseNativeTitlebar
{
get => GetNativeTitlebar();
set => SetIsNativeTitlebar(value);
}
public bool SaveToRegistry
{
get => GetSaveToRegistry();
set => SetSaveToRegistry(value);
}
public bool GetShowAllUI()
{
int value = (int)GetValue("UIType", 0);
return value != 0;
}
public void SetShowAllUI(bool value)
{
SetValue("UIType", value, RegistryValueKind.DWord);
}
public bool GetNativeTitlebar()
{
int value = (int)GetValue("IsNative", 0);
return value != 0;
}
public void SetIsNativeTitlebar(bool value)
{
SetValue("IsNative", value, RegistryValueKind.DWord);
}
public bool GetSaveToRegistry()
{
int value = (int)GetValue("SaveToRegistry", 1);
return value != 0;
}
public void SetSaveToRegistry(bool value)
{
SetValue("SaveToRegistry", value, RegistryValueKind.DWord);
}
private static void SetValue(string name, object value, RegistryValueKind registryValueKind)
{
var key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\AWA", true);
if (key == null)
{
key.Close();
return;
}
key.SetValue(name, value, registryValueKind);
key.Close();
}
public static object GetValue(string name, object defaultValue) {
var key = Registry.CurrentUser.OpenSubKey("SOFTWARE", true);
key.CreateSubKey("AWA", RegistryKeyPermissionCheck.Default);
key.Close();
var key2 = Registry.CurrentUser.OpenSubKey("SOFTWARE\\AWA", true);
object value = defaultValue;
try
{
value = (int)key2.GetValue(name, 0);
}
catch { }
key2.Close();
return value;
}
}
}