diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..54705de --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +text=auto + +text eol=lf \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index f4df959..5ad59d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -478,7 +478,7 @@ dependencies = [ "iana-time-zone-haiku", "js-sys", "wasm-bindgen", - "windows-core", + "windows-core 0.52.0", ] [[package]] @@ -817,15 +817,14 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.30.13" +version = "0.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a5b4ddaee55fb2bea2bf0e5000747e5f5c0de765e5a5ff87f4cd106439f4bb3" +checksum = "d4115055da5f572fff541dd0c4e61b0262977f453cc9fe04be83aba25a89bdab" dependencies = [ - "cfg-if", "core-foundation-sys", "libc", + "memchr", "ntapi", - "once_cell", "rayon", "windows", ] @@ -988,11 +987,11 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.52.0" +version = "0.57.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e48a53791691ab099e5e2ad123536d0fff50652600abaf43bbf952894110d0be" +checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143" dependencies = [ - "windows-core", + "windows-core 0.57.0", "windows-targets", ] @@ -1005,6 +1004,49 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-core" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-result", + "windows-targets", +] + +[[package]] +name = "windows-implement" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9107ddc059d5b6fbfbffdfa7a7fe3e22a226def0b2608f72e9d552763d3e1ad7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-interface" +version = "0.57.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bee4b38ea3cde66011baa44dba677c432a78593e202392d1e9070cf2a7fca7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "windows-result" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/Cargo.toml b/Cargo.toml index 4cda1bb..e515560 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,36 +1,35 @@ [package] -name = "sealupd" -version = "0.1.0" -edition = "2021" + name = "sealupd" + version = "0.1.0" + edition = "2021" [profile.release] -strip = true -opt-level = 'z' -lto = true -codegen-units = 1 -panic = "abort" + strip = true + opt-level = 'z' + lto = true + codegen-units = 1 + panic = "abort" [dependencies] -# Command-line parser -clap = { version = "4.5.11", features = ["derive"] } + # Command-line parser + clap = { version = "4.5.11", features = ["derive"] } -# System info -sysinfo = "0.30.13" + # System info + sysinfo = "0.31.2" -# Logging -log = "0.4.22" -fern = "0.6.2" -chrono = "0.4.38" - -# File archives -zip = "2.1.5" -tar = "0.4.41" -flate2 = "1.0.30" + # Logging + log = "0.4.22" + fern = "0.6.2" + chrono = "0.4.38" + # File archives + zip = "2.1.5" + tar = "0.4.41" + flate2 = "1.0.30" [build-dependencies] -# Static links on Windows -static_vcruntime = "2.0.0" + # Static links on Windows + static_vcruntime = "2.0.0" -# Manifest files for 32-bit Windows -embed-manifest = "1.4.0" + # Manifest files for 32-bit Windows + embed-manifest = "1.4.0" diff --git a/src/proc.rs b/src/proc.rs index 529d939..661c26b 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -3,7 +3,22 @@ use std::{process, thread, time::Duration}; use log::debug; -use sysinfo::{Pid, ProcessRefreshKind, RefreshKind, System}; +use sysinfo::{Pid, ProcessRefreshKind, ProcessesToUpdate, RefreshKind, System}; + +struct RefreshSpecs { + refresh_kind: RefreshKind, + proc_refresh_kind: ProcessRefreshKind, +} + +impl RefreshSpecs { + pub fn new() -> Self { + let proc_refresh_kind = ProcessRefreshKind::new(); + RefreshSpecs { + refresh_kind: RefreshKind::new().with_processes(proc_refresh_kind), + proc_refresh_kind, + } + } +} /// Waits for the process with specified PID to finish. If the program is spawned /// by that process, finishes waiting if the program has inherited the PID. @@ -14,21 +29,24 @@ pub fn wait(pid: u32) { return; } - let mut sys = System::new_with_specifics( - RefreshKind::new().with_processes(ProcessRefreshKind::everything()), - ); + let specs = RefreshSpecs::new(); + let mut sys = System::new_with_specifics(specs.refresh_kind); loop { match sys.process(pid) { None => break, Some(proc) => { let pname = proc.name(); - debug!("Found process {} \"{}\"", pid, pname.escape_debug()); + debug!( + "Found process {} \"{}\"", + pid, + pname.to_string_lossy().escape_debug() + ); if pname == env!("CARGO_PKG_NAME") || prog_pid == pid { break; } - sys.refresh_processes(); + sys.refresh_processes_specifics(ProcessesToUpdate::All, specs.proc_refresh_kind); prog_pid = Pid::from_u32(process::id()); thread::sleep(Duration::from_secs(1)); }