diff --git a/plugins/shell/Cargo.toml b/plugins/shell/Cargo.toml index 6ce62b64..8aad4651 100644 --- a/plugins/shell/Cargo.toml +++ b/plugins/shell/Cargo.toml @@ -46,6 +46,7 @@ features = [ "Win32_UI_Shell_Common", "Win32_UI_WindowsAndMessaging", "Win32_System_Com", + "Win32_System_Registry", ] [target.'cfg(target_os = "ios")'.dependencies] diff --git a/plugins/shell/src/open/linux.rs b/plugins/shell/src/open/linux.rs new file mode 100644 index 00000000..182ec0ec --- /dev/null +++ b/plugins/shell/src/open/linux.rs @@ -0,0 +1,3 @@ +use std::path::Path; + +pub fn show_item_in_directory(file: &Path) -> crate::Result<()> {} diff --git a/plugins/shell/src/open/windows.rs b/plugins/shell/src/open/windows.rs index 131a4e6b..146bbd6f 100644 --- a/plugins/shell/src/open/windows.rs +++ b/plugins/shell/src/open/windows.rs @@ -3,11 +3,14 @@ use std::path::Path; use windows::{ core::{w, HSTRING, PCWSTR}, Win32::{ - Foundation::{ERROR_FILE_NOT_FOUND, HWND}, + Foundation::ERROR_FILE_NOT_FOUND, System::Com::CoInitialize, UI::{ - Shell::{ILCreateFromPathW, ILFree, SHOpenFolderAndSelectItems, ShellExecuteW}, - WindowsAndMessaging::SW_SHOW, + Shell::{ + ILCreateFromPathW, ILFree, SHOpenFolderAndSelectItems, ShellExecuteExW, + SHELLEXECUTEINFOW, + }, + WindowsAndMessaging::SW_SHOWNORMAL, }, }, }; @@ -22,20 +25,27 @@ pub fn show_item_in_directory(file: &Path) -> crate::Result<()> { let dir = HSTRING::from(dir); let dir_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(dir.as_ptr())) }; - let file = HSTRING::from(file); - let file_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(file.as_ptr())) }; + let file_h = HSTRING::from(file); + let file_item = unsafe { ILCreateFromPathW(PCWSTR::from_raw(file_h.as_ptr())) }; unsafe { if let Err(e) = SHOpenFolderAndSelectItems(dir_item, Some(&[file_item]), 0) { if e.code().0 == ERROR_FILE_NOT_FOUND.0 as i32 { - ShellExecuteW( - HWND::default(), - w!("open"), - PCWSTR::from_raw(dir.as_ptr()), - PCWSTR::null(), - PCWSTR::null(), - SW_SHOW, - ); + let is_dir = std::fs::metadata(file).map(|f| f.is_dir()).unwrap_or(false); + let mut info = SHELLEXECUTEINFOW { + cbSize: std::mem::size_of::() as _, + nShow: SW_SHOWNORMAL.0, + lpVerb: if is_dir { + w!("explore") + } else { + PCWSTR::null() + }, + lpClass: if is_dir { w!("folder") } else { PCWSTR::null() }, + lpFile: PCWSTR(file_h.as_ptr()), + ..std::mem::zeroed() + }; + + ShellExecuteExW(&mut info)?; } } }