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

@@ -8,7 +8,47 @@
#import <Cocoa/Cocoa.h>
extern char **environ;
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const 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);
}