-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRegistrySettingsViewModel.cs
93 lines (78 loc) · 3.08 KB
/
RegistrySettingsViewModel.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
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace AdvancedWindowsAppearence
{
public class RegistrySettingsViewModel: INotifyPropertyChanged
{
public ObservableCollection<BoolRegistrySetting> RegistrySettings { get; set; } = new ObservableCollection<BoolRegistrySetting>();
private bool _isEdited;
public event PropertyChangedEventHandler PropertyChanged;
internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public bool IsEdited { get => _isEdited; set
{
_isEdited = value;
NotifyPropertyChanged();
}
}
public void Add(string name, string registrykey, Version winVer)
{
var registryPath = @"Software\Microsoft\Windows\DWM";
AddWithPath(name, registryPath, registrykey, winVer);
}
public void AddWithPath(string name, string registrypath, string registrykey, Version minimalWinVer)
{
if (minimalWinVer.CompareTo(Environment.OSVersion.Version) >= 0)
{
RegistrySettings.Add(new BoolRegistrySetting());
return;
}
BoolRegistrySetting registrySetting = new BoolRegistrySetting(name, registrypath, registrykey);
registrySetting.PropertyChanged += RegistrySetting_PropertyChanged;
RegistrySettings.Add(registrySetting);
}
private void RegistrySetting_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
IsEdited = true;
}
public async Task SaveAll()
{
List<Task> tasks = new List<Task>();
foreach (BoolRegistrySetting registrySetting in RegistrySettings)
{
if (registrySetting == null) continue;
if (!registrySetting.Checked.HasValue) continue;
tasks.Add(Task.Run(() => registrySetting.SaveToRegistry()));
}
await Task.WhenAll(tasks);
}
public string GetSettingsInReg()
{
string output = "";
string prevPath = "";
foreach (var rs in RegistrySettings)
{
if (!rs.IsEnabled)
continue;
string curPath = rs.RegistryPath.Replace(rs.RegistryKey + "\\", "");
if (prevPath != curPath)
{
output += "\n[HKEY_CURRENT_USER\\" + curPath + "]";
prevPath = curPath;
}
if (rs.Checked.HasValue)
output += "\n\"" + rs.RegistryKey + "\"=dword:0000000" + Convert.ToInt32(rs.Checked.Value);
}
output += Environment.NewLine + Environment.NewLine;
return output;
}
}
}