Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
- fix build
- don't quote path anymore as it's seemingly not required.
  After all, we are passing the argument directly.
  • Loading branch information
Byron committed Feb 5, 2023
1 parent 056cb00 commit 7ab725a
Showing 1 changed file with 4 additions and 32 deletions.
36 changes: 4 additions & 32 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,9 @@
use std::{
ffi::{OsStr, OsString},
io,
os::windows::ffi::OsStrExt,
ptr,
};
use std::{ffi::OsStr, io};

use std::os::raw::c_int;

use crate::IntoResult;

fn convert_path(path: &OsStr) -> io::Result<Vec<u16>> {
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<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
let path = convert_path(path.as_ref())?;
Command::new("cmd")
std::process::Command::new("cmd")
.arg("/c")
.arg("start")
.arg(path.as_ref())
Expand All @@ -39,8 +12,7 @@ pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
}

pub fn with<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> io::Result<()> {
let path = convert_path(path.as_ref())?;
Command::new("cmd")
std::process::Command::new("cmd")
.arg("/c")
.arg(app.into())
.arg(path.as_ref())
Expand Down

0 comments on commit 7ab725a

Please sign in to comment.