mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2025-02-20 11:43:27 +08:00
Monitor (Windows): code refactor
This commit is contained in:
parent
519f3bfd50
commit
46b0c6e76b
@ -2,6 +2,7 @@
|
||||
|
||||
#include "common/io/io.h"
|
||||
#include "util/edidHelper.h"
|
||||
#include "util/mallocHelper.h"
|
||||
#include "util/stringUtils.h"
|
||||
#include "util/windows/registry.h"
|
||||
#include "util/windows/unicode.h"
|
||||
@ -30,8 +31,12 @@ const char* ffDetectMonitor(FFlist* results)
|
||||
FF_HKEY_AUTO_DESTROY hKey = SetupDiOpenDevRegKey(hdev, &did, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_QUERY_VALUE);
|
||||
if (!hKey) continue;
|
||||
|
||||
uint8_t edidData[256] = {};
|
||||
if (!ffRegReadData(hKey, L"EDID", edidData, sizeof(edidData), NULL)) continue;
|
||||
FF_AUTO_FREE uint8_t* edidData = NULL;
|
||||
uint32_t edidLength = 0;
|
||||
if (!ffRegReadData(hKey, L"EDID", &edidData, &edidLength, NULL)) continue;
|
||||
if (edidLength == 0 || edidLength % 128 != 0)
|
||||
continue;
|
||||
|
||||
uint32_t width, height;
|
||||
ffEdidGetPhysicalResolution(edidData, &width, &height);
|
||||
if (width == 0 || height == 0) continue;
|
||||
@ -39,6 +44,7 @@ const char* ffDetectMonitor(FFlist* results)
|
||||
FFMonitorResult* display = (FFMonitorResult*) ffListAdd(results);
|
||||
display->width = width;
|
||||
display->height = height;
|
||||
display->hdrCompatible = ffEdidGetHdrCompatible(edidData, edidLength); // Doesn't work. edidLength is always 128
|
||||
ffStrbufInit(&display->name);
|
||||
ffEdidGetName(edidData, &display->name);
|
||||
ffEdidGetPhysicalSize(edidData, &display->physicalWidth, &display->physicalHeight);
|
||||
|
@ -64,10 +64,25 @@ bool ffRegReadStrbuf(HKEY hKey, const wchar_t* valueNameW, FFstrbuf* result, FFs
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ffRegReadData(HKEY hKey, const wchar_t* valueNameW, uint8_t* result, uint32_t bufSize, FFstrbuf* error)
|
||||
bool ffRegReadData(HKEY hKey, const wchar_t* valueNameW, uint8_t** result, uint32_t* length, FFstrbuf* error)
|
||||
{
|
||||
static_assert(sizeof(DWORD) == sizeof(uint32_t), "");
|
||||
LONG err = RegGetValueW(hKey, NULL, valueNameW, RRF_RT_REG_BINARY, NULL, result, (DWORD*) &bufSize);
|
||||
assert(result && length);
|
||||
DWORD bufSize = 0;
|
||||
LONG err = RegGetValueW(hKey, NULL, valueNameW, RRF_RT_REG_BINARY, NULL, NULL, &bufSize);
|
||||
if(err != ERROR_SUCCESS || bufSize == 0)
|
||||
{
|
||||
if(error)
|
||||
{
|
||||
if(!valueNameW)
|
||||
valueNameW = L"(default)";
|
||||
FF_STRBUF_AUTO_DESTROY valueNameA = ffStrbufCreateWS(valueNameW);
|
||||
ffStrbufAppendF(error, "RegGetValueW(%s, NULL, RRF_RT_REG_BINARY, NULL, NULL, &bufSize) failed", valueNameA.chars);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t* buf = (uint8_t*) malloc(bufSize);
|
||||
err = RegGetValueW(hKey, NULL, valueNameW, RRF_RT_REG_BINARY, NULL, buf, &bufSize);
|
||||
if(err != ERROR_SUCCESS)
|
||||
{
|
||||
if(error)
|
||||
@ -75,10 +90,13 @@ bool ffRegReadData(HKEY hKey, const wchar_t* valueNameW, uint8_t* result, uint32
|
||||
if(!valueNameW)
|
||||
valueNameW = L"(default)";
|
||||
FF_STRBUF_AUTO_DESTROY valueNameA = ffStrbufCreateWS(valueNameW);
|
||||
ffStrbufAppendF(error, "RegGetValueW(%s, NULL, RRF_RT_REG_SZ) failed", valueNameA.chars);
|
||||
ffStrbufAppendF(error, "RegGetValueW(%s, NULL, RRF_RT_REG_BINARY, NULL, length) failed", valueNameA.chars);
|
||||
}
|
||||
free(buf);
|
||||
return false;
|
||||
}
|
||||
*result = buf;
|
||||
*length = bufSize;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ static inline void wrapRegCloseKey(HKEY* phKey)
|
||||
|
||||
bool ffRegOpenKeyForRead(HKEY hKey, const wchar_t* subKeyW, HKEY* result, FFstrbuf* error);
|
||||
bool ffRegReadStrbuf(HKEY hKey, const wchar_t* valueNameW, FFstrbuf* result, FFstrbuf* error);
|
||||
bool ffRegReadData(HKEY hKey, const wchar_t* valueNameW, uint8_t* result, uint32_t bufSize, FFstrbuf* error);
|
||||
bool ffRegReadData(HKEY hKey, const wchar_t* valueNameW, uint8_t** result, uint32_t* length, FFstrbuf* error);
|
||||
bool ffRegReadUint(HKEY hKey, const wchar_t* valueNameW, uint32_t* result, FFstrbuf* error);
|
||||
bool ffRegReadUint64(HKEY hKey, const wchar_t* valueNameW, uint64_t* result, FFstrbuf* error);
|
||||
bool ffRegGetSubKey(HKEY hKey, uint32_t index, FFstrbuf* result, FFstrbuf* error);
|
||||
|
Loading…
x
Reference in New Issue
Block a user