diff --git a/QuickLook.Native.Shell32/QuickLook.Native.Shell32.vcxproj b/QuickLook.Native.Shell32/QuickLook.Native.Shell32.vcxproj index 52e1db8..bccd8ea 100644 --- a/QuickLook.Native.Shell32/QuickLook.Native.Shell32.vcxproj +++ b/QuickLook.Native.Shell32/QuickLook.Native.Shell32.vcxproj @@ -15,7 +15,7 @@ {D31EE321-C2B0-4984-B749-736F7DE509F1} Win32Proj QuickLookShell32Helper - 10.0.15063.0 + 10.0.14393.0 QuickLook.Native.Shell32 diff --git a/QuickLook.Native.Shell32/Shell32.cpp b/QuickLook.Native.Shell32/Shell32.cpp index 3e69893..bce945f 100644 --- a/QuickLook.Native.Shell32/Shell32.cpp +++ b/QuickLook.Native.Shell32/Shell32.cpp @@ -47,17 +47,19 @@ void Shell32::GetCurrentSelectionBuffer(PWCHAR buffer) wcscpy_s(pos - 1, 1, L""); } -void Shell32::SaveSelectedFromExplorer() { +void Shell32::SaveSelectedFromExplorer() +{ CoInitialize(nullptr); CComPtr psw; - HRESULT ret=psw.CoCreateInstance(CLSID_ShellWindows); + HRESULT ret = psw.CoCreateInstance(CLSID_ShellWindows); auto hwndFGW = GetForegroundWindow(); auto fFound = FALSE; - for (int i = 0; !fFound; i++) { + for (int i = 0; !fFound; i++) + { VARIANT vi; V_VT(&vi) = VT_I4; V_I4(&vi) = i; @@ -67,13 +69,16 @@ void Shell32::SaveSelectedFromExplorer() { if (SUCCEEDED(psw->Item(vi, &pdisp))) { CComPtr pwba; - if (SUCCEEDED(pdisp->QueryInterface(IID_IWebBrowserApp, reinterpret_cast(&pwba)))) { + if (SUCCEEDED(pdisp->QueryInterface(IID_IWebBrowserApp, reinterpret_cast(&pwba)))) + { HWND hwndWBA; - if (SUCCEEDED(pwba->get_HWND(reinterpret_cast(&hwndWBA))) && hwndWBA == hwndFGW) { + if (SUCCEEDED(pwba->get_HWND(reinterpret_cast(&hwndWBA))) && hwndWBA == hwndFGW) + { fFound = TRUE; CComPtr ppdisp; - if (SUCCEEDED(pwba->get_Document(&ppdisp))) { + if (SUCCEEDED(pwba->get_Document(&ppdisp))) + { CComPtr pshvd; if (SUCCEEDED(ppdisp->QueryInterface(IID_IShellFolderViewDual2, reinterpret_cast(&pshvd)))) { @@ -120,7 +125,7 @@ CComQIPtr Shell32::AttachDesktopShellWindow() if (SUCCEEDED(psw.CoCreateInstance(CLSID_ShellWindows))) { - VARIANT pvarLoc = { VT_EMPTY }; + VARIANT pvarLoc = {VT_EMPTY}; long phwnd; psw->FindWindowSW(&pvarLoc, &pvarLoc, SWC_DESKTOP, &phwnd, SWFO_NEEDDISPATCH, reinterpret_cast(&pdispOut)); } @@ -135,10 +140,10 @@ void Shell32::SaveSelectedFromDesktop() return; CComQIPtr psp(pWebBrowser2); - CComPtr psb; - CComPtr psv; - CComPtr pfv; - CComPtr ppf2; + CComPtr psb; + CComPtr psv; + CComPtr pfv; + CComPtr ppf2; if (!psp) return; @@ -164,7 +169,8 @@ void Shell32::SaveSelectedFromDesktop() } } -void Shell32::vectorFromDataObject(CComPtr dao) { +void Shell32::vectorFromDataObject(CComPtr dao) +{ FORMATETC formatetc; STGMEDIUM medium; diff --git a/QuickLook.Native.Shell32/Shell32.h b/QuickLook.Native.Shell32/Shell32.h index a278016..bfd5df2 100644 --- a/QuickLook.Native.Shell32/Shell32.h +++ b/QuickLook.Native.Shell32/Shell32.h @@ -26,4 +26,3 @@ private: static CComQIPtr AttachDesktopShellWindow(); static void vectorFromDataObject(CComPtr dao); }; - diff --git a/QuickLook.Native.Shell32/dllmain.cpp b/QuickLook.Native.Shell32/dllmain.cpp index 78d8d49..f8373b0 100644 --- a/QuickLook.Native.Shell32/dllmain.cpp +++ b/QuickLook.Native.Shell32/dllmain.cpp @@ -2,7 +2,7 @@ #include "stdafx.h" #include "Shell32.h" -BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) +BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { switch (ul_reason_for_call) { @@ -15,4 +15,3 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReser } return TRUE; } - diff --git a/QuickLook.Native.Shell32/stdafx.h b/QuickLook.Native.Shell32/stdafx.h index d32e163..2e9e202 100644 --- a/QuickLook.Native.Shell32/stdafx.h +++ b/QuickLook.Native.Shell32/stdafx.h @@ -12,7 +12,6 @@ #include - // TODO: reference additional headers your program requires here #include #include diff --git a/QuickLook.Plugin.PDFViewer/Class1.cs b/QuickLook.Plugin.PDFViewer/Class1.cs index 0223c6e..134efe6 100644 --- a/QuickLook.Plugin.PDFViewer/Class1.cs +++ b/QuickLook.Plugin.PDFViewer/Class1.cs @@ -1,52 +1,40 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; +using System.Linq; using System.Text; -using System.Threading.Tasks; using System.Windows; using System.Windows.Media; -using System.Windows.Threading; using MoonPdfLib; +using QuickLook.ExtensionMethods; namespace QuickLook.Plugin.PDFViewer { - public class Class1:IViewer + public class Class1 : IViewer { - public bool CanView(string path, byte[] sample) + public PluginType Type => PluginType.ByExtension | PluginType.ByContent; + + public string[] SupportExtensions => new[] {".pdf"}; + + public bool CheckSupportByContent(byte[] sample) { - if (String.IsNullOrEmpty(path)) - return false; - - if (Path.GetExtension(path).ToLower() == ".pdf") - return true; - - if (Encoding.ASCII.GetString(sample.Take(4).ToArray()) == "%PDF") - return true; - - return false; + return Encoding.ASCII.GetString(sample.Take(4).ToArray()) == "%PDF"; } public void View(string path, ViewContentContainer container) { - MoonPdfPanel pdfPanel = new MoonPdfPanel + var pdfPanel = new MoonPdfPanel { ViewType = ViewType.SinglePage, PageRowDisplay = PageRowDisplayType.ContinuousPageRows, - PageMargin = new System.Windows.Thickness(0, 2, 4, 2), + PageMargin = new Thickness(0, 2, 4, 2), Background = new SolidColorBrush(Colors.LightGray) }; - container.SetContent(pdfPanel); - Task.Delay(200).ContinueWith(t => container.Dispatcher.Invoke(() => pdfPanel.OpenFile(path))); - - Task.Delay(400).ContinueWith(t => container.Dispatcher.Invoke(() => pdfPanel.ZoomToWidth())); + container.Dispatcher.Delay(100, o => pdfPanel.OpenFile(path)); + //container.Dispatcher.Delay(200, o => pdfPanel.ZoomToWidth()); } public void Close() { - return; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin.PDFViewer/Properties/AssemblyInfo.cs b/QuickLook.Plugin.PDFViewer/Properties/AssemblyInfo.cs index c979bc0..2c01534 100644 --- a/QuickLook.Plugin.PDFViewer/Properties/AssemblyInfo.cs +++ b/QuickLook.Plugin.PDFViewer/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -33,4 +32,4 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PDFViewer.csproj b/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PDFViewer.csproj index c8d6d66..7e3b1eb 100644 --- a/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PDFViewer.csproj +++ b/QuickLook.Plugin.PDFViewer/QuickLook.Plugin.PDFViewer.csproj @@ -20,6 +20,7 @@ DEBUG;TRACE prompt 4 + x86 pdbonly diff --git a/QuickLook.Plugin.PDFViewer/packages.config b/QuickLook.Plugin.PDFViewer/packages.config index 2bc521b..a24d94b 100644 --- a/QuickLook.Plugin.PDFViewer/packages.config +++ b/QuickLook.Plugin.PDFViewer/packages.config @@ -1,4 +1,5 @@  + \ No newline at end of file diff --git a/QuickLook.sln b/QuickLook.sln index 3de82d4..f0a5e6a 100644 --- a/QuickLook.sln +++ b/QuickLook.sln @@ -14,46 +14,20 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.PDFViewer" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|Any CPU = Release|Any CPU - Release|x64 = Release|x64 Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Debug|x64.ActiveCfg = Debug|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Debug|x64.Build.0 = Debug|Any CPU {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Debug|x86.ActiveCfg = Debug|Any CPU {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Debug|x86.Build.0 = Debug|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Release|Any CPU.Build.0 = Release|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Release|x64.ActiveCfg = Release|Any CPU - {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Release|x64.Build.0 = Release|Any CPU {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Release|x86.ActiveCfg = Release|Any CPU {8B4A9CE5-67B5-4A94-81CB-3771F688FDEB}.Release|x86.Build.0 = Release|Any CPU - {D31EE321-C2B0-4984-B749-736F7DE509F1}.Debug|Any CPU.ActiveCfg = Debug|Win32 - {D31EE321-C2B0-4984-B749-736F7DE509F1}.Debug|Any CPU.Build.0 = Debug|Win32 - {D31EE321-C2B0-4984-B749-736F7DE509F1}.Debug|x64.ActiveCfg = Debug|Win32 {D31EE321-C2B0-4984-B749-736F7DE509F1}.Debug|x86.ActiveCfg = Debug|Win32 {D31EE321-C2B0-4984-B749-736F7DE509F1}.Debug|x86.Build.0 = Debug|Win32 - {D31EE321-C2B0-4984-B749-736F7DE509F1}.Release|Any CPU.ActiveCfg = Release|Win32 - {D31EE321-C2B0-4984-B749-736F7DE509F1}.Release|Any CPU.Build.0 = Release|Win32 - {D31EE321-C2B0-4984-B749-736F7DE509F1}.Release|x64.ActiveCfg = Release|Win32 {D31EE321-C2B0-4984-B749-736F7DE509F1}.Release|x86.ActiveCfg = Release|Win32 {D31EE321-C2B0-4984-B749-736F7DE509F1}.Release|x86.Build.0 = Release|Win32 - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Debug|x64.ActiveCfg = Debug|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Debug|x64.Build.0 = Debug|Any CPU {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Debug|x86.ActiveCfg = Debug|Any CPU {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Debug|x86.Build.0 = Debug|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Release|Any CPU.Build.0 = Release|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Release|x64.ActiveCfg = Release|Any CPU - {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Release|x64.Build.0 = Release|Any CPU {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Release|x86.ActiveCfg = Release|Any CPU {A82AC69C-EDF5-4F0D-8CBD-8E5E3C06E64D}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection diff --git a/QuickLook/App.config b/QuickLook/App.config index 88fa402..51fffc7 100644 --- a/QuickLook/App.config +++ b/QuickLook/App.config @@ -1,6 +1,7 @@ - + + - - - + + + \ No newline at end of file diff --git a/QuickLook/App.xaml b/QuickLook/App.xaml index 8f0f19e..025d877 100644 --- a/QuickLook/App.xaml +++ b/QuickLook/App.xaml @@ -2,8 +2,9 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:QuickLook" - Startup="Application_Startup"> + Startup="Application_Startup" + ShutdownMode="OnExplicitShutdown"> - + - + \ No newline at end of file diff --git a/QuickLook/App.xaml.cs b/QuickLook/App.xaml.cs index 7708ba2..67bbd73 100644 --- a/QuickLook/App.xaml.cs +++ b/QuickLook/App.xaml.cs @@ -1,19 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.IO; -using System.Linq; +using System.IO; using System.Reflection; -using System.Threading.Tasks; using System.Windows; -using QuickLook.Plugin; -using QuickLook.Utilities; namespace QuickLook { /// - /// Interaction logic for App.xaml + /// Interaction logic for App.xaml /// public partial class App : Application { @@ -26,4 +18,4 @@ namespace QuickLook BackgroundListener.GetInstance(); } } -} +} \ No newline at end of file diff --git a/QuickLook/BackgroundListener.cs b/QuickLook/BackgroundListener.cs index e1eb04a..44f3147 100644 --- a/QuickLook/BackgroundListener.cs +++ b/QuickLook/BackgroundListener.cs @@ -1,5 +1,6 @@ -using System.Text; -using System.Threading; +using System; +using System.Text; +using System.Threading.Tasks; using System.Windows.Forms; using QuickLook.Utilities; @@ -18,16 +19,20 @@ namespace QuickLook private void HotkeyEventHandler(object sender, KeyEventArgs e) { - string[] paths; + var paths = new string[0]; // communicate with COM in a separate thread - var tCom = new Thread(() => paths = GetCurrentSelection()); + Task.Run(() => paths = GetCurrentSelection()).Wait(); - tCom.Start(); - tCom.Join(); + var ddd = PathToPluginMatcher.FindMatch(paths); var mw = new MainWindow(); + + ddd.View(paths[0], mw.ViewContentContainer); + mw.Show(); + + mw.ShowFinishLoadingAnimation(TimeSpan.FromMilliseconds(200)); } private void InstallHook(KeyEventHandler handler) diff --git a/QuickLook/ExtensionMethods/DispatcherExtensions.cs b/QuickLook/ExtensionMethods/DispatcherExtensions.cs index 0b990bf..6c5245d 100644 --- a/QuickLook/ExtensionMethods/DispatcherExtensions.cs +++ b/QuickLook/ExtensionMethods/DispatcherExtensions.cs @@ -4,7 +4,7 @@ using System.Windows.Threading; namespace QuickLook.ExtensionMethods { - internal static class DispatcherExtensions + public static class DispatcherExtensions { public static void Delay(this Dispatcher disp, int delayMs, Action action, object parm = null) diff --git a/QuickLook/MainWindow.xaml b/QuickLook/MainWindow.xaml index 0f774de..566be3a 100644 --- a/QuickLook/MainWindow.xaml +++ b/QuickLook/MainWindow.xaml @@ -9,21 +9,61 @@ xmlns:plugin="clr-namespace:QuickLook.Plugin" mc:Ignorable="d" x:Class="QuickLook.MainWindow" x:Name="mainWindow" AllowsTransparency="True" WindowStyle="None" UseLayoutRounding="True" - Topmost="True" d:DesignWidth="624" d:DesignHeight="700" Width="624" Height="700" WindowStartupLocation="CenterScreen" + Topmost="True" d:DesignWidth="624" d:DesignHeight="700" + WindowStartupLocation="CenterScreen" x:ClassModifier="internal"> - + - - + + + + + + + + + + + + + - - + + + + + + + -