mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Chassis: code refactor
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#include "chassis.h"
|
||||
|
||||
const char* ffChassisTypeToString(uint32_t chassisType)
|
||||
const char* ffChassisTypeToString(uint32_t type)
|
||||
{
|
||||
// https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.2.0.pdf
|
||||
// 7.4.1 System Enclosure or Chassis Types
|
||||
switch (chassisType)
|
||||
switch (type)
|
||||
{
|
||||
case 0x01: return "Other";
|
||||
case 0x02: return "Unknown";
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
typedef struct FFChassisResult
|
||||
{
|
||||
FFstrbuf chassisType;
|
||||
FFstrbuf chassisVendor;
|
||||
FFstrbuf chassisVersion;
|
||||
FFstrbuf type;
|
||||
FFstrbuf vendor;
|
||||
FFstrbuf version;
|
||||
} FFChassisResult;
|
||||
|
||||
const char* ffDetectChassis(FFChassisResult* result);
|
||||
const char* ffChassisTypeToString(uint32_t chassisType);
|
||||
const char* ffChassisTypeToString(uint32_t type);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
{
|
||||
// Unlike other platforms, `smbios.chassis.type` return display string directly on my machine
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.type", &result->chassisType);
|
||||
ffCleanUpSmbiosValue(&result->chassisType);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.maker", &result->chassisVendor);
|
||||
ffCleanUpSmbiosValue(&result->chassisVendor);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.version", &result->chassisVersion);
|
||||
ffCleanUpSmbiosValue(&result->chassisVersion);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.type", &result->type);
|
||||
ffCleanUpSmbiosValue(&result->type);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.maker", &result->vendor);
|
||||
ffCleanUpSmbiosValue(&result->vendor);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.version", &result->version);
|
||||
ffCleanUpSmbiosValue(&result->version);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@ static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstr
|
||||
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
{
|
||||
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->chassisType);
|
||||
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->chassisVendor);
|
||||
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->chassisVersion);
|
||||
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->type);
|
||||
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->vendor);
|
||||
getSmbiosValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->version);
|
||||
|
||||
if(result->chassisType.length)
|
||||
if(result->type.length)
|
||||
{
|
||||
const char* chassisTypeStr = ffChassisTypeToString(ffStrbufToUInt16(&result->chassisType, 9999));
|
||||
if(chassisTypeStr)
|
||||
ffStrbufSetS(&result->chassisType, chassisTypeStr);
|
||||
const char* typeStr = ffChassisTypeToString(ffStrbufToUInt16(&result->type, 9999));
|
||||
if(typeStr)
|
||||
ffStrbufSetS(&result->type, typeStr);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ const char* ffDetectChassis(FFChassisResult* result)
|
||||
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"HARDWARE\\DESCRIPTION\\System\\BIOS", &hKey, NULL)) // SMBIOS
|
||||
return "ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L\"HARDWARE\\DESCRIPTION\\System\\BIOS\", &hKey, NULL) failed";
|
||||
|
||||
uint32_t chassisType = 0;
|
||||
if(!ffRegReadUint(hKey, L"EnclosureType", &chassisType, NULL))
|
||||
uint32_t type = 0;
|
||||
if(!ffRegReadUint(hKey, L"EnclosureType", &type, NULL))
|
||||
return "\"HKEY_LOCAL_MACHINE\\HARDWARE\\DESCRIPTION\\System\\BIOS\\EnclosureType\" doesn't exist";
|
||||
|
||||
const char* chassisTypeStr = ffChassisTypeToString(chassisType);
|
||||
if(!chassisTypeStr)
|
||||
const char* typeStr = ffChassisTypeToString(type);
|
||||
if(!typeStr)
|
||||
return "Unknown chassis type";
|
||||
|
||||
ffStrbufAppendS(&result->chassisType, chassisTypeStr);
|
||||
ffStrbufAppendS(&result->type, typeStr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
void ffPrintChassis(FFinstance* instance, FFChassisOptions* options)
|
||||
{
|
||||
FFChassisResult result;
|
||||
ffStrbufInit(&result.chassisType);
|
||||
ffStrbufInit(&result.chassisVendor);
|
||||
ffStrbufInit(&result.chassisVersion);
|
||||
ffStrbufInit(&result.type);
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.version);
|
||||
|
||||
const char* error = ffDetectChassis(&result);
|
||||
|
||||
@@ -21,7 +21,7 @@ void ffPrintChassis(FFinstance* instance, FFChassisOptions* options)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(result.chassisType.length == 0)
|
||||
if(result.type.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "chassis_type is not set by O.E.M.");
|
||||
goto exit;
|
||||
@@ -30,24 +30,24 @@ void ffPrintChassis(FFinstance* instance, FFChassisOptions* options)
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs.key, &options->moduleArgs.keyColor);
|
||||
ffStrbufWriteTo(&result.chassisType, stdout);
|
||||
if (result.chassisVersion.length)
|
||||
printf(" (%s)", result.chassisVersion.chars);
|
||||
ffStrbufWriteTo(&result.type, stdout);
|
||||
if (result.version.length)
|
||||
printf(" (%s)", result.version.chars);
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, FF_CHASSIS_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisType},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisVendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.chassisVersion},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.type},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.vendor},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result.version},
|
||||
});
|
||||
}
|
||||
|
||||
exit:
|
||||
ffStrbufDestroy(&result.chassisType);
|
||||
ffStrbufDestroy(&result.chassisVendor);
|
||||
ffStrbufDestroy(&result.chassisVersion);
|
||||
ffStrbufDestroy(&result.type);
|
||||
ffStrbufDestroy(&result.vendor);
|
||||
ffStrbufDestroy(&result.version);
|
||||
}
|
||||
|
||||
void ffInitChassisOptions(FFChassisOptions* options)
|
||||
|
||||
Reference in New Issue
Block a user