From b74c2b79318779e69da88e7639b322b9a54d862c Mon Sep 17 00:00:00 2001 From: Joel de Vahl Date: Wed, 8 Oct 2008 16:33:08 +0000 Subject: [PATCH] Initial launcher (again) --- default.bam | 10 +- scripts/make_release.py | 6 +- .../external/glfw/lib/macosx/macosx_init.c | 3 +- src/osxlaunch/main.m | 101 ++++++++++++++++++ 4 files changed, 112 insertions(+), 8 deletions(-) create mode 100644 src/osxlaunch/main.m diff --git a/default.bam b/default.bam index cbe63fed3..7f39ed733 100644 --- a/default.bam +++ b/default.bam @@ -315,6 +315,8 @@ function build(settings) -- build tools (TODO: fix this so we don't get double _d_d stuff) tools_src = Collect("src/tools/*.cpp", "src/tools/*.c") + + osxlaunch_src = Collect("src/osxlaunch/*.m") objs = Compile(settings, tools_src) tools = {} @@ -337,9 +339,9 @@ function build(settings) masterserver_exe = Link(server_settings, "mastersrv", masterserver, engine, zlib) - --if platform == "macosx" then - -- osxlaunch_exe = Link(client_settings, "TeeLaunch", osxlaunch) - --end + if platform == "macosx" then + osxlaunch_exe = Link(client_settings, "osxlaunch", osxlaunch_src) + end -- make targets c = PseudoTarget("client".."_"..settings.config_name, client_exe) @@ -355,7 +357,7 @@ function build(settings) Target(t) if platform == "macosx" then - o = PseudoTarget("TeeLaunch".."_"..settings.config_name, osxlaunch_exe) + o = PseudoTarget("osxlaunch".."_"..settings.config_name, osxlaunch_exe) all = PseudoTarget(settings.config_name, c, s, v, m, t, o) else all = PseudoTarget(settings.config_name, c, s, v, m, t) diff --git a/scripts/make_release.py b/scripts/make_release.py index 4bcff6cb6..e23148849 100644 --- a/scripts/make_release.py +++ b/scripts/make_release.py @@ -37,7 +37,7 @@ if platform == 'win32': if 'osx_' in platform: use_zip = 1 use_gz = 0 - use_bundle = 0 + use_bundle = 1 def copydir(src, dst, excl=[]): for root, dirs, files in os.walk(src, topdown=True): @@ -90,7 +90,7 @@ if use_bundle: shutil.copy("other/icons/Teeworlds.icns", bundle_resource_dir) shutil.copy(name+exe_ext, bundle_bin_dir) shutil.copy(name+"_srv"+exe_ext, bundle_bin_dir) - shutil.copy("TeeLaunch"+exe_ext, bundle_bin_dir) + shutil.copy("osxlaunch"+exe_ext, bundle_bin_dir) file(os.path.join(bundle_content_dir, "Info.plist"), "w").write(""" @@ -99,7 +99,7 @@ if use_bundle: CFBundleDevelopmentRegion English CFBundleExecutable - teeworlds + osxlaunch CFBundleIconFile Teeworlds CFBundleInfoDictionaryVersion diff --git a/src/engine/external/glfw/lib/macosx/macosx_init.c b/src/engine/external/glfw/lib/macosx/macosx_init.c index c123daf09..3ee6dc437 100644 --- a/src/engine/external/glfw/lib/macosx/macosx_init.c +++ b/src/engine/external/glfw/lib/macosx/macosx_init.c @@ -96,11 +96,12 @@ void _glfwChangeToResourcesDirectory( void ) } CFRelease( resourcesURL ); - +/* if( chdir( resourcesPath ) != 0 ) { UNBUNDLED; } + */ } int _glfwPlatformInit( void ) diff --git a/src/osxlaunch/main.m b/src/osxlaunch/main.m new file mode 100644 index 000000000..a2c5dba57 --- /dev/null +++ b/src/osxlaunch/main.m @@ -0,0 +1,101 @@ +#import +#include + +@interface ServerView : NSTextView +{ + NSTask *task; + NSFileHandle *file; +} +- (void)listenTo: (NSTask*)t; +@end + +@implementation ServerView +- (void)listenTo: (NSTask*)t; +{ + NSPipe *pipe; + task = t; + pipe = [NSPipe pipe]; + [task setStandardOutput: pipe]; + file = [pipe fileHandleForReading]; + + [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(outputNotification:) name: NSFileHandleReadCompletionNotification object: file]; + + [file readInBackgroundAndNotify]; +} + +- (void) outputNotification: (NSNotification *) notification +{ + NSData *data = [[[notification userInfo] objectForKey: NSFileHandleNotificationDataItem] retain]; + NSString *string = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]; + + NSRange end = NSMakeRange([[self string] length], 0); + + [self replaceCharactersInRange: end withString: string]; + end.location += [string length]; + [self scrollRangeToVisible: end]; + + [string release]; + [file readInBackgroundAndNotify]; +} + +-(void)windowWillClose:(NSNotification *)notification +{ + [task terminate]; + [NSApp terminate:self]; +} +@end + +int main(int argc, char **argv) +{ + UInt32 mod = GetCurrentKeyModifiers(); + + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSApp = [NSApplication sharedApplication]; + NSBundle* mainBundle = [NSBundle mainBundle]; + NSTask *task; + task = [[NSTask alloc] init]; + [task setCurrentDirectoryPath: [mainBundle resourcePath]]; + + if(mod & optionKey) + { + // run server + NSWindow *window; + ServerView *view; + NSRect graphicsRect; + + graphicsRect = NSMakeRect(100.0, 1000.0, 600.0, 400.0); + + window = [[NSWindow alloc] + initWithContentRect: graphicsRect + styleMask: NSTitledWindowMask + | NSClosableWindowMask + | NSMiniaturizableWindowMask + backing: NSBackingStoreBuffered + defer: NO]; + + [window setTitle: @"Teewars Server"]; + + view = [[[ServerView alloc] initWithFrame: graphicsRect] autorelease]; + [view setEditable: NO]; + + [window setContentView: view]; + [window setDelegate: view]; + [window makeKeyAndOrderFront: nil]; + + [view listenTo: task]; + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teeworlds_srv"]]; + [task launch]; + [NSApp run]; + [task terminate]; + } + else + { + // run client + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teeworlds"]]; + [task launch]; + } + + [NSApp release]; + [pool release]; + return(EXIT_SUCCESS); +}