Files
fastfetch/src/detection/font/font_windows.cpp
T
李通洲 e8e586ce7c Windows / macOS: simplify code
1. simplify resource management by using C++ RAII like GCC attribute extension `cleanup`
2. simplify HEKY reading

Actually `__attribute__((__cleanup__(cleanupFn)))` is supported on all major C compiler ( gcc, clang and icc ) except MSVC I only used it on Windows and macOS for now. Let's see if the project author like it.
2022-11-17 19:54:36 +08:00

33 lines
906 B
C++

extern "C" {
#include "font.h"
#include "common/font.h"
}
#include "util/windows/wmi.hpp"
#include <wchar.h>
extern "C"
void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result)
{
wchar_t sql[256] = {};
swprintf(sql, 256, L"SELECT IconTitleFaceName, IconTitleSize FROM Win32_Desktop WHERE Name LIKE '%%\\\\%s'", instance->state.passwd->pw_name);
FFWmiQuery query(sql, &result->error);
if(!query)
return;
if(FFWmiRecord record = query.next())
{
FF_STRBUF_AUTO_DESTROY fontName;
ffStrbufInit(&fontName);
record.getString(L"IconTitleFaceName", &fontName);
uint64_t fontSize;
record.getUnsigned(L"IconTitleSize", &fontSize);
ffStrbufAppendF(&result->fonts[0], "%*s (%upt)", fontName.length, fontName.chars, (unsigned)fontSize);
}
else
ffStrbufInitS(&result->error, "No WMI result returned");
}