mirror of https://github.com/mpv-player/mpv
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:
parent
96fb9103b5
commit
54d998d5e7
2
Makefile
2
Makefile
|
@ -47,7 +47,7 @@ SOURCES-$(LIBPOSTPROC) += video/filter/vf_pp.c
|
||||||
SOURCES-$(LIBSMBCLIENT) += stream/stream_smb.c
|
SOURCES-$(LIBSMBCLIENT) += stream/stream_smb.c
|
||||||
|
|
||||||
SOURCES-$(MACOSX_FINDER) += osdep/macosx_finder_args.m
|
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 \
|
video/out/cocoa_common.m \
|
||||||
osdep/cocoa_events.m
|
osdep/cocoa_events.m
|
||||||
SOURCES-$(MNG) += demux/demux_mng.c
|
SOURCES-$(MNG) += demux/demux_mng.c
|
||||||
|
|
|
@ -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
|
* Checks at runtime that OSX version is the same or newer than the one
|
||||||
* provided as input.
|
* 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)
|
int is_osx_version_at_least(int majorv, int minorv, int bugfixv)
|
||||||
{
|
{
|
||||||
OSErr err;
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
||||||
SInt32 major, minor, bugfix;
|
NSString *plist = @"/System/Library/CoreServices/SystemVersion.plist";
|
||||||
if ((err = Gestalt(gestaltSystemVersionMajor, &major)) != noErr)
|
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:plist];
|
||||||
goto fail;
|
NSString *version = [dict objectForKey:@"ProductVersion"];
|
||||||
if ((err = Gestalt(gestaltSystemVersionMinor, &minor)) != noErr)
|
NSArray *components = [version componentsSeparatedByString:@"."];
|
||||||
goto fail;
|
int rv = 0;
|
||||||
if ((err = Gestalt(gestaltSystemVersionBugFix, &bugfix)) != noErr)
|
|
||||||
goto fail;
|
// 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 ||
|
if(major > majorv ||
|
||||||
(major == majorv && (minor > minorv ||
|
(major == majorv && (minor > minorv ||
|
||||||
(minor == minorv && bugfix >= bugfixv))))
|
(minor == minorv && bugfix >= bugfixv))))
|
||||||
return 1;
|
rv = 1;
|
||||||
else
|
|
||||||
return 0;
|
cleanup_and_return:
|
||||||
fail:
|
[pool release];
|
||||||
// There's no reason the Gestalt system call should fail on OSX.
|
return rv;
|
||||||
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;
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue