Kernel (Windows): move kernel.displayVersion to OS.codeName

This commit is contained in:
李通洲
2025-09-30 10:01:01 +08:00
parent 9b1e318bd1
commit 1594a69d6c
6 changed files with 40 additions and 36 deletions
+20
View File
@@ -2,11 +2,28 @@
#include "common/library.h"
#include "util/windows/unicode.h"
#include "util/stringUtils.h"
#include "util/windows/registry.h"
#include <windows.h>
PWSTR WINAPI BrandingFormatString(PCWSTR format);
static bool getCodeName(FFOSResult* os)
{
FF_HKEY_AUTO_DESTROY hKey = NULL;
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hKey, NULL))
return false;
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &os->codename, NULL))
{
if (!ffRegReadStrbuf(hKey, L"CSDVersion", &os->codename, NULL)) // For Windows 7 and Windows 8
if (!ffRegReadStrbuf(hKey, L"ReleaseId", &os->codename, NULL)) // For old Windows 10
return false;
}
return true;
}
void ffDetectOSImpl(FFOSResult* os)
{
//https://dennisbabkin.com/blog/?t=how-to-tell-the-real-version-of-windows-your-app-is-running-on#ver_string
@@ -57,4 +74,7 @@ void ffDetectOSImpl(FFOSResult* os)
ffStrbufAppendF(&os->id, "%s %s", os->name.chars, os->version.chars);
ffStrbufSetStatic(&os->idLike, "Windows");
if (getCodeName(os) && os->codename.length > 0)
ffStrbufAppendF(&os->prettyName, " (%s)", os->codename.chars);
}
+1 -8
View File
@@ -10,12 +10,7 @@ bool ffPrintKernel(FFKernelOptions* options)
if(options->moduleArgs.outputFormat.length == 0)
{
ffPrintLogoAndKey(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
printf("%s %s", info->name.chars, info->release.chars);
if(info->displayVersion.length > 0)
printf(" (%s)\n", info->displayVersion.chars);
else
putchar('\n');
printf("%s %s\n", info->name.chars, info->release.chars);
}
else
{
@@ -26,7 +21,6 @@ bool ffPrintKernel(FFKernelOptions* options)
FF_FORMAT_ARG(info->release, "release"),
FF_FORMAT_ARG(info->version, "version"),
FF_FORMAT_ARG(info->architecture, "arch"),
FF_FORMAT_ARG(info->displayVersion, "display-version"),
FF_FORMAT_ARG(str, "page-size"),
}));
}
@@ -61,7 +55,6 @@ bool ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson
yyjson_mut_obj_add_strbuf(doc, obj, "name", &info->name);
yyjson_mut_obj_add_strbuf(doc, obj, "release", &info->release);
yyjson_mut_obj_add_strbuf(doc, obj, "version", &info->version);
yyjson_mut_obj_add_strbuf(doc, obj, "displayVersion", &info->displayVersion);
yyjson_mut_obj_add_uint(doc, obj, "pageSize", info->pageSize);
return true;
-1
View File
@@ -56,7 +56,6 @@ void ffPlatformDestroy(FFPlatform* platform)
ffStrbufDestroy(&info->name);
ffStrbufDestroy(&info->release);
ffStrbufDestroy(&info->version);
ffStrbufDestroy(&info->displayVersion);
}
void ffPlatformPathAddAbsolute(FFlist* dirs, const char* path)
-1
View File
@@ -9,7 +9,6 @@ typedef struct FFPlatformSysinfo
FFstrbuf release;
FFstrbuf version;
FFstrbuf architecture;
FFstrbuf displayVersion;
uint32_t pageSize;
} FFPlatformSysinfo;
-1
View File
@@ -211,7 +211,6 @@ static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts)
else
#endif
ffStrbufAppendS(&info->architecture, uts->machine);
ffStrbufInit(&info->displayVersion);
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__)
size_t length = sizeof(info->pageSize);
+19 -25
View File
@@ -168,15 +168,14 @@ static void getUserShell(FFPlatform* platform)
ffStrbufReplaceAllC(&platform->userShell, '\\', '/');
}
static void detectWine(FFstrbuf* buf)
static const char* detectWine(void)
{
const char * __cdecl wine_get_version(void);
HMODULE hntdll = GetModuleHandleW(L"ntdll.dll");
if (!hntdll) return;
if (!hntdll) return NULL;
FF_LIBRARY_LOAD_SYMBOL_LAZY(hntdll, wine_get_version);
if (!ffwine_get_version) return;
ffStrbufAppendS(buf, buf->length ? " - wine " : "wine ");
ffStrbufAppendS(buf, ffwine_get_version());
if (!ffwine_get_version) return NULL;
return ffwine_get_version();
}
static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
@@ -199,29 +198,24 @@ static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
(unsigned) osVersion.dwBuildNumber,
(unsigned) ubr);
ffStrbufInit(&info->displayVersion);
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &info->displayVersion, NULL))
{
if (osVersion.szCSDVersion[0])
ffStrbufSetWS(&info->displayVersion, osVersion.szCSDVersion);
else
ffRegReadStrbuf(hKey, L"ReleaseId", &info->displayVersion, NULL); // For old Windows 10
}
detectWine(&info->displayVersion);
ffRegReadStrbuf(hKey, L"BuildLabEx", &info->version, NULL);
switch (osVersion.dwPlatformId)
const char* wineVersion = detectWine();
if (wineVersion)
ffStrbufSetF(&info->name, "Wine_%s", wineVersion);
{
case VER_PLATFORM_WIN32s:
ffStrbufSetStatic(&info->name, "WIN32s");
break;
case VER_PLATFORM_WIN32_WINDOWS:
ffStrbufSetStatic(&info->name, "WIN32_WINDOWS");
break;
case VER_PLATFORM_WIN32_NT:
ffStrbufSetStatic(&info->name, "WIN32_NT");
break;
switch (osVersion.dwPlatformId)
{
case VER_PLATFORM_WIN32s:
ffStrbufSetStatic(&info->name, "WIN32s");
break;
case VER_PLATFORM_WIN32_WINDOWS:
ffStrbufSetStatic(&info->name, "WIN32_WINDOWS");
break;
case VER_PLATFORM_WIN32_NT:
ffStrbufSetStatic(&info->name, "WIN32_NT");
break;
}
}
}