mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Kernel (Windows): detect service pack version
This commit is contained in:
@@ -21,6 +21,7 @@ typedef struct FFPlatform {
|
||||
FFstrbuf systemRelease;
|
||||
FFstrbuf systemVersion;
|
||||
FFstrbuf systemArchitecture;
|
||||
FFstrbuf systemDisplayVersion;
|
||||
} FFPlatform;
|
||||
|
||||
void ffPlatformInit(FFPlatform* platform);
|
||||
|
||||
@@ -175,4 +175,5 @@ void ffPlatformInitImpl(FFPlatform* platform)
|
||||
ffStrbufAppendS(&platform->systemRelease, uts.release);
|
||||
ffStrbufAppendS(&platform->systemVersion, uts.version);
|
||||
ffStrbufAppendS(&platform->systemArchitecture, uts.machine);
|
||||
ffStrbufInit(&platform->systemVersion);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,16 @@
|
||||
#include "common/io/io.h"
|
||||
#include "util/stringUtils.h"
|
||||
#include "util/windows/unicode.h"
|
||||
#include "util/windows/registry.h"
|
||||
|
||||
#include <winternl.h>
|
||||
#include <Windows.h>
|
||||
#include <shlobj.h>
|
||||
|
||||
NTSTATUS NTAPI RtlGetVersion(
|
||||
_Inout_ PRTL_OSVERSIONINFOW lpVersionInformation
|
||||
);
|
||||
|
||||
static void getExePath(FFPlatform* platform)
|
||||
{
|
||||
wchar_t exePathW[MAX_PATH];
|
||||
@@ -137,55 +143,44 @@ static void getUserShell(FFPlatform* platform)
|
||||
ffStrbufReplaceAllC(&platform->userShell, '\\', '/');
|
||||
}
|
||||
|
||||
static void getSystemName(FFPlatform* platform)
|
||||
{
|
||||
ffStrbufAppendS(&platform->systemName, getenv("OS"));
|
||||
}
|
||||
|
||||
static void getSystemReleaseAndVersion(FFPlatform* platform)
|
||||
{
|
||||
HKEY hKey;
|
||||
if(RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
|
||||
RTL_OSVERSIONINFOW osVersion = { .dwOSVersionInfoSize = sizeof(osVersion) };
|
||||
if (!NT_SUCCESS(RtlGetVersion(&osVersion)))
|
||||
return;
|
||||
|
||||
DWORD bufSize;
|
||||
FF_HKEY_AUTO_DESTROY hKey = NULL;
|
||||
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hKey, NULL))
|
||||
return;
|
||||
|
||||
char currentVersion[32];
|
||||
uint32_t ubr = 0;
|
||||
ffRegReadUint(hKey, L"UBR", &ubr, NULL);
|
||||
|
||||
ffStrbufAppendF(&platform->systemRelease,
|
||||
"%u.%u.%u.%u",
|
||||
(unsigned) osVersion.dwMajorVersion,
|
||||
(unsigned) osVersion.dwMinorVersion,
|
||||
(unsigned) osVersion.dwBuildNumber,
|
||||
(unsigned) ubr);
|
||||
|
||||
ffStrbufInit(&platform->systemDisplayVersion);
|
||||
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &platform->systemDisplayVersion, NULL) && osVersion.szCSDVersion[0])
|
||||
ffStrbufSetWS(&platform->systemDisplayVersion, osVersion.szCSDVersion);
|
||||
|
||||
ffRegReadStrbuf(hKey, L"BuildLabEx", &platform->systemVersion, NULL);
|
||||
|
||||
switch (osVersion.dwPlatformId)
|
||||
{
|
||||
DWORD currentMajorVersionNumber;
|
||||
DWORD currentMinorVersionNumber;
|
||||
bufSize = sizeof(currentMajorVersionNumber);
|
||||
if(RegGetValueW(hKey, NULL, L"CurrentMajorVersionNumber", RRF_RT_REG_DWORD, NULL, ¤tMajorVersionNumber, &bufSize) == ERROR_SUCCESS &&
|
||||
RegGetValueW(hKey, NULL, L"CurrentMinorVersionNumber", RRF_RT_REG_DWORD, NULL, ¤tMinorVersionNumber, &bufSize) == ERROR_SUCCESS
|
||||
)
|
||||
snprintf(currentVersion, sizeof(currentVersion), "%u.%u", (unsigned)currentMajorVersionNumber, (unsigned)currentMinorVersionNumber);
|
||||
else
|
||||
{
|
||||
bufSize = sizeof(currentVersion);
|
||||
if(RegGetValueA(hKey, NULL, "CurrentVersion", RRF_RT_REG_SZ, NULL, currentVersion, &bufSize) != ERROR_SUCCESS)
|
||||
strcpy(currentVersion, "0.0");
|
||||
}
|
||||
case VER_PLATFORM_WIN32s:
|
||||
ffStrbufAppendS(&platform->systemName, "WIN32s");
|
||||
break;
|
||||
case VER_PLATFORM_WIN32_WINDOWS:
|
||||
ffStrbufAppendS(&platform->systemName, "WIN32_WINDOWS");
|
||||
break;
|
||||
case VER_PLATFORM_WIN32_NT:
|
||||
ffStrbufAppendS(&platform->systemName, "WIN32_NT");
|
||||
break;
|
||||
}
|
||||
|
||||
char currentBuildNumber[32];
|
||||
bufSize = sizeof(currentBuildNumber);
|
||||
if(RegGetValueA(hKey, NULL, "CurrentBuildNumber", RRF_RT_REG_SZ, NULL, currentBuildNumber, &bufSize) != ERROR_SUCCESS)
|
||||
strcpy(currentBuildNumber, "0");
|
||||
|
||||
DWORD ubr;
|
||||
bufSize = sizeof(ubr);
|
||||
if(RegGetValueW(hKey, NULL, L"UBR", RRF_RT_REG_DWORD, NULL, &ubr, &bufSize) != ERROR_SUCCESS || bufSize != sizeof(ubr))
|
||||
ubr = 0;
|
||||
|
||||
ffStrbufAppendF(&platform->systemRelease, "%s.%s.%u", currentVersion, currentBuildNumber, (unsigned)ubr);
|
||||
|
||||
ffStrbufEnsureFree(&platform->systemVersion, 256);
|
||||
bufSize = (DWORD) ffStrbufGetFree(&platform->systemVersion);
|
||||
if(RegGetValueA(hKey, NULL, "DisplayVersion", RRF_RT_REG_SZ, NULL, platform->systemVersion.chars, &bufSize) == ERROR_SUCCESS)
|
||||
platform->systemVersion.length = (uint32_t) bufSize - 1;
|
||||
|
||||
RegCloseKey(hKey);
|
||||
}
|
||||
|
||||
static void getSystemArchitecture(FFPlatform* platform)
|
||||
@@ -234,7 +229,6 @@ void ffPlatformInitImpl(FFPlatform* platform)
|
||||
getHostName(platform);
|
||||
getUserShell(platform);
|
||||
|
||||
getSystemName(platform);
|
||||
getSystemReleaseAndVersion(platform);
|
||||
getSystemArchitecture(platform);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user