From f64bf732799c8b0c4221eaaf61d55e9ea8477193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Mon, 21 Aug 2023 20:24:15 +0800 Subject: [PATCH] Windows: fix compiling for GCC --- CHANGELOG.md | 7 ++ src/util/windows/wmi.hpp | 212 ++++++++++++++++++++------------------- 2 files changed, 116 insertions(+), 103 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b9cf6773e..7aa6c602b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# 2.0.2 + +Fix compiling for MSYS2, no functional changes. + +Bugfixes: +* Workarund [a compiler bug of GCC](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85282) (Windows) + # 2.0.1 First stable release of Fastfetch V2 diff --git a/src/util/windows/wmi.hpp b/src/util/windows/wmi.hpp index 29ff621a0..f9719a664 100644 --- a/src/util/windows/wmi.hpp +++ b/src/util/windows/wmi.hpp @@ -14,6 +14,7 @@ extern "C" { #include #include #include +#include enum class FFWmiNamespace { CIMV2, @@ -36,115 +37,120 @@ struct FFWmiVariant: VARIANT { return this->hasValue(); } - template T get(); + template T get() + { + // boolean + if constexpr (std::is_same_v) { + assert(this->vt == VT_BOOL); + return this->boolVal != VARIANT_FALSE; + } - // boolean - template <> bool get() { - assert(this->vt == VT_BOOL); - return this->boolVal != VARIANT_FALSE; - } + // signed + else if constexpr (std::is_same_v) { + assert(this->vt == VT_I1); + return this->cVal; + } + else if constexpr (std::is_same_v) { + assert(vt == VT_I2); + return this->iVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_I4 || vt == VT_INT); + return this->intVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_I8); + return this->llVal; + } - // signed - template <> int8_t get() { - assert(this->vt == VT_I1); - return this->cVal; - } - template <> int16_t get() { - assert(vt == VT_I2); - return this->iVal; - } - template <> int32_t get() { - assert(this->vt == VT_I4 || vt == VT_INT); - return this->intVal; - } - template <> int64_t get() { - assert(this->vt == VT_I8); - return this->llVal; - } + // unsigned + else if constexpr (std::is_same_v) { + assert(this->vt == VT_UI1); + return this->bVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_UI2); + return this->uiVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_UI4 || vt == VT_UINT); + return this->uintVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_UI8); + return this->ullVal; + } - // unsigned - template <> uint8_t get() { - assert(this->vt == VT_UI1); - return this->bVal; - } - template <> uint16_t get() { - assert(this->vt == VT_UI2); - return this->uiVal; - } - template <> uint32_t get() { - assert(this->vt == VT_UI4 || vt == VT_UINT); - return this->uintVal; - } - template <> uint64_t get() { - assert(this->vt == VT_UI8); - return this->ullVal; - } + // decimal + else if constexpr (std::is_same_v) { + assert(this->vt == VT_R4); + return this->fltVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_R8); + return this->dblVal; + } - // decimal - template <> float get() { - assert(this->vt == VT_R4); - return this->fltVal; - } - template <> double get() { - assert(this->vt == VT_R8); - return this->dblVal; - } + // string + else if constexpr (std::is_same_v) { + assert(this->vt == VT_LPSTR); + return this->pcVal; + } + else if constexpr (std::is_same_v) { + assert(this->vt == VT_BSTR || this->vt == VT_LPWSTR); + if (this->vt == VT_LPWSTR) + return this->bstrVal; + else + return { this->bstrVal, SysStringLen(this->bstrVal) }; + } - // string - template <> std::string_view get() { - assert(this->vt == VT_LPSTR); - return this->pcVal; - } - template <> std::wstring_view get() { - assert(this->vt == VT_BSTR || this->vt == VT_LPWSTR); - if (this->vt == VT_LPWSTR) - return this->bstrVal; - else - return { this->bstrVal, SysStringLen(this->bstrVal) }; - } + // array signed + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_I1); + return std::make_pair((int8_t*)this->parray->pvData, this->parray->cDims); + } + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_I2); + return std::make_pair((int16_t*)this->parray->pvData, this->parray->cDims); + } + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_I4); + return std::make_pair((int32_t*)this->parray->pvData, this->parray->cDims); + } + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_I8); + return std::make_pair((int64_t*)this->parray->pvData, this->parray->cDims); + } - // array signed - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_I1); - return std::make_pair((int8_t*)this->parray->pvData, this->parray->cDims); - } - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_I2); - return std::make_pair((int16_t*)this->parray->pvData, this->parray->cDims); - } - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_I4); - return std::make_pair((int32_t*)this->parray->pvData, this->parray->cDims); - } - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_I8); - return std::make_pair((int64_t*)this->parray->pvData, this->parray->cDims); - } - - // array unsigned - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_UI1); - return std::make_pair((uint8_t*)this->parray->pvData, this->parray->cDims); - } - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_UI2); - return std::make_pair((uint16_t*)this->parray->pvData, this->parray->cDims); - } - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_UI4); - return std::make_pair((uint32_t*)this->parray->pvData, this->parray->cDims); - } - template <> std::pair get() { - assert(this->vt & VT_ARRAY); - assert((this->vt & ~VT_ARRAY) == VT_UI8); - return std::make_pair((uint64_t*)this->parray->pvData, this->parray->cDims); + // array unsigned + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_UI1); + return std::make_pair((uint8_t*)this->parray->pvData, this->parray->cDims); + } + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_UI2); + return std::make_pair((uint16_t*)this->parray->pvData, this->parray->cDims); + } + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_UI4); + return std::make_pair((uint32_t*)this->parray->pvData, this->parray->cDims); + } + else if constexpr (std::is_same_v>) { + assert(this->vt & VT_ARRAY); + assert((this->vt & ~VT_ARRAY) == VT_UI8); + return std::make_pair((uint64_t*)this->parray->pvData, this->parray->cDims); + } + else { + assert(false && "unsupported type"); + __builtin_unreachable(); + } } };