Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/cross-platform-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,7 @@ jobs:
- name: Run fmt
run: ${{ env.CARGO }} fmt ${{ env.TARGET_FLAGS }} --all -- --check
- name: Run clippy
run: ${{ env.CARGO }} clippy ${{ env.TARGET_FLAGS }}
run: ${{ env.CARGO }} clippy ${{ env.TARGET_FLAGS }} -- -D warnings
- name: Run clippy
run: ${{ env.CARGO }} clippy ${{ env.TARGET_FLAGS }} --all-features -- -D warnings -A clippy::incompatible_msrv

1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ impl IntoResult<io::Result<()>> for io::Result<std::process::ExitStatus> {

trait CommandExt {
fn status_without_output(&mut self) -> io::Result<std::process::ExitStatus>;
#[cfg_attr(feature = "shellexecute-on-windows", allow(dead_code))]
fn spawn_detached(&mut self) -> io::Result<()>;
}

Expand Down
23 changes: 9 additions & 14 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@ pub fn that_detached<T: AsRef<OsStr>>(path: T) -> std::io::Result<()> {
let path = path.as_ref();
let is_dir = std::fs::metadata(path).map(|f| f.is_dir()).unwrap_or(false);

if is_dir {
if shell_open_folder(path).is_ok() {
return Ok(());
}
if is_dir && shell_open_folder(path).is_ok() {
return Ok(());
};

let path = wide(path);
Expand All @@ -69,8 +67,8 @@ pub fn that_detached<T: AsRef<OsStr>>(path: T) -> std::io::Result<()> {

#[cfg(feature = "shellexecute-on-windows")]
fn shell_open_folder(path: &OsStr) -> Result<(), std::io::Error> {
let path = dunce::canonicalize(path)?;
let path = wide(path);
let path = std::path::absolute(path)?;
let path = wide(dunce::simplified(&path));
unsafe { ffi::CoInitialize(std::ptr::null()) };
let folder = unsafe { ffi::ILCreateFromPathW(path.as_ptr()) };
if folder.is_null() {
Expand Down Expand Up @@ -139,14 +137,8 @@ pub unsafe fn SHOpenFolderAndSelectItems(

match ffi::SHOpenFolderAndSelectItems(
pidlfolder,
apidl
.as_deref()
.map_or(0, |slice| slice.len().try_into().unwrap()),
core::mem::transmute(
apidl
.as_deref()
.map_or(core::ptr::null(), |slice| slice.as_ptr()),
),
apidl.map_or(0, |slice| slice.len().try_into().unwrap()),
apidl.map_or(core::ptr::null(), |slice| slice.as_ptr()),
dwflags,
) {
0 => Ok(()),
Expand All @@ -173,6 +165,7 @@ mod ffi {
// Taken from https://docs.rs/windows-sys/latest/windows_sys/
#[cfg_attr(not(target_arch = "x86"), repr(C))]
#[cfg_attr(target_arch = "x86", repr(C, packed(1)))]
#[allow(clippy::upper_case_acronyms)]
pub struct SHELLEXECUTEINFOW {
pub cbSize: u32,
pub fMask: u32,
Expand Down Expand Up @@ -201,13 +194,15 @@ mod ffi {

// Taken from https://microsoft.github.io/windows-docs-rs/doc/windows/
#[repr(C, packed(1))]
#[allow(clippy::upper_case_acronyms)]
pub struct SHITEMID {
pub cb: u16,
pub abID: [u8; 1],
}

// Taken from https://microsoft.github.io/windows-docs-rs/doc/windows/
#[repr(C, packed(1))]
#[allow(clippy::upper_case_acronyms)]
pub struct ITEMIDLIST {
pub mkid: SHITEMID,
}
Expand Down
Loading