mirror of
https://github.com/microsoft/PowerToys.git
synced 2024-12-14 19:49:15 +08:00
enhance lnk program exception handling
This commit is contained in:
parent
6b640ea55e
commit
c56e4557f9
@ -61,9 +61,9 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
IStream stream;
|
IStream stream;
|
||||||
const uint noAttribute = 0x80;
|
const uint noAttribute = 0x80;
|
||||||
const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
|
const Stgm exclusiveRead = Stgm.Read | Stgm.ShareExclusive;
|
||||||
var result = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);
|
var hResult = SHCreateStreamOnFileEx(path, exclusiveRead, noAttribute, false, null, out stream);
|
||||||
|
|
||||||
if (result == Hresult.Ok)
|
if (hResult == Hresult.Ok)
|
||||||
{
|
{
|
||||||
var reader = appxFactory.CreateManifestReader(stream);
|
var reader = appxFactory.CreateManifestReader(stream);
|
||||||
var manifestApps = reader.GetApplications();
|
var manifestApps = reader.GetApplications();
|
||||||
@ -81,6 +81,12 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
}
|
}
|
||||||
Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
|
Apps = apps.Where(a => a.AppListEntry != "none").ToArray();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.Error($"SHCreateStreamOnFileEx on path: <{path}> failed, HResult error code: {hResult}. Package location: <{Location}>.");
|
||||||
|
var exception = Marshal.GetExceptionForHR((int)hResult);
|
||||||
|
Log.Exception(exception);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ using System.ComponentModel;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using Shell;
|
using Shell;
|
||||||
@ -139,7 +140,7 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
{
|
{
|
||||||
var link = new ShellLink();
|
var link = new ShellLink();
|
||||||
const uint STGM_READ = 0;
|
const uint STGM_READ = 0;
|
||||||
((IPersistFile)link).Load(path, STGM_READ);
|
((IPersistFile) link).Load(path, STGM_READ);
|
||||||
var hwnd = new _RemotableHandle();
|
var hwnd = new _RemotableHandle();
|
||||||
link.Resolve(ref hwnd, 0);
|
link.Resolve(ref hwnd, 0);
|
||||||
|
|
||||||
@ -150,30 +151,43 @@ namespace Wox.Plugin.Program.Programs
|
|||||||
const uint SLGP_SHORTPATH = 1;
|
const uint SLGP_SHORTPATH = 1;
|
||||||
link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
|
link.GetPath(buffer, buffer.Capacity, ref data, SLGP_SHORTPATH);
|
||||||
var target = buffer.ToString();
|
var target = buffer.ToString();
|
||||||
var extension = Extension(target);
|
if (!string.IsNullOrEmpty(target))
|
||||||
if (!string.IsNullOrEmpty(target) && (extension == ExeExtension))
|
|
||||||
{
|
{
|
||||||
buffer = new StringBuilder(MAX_PATH);
|
var extension = Extension(target);
|
||||||
link.GetDescription(buffer, MAX_PATH);
|
if (extension == ExeExtension && File.Exists(target))
|
||||||
var description = buffer.ToString();
|
|
||||||
if (!string.IsNullOrEmpty(description))
|
|
||||||
{
|
{
|
||||||
program.Description = description;
|
buffer = new StringBuilder(MAX_PATH);
|
||||||
}
|
link.GetDescription(buffer, MAX_PATH);
|
||||||
else
|
var description = buffer.ToString();
|
||||||
{
|
if (!string.IsNullOrEmpty(description))
|
||||||
var info = FileVersionInfo.GetVersionInfo(target);
|
|
||||||
if (!string.IsNullOrEmpty(info.FileDescription))
|
|
||||||
{
|
{
|
||||||
program.Description = info.FileDescription;
|
program.Description = description;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var info = FileVersionInfo.GetVersionInfo(target);
|
||||||
|
if (!string.IsNullOrEmpty(info.FileDescription))
|
||||||
|
{
|
||||||
|
program.Description = info.FileDescription;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (COMException e)
|
||||||
|
{
|
||||||
|
// C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\MiracastView.lnk always cause exception
|
||||||
|
Log.Error($"COMException when parsing shortcut: {path}, HResult: {e.HResult}");
|
||||||
|
Log.Exception(e);
|
||||||
|
program.Valid = false;
|
||||||
|
return program;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error($"Error when parsing shortcut: {path}");
|
Log.Error($"Error when parsing shortcut: {path}");
|
||||||
|
Log.Exception(e);
|
||||||
|
program.Valid = false;
|
||||||
return program;
|
return program;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user