mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
OS: add support for Windows
This commit is contained in:
+1
-1
@@ -318,6 +318,7 @@ if(WIN_MSYS)
|
||||
src/detection/wmtheme/wmtheme_windows.c
|
||||
src/detection/opengl/opengl_windows.c
|
||||
src/detection/users/users_windows.cpp
|
||||
src/detection/os/os_windows.cpp
|
||||
src/util/windows/wmi.cpp
|
||||
|
||||
# Shared
|
||||
@@ -325,7 +326,6 @@ if(WIN_MSYS)
|
||||
src/detection/poweradapter/poweradapter_linux.c
|
||||
|
||||
# TODO
|
||||
src/detection/os/os_linux.c
|
||||
src/detection/media/media_linux.c
|
||||
src/detection/font/font_linux.c
|
||||
src/detection/cpu/cpu_linux.c
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
extern "C" {
|
||||
#include "os.h"
|
||||
}
|
||||
#include "util/windows/wmi.hpp"
|
||||
|
||||
extern "C"
|
||||
void ffDetectOSImpl(FFOSResult* os, const FFinstance* instance)
|
||||
{
|
||||
ffStrbufInit(&os->name);
|
||||
ffStrbufInit(&os->prettyName);
|
||||
ffStrbufInit(&os->id);
|
||||
ffStrbufInit(&os->idLike);
|
||||
ffStrbufInit(&os->variant);
|
||||
ffStrbufInit(&os->variantID);
|
||||
ffStrbufInit(&os->version);
|
||||
ffStrbufInit(&os->versionID);
|
||||
ffStrbufInit(&os->codename);
|
||||
ffStrbufInit(&os->buildID);
|
||||
ffStrbufInit(&os->systemName);
|
||||
ffStrbufInit(&os->architecture);
|
||||
|
||||
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT Caption, Version, BuildNumber, OSArchitecture FROM Win32_OperatingSystem", nullptr);
|
||||
|
||||
if(!pEnumerator)
|
||||
return;
|
||||
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
|
||||
{
|
||||
pEnumerator->Release();
|
||||
return;
|
||||
}
|
||||
|
||||
ffGetWmiObjValue(pclsObj, L"Caption", &os->variant); // Microsoft Windows 11 家庭中文版
|
||||
if(ffStrbufStartsWithS(&os->variant, "Microsoft Windows "))
|
||||
{
|
||||
ffStrbufAppendS(&os->name, "Microsoft Windows");
|
||||
ffStrbufAppendS(&os->prettyName, "Windows");
|
||||
|
||||
ffStrbufSubstrAfter(&os->variant, strlen("Microsoft Windows ") - 1); // 11 家庭中文版
|
||||
uint32_t index = ffStrbufFirstIndexC(&os->variant, ' ');
|
||||
ffStrbufAppendNS(&os->version, index, os->variant.chars);
|
||||
ffStrbufSubstrAfter(&os->variant, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unknown Windows name, please report this
|
||||
ffStrbufAppend(&os->name, &os->variant);
|
||||
ffStrbufClear(&os->variant);
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
ffStrbufAppendS(&os->id, "MSYS2");
|
||||
#else
|
||||
// Enable this after we have Windows logo support
|
||||
ffStrbufAppendF(&os->id, "Windows %*s", &os->version.length, &os->version.chars);
|
||||
#endif
|
||||
|
||||
ffGetWmiObjValue(pclsObj, L"BuildNumber", &os->buildID);
|
||||
ffGetWmiObjValue(pclsObj, L"OSArchitecture", &os->architecture);
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
ffStrbufSetS(&os->systemName, instance->state.utsname.sysname);
|
||||
#else
|
||||
ffStrbufSetS(&os->systemName, "Windows");
|
||||
#endif
|
||||
|
||||
pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
}
|
||||
Reference in New Issue
Block a user