osx_common: Avoid deprecated Gestalt calls

Gestalt is deprecated since 10.8. Change the code to read the OS version from
a system plist file.

As mentioned http://stackoverflow.com/a/11072974/499456 Apple engineers are
suggesting this plist reading approach.
This commit is contained in:
Stefano Pigozzi 2012-12-01 22:07:33 +01:00
parent 96fb9103b5
commit 54d998d5e7
2 changed files with 27 additions and 17 deletions

View File

@ -47,7 +47,7 @@ SOURCES-$(LIBPOSTPROC) += video/filter/vf_pp.c
SOURCES-$(LIBSMBCLIENT) += stream/stream_smb.c
SOURCES-$(MACOSX_FINDER) += osdep/macosx_finder_args.m
SOURCES-$(COCOA) += video/out/osx_common.c \
SOURCES-$(COCOA) += video/out/osx_common.m \
video/out/cocoa_common.m \
osdep/cocoa_events.m
SOURCES-$(MNG) += demux/demux_mng.c

View File

@ -118,27 +118,37 @@ int convert_key(unsigned key, unsigned charcode)
/**
* Checks at runtime that OSX version is the same or newer than the one
* provided as input.
* Currently reads SystemVersion.plist file since Gestalt was deprecated.
* This is supposedly the current way supported by Apple engineers. More info:
* http://stackoverflow.com/a/11072974/499456
*/
int is_osx_version_at_least(int majorv, int minorv, int bugfixv)
{
OSErr err;
SInt32 major, minor, bugfix;
if ((err = Gestalt(gestaltSystemVersionMajor, &major)) != noErr)
goto fail;
if ((err = Gestalt(gestaltSystemVersionMinor, &minor)) != noErr)
goto fail;
if ((err = Gestalt(gestaltSystemVersionBugFix, &bugfix)) != noErr)
goto fail;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *plist = @"/System/Library/CoreServices/SystemVersion.plist";
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:plist];
NSString *version = [dict objectForKey:@"ProductVersion"];
NSArray *components = [version componentsSeparatedByString:@"."];
int rv = 0;
// All the above code just sends messages to nil. If anything failed,
// we just end up with an invalid components array.
if ([components count] != 3) {
mp_msg(MSGT_VO, MSGL_ERR, "[osx] Failed to get your system version. "
"Please open a bug report.\n");
goto cleanup_and_return;
}
int major = [[components objectAtIndex:0] intValue];
int minor = [[components objectAtIndex:1] intValue];
int bugfix = [[components objectAtIndex:2] intValue];
if(major > majorv ||
(major == majorv && (minor > minorv ||
(minor == minorv && bugfix >= bugfixv))))
return 1;
else
return 0;
fail:
// There's no reason the Gestalt system call should fail on OSX.
mp_msg(MSGT_VO, MSGL_FATAL, "[osx] Failed to get system version number. "
"Please contact the developers. Error code: %ld\n", (long)err);
return 0;
rv = 1;
cleanup_and_return:
[pool release];
return rv;
}