diff --git a/src/lib.rs b/src/lib.rs index 0a0b2ec..d0647f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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; @@ -107,7 +107,25 @@ mod windows { } pub fn that + Sized>(path: T) -> io::Result { - Command::new("explorer").arg(path).spawn()?.wait() + const SW_SHOW: c_int = 5; + + let path = convert_path(path.as_ref())?; + let operation: Vec = 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 + Sized>(