Skip to content

Portable Tool for an Ideal Windows Setup

-added method - GetSubKeyNames for registryHelp

Greedeks526593a63459
diff --git a/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs b/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs
index 52b51cfc..73078e7e 100644
--- a/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs
+++ b/.Source/GTweak/Utilities/Helpers/RegistryHelp.cs
@@ -1,6 +1,7 @@
using GTweak.Utilities.Control;
using Microsoft.Win32;
using System;
+using System.Collections.Generic;
using System.Threading.Tasks;
namespace GTweak.Utilities.Helpers
@@ -127,15 +128,20 @@ namespace GTweak.Utilities.Helpers
}
internal static T GetValue<T>(in string subKey, in string valueName, in T defaultValue)
+ {
+ try { return (T)Convert.ChangeType(Registry.GetValue(subKey, valueName, defaultValue), typeof(T)); }
+ catch { return defaultValue; }
+ }
+
+ internal static HashSet<string> GetSubKeyNames(RegistryKey baseKey, string subKeyPath)
{
try
{
- return (T)Convert.ChangeType(Registry.GetValue(subKey, valueName, defaultValue), typeof(T));
- }
- catch
- {
- return defaultValue;
+ using RegistryKey key = baseKey.OpenSubKey(subKeyPath);
+ return key != null ? new HashSet<string>(key.GetSubKeyNames(), StringComparer.OrdinalIgnoreCase): new HashSet<string>();
}
+ catch { return new HashSet<string>(); }
}
+
}
}
diff --git a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
index 43fa51c4..3b7a62c1 100644
--- a/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
+++ b/.Source/GTweak/Utilities/Tweaks/UninstallingPakages.cs
@@ -12,7 +12,7 @@ namespace GTweak.Utilities.Tweaks
{
internal sealed class UninstallingPakages : TaskSchedulerManager
{
- internal static HashSet<string> InstalledPackages = new HashSet<string>();
+ internal static HashSet<string> InstalledPackages = RegistryHelp.GetSubKeyNames(Registry.CurrentUser, @"Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages");
internal static bool IsOneDriveInstalled => File.Exists(Environment.ExpandEnvironmentVariables(@"%userprofile%\AppData\Local\Microsoft\OneDrive\OneDrive.exe"));
private static bool isLocalAccount = false;
@@ -79,11 +79,7 @@ namespace GTweak.Utilities.Tweaks
return false;
}
- internal void LoadInstalledPackages()
- {
- using RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages");
- InstalledPackages = key != null ? new HashSet<string>(key.GetSubKeyNames(), StringComparer.OrdinalIgnoreCase) : new HashSet<string>();
- }
+ internal void LoadInstalledPackages() => InstalledPackages = RegistryHelp.GetSubKeyNames(Registry.CurrentUser, @"Software\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\Repository\Packages");
internal static Task DeletingPackage(string packageName, bool removeWebViewFlag = false)
{