Replace deprecated WINAPI GetVersionInfoEx (#6496)
authoradrido <robots_only_adrido@gmx.com>
Sat, 7 Oct 2017 13:13:13 +0000 (15:13 +0200)
committerLoïc Blot <nerzhul@users.noreply.github.com>
Sat, 7 Oct 2017 13:13:13 +0000 (15:13 +0200)
* Replace deprecated WINAPI GetVersionInfoEx

src/CMakeLists.txt
src/porting.cpp

index c7eb5fb593ed248b28af502a58663e493f533245..d82887b380e1b5e4515a9f9a86924a4b1357dc56 100644 (file)
@@ -268,7 +268,7 @@ if(WIN32)
        else() # Probably MinGW = GCC
                set(PLATFORM_LIBS "")
        endif()
-       set(PLATFORM_LIBS ws2_32.lib shlwapi.lib ${PLATFORM_LIBS})
+       set(PLATFORM_LIBS ws2_32.lib version.lib shlwapi.lib ${PLATFORM_LIBS})
 
        # Zlib stuff
        set(ZLIB_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/../../zlib/zlib-1.2.5"
index 04a7952c6ac73f8e7b4a61f179c25c8b60be26d0..1e3d610bce6609c1e7fea150fac3fd9800efb11e 100644 (file)
@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
        #include <windows.h>
        #include <wincrypt.h>
        #include <algorithm>
+       #include <shlwapi.h>
 #endif
 #if !defined(_WIN32)
        #include <unistd.h>
@@ -173,20 +174,26 @@ bool detectMSVCBuildDir(const std::string &path)
 std::string get_sysinfo()
 {
 #ifdef _WIN32
-       OSVERSIONINFO osvi;
+
        std::ostringstream oss;
-       std::string tmp;
-       ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
-       osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
-       GetVersionEx(&osvi);
-       tmp = osvi.szCSDVersion;
-       std::replace(tmp.begin(), tmp.end(), ' ', '_');
-
-       oss << "Windows/" << osvi.dwMajorVersion << "."
-               << osvi.dwMinorVersion;
-       if (osvi.szCSDVersion[0])
-               oss << "-" << tmp;
-       oss << " ";
+       LPSTR filePath = new char[MAX_PATH];
+       UINT blockSize;
+       VS_FIXEDFILEINFO *fixedFileInfo;
+
+       GetSystemDirectoryA(filePath, MAX_PATH);
+       PathAppendA(filePath, "kernel32.dll");
+
+       DWORD dwVersionSize = GetFileVersionInfoSizeA(filePath, NULL);
+       LPBYTE lpVersionInfo = new BYTE[dwVersionSize];
+
+       GetFileVersionInfoA(filePath, 0, dwVersionSize, lpVersionInfo);
+       VerQueryValueA(lpVersionInfo, "\\", (LPVOID *)&fixedFileInfo, &blockSize);
+
+       oss << "Windows/"
+               << HIWORD(fixedFileInfo->dwProductVersionMS) << '.' // Major
+               << LOWORD(fixedFileInfo->dwProductVersionMS) << '.' // Minor
+               << HIWORD(fixedFileInfo->dwProductVersionLS) << ' '; // Build
+
        #ifdef _WIN64
        oss << "x86_64";
        #else
@@ -197,6 +204,9 @@ std::string get_sysinfo()
                oss << "x86";
        #endif
 
+       delete[] lpVersionInfo;
+       delete[] filePath;
+
        return oss.str();
 #else
        struct utsname osinfo;