Add wxCheckOsVersion() to implement platform based OS version checks.
Windows implements VerifyVersionInfo api since Win2k. Starting with Windows 8.1 GetVersionEx is deprecated and may not return the expected version number if the application does not contain the correct compatibility information in its manifest. VerifyVersionInfo works independent of manifest in the executable (and is the recommend way to check). Existing code may already use wxPlatformInfo::CheckOSVersion() so the method forwards the call to wxCheckOsVersion if initialized for the current system.
This commit is contained in:
parent
d8e291c27a
commit
2b3633b3c0
@ -190,13 +190,7 @@ public:
|
||||
{ return m_osVersionMinor; }
|
||||
|
||||
// return true if the OS version >= major.minor
|
||||
bool CheckOSVersion(int major, int minor) const
|
||||
{
|
||||
return DoCheckVersion(GetOSMajorVersion(),
|
||||
GetOSMinorVersion(),
|
||||
major,
|
||||
minor);
|
||||
}
|
||||
bool CheckOSVersion(int major, int minor) const;
|
||||
|
||||
int GetToolkitMajorVersion() const
|
||||
{ return m_tkVersionMajor; }
|
||||
@ -300,6 +294,8 @@ protected:
|
||||
return majorCur > major || (majorCur == major && minorCur >= minor);
|
||||
}
|
||||
|
||||
bool m_initializedForCurrentPlatform;
|
||||
|
||||
void InitForCurrentPlatform();
|
||||
|
||||
|
||||
|
@ -143,6 +143,9 @@ WXDLLIMPEXP_BASE wxString wxGetOsDescription();
|
||||
WXDLLIMPEXP_BASE wxOperatingSystemId wxGetOsVersion(int *majorVsn = NULL,
|
||||
int *minorVsn = NULL);
|
||||
|
||||
// Check is OS version is at least the specified major and minor version
|
||||
WXDLLIMPEXP_BASE bool wxCheckOsVersion(int majorVsn, int minorVsn = 0);
|
||||
|
||||
// Get platform endianness
|
||||
WXDLLIMPEXP_BASE bool wxIsPlatformLittleEndian();
|
||||
|
||||
|
@ -879,6 +879,18 @@ wxString wxGetOsDescription();
|
||||
*/
|
||||
wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL);
|
||||
|
||||
/**
|
||||
Returns @true the version of the operating system on which the program
|
||||
is running under is the same or later than the given version.
|
||||
|
||||
@since 3.1.0
|
||||
|
||||
@see wxGetOsVersion(), wxPlatformInfo
|
||||
|
||||
@header{wx/utils.h}
|
||||
*/
|
||||
bool wxCheckOsVersion(int majorVsn, int minorVsn = 0);
|
||||
|
||||
/**
|
||||
Returns @true if the operating system the program is running under is 64
|
||||
bit. The check is performed at run-time and may differ from the value
|
||||
|
@ -135,6 +135,8 @@ wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
|
||||
wxEndianness endian,
|
||||
bool usingUniversal)
|
||||
{
|
||||
m_initializedForCurrentPlatform = false;
|
||||
|
||||
m_tkVersionMajor = tkMajor;
|
||||
m_tkVersionMinor = tkMinor;
|
||||
m_port = pid;
|
||||
@ -166,6 +168,8 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
|
||||
|
||||
void wxPlatformInfo::InitForCurrentPlatform()
|
||||
{
|
||||
m_initializedForCurrentPlatform = true;
|
||||
|
||||
// autodetect all informations
|
||||
const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
|
||||
if ( !traits )
|
||||
@ -294,6 +298,19 @@ wxString wxPlatformInfo::GetEndiannessName(wxEndianness end)
|
||||
return wxEndiannessNames[end];
|
||||
}
|
||||
|
||||
bool wxPlatformInfo::CheckOSVersion(int major, int minor) const
|
||||
{
|
||||
// If this instance of wxPlatformInfo has been initialized by InitForCurrentPlatform()
|
||||
// this check gets forwarded to the wxCheckOsVersion which might do more than a simple
|
||||
// number check if supported by the platform
|
||||
if (m_initializedForCurrentPlatform)
|
||||
return wxCheckOsVersion(major, minor);
|
||||
else
|
||||
return DoCheckVersion(GetOSMajorVersion(),
|
||||
GetOSMinorVersion(),
|
||||
major,
|
||||
minor);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxPlatformInfo - string -> enum conversions
|
||||
|
@ -1327,6 +1327,21 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
|
||||
return s_version.os;
|
||||
}
|
||||
|
||||
bool wxCheckOsVersion(int majorVsn, int minorVsn)
|
||||
{
|
||||
OSVERSIONINFOEX osvi = { sizeof(osvi), 0, 0, 0, 0, { 0 }, 0, 0 };
|
||||
DWORDLONG const dwlConditionMask =
|
||||
::VerSetConditionMask(
|
||||
::VerSetConditionMask(
|
||||
0, VER_MAJORVERSION, VER_GREATER_EQUAL),
|
||||
VER_MINORVERSION, VER_GREATER_EQUAL);
|
||||
|
||||
osvi.dwMajorVersion = majorVsn;
|
||||
osvi.dwMinorVersion = minorVsn;
|
||||
|
||||
return ::VerifyVersionInfo(&osvi, VER_MAJORVERSION | VER_MINORVERSION, dwlConditionMask) != FALSE;
|
||||
}
|
||||
|
||||
wxWinVersion wxGetWinVersion()
|
||||
{
|
||||
int verMaj,
|
||||
|
@ -1150,6 +1150,14 @@ wxString wxGetOsDescription()
|
||||
|
||||
#endif // !__DARWIN__
|
||||
|
||||
bool wxCheckOsVersion(int majorVsn, int minorVsn)
|
||||
{
|
||||
int majorCur, minorCur;
|
||||
wxGetOsVersion(&majorCur, &minorCur);
|
||||
|
||||
return majorCur > majorVsn || (majorCur == majorVsn && minorCur >= minorVsn);
|
||||
}
|
||||
|
||||
unsigned long wxGetProcessId()
|
||||
{
|
||||
return (unsigned long)getpid();
|
||||
|
Loading…
Reference in New Issue
Block a user