forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindowsVersion.h
195 lines (160 loc) · 3.83 KB
/
WindowsVersion.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef mozilla_WindowsVersion_h
#define mozilla_WindowsVersion_h
#include "mozilla/Attributes.h"
#include <stdint.h>
#include <windows.h>
namespace mozilla {
inline bool
IsWindowsVersionOrLater(uint32_t aVersion)
{
static uint32_t minVersion = 0;
static uint32_t maxVersion = UINT32_MAX;
if (minVersion >= aVersion) {
return true;
}
if (aVersion >= maxVersion) {
return false;
}
OSVERSIONINFOEX info;
ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
info.dwMajorVersion = aVersion >> 24;
info.dwMinorVersion = (aVersion >> 16) & 0xFF;
info.wServicePackMajor = (aVersion >> 8) & 0xFF;
info.wServicePackMinor = aVersion & 0xFF;
DWORDLONG conditionMask = 0;
VER_SET_CONDITION(conditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL);
VER_SET_CONDITION(conditionMask, VER_MINORVERSION, VER_GREATER_EQUAL);
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL);
VER_SET_CONDITION(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER_EQUAL);
if (VerifyVersionInfo(&info,
VER_MAJORVERSION | VER_MINORVERSION |
VER_SERVICEPACKMAJOR | VER_SERVICEPACKMINOR,
conditionMask)) {
minVersion = aVersion;
return true;
}
maxVersion = aVersion;
return false;
}
inline bool
IsWindowsBuildOrLater(uint32_t aBuild)
{
static uint32_t minBuild = 0;
static uint32_t maxBuild = UINT32_MAX;
if (minBuild >= aBuild) {
return true;
}
if (aBuild >= maxBuild) {
return false;
}
OSVERSIONINFOEX info;
ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
info.dwBuildNumber = aBuild;
DWORDLONG conditionMask = 0;
VER_SET_CONDITION(conditionMask, VER_BUILDNUMBER, VER_GREATER_EQUAL);
if (VerifyVersionInfo(&info, VER_BUILDNUMBER, conditionMask)) {
minBuild = aBuild;
return true;
}
maxBuild = aBuild;
return false;
}
#if defined(_M_X64) || defined(_M_AMD64)
// We support only Win7 or later on Win64.
MOZ_ALWAYS_INLINE bool
IsXPSP3OrLater()
{
return true;
}
MOZ_ALWAYS_INLINE bool
IsWin2003OrLater()
{
return true;
}
MOZ_ALWAYS_INLINE bool
IsWin2003SP2OrLater()
{
return true;
}
MOZ_ALWAYS_INLINE bool
IsVistaOrLater()
{
return true;
}
MOZ_ALWAYS_INLINE bool
IsVistaSP1OrLater()
{
return true;
}
MOZ_ALWAYS_INLINE bool
IsWin7OrLater()
{
return true;
}
#else
MOZ_ALWAYS_INLINE bool
IsXPSP3OrLater()
{
return IsWindowsVersionOrLater(0x05010300ul);
}
MOZ_ALWAYS_INLINE bool
IsWin2003OrLater()
{
return IsWindowsVersionOrLater(0x05020000ul);
}
MOZ_ALWAYS_INLINE bool
IsWin2003SP2OrLater()
{
return IsWindowsVersionOrLater(0x05020200ul);
}
MOZ_ALWAYS_INLINE bool
IsVistaOrLater()
{
return IsWindowsVersionOrLater(0x06000000ul);
}
MOZ_ALWAYS_INLINE bool
IsVistaSP1OrLater()
{
return IsWindowsVersionOrLater(0x06000100ul);
}
MOZ_ALWAYS_INLINE bool
IsWin7OrLater()
{
return IsWindowsVersionOrLater(0x06010000ul);
}
#endif
MOZ_ALWAYS_INLINE bool
IsWin7SP1OrLater()
{
return IsWindowsVersionOrLater(0x06010100ul);
}
MOZ_ALWAYS_INLINE bool
IsWin8OrLater()
{
return IsWindowsVersionOrLater(0x06020000ul);
}
MOZ_ALWAYS_INLINE bool
IsWin8Point1OrLater()
{
return IsWindowsVersionOrLater(0x06030000ul);
}
MOZ_ALWAYS_INLINE bool
IsWin10OrLater()
{
return IsWindowsVersionOrLater(0x0a000000ul);
}
MOZ_ALWAYS_INLINE bool
IsNotWin7PreRTM()
{
return IsWin7SP1OrLater() || !IsWin7OrLater() ||
IsWindowsBuildOrLater(7600);
}
} // namespace mozilla
#endif /* mozilla_WindowsVersion_h */