Skip to content

Commit

Permalink
Merge pull request #27 from hybras/master
Browse files Browse the repository at this point in the history
Revert usage of Command::new(explorer) to ShellExecuteW
  • Loading branch information
Byron committed Mar 3, 2021
2 parents 831d440 + f113b80 commit b58fa52
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ mod windows {
use std::ffi::OsStr;
use std::io;
use std::os::windows::{ffi::OsStrExt, process::ExitStatusExt};
use std::process::{Command, ExitStatus};
use std::process::ExitStatus;
use std::ptr;

use winapi::ctypes::c_int;
Expand All @@ -107,7 +107,25 @@ mod windows {
}

pub fn that<T: AsRef<OsStr> + Sized>(path: T) -> io::Result<ExitStatus> {
Command::new("explorer").arg(path).spawn()?.wait()
const SW_SHOW: c_int = 5;

let path = convert_path(path.as_ref())?;
let operation: Vec<u16> = OsStr::new("open\0").encode_wide().collect();
let result = unsafe {
ShellExecuteW(
ptr::null_mut(),
operation.as_ptr(),
path.as_ptr(),
ptr::null(),
ptr::null(),
SW_SHOW,
)
};
if result as c_int > 32 {
Ok(ExitStatus::from_raw(0))
} else {
Err(io::Error::last_os_error())
}
}

pub fn with<T: AsRef<OsStr> + Sized>(
Expand Down

0 comments on commit b58fa52

Please sign in to comment.