Skip to content

Commit 1594a69

Browse files
committed
Kernel (Windows): move kernel.displayVersion to OS.codeName
1 parent 9b1e318 commit 1594a69

File tree

6 files changed

+40
-36
lines changed

6 files changed

+40
-36
lines changed

src/detection/os/os_windows.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,28 @@
22
#include "common/library.h"
33
#include "util/windows/unicode.h"
44
#include "util/stringUtils.h"
5+
#include "util/windows/registry.h"
56

67
#include <windows.h>
78

89
PWSTR WINAPI BrandingFormatString(PCWSTR format);
910

11+
static bool getCodeName(FFOSResult* os)
12+
{
13+
FF_HKEY_AUTO_DESTROY hKey = NULL;
14+
if(!ffRegOpenKeyForRead(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", &hKey, NULL))
15+
return false;
16+
17+
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &os->codename, NULL))
18+
{
19+
if (!ffRegReadStrbuf(hKey, L"CSDVersion", &os->codename, NULL)) // For Windows 7 and Windows 8
20+
if (!ffRegReadStrbuf(hKey, L"ReleaseId", &os->codename, NULL)) // For old Windows 10
21+
return false;
22+
}
23+
24+
return true;
25+
}
26+
1027
void ffDetectOSImpl(FFOSResult* os)
1128
{
1229
//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)
5774

5875
ffStrbufAppendF(&os->id, "%s %s", os->name.chars, os->version.chars);
5976
ffStrbufSetStatic(&os->idLike, "Windows");
77+
78+
if (getCodeName(os) && os->codename.length > 0)
79+
ffStrbufAppendF(&os->prettyName, " (%s)", os->codename.chars);
6080
}

src/modules/kernel/kernel.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,7 @@ bool ffPrintKernel(FFKernelOptions* options)
1010
if(options->moduleArgs.outputFormat.length == 0)
1111
{
1212
ffPrintLogoAndKey(FF_KERNEL_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
13-
printf("%s %s", info->name.chars, info->release.chars);
14-
15-
if(info->displayVersion.length > 0)
16-
printf(" (%s)\n", info->displayVersion.chars);
17-
else
18-
putchar('\n');
13+
printf("%s %s\n", info->name.chars, info->release.chars);
1914
}
2015
else
2116
{
@@ -26,7 +21,6 @@ bool ffPrintKernel(FFKernelOptions* options)
2621
FF_FORMAT_ARG(info->release, "release"),
2722
FF_FORMAT_ARG(info->version, "version"),
2823
FF_FORMAT_ARG(info->architecture, "arch"),
29-
FF_FORMAT_ARG(info->displayVersion, "display-version"),
3024
FF_FORMAT_ARG(str, "page-size"),
3125
}));
3226
}
@@ -61,7 +55,6 @@ bool ffGenerateKernelJsonResult(FF_MAYBE_UNUSED FFKernelOptions* options, yyjson
6155
yyjson_mut_obj_add_strbuf(doc, obj, "name", &info->name);
6256
yyjson_mut_obj_add_strbuf(doc, obj, "release", &info->release);
6357
yyjson_mut_obj_add_strbuf(doc, obj, "version", &info->version);
64-
yyjson_mut_obj_add_strbuf(doc, obj, "displayVersion", &info->displayVersion);
6558
yyjson_mut_obj_add_uint(doc, obj, "pageSize", info->pageSize);
6659

6760
return true;

src/util/platform/FFPlatform.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ void ffPlatformDestroy(FFPlatform* platform)
5656
ffStrbufDestroy(&info->name);
5757
ffStrbufDestroy(&info->release);
5858
ffStrbufDestroy(&info->version);
59-
ffStrbufDestroy(&info->displayVersion);
6059
}
6160

6261
void ffPlatformPathAddAbsolute(FFlist* dirs, const char* path)

src/util/platform/FFPlatform.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ typedef struct FFPlatformSysinfo
99
FFstrbuf release;
1010
FFstrbuf version;
1111
FFstrbuf architecture;
12-
FFstrbuf displayVersion;
1312
uint32_t pageSize;
1413
} FFPlatformSysinfo;
1514

src/util/platform/FFPlatform_unix.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ static void getSysinfo(FFPlatformSysinfo* info, const struct utsname* uts)
211211
else
212212
#endif
213213
ffStrbufAppendS(&info->architecture, uts->machine);
214-
ffStrbufInit(&info->displayVersion);
215214

216215
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) || defined(__NetBSD__)
217216
size_t length = sizeof(info->pageSize);

src/util/platform/FFPlatform_windows.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,14 @@ static void getUserShell(FFPlatform* platform)
168168
ffStrbufReplaceAllC(&platform->userShell, '\\', '/');
169169
}
170170

171-
static void detectWine(FFstrbuf* buf)
171+
static const char* detectWine(void)
172172
{
173173
const char * __cdecl wine_get_version(void);
174174
HMODULE hntdll = GetModuleHandleW(L"ntdll.dll");
175-
if (!hntdll) return;
175+
if (!hntdll) return NULL;
176176
FF_LIBRARY_LOAD_SYMBOL_LAZY(hntdll, wine_get_version);
177-
if (!ffwine_get_version) return;
178-
ffStrbufAppendS(buf, buf->length ? " - wine " : "wine ");
179-
ffStrbufAppendS(buf, ffwine_get_version());
177+
if (!ffwine_get_version) return NULL;
178+
return ffwine_get_version();
180179
}
181180

182181
static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
@@ -199,29 +198,24 @@ static void getSystemReleaseAndVersion(FFPlatformSysinfo* info)
199198
(unsigned) osVersion.dwBuildNumber,
200199
(unsigned) ubr);
201200

202-
ffStrbufInit(&info->displayVersion);
203-
if(!ffRegReadStrbuf(hKey, L"DisplayVersion", &info->displayVersion, NULL))
204-
{
205-
if (osVersion.szCSDVersion[0])
206-
ffStrbufSetWS(&info->displayVersion, osVersion.szCSDVersion);
207-
else
208-
ffRegReadStrbuf(hKey, L"ReleaseId", &info->displayVersion, NULL); // For old Windows 10
209-
}
210-
detectWine(&info->displayVersion);
211-
212201
ffRegReadStrbuf(hKey, L"BuildLabEx", &info->version, NULL);
213202

214-
switch (osVersion.dwPlatformId)
203+
const char* wineVersion = detectWine();
204+
if (wineVersion)
205+
ffStrbufSetF(&info->name, "Wine_%s", wineVersion);
215206
{
216-
case VER_PLATFORM_WIN32s:
217-
ffStrbufSetStatic(&info->name, "WIN32s");
218-
break;
219-
case VER_PLATFORM_WIN32_WINDOWS:
220-
ffStrbufSetStatic(&info->name, "WIN32_WINDOWS");
221-
break;
222-
case VER_PLATFORM_WIN32_NT:
223-
ffStrbufSetStatic(&info->name, "WIN32_NT");
224-
break;
207+
switch (osVersion.dwPlatformId)
208+
{
209+
case VER_PLATFORM_WIN32s:
210+
ffStrbufSetStatic(&info->name, "WIN32s");
211+
break;
212+
case VER_PLATFORM_WIN32_WINDOWS:
213+
ffStrbufSetStatic(&info->name, "WIN32_WINDOWS");
214+
break;
215+
case VER_PLATFORM_WIN32_NT:
216+
ffStrbufSetStatic(&info->name, "WIN32_NT");
217+
break;
218+
}
225219
}
226220
}
227221

0 commit comments

Comments
 (0)