Files
fastfetch/src/detection/cpu/cpu_windows.c
T

55 lines
2.1 KiB
C
Raw Normal View History

2022-11-21 22:26:50 +08:00
#include "cpu.h"
2023-02-23 21:31:33 +08:00
#include "detection/temps/temps_windows.h"
2022-11-26 12:55:48 +08:00
#include "util/windows/registry.h"
2022-11-23 15:10:40 +08:00
#include "util/mallocHelper.h"
2022-11-21 22:26:50 +08:00
2023-06-12 09:56:03 +08:00
const char* ffDetectCPUImpl(FF_MAYBE_UNUSED const FFinstance* instance, const FFCPUOptions* options, FFCPUResult* cpu)
2022-11-21 22:26:50 +08:00
{
{
DWORD length = 0;
2023-06-12 09:56:03 +08:00
if (GetLogicalProcessorInformationEx(RelationAll, NULL, &length) != ERROR_INSUFFICIENT_BUFFER)
return "GetLogicalProcessorInformationEx(RelationAll, NULL, &length) failed";
2022-11-23 15:10:40 +08:00
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* FF_AUTO_FREE
2023-03-21 15:27:04 +08:00
pProcessorInfo = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)malloc(length);
2022-11-21 22:26:50 +08:00
2023-06-12 09:56:03 +08:00
if (pProcessorInfo && GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length))
2022-11-21 22:26:50 +08:00
{
for(
2023-03-21 15:27:04 +08:00
SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX* ptr = pProcessorInfo;
(uint8_t*)ptr < ((uint8_t*)pProcessorInfo) + length;
2022-11-21 22:26:50 +08:00
ptr = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX*)(((uint8_t*)ptr) + ptr->Size)
)
{
if(ptr->Relationship == RelationProcessorCore)
++cpu->coresPhysical;
2023-03-21 15:27:04 +08:00
else if(ptr->Relationship == RelationGroup)
{
cpu->coresOnline += ptr->Group.GroupInfo->ActiveProcessorCount;
cpu->coresLogical += ptr->Group.GroupInfo->MaximumProcessorCount;
}
2022-11-21 22:26:50 +08:00
}
}
2023-06-12 09:56:03 +08:00
else
return "GetLogicalProcessorInformationEx(RelationAll, pProcessorInfo, &length) failed";
2022-11-21 22:26:50 +08:00
}
FF_HKEY_AUTO_DESTROY hKey;
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", &hKey, NULL))
2023-06-12 09:56:03 +08:00
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0\", &hKey, NULL) failed";
2022-11-21 22:26:50 +08:00
{
uint32_t mhz;
if(ffRegReadUint(hKey, L"~MHz", &mhz, NULL))
2022-11-21 22:26:50 +08:00
cpu->frequencyMax = mhz / 1000.0;
}
ffRegReadStrbuf(hKey, L"ProcessorNameString", &cpu->name, NULL);
ffRegReadStrbuf(hKey, L"VendorIdentifier", &cpu->vendor, NULL);
2023-02-23 21:31:33 +08:00
2023-06-12 09:56:03 +08:00
if(options->temp)
2023-02-23 21:31:33 +08:00
ffDetectSmbiosTemp(&cpu->temperature, NULL);
2023-06-12 09:56:03 +08:00
return NULL;
2022-11-21 22:26:50 +08:00
}