mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
CPUUsage (Windows): simplifies Win10 detection
This commit is contained in:
+15
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
#include "fastfetch.h"
|
||||
#include "detection/cpuusage/cpuusage.h"
|
||||
|
||||
#include "common/mallocHelper.h"
|
||||
#include "common/debug.h"
|
||||
|
||||
#include <ntstatus.h>
|
||||
#include <winternl.h>
|
||||
#include <windows.h>
|
||||
#include <wchar.h>
|
||||
#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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user