New launch mechanism: removes wrapper app bundle, and supports paths with spaces.

This commit is contained in:
Paul Chote
2010-12-23 10:35:41 +13:00
parent 3149f3efa2
commit 275dfc43be
8 changed files with 47 additions and 35 deletions

View File

@@ -94,22 +94,22 @@
-(void)launchMod:(NSString *)mod -(void)launchMod:(NSString *)mod
{ {
// Use LaunchServices because neither NSTask or NSWorkspace support Info.plist _and_ arguments pre-10.6 // Use LaunchServices because neither NSTask or NSWorkspace support Info.plist _and_ arguments pre-10.6
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"OpenRA.app/Contents/MacOS/OpenRA"];
// First argument is the directory to run in // First argument is the directory to run in
// Second...Nth arguments are passed to OpenRA.Game.exe // Second...Nth arguments are passed to OpenRA.Game.exe
// Launcher wrapper sets mono --debug, gl renderer and support dir. // Launcher wrapper sets mono --debug, gl renderer and support dir.
NSArray *args = [NSArray arrayWithObjects:gamePath, NSArray *args = [NSArray arrayWithObjects:@"--launch", gamePath,
[NSString stringWithFormat:@"SupportDir=%@",[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath]],
[NSString stringWithFormat:@"Game.Mods=%@",mod], [NSString stringWithFormat:@"Game.Mods=%@",mod],
nil]; nil];
FSRef appRef; FSRef appRef;
CFURLGetFSRef((CFURLRef)[NSURL URLWithString:path], &appRef); CFURLGetFSRef((CFURLRef)[NSURL URLWithString:[[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], &appRef);
// Set the launch parameters // Set the launch parameters
LSApplicationParameters params; LSApplicationParameters params;
params.version = 0; params.version = 0;
params.flags = kLSLaunchDefaults; params.flags = kLSLaunchDefaults | kLSLaunchNewInstance;
params.application = &appRef; params.application = &appRef;
params.asyncLaunchRefCon = NULL; params.asyncLaunchRefCon = NULL;
params.environment = NULL; // CFDictionaryRef of environment variables; could be useful params.environment = NULL; // CFDictionaryRef of environment variables; could be useful

View File

@@ -18,7 +18,6 @@
DA81FB9312910A8B00C48F2F /* ImageAndTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FB9212910A8B00C48F2F /* ImageAndTextCell.m */; }; DA81FB9312910A8B00C48F2F /* ImageAndTextCell.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FB9212910A8B00C48F2F /* ImageAndTextCell.m */; };
DA81FBDC12910E4900C48F2F /* OpenRA.icns in Resources */ = {isa = PBXBuildFile; fileRef = DA81FBDB12910E4900C48F2F /* OpenRA.icns */; }; DA81FBDC12910E4900C48F2F /* OpenRA.icns in Resources */ = {isa = PBXBuildFile; fileRef = DA81FBDB12910E4900C48F2F /* OpenRA.icns */; };
DA81FC3F12911E2B00C48F2F /* GameInstall.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FC3E12911E2B00C48F2F /* GameInstall.m */; }; DA81FC3F12911E2B00C48F2F /* GameInstall.m in Sources */ = {isa = PBXBuildFile; fileRef = DA81FC3E12911E2B00C48F2F /* GameInstall.m */; };
DA9292C81291DF2D00EDB02E /* OpenRA.app in Resources */ = {isa = PBXBuildFile; fileRef = DA9292C71291DF2D00EDB02E /* OpenRA.app */; };
DA9295A712921DF900EDB02E /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA9295A612921DF900EDB02E /* WebKit.framework */; }; DA9295A712921DF900EDB02E /* WebKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA9295A612921DF900EDB02E /* WebKit.framework */; };
DA9296901292328200EDB02E /* SidebarEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = DA92968F1292328200EDB02E /* SidebarEntry.m */; }; DA9296901292328200EDB02E /* SidebarEntry.m in Sources */ = {isa = PBXBuildFile; fileRef = DA92968F1292328200EDB02E /* SidebarEntry.m */; };
DAB887F5129E5D6C00C99407 /* SDL in Resources */ = {isa = PBXBuildFile; fileRef = DAB887EE129E5D6100C99407 /* SDL */; }; DAB887F5129E5D6C00C99407 /* SDL in Resources */ = {isa = PBXBuildFile; fileRef = DAB887EE129E5D6100C99407 /* SDL */; };
@@ -47,7 +46,6 @@
DA81FBDB12910E4900C48F2F /* OpenRA.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = OpenRA.icns; sourceTree = "<group>"; }; DA81FBDB12910E4900C48F2F /* OpenRA.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = OpenRA.icns; sourceTree = "<group>"; };
DA81FC3D12911E2B00C48F2F /* GameInstall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameInstall.h; sourceTree = "<group>"; }; DA81FC3D12911E2B00C48F2F /* GameInstall.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GameInstall.h; sourceTree = "<group>"; };
DA81FC3E12911E2B00C48F2F /* GameInstall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameInstall.m; sourceTree = "<group>"; }; DA81FC3E12911E2B00C48F2F /* GameInstall.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GameInstall.m; sourceTree = "<group>"; };
DA9292C71291DF2D00EDB02E /* OpenRA.app */ = {isa = PBXFileReference; lastKnownFileType = wrapper.application; path = OpenRA.app; sourceTree = "<group>"; };
DA9295A612921DF900EDB02E /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; }; DA9295A612921DF900EDB02E /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = WebKit.framework; path = System/Library/Frameworks/WebKit.framework; sourceTree = SDKROOT; };
DA92968E1292328200EDB02E /* SidebarEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SidebarEntry.h; sourceTree = "<group>"; }; DA92968E1292328200EDB02E /* SidebarEntry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SidebarEntry.h; sourceTree = "<group>"; };
DA92968F1292328200EDB02E /* SidebarEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SidebarEntry.m; sourceTree = "<group>"; }; DA92968F1292328200EDB02E /* SidebarEntry.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SidebarEntry.m; sourceTree = "<group>"; };
@@ -139,7 +137,6 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
DAB887EE129E5D6100C99407 /* SDL */, DAB887EE129E5D6100C99407 /* SDL */,
DA9292C71291DF2D00EDB02E /* OpenRA.app */,
DA81FBDB12910E4900C48F2F /* OpenRA.icns */, DA81FBDB12910E4900C48F2F /* OpenRA.icns */,
8D1107310486CEB800E47090 /* OpenRA-Info.plist */, 8D1107310486CEB800E47090 /* OpenRA-Info.plist */,
089C165CFE840E0CC02AAC07 /* InfoPlist.strings */, 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */,
@@ -214,7 +211,6 @@
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */, 8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */,
1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */, 1DDD58160DA1D0A300B32029 /* MainMenu.xib in Resources */,
DA81FBDC12910E4900C48F2F /* OpenRA.icns in Resources */, DA81FBDC12910E4900C48F2F /* OpenRA.icns in Resources */,
DA9292C81291DF2D00EDB02E /* OpenRA.app in Resources */,
); );
runOnlyForDeploymentPostprocessing = 0; runOnlyForDeploymentPostprocessing = 0;
}; };

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>OpenRA</string>
<key>CFBundleExecutable</key>
<string>OpenRA</string>
<key>CFBundleIconFile</key>
<string>OpenRA.icns</string>
</dict>
</plist>

View File

@@ -1,11 +0,0 @@
#!/bin/bash
# Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
# This file is part of OpenRA, which is free software. It is made
# available to you under the terms of the GNU General Public License
# as published by the Free Software Foundation. For more information,
# see LICENSE.
export DYLD_LIBRARY_PATH="$1:$DYLD_LIBRARY_PATH"
echo "Launching OpenRA from $1"
cd $1
mono --debug OpenRA.Game.exe SupportDir=~/Library/"Application Support"/OpenRA ${@:2}

View File

@@ -8,7 +8,47 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
extern char **environ;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
/* When launching a mod, the arguments are of the form
* --launch <game dir> <support dir option> <mod option> */
if (argc >= 5 && strcmp(argv[1], "--launch") == 0)
{
/* Change into the game dir */
chdir(argv[2]);
/* Command line args for mono */
char *args[] = {
"/Library/Frameworks/Mono.framework/Commands/mono",
"--debug",
"OpenRA.Game.exe",
argv[3],
argv[4],
NULL
};
/* add game dir to DYLD_LIBRARY_PATH */
char *old = getenv("DYLD_LIBRARY_PATH");
if (old == NULL)
setenv("DYLD_LIBRARY_PATH", argv[2], 1);
else
{
char buf[512];
int len = strlen(argv[2]) + strlen(old) + 2;
if (len > 512)
{
NSLog(@"Insufficient DYLD_LIBRARY_PATH buffer length. Wanted %d, had 512", len);
exit(1);
}
sprintf(buf,"%s:%s",argv[2], old);
setenv("DYLD_LIBRARY_PATH", buf, 1);
}
/* Exec mono */
execve(args[0], args, environ);
}
/* Else, start the launcher */
return NSApplicationMain(argc, (const char **) argv); return NSApplicationMain(argc, (const char **) argv);
} }