Launch the game with argv *and* a dock icon

This commit is contained in:
Paul Chote
2010-04-17 02:36:31 +12:00
parent 47ccd80b14
commit cd7b4de529

View File

@@ -37,21 +37,30 @@
[settings setValue:modString forSetting:@"InitialMods"]; [settings setValue:modString forSetting:@"InitialMods"];
[settings save]; [settings save];
// Launch the game // Neither NSTask or NSWorkspace do what we want on pre-10.6 (we want *both* Info.plist and argument support)
NSMutableArray *args = [NSMutableArray arrayWithObjects:@"settings=../../../launcher.ini",nil]; // so use the LaunchServices api directly
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OpenRA.app/Contents/MacOS/OpenRA"]; NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OpenRA.app/Contents/MacOS/OpenRA"];
NSArray *args = [NSArray arrayWithObjects:@"settings=../../../launcher.ini",nil];
NSTask *task = [[NSTask alloc] init]; FSRef appRef;
[task setLaunchPath:path]; CFURLGetFSRef((CFURLRef)[NSURL URLWithString:path], &appRef);
[task setArguments:args];
[task launch]; // Set the launch parameters
LSApplicationParameters params;
params.version = 0;
params.flags = kLSLaunchDefaults;
params.application = &appRef;
params.asyncLaunchRefCon = NULL;
params.environment = NULL; // CFDictionaryRef of environment variables; could be useful
params.argv = (CFArrayRef)args;
params.initialEvent = NULL;
// Bring the game to the front
ProcessSerialNumber psn; ProcessSerialNumber psn;
if (noErr == GetProcessForPID([task processIdentifier], &psn)) { OSStatus err = LSOpenApplication(&params, &psn);
// Bring the game window to the front
if (err == noErr)
SetFrontProcess(&psn); SetFrontProcess(&psn);
}
[task release];
// Close the launcher // Close the launcher
[NSApp terminate: nil]; [NSApp terminate: nil];