From 5428b6140c2efa0a122079bed443005080de3d51 Mon Sep 17 00:00:00 2001 From: SlimeNull Date: Wed, 27 Mar 2024 20:56:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=20Everything=20?= =?UTF-8?q?=E6=89=93=E5=BC=80=E5=B1=9E=E6=80=A7=E7=AA=97=E5=8F=A3,=20?= =?UTF-8?q?=E6=88=96=E8=80=85=E6=89=93=E5=BC=80=E6=89=80=E5=9C=A8=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CurvaLauncher.Common/Apis/ICommonApi.cs | 3 ++ src/CurvaLauncher/Apis/CommonApi.cs | 42 ++++++++++++++++++- .../EverythingQueryResult.cs | 4 +- src/TestConsole/Program.cs | 42 +++++++++++++++++++ 4 files changed, 88 insertions(+), 3 deletions(-) diff --git a/src/CurvaLauncher.Common/Apis/ICommonApi.cs b/src/CurvaLauncher.Common/Apis/ICommonApi.cs index 49e3b03..774bb13 100644 --- a/src/CurvaLauncher.Common/Apis/ICommonApi.cs +++ b/src/CurvaLauncher.Common/Apis/ICommonApi.cs @@ -7,6 +7,9 @@ public interface ICommonApi public void Open(string name); public void OpenExecutable(string file); + public void ShowInFileExplorer(string path); + public void ShowPropertiesWindow(string path); + public void ShowText(string text, TextOptions options); public void ShowImage(ImageSource image, ImageOptions options); } diff --git a/src/CurvaLauncher/Apis/CommonApi.cs b/src/CurvaLauncher/Apis/CommonApi.cs index 116a6b6..5589dbb 100644 --- a/src/CurvaLauncher/Apis/CommonApi.cs +++ b/src/CurvaLauncher/Apis/CommonApi.cs @@ -1,4 +1,6 @@ -using System.Diagnostics; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; using System.Windows.Media; using CurvaLauncher.Views.Dialogs; @@ -6,6 +8,21 @@ namespace CurvaLauncher.Apis { public class CommonApi : ICommonApi { + [DllImport("shell32.dll", ExactSpelling = true)] + static extern void ILFree(IntPtr pidlList); + + [DllImport("shell32.dll", CharSet = CharSet.Unicode)] + static extern IntPtr ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath); + + [DllImport("shell32.dll")] + static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cidl, IntPtr[]? apidl, uint dwFlags); + + [DllImport("shell32.dll", CharSet = CharSet.Unicode)] + public static extern bool SHObjectProperties(IntPtr hwnd, uint shopObjectType, string pszObjectName, string? pszPropertyPage); + + [DllImport("shell32.dll", CharSet = CharSet.Unicode)] + public static extern int ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string? lpParameters, string? lpDirectory, int nShowCmd); + private CommonApi() { } public static CommonApi Instance { get; } = new(); @@ -24,6 +41,29 @@ public void OpenExecutable(string file) => Process.Start( UseShellExecute = false }); + public void ShowInFileExplorer(string path) + { + IntPtr pidlList = ILCreateFromPathW(path); + if (pidlList == IntPtr.Zero) + { + throw new ArgumentException("Invalid path"); + } + + try + { + SHOpenFolderAndSelectItems(pidlList, 0, null, 0); + } + finally + { + ILFree(pidlList); + } + } + + public void ShowPropertiesWindow(string path) + { + bool invoked = SHObjectProperties(IntPtr.Zero, 2, path, null); + } + public void ShowImage(ImageSource image, ImageOptions options) { new SimpleImageDialog(image, options) diff --git a/src/Plugins/CurvaLauncher.Plugins.Everything/EverythingQueryResult.cs b/src/Plugins/CurvaLauncher.Plugins.Everything/EverythingQueryResult.cs index f404581..7ef2980 100644 --- a/src/Plugins/CurvaLauncher.Plugins.Everything/EverythingQueryResult.cs +++ b/src/Plugins/CurvaLauncher.Plugins.Everything/EverythingQueryResult.cs @@ -40,11 +40,11 @@ public void Invoke() { if (_plugin.HostContext.IsAltKeyPressed()) { - + _plugin.HostContext.Api.ShowPropertiesWindow(_itemFullPath); } else if (_plugin.HostContext.IsCtrlKeyPressed()) { - + _plugin.HostContext.Api.ShowInFileExplorer(_itemFullPath); } else { diff --git a/src/TestConsole/Program.cs b/src/TestConsole/Program.cs index 3ac84d5..c46c602 100644 --- a/src/TestConsole/Program.cs +++ b/src/TestConsole/Program.cs @@ -3,6 +3,48 @@ using ZXing; using ZXing.Common; using ZXing.QrCode; +using System; +using System.Runtime.InteropServices; + + +[DllImport("shell32.dll", ExactSpelling = true)] +static extern void ILFree(IntPtr pidlList); + +[DllImport("shell32.dll", CharSet = CharSet.Unicode)] +static extern IntPtr ILCreateFromPathW([MarshalAs(UnmanagedType.LPWStr)] string pszPath); + +[DllImport("shell32.dll")] +static extern int SHOpenFolderAndSelectItems(IntPtr pidlList, uint cidl, IntPtr[] apidl, uint dwFlags); + +static void ShowInFileExplorer(string path) +{ + IntPtr pidlList = ILCreateFromPathW(path); + if (pidlList == IntPtr.Zero) + { + throw new ArgumentException("Invalid path"); + } + + try + { + SHOpenFolderAndSelectItems(pidlList, 0, null, 0); + } + finally + { + ILFree(pidlList); + } +} + +string filePath = @"C:\Users"; + +// Example usage +try +{ + ShowInFileExplorer(filePath); +} +catch (Exception ex) +{ + Console.WriteLine($"Error: {ex.Message}"); +} var w = new QRCodeWriter(); var b = w.encode("Fuck you world", BarcodeFormat.QR_CODE, 100, 100);