Skip to content

Commit 4146bb6

Browse files
committed
OS (Windows): hard linking winbrand
1 parent 9188715 commit 4146bb6

File tree

2 files changed

+7
-39
lines changed

2 files changed

+7
-39
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ elseif(WIN32)
857857
src/detection/physicalmemory/physicalmemory_linux.c
858858
src/detection/netio/netio_windows.c
859859
src/detection/opengl/opengl_windows.c
860-
src/detection/os/os_windows.cpp
860+
src/detection/os/os_windows.c
861861
src/detection/packages/packages_windows.c
862862
src/detection/poweradapter/poweradapter_nosupport.c
863863
src/detection/processes/processes_windows.c
@@ -1315,6 +1315,7 @@ elseif(WIN32)
13151315
PRIVATE "wtsapi32"
13161316
PRIVATE "imagehlp"
13171317
PRIVATE "cfgmgr32"
1318+
PRIVATE "winbrand"
13181319
)
13191320
elseif(FreeBSD)
13201321
target_link_libraries(libfastfetch

src/detection/os/os_windows.cpp renamed to src/detection/os/os_windows.c

Lines changed: 5 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,18 @@
1-
extern "C" {
21
#include "os.h"
32
#include "common/library.h"
4-
}
5-
#include "util/windows/unicode.hpp"
6-
#include "util/windows/wmi.hpp"
3+
#include "util/windows/unicode.h"
74
#include "util/stringUtils.h"
85

9-
static const char* getOsNameByWmi(FFstrbuf* osName)
10-
{
11-
FFWmiQuery query(L"SELECT Caption FROM Win32_OperatingSystem");
12-
if(!query)
13-
return "Query WMI service failed";
14-
15-
if(FFWmiRecord record = query.next())
16-
{
17-
if(auto vtCaption = record.get(L"Caption"))
18-
{
19-
ffStrbufSetWSV(osName, vtCaption.get<std::wstring_view>());
20-
ffStrbufTrimRight(osName, ' ');
21-
return NULL;
22-
}
23-
return "Get Caption failed";
24-
}
25-
26-
return "No WMI result returned";
27-
}
6+
#include <windows.h>
287

298
PWSTR WINAPI BrandingFormatString(PCWSTR format);
309

31-
static const char* getOsNameByWinbrand(FFstrbuf* osName)
10+
void ffDetectOSImpl(FFOSResult* os)
3211
{
3312
//https://dennisbabkin.com/blog/?t=how-to-tell-the-real-version-of-windows-your-app-is-running-on#ver_string
34-
FF_LIBRARY_LOAD(winbrand, "dlopen winbrand" FF_LIBRARY_EXTENSION " failed", "winbrand" FF_LIBRARY_EXTENSION, 1);
35-
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(winbrand, BrandingFormatString);
36-
37-
const wchar_t* rawName = ffBrandingFormatString(L"%WINDOWS_LONG%");
38-
ffStrbufSetWS(osName, rawName);
13+
const wchar_t* rawName = BrandingFormatString(L"%WINDOWS_LONG%");
14+
ffStrbufSetWS(&os->variant, rawName);
3915
GlobalFree((HGLOBAL)rawName);
40-
return NULL;
41-
}
42-
43-
extern "C"
44-
void ffDetectOSImpl(FFOSResult* os)
45-
{
46-
if(getOsNameByWinbrand(&os->variant) && getOsNameByWmi(&os->variant))
47-
return;
48-
4916
ffStrbufTrimRight(&os->variant, ' ');
5017

5118
//WMI returns the "Microsoft" prefix while BrandingFormatString doesn't. Make them consistent.

0 commit comments

Comments
 (0)