-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAeroColorRegistrySetting.cs
145 lines (128 loc) · 4.29 KB
/
AeroColorRegistrySetting.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using AdvancedWindowsAppearence.Converters;
namespace AdvancedWindowsAppearence
{
public class AeroColorRegistrySetting : BoolRegistrySetting, INotifyPropertyChanged
{
private Color? _itemColor;
public Color? ItemColor { get
{
return _itemColor;
}
set
{
_itemColor = value;
_opacity = _itemColor.GetValueOrDefault().A;
NotifyPropertyChanged();
}
}
public string ItemColorValue {
get
{
if(!ItemColor.HasValue)
return null;
return Color_ConvertToRegistryFormat(ItemColor.Value);
}
}
private byte _opacity;
public byte Opacity
{
get
{
return _opacity;
}
set
{
_opacity = value;
ItemColor = Color.FromArgb(value, ItemColor.GetValueOrDefault(Color.Transparent));
NotifyPropertyChanged();
}
}
private bool _edited;
public bool Enabled
{
get { return _edited; }
set
{
_edited = value;
NotifyPropertyChanged();
}
}
public AeroColorRegistrySetting(string name, string registrykey)
{
Name = name;
RegistryKey = registrykey;
RegistryPath = @"Software\Microsoft\Windows\DWM";
ItemColor = GetAeroColorFromRegistry(RegistryKey, false);
Console.WriteLine(ItemColor.Value);
}
public AeroColorRegistrySetting(string name, string registrypath, string registrykey)
{
Name = name;
RegistryKey = registrykey;
if (string.IsNullOrEmpty(registrypath)) RegistryPath = @"Software\Microsoft\Windows\DWM";
else RegistryPath = registrypath;
ItemColor = GetAeroColorFromRegistry(RegistryKey, true);
Console.WriteLine(ItemColor.Value);
}
public Color? GetAeroColorFromRegistry(string registrykey, bool invertRedAndBlue)
{
if (registrykey == null || registrykey == "") return null;
Color color = new Color();
var colorReg = GetValueFromRegistry();
if (colorReg == null)
{
this.Enabled = false;
if(registrykey == "")
return Color.Silver;
else
return Color.DodgerBlue;
}
try
{
color = (Color)(new ColorConverter()).ConvertFromInvariantString(colorReg.ToString());
if (invertRedAndBlue)
{
color = Color.FromArgb(color.A, color.B, color.G, color.R);
}
this.Enabled = true;
}
catch
{
return null;
}
if(registrykey == "ColorizationColor")
{
if(Environment.OSVersion.Version > new Version(10, 0))
color = Color.FromArgb(255, color.R, color.G, color.B);
App.Current.Resources["ThemeColor"] = BrushToColorConverter.MediaColorToBrush(color);
}
return color;
}
public new void SaveToRegistry()
{
if (!ItemColor.HasValue) return;
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(RegistryPath, true);
if (registryKey == null)
{
Registry.CurrentUser.CreateSubKey(RegistryPath);
}
registryKey.SetValue(RegistryKey, Color_ConvertToRegistryFormat(ItemColor.Value), RegistryValueKind.DWord);
registryKey.Close();
return;
}
string Color_ConvertToRegistryFormat(Color color)
{
string colorstring = (color.R | (color.G << 8) | (color.B << 16) | (color.A << 24)).ToString();
return colorstring;
}
}
}