- replaced usage of deprecated APIs to get macOS version

This commit is contained in:
alexey.lysiuk 2018-07-15 10:43:52 +03:00
parent 181c923001
commit fc7af31cb9

View file

@ -125,20 +125,36 @@ void Mac_I_FatalError(const char* const message)
} }
#if MAC_OS_X_VERSION_MAX_ALLOWED < 101000
// Available since 10.9 with no public declaration/definition until 10.10
struct NSOperatingSystemVersion
{
NSInteger majorVersion;
NSInteger minorVersion;
NSInteger patchVersion;
};
@interface NSProcessInfo(OperatingSystemVersion)
- (NSOperatingSystemVersion)operatingSystemVersion;
@end
#endif // before 10.10
static void I_DetectOS() static void I_DetectOS()
{ {
SInt32 majorVersion = 0; NSOperatingSystemVersion version = {};
Gestalt(gestaltSystemVersionMajor, &majorVersion); NSProcessInfo* const processInfo = [NSProcessInfo processInfo];
SInt32 minorVersion = 0; if ([processInfo respondsToSelector:@selector(operatingSystemVersion)])
Gestalt(gestaltSystemVersionMinor, &minorVersion); {
version = [processInfo operatingSystemVersion];
SInt32 bugFixVersion = 0; }
Gestalt(gestaltSystemVersionBugFix, &bugFixVersion);
const char* name = "Unknown version"; const char* name = "Unknown version";
if (10 == majorVersion) switch (minorVersion) if (10 == version.majorVersion) switch (version.minorVersion)
{ {
case 7: name = "Mac OS X Lion"; break; case 7: name = "Mac OS X Lion"; break;
case 8: name = "OS X Mountain Lion"; break; case 8: name = "OS X Mountain Lion"; break;
@ -164,8 +180,8 @@ static void I_DetectOS()
#endif #endif
Printf("OS: %s %d.%d.%d (%s) %s\n", name, Printf("OS: %s %d.%d.%d (%s) %s\n", name,
int(majorVersion), int(minorVersion), int(bugFixVersion), int(version.majorVersion), int(version.minorVersion), int(version.patchVersion),
release, architecture); release, architecture);
} }