CPU: add support for Windows

This commit is contained in:
李通洲 2022-10-07 15:57:09 +08:00
parent a7e93faac8
commit 32d3edc690
2 changed files with 52 additions and 1 deletions

View File

@ -314,6 +314,7 @@ if(WIN_MSYS)
src/detection/host/host_windows.cpp
src/detection/bios/bios_windows.cpp
src/detection/board/board_windows.cpp
src/detection/cpu/cpu_windows.cpp
src/detection/gpu/gpu_windows.cpp
src/detection/battery/battery_windows.cpp
src/detection/displayserver/displayserver_windows.c
@ -332,7 +333,6 @@ if(WIN_MSYS)
# TODO
src/detection/media/media_linux.c
src/detection/font/font_linux.c
src/detection/cpu/cpu_linux.c
src/detection/memory/memory_linux.c
src/detection/cpuUsage/cpuUsage_linux.c
src/detection/temps/temps_linux.c

View File

@ -0,0 +1,51 @@
extern "C" {
#include "cpu.h"
}
#include "util/windows/wmi.hpp"
extern "C"
void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu, bool cached)
{
FF_UNUSED(instance);
cpu->temperature = FF_CPU_TEMP_UNSET;
if(cached)
return;
cpu->coresPhysical = cpu->coresLogical = cpu->coresOnline = 0;
ffStrbufInit(&cpu->name);
ffStrbufInit(&cpu->vendor);
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT Name, Manufacturer, NumberOfCores, NumberOfLogicalProcessors, ThreadCount, CurrentClockSpeed, MaxClockSpeed FROM Win32_Processor WHERE ProcessorType = 3", nullptr);
if(!pEnumerator)
return;
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
{
pEnumerator->Release();
return;
}
ffGetWmiObjString(pclsObj, L"Name", &cpu->name);
ffGetWmiObjString(pclsObj, L"Manufacturer", &cpu->vendor);
uint64_t value;
ffGetWmiObjUnsigned(pclsObj, L"NumberOfCores", &value);
cpu->coresPhysical = (uint16_t)value;
ffGetWmiObjUnsigned(pclsObj, L"NumberOfLogicalProcessors", &value);
cpu->coresLogical = (uint16_t)value;
ffGetWmiObjUnsigned(pclsObj, L"ThreadCount", &value);
cpu->coresOnline = (uint16_t)value;
ffGetWmiObjUnsigned(pclsObj, L"CurrentClockSpeed", &value); //There's no MinClockSpeed in Win32_Processor
cpu->frequencyMin = (double)value / 1000.0;
ffGetWmiObjUnsigned(pclsObj, L"MaxClockSpeed", &value);
cpu->frequencyMax = (double)value / 1000.0;
pclsObj->Release();
pEnumerator->Release();
}