diff options
| author | Joel de Vahl <joel@stalverk80.se> | 2007-12-19 18:47:47 +0000 |
|---|---|---|
| committer | Joel de Vahl <joel@stalverk80.se> | 2007-12-19 18:47:47 +0000 |
| commit | c93dbcaa535691e737f9ea58fab3ce7b151aae1f (patch) | |
| tree | 0e1bef1d5562a71844f1bf61fed370d06a189783 /src/osxlaunch | |
| parent | 8254bf23366950dd6010ab03053867aefb7a1438 (diff) | |
| download | zcatch-c93dbcaa535691e737f9ea58fab3ce7b151aae1f.tar.gz zcatch-c93dbcaa535691e737f9ea58fab3ce7b151aae1f.zip | |
Initial server launcher for osx.
Diffstat (limited to 'src/osxlaunch')
| -rw-r--r-- | src/osxlaunch/main.m | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/src/osxlaunch/main.m b/src/osxlaunch/main.m new file mode 100644 index 00000000..5f3d6ab6 --- /dev/null +++ b/src/osxlaunch/main.m @@ -0,0 +1,104 @@ +#import <Cocoa/Cocoa.h> +#include <Carbon/Carbon.h> + +@interface ServerView : NSTextView +{ + NSFileHandle *file; +} +- (void)listenTo: (NSFileHandle*)f; +@end + +@implementation ServerView +- (void)listenTo: (NSFileHandle*)f; +{ + file = f; + + [[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 +{ + [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]]; + NSPipe *pipe; + NSFileHandle *file; + pipe = [NSPipe pipe]; + [task setStandardOutput: pipe]; + file = [pipe fileHandleForReading]; + + + 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: file]; + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teewars_srv"]]; + [task launch]; + [NSApp run]; + [task terminate]; + } + else + { + // run client + [task setLaunchPath: [mainBundle pathForAuxiliaryExecutable: @"teewars"]]; + [task launch]; + [task waitUntilExit]; + } + + + + [NSApp release]; + [pool release]; + return(EXIT_SUCCESS); +} |