Catch exception in ShellLinkHelper

This commit is contained in:
Vic 2022-12-31 21:02:27 +08:00
parent 207b29f816
commit e6b8a0dde2
2 changed files with 14 additions and 12 deletions

View file

@ -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);

View file

@ -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}" +