diff --git a/OpenRA.Launcher.Mac/Controller.h b/OpenRA.Launcher.Mac/Controller.h index e91b38eb2a..577a21d017 100644 --- a/OpenRA.Launcher.Mac/Controller.h +++ b/OpenRA.Launcher.Mac/Controller.h @@ -22,4 +22,5 @@ - (BOOL)initMono; - (void)runUtilityWithArgs:(NSArray *)arg; - (void)utilityResponded:(NSNotification *)n; +- (BOOL)shouldHideMenubar; @end diff --git a/OpenRA.Launcher.Mac/Controller.m b/OpenRA.Launcher.Mac/Controller.m index babe4260ac..62da368070 100644 --- a/OpenRA.Launcher.Mac/Controller.m +++ b/OpenRA.Launcher.Mac/Controller.m @@ -5,7 +5,6 @@ * as published by the Free Software Foundation. For more information, * see LICENSE. */ -#import "main.h" #import "Controller.h" @implementation Controller @@ -17,16 +16,12 @@ forKey:@"gamepath"]]; } +extern char **environ; - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - gamePath = [[NSUserDefaults standardUserDefaults] stringForKey:@"gamepath"]; NSArray *args = [[NSProcessInfo processInfo] arguments]; + gamePath = [[NSUserDefaults standardUserDefaults] stringForKey:@"gamepath"]; - // Ingame requests for native dialogs - if ([args containsObject:@"--display-filepicker"]) - [self launchFilePicker:args]; - - // Try and launch the game if (![self initMono]) { @@ -42,16 +37,21 @@ [[NSApplication sharedApplication] terminate:self]; } + // Ingame requests for native dialogs + if ([args containsObject:@"--display-filepicker"]) + [self launchFilePicker:args]; + // Extract a zip file - if ([args containsObject:@"--extract-zip"]) + else if ([args containsObject:@"--extract-zip"]) [self extractZip:args]; // Install ra packages from cd - if ([args containsObject:@"--install-ra-packages"]) + else if ([args containsObject:@"--install-ra-packages"]) [self installRAPackages:args]; + else + [self launchMod:@"cnc"]; - [self launchMod:@"cnc"]; [NSApp terminate: nil]; } @@ -72,8 +72,10 @@ - (void)launchFilePicker:(NSArray *)args { [NSApp activateIgnoringOtherApps:YES]; - hide_menubar_if_necessary(); - + + if ([self shouldHideMenubar]) + [NSMenu setMenuBarVisible:NO]; + NSOpenPanel *op = [NSOpenPanel openPanel]; [op setLevel:CGShieldingWindowLevel()]; [op setAllowsMultipleSelection:NO]; @@ -88,6 +90,28 @@ [NSApp terminate: nil]; } +- (BOOL)shouldHideMenubar +{ + NSTask *task = [[[NSTask alloc] init] autorelease]; + NSPipe *pipe = [NSPipe pipe]; + + NSMutableArray *taskArgs = [NSMutableArray arrayWithObjects:@"OpenRA.Utility.exe", + @"--settings-value", + [@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath], + @"Graphics.Mode", nil]; + + [task setCurrentDirectoryPath:gamePath]; + [task setLaunchPath:monoPath]; + [task setArguments:taskArgs]; + [task setStandardOutput:pipe]; + NSFileHandle *readHandle = [pipe fileHandleForReading]; + [task launch]; + [task waitUntilExit]; + NSString *response = [[[NSString alloc] initWithData:[readHandle readDataToEndOfFile] + encoding: NSUTF8StringEncoding] autorelease]; + return ![response isEqualToString:@"Windowed\n"]; +} + -(void)launchMod:(NSString *)mod { // Use LaunchServices because neither NSTask or NSWorkspace support Info.plist _and_ arguments pre-10.6 @@ -95,12 +119,14 @@ // First argument is the directory to run in // Second...Nth arguments are passed to OpenRA.Game.exe // Launcher wrapper sets mono --debug, gl renderer and support dir. - NSArray *args = [NSArray arrayWithObjects:@"--launch", gamePath, monoPath, + NSArray *args = [NSArray arrayWithObjects:@"--launch", + [self shouldHideMenubar] ? @"--hide-menubar" : @"--no-hide-menubar", + gamePath, + monoPath, [NSString stringWithFormat:@"UtilityPath=%@", [[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], [NSString stringWithFormat:@"SupportDir=%@",[@"~/Library/Application Support/OpenRA" stringByExpandingTildeInPath]], [NSString stringWithFormat:@"Game.Mods=%@",mod], nil]; - FSRef appRef; CFURLGetFSRef((CFURLRef)[NSURL URLWithString:[[[NSBundle mainBundle] executablePath] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]], &appRef); diff --git a/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj b/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj index aa4ddbecbd..878f66cc8a 100644 --- a/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj +++ b/OpenRA.Launcher.Mac/OpenRA.xcodeproj/project.pbxproj @@ -27,7 +27,6 @@ 29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = ""; }; 8D1107310486CEB800E47090 /* OpenRA-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OpenRA-Info.plist"; sourceTree = ""; }; 8D1107320486CEB800E47090 /* OpenRA.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = OpenRA.app; sourceTree = BUILT_PRODUCTS_DIR; }; - DA134CC412E6F131009AA0EF /* main.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = main.h; sourceTree = ""; }; DA81FA801290F5C800C48F2F /* Controller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = ""; }; DA81FA811290F5C800C48F2F /* Controller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = ""; }; DA81FBDB12910E4900C48F2F /* OpenRA.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = OpenRA.icns; sourceTree = ""; }; @@ -100,7 +99,6 @@ children = ( 256AC3F00F4B6AF500CF3369 /* OpenRA_Prefix.pch */, 29B97316FDCFA39411CA2CEA /* main.m */, - DA134CC412E6F131009AA0EF /* main.h */, ); name = "Other Sources"; sourceTree = ""; diff --git a/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA b/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA index ce9e955b59..4670cb2627 100755 Binary files a/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA and b/OpenRA.Launcher.Mac/build/Release/OpenRA.app/Contents/MacOS/OpenRA differ diff --git a/OpenRA.Launcher.Mac/main.h b/OpenRA.Launcher.Mac/main.h deleted file mode 100644 index e278eacfd0..0000000000 --- a/OpenRA.Launcher.Mac/main.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * main.h - * OpenRA - * - * Created by Paul Chote on 19/01/11. - * Copyright 2011 OpenRA. All rights reserved. - * - */ - -void hide_menubar_if_necessary(); \ No newline at end of file diff --git a/OpenRA.Launcher.Mac/main.m b/OpenRA.Launcher.Mac/main.m index a9515743a4..8987557928 100644 --- a/OpenRA.Launcher.Mac/main.m +++ b/OpenRA.Launcher.Mac/main.m @@ -7,48 +7,48 @@ // #import -#import "main.h" extern char **environ; int main(int argc, char *argv[]) { /* When launching a mod, the arguments are of the form * --launch */ - if (argc >= 6 && strcmp(argv[1], "--launch") == 0) + if (argc >= 8 && strcmp(argv[1], "--launch") == 0) { /* Change into the game dir */ - chdir(argv[2]); + chdir(argv[3]); /* Command line args for mono */ char *args[] = { - argv[3], + argv[4], "--debug", "OpenRA.Game.exe", - argv[4], argv[5], argv[6], + argv[7], NULL }; /* add game dir to DYLD_LIBRARY_PATH */ char *old = getenv("DYLD_LIBRARY_PATH"); if (old == NULL) - setenv("DYLD_LIBRARY_PATH", argv[2], 1); + setenv("DYLD_LIBRARY_PATH", argv[3], 1); else { char buf[512]; - int len = strlen(argv[2]) + strlen(old) + 2; + int len = strlen(argv[3]) + 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); + sprintf(buf,"%s:%s",argv[3], old); setenv("DYLD_LIBRARY_PATH", buf, 1); } - - hide_menubar_if_necessary(); + if (strcmp(argv[2], "--hide-menubar") == 0) + [NSMenu setMenuBarVisible:NO]; + /* Exec mono */ execve(args[0], args, environ); } @@ -56,11 +56,3 @@ int main(int argc, char *argv[]) /* Else, start the launcher */ return NSApplicationMain(argc, (const char **) argv); } - -// Hide the menubar and dock if we are running fullscreen -void hide_menubar_if_necessary() -{ - // TODO: HACK: Parse the settings.yaml / commandline args for fullscreen options - if (YES) - [NSMenu setMenuBarVisible:NO]; -}