Fix #623: resolve LNK as early as possible

This commit is contained in:
Paddy Xu
2020-05-07 21:27:09 +03:00
parent aeba5bddfe
commit 748d9109b2
2 changed files with 17 additions and 16 deletions
+17 -1
View File
@@ -17,7 +17,9 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
using System.Threading.Tasks;
@@ -99,7 +101,21 @@ namespace QuickLook.NativeMethods
Debug.WriteLine(e);
}
return sb?.ToString() ?? string.Empty;
return ResolveShortcut(sb?.ToString() ?? string.Empty);
}
private static string ResolveShortcut(string path)
{
if (string.IsNullOrEmpty(path)) return path;
if (Path.GetExtension(path).ToLower() != ".lnk") return path;
var link = new ShellLink();
((IPersistFile) link).Load(path, 0);
var sb = new StringBuilder(MaxPath);
((IShellLinkW) link).GetPath(sb, sb.Capacity, out _, 0);
return sb.Length == 0 ? path : sb.ToString();
}
internal enum FocusedWindowType
-15
View File
@@ -125,9 +125,6 @@ namespace QuickLook
var wParam = msg.Substring(0, split);
var lParam = msg.Substring(split + 1, msg.Length - split - 1);
if (!string.IsNullOrEmpty(lParam))
lParam = ResolveShortcut(lParam);
switch (wParam)
{
case PipeMessages.RunAndClose:
@@ -171,17 +168,5 @@ namespace QuickLook
{
return _instance ?? (_instance = new PipeServerManager());
}
public static string ResolveShortcut(string filename)
{
if (Path.GetExtension(filename).ToLower() != ".lnk")
return filename;
var link = new ShellLink();
((IPersistFile) link).Load(filename, 0);
var sb = new StringBuilder(260);
((IShellLinkW) link).GetPath(sb, sb.Capacity, out _, 0);
return sb.ToString();
}
}
}