Launch the game with argv *and* a dock icon
This commit is contained in:
@@ -36,23 +36,32 @@
|
|||||||
NSString *modString = [[mods objectAtIndex:[modsList selectedRow]] objectForKey:@"Mods"];
|
NSString *modString = [[mods objectAtIndex:[modsList selectedRow]] objectForKey:@"Mods"];
|
||||||
[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];
|
||||||
|
|
||||||
|
FSRef appRef;
|
||||||
|
CFURLGetFSRef((CFURLRef)[NSURL URLWithString:path], &appRef);
|
||||||
|
|
||||||
NSTask *task = [[NSTask alloc] init];
|
// Set the launch parameters
|
||||||
[task setLaunchPath:path];
|
LSApplicationParameters params;
|
||||||
[task setArguments:args];
|
params.version = 0;
|
||||||
[task launch];
|
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(¶ms, &psn);
|
||||||
SetFrontProcess(&psn);
|
|
||||||
}
|
|
||||||
[task release];
|
|
||||||
|
|
||||||
|
// Bring the game window to the front
|
||||||
|
if (err == noErr)
|
||||||
|
SetFrontProcess(&psn);
|
||||||
|
|
||||||
// Close the launcher
|
// Close the launcher
|
||||||
[NSApp terminate: nil];
|
[NSApp terminate: nil];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user