From ab1906bf994cdf1f0769539eda71f0513921ed93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E7=B1=B3=E5=89=8D=E6=9C=89=E8=95=89=E7=9A=AE?= Date: Sat, 14 Dec 2024 13:31:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8window=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E8=A1=A8=E6=9B=BF=E6=8D=A2sysinfo=20(#169)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.toml | 2 +- src/windows/utils.rs | 27 ++++++++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f0514d1..df28dee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,6 @@ vendored = ["dbus/vendored"] [dependencies] image = "0.25" log = "0.4" -sysinfo = "0.33" thiserror = "2.0" [target.'cfg(target_os = "macos")'.dependencies] @@ -33,6 +32,7 @@ windows = { version = "0.58", features = [ "Win32_Storage_Xps", "Win32_System_Threading", "Win32_System_ProcessStatus", + "Win32_System_Registry", "Win32_Storage_FileSystem", "Win32_Graphics_Dxgi", "Win32_Graphics_Direct3D", diff --git a/src/windows/utils.rs b/src/windows/utils.rs index ad968cd..df55587 100644 --- a/src/windows/utils.rs +++ b/src/windows/utils.rs @@ -1,5 +1,6 @@ use image::RgbaImage; -use sysinfo::System; +use windows::core::w; +use windows::Win32::System::Registry::{RegGetValueW, HKEY_LOCAL_MACHINE, RRF_RT_REG_DWORD}; use windows::Win32::Foundation::GetLastError; use crate::{error::XCapResult, XCapError}; @@ -15,12 +16,24 @@ pub(super) fn wide_string_to_string(wide_string: &[u16]) -> XCapResult { } pub(super) fn get_os_major_version() -> u8 { - System::os_version() - .map(|os_version| { - let strs: Vec<&str> = os_version.split(' ').collect(); - strs[0].parse::().unwrap_or(0) - }) - .unwrap_or(0) + unsafe { + let mut buf_len: u32 = 4; + let mut buf = [0u8; 4]; + let err = RegGetValueW( + HKEY_LOCAL_MACHINE, + w!(r"SOFTWARE\Microsoft\Windows NT\CurrentVersion"), + w!("CurrentMajorVersionNumber"), + RRF_RT_REG_DWORD, + None, + Some(buf.as_mut_ptr().cast()), + Some(&mut buf_len), + ); + if err.is_ok() { + u32::from_le_bytes(buf) as u8 + } else { + 0 + } + } } pub(super) fn log_last_error(label: T) {