mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Chassis: refactor
This commit is contained in:
@@ -10,9 +10,8 @@ typedef struct FFChassisResult
|
||||
FFstrbuf chassisType;
|
||||
FFstrbuf chassisVendor;
|
||||
FFstrbuf chassisVersion;
|
||||
FFstrbuf error;
|
||||
} FFChassisResult;
|
||||
|
||||
void ffDetectChassis(FFChassisResult* result);
|
||||
const char* ffDetectChassis(FFChassisResult* result);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
#include "chassis.h"
|
||||
#include "common/settings.h"
|
||||
|
||||
void ffDetectChassis(FFChassisResult* result)
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
{
|
||||
ffStrbufInit(&result->error);
|
||||
ffStrbufInit(&result->chassisType);
|
||||
ffStrbufInit(&result->chassisVendor);
|
||||
ffStrbufInit(&result->chassisVersion);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.type", &result->chassisType);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.maker", &result->chassisVendor);
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.version", &result->chassisVersion);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -40,16 +40,10 @@ static void getHostValue(const char* devicesPath, const char* classPath, FFstrbu
|
||||
ffStrbufClear(buffer);
|
||||
}
|
||||
|
||||
void ffDetectChassis(FFChassisResult* result)
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
{
|
||||
ffStrbufInit(&result->error);
|
||||
|
||||
ffStrbufInit(&result->chassisType);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/chassis_type", "/sys/class/dmi/id/chassis_type", &result->chassisType);
|
||||
|
||||
ffStrbufInit(&result->chassisVendor);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/chassis_vendor", "/sys/class/dmi/id/chassis_vendor", &result->chassisVendor);
|
||||
|
||||
ffStrbufInit(&result->chassisVersion);
|
||||
getHostValue("/sys/devices/virtual/dmi/id/chassis_version", "/sys/class/dmi/id/chassis_version", &result->chassisVersion);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
#include "chassis.h"
|
||||
|
||||
void ffDetectChassis(FFChassisResult* result)
|
||||
const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result)
|
||||
{
|
||||
ffStrbufInitS(&result->error, "Not supported on this platform");
|
||||
|
||||
ffStrbufInit(&result->chassisType);
|
||||
ffStrbufInit(&result->chassisVendor);
|
||||
ffStrbufInit(&result->chassisVersion);
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
|
||||
@@ -8,18 +8,22 @@
|
||||
void ffPrintChassis(FFinstance* instance, FFChassisOptions* options)
|
||||
{
|
||||
FFChassisResult result;
|
||||
ffDetectChassis(&result);
|
||||
ffStrbufInit(&result.chassisType);
|
||||
ffStrbufInit(&result.chassisVendor);
|
||||
ffStrbufInit(&result.chassisVersion);
|
||||
|
||||
if(result.error.length > 0)
|
||||
const char* error = ffDetectChassis(&result);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "%*s", result.error.length, result.error.chars);
|
||||
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(result.chassisType.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "chassis_type is not set by O.E.M.");
|
||||
return;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
@@ -46,7 +50,6 @@ exit:
|
||||
ffStrbufDestroy(&result.chassisType);
|
||||
ffStrbufDestroy(&result.chassisVendor);
|
||||
ffStrbufDestroy(&result.chassisVersion);
|
||||
ffStrbufDestroy(&result.error);
|
||||
}
|
||||
|
||||
void ffInitChassisOptions(FFChassisOptions* options)
|
||||
|
||||
Reference in New Issue
Block a user