mfbt/WindowsVersion.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mfbt/WindowsVersion.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,125 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +#ifndef mozilla_WindowsVersion_h
     1.9 +#define mozilla_WindowsVersion_h
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include <stdint.h>
    1.13 +#include <windows.h>
    1.14 +
    1.15 +namespace mozilla
    1.16 +{
    1.17 +  inline bool
    1.18 +  IsWindowsVersionOrLater(uint32_t aVersion)
    1.19 +  {
    1.20 +    static uint32_t minVersion = 0;
    1.21 +    static uint32_t maxVersion = UINT32_MAX;
    1.22 +
    1.23 +    if (minVersion >= aVersion) {
    1.24 +      return true;
    1.25 +    }
    1.26 +
    1.27 +    if (aVersion >= maxVersion) {
    1.28 +      return false;
    1.29 +    }
    1.30 +
    1.31 +    OSVERSIONINFOEX info;
    1.32 +    ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
    1.33 +    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    1.34 +    info.dwMajorVersion = aVersion >> 24;
    1.35 +    info.dwMinorVersion = (aVersion >> 16) & 0xFF;
    1.36 +    info.wServicePackMajor = (aVersion >> 8) & 0xFF;
    1.37 +    info.wServicePackMinor = aVersion & 0xFF;
    1.38 +
    1.39 +    DWORDLONG conditionMask = 0;
    1.40 +    VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
    1.41 +    VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
    1.42 +    VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
    1.43 +    VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
    1.44 +
    1.45 +    if (VerifyVersionInfo(&info,
    1.46 +                          VER_MAJORVERSION | VER_MINORVERSION |
    1.47 +                          VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
    1.48 +                          conditionMask)) {
    1.49 +      minVersion = aVersion;
    1.50 +      return true;
    1.51 +    }
    1.52 +
    1.53 +    maxVersion = aVersion;
    1.54 +    return false;
    1.55 +  }
    1.56 +
    1.57 +  inline bool
    1.58 +  IsWindowsBuildOrLater(uint32_t aBuild)
    1.59 +  {
    1.60 +    static uint32_t minBuild = 0;
    1.61 +    static uint32_t maxBuild = UINT32_MAX;
    1.62 +
    1.63 +    if (minBuild >= aBuild) {
    1.64 +      return true;
    1.65 +    }
    1.66 +
    1.67 +    if (aBuild >= maxBuild) {
    1.68 +      return false;
    1.69 +    }
    1.70 +
    1.71 +    OSVERSIONINFOEX info;
    1.72 +    ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
    1.73 +    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    1.74 +    info.dwBuildNumber = aBuild;
    1.75 +
    1.76 +    DWORDLONG conditionMask = 0;
    1.77 +    VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
    1.78 +
    1.79 +    if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) {
    1.80 +      minBuild = aBuild;
    1.81 +      return true;
    1.82 +    }
    1.83 +
    1.84 +    maxBuild = aBuild;
    1.85 +    return false;
    1.86 +  }
    1.87 +
    1.88 +  MOZ_ALWAYS_INLINE bool
    1.89 +  IsXPSP3OrLater()
    1.90 +  { return IsWindowsVersionOrLater(0x05010300ul); }
    1.91 +
    1.92 +  MOZ_ALWAYS_INLINE bool
    1.93 +  IsWin2003OrLater()
    1.94 +  { return IsWindowsVersionOrLater(0x05020000ul); }
    1.95 +
    1.96 +  MOZ_ALWAYS_INLINE bool
    1.97 +  IsWin2003SP2OrLater()
    1.98 +  { return IsWindowsVersionOrLater(0x05020200ul); }
    1.99 +
   1.100 +  MOZ_ALWAYS_INLINE bool
   1.101 +  IsVistaOrLater()
   1.102 +  { return IsWindowsVersionOrLater(0x06000000ul); }
   1.103 +
   1.104 +  MOZ_ALWAYS_INLINE bool
   1.105 +  IsVistaSP1OrLater()
   1.106 +  { return IsWindowsVersionOrLater(0x06000100ul); }
   1.107 +
   1.108 +  MOZ_ALWAYS_INLINE bool
   1.109 +  IsWin7OrLater()
   1.110 +  { return IsWindowsVersionOrLater(0x06010000ul); }
   1.111 +
   1.112 +  MOZ_ALWAYS_INLINE bool
   1.113 +  IsWin7SP1OrLater()
   1.114 +  { return IsWindowsVersionOrLater(0x06010100ul); }
   1.115 +
   1.116 +  MOZ_ALWAYS_INLINE bool
   1.117 +  IsWin8OrLater()
   1.118 +  { return IsWindowsVersionOrLater(0x06020000ul); }
   1.119 +
   1.120 +  MOZ_ALWAYS_INLINE bool
   1.121 +  IsNotWin7PreRTM()
   1.122 +  {
   1.123 +    return IsWin7SP1OrLater() || !IsWin7OrLater() ||
   1.124 +           IsWindowsBuildOrLater(7600);
   1.125 +  }
   1.126 +}
   1.127 +
   1.128 +#endif /* mozilla_WindowsVersion_h */

mercurial