From d77eac20f3a4a6fe76b0602c05d7b326aea119c9 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Sun, 19 Feb 2023 15:37:54 +0900 Subject: [PATCH 1/2] Catch COMException --- src/Files.App/Shell/ContextMenu.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Files.App/Shell/ContextMenu.cs b/src/Files.App/Shell/ContextMenu.cs index e23e6c005cb6..d5a37aa08659 100644 --- a/src/Files.App/Shell/ContextMenu.cs +++ b/src/Files.App/Shell/ContextMenu.cs @@ -259,7 +259,7 @@ private static void EnumMenuItems( { cMenu2?.HandleMenuMsg((uint)User32.WindowMessage.WM_INITMENUPOPUP, (IntPtr)mii.hSubMenu, new IntPtr(ii)); } - catch (NotImplementedException) + catch (Exception ex) when (ex is COMException || ex is NotImplementedException) { // Only for dynamic/owner drawn? (open with, etc) } From f80925f004fc156a7b5f3e4419cc9f5bf1b0ca13 Mon Sep 17 00:00:00 2001 From: hishitetsu <66369541+hishitetsu@users.noreply.github.com> Date: Sun, 19 Feb 2023 16:25:35 +0900 Subject: [PATCH 2/2] Refactor --- src/Files.App/Shell/ContextMenu.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Files.App/Shell/ContextMenu.cs b/src/Files.App/Shell/ContextMenu.cs index d5a37aa08659..49b0b4f5ca99 100644 --- a/src/Files.App/Shell/ContextMenu.cs +++ b/src/Files.App/Shell/ContextMenu.cs @@ -62,7 +62,7 @@ public async Task InvokeVerb(string? verb) return true; } - catch (Exception ex) when (ex is COMException || ex is UnauthorizedAccessException) + catch (Exception ex) when (ex is COMException or UnauthorizedAccessException) { Debug.WriteLine(ex); } @@ -90,7 +90,7 @@ public async Task InvokeItem(int itemID) Win32API.BringToForeground(currentWindows); } - catch (Exception ex) when (ex is COMException || ex is UnauthorizedAccessException) + catch (Exception ex) when (ex is COMException or UnauthorizedAccessException) { Debug.WriteLine(ex); } @@ -110,7 +110,7 @@ public async Task InvokeItem(int itemID) shellItems.Add(ShellFolderExtensions.GetShellItemFromPathOrPidl(fp)); return GetContextMenuForFiles(shellItems.ToArray(), flags, owningThread, itemFilter); } - catch (Exception ex) when (ex is ArgumentException || ex is FileNotFoundException) + catch (Exception ex) when (ex is ArgumentException or FileNotFoundException) { // Return empty context menu return null; @@ -168,7 +168,7 @@ public async Task InvokeItem(int itemID) return contextMenu; } - catch (Exception ex) when (ex is ArgumentException || ex is FileNotFoundException) + catch (Exception ex) when (ex is ArgumentException or FileNotFoundException) { // Return empty context menu return null; @@ -259,7 +259,7 @@ private static void EnumMenuItems( { cMenu2?.HandleMenuMsg((uint)User32.WindowMessage.WM_INITMENUPOPUP, (IntPtr)mii.hSubMenu, new IntPtr(ii)); } - catch (Exception ex) when (ex is COMException || ex is NotImplementedException) + catch (Exception ex) when (ex is COMException or NotImplementedException) { // Only for dynamic/owner drawn? (open with, etc) } @@ -297,7 +297,7 @@ private static void EnumMenuItems( return commandString.ToString(); } - catch (Exception ex) when (ex is InvalidCastException || ex is ArgumentException) + catch (Exception ex) when (ex is InvalidCastException or ArgumentException) { // TODO: Investigate this... Debug.WriteLine(ex); @@ -305,7 +305,7 @@ private static void EnumMenuItems( return null; } - catch (Exception ex) when (ex is COMException || ex is NotImplementedException) + catch (Exception ex) when (ex is COMException or NotImplementedException) { // Not every item has an associated verb return null;