Add a micro version parameter to wxGetOsVersion

In addition to getting a major and minor OS version allow a micro
version to be retrieved. In case of running on e.g. OS X 10.10.3 this
allows the "3" to be retrieved again.
This commit is contained in:
Dimitri Schoolwerth 2015-06-24 06:22:33 +04:00 committed by Tobias Taschner
parent 5983274af6
commit b1a9c6e79e
5 changed files with 30 additions and 11 deletions

View File

@ -141,7 +141,8 @@ WXDLLIMPEXP_BASE wxString wxGetOsDescription();
// Get OS version
WXDLLIMPEXP_BASE wxOperatingSystemId wxGetOsVersion(int *verMaj = NULL,
int *verMin = NULL);
int *verMin = NULL,
int *verMicro = NULL);
// Check is OS version is at least the specified major and minor version
WXDLLIMPEXP_BASE bool wxCheckOsVersion(int majorVsn, int minorVsn = 0);

View File

@ -842,16 +842,22 @@ wxString wxGetOsDescription();
/**
Gets the version and the operating system ID for currently running OS.
The returned wxOperatingSystemId value can be used for a basic categorization
of the OS family; the major and minor version numbers allows to detect a specific
system.
of the OS family; the major, minor, and micro version numbers allows to
detect a specific system.
If on Unix-like systems the version can't be detected all three version
numbers will have a value of -1.
On systems where only the micro version can't be detected or doesn't make
sense such as Windows, it will have a value of 0.
For Unix-like systems (@c wxOS_UNIX) the major and minor version integers will
contain the kernel major and minor version numbers (as returned by the
'uname -r' command); e.g. "4" and "1" if the machine is using kernel 4.1.4.
For OS X systems (@c wxOS_MAC) the major and minor version integers are the
natural version numbers associated with the OS; e.g. "10" and "11" if the machine
is using OS X El Capitan.
natural version numbers associated with the OS; e.g. "10", "11" and "2" if
the machine is using OS X El Capitan 10.11.2.
For Windows-like systems (@c wxOS_WINDOWS) the major and minor version integers will
contain the following values:
@ -878,7 +884,7 @@ wxString wxGetOsDescription();
@header{wx/utils.h}
*/
wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL);
wxOperatingSystemId wxGetOsVersion(int* major = NULL, int* minor = NULL, int* micro = NULL);
/**
Returns @true if the version of the operating system on which the program

View File

@ -1235,7 +1235,7 @@ bool wxIsPlatform64Bit()
#endif // Win64/Win32
}
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
{
static struct
{
@ -1273,6 +1273,8 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
*verMaj = s_version.verMaj;
if ( verMin )
*verMin = s_version.verMin;
if ( verMicro )
*verMicro = 0;
return s_version.os;
}

View File

@ -28,7 +28,7 @@
#endif
// our OS version is the same in non GUI and GUI cases
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
{
#ifdef wxHAS_NSPROCESSINFO
if ([NSProcessInfo instancesRespondToSelector:@selector(operatingSystemVersion)])
@ -40,6 +40,9 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
if ( verMin != NULL )
*verMin = osVer.minorVersion;
if ( verMicro != NULL )
*verMicro = osVer.patchVersion;
}
else
#endif
@ -47,13 +50,15 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
// On OS X versions prior to 10.10 NSProcessInfo does not provide the OS version
// Deprecated Gestalt calls are required instead
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
SInt32 maj, min;
SInt32 maj, min, micro;
#ifdef __WXOSX_IPHONE__
maj = 7;
min = 0;
micro = 0;
#else
Gestalt(gestaltSystemVersionMajor, &maj);
Gestalt(gestaltSystemVersionMinor, &min);
Gestalt(gestaltSystemVersionBugFix, &micro);
#endif
wxGCC_WARNING_RESTORE()
@ -62,6 +67,9 @@ wxGCC_WARNING_RESTORE()
if ( verMin != NULL )
*verMin = min;
if ( verMicro != NULL )
*verMicro = micro;
}
return wxOS_MAC_OSX_DARWIN;

View File

@ -1114,7 +1114,7 @@ wxLinuxDistributionInfo wxGetLinuxDistributionInfo()
// these functions are in src/osx/utilsexc_base.cpp for wxMac
#ifndef __DARWIN__
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin, int *verMicro)
{
// get OS version
int major, minor;
@ -1131,6 +1131,8 @@ wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
*verMaj = major;
if ( verMin )
*verMin = minor;
if ( verMicro )
*verMicro = (major == -1) ? -1 : 0;
// try to understand which OS are we running
wxString kernel = wxGetCommandOutput(wxT("uname -s"));