From: James Turner Date: Mon, 20 Apr 2015 09:57:54 +0000 (+0100) Subject: Windows versionhelpers.h support. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5bbdcfd24032c917959604cb7208ca76d7e70579;p=simgear.git Windows versionhelpers.h support. --- diff --git a/simgear/misc/CMakeLists.txt b/simgear/misc/CMakeLists.txt index 3cf1e96a..5fa8a904 100644 --- a/simgear/misc/CMakeLists.txt +++ b/simgear/misc/CMakeLists.txt @@ -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() diff --git a/simgear/misc/sg_path.cxx b/simgear/misc/sg_path.cxx index d1475b11..756bfc22 100644 --- a/simgear/misc/sg_path.cxx +++ b/simgear/misc/sg_path.cxx @@ -57,7 +57,9 @@ static const char sgSearchPathSep = ':'; #ifdef _WIN32 #include // for CSIDL -#include +// TODO: replace this include file with the official 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 index 00000000..bc0b7b32 --- /dev/null +++ b/simgear/misc/sgversionhelpers.hxx @@ -0,0 +1,122 @@ +// Clean drop-in replacement for the versionhelpers.h header +// +// Copyright (C) 2015 Alessandro Menti +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + +#ifndef SG_VERSIONHELPERS_HXX_ +#define SG_VERSIONHELPERS_HXX_ + +#include + +#ifdef __cplusplus +#define VERSIONHELPERAPI inline bool +#else +#define VERSIONHELPERAPI FORCEINLINE BOOL +#endif // __cplusplus + +/* Windows 8/8.1 version numbers, not defined in the Windows 7 SDK. */ +#ifndef _WIN32_WINNT_WIN8 +#define _WIN32_WINNT_WIN8 0x0602 +#endif +#ifndef _WIN32_WINNT_WINBLUE +#define _WIN32_WINNT_WINBLUE 0x0603 +#endif + +VERSIONHELPERAPI IsWindowsVersionOrGreater(WORD wMajorVersion, + WORD wMinorVersion, WORD wServicePackMajor) { + OSVERSIONINFOEXW osVersionInfo; + DWORDLONG dwlConditionMask = 0; + ZeroMemory(&osVersionInfo, sizeof(osVersionInfo)); + osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo); + osVersionInfo.dwMajorVersion = wMajorVersion; + osVersionInfo.dwMinorVersion = wMinorVersion; + osVersionInfo.wServicePackMajor = wServicePackMajor; + VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, + VER_GREATER_EQUAL); + VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, + VER_GREATER_EQUAL); + VER_SET_CONDITION(dwlConditionMask, VER_SERVICEPACKMAJOR, + VER_GREATER_EQUAL); + return VerifyVersionInfoW(&osVersionInfo, VER_MAJORVERSION + | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask); +} + +VERSIONHELPERAPI IsWindowsXPOrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), + LOBYTE(_WIN32_WINNT_WINXP), 0); +} + +VERSIONHELPERAPI IsWindowsXPSP1OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), + LOBYTE(_WIN32_WINNT_WINXP), 1); +} + +VERSIONHELPERAPI IsWindowsXPSP2OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), + LOBYTE(_WIN32_WINNT_WINXP), 2); +} + +VERSIONHELPERAPI IsWindowsXPSP3OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINXP), + LOBYTE(_WIN32_WINNT_WINXP), 3); +} + +VERSIONHELPERAPI IsWindowsVistaOrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), + LOBYTE(_WIN32_WINNT_VISTA), 0); +} + +VERSIONHELPERAPI IsWindowsVistaSP1OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), + LOBYTE(_WIN32_WINNT_VISTA), 1); +} + +VERSIONHELPERAPI IsWindowsVistaSP2OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_VISTA), + LOBYTE(_WIN32_WINNT_VISTA), 2); +} + +VERSIONHELPERAPI IsWindows7OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), + LOBYTE(_WIN32_WINNT_WIN7), 0); +} + +VERSIONHELPERAPI IsWindows7SP1OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN7), + LOBYTE(_WIN32_WINNT_WIN7), 1); +} + +VERSIONHELPERAPI IsWindows8OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WIN8), + LOBYTE(_WIN32_WINNT_WIN8), 0); +} + +VERSIONHELPERAPI IsWindows8Point1OrGreater() { + return IsWindowsVersionOrGreater(HIBYTE(_WIN32_WINNT_WINBLUE), + LOBYTE(_WIN32_WINNT_WINBLUE), 0); +} + +VERSIONHELPERAPI IsWindowsServer() { + OSVERSIONINFOEXW osVersionInfo; + DWORDLONG dwlConditionMask = 0; + ZeroMemory(&osVersionInfo, sizeof(osVersionInfo)); + osVersionInfo.dwOSVersionInfoSize = sizeof(osVersionInfo); + osVersionInfo.wProductType = VER_NT_WORKSTATION; + VER_SET_CONDITION(dwlConditionMask, VER_PRODUCT_TYPE, VER_EQUAL); + return !VerifyVersionInfoW(&osVersionInfo, VER_PRODUCT_TYPE, + dwlConditionMask); +} +#endif // SG_VERSIONHELPERS_HXX_