From 1bc193a3b66bdef45de64daa14f5328543a76c2e Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Fri, 2 Jun 2017 22:37:41 +0300 Subject: [PATCH] Fix Wow64 redirection issue --- QuickLook/Helpers/FileHelper.cs | 21 ++++++++++----------- QuickLook/MainWindowTransparent.xaml.cs | 13 ++++++++++--- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/QuickLook/Helpers/FileHelper.cs b/QuickLook/Helpers/FileHelper.cs index cb164d9..9c983bf 100644 --- a/QuickLook/Helpers/FileHelper.cs +++ b/QuickLook/Helpers/FileHelper.cs @@ -11,16 +11,6 @@ namespace QuickLook.Helpers { internal class FileHelper { - private static string GetExecutable(string line) - { - var ret = line.StartsWith("\"") - ? line.Split(new[] {"\" "}, 2, StringSplitOptions.None) - : line.Split(new[] {' '}, 2, StringSplitOptions.None); - - ret[0] = ret[0].StartsWith("\"") ? ret[0].Substring(1) : ret[0]; - return ret[0]; - } - public static bool? GetAssocApplication(string path, out string appFriendlyName) { appFriendlyName = string.Empty; @@ -38,7 +28,7 @@ namespace QuickLook.Helpers { var shell = (IWshShell) new WshShell(); var link = shell.CreateShortcut(path); - path = GetExecutable(link.TargetPath); + path = FixWow64Path(link.TargetPath); } var ext = Path.GetExtension(path).ToLower(); @@ -59,6 +49,15 @@ namespace QuickLook.Helpers return isExe; } + public static string FixWow64Path(string targetPath) + { + if (!File.Exists(targetPath) && !Directory.Exists(targetPath)) + if (targetPath.Contains("Program Files (x86)")) + return targetPath.Replace("Program Files (x86)", "Program Files"); + + return targetPath; + } + [DllImport("shlwapi.dll", CharSet = CharSet.Auto, SetLastError = true)] private static extern uint AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string pszExtra, [Out] StringBuilder sOut, [In] [Out] ref uint nOut); diff --git a/QuickLook/MainWindowTransparent.xaml.cs b/QuickLook/MainWindowTransparent.xaml.cs index cd89c8b..5503f15 100644 --- a/QuickLook/MainWindowTransparent.xaml.cs +++ b/QuickLook/MainWindowTransparent.xaml.cs @@ -50,10 +50,17 @@ namespace QuickLook if (string.IsNullOrEmpty(_path)) return; - Process.Start(new ProcessStartInfo(_path) + try { - WorkingDirectory = Path.GetDirectoryName(_path) - }); + Process.Start(new ProcessStartInfo(_path) + { + WorkingDirectory = Path.GetDirectoryName(_path) + }); + } + catch (Exception e) + { + Debug.WriteLine(e.Message); + } BeginHide(); }