From 86b2a8530bb7bc6fc83123bcd39f09fa4d5391de Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Tue, 6 Jan 2015 17:06:29 +0200 Subject: [PATCH] Fixed launching with additional arguments from IWAD picker on OS X 10.4 --- src/posix/osx/iwadpicker_cocoa.mm | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/posix/osx/iwadpicker_cocoa.mm b/src/posix/osx/iwadpicker_cocoa.mm index e5050f8012..d2bc1ff0cc 100644 --- a/src/posix/osx/iwadpicker_cocoa.mm +++ b/src/posix/osx/iwadpicker_cocoa.mm @@ -408,21 +408,28 @@ static void RestartWithParameters(const char* iwadPath, NSString* parameters) @try { - const int commandLineParametersCount = Args->NumArgs(); - assert(commandLineParametersCount > 0); - NSString* executablePath = [NSString stringWithUTF8String:Args->GetArg(0)]; - NSString* architecture = GetArchitectureString(); - NSMutableArray* arguments = [NSMutableArray arrayWithCapacity:commandLineParametersCount + 6]; - [arguments addObject:@"-arch"]; - [arguments addObject:architecture]; - [arguments addObject:executablePath]; + NSMutableArray* const arguments = [[NSMutableArray alloc] init]; + + // The following value shoud be equal to NSAppKitVersionNumber10_5 + // It's hard-coded in order to build with earlier SDKs + const bool canSelectArchitecture = NSAppKitVersionNumber >= 949; + + if (canSelectArchitecture) + { + [arguments addObject:@"-arch"]; + [arguments addObject:GetArchitectureString()]; + [arguments addObject:executablePath]; + + executablePath = @"/usr/bin/arch"; + } + [arguments addObject:@"-wad_picker_restart"]; [arguments addObject:@"-iwad"]; [arguments addObject:[NSString stringWithUTF8String:iwadPath]]; - for (int i = 1; i < commandLineParametersCount; ++i) + for (int i = 1, count = Args->NumArgs(); i < count; ++i) { NSString* currentParameter = [NSString stringWithUTF8String:Args->GetArg(i)]; [arguments addObject:currentParameter]; @@ -442,7 +449,8 @@ static void RestartWithParameters(const char* iwadPath, NSString* parameters) wordfree(&expansion); } - [NSTask launchedTaskWithLaunchPath:@"/usr/bin/arch" arguments:arguments]; + [NSTask launchedTaskWithLaunchPath:executablePath + arguments:arguments]; _exit(0); // to avoid atexit()'s functions }