mirror of
https://github.com/QL-Win/QuickLook.git
synced 2026-05-17 01:01:29 +08:00
Fix #623: resolve LNK as early as possible
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user