1+ extern " C" {
12#include " os.h"
23#include " common/library.h"
3- #include "util/windows/unicode.h"
44#include " util/stringUtils.h"
55#include " util/windows/registry.h"
6+ }
7+ #include " util/windows/unicode.hpp"
8+ #include " util/windows/wmi.hpp"
9+
10+ static const char * getOsNameByWmi (FFstrbuf* osName)
11+ {
12+ FFWmiQuery query (L" SELECT Caption FROM Win32_OperatingSystem" );
13+ if (!query)
14+ return " Query WMI service failed" ;
15+
16+ if (FFWmiRecord record = query.next ())
17+ {
18+ if (auto vtCaption = record.get (L" Caption" ))
19+ {
20+ ffStrbufSetWSV (osName, vtCaption.get <std::wstring_view>());
21+ ffStrbufTrimRight (osName, ' ' );
22+ return NULL ;
23+ }
24+ return " Get Caption failed" ;
25+ }
626
7- #include <windows.h>
27+ return " No WMI result returned" ;
28+ }
829
930PWSTR WINAPI BrandingFormatString (PCWSTR format);
1031
@@ -24,19 +45,32 @@ static bool getCodeName(FFOSResult* os)
2445 return true ;
2546}
2647
27- void ffDetectOSImpl ( FFOSResult * os )
48+ static const char * getOsNameByWinbrand (FFstrbuf* osName )
2849{
2950 // https://dennisbabkin.com/blog/?t=how-to-tell-the-real-version-of-windows-your-app-is-running-on#ver_string
30- const wchar_t * rawName = BrandingFormatString (L"%WINDOWS_LONG%" );
31- ffStrbufSetWS (& os -> variant , rawName );
51+ FF_LIBRARY_LOAD (winbrand, " dlopen winbrand" FF_LIBRARY_EXTENSION " failed" , " winbrand" FF_LIBRARY_EXTENSION, 1 );
52+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (winbrand, BrandingFormatString);
53+
54+ const wchar_t * rawName = ffBrandingFormatString (L" %WINDOWS_LONG%" );
55+ ffStrbufSetWS (osName, rawName);
3256 GlobalFree ((HGLOBAL)rawName);
33- ffStrbufSet (& os -> prettyName , & os -> variant );
57+ return NULL ;
58+ }
59+
60+ extern " C"
61+ void ffDetectOSImpl (FFOSResult* os)
62+ {
63+ if (getOsNameByWinbrand (&os->variant ) && getOsNameByWmi (&os->variant ))
64+ return ;
65+
3466 ffStrbufTrimRight (&os->variant , ' ' );
3567
3668 // WMI returns the "Microsoft" prefix while BrandingFormatString doesn't. Make them consistent.
3769 if (ffStrbufStartsWithS (&os->variant , " Microsoft " ))
3870 ffStrbufSubstrAfter (&os->variant , strlen (" Microsoft " ) - 1 );
3971
72+ ffStrbufSet (&os->prettyName , &os->variant );
73+
4074 if (ffStrbufStartsWithS (&os->variant , " Windows " ))
4175 {
4276 ffStrbufAppendS (&os->name , " Windows" );
0 commit comments