Skip to content

Commit

Permalink
Crashfix (#8)
Browse files Browse the repository at this point in the history
* Add CreateSubKey

* Fix Typo

* Change Error Messages

* Small Changes To Logic

* Version Bump
  • Loading branch information
xM4ddy authored May 2, 2024
1 parent dd077c2 commit 04ff6bb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
ResizeMode="NoResize"
Title="OFGB - Version 0.1" Height="260" Width="240" Background="#202020">
Title="OFGB - Version 0.2" Height="260" Width="240" Background="#202020">
<Grid>
<CheckBox x:Name="cb1" Margin="5,0,0,0" Checked="Checked" Unchecked="Unchecked" Content="Disable File Explorer Ads" />
<CheckBox x:Name="cb2" Margin="5,20,0,0" Checked="Checked" Unchecked="Unchecked" Content="Disable Lock Screen Tips And Ads" />
Expand Down
81 changes: 49 additions & 32 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ namespace OFGB
/// </summary>
public partial class MainWindow : Window
{
const string cur_ver = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\";

[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);
internal static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize);

public MainWindow()
{
Expand All @@ -30,47 +32,48 @@ public MainWindow()

private void InitializeKeys()
{
// https://www.elevenforum.com/t/disable-ads-in-windows-11.8004/
// Sync provider notifications in File Explorer
bool key1 = CreateKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "ShowSyncProviderNotifications");
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("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "RotatingLockScreenOverlayEnabled");
bool key3 = CreateKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-338387Enabled");
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("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-338393Enabled");
bool key5 = CreateKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-353694Enabled");
bool key6 = CreateKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-353696Enabled");
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("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-338389Enabled");
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("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UserProfileEngagement", "ScoobeSystemSettingEnabled");
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("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-310093Enabled");
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("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AdvertisingInfo", "Enabled");
bool key10 = CreateKey(cur_ver + "AdvertisingInfo", "Enabled");
cb7.IsChecked = !key10;

// Tailored experiences
bool key11 = CreateKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Privacy", "TailoredExperiencesWithDiagnosticDataEnabled");
bool key11 = CreateKey(cur_ver + "Privacy", "TailoredExperiencesWithDiagnosticDataEnabled");
cb8.IsChecked = !key11;

// "Show recommendations for tips, shortcuts, new apps, and more" on Start
bool key12 = CreateKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "Start_IrisRecommendations");
bool key12 = CreateKey(cur_ver + "Explorer\\Advanced", "Start_IrisRecommendations");
cb9.IsChecked = !key12;
}

private bool CreateKey(string loc, string key)
private static bool CreateKey(string loc, string key)
{
if (Registry.CurrentUser.OpenSubKey(loc, true) is not null)
{
Expand All @@ -79,6 +82,7 @@ private bool CreateKey(string loc, string key)
if (keyRef is not null && keyRef.GetValue(key) is null)
{
keyRef.SetValue(key, 0);
keyRef.Close();
return false;
}
else if (keyRef is not null)
Expand All @@ -87,63 +91,76 @@ private bool CreateKey(string loc, string key)
}
else
{
throw new InvalidOperationException("Null KeyRef");
MessageBox.Show("Null KeyRef Used", "Fatal Error 1", MessageBoxButton.OK, MessageBoxImage.Error);
throw new InvalidOperationException("Null KeyRef Used While Creating Key");
}
}
else
{
throw new InvalidOperationException("Error Initializing While Creating Key");
RegistryKey? keyRef = Registry.CurrentUser.CreateSubKey(loc);

if (keyRef is not null)
{
keyRef.SetValue(key, 0);
keyRef.Close();
return false;
}
else
{
MessageBox.Show("Null KeyRef Used", "Fatal Error 2", MessageBoxButton.OK, MessageBoxImage.Error);
throw new InvalidOperationException("Null KeyRef Used While Creating Key");
}
}
}

private bool toggleOptions(string name, bool enable)
private static bool ToggleOptions(string name, bool enable)
{
int value = !enable ? unchecked((int)0x00000001u) : unchecked((int)0x00000000u);
int value = Convert.ToInt32(!enable);

switch (name)
{
case "cb1":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "ShowSyncProviderNotifications", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Explorer\\Advanced\\", "ShowSyncProviderNotifications", value);
break;
case "cb2":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "RotatingLockScreenOverlayEnabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-338387Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "RotatingLockScreenOverlayEnabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-338387Enabled", value);
break;
case "cb3":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-338393Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-353694Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-353696Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-338393Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-353694Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-353696Enabled", value);
break;
case "cb4":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-338389Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-338389Enabled", value);
break;
case "cb5":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\UserProfileEngagement", "ScoobeSystemSettingEnabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "UserProfileEngagement", "ScoobeSystemSettingEnabled", value);
break;
case "cb6":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ContentDeliveryManager", "SubscribedContent-310093Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "ContentDeliveryManager", "SubscribedContent-310093Enabled", value);
break;
case "cb7":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\AdvertisingInfo", "Enabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "AdvertisingInfo", "Enabled", value);
break;
case "cb8":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Privacy", "TailoredExperiencesWithDiagnosticDataEnabled", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Privacy", "TailoredExperiencesWithDiagnosticDataEnabled", value);
break;
case "cb9":
Registry.SetValue("HKEY_CURRENT_USER\\" + "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced", "Start_IrisRecommendations", value);
Registry.SetValue("HKEY_CURRENT_USER\\" + cur_ver + "Explorer\\Advanced", "Start_IrisRecommendations", value);
break;
}
return true;
}

private void Checked(object sender, RoutedEventArgs e)
{
toggleOptions(((CheckBox)sender).Name, true);
ToggleOptions(((CheckBox)sender).Name, true);
}

private void Unchecked(object sender, RoutedEventArgs e)
{
toggleOptions(((CheckBox)sender).Name, false);
ToggleOptions(((CheckBox)sender).Name, false);
}
}
}

0 comments on commit 04ff6bb

Please sign in to comment.