Skip to content

Commit

Permalink
Merge pull request #12 from neeleshpoli/gpu-specs
Browse files Browse the repository at this point in the history
Gpu specs
  • Loading branch information
neeleshpoli authored Sep 18, 2023
2 parents 93dd9eb + 37128b4 commit 20b8f7b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/hardware/gpu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
pub mod windows {
use crate::utils::windows::{Error::SysProbeResult, WMIWrapper};

#[derive(Debug)]
pub struct GraphicsInfo {
name: String,
memory: String,
// May not return anything since the GPU may not be outputting anything
horizontal_resolution: Option<u32>,
vertical_resolution: Option<u32>,
refresh_rate: Option<u32>,
bits_per_pixel: Option<u32>,
}

pub fn get_graphics_info() -> SysProbeResult<Vec<GraphicsInfo>> {
let wmi_getter = WMIWrapper::new("root\\CIMV2")?;
let graphics_info = wmi_getter.get("Win32_VideoController", "Name, AdapterRAM, CurrentHorizontalResolution, CurrentVerticalResolution, CurrentRefreshRate, CurrentBitsPerPixel")?;

let mut parsed_graphics_info: Vec<GraphicsInfo> = Vec::new();

for info in graphics_info {
parsed_graphics_info.push(
GraphicsInfo {
name: {
println!("{}", info.get("Name").unwrap().to_string());
info.get("Name").unwrap().to_string()
},
memory: info.get("AdapterRAM").unwrap().to_string(),
horizontal_resolution: match info.get("CurrentHorizontalResolution").unwrap().as_str() {
"" => None,
_ => Some(info.get("CurrentHorizontalResolution").unwrap().to_string().parse().unwrap()),
},
vertical_resolution: match info.get("CurrentVerticalResolution").unwrap().as_str() {
"" => None,
_ => Some(info.get("CurrentVerticalResolution").unwrap().to_string().parse().unwrap()),
},
refresh_rate: match info.get("CurrentRefreshRate").unwrap().as_str() {
"" => None,
_ => Some(info.get("CurrentRefreshRate").unwrap().to_string().parse().unwrap()),
},
bits_per_pixel: match info.get("CurrentBitsPerPixel").unwrap().as_str() {
"" => None,
_ => Some(info.get("CurrentBitsPerPixel").unwrap().to_string().parse().unwrap()),
},
}
)
}

Ok(parsed_graphics_info)
}
}
5 changes: 4 additions & 1 deletion src/hardware/mod.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
mod processor;
mod gpu;
#[cfg(target_os = "windows")]
pub mod windows {
use crate::utils::windows::Error::SysProbeResult;

use super::processor;
use super::{processor, gpu::windows::{GraphicsInfo, get_graphics_info}};

#[derive(Debug)]
pub struct HardwareInfo {
processor_info: processor::windows::ProcessorInfo,
graphics_info: Vec<GraphicsInfo>,
}

pub fn get_hardware_info() -> SysProbeResult<HardwareInfo> {
Ok(
HardwareInfo {
processor_info: processor::windows::get_processor_info()?,
graphics_info: get_graphics_info()?,
}
)
}
Expand Down

0 comments on commit 20b8f7b

Please sign in to comment.