mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-12 10:22:12 +02:00
WMI (Windows): add --wmi-timeout option
This commit is contained in:
@@ -18,6 +18,7 @@ Features:
|
||||
* Support `--*-key-color` option to change the key color of specified module
|
||||
* Support `--colors-symbol` and `--colors-padding-left`
|
||||
* Add LM (Login Manager) module
|
||||
* Add `--wmi-timeout` option (Windows)
|
||||
|
||||
# 1.11.3
|
||||
|
||||
|
||||
@@ -220,6 +220,10 @@
|
||||
"osFile": {
|
||||
"type": "string",
|
||||
"title": "Set the path to the file containing OS information. Linux only"
|
||||
},
|
||||
"wmiTimeout": {
|
||||
"type": "integer",
|
||||
"title": "Set the timeout (ms) for WMI queries, `-1` for no timeout. Windows only"
|
||||
}
|
||||
},
|
||||
"additionalProperties": false
|
||||
|
||||
@@ -41,6 +41,8 @@ static void defaultConfig(void)
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
ffStrbufInit(&instance.config.playerName);
|
||||
ffStrbufInit(&instance.config.osFile);
|
||||
#elif defined(_WIN32)
|
||||
instance.config.wmiTimeout = 5000;
|
||||
#endif
|
||||
|
||||
instance.config.showErrors = false;
|
||||
|
||||
@@ -312,6 +312,9 @@ const char* ffParseGeneralJsonConfig(void)
|
||||
ffStrbufSetS(&config->playerName, yyjson_get_str(val));
|
||||
else if (ffStrEqualsIgnCase(key, "osFile"))
|
||||
ffStrbufSetS(&config->osFile, yyjson_get_str(val));
|
||||
#elif defined(_WIN32)
|
||||
else if (ffStrEqualsIgnCase(key, "wmiTimeout"))
|
||||
config->wmiTimeout = yyjson_get_uint(val);
|
||||
#endif
|
||||
|
||||
else
|
||||
|
||||
@@ -81,6 +81,25 @@ uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value)
|
||||
return num;
|
||||
}
|
||||
|
||||
int32_t ffOptionParseInt32(const char* argumentKey, const char* value)
|
||||
{
|
||||
if(value == NULL)
|
||||
{
|
||||
fprintf(stderr, "Error: usage: %s <num>\n", argumentKey);
|
||||
exit(480);
|
||||
}
|
||||
|
||||
char* end;
|
||||
int32_t num = (int32_t) strtol(value, &end, 10);
|
||||
if(*end != '\0')
|
||||
{
|
||||
fprintf(stderr, "Error: usage: %s <num>\n", argumentKey);
|
||||
exit(479);
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[])
|
||||
{
|
||||
if(requestedKey == NULL)
|
||||
|
||||
@@ -19,6 +19,7 @@ const char* ffOptionTestPrefix(const char* argumentKey, const char* moduleName);
|
||||
bool ffOptionParseModuleArgs(const char* argumentKey, const char* pkey, const char* value, FFModuleArgs* result);
|
||||
void ffOptionParseString(const char* argumentKey, const char* value, FFstrbuf* buffer);
|
||||
FF_C_NODISCARD uint32_t ffOptionParseUInt32(const char* argumentKey, const char* value);
|
||||
FF_C_NODISCARD int32_t ffOptionParseInt32(const char* argumentKey, const char* value);
|
||||
FF_C_NODISCARD int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]);
|
||||
FF_C_NODISCARD bool ffOptionParseBoolean(const char* str);
|
||||
void ffOptionParseColor(const char* value, FFstrbuf* buffer);
|
||||
|
||||
@@ -58,6 +58,12 @@
|
||||
# Default is true.
|
||||
#--hide-cursor true
|
||||
|
||||
# WMI timeout option:
|
||||
# Sets the timeout (ms) for WMI queries. Windows only
|
||||
# Must be an integer.
|
||||
# Default is 5000
|
||||
#--wmi-timeout 5000
|
||||
|
||||
# Logo option:
|
||||
# Sets the logo to use.
|
||||
# List available logos with "fastfetch --list-logos".
|
||||
|
||||
@@ -843,6 +843,9 @@ static void parseOption(FFdata* data, const char* key, const char* value)
|
||||
ffOptionParseString(key, value, &instance.config.playerName);
|
||||
else if (ffStrEqualsIgnCase(key, "--os-file"))
|
||||
ffOptionParseString(key, value, &instance.config.osFile);
|
||||
#elif defined(_WIN32)
|
||||
else if (ffStrEqualsIgnCase(key, "--wmi-timeout"))
|
||||
instance.config.wmiTimeout = ffOptionParseInt32(key, value);
|
||||
#endif
|
||||
|
||||
////////////////
|
||||
|
||||
@@ -53,6 +53,8 @@ typedef struct FFconfig
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
FFstrbuf playerName;
|
||||
FFstrbuf osFile;
|
||||
#elif defined(_WIN32)
|
||||
int32_t wmiTimeout;
|
||||
#endif
|
||||
|
||||
FFTitleOptions title;
|
||||
|
||||
@@ -157,7 +157,7 @@ bool FFWmiRecord::getString(const wchar_t* key, FFstrbuf* strbuf)
|
||||
}
|
||||
else
|
||||
{
|
||||
ffStrbufSetWS(strbuf, SysStringLen(vtProp.bstrVal), vtProp.bstrVal);
|
||||
ffStrbufSetNWS(strbuf, SysStringLen(vtProp.bstrVal), vtProp.bstrVal);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern "C" {
|
||||
#include "util/FFstrbuf.h"
|
||||
#include "fastfetch.h"
|
||||
}
|
||||
|
||||
#include <initguid.h>
|
||||
@@ -21,10 +21,6 @@ enum class FFWmiNamespace {
|
||||
LAST,
|
||||
};
|
||||
|
||||
enum {
|
||||
FF_WMI_QUERY_TIMEOUT = 5000
|
||||
};
|
||||
|
||||
struct FFWmiVariant: VARIANT {
|
||||
explicit FFWmiVariant() { VariantInit(this); }
|
||||
~FFWmiVariant() { VariantClear(this); }
|
||||
@@ -160,7 +156,7 @@ struct FFWmiRecord
|
||||
if(!pEnumerator) return;
|
||||
|
||||
ULONG ret;
|
||||
bool ok = SUCCEEDED(pEnumerator->Next(FF_WMI_QUERY_TIMEOUT, 1, &obj, &ret)) && ret;
|
||||
bool ok = SUCCEEDED(pEnumerator->Next(instance.config.wmiTimeout, 1, &obj, &ret)) && ret;
|
||||
if(!ok) obj = nullptr;
|
||||
}
|
||||
FFWmiRecord(const FFWmiRecord&) = delete;
|
||||
|
||||
Reference in New Issue
Block a user