Delete associated registry value when removing file association

Enhanced the `DeleteFileAssociationViaRegistry` method to also delete the default registry value associated with the file extension if it matches the given application extension. This ensures a more thorough cleanup of file type associations in the registry.

Signed-off-by: Ivandro Jao <Ivandrofly@gmail.com>
This commit is contained in:
Ivandro Jao 2024-10-03 15:44:01 +01:00
parent 4ebe2da219
commit ffcc9343bf

View File

@ -97,13 +97,25 @@ namespace Nikse.SubtitleEdit.Logic
internal static void DeleteFileAssociationViaRegistry(string ext, string appName) internal static void DeleteFileAssociationViaRegistry(string ext, string appName)
{ {
var appExtensionRegKey = $"{appName}{ext}";
using (var registryKey = Registry.CurrentUser.OpenSubKey(@"Software\Classes\", true)) using (var registryKey = Registry.CurrentUser.OpenSubKey(@"Software\Classes\", true))
{ {
if (registryKey?.OpenSubKey($"{appName}{ext}") != null) if (registryKey?.OpenSubKey(appExtensionRegKey) != null)
{ {
registryKey.DeleteSubKeyTree($"{appName}{ext}"); registryKey.DeleteSubKeyTree($"{appName}{ext}");
} }
} }
// (Default)
const string defaultRegValueName = "";
using (var registryKey = Registry.CurrentUser.OpenSubKey("Software\\Classes\\" + ext, true))
{
var registryValue = registryKey?.GetValue(defaultRegValueName);
if (appExtensionRegKey.Equals((string)registryValue, StringComparison.Ordinal))
{
registryKey.DeleteValue(defaultRegValueName);
}
}
} }
internal static void Refresh() internal static void Refresh()
@ -112,4 +124,4 @@ namespace Nikse.SubtitleEdit.Logic
SHChangeNotify(0x08000000, 0x2000, IntPtr.Zero, IntPtr.Zero); SHChangeNotify(0x08000000, 0x2000, IntPtr.Zero, IntPtr.Zero);
} }
} }
} }