From 22bc6b5b6ab200d432d22356b78a59db787e9374 Mon Sep 17 00:00:00 2001 From: donpat1to Date: Fri, 1 Aug 2025 22:49:09 +0200 Subject: [PATCH] removed somehting --- WatcherAgent/Cargo.toml | 1 + WatcherAgent/src/main.rs | 61 ++++------------------------------------ 2 files changed, 7 insertions(+), 55 deletions(-) diff --git a/WatcherAgent/Cargo.toml b/WatcherAgent/Cargo.toml index edf74c3..1a8524b 100644 --- a/WatcherAgent/Cargo.toml +++ b/WatcherAgent/Cargo.toml @@ -20,6 +20,7 @@ nvml-wrapper = "0.10" [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["winuser", "pdh", "ifmib", "iphlpapi", "winerror"] } +systemstat = "0.2.5" [target.'cfg(unix)'.dependencies] glob = "0.3" \ No newline at end of file diff --git a/WatcherAgent/src/main.rs b/WatcherAgent/src/main.rs index f4c27d2..affa0c7 100644 --- a/WatcherAgent/src/main.rs +++ b/WatcherAgent/src/main.rs @@ -13,6 +13,7 @@ use tokio::time::{interval, sleep, Instant}; use std::ffi::OsStr; use std::os::windows::ffi::OsStrExt; use std::ptr; +use systemstat::{Platform, System as SysStat}; use winapi::shared::winerror::ERROR_SUCCESS; use winapi::um::pdh::PDH_FMT_COUNTERVALUE; use winapi::um::pdh::{ @@ -449,67 +450,17 @@ fn get_cpu_temp() -> Option { #[cfg(target_os = "windows")] { - println!("Attempting to get CPU temperature on Windows..."); + let sys = SysStat::new(); - unsafe { - let mut query = ptr::null_mut(); - let mut counter = ptr::null_mut(); - - // Open a query - if PdhOpenQueryW(ptr::null(), 0, &mut query) != ERROR_SUCCESS as i32 { - println!("Failed to open PDH query"); + match sys.cpu_temp() { + Ok(temp) => return Some(temp), + Err(e) => { + eprintln!("Fehler beim Lesen der CPU-Temperatur: {}", e); return None; } - - // Create the counter path (this is system-dependent and may need adjustment) - let counter_path: Vec = OsStr::new("\\Thermal Zone Temperature(_TZ.TZ00._TMP)") - .encode_wide() - .chain(Some(0)) - .collect(); - - // Add counter - if PdhAddCounterW(query, counter_path.as_ptr(), 0, &mut counter) != ERROR_SUCCESS as i32 - { - println!("Failed to add PDH counter"); - pdh_close_query(query); - return None; - } - - // Collect data - if PdhCollectQueryData(query) != ERROR_SUCCESS as i32 { - println!("Failed to collect query data"); - pdh_close_query(query); - return None; - } - - // Get formatted value - let mut value = PDH_FMT_COUNTERVALUE { - CStatus: 0, - u: std::mem::zeroed(), - }; - - if PdhGetFormattedCounterValue(counter, PDH_FMT_DOUBLE, ptr::null_mut(), &mut value) - != ERROR_SUCCESS as i32 - { - println!("Failed to get formatted counter value"); - pdh_close_query(query); - return None; - } - - pdh_close_query(query); - - if value.CStatus == ERROR_SUCCESS as u32 { - return Some(*value.u.doubleValue() as f32); - } } } - // Helper function to close the PDH query - unsafe fn pdh_close_query(query: *mut winapi::ctypes::c_void) { - use winapi::um::pdh::PdhCloseQuery; - PdhCloseQuery(query); - } - #[cfg(not(any(target_os = "linux", target_os = "windows")))] { // Fallback for unsupported OS