mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 05:04:17 +01:00
Chassis (Windows): add flag --chassis-use-wmi
This commit is contained in:
@@ -125,6 +125,7 @@ Module specific options:
|
||||
--title-color-user <color>: Set color of the user name (left part). Default is empty (use color of `--color-title`).
|
||||
--title-color-at <color>: Set color of the @ symbol (middle part). Default is empty (use color of `--color-title`)
|
||||
--title-color-host <color>: Set color of the host name (right part). Default is empty (use color of `--color-title`)
|
||||
--chassis-use-wmi <?value>: Set if WMI query should be used on Windows, which detects more information but slower. Default is false
|
||||
--separator-string <str>: Set the string printed by the separator module
|
||||
--os-file <path>: Set the path to the file containing OS information. Linux only
|
||||
--disk-folders <folders>: A colon (semicolon on Windows) separated list of folder paths for the disk output. Default is "/:/home" ("C:\\;D:\\ ..." on Windows)
|
||||
|
||||
@@ -12,7 +12,7 @@ typedef struct FFChassisResult
|
||||
FFstrbuf version;
|
||||
} FFChassisResult;
|
||||
|
||||
const char* ffDetectChassis(FFChassisResult* result);
|
||||
const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options);
|
||||
const char* ffChassisTypeToString(uint32_t type);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "common/settings.h"
|
||||
#include "util/smbiosHelper.h"
|
||||
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
const char* ffDetectChassis(FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options)
|
||||
{
|
||||
// Unlike other platforms, `smbios.chassis.type` return display string directly on my machine
|
||||
ffSettingsGetFreeBSDKenv("smbios.chassis.type", &result->type);
|
||||
|
||||
@@ -17,7 +17,7 @@ static void getSmbiosValue(const char* devicesPath, const char* classPath, FFstr
|
||||
ffStrbufClear(buffer);
|
||||
}
|
||||
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
const char* ffDetectChassis(FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "chassis.h"
|
||||
|
||||
const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result)
|
||||
const char* ffDetectChassis(FF_MAYBE_UNUSED FFChassisResult* result, FF_MAYBE_UNUSED FFChassisOptions* options)
|
||||
{
|
||||
return "Not supported on this platform";
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result)
|
||||
{
|
||||
auto [arr, len] = vtProp.get<std::pair<const int32_t*, uint32_t>>();
|
||||
if(len == 0)
|
||||
return "ChassisTypes contain no data failed";
|
||||
return "ChassisTypes contain no data";
|
||||
for (uint32_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
@@ -65,9 +65,9 @@ FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result)
|
||||
}
|
||||
|
||||
extern "C"
|
||||
const char* ffDetectChassis(FFChassisResult* result)
|
||||
const char* ffDetectChassis(FFChassisResult* result, FFChassisOptions* options)
|
||||
{
|
||||
if (instance.config.general.allowSlowOperations)
|
||||
if (options->useWmi)
|
||||
return detectWithWmi(result);
|
||||
return detectWithRegistry(result);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void ffPrintChassis(FFChassisOptions* options)
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.version);
|
||||
|
||||
const char* error = ffDetectChassis(&result);
|
||||
const char* error = ffDetectChassis(&result, options);
|
||||
|
||||
if(error)
|
||||
{
|
||||
@@ -57,6 +57,14 @@ bool ffParseChassisCommandOptions(FFChassisOptions* options, const char* key, co
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ffStrEqualsIgnCase(subKey, "use-wmi"))
|
||||
{
|
||||
options->useWmi = ffOptionParseBoolean(value);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -73,6 +81,14 @@ void ffParseChassisJsonObject(FFChassisOptions* options, yyjson_val* module)
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
||||
continue;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (ffStrEqualsIgnCase(key, "useWmi"))
|
||||
{
|
||||
options->useWmi = yyjson_get_bool(val);
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
ffPrintError(FF_CHASSIS_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
@@ -83,6 +99,11 @@ void ffGenerateChassisJsonConfig(FFChassisOptions* options, yyjson_mut_doc* doc,
|
||||
ffInitChassisOptions(&defaultOptions);
|
||||
|
||||
ffJsonConfigGenerateModuleArgsConfig(doc, module, &defaultOptions.moduleArgs, &options->moduleArgs);
|
||||
|
||||
#ifdef _WIN32
|
||||
if (options->useWmi != defaultOptions.useWmi)
|
||||
yyjson_mut_obj_add_bool(doc, module, "useWmi", options->useWmi);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
|
||||
@@ -92,7 +113,7 @@ void ffGenerateChassisJsonResult(FF_MAYBE_UNUSED FFChassisOptions* options, yyjs
|
||||
ffStrbufInit(&result.vendor);
|
||||
ffStrbufInit(&result.version);
|
||||
|
||||
const char* error = ffDetectChassis(&result);
|
||||
const char* error = ffDetectChassis(&result, options);
|
||||
|
||||
if (error)
|
||||
{
|
||||
@@ -139,6 +160,10 @@ void ffInitChassisOptions(FFChassisOptions* options)
|
||||
ffGenerateChassisJsonConfig
|
||||
);
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
|
||||
#ifdef _WIN32
|
||||
options->useWmi = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ffDestroyChassisOptions(FFChassisOptions* options)
|
||||
|
||||
@@ -8,4 +8,8 @@ typedef struct FFChassisOptions
|
||||
{
|
||||
FFModuleBaseInfo moduleInfo;
|
||||
FFModuleArgs moduleArgs;
|
||||
|
||||
#ifdef _WIN32
|
||||
bool useWmi;
|
||||
#endif
|
||||
} FFChassisOptions;
|
||||
|
||||
Reference in New Issue
Block a user