From e6b8a0dde2b477e53585a66cbf6469e269408217 Mon Sep 17 00:00:00 2001 From: Vic <10308169+VictoriousRaptor@users.noreply.github.com> Date: Sat, 31 Dec 2022 21:02:27 +0800 Subject: [PATCH] Catch exception in ShellLinkHelper --- .../Programs/ShellLinkHelper.cs | 17 ++++++++++++++--- .../Programs/Win32.cs | 9 --------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs index b93fb23c9..78c66d604 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/ShellLinkHelper.cs @@ -3,6 +3,7 @@ using System.Text; using System.Runtime.InteropServices; using Accessibility; using System.Runtime.InteropServices.ComTypes; +using Flow.Launcher.Plugin.Program.Logger; namespace Flow.Launcher.Plugin.Program.Programs { @@ -119,9 +120,19 @@ namespace Flow.Launcher.Plugin.Program.Programs // To set the app description if (!String.IsNullOrEmpty(target)) { - buffer = new StringBuilder(MAX_PATH); - ((IShellLinkW)link).GetDescription(buffer, MAX_PATH); - description = buffer.ToString(); + try + { + buffer = new StringBuilder(MAX_PATH); + ((IShellLinkW)link).GetDescription(buffer, MAX_PATH); + description = buffer.ToString(); + } + catch (COMException e) + { + // C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception + ProgramLogger.LogException($"|IShellLinkW|retrieveTargetPath|{path}" + + "|Error caused likely due to trying to get the description of the program", + e); + } buffer.Clear(); ((IShellLinkW)link).GetArguments(buffer, MAX_PATH); diff --git a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs index 6b245d2c4..019048295 100644 --- a/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs +++ b/Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs @@ -309,15 +309,6 @@ namespace Flow.Launcher.Plugin.Program.Programs return program; } - catch (COMException e) - { - // C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception - ProgramLogger.LogException($"|Win32|LnkProgram|{path}" + - "|Error caused likely due to trying to get the description of the program", - e); - - return Default; - } catch (FileNotFoundException e) { ProgramLogger.LogException($"|Win32|LnkProgram|{path}" +