"Fossies" - the Fresh Open Source Software Archive

Member "unrar/isnt.cpp" (4 May 2022, 2528 Bytes) of package /linux/misc/unrarsrc-6.1.7.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "isnt.cpp" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 6.1.4_vs_6.1.5.

    1 #include "rar.hpp"
    2 
    3 DWORD WinNT()
    4 {
    5   static int dwPlatformId=-1;
    6   static DWORD dwMajorVersion,dwMinorVersion;
    7   if (dwPlatformId==-1)
    8   {
    9     OSVERSIONINFO WinVer;
   10     WinVer.dwOSVersionInfoSize=sizeof(WinVer);
   11     GetVersionEx(&WinVer);
   12     dwPlatformId=WinVer.dwPlatformId;
   13     dwMajorVersion=WinVer.dwMajorVersion;
   14     dwMinorVersion=WinVer.dwMinorVersion;
   15 
   16   }
   17   DWORD Result=0;
   18   if (dwPlatformId==VER_PLATFORM_WIN32_NT)
   19     Result=dwMajorVersion*0x100+dwMinorVersion;
   20 
   21 
   22   return Result;
   23 }
   24 
   25 
   26 // Replace it with documented Windows 11 check when available.
   27 #include <comdef.h>
   28 #include <Wbemidl.h>
   29 #pragma comment(lib, "wbemuuid.lib")
   30 
   31 static bool WMI_IsWindows10()
   32 {
   33   IWbemLocator *pLoc = NULL;
   34 
   35   HRESULT hres = CoCreateInstance(CLSID_WbemLocator,0,CLSCTX_INPROC_SERVER,
   36                           IID_IWbemLocator,(LPVOID *)&pLoc);
   37  
   38   if (FAILED(hres))
   39     return false;
   40 
   41   IWbemServices *pSvc = NULL;
   42  
   43   hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,0,NULL,0,0,&pSvc);
   44     
   45   if (FAILED(hres))
   46   {
   47     pLoc->Release();     
   48     return false;
   49   }
   50 
   51   hres = CoSetProxyBlanket(pSvc,RPC_C_AUTHN_WINNT,RPC_C_AUTHZ_NONE,NULL,
   52          RPC_C_AUTHN_LEVEL_CALL,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE);
   53 
   54   if (FAILED(hres))
   55   {
   56     pSvc->Release();
   57     pLoc->Release();     
   58     return false;
   59   }
   60 
   61   IEnumWbemClassObject *pEnumerator = NULL;
   62   hres = pSvc->ExecQuery(bstr_t("WQL"), bstr_t("SELECT * FROM Win32_OperatingSystem"),
   63          WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, NULL, &pEnumerator);
   64     
   65   if (FAILED(hres))
   66   {
   67     pSvc->Release();
   68     pLoc->Release();
   69     return false;
   70   }
   71 
   72   IWbemClassObject *pclsObj = NULL;
   73   ULONG uReturn = 0;
   74    
   75   bool Win10=false;
   76   while (pEnumerator!=NULL)
   77   {
   78     HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
   79 
   80     if (uReturn==0)
   81       break;
   82 
   83     VARIANT vtProp;
   84 
   85     hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
   86     Win10|=wcsstr(vtProp.bstrVal,L"Windows 10")!=NULL;
   87     VariantClear(&vtProp);
   88 
   89     pclsObj->Release();
   90   }
   91 
   92   pSvc->Release();
   93   pLoc->Release();
   94   pEnumerator->Release();
   95 
   96   return Win10;
   97 }
   98 
   99 
  100 // Replace it with actual check when available.
  101 bool IsWindows11OrGreater()
  102 {
  103   static bool IsSet=false,IsWin11=false;
  104   if (!IsSet)
  105   {
  106     OSVERSIONINFO WinVer;
  107     WinVer.dwOSVersionInfoSize=sizeof(WinVer);
  108     GetVersionEx(&WinVer);
  109     IsWin11=WinVer.dwMajorVersion>10 || 
  110           WinVer.dwMajorVersion==10 && WinVer.dwBuildNumber >= 22000 && !WMI_IsWindows10();
  111     IsSet=true;
  112   }
  113   return IsWin11;
  114 }