From 19373a28a7fa0b4e18d46920e88855344e496b9d Mon Sep 17 00:00:00 2001 From: ema Date: Tue, 6 May 2025 02:52:31 +0800 Subject: [PATCH] First commit CLSIDViewer #1610 --- .../QuickLook.Native32/HelperMethods.cpp | 2 +- .../CLSIDInfoPanel.xaml | 18 +++++ .../CLSIDInfoPanel.xaml.cs | 44 +++++++++++ .../CLSIDRegister.cs | 40 ++++++++++ .../QuickLook.Plugin.CLSIDViewer/Plugin.cs | 72 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 50 +++++++++++++ .../QuickLook.Plugin.CLSIDViewer.csproj | 74 +++++++++++++++++++ .../Properties/AssemblyInfo.cs | 12 +-- QuickLook.sln | 12 +++ QuickLook/NativeMethods/QuickLook.cs | 5 +- QuickLook/PipeServerManager.cs | 2 +- QuickLook/ViewWindowManager.cs | 7 +- 12 files changed, 325 insertions(+), 13 deletions(-) create mode 100644 QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml create mode 100644 QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml.cs create mode 100644 QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDRegister.cs create mode 100644 QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Plugin.cs create mode 100644 QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Properties/AssemblyInfo.cs create mode 100644 QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/QuickLook.Plugin.CLSIDViewer.csproj diff --git a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp index a1cc028..4b54014 100644 --- a/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp +++ b/QuickLook.Native/QuickLook.Native32/HelperMethods.cpp @@ -68,7 +68,7 @@ void HelperMethods::ObtainFirstItem(CComPtr dao, PWCHAR buffer) } // If CF_HDROP fails, try CFSTR_SHELLIDLIST - // Support Desktop Icon (This PC, Recycle Bin and so on) + // Support Desktop Icons (This PC, Recycle Bin and so on) // https://github.com/QL-Win/QuickLook/issues/1610 static const CLIPFORMAT cfShellIDList = (CLIPFORMAT)RegisterClipboardFormatW(CFSTR_SHELLIDLIST); formatetc.cfFormat = cfShellIDList; diff --git a/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml new file mode 100644 index 0000000..4507520 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml.cs b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml.cs new file mode 100644 index 0000000..f053754 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDInfoPanel.xaml.cs @@ -0,0 +1,44 @@ +// Copyright © 2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Windows; +using System.Windows.Controls; + +namespace QuickLook.Plugin.CLSIDViewer; + +public partial class CLSIDInfoPanel : UserControl +{ + public CLSIDInfoPanel() + { + InitializeComponent(); + } + + public void DisplayInfo(string path) + { + switch (path.ToUpper()) + { + case "::{645FF040-5081-101B-9F08-00AA002F954E}" // Recycle Bin + or "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}": // This PC + break; + + default: + UnsupportedTextBlock.Text = $"Unsupported for {path}"; + UnsupportedTextBlock.Visibility = Visibility.Visible; + break; + } + } +} diff --git a/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDRegister.cs b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDRegister.cs new file mode 100644 index 0000000..5a105b4 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/CLSIDRegister.cs @@ -0,0 +1,40 @@ +// Copyright © 2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using Microsoft.Win32; +using System; +using System.Diagnostics; + +namespace QuickLook.Plugin.CLSIDViewer; + +internal static class CLSIDRegister +{ + public static string GetName(string clsid) + { + try + { + // Such as `Computer\HKEY_CLASSES_ROOT\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}` + string displayName = Registry.GetValue($@"HKEY_CLASSES_ROOT\CLSID\{clsid.Replace(":", string.Empty)}", string.Empty, null)?.ToString(); + return displayName; + } + catch (Exception ex) + { + Debug.WriteLine("Error reading registry: " + ex.Message); + } + return string.Empty; + } +} diff --git a/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Plugin.cs b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Plugin.cs new file mode 100644 index 0000000..498bad8 --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Plugin.cs @@ -0,0 +1,72 @@ +// Copyright © 2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using QuickLook.Common.Plugin; +using System; +using System.Text.RegularExpressions; +using System.Windows; + +namespace QuickLook.Plugin.CLSIDViewer; + +public class Plugin : IViewer +{ + private CLSIDInfoPanel _ip; + private string _path; + + public int Priority => -1; + + public void Init() + { + } + + public bool CanHandle(string path) + { + if (string.IsNullOrWhiteSpace(path)) + return false; + + // Use Regex to check whether a string like "::{645FF040-5081-101B-9F08-00AA002F954E}" + bool isCLSID = path.StartsWith("::") + && Regex.IsMatch(path, @"^::\{[0-9A-Fa-f]{8}-([0-9A-Fa-f]{4}-){3}[0-9A-Fa-f]{12}\}$"); + + return isCLSID; + } + + public void Prepare(string path, ContextObject context) + { + context.PreferredSize = new Size { Width = 520, Height = 192 }; + } + + public void View(string path, ContextObject context) + { + _path = path; + _ip = new CLSIDInfoPanel(); + + _ip.DisplayInfo(_path); + _ip.Tag = context; + + context.ViewerContent = _ip; + context.Title = $"{CLSIDRegister.GetName(path)}"; + context.IsBusy = false; + } + + public void Cleanup() + { + GC.SuppressFinalize(this); + + _ip = null; + } +} diff --git a/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Properties/AssemblyInfo.cs b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..8ce6b9a --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/Properties/AssemblyInfo.cs @@ -0,0 +1,50 @@ +// Copyright © 2025 QL-Win Contributors +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("QuickLook.Plugin.CLSIDViewer")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("pooi.moe")] +[assembly: AssemblyProduct("QuickLook.Plugin.CLSIDViewer")] +[assembly: AssemblyCopyright("Copyright © QL-Win Contributors")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("538fd6ba-2af1-4dda-93a2-6c0a12b00843")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/QuickLook.Plugin.CLSIDViewer.csproj b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/QuickLook.Plugin.CLSIDViewer.csproj new file mode 100644 index 0000000..679617a --- /dev/null +++ b/QuickLook.Plugin/QuickLook.Plugin.CLSIDViewer/QuickLook.Plugin.CLSIDViewer.csproj @@ -0,0 +1,74 @@ + + + + Library + net462 + QuickLook.Plugin.CLSIDViewer + QuickLook.Plugin.CLSIDViewer + 512 + false + true + latest + false + false + false + MinimumRecommendedRules.ruleset + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843} + + + + true + full + false + ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.CLSIDViewer\ + DEBUG;TRACE + prompt + + + + pdbonly + true + ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.CLSIDViewer\ + TRACE + prompt + + + + true + full + ..\..\Build\Debug\QuickLook.Plugin\QuickLook.Plugin.CLSIDViewer\ + DEBUG;TRACE + x86 + prompt + + + + ..\..\Build\Release\QuickLook.Plugin\QuickLook.Plugin.CLSIDViewer\ + TRACE + true + pdbonly + x86 + prompt + + + + + {85FDD6BA-871D-46C8-BD64-F6BB0CB5EA95} + QuickLook.Common + False + + + + + + Properties\GitVersion.cs + + + + + + PreserveNewest + + + + diff --git a/QuickLook.Plugin/QuickLook.Plugin.PEViewer/Properties/AssemblyInfo.cs b/QuickLook.Plugin/QuickLook.Plugin.PEViewer/Properties/AssemblyInfo.cs index 8b33ea1..c1cb309 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.PEViewer/Properties/AssemblyInfo.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.PEViewer/Properties/AssemblyInfo.cs @@ -1,17 +1,17 @@ // Copyright © 2024 ema -// +// // This file is part of QuickLook program. -// +// // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program. If not, see . @@ -26,7 +26,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("pooi.moe")] [assembly: AssemblyProduct("QuickLook.Plugin.PEViewer")] -[assembly: AssemblyCopyright("Copyright © ema 2024")] +[assembly: AssemblyCopyright("Copyright © QL-Win Contributors")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -47,4 +47,4 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] \ No newline at end of file +// [assembly: AssemblyVersion("1.0.*")] diff --git a/QuickLook.sln b/QuickLook.sln index 4a9836e..532c04e 100644 --- a/QuickLook.sln +++ b/QuickLook.sln @@ -51,6 +51,7 @@ Project("{930C7802-8A8C-48F9-8165-68863BCCD9DD}") = "QuickLook.Installer", "Quic {BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA} = {BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA} {8D50A1DA-601C-4C26-9A7E-7D477EA8430A} = {8D50A1DA-601C-4C26-9A7E-7D477EA8430A} {CE40160D-5E3C-4A41-9BDA-C4F414C174EB} = {CE40160D-5E3C-4A41-9BDA-C4F414C174EB} + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843} = {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843} EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QuickLook.Native64", "QuickLook.Native\QuickLook.Native64\QuickLook.Native64.vcxproj", "{794E4DCF-F715-4836-9D30-ABD296586D23}" @@ -77,6 +78,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.PEViewer", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.FontViewer", "QuickLook.Plugin\QuickLook.Plugin.FontViewer\QuickLook.Plugin.FontViewer.csproj", "{CE40160D-5E3C-4A41-9BDA-C4F414C174EB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "QuickLook.Plugin.CLSIDViewer", "QuickLook.Plugin\QuickLook.Plugin.CLSIDViewer\QuickLook.Plugin.CLSIDViewer.csproj", "{538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -223,6 +226,14 @@ Global {CE40160D-5E3C-4A41-9BDA-C4F414C174EB}.Release|Any CPU.Build.0 = Release|Any CPU {CE40160D-5E3C-4A41-9BDA-C4F414C174EB}.Release|x86.ActiveCfg = Release|Any CPU {CE40160D-5E3C-4A41-9BDA-C4F414C174EB}.Release|x86.Build.0 = Release|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Debug|Any CPU.Build.0 = Debug|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Debug|x86.ActiveCfg = Debug|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Debug|x86.Build.0 = Debug|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Release|Any CPU.ActiveCfg = Release|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Release|Any CPU.Build.0 = Release|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Release|x86.ActiveCfg = Release|Any CPU + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -243,6 +254,7 @@ Global {BD58F3FC-7601-47BA-AAA1-D8A9D54A33DA} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} {8D50A1DA-601C-4C26-9A7E-7D477EA8430A} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} {CE40160D-5E3C-4A41-9BDA-C4F414C174EB} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} + {538FD6BA-2AF1-4DDA-93A2-6C0A12B00843} = {06EFDBE0-6408-4B37-BCF2-0CF9EBEA2E93} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {D3761C32-8C5F-498A-892B-3B0882994B62} diff --git a/QuickLook/NativeMethods/QuickLook.cs b/QuickLook/NativeMethods/QuickLook.cs index fcd19ef..9274fe7 100644 --- a/QuickLook/NativeMethods/QuickLook.cs +++ b/QuickLook/NativeMethods/QuickLook.cs @@ -102,10 +102,11 @@ internal static class QuickLook thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); - if (sb.Length > 2 && sb[0].Equals('"') && sb[sb.Length - 1].Equals('"')) + if (sb.Length > 2 && sb[0] == '"' && sb[sb.Length - 1] == '"') { // We got a quoted string which breaks ResolveShortcut - sb = sb.Replace("\"", string.Empty, 0, 1).Replace("\"", string.Empty, sb.Length - 1, 1); + sb.Remove(sb.Length - 1, 1); // remove last " + sb.Remove(0, 1); // remove first " } return ResolveShortcut(sb?.ToString() ?? string.Empty); } diff --git a/QuickLook/PipeServerManager.cs b/QuickLook/PipeServerManager.cs index 9c3dc72..7e556c9 100644 --- a/QuickLook/PipeServerManager.cs +++ b/QuickLook/PipeServerManager.cs @@ -170,6 +170,6 @@ internal class PipeServerManager : IDisposable public static PipeServerManager GetInstance() { - return _instance ?? (_instance = new PipeServerManager()); + return _instance ??= new PipeServerManager(); } } diff --git a/QuickLook/ViewWindowManager.cs b/QuickLook/ViewWindowManager.cs index ac9cb14..fcb7e9a 100644 --- a/QuickLook/ViewWindowManager.cs +++ b/QuickLook/ViewWindowManager.cs @@ -129,7 +129,8 @@ internal class ViewWindowManager : IDisposable return; if (!Directory.Exists(path) && !File.Exists(path)) - return; + if (!path.StartsWith("::")) // CLSID + return; _invokedPath = path; @@ -197,7 +198,7 @@ internal class ViewWindowManager : IDisposable { if (ProcessHelper.IsShuttingDown()) return; - if (!(sender is ViewerWindow w) || w.Pinned) + if (sender is not ViewerWindow w || w.Pinned) return; // Pinned window has already been forgotten StopFocusMonitor(); InitNewViewerWindow(); @@ -206,6 +207,6 @@ internal class ViewWindowManager : IDisposable internal static ViewWindowManager GetInstance() { - return _instance ?? (_instance = new ViewWindowManager()); + return _instance ??= new ViewWindowManager(); } }