summaryrefslogtreecommitdiffstats
path: root/video
diff options
context:
space:
mode:
authorStefano Pigozzi <stefano.pigozzi@gmail.com>2012-12-01 22:07:33 +0100
committerStefano Pigozzi <stefano.pigozzi@gmail.com>2012-12-02 10:42:46 +0100
commit54d998d5e7f101312cf26e9fc4d199fa9fed33c2 (patch)
treed37d0a543b6de84b86a06f82dfdd5700db455b3a /video
parent96fb9103b55b253002fa8bc536c65f07477d4b69 (diff)
downloadmpv-54d998d5e7f101312cf26e9fc4d199fa9fed33c2.tar.bz2
mpv-54d998d5e7f101312cf26e9fc4d199fa9fed33c2.tar.xz
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.
Diffstat (limited to 'video')
-rw-r--r--video/out/osx_common.m (renamed from video/out/osx_common.c)42
1 files changed, 26 insertions, 16 deletions
diff --git a/video/out/osx_common.c b/video/out/osx_common.m
index ff2df8daff..58198c11e2 100644
--- a/video/out/osx_common.c
+++ b/video/out/osx_common.m
@@ -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;
}