Chassis (Windows): add flag --chassis-use-wmi

This commit is contained in:
李通洲
2023-10-30 14:31:19 +08:00
parent 485bcbf054
commit b462006280
10 changed files with 56 additions and 14 deletions
+3 -1
View File
@@ -7,7 +7,9 @@ Changes:
* Display keys `percent*` and `size*` in JSON config are restructured. `{ "sizeNdigits": 1 }` is now `{ "size": { "ndigits": 1 } }`
* With the introduction of `--migrate-config`, the old flag based config file is deprecated, and will be removed in 3.0.0 (next major version)
* Support of `--gen-config conf` is deprecated accordingly, and will be removed in 2.3.0 (next minor version)
* A new flag `--packages-winget` is introduced to control whether `winget` packages count should be detected. It was controlled by `--allow-slow-operations` previously. Note it's a very slow operation, please enable it with caution.
* The global flag `--allow-slow-operations` is splitted into some explicit flags in differnet modules
* `--packages-winget`: control whether `winget` packages count should be detected. Note it's a very slow operation, please enable it with caution.
* `--chassis-use-wmi`: control whether `WMI` query should be used to detect chassis type, which detects more information, but slower. This flag only affects `--chassis-format` and `--format json`.
Features:
* Quirks for MIPS platforms (CPU, Linux)
+14 -4
View File
@@ -644,10 +644,6 @@
"const": "board",
"description": "Print mather board name and other info"
},
{
"const": "chassis",
"description": "Print chassis type (desktop, laptop, etc)"
},
{
"const": "cursor",
"description": "Print cursor style name"
@@ -867,6 +863,20 @@
}
}
},
{
"title": "Chassis",
"properties": {
"type": {
"const": "chassis",
"description": "Print chassis type (desktop, laptop, etc)"
},
"useWmi": {
"description": "Set if WMI query should be used on Windows, which detects more information but slower",
"type": "boolean",
"default": false
}
}
},
{
"title": "CPU",
"properties": {
+1
View File
@@ -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)
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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 -1
View File
@@ -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";
}
+3 -3
View File
@@ -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);
}
+27 -2
View File
@@ -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)
+4
View File
@@ -8,4 +8,8 @@ typedef struct FFChassisOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
#ifdef _WIN32
bool useWmi;
#endif
} FFChassisOptions;