removed somehting

This commit is contained in:
2025-08-01 22:49:09 +02:00
parent 9c5709ca50
commit 22bc6b5b6a
2 changed files with 7 additions and 55 deletions

View File

@@ -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"

View File

@@ -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<f32> {
#[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<u16> = 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