Skip to content

Commit

Permalink
Migrate to windows-sys
Browse files Browse the repository at this point in the history
  • Loading branch information
Legend-Master committed Mar 12, 2024
1 parent 67e12d7 commit 5e3cc99
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 43 deletions.
31 changes: 1 addition & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions plugins/updater/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ tar = "0.4"

[target."cfg(target_os = \"windows\")".dependencies]
zip = { version = "0.6", default-features = false }
windows = { version = "0.54", features = [
"Win32_System_WinRT",
"Win32_UI_Shell",
"Win32_UI_WindowsAndMessaging",
] }
windows-sys = { version = "0.52.0", features = ["Win32_Foundation", "Win32_UI_WindowsAndMessaging"] }

[target."cfg(any(target_os = \"macos\", target_os = \"linux\"))".dependencies]
flate2 = "1.0.27"
Expand Down
30 changes: 22 additions & 8 deletions plugins/updater/src/updater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,9 @@ impl Update {
fn install_inner(&self, bytes: Vec<u8>) -> Result<()> {
use std::fs;

use windows::{
core::{w, HSTRING},
use windows_sys::{
core::HSTRING,
w,
Win32::UI::{Shell::ShellExecuteW, WindowsAndMessaging::SW_SHOW},
};

Expand Down Expand Up @@ -575,12 +576,25 @@ impl Update {
} else {
continue;
}
let file = HSTRING::from(found_path.as_os_str());
let parameters = HSTRING::from(installer_args.join(OsStr::new(" ")));
let ret =
unsafe { ShellExecuteW(None, w!("runas"), &file, &parameters, None, SW_SHOW) };
if ret.0 <= 32 {
return Err(Error::Io(windows::core::Error::from_win32().into()));
let file = HSTRING::from(found_path.as_os_str().as_encoded_bytes().as_ptr() as _);
let parameters = HSTRING::from(
installer_args
.join(OsStr::new(" "))
.as_encoded_bytes()
.as_ptr() as _,
);
let ret = unsafe {
ShellExecuteW(
0,
w!("runas"),
file as _,
parameters as _,
std::ptr::null(),
SW_SHOW,
)
};
if ret <= 32 {
return Err(Error::Io(std::io::Error::last_os_error()));
}
std::process::exit(0);
}
Expand Down

0 comments on commit 5e3cc99

Please sign in to comment.