From d0f979ecd9a8e7eeb879af4ff3f7cee1968f3b4f Mon Sep 17 00:00:00 2001 From: GreyMerlin Date: Wed, 25 Jul 2018 19:20:17 -0700 Subject: [PATCH] Eliminate use of deprecated `GetVersionEx()` * Add "Win_VersionHelper.h" to implement the proper modern runtime checking for the Windows version. * Unrelated: is useless in a UNICODE application. --- Src/DirTravel.cpp | 8 ++------ Src/Merge.vs2017.vcxproj | 1 + Src/Merge.vs2017.vcxproj.filters | 3 +++ Src/Win_VersionHelper.h | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 Src/Win_VersionHelper.h diff --git a/Src/DirTravel.cpp b/Src/DirTravel.cpp index 93af3f1b2..defcc3ef0 100644 --- a/Src/DirTravel.cpp +++ b/Src/DirTravel.cpp @@ -12,12 +12,12 @@ #include #include #include -#include #include "TFile.h" #include "UnicodeString.h" #include "DirItem.h" #include "unicoder.h" #include "paths.h" +#include "Win_VersionHelper.h" using Poco::DirectoryIterator; using Poco::Timestamp; @@ -83,11 +83,7 @@ static void LoadFiles(const String& sDir, DirItemArray * dirs, DirItemArray * fi WIN32_FIND_DATA ff; HANDLE h; - OSVERSIONINFO vi; - vi.dwOSVersionInfoSize = sizeof(vi); - GetVersionEx(&vi); - - if (vi.dwMajorVersion * 10 + vi.dwMinorVersion >= 61) + if (IsWin7_OrGreater()) // (also 'Windows Server 2008 R2' and greater) for FIND_FIRST_EX_LARGE_FETCH h = FindFirstFileEx(TFile(sPattern).wpath().c_str(), FindExInfoBasic, &ff, FindExSearchNameMatch, NULL, FIND_FIRST_EX_LARGE_FETCH); else h = FindFirstFile(TFile(sPattern).wpath().c_str(), &ff); diff --git a/Src/Merge.vs2017.vcxproj b/Src/Merge.vs2017.vcxproj index b0d552fd3..cc3e92130 100644 --- a/Src/Merge.vs2017.vcxproj +++ b/Src/Merge.vs2017.vcxproj @@ -1129,6 +1129,7 @@ + diff --git a/Src/Merge.vs2017.vcxproj.filters b/Src/Merge.vs2017.vcxproj.filters index c0fcb89fc..226495562 100644 --- a/Src/Merge.vs2017.vcxproj.filters +++ b/Src/Merge.vs2017.vcxproj.filters @@ -1449,6 +1449,9 @@ MergeTest + + Header Files + diff --git a/Src/Win_VersionHelper.h b/Src/Win_VersionHelper.h new file mode 100644 index 000000000..746dd4b77 --- /dev/null +++ b/Src/Win_VersionHelper.h @@ -0,0 +1,39 @@ +/** + * @file Win_VersionHelper.h + * + * @brief Defines quick-and-dirty runtime Windows version checking. + + * All we need in WinMerge is `IsWin7_OrGreater()` + * But other possibilities (and slightly different implementation) can be seen in ... + * 'C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\VersionHelpers.h' + * + */ + +#pragma once + +#include + +inline bool +IsWinVer_OrGreater(WORD wVersion, WORD wServicePack = 0) +{ + DWORDLONG dwlConditionMask = 0; + 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 ); + + OSVERSIONINFOEXW osvi; + ::ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); + osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); + osvi.dwMajorVersion = HIBYTE(wVersion); + osvi.dwMinorVersion = LOBYTE(wVersion); + osvi.wServicePackMajor = wServicePack; + + return VerifyVersionInfoW(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; +} + + +inline bool +IsWin7_OrGreater() +{ + return IsWinVer_OrGreater( _WIN32_WINNT_WIN7 ); +} -- 2.11.0