From fb2d65f2be87f4c025ef20628f18a93a493fc464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Wed, 21 Oct 2015 09:49:35 +0200 Subject: [PATCH] Fix compatibility with pre-10.10 OS X User-Agent change from 2c8dae7c broke Poedit on OS X older than Yosemite, where it caused early abort, because [NSProcessInfo operatingSystemVersion] wasn't available until 10.9.2 (and 10.10 officially). Use the now-deprecated Gestalt() function on older systems. --- src/http_client_osx.mm | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/http_client_osx.mm b/src/http_client_osx.mm index b96fd90e5a..8d3945c88e 100644 --- a/src/http_client_osx.mm +++ b/src/http_client_osx.mm @@ -130,10 +130,24 @@ static inline json_dict make_json_dict(NSDictionary *d) // to the server. [m_native.operationQueue setMaxConcurrentOperationCount:NSIntegerMax]; - NSOperatingSystemVersion osx = [[NSProcessInfo processInfo] operatingSystemVersion]; - NSString *osx_str = (osx.patchVersion == 0) - ? [NSString stringWithFormat:@"%d.%d", (int)osx.majorVersion, (int)osx.minorVersion] - : [NSString stringWithFormat:@"%d.%d.%d", (int)osx.majorVersion, (int)osx.minorVersion, (int)osx.patchVersion]; + int majorVersion, minorVersion, patchVersion; + NSProcessInfo *process = [NSProcessInfo processInfo]; + if ([process respondsToSelector:@selector(operatingSystemVersion)]) + { + NSOperatingSystemVersion osx = [process operatingSystemVersion]; + majorVersion = (int)osx.majorVersion; + minorVersion = (int)osx.minorVersion; + patchVersion = (int)osx.patchVersion; + } + else + { + Gestalt(gestaltSystemVersionMajor, &majorVersion); + Gestalt(gestaltSystemVersionMinor, &minorVersion); + Gestalt(gestaltSystemVersionBugFix, &patchVersion); + } + NSString *osx_str = (patchVersion == 0) + ? [NSString stringWithFormat:@"%d.%d", majorVersion, minorVersion] + : [NSString stringWithFormat:@"%d.%d.%d", majorVersion, minorVersion, patchVersion]; [m_native setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"Poedit/%s (Mac OS X %@)", POEDIT_VERSION, osx_str]]; }