diff --git a/.github/workflows/cross-platform-testing.yml b/.github/workflows/cross-platform-testing.yml index 47757dd..1f1c581 100644 --- a/.github/workflows/cross-platform-testing.yml +++ b/.github/workflows/cross-platform-testing.yml @@ -20,7 +20,7 @@ jobs: RUST_BACKTRACE: 1 strategy: matrix: - build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc] + build: [linux, linux-arm, macos, win-msvc, win-gnu] include: - build: linux os: ubuntu-18.04 @@ -42,10 +42,6 @@ jobs: os: windows-2019 rust: stable target: x86_64-pc-windows-gnu - - build: win32-msvc - os: windows-2019 - rust: stable - target: i686-pc-windows-msvc steps: - name: Checkout repository diff --git a/Cargo.toml b/Cargo.toml index 268168b..e37dcb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,5 @@ test = false doc = false name = "open" -[target.'cfg(windows)'.dependencies] -windows-sys = { version = "0.42", features = ["Win32_UI_Shell", "Win32_Foundation", "Win32_UI_WindowsAndMessaging"] } - [target.'cfg(all(unix, not(macos)))'.dependencies] pathdiff = "0.2.0" diff --git a/src/windows.rs b/src/windows.rs index 125770e..b2b8658 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -1,66 +1,21 @@ -use std::{ - ffi::{OsStr, OsString}, - io, - os::windows::ffi::OsStrExt, - ptr, -}; +use std::{ffi::OsStr, io}; -use std::os::raw::c_int; -use windows_sys::Win32::UI::Shell::ShellExecuteW; -use windows_sys::Win32::UI::WindowsAndMessaging::SW_SHOW; - -use crate::IntoResult; - -fn convert_path(path: &OsStr) -> io::Result> { - let mut quoted_path = OsString::with_capacity(path.len()); - - // Surround path with double quotes "" to handle spaces in path. - quoted_path.push("\""); - quoted_path.push(&path); - quoted_path.push("\""); - - let mut wide_chars: Vec<_> = quoted_path.encode_wide().collect(); - if wide_chars.iter().any(|&u| u == 0) { - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - "path contains NUL byte(s)", - )); - } - wide_chars.push(0); - Ok(wide_chars) -} +use crate::{CommandExt, IntoResult}; pub fn that>(path: T) -> io::Result<()> { - let path = convert_path(path.as_ref())?; - let operation: Vec = OsStr::new("open\0").encode_wide().collect(); - let result = unsafe { - ShellExecuteW( - 0, - operation.as_ptr(), - path.as_ptr(), - ptr::null(), - ptr::null(), - SW_SHOW, - ) - }; - (result as c_int).into_result() + std::process::Command::new("cmd") + .arg("/c") + .arg("start") + .arg(path.as_ref()) + .status_without_output() + .into_result() } pub fn with>(path: T, app: impl Into) -> io::Result<()> { - let path = convert_path(path.as_ref())?; - let operation: Vec = OsStr::new("open\0").encode_wide().collect(); - let app_name: Vec = OsStr::new(&format!("{}\0", app.into())) - .encode_wide() - .collect(); - let result = unsafe { - ShellExecuteW( - 0, - operation.as_ptr(), - app_name.as_ptr(), - path.as_ptr(), - ptr::null(), - SW_SHOW, - ) - }; - (result as c_int).into_result() + std::process::Command::new("cmd") + .arg("/c") + .arg(app.into()) + .arg(path.as_ref()) + .status_without_output() + .into_result() }