]> git.mxchange.org Git - simgear.git/commitdiff
Windows versionhelpers.h support.
authorJames Turner <zakalawe@mac.com>
Mon, 20 Apr 2015 09:57:54 +0000 (10:57 +0100)
committerJames Turner <zakalawe@mac.com>
Mon, 20 Apr 2015 09:58:11 +0000 (10:58 +0100)
simgear/misc/CMakeLists.txt
simgear/misc/sg_path.cxx
simgear/misc/sgversionhelpers.hxx [new file with mode: 0644]

index 3cf1e96a44bb87a94e49e6a4e8e6b95ada7c5f96..5fa8a90409954afa41aa7cfb08138edfdb137062 100644 (file)
@@ -1,7 +1,7 @@
 
 include (SimGearComponent)
 
-set(HEADERS 
+set(HEADERS
     CSSBorder.hxx
     ListDiff.hxx
     ResourceManager.hxx
@@ -37,6 +37,10 @@ set(SOURCES
     gzcontainerfile.cxx
     )
 
+if (WINDOWS)
+    list(APPEND HEADERS sgversionhelpers.hxx)
+endif()
+
 if (APPLE)
     list(APPEND SOURCES CocoaHelpers.mm)
 endif()
index d1475b1142b0d20a3b840b6cc6f93fb1c4874cce..756bfc224fce6b7ee61389f7c9b0af250e26b523 100644 (file)
@@ -57,7 +57,9 @@ static const char sgSearchPathSep = ':';
 
 #ifdef _WIN32
 #include <ShlObj.h>         // for CSIDL
-#include <versionhelpers.h>
+// TODO: replace this include file with the official <versionhelpers.h> header
+// included in the Windows 8.1 SDK
+#include "sgversionhelpers.hxx"
 
 static SGPath pathForCSIDL(int csidl, const SGPath& def)
 {
diff --git a/simgear/misc/sgversionhelpers.hxx b/simgear/misc/sgversionhelpers.hxx
new file mode 100644 (file)
index 0000000..bc0b7b3
--- /dev/null
@@ -0,0 +1,122 @@
+// Clean drop-in replacement for the versionhelpers.h header\r
+//\r
+// Copyright (C) 2015 Alessandro Menti <alessandro.menti@hotmail.it>\r
+//\r
+// This library is free software; you can redistribute it and/or\r
+// modify it under the terms of the GNU Library General Public\r
+// License as published by the Free Software Foundation; either\r
+// version 2 of the License, or (at your option) any later version.\r
+//\r
+// This library is distributed in the hope that it will be useful,\r
+// but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+// Library General Public License for more details.\r
+//\r
+// You should have received a copy of the GNU Library General Public\r
+// License along with this library; if not, write to the Free Software\r
+// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA\r
+\r
+#ifndef SG_VERSIONHELPERS_HXX_\r
+#define SG_VERSIONHELPERS_HXX_\r
+\r
+#include <sdkddkver.h>\r
+\r
+#ifdef __cplusplus\r
+#define VERSIONHELPERAPI inline bool\r
+#else\r
+#define VERSIONHELPERAPI FORCEINLINE BOOL\r
+#endif // __cplusplus\r
+\r
+/* Windows 8/8.1 version numbers, not defined in the Windows 7 SDK. */\r
+#ifndef _WIN32_WINNT_WIN8\r
+#define _WIN32_WINNT_WIN8 0x0602\r
+#endif\r
+#ifndef _WIN32_WINNT_WINBLUE\r
+#define _WIN32_WINNT_WINBLUE 0x0603\r
+#endif\r
+\r
+VERSIONHELPERAPI IsWindowsVersionOrGreater(WORD wMajorVersion,\r
+    WORD wMinorVersion, WORD wServicePackMajor) {\r
+    OSVERSIONINFOEXW osVersionInfo;\r
+    DWORDLONG dwlConditionMask = 0;\r
+    ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));\r
+    osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);\r
+    osVersionInfo.dwMajorVersion = wMajorVersion;\r
+    osVersionInfo.dwMinorVersion = wMinorVersion;\r
+    osVersionInfo.wServicePackMajor = wServicePackMajor;\r
+    VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION,\r
+        VER_GREATER_EQUAL);\r
+    VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION,\r
+        VER_GREATER_EQUAL);\r
+    VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR,\r
+        VER_GREATER_EQUAL);\r
+    return VerifyVersionInfoW(&osVersionInfo, VER_MAJORVERSION\r
+        | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsXPOrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP),\r
+        LOBYTE(_WIN32_WINNT_WINXP), 0);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsXPSP1OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP),\r
+        LOBYTE(_WIN32_WINNT_WINXP), 1);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsXPSP2OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP),\r
+        LOBYTE(_WIN32_WINNT_WINXP), 2);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsXPSP3OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP),\r
+        LOBYTE(_WIN32_WINNT_WINXP), 3);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsVistaOrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA),\r
+        LOBYTE(_WIN32_WINNT_VISTA), 0);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsVistaSP1OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA),\r
+        LOBYTE(_WIN32_WINNT_VISTA), 1);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsVistaSP2OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA),\r
+        LOBYTE(_WIN32_WINNT_VISTA), 2);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindows7OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7),\r
+        LOBYTE(_WIN32_WINNT_WIN7), 0);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindows7SP1OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7),\r
+        LOBYTE(_WIN32_WINNT_WIN7), 1);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindows8OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8),\r
+        LOBYTE(_WIN32_WINNT_WIN8), 0);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindows8Point1OrGreater() {\r
+    return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE),\r
+        LOBYTE(_WIN32_WINNT_WINBLUE), 0);\r
+}\r
+\r
+VERSIONHELPERAPI IsWindowsServer() {\r
+    OSVERSIONINFOEXW osVersionInfo;\r
+    DWORDLONG dwlConditionMask = 0;\r
+    ZeroMemory(&osVersionInfo, sizeof(osVersionInfo));\r
+    osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo);\r
+    osVersionInfo.wProductType = VER_NT_WORKSTATION;\r
+    VER_SET_CONDITION(dwlConditionMask, VER_PRODUCT_TYPE, VER_EQUAL);\r
+    return !VerifyVersionInfoW(&osVersionInfo, VER_PRODUCT_TYPE,\r
+        dwlConditionMask);\r
+}\r
+#endif // SG_VERSIONHELPERS_HXX_\r