From dfb0caad9ed91fbd814eada76cc37fe5f656c804 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Fri, 23 Jun 2023 02:03:04 +0900 Subject: [PATCH] Fix: Fixed an issue where the right-click menu would sometimes freeze the app (#12686) --- src/Files.App/Shell/ShellNewMenuHelper.cs | 30 ++++++++++++++--------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Files.App/Shell/ShellNewMenuHelper.cs b/src/Files.App/Shell/ShellNewMenuHelper.cs index ec6a2c0fc244..cd5457ddde0b 100644 --- a/src/Files.App/Shell/ShellNewMenuHelper.cs +++ b/src/Files.App/Shell/ShellNewMenuHelper.cs @@ -50,22 +50,28 @@ public static async Task GetNewContextMenuEntryForType(string ext private static async Task GetShellNewRegistryEntries(RegistryKey current, RegistryKey root) { - foreach (var keyName in current.GetSubKeyNames()) + try { - using var key = current.OpenSubKeySafe(keyName); - - if (key is null) - continue; - - if (keyName == "ShellNew") - return await ParseShellNewRegistryEntry(key, root); - else + foreach (var keyName in current.GetSubKeyNames()) { - var ret = await GetShellNewRegistryEntries(key, root); - if (ret is not null) - return ret; + using var key = current.OpenSubKeySafe(keyName); + + if (key is null) + continue; + + if (keyName == "ShellNew") + return await ParseShellNewRegistryEntry(key, root); + else + { + var ret = await GetShellNewRegistryEntries(key, root); + if (ret is not null) + return ret; + } } } + catch { + // Ignore exceptions when the registry is inaccessible to avoid freezes + } return null; }