diff options
author | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:31:50 +0200 |
---|---|---|
committer | Daniel Wilhelm <daniel@wili.li> | 2014-04-18 17:31:50 +0200 |
commit | 570916ddc376b09205125eaaab517561dfead9f0 (patch) | |
tree | 309a94f040707c402623e4f9f887346d1b561df7 /zen/win_ver.h | |
parent | 6.2 (diff) | |
download | FreeFileSync-570916ddc376b09205125eaaab517561dfead9f0.tar.gz FreeFileSync-570916ddc376b09205125eaaab517561dfead9f0.tar.bz2 FreeFileSync-570916ddc376b09205125eaaab517561dfead9f0.zip |
6.3
Diffstat (limited to 'zen/win_ver.h')
-rw-r--r-- | zen/win_ver.h | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/zen/win_ver.h b/zen/win_ver.h index 2c5e2f81..8797b596 100644 --- a/zen/win_ver.h +++ b/zen/win_ver.h @@ -7,19 +7,28 @@ #ifndef WINDOWS_VERSION_HEADER_238470348254325 #define WINDOWS_VERSION_HEADER_238470348254325 +#include <cstdint> #include <zen/win.h> //includes "windows.h" namespace zen { -bool winXpOrLater(); -bool winServer2003orLater(); -bool vistaOrLater(); -bool win7OrLater(); -bool win8OrLater(); - - +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; } @@ -29,42 +38,27 @@ bool win8OrLater(); //######################### implementation ######################### -//version overview: http://msdn.microsoft.com/en-us/library/ms724834(VS.85).aspx +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; +} -//2000 is version 5.0 -//XP is version 5.1 -//Server 2003 is version 5.2 -//Vista is version 6.0 -//Seven is version 6.1 -//Eight is version 6.2 -namespace impl -{ inline -bool winXyOrLater(DWORD major, DWORD minor) +std::uint64_t getOsVersion() { OSVERSIONINFO osvi = {}; osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - if (::GetVersionEx(&osvi)) //38 ns per call! (yes, that's nano!) -> we do NOT miss C++11 thread safe statics right now... - return osvi.dwMajorVersion != major ? osvi.dwMajorVersion > major : osvi.dwMinorVersion >= minor; - return false; -} + 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); } - -inline -bool winXpOrLater() { return impl::winXyOrLater(5, 1); } - -inline -bool winServer2003orLater() { return impl::winXyOrLater(5, 2); } - -inline -bool vistaOrLater() { return impl::winXyOrLater(6, 0); } - -inline -bool win7OrLater() { return impl::winXyOrLater(6, 1); } - -inline -bool win8OrLater() { return impl::winXyOrLater(6, 2); } } #endif //WINDOWS_VERSION_HEADER_238470348254325 |