From d39a880b8a44929cfcfb2d91ea8e8d53ce3181dd Mon Sep 17 00:00:00 2001 From: Jasper Bekkers Date: Wed, 14 Aug 2024 14:18:15 +0200 Subject: [PATCH] Update to windows 0.58 --- Cargo.toml | 4 +--- src/windows/cpu.rs | 20 ++++++++++---------- src/windows/sid.rs | 4 ++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 68b3f1c40..e9a216b4f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -97,9 +97,7 @@ serde = { version = "^1.0.190", optional = true } [target.'cfg(windows)'.dependencies] ntapi = { version = "0.4", optional = true } -# Support a range of versions in order to avoid duplication of this crate. Make sure to test all -# versions when bumping to a new release, and only increase the minimum when absolutely necessary. -windows = { version = ">=0.54, <=0.57", optional = true } +windows = { version = "0.58", optional = true } [target.'cfg(not(any(target_os = "unknown", target_arch = "wasm32")))'.dependencies] libc = "^0.2.153" diff --git a/src/windows/cpu.rs b/src/windows/cpu.rs index 1830bd2d0..50dbe38d5 100644 --- a/src/windows/cpu.rs +++ b/src/windows/cpu.rs @@ -135,9 +135,9 @@ unsafe fn init_load_avg() -> Mutex> { } struct InternalQuery { - query: HANDLE, + query: isize, event: HANDLE, - data: HashMap, + data: HashMap, } unsafe impl Send for InternalQuery {} @@ -147,15 +147,15 @@ impl Drop for InternalQuery { fn drop(&mut self) { unsafe { for (_, counter) in self.data.iter() { - PdhRemoveCounter(counter.0); + PdhRemoveCounter(*counter); } if !self.event.is_invalid() { let _err = CloseHandle(self.event); } - if !self.query.is_invalid() { - PdhCloseQuery(self.query.0); + if !(self.query == -1 || self.query == 0) { + PdhCloseQuery(self.query); } } } @@ -171,7 +171,7 @@ impl Query { unsafe { if PdhOpenQueryA(PCSTR::null(), 0, &mut query) == ERROR_SUCCESS.0 { let q = InternalQuery { - query: HANDLE(query), + query, event: HANDLE::default(), data: HashMap::new(), }; @@ -190,7 +190,7 @@ impl Query { let mut display_value = mem::MaybeUninit::::uninit(); return if PdhGetFormattedCounterValue( - counter.0, + *counter, PDH_FMT_DOUBLE, None, display_value.as_mut_ptr(), @@ -216,13 +216,13 @@ impl Query { unsafe { let mut counter = 0; let ret = PdhAddEnglishCounterW( - self.internal.query.0, + self.internal.query, PCWSTR::from_raw(getter.as_ptr()), 0, &mut counter, ); if ret == ERROR_SUCCESS.0 { - self.internal.data.insert(name.clone(), HANDLE(counter)); + self.internal.data.insert(name.clone(), counter); } else { sysinfo_debug!( "Query::add_english_counter: failed to add counter '{}': {:x}...", @@ -237,7 +237,7 @@ impl Query { pub fn refresh(&self) { unsafe { - if PdhCollectQueryData(self.internal.query.0) != ERROR_SUCCESS.0 { + if PdhCollectQueryData(self.internal.query) != ERROR_SUCCESS.0 { sysinfo_debug!("failed to refresh CPU data"); } } diff --git a/src/windows/sid.rs b/src/windows/sid.rs index 85c5b4b45..b1cdad194 100644 --- a/src/windows/sid.rs +++ b/src/windows/sid.rs @@ -3,10 +3,10 @@ use std::{fmt::Display, str::FromStr}; use windows::core::{PCWSTR, PWSTR}; -use windows::Win32::Foundation::{LocalFree, ERROR_INSUFFICIENT_BUFFER, HLOCAL, PSID}; +use windows::Win32::Foundation::{LocalFree, ERROR_INSUFFICIENT_BUFFER, HLOCAL}; use windows::Win32::Security::Authorization::{ConvertSidToStringSidW, ConvertStringSidToSidW}; use windows::Win32::Security::{ - CopySid, GetLengthSid, IsValidSid, LookupAccountSidW, SidTypeUnknown, + CopySid, GetLengthSid, IsValidSid, LookupAccountSidW, SidTypeUnknown, PSID }; use crate::sys::utils::to_utf8_str;