Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Sep 16, 2022
1 parent 1ab9bc3 commit e0d5968
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
use std::{ffi::{OsStr,OsString}, io, os::windows::ffi::OsStrExt, ptr};
use std::{
ffi::{OsStr, OsString},
io,
os::windows::ffi::OsStrExt,
ptr,
};

use std::os::raw::c_int;
use windows_sys::Win32::UI::Shell::ShellExecuteW;

use crate::IntoResult;

fn convert_path(path: &OsStr) -> io::Result<Vec<u16>> {
// Surround path with double quotes "" to handle spaces in path.
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 maybe_result: Vec<_> = quoted_path.encode_wide().collect();
if maybe_result.iter().any(|&u| u == 0) {
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)",
));
}
maybe_result.push(0);
Ok(maybe_result)
wide_chars.push(0);
Ok(wide_chars)
}

pub fn that<T: AsRef<OsStr>>(path: T) -> io::Result<()> {
Expand Down

0 comments on commit e0d5968

Please sign in to comment.