|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 #ifndef mozilla_WindowsVersion_h |
|
6 #define mozilla_WindowsVersion_h |
|
7 |
|
8 #include "mozilla/Attributes.h" |
|
9 #include <stdint.h> |
|
10 #include <windows.h> |
|
11 |
|
12 namespace mozilla |
|
13 { |
|
14 inline bool |
|
15 IsWindowsVersionOrLater(uint32_t aVersion) |
|
16 { |
|
17 static uint32_t minVersion = 0; |
|
18 static uint32_t maxVersion = UINT32_MAX; |
|
19 |
|
20 if (minVersion >= aVersion) { |
|
21 return true; |
|
22 } |
|
23 |
|
24 if (aVersion >= maxVersion) { |
|
25 return false; |
|
26 } |
|
27 |
|
28 OSVERSIONINFOEX info; |
|
29 ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); |
|
30 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
|
31 info.dwMajorVersion = aVersion >> 24; |
|
32 info.dwMinorVersion = (aVersion >> 16) & 0xFF; |
|
33 info.wServicePackMajor = (aVersion >> 8) & 0xFF; |
|
34 info.wServicePackMinor = aVersion & 0xFF; |
|
35 |
|
36 DWORDLONG conditionMask = 0; |
|
37 VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); |
|
38 VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); |
|
39 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); |
|
40 VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL); |
|
41 |
|
42 if (VerifyVersionInfo(&info, |
|
43 VER_MAJORVERSION | VER_MINORVERSION | |
|
44 VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR, |
|
45 conditionMask)) { |
|
46 minVersion = aVersion; |
|
47 return true; |
|
48 } |
|
49 |
|
50 maxVersion = aVersion; |
|
51 return false; |
|
52 } |
|
53 |
|
54 inline bool |
|
55 IsWindowsBuildOrLater(uint32_t aBuild) |
|
56 { |
|
57 static uint32_t minBuild = 0; |
|
58 static uint32_t maxBuild = UINT32_MAX; |
|
59 |
|
60 if (minBuild >= aBuild) { |
|
61 return true; |
|
62 } |
|
63 |
|
64 if (aBuild >= maxBuild) { |
|
65 return false; |
|
66 } |
|
67 |
|
68 OSVERSIONINFOEX info; |
|
69 ZeroMemory(&info, sizeof(OSVERSIONINFOEX)); |
|
70 info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); |
|
71 info.dwBuildNumber = aBuild; |
|
72 |
|
73 DWORDLONG conditionMask = 0; |
|
74 VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL); |
|
75 |
|
76 if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) { |
|
77 minBuild = aBuild; |
|
78 return true; |
|
79 } |
|
80 |
|
81 maxBuild = aBuild; |
|
82 return false; |
|
83 } |
|
84 |
|
85 MOZ_ALWAYS_INLINE bool |
|
86 IsXPSP3OrLater() |
|
87 { return IsWindowsVersionOrLater(0x05010300ul); } |
|
88 |
|
89 MOZ_ALWAYS_INLINE bool |
|
90 IsWin2003OrLater() |
|
91 { return IsWindowsVersionOrLater(0x05020000ul); } |
|
92 |
|
93 MOZ_ALWAYS_INLINE bool |
|
94 IsWin2003SP2OrLater() |
|
95 { return IsWindowsVersionOrLater(0x05020200ul); } |
|
96 |
|
97 MOZ_ALWAYS_INLINE bool |
|
98 IsVistaOrLater() |
|
99 { return IsWindowsVersionOrLater(0x06000000ul); } |
|
100 |
|
101 MOZ_ALWAYS_INLINE bool |
|
102 IsVistaSP1OrLater() |
|
103 { return IsWindowsVersionOrLater(0x06000100ul); } |
|
104 |
|
105 MOZ_ALWAYS_INLINE bool |
|
106 IsWin7OrLater() |
|
107 { return IsWindowsVersionOrLater(0x06010000ul); } |
|
108 |
|
109 MOZ_ALWAYS_INLINE bool |
|
110 IsWin7SP1OrLater() |
|
111 { return IsWindowsVersionOrLater(0x06010100ul); } |
|
112 |
|
113 MOZ_ALWAYS_INLINE bool |
|
114 IsWin8OrLater() |
|
115 { return IsWindowsVersionOrLater(0x06020000ul); } |
|
116 |
|
117 MOZ_ALWAYS_INLINE bool |
|
118 IsNotWin7PreRTM() |
|
119 { |
|
120 return IsWin7SP1OrLater() || !IsWin7OrLater() || |
|
121 IsWindowsBuildOrLater(7600); |
|
122 } |
|
123 } |
|
124 |
|
125 #endif /* mozilla_WindowsVersion_h */ |