blob: 766c0ee9f36c36514ec1288f37c6d30c42909a22 (
plain)
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
|
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
// * Copyright (C) Zenju (zenju AT gmx DOT de) - All Rights Reserved *
// **************************************************************************
#ifndef WINDOWS_VERSION_HEADER_238470348254325
#define WINDOWS_VERSION_HEADER_238470348254325
#include <cstdint>
#include <zen/win.h> //includes "windows.h"
namespace zen
{
std::uint64_t getOsVersion();
std::uint64_t toBigOsNumber(DWORD high, DWORD low);
//version overview: http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx
const std::uint64_t osVersionWin81 = toBigOsNumber(6, 3);
const std::uint64_t osVersionWin8 = toBigOsNumber(6, 2);
const std::uint64_t osVersionWin7 = toBigOsNumber(6, 1);
const std::uint64_t osVersionWinVista = toBigOsNumber(6, 0);
const std::uint64_t osVersionWinServer2003 = toBigOsNumber(5, 2);
const std::uint64_t osVersionWinXp = toBigOsNumber(5, 1);
inline bool win81OrLater () { return getOsVersion() >= osVersionWin81; }
inline bool win8OrLater () { return getOsVersion() >= osVersionWin8; }
inline bool win7OrLater () { return getOsVersion() >= osVersionWin7; }
inline bool vistaOrLater () { return getOsVersion() >= osVersionWinVista; }
inline bool winServer2003orLater() { return getOsVersion() >= osVersionWinServer2003; }
inline bool winXpOrLater () { return getOsVersion() >= osVersionWinXp; }
//######################### implementation #########################
inline
std::uint64_t toBigOsNumber(DWORD high, DWORD low)
{
ULARGE_INTEGER tmp = {};
tmp.HighPart = high;
tmp.LowPart = low;
static_assert(sizeof(tmp) == sizeof(std::uint64_t), "");
return tmp.QuadPart;
}
inline
std::uint64_t getOsVersion()
{
OSVERSIONINFO osvi = {};
osvi.dwOSVersionInfoSize = sizeof(osvi);
if (!::GetVersionEx(&osvi)) //38 ns per call! (yes, that's nano!) -> we do NOT miss C++11 thread safe statics right now...
return 0;
return toBigOsNumber(osvi.dwMajorVersion, osvi.dwMinorVersion);
}
}
#endif //WINDOWS_VERSION_HEADER_238470348254325
|