mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Kernel: fix detection on Windows
According to MSDN, GetVersionExA is not reliable. We have to query WMI instead.
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
// https://github.com/tniessen/iperf-windows/blob/master/win32-compat/sys/utsname.c
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "utsname.h"
|
||||
|
||||
int uname(struct utsname *name)
|
||||
{
|
||||
memset(name, 0, sizeof(*name));
|
||||
|
||||
// Get Windows version info
|
||||
OSVERSIONINFOA versionInfo = {
|
||||
.dwOSVersionInfoSize = sizeof(OSVERSIONINFO),
|
||||
};
|
||||
GetVersionExA(&versionInfo);
|
||||
|
||||
// Get hardware info
|
||||
SYSTEM_INFO sysInfo = {0};
|
||||
GetSystemInfo(&sysInfo);
|
||||
|
||||
// Set implementation name
|
||||
strcpy(name->sysname, "Windows_NT");
|
||||
sprintf(name->release, "%u.%u.%u", (unsigned)versionInfo.dwMajorVersion, (unsigned)versionInfo.dwMinorVersion, (unsigned)versionInfo.dwBuildNumber);
|
||||
name->version[0] = '\0';
|
||||
|
||||
// Set hostname
|
||||
DWORD bufSize = UTSNAME_MAXLENGTH - 1;
|
||||
if(GetComputerNameA(name->nodename, &bufSize))
|
||||
return 1;
|
||||
name->nodename[bufSize] = '\0';
|
||||
|
||||
// Set processor architecture
|
||||
switch (sysInfo.wProcessorArchitecture)
|
||||
{
|
||||
case PROCESSOR_ARCHITECTURE_AMD64:
|
||||
strcpy(name->machine, "x86_64");
|
||||
break;
|
||||
case PROCESSOR_ARCHITECTURE_IA64:
|
||||
strcpy(name->machine, "ia64");
|
||||
break;
|
||||
case PROCESSOR_ARCHITECTURE_INTEL:
|
||||
strcpy(name->machine, "x86");
|
||||
break;
|
||||
case PROCESSOR_ARCHITECTURE_ARM64:
|
||||
strcpy(name->machine, "aarch64");
|
||||
break;
|
||||
case PROCESSOR_ARCHITECTURE_ARM:
|
||||
strcpy(name->machine, "arm");
|
||||
break;
|
||||
case PROCESSOR_ARCHITECTURE_UNKNOWN:
|
||||
default:
|
||||
strcpy(name->machine, "unknown");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "util/windows/wmi.hpp"
|
||||
extern "C" {
|
||||
#include "utsname.h"
|
||||
}
|
||||
|
||||
int uname(struct utsname *name)
|
||||
{
|
||||
memset(name, 0, sizeof(*name));
|
||||
|
||||
strncpy(name->sysname, "Windows_NT", UTSNAME_MAXLENGTH);
|
||||
|
||||
IEnumWbemClassObject* pEnumerator = ffQueryWmi(L"SELECT Version, CSName, OSArchitecture FROM Win32_OperatingSystem", nullptr);
|
||||
if(!pEnumerator)
|
||||
return -1;
|
||||
|
||||
IWbemClassObject *pclsObj = NULL;
|
||||
ULONG uReturn = 0;
|
||||
|
||||
if(FAILED(pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn)) || uReturn == 0)
|
||||
{
|
||||
pEnumerator->Release();
|
||||
return -1;
|
||||
}
|
||||
|
||||
FFstrbuf value;
|
||||
ffStrbufInit(&value);
|
||||
ffGetWmiObjString(pclsObj, L"Version", &value);
|
||||
strncpy(name->release, value.chars, UTSNAME_MAXLENGTH);
|
||||
|
||||
ffStrbufClear(&value);
|
||||
ffGetWmiObjString(pclsObj, L"CSName", &value);
|
||||
strncpy(name->nodename, value.chars, UTSNAME_MAXLENGTH);
|
||||
|
||||
ffStrbufClear(&value);
|
||||
ffGetWmiObjString(pclsObj, L"OSArchitecture", &value);
|
||||
strncpy(name->machine, value.chars, UTSNAME_MAXLENGTH);
|
||||
|
||||
ffStrbufDestroy(&value);
|
||||
pclsObj->Release();
|
||||
pEnumerator->Release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user