diff --git a/CHANGELOG.md b/CHANGELOG.md index f7b57b7a4..54e32c3fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/doc/json_schema.json b/doc/json_schema.json index 919c86de6..158a1e5ff 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -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 diff --git a/src/common/init.c b/src/common/init.c index 423f0de58..061d70344 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -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; diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 13b6e514f..171548596 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -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 diff --git a/src/common/option.c b/src/common/option.c index 95c44e3e4..86a3b7363 100644 --- a/src/common/option.c +++ b/src/common/option.c @@ -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 \n", argumentKey); + exit(480); + } + + char* end; + int32_t num = (int32_t) strtol(value, &end, 10); + if(*end != '\0') + { + fprintf(stderr, "Error: usage: %s \n", argumentKey); + exit(479); + } + + return num; +} + int ffOptionParseEnum(const char* argumentKey, const char* requestedKey, FFKeyValuePair pairs[]) { if(requestedKey == NULL) diff --git a/src/common/option.h b/src/common/option.h index 07aded18d..bbd956506 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -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); diff --git a/src/data/config_user.txt b/src/data/config_user.txt index a25ecf913..29823779e 100644 --- a/src/data/config_user.txt +++ b/src/data/config_user.txt @@ -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". diff --git a/src/fastfetch.c b/src/fastfetch.c index 07efb414a..49c909d22 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -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 //////////////// diff --git a/src/fastfetch.h b/src/fastfetch.h index c76882c15..7db8ec8d1 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -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; diff --git a/src/util/windows/wmi.cpp b/src/util/windows/wmi.cpp index af84c7013..a131bceb5 100644 --- a/src/util/windows/wmi.cpp +++ b/src/util/windows/wmi.cpp @@ -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; diff --git a/src/util/windows/wmi.hpp b/src/util/windows/wmi.hpp index b31b84533..29ff621a0 100644 --- a/src/util/windows/wmi.hpp +++ b/src/util/windows/wmi.hpp @@ -6,7 +6,7 @@ #ifdef __cplusplus extern "C" { - #include "util/FFstrbuf.h" + #include "fastfetch.h" } #include @@ -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;