macosx_application: remove deprecation warning on OS X 10.9

GetCurrentProcess() is deprecated on 10.9. Make a universal solution by
checking OS version number.

get_system_version() function is the recommended Apple way of getting the
OS version, since Gestalt is also deprecated (and does pretty much the same
thing anyway)

Updating HIDRemote.m to use a similar function would allow to get rid of the
2 other warnings.
This commit is contained in:
Nyx0uf 2013-09-16 19:35:01 +02:00 committed by Stefano Pigozzi
parent 44b6696279
commit 95a2151d19
1 changed files with 28 additions and 14 deletions

View File

@ -413,25 +413,39 @@ static void macosx_redirect_output_to_logfile(const char *filename)
[pool release]; [pool release];
} }
static bool psn_matches_current_process(char *psn_arg_to_check) static void get_system_version(int* major, int* minor, int* bugfix)
{ {
ProcessSerialNumber psn; static dispatch_once_t once_token;
GetCurrentProcess(&psn); static int s_major = 0;
static int s_minor = 0;
NSString *in_psn = [NSString stringWithUTF8String:psn_arg_to_check]; static int s_bugfix = 0;
NSString *real_psn = [NSString stringWithFormat:@"-psn_%u_%u", dispatch_once(&once_token, ^{
psn.highLongOfPSN, psn.lowLongOfPSN]; NSString *version_plist =
@"/System/Library/CoreServices/SystemVersion.plist";
return [real_psn isEqualToString:in_psn]; NSString *version_string =
[NSDictionary dictionaryWithContentsOfFile:version_plist]
[@"ProductVersion"];
NSArray* versions = [version_string componentsSeparatedByString:@"."];
int count = [versions count];
if (count >= 1)
s_major = [versions[0] intValue];
if (count >= 2)
s_minor = [versions[1] intValue];
if (count >= 3)
s_bugfix = [versions[2] intValue];
});
*major = s_major;
*minor = s_minor;
*bugfix = s_bugfix;
} }
static bool bundle_started_from_finder(int argc, char **argv) static bool bundle_started_from_finder(int argc, char **argv)
{ {
bool bundle_detected = [[NSBundle mainBundle] bundleIdentifier]; bool bundle_detected = [[NSBundle mainBundle] bundleIdentifier];
bool pre_mavericks_args = argc==2 && psn_matches_current_process(argv[1]); int major, minor, bugfix;
bool post_mavericks_args = argc==1; get_system_version(&major, &minor, &bugfix);
bool finder_args = ((major == 10) && (minor >= 9)) ? argc==1 : argc==2;
return bundle_detected && (pre_mavericks_args || post_mavericks_args); return bundle_detected && finder_args;
} }
void macosx_finder_args_preinit(int *argc, char ***argv) void macosx_finder_args_preinit(int *argc, char ***argv)