removed somehting
This commit is contained in:
@@ -20,6 +20,7 @@ nvml-wrapper = "0.10"
|
|||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
winapi = { version = "0.3", features = ["winuser", "pdh", "ifmib", "iphlpapi", "winerror"] }
|
winapi = { version = "0.3", features = ["winuser", "pdh", "ifmib", "iphlpapi", "winerror"] }
|
||||||
|
systemstat = "0.2.5"
|
||||||
|
|
||||||
[target.'cfg(unix)'.dependencies]
|
[target.'cfg(unix)'.dependencies]
|
||||||
glob = "0.3"
|
glob = "0.3"
|
@@ -13,6 +13,7 @@ use tokio::time::{interval, sleep, Instant};
|
|||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::os::windows::ffi::OsStrExt;
|
use std::os::windows::ffi::OsStrExt;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
use systemstat::{Platform, System as SysStat};
|
||||||
use winapi::shared::winerror::ERROR_SUCCESS;
|
use winapi::shared::winerror::ERROR_SUCCESS;
|
||||||
use winapi::um::pdh::PDH_FMT_COUNTERVALUE;
|
use winapi::um::pdh::PDH_FMT_COUNTERVALUE;
|
||||||
use winapi::um::pdh::{
|
use winapi::um::pdh::{
|
||||||
@@ -449,65 +450,15 @@ fn get_cpu_temp() -> Option<f32> {
|
|||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
println!("Attempting to get CPU temperature on Windows...");
|
let sys = SysStat::new();
|
||||||
|
|
||||||
unsafe {
|
match sys.cpu_temp() {
|
||||||
let mut query = ptr::null_mut();
|
Ok(temp) => return Some(temp),
|
||||||
let mut counter = ptr::null_mut();
|
Err(e) => {
|
||||||
|
eprintln!("Fehler beim Lesen der CPU-Temperatur: {}", e);
|
||||||
// Open a query
|
|
||||||
if PdhOpenQueryW(ptr::null(), 0, &mut query) != ERROR_SUCCESS as i32 {
|
|
||||||
println!("Failed to open PDH query");
|
|
||||||
return None;
|
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")))]
|
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
|
||||||
|
Reference in New Issue
Block a user