mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-06 13:14:21 +01:00
WMI (Windows): code refactor
This commit is contained in:
@@ -3,6 +3,7 @@ extern "C"
|
||||
#include "brightness.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
#include "util/windows/unicode.hpp"
|
||||
|
||||
extern "C"
|
||||
const char* ffDetectBrightness(FFlist* result)
|
||||
@@ -13,15 +14,19 @@ const char* ffDetectBrightness(FFlist* result)
|
||||
|
||||
while(FFWmiRecord record = query.next())
|
||||
{
|
||||
FFBrightnessResult* display = (FFBrightnessResult*) ffListAdd(result);
|
||||
ffStrbufInit(&display->name);
|
||||
record.getString(L"InstanceName", &display->name);
|
||||
ffStrbufSubstrAfterFirstC(&display->name, '\\');
|
||||
ffStrbufSubstrBeforeFirstC(&display->name, '\\');
|
||||
if(FFWmiVariant vtValue = record.get(L"CurrentBrightness"))
|
||||
{
|
||||
FFBrightnessResult* display = (FFBrightnessResult*) ffListAdd(result);
|
||||
display->value = vtValue.get<uint8_t>();
|
||||
|
||||
uint64_t brightness;
|
||||
record.getUnsigned(L"CurrentBrightness", &brightness);
|
||||
display->value = (float) brightness;
|
||||
ffStrbufInit(&display->name);
|
||||
if (FFWmiVariant vtName = record.get(L"InstanceName"))
|
||||
{
|
||||
ffStrbufSetWSV(&display->name, vtName.get<std::wstring_view>());
|
||||
ffStrbufSubstrAfterFirstC(&display->name, '\\');
|
||||
ffStrbufSubstrBeforeFirstC(&display->name, '\\');
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ extern "C" {
|
||||
#include "util/windows/registry.h"
|
||||
#include "util/smbiosHelper.h"
|
||||
}
|
||||
#include "util/windows/unicode.hpp"
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
static const char* detectWithRegistry(FFChassisResult* result)
|
||||
@@ -31,26 +32,33 @@ FF_MAYBE_UNUSED static const char* detectWithWmi(FFChassisResult* result)
|
||||
|
||||
if (FFWmiRecord record = query.next())
|
||||
{
|
||||
FFWmiVariant vtProp;
|
||||
if(FAILED(record.obj->Get(L"ChassisTypes", 0, &vtProp, nullptr, nullptr)))
|
||||
if (auto vtProp = record.get(L"ChassisTypes"))
|
||||
{
|
||||
auto [arr, len] = vtProp.get<std::pair<const int32_t*, uint32_t>>();
|
||||
if(len == 0)
|
||||
return "ChassisTypes contain no data failed";
|
||||
for (uint32_t i = 0; i < len; ++i)
|
||||
{
|
||||
if (i > 0)
|
||||
ffStrbufAppendS(&result->type, ", ");
|
||||
ffStrbufAppendS(&result->type, ffChassisTypeToString((uint32_t) arr[i]));
|
||||
}
|
||||
}
|
||||
else
|
||||
return "Get ChassisTypes failed";
|
||||
|
||||
auto [arr, len] = (std::pair<const int32_t*, uint32_t>) vtProp;
|
||||
|
||||
if(len == 0)
|
||||
return "ChassisTypes contain no data failed";
|
||||
|
||||
for (uint32_t i = 0; i < len; ++i)
|
||||
if (auto vtProp = record.get(L"Version"))
|
||||
{
|
||||
if (i > 0)
|
||||
ffStrbufAppendS(&result->type, ", ");
|
||||
ffStrbufAppendS(&result->type, ffChassisTypeToString((uint32_t) arr[i]));
|
||||
ffStrbufSetWSV(&result->version, vtProp.get<std::wstring_view>());
|
||||
ffCleanUpSmbiosValue(&result->version);
|
||||
}
|
||||
|
||||
if (auto vtProp = record.get(L"Manufacturer"))
|
||||
{
|
||||
ffStrbufSetWSV(&result->vendor, vtProp.get<std::wstring_view>());
|
||||
ffCleanUpSmbiosValue(&result->vendor);
|
||||
}
|
||||
|
||||
record.getString(L"Version", &result->version);
|
||||
ffCleanUpSmbiosValue(&result->version);
|
||||
record.getString(L"Manufacturer", &result->vendor);
|
||||
ffCleanUpSmbiosValue(&result->vendor);
|
||||
return NULL;
|
||||
}
|
||||
return "No WMI result returned";
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
extern "C" {
|
||||
#include "os.h"
|
||||
#include "util/windows/unicode.h"
|
||||
#include "common/library.h"
|
||||
}
|
||||
#include "util/windows/unicode.hpp"
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
static const char* getOsNameByWmi(FFstrbuf* osName)
|
||||
@@ -12,9 +13,13 @@ static const char* getOsNameByWmi(FFstrbuf* osName)
|
||||
|
||||
if(FFWmiRecord record = query.next())
|
||||
{
|
||||
record.getString(L"Caption", osName);
|
||||
ffStrbufTrimRight(osName, ' ');
|
||||
return NULL;
|
||||
if(auto vtCaption = record.get(L"Caption"))
|
||||
{
|
||||
ffStrbufSetWSV(osName, vtCaption.get<std::wstring_view>());
|
||||
ffStrbufTrimRight(osName, ' ');
|
||||
return NULL;
|
||||
}
|
||||
return "Get Caption failed";
|
||||
}
|
||||
|
||||
return "No WMI result returned";
|
||||
@@ -29,9 +34,9 @@ static const char* getOsNameByWinbrand(FFstrbuf* osName)
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(winbrand, BrandingFormatString);
|
||||
|
||||
const wchar_t* rawName = ffBrandingFormatString(L"%WINDOWS_LONG%");
|
||||
ffStrbufSetWS(osName, rawName);
|
||||
GlobalFree((HGLOBAL)rawName);
|
||||
return NULL;
|
||||
ffStrbufSetWS(osName, rawName);
|
||||
GlobalFree((HGLOBAL)rawName);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
|
||||
@@ -15,10 +15,21 @@ const char* ffDetectSmbiosTemp(double* current, double* critical)
|
||||
|
||||
if(FFWmiRecord record = query.next())
|
||||
{
|
||||
if (current && record.getReal(L"CurrentTemperature", current)) // In tenth of degrees Kelvin
|
||||
*current = *current / 10 - 273.15;
|
||||
if (critical && record.getReal(L"CriticalTripPoint", critical)) // In tenth of degrees Kelvin
|
||||
*critical = *critical / 10 - 273.15;
|
||||
if (current)
|
||||
{
|
||||
if(auto vtCurrent = record.get(L"CurrentTemperature"))
|
||||
*current = vtCurrent.get<int32_t>() / 10 - 273.15; // In tenth of degrees Kelvin
|
||||
else
|
||||
*current = 0.0/0.0;
|
||||
}
|
||||
|
||||
if (critical)
|
||||
{
|
||||
if(auto vtCritical = record.get(L"CriticalTripPoint"))
|
||||
*critical = vtCritical.get<int32_t>() / 10 - 273.15; // In tenth of degrees Kelvin
|
||||
else
|
||||
*critical = 0.0/0.0;
|
||||
}
|
||||
}
|
||||
|
||||
return "No WMI result returned";
|
||||
|
||||
Reference in New Issue
Block a user