diff --git a/src/common/windows/nt.h b/src/common/windows/nt.h index 22859f728..446bd271f 100644 --- a/src/common/windows/nt.h +++ b/src/common/windows/nt.h @@ -635,7 +635,7 @@ typedef struct _KUSER_SHARED_DATA // ... more fields follow, but we don't need them } KUSER_SHARED_DATA, *PKUSER_SHARED_DATA; -#define SharedUserData ((const KUSER_SHARED_DATA*) 0x7FFE0000UL) +#define SharedUserData ((const KUSER_SHARED_DATA*) 0x7FFE0000UL) static inline uint64_t ffKSystemTimeToUInt64(const volatile KSYSTEM_TIME* pTime) { @@ -656,3 +656,17 @@ static inline uint64_t ffKSystemTimeToUInt64(const volatile KSYSTEM_TIME* pTime) return ((uint64_t) high1 << 32) | low; #endif } + +static inline bool ffIsWindows10OrGreater() +{ + #if FF_WIN7_COMPAT + return SharedUserData->NtMajorVersion >= 10; + #else + return true; + #endif +} + +static inline bool ffIsWindows11OrGreater() +{ + return ffIsWindows10OrGreater() && SharedUserData->NtBuildNumber >= 22000; +} diff --git a/src/detection/cpuusage/cpuusage_windows.c b/src/detection/cpuusage/cpuusage_windows.c index 89ce1a1a0..1e96f43d5 100644 --- a/src/detection/cpuusage/cpuusage_windows.c +++ b/src/detection/cpuusage/cpuusage_windows.c @@ -1,13 +1,12 @@ -#include "fastfetch.h" #include "detection/cpuusage/cpuusage.h" - #include "common/mallocHelper.h" +#include "common/debug.h" #include -#include #include #include #include "common/windows/perflib_.h" +#include "common/windows/nt.h" static const char* getInfoByNqsi(FFlist* cpuTimes) { @@ -155,20 +154,17 @@ static const char* getInfoByPerflib(FFlist* cpuTimes) const char* ffGetCpuUsageInfo(FFlist* cpuTimes) { - #if !FF_WIN7_COMPAT - static uint8_t winver = 10; // Assume Windows 10 or later for WoA - #else - static uint8_t winver = 0; - if (winver == 0) - winver = (uint8_t) ffStrbufToUInt(&instance.state.platform.sysinfo.release, 1); - #endif + const char* error = NULL; - if (winver >= 10) + if (ffIsWindows10OrGreater()) { - if (getInfoByPerflib(cpuTimes) == NULL) return NULL; + error = getInfoByPerflib(cpuTimes); + FF_DEBUG("Get CPU usage info by Perflib: %s", error ?: "success"); + if (!error) return NULL; ffListClear(cpuTimes); - winver = 1; // Fall back to NQSI } - return getInfoByNqsi(cpuTimes); + error = getInfoByNqsi(cpuTimes); + FF_DEBUG("Get CPU usage info by NtQuerySystemInformation: %s", error ?: "success"); + return error; }