diff options
author | glx22 <glx@openttd.org> | 2021-05-20 18:40:11 +0200 |
---|---|---|
committer | Loïc Guilloux <glx22@users.noreply.github.com> | 2021-06-10 23:17:29 +0200 |
commit | f4c7d5577ed83d426371f86d780aed01c5370953 (patch) | |
tree | 0f8ed944d85cc7df95b699c96a28bebbced8b24d | |
parent | ed3946e295f0e74880d85ffb6f6a933ca87e460d (diff) | |
download | openttd-f4c7d5577ed83d426371f86d780aed01c5370953.tar.xz |
Codechange: [WIN32] Use VersionHelpers where appropriate
-rw-r--r-- | src/os/windows/win32.cpp | 32 | ||||
-rw-r--r-- | src/os/windows/win32.h | 1 | ||||
-rw-r--r-- | src/sound/win32_s.cpp | 3 | ||||
-rw-r--r-- | src/video/win32_v.cpp | 1 |
4 files changed, 3 insertions, 34 deletions
diff --git a/src/os/windows/win32.cpp b/src/os/windows/win32.cpp index 3ed0cdb2a..4478caa65 100644 --- a/src/os/windows/win32.cpp +++ b/src/os/windows/win32.cpp @@ -707,38 +707,6 @@ int OTTDStringCompare(const char *s1, const char *s2) return CompareString(MAKELCID(_current_language->winlangid, SORT_DEFAULT), NORM_IGNORECASE, s1_buf, -1, s2_buf, -1); } -/** - * Is the current Windows version Vista or later? - * @return True if the current Windows is Vista or later. - */ -bool IsWindowsVistaOrGreater() -{ - typedef BOOL (WINAPI * LPVERIFYVERSIONINFO)(LPOSVERSIONINFOEX, DWORD, DWORDLONG); - typedef ULONGLONG (NTAPI * LPVERSETCONDITIONMASK)(ULONGLONG, DWORD, BYTE); -#ifdef UNICODE - static LPVERIFYVERSIONINFO _VerifyVersionInfo = (LPVERIFYVERSIONINFO)GetProcAddress(GetModuleHandle(_T("Kernel32")), "VerifyVersionInfoW"); -#else - static LPVERIFYVERSIONINFO _VerifyVersionInfo = (LPVERIFYVERSIONINFO)GetProcAddress(GetModuleHandle(_T("Kernel32")), "VerifyVersionInfoA"); -#endif - static LPVERSETCONDITIONMASK _VerSetConditionMask = (LPVERSETCONDITIONMASK)GetProcAddress(GetModuleHandle(_T("Kernel32")), "VerSetConditionMask"); - - if (_VerifyVersionInfo != nullptr && _VerSetConditionMask != nullptr) { - OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, 0, 0, {0}, 0, 0 }; - DWORDLONG dwlConditionMask = 0; - dwlConditionMask = _VerSetConditionMask(dwlConditionMask, VER_MAJORVERSION, VER_GREATER_EQUAL); - dwlConditionMask = _VerSetConditionMask(dwlConditionMask, VER_MINORVERSION, VER_GREATER_EQUAL); - dwlConditionMask = _VerSetConditionMask(dwlConditionMask, VER_SERVICEPACKMAJOR, VER_GREATER_EQUAL); - - osvi.dwMajorVersion = 6; - osvi.dwMinorVersion = 0; - osvi.wServicePackMajor = 0; - - return _VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION | VER_SERVICEPACKMAJOR, dwlConditionMask) != FALSE; - } else { - return LOBYTE(GetVersion()) >= 6; - } -} - #ifdef _MSC_VER /* Based on code from MSDN: https://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx */ const DWORD MS_VC_EXCEPTION = 0x406D1388; diff --git a/src/os/windows/win32.h b/src/os/windows/win32.h index 095181c46..b2048375b 100644 --- a/src/os/windows/win32.h +++ b/src/os/windows/win32.h @@ -25,6 +25,5 @@ wchar_t *convert_to_fs(const char *name, wchar_t *utf16_buf, size_t buflen); void Win32SetCurrentLocaleName(const char *iso_code); int OTTDStringCompare(const char *s1, const char *s2); -bool IsWindowsVistaOrGreater(); #endif /* WIN32_H */ diff --git a/src/sound/win32_s.cpp b/src/sound/win32_s.cpp index eccbb4f42..87959e586 100644 --- a/src/sound/win32_s.cpp +++ b/src/sound/win32_s.cpp @@ -17,6 +17,7 @@ #include "win32_s.h" #include <windows.h> #include <mmsystem.h> +#include <versionhelpers.h> #include "../os/windows/win32.h" #include "../thread.h" @@ -69,7 +70,7 @@ const char *SoundDriver_Win32::Start(const StringList &parm) wfex.nAvgBytesPerSec = wfex.nSamplesPerSec * wfex.nBlockAlign; /* Limit buffer size to prevent overflows. */ - _bufsize = GetDriverParamInt(parm, "bufsize", (GB(GetVersion(), 0, 8) > 5) ? 8192 : 4096); + _bufsize = GetDriverParamInt(parm, "bufsize", IsWindowsVistaOrGreater() ? 8192 : 4096); _bufsize = std::min<int>(_bufsize, UINT16_MAX); try { diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index f0291db71..7dfc0034a 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -25,6 +25,7 @@ #include "win32_v.h" #include <windows.h> #include <imm.h> +#include <versionhelpers.h> #include "../safeguards.h" |