forked from xM4ddy/OFGB
-
Notifications
You must be signed in to change notification settings - Fork 23
/
MainWindow.xaml.cs
188 lines (161 loc) · 8.86 KB
/
MainWindow.xaml.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using Microsoft.Win32;
using System;
using System.Windows;
using System.Windows.Interop;
using System.Runtime.InteropServices;
using System.Windows.Controls;
using System.Security.Principal;
namespace OFGB
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
[LibraryImport("dwmapi.dll", EntryPoint = "DwmSetWindowAttribute")]
internal static partial int DwmSetWindowAttribute(IntPtr hwnd, int attr, [In] int[] attrValue, int attrSize);
const string cur_ver = "Software\\Microsoft\\Windows\\CurrentVersion\\";
public MainWindow()
{
InitializeComponent();
InitializeKeys();
DwmSetWindowAttribute(new WindowInteropHelper(Application.Current.MainWindow).EnsureHandle(), 33, [2], sizeof(int));
}
private void InitializeKeys()
{
// Sync provider notifications in File Explorer
bool key1 = CreateKey(cur_ver + "Explorer\\Advanced", "ShowSyncProviderNotifications");
cb1.IsChecked = key1;
// Get fun facts, tips, tricks, and more on your lock screen
bool key2 = CreateKey(cur_ver + "ContentDeliveryManager", "RotatingLockScreenOverlayEnabled");
bool key3 = CreateKey(cur_ver + "ContentDeliveryManager", "SubscribedContent-338387Enabled");
cb2.IsChecked = key2 && key3;
// Show suggested content in Settings app
bool key4 = CreateKey(cur_ver + "ContentDeliveryManager", "SubscribedContent-338393Enabled");
bool key5 = CreateKey(cur_ver + "ContentDeliveryManager", "SubscribedContent-353694Enabled");
bool key6 = CreateKey(cur_ver + "ContentDeliveryManager", "SubscribedContent-353696Enabled");
cb3.IsChecked = key4 && key5 && key6;
// Get tips and suggestions when using Windows
bool key7 = CreateKey(cur_ver + "ContentDeliveryManager", "SubscribedContent-338389Enabled");
cb4.IsChecked = key7;
// Suggest ways to get the most out of Windows and finish setting up this device
bool key8 = CreateKey(cur_ver + "UserProfileEngagement", "ScoobeSystemSettingEnabled");
cb5.IsChecked = key8;
// Show me the Windows welcome experience after updates and occasionally when I sign in to highlight what's new and suggested
bool key9 = CreateKey(cur_ver + "ContentDeliveryManager", "SubscribedContent-310093Enabled");
cb6.IsChecked = key9;
// Let apps show me personalized ads by using my advertising ID
bool key10 = CreateKey(cur_ver + "AdvertisingInfo", "Enabled");
cb7.IsChecked = key10;
// Tailored experiences
bool key11 = CreateKey(cur_ver + "Privacy", "TailoredExperiencesWithDiagnosticDataEnabled");
cb8.IsChecked = key11;
// "Show recommendations for tips, shortcuts, new apps, and more" on Start
bool key12 = CreateKey(cur_ver + "Explorer\\Advanced", "Start_IrisRecommendations");
cb9.IsChecked = key12;
// "Turn off notifications from <app>? We noticed you haven't opened these in a while."
bool key13 = CreateKey(cur_ver + "Notifications\\Settings\\Windows.ActionCenter.SmartOptOut", "Enabled");
cb10.IsChecked = key13;
// These Need To Be Run As Administrator
if (IsRunningAsAdministrator())
{
// Show Bing Results in Windows Search (Inverted, 1 == Disabled)
bool key14 = CreateKey("Software\\Policies\\Microsoft\\Windows\\Explorer", "DisableSearchBoxSuggestions");
bool key15 = CreateKey(cur_ver + "Search", "BingSearchEnabled");
cb11.IsChecked = !key14 && key15;
// Disable Edge desktop search widget bar
bool key16 = CreateKey("Software\\Policies\\Microsoft\\Edge", "WebWidgetAllowed");
cb12.IsChecked = key16;
}
else
{
cb11.IsEnabled = false;
cb12.IsEnabled = false;
}
}
private static bool CreateKey(string loc, string key)
{
RegistryKey? keyRef;
int value;
if (Registry.CurrentUser.OpenSubKey(loc, true) is not null)
{
keyRef = Registry.CurrentUser.OpenSubKey(loc, true);
}
else
{
keyRef = Registry.CurrentUser.CreateSubKey(loc);
keyRef.SetValue(key, 0);
}
if (keyRef is null)
{
MessageBox.Show("Failed to create a registry subkey during initialization 初始化期间创建注册表子键失败!", "OFGB: Fatal Error 致命错误", MessageBoxButton.OK, MessageBoxImage.Error);
throw new InvalidOperationException("OFGB: Failed to create subkey during initialization!");
}
value = Convert.ToInt32(keyRef.GetValue(key));
keyRef.Close();
return !(value != 0);
}
private static void ToggleOptions(string checkboxName, bool enable)
{
switch (checkboxName)
{
case "cb1":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Explorer\\Advanced\\", "ShowSyncProviderNotifications", Convert.ToInt32(!enable));
break;
case "cb2":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "RotatingLockScreenOverlayEnabled", Convert.ToInt32(!enable));
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-338387Enabled", Convert.ToInt32(!enable));
break;
case "cb3":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-338393Enabled", Convert.ToInt32(!enable));
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-353694Enabled", Convert.ToInt32(!enable));
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-353696Enabled", Convert.ToInt32(!enable));
break;
case "cb4":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-338389Enabled", Convert.ToInt32(!enable));
break;
case "cb5":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "UserProfileEngagement", "ScoobeSystemSettingEnabled", Convert.ToInt32(!enable));
break;
case "cb6":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-310093Enabled", Convert.ToInt32(!enable));
break;
case "cb7":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "AdvertisingInfo", "Enabled", Convert.ToInt32(!enable));
break;
case "cb8":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Privacy", "TailoredExperiencesWithDiagnosticDataEnabled", Convert.ToInt32(!enable));
break;
case "cb9":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Explorer\\Advanced", "Start_IrisRecommendations", Convert.ToInt32(!enable));
break;
case "cb10":
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Notifications\\Settings\\Windows.ActionCenter.SmartOptOut", "Enabled", Convert.ToInt32(!enable));
break;
case "cb11":
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Policies\\Microsoft\\Windows\\Explorer", "DisableSearchBoxSuggestions", Convert.ToInt32(enable)); // <- Inverted
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Search", "BingSearchEnabled", Convert.ToInt32(!enable));
break;
case "cb12":
Registry.SetValue("HKEY_CURRENT_USER\\Software\\Policies\\Microsoft\\Edge", "WebWidgetAllowed", Convert.ToInt32(!enable));
break;
}
}
public static bool IsRunningAsAdministrator()
{
return new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
}
private void Checked(object sender, RoutedEventArgs e)
{
ToggleOptions(((CheckBox)sender).Name, true);
}
private void Unchecked(object sender, RoutedEventArgs e)
{
ToggleOptions(((CheckBox)sender).Name, false);
}
private void Close(object sender, RoutedEventArgs e)
{
Close();
}
}
}