PhysicalMemory: try converting vendor ID to name

This commit is contained in:
李通洲
2024-05-13 20:29:46 +08:00
parent caef317ade
commit 56403bab5c
5 changed files with 47 additions and 2 deletions
+1
View File
@@ -297,6 +297,7 @@ set(LIBFASTFETCH_SRC
src/detection/opencl/opencl.c
src/detection/os/os.c
src/detection/packages/packages.c
src/detection/physicalmemory/physicalmemory.c
src/detection/publicip/publicip.c
src/detection/terminaltheme/terminaltheme.c
src/detection/terminalfont/terminalfont.c
@@ -0,0 +1,42 @@
#include "physicalmemory.h"
static inline const char* getVendorString(unsigned vendorId)
{
switch (vendorId)
{
case 0x017A: return "Apacer";
case 0x0198: return "HyperX";
case 0x029E: return "Corsair";
case 0x04CB: return "A-DATA";
case 0x04CD: return "G-Skill";
case 0x059B: case 0x859B: case 0x1315: return "Crucial";
case 0x00CE: case 0x80CE: case 0xCE00: return "Samsung";
case 0x014F: return "Transcend";
case 0x2C00: case 0x802C: return "Micron";
case 0xAD00: case 0x80AD: return "Hynix";
case 0x5105: case 0x8551: return "Qimonda";
case 0x02FE: return "Elpida";
default: return NULL;
}
}
void FFPhysicalMemoryUpdateVendorString(FFPhysicalMemoryResult* device)
{
char vendorIdStr[5];
if (ffStrbufStartsWithS(&device->vendor, "0x"))
{
if (device->vendor.length < 6) return;
memcpy(vendorIdStr, device->vendor.chars + 2, 4);
}
else
{
if (device->vendor.length < 4) return;
memcpy(vendorIdStr, device->vendor.chars, 4);
}
vendorIdStr[4] = '\0';
char* pEnd = NULL;
uint32_t vendorId = (uint32_t) strtoul(vendorIdStr, &pEnd, 16);
if (*pEnd != '\0') return;
const char* vendorStr = getVendorString(vendorId);
if (vendorStr) ffStrbufSetStatic(&device->vendor, vendorStr);
}
@@ -17,3 +17,5 @@ typedef struct FFPhysicalMemoryResult
} FFPhysicalMemoryResult;
const char* ffDetectPhysicalMemory(FFlist* result); // list of FFPhysicalMemoryResult
void FFPhysicalMemoryUpdateVendorString(FFPhysicalMemoryResult* device);
@@ -23,7 +23,7 @@ static void appendDevice(
ffStrbufInit(&device->formFactor);
ffStrbufInitS(&device->locator, locator.UTF8String);
ffStrbufInitS(&device->vendor, vendor.UTF8String);
ffCleanUpSmbiosValue(&device->vendor);
FFPhysicalMemoryUpdateVendorString(device);
ffStrbufInitS(&device->serial, serial.UTF8String);
ffCleanUpSmbiosValue(&device->serial);
ffStrbufInitS(&device->partNumber, partNumber.UTF8String);
@@ -183,7 +183,7 @@ const char* ffDetectPhysicalMemory(FFlist* result)
device->maxSpeed = data->Speed == 0xFFFF ? data->ExtendedSpeed : data->Speed;
ffStrbufSetStatic(&device->vendor, ffSmbiosLocateString(strings, data->Manufacturer));
ffCleanUpSmbiosValue(&device->vendor);
FFPhysicalMemoryUpdateVendorString(device);
ffStrbufSetStatic(&device->serial, ffSmbiosLocateString(strings, data->SerialNumber));
ffCleanUpSmbiosValue(&device->serial);