Skip to content

Commit

Permalink
split into two functions for better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir committed Feb 29, 2024
1 parent 191cb0e commit 4506b2f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/windows.rs
Expand Up @@ -40,24 +40,34 @@ fn wrap_in_quotes<T: AsRef<OsStr>>(path: T) -> OsString {
}

pub fn that_detached<T: AsRef<OsStr>>(path: T) -> std::io::Result<()> {
detached(path, None::<&str>)
}
let path = wide(path);

pub fn with_detached<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> std::io::Result<()> {
detached(path, Some(app))
unsafe {
ShellExecuteW(
0,
ffi::OPEN,
path.as_ptr(),
ptr::null(),
ptr::null(),
ffi::SW_SHOW,
)
}
}

#[inline]
fn detached<T: AsRef<OsStr>>(path: T, app: Option<impl Into<String>>) -> std::io::Result<()> {
pub fn with_detached<T: AsRef<OsStr>>(path: T, app: impl Into<String>) -> std::io::Result<()> {
let app = wide(app.into());
let path = wide(path);
let app = app.map(|a| wide(a.into()));

let (app, args) = match app {
Some(app) => (app.as_ptr(), path.as_ptr()),
None => (path.as_ptr(), ptr::null()),
};

unsafe { ShellExecuteW(0, ffi::OPEN, app, args, ptr::null(), ffi::SW_SHOW) }
unsafe {
ShellExecuteW(
0,
ffi::OPEN,
app.as_ptr(),
path.as_ptr(),
ptr::null(),
ffi::SW_SHOW,
)
}
}

/// Encodes as wide and adds a null character.
Expand Down

0 comments on commit 4506b2f

Please sign in to comment.