diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 38dc5cf..c16c653 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -32,5 +32,5 @@ jobs: - name: Get Build Artifact uses: actions/upload-artifact@v3 with: - name: sys-probe + name: sys-probe-build-${{ github.run_number }} path: target/x86_64-pc-windows-msvc/release/sys-probe.exe \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 7695a2d..3b42a54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ dependencies = [ [[package]] name = "sys-probe" -version = "0.1.0" +version = "0.2.0" dependencies = [ "chrono", "windows 0.51.1", diff --git a/Cargo.toml b/Cargo.toml index e3dfdad..c6fc33a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "sys-probe" -version = "0.1.0" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/hardware/mod.rs b/src/hardware/mod.rs new file mode 100644 index 0000000..bd50d75 --- /dev/null +++ b/src/hardware/mod.rs @@ -0,0 +1,17 @@ +mod processor; +pub mod windows { + use super::processor; + + #[derive(Debug)] + pub struct HardwareInfo { + processor_info: processor::windows::ProcessorInfo, + } + + pub fn get_hardware_info() -> Result { + Ok( + HardwareInfo { + processor_info: processor::windows::get_processor_info()?, + } + ) + } +} \ No newline at end of file diff --git a/src/hardware/processor.rs b/src/hardware/processor.rs new file mode 100644 index 0000000..43c43a2 --- /dev/null +++ b/src/hardware/processor.rs @@ -0,0 +1,44 @@ +pub mod windows { + use crate::utils::windows::get_wmi; + + #[derive(Debug)] + pub struct ProcessorInfo { + name: String, + cores: u32, + threads: u32, + current_clock_speed: u32, + current_voltage: Option, + max_clock_speed: u32, + processor_socket: String, + load_percentage: u16, + voltage_caps: Option, + } + + pub fn get_processor_info() -> Result { + let processor_info = get_wmi("Win32_Processor", "Name, NumberOfCores, ThreadCount, CurrentClockSpeed, CurrentVoltage, MaxClockSpeed, SocketDesignation, LoadPercentage, VoltageCaps")?; + + Ok( + ProcessorInfo { + name: processor_info.get("Name").unwrap().to_string(), + cores: processor_info.get("NumberOfCores").unwrap().to_string().parse().unwrap(), + threads: processor_info.get("ThreadCount").unwrap().to_string().parse().unwrap(), + current_clock_speed: processor_info.get("CurrentClockSpeed").unwrap().to_string().parse().unwrap(), + current_voltage: { + let value:u16 = processor_info.get("CurrentVoltage").unwrap().parse().unwrap(); + if (value & 0x0080) != 0 { + Some((value & 0x7f) * 10) + } else { + None + } + }, + max_clock_speed: processor_info.get("MaxClockSpeed").unwrap().to_string().parse().unwrap(), + processor_socket: processor_info.get("SocketDesignation").unwrap().to_string(), + load_percentage: processor_info.get("LoadPercentage").unwrap().to_string().parse().unwrap(), + voltage_caps: match processor_info.get("VoltageCaps").unwrap().as_str() { + "" => None, + value => Some(value.to_string()), + }, + } + ) + } +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 74f76f3..b8c82fd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,9 +6,13 @@ use windows::Win32::System::Com::{CoInitializeEx, CoInitializeSecurity, COINIT_M #[cfg(target_os = "windows")] use crate::basic_info::windows::get_basic_info; +mod hardware; + #[cfg(target_os = "windows")] fn main() -> windows::core::Result<()> { // Initialize secutriy for WMI + + use crate::{utils::windows::get_wmi, hardware::windows::get_hardware_info}; unsafe { CoInitializeEx(None, COINIT_MULTITHREADED)?; CoInitializeSecurity(None, -1, None, None, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, None, EOAC_NONE, None)?; @@ -16,6 +20,7 @@ fn main() -> windows::core::Result<()> { // Get basic info and print it println!("{:#?}", get_basic_info()); + println!("{:#?}", get_hardware_info()); Ok(()) } \ No newline at end of file