Skip to content

Commit

Permalink
Switch from winapi to windows-rs
Browse files Browse the repository at this point in the history
  • Loading branch information
mtkennerly committed Sep 21, 2024
1 parent b08858c commit b6eb84c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 23 deletions.
69 changes: 57 additions & 12 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ zip = "0.6.6"
[target.'cfg(windows)'.dependencies]
known-folders = "1.2.0"
winreg = "0.52.0"
winapi = { version = "0.3.9", features = ["wincon", "processenv"], default-features = false }
windows = { version = "0.58.0", features = ["Win32_System_Console", "Win32_System_Threading"] }

[target.'cfg(windows)'.build-dependencies]
winres = "0.1.12"
Expand Down
2 changes: 1 addition & 1 deletion src/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl RcloneProcess {
#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
command.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW);
command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
}

log::debug!("Running command: {} {:?}", &program, &args);
Expand Down
15 changes: 7 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,24 @@ fn prepare_logging() -> Result<flexi_logger::LoggerHandle, flexi_logger::FlexiLo
/// https://github.com/rust-lang/rust/issues/113277
#[cfg(target_os = "windows")]
unsafe fn detach_console() {
use winapi::um::{
processenv::SetStdHandle,
winbase::{STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE},
wincon::FreeConsole,
use windows::Win32::{
Foundation::HANDLE,
System::Console::{FreeConsole, SetStdHandle, STD_ERROR_HANDLE, STD_INPUT_HANDLE, STD_OUTPUT_HANDLE},
};

if FreeConsole() == 0 {
if FreeConsole().is_err() {
eprintln!("Unable to detach the console");
std::process::exit(1);
}
if SetStdHandle(STD_INPUT_HANDLE, std::ptr::null_mut()) == 0 {
if SetStdHandle(STD_INPUT_HANDLE, HANDLE::default()).is_err() {
eprintln!("Unable to reset stdin handle");
std::process::exit(1);
}
if SetStdHandle(STD_OUTPUT_HANDLE, std::ptr::null_mut()) == 0 {
if SetStdHandle(STD_OUTPUT_HANDLE, HANDLE::default()).is_err() {
eprintln!("Unable to reset stdout handle");
std::process::exit(1);
}
if SetStdHandle(STD_ERROR_HANDLE, std::ptr::null_mut()) == 0 {
if SetStdHandle(STD_ERROR_HANDLE, HANDLE::default()).is_err() {
eprintln!("Unable to reset stderr handle");
std::process::exit(1);
}
Expand Down
2 changes: 1 addition & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn run_command(
#[cfg(target_os = "windows")]
{
use std::os::windows::process::CommandExt;
command.creation_flags(winapi::um::winbase::CREATE_NO_WINDOW);
command.creation_flags(windows::Win32::System::Threading::CREATE_NO_WINDOW.0);
}

let collect_args = || {
Expand Down

0 comments on commit b6eb84c

Please sign in to comment.