This repository has been archived by the owner on Jul 15, 2022. It is now read-only.
/
MainWindow.m
121 lines (107 loc) · 3.51 KB
/
MainWindow.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//
// MainWindow.m
// Chaos Starter
//
// Created by Peter Kendall on 1/6/08.
// Copyright 2008 @PAK software. All rights reserved.
//
#import "MainWindow.h"
@implementation MainWindow
-(MainWindow*)init
{
if(self=[super init])
{
//get notification if one of the text boxes contents changes and set it to textChange:
[[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(textChange:) name: @"NSControlTextDidChangeNotification" object: UTpath];
}
return self;
}
-(IBAction)browse: (id)sender
{
NSString *path=[NSString stringWithString: @"-1"];
//setup and display the open dialog box
NSArray *fileTypes=[NSArray arrayWithObject: @"app"];
NSOpenPanel *oPanel=[NSOpenPanel openPanel];
int result=[oPanel runModalForDirectory: nil file: nil types: fileTypes];
if(result==NSOKButton)
{
NSArray *file=[oPanel filenames];
path=[file objectAtIndex: 0];
//set the UT2k4 location text box to the path
[UTpath setStringValue: path];
//send a notification that the text changed b/c the text box doesn't do it
[[NSNotificationCenter defaultCenter] postNotificationName: @"NSControlTextDidChangeNotification" object: UTpath];
}
}
-(IBAction)start: (id)sender
{
[self runUT2k4];
}
-(void)textChange: (NSNotification*)notification
{
if([[UTpath stringValue] length]!=0)
{
[startButton setEnabled: YES];
}
else
{
[startButton setEnabled: NO];
}
}
-(void)applicationDidFinishLaunching: (NSNotification*)notification
{
//read in from the preferences
NSFileManager *prefs=[NSFileManager defaultManager];
//add in some code that checks if the .plist file exists first before any of these bottom 2
if([prefs fileExistsAtPath: [NSHomeDirectory() stringByAppendingString: @"/Library/Preferences/com.atPAK.Chaos Starter.plist"]]==YES) //The new prefs exist
{
NSDictionary *root=[NSDictionary dictionaryWithContentsOfFile: [NSHomeDirectory() stringByAppendingString: @"/Library/Preferences/com.atPAK.Chaos Starter.plist"]];
NSString *path=[root valueForKey: @"UTpath"];
if(path!=nil)
{
[UTpath setStringValue: path];
[[NSNotificationCenter defaultCenter] postNotificationName: @"NSControlTextDidChangeNotification" object: UTpath];
}
//are we to not show anything and automaticly open UT2k4?
NSNumber *checked=[root valueForKey: @"noShow"];
if(checked!=nil)
{
if([checked intValue]==NSOnState)
{
[noShow setState: NSOnState];
//don't show, but do we want to force it to show?
CGEventRef event=CGEventCreate(NULL);
CGEventFlags mods=CGEventGetFlags(event);
if(!(mods & kCGEventFlagMaskCommand))
{
//we don't want to show
[self runUT2k4];
}
CFRelease(event);
}
}
}
}
-(void)applicationWillTerminate: (NSNotification*)notification
{
NSMutableDictionary *root=[NSMutableDictionary dictionary];
[root setValue: [UTpath stringValue] forKey: @"UTpath"];
[root setValue: [NSNumber numberWithInt: [noShow state]] forKey: @"noShow"];
[root writeToFile: [NSHomeDirectory() stringByAppendingString: @"/Library/Preferences/com.atPAK.Chaos Starter.plist"] atomically: YES];
}
-(void)runUT2k4
{
NSTask* task=[[NSTask alloc] init];
[task setLaunchPath: [[UTpath stringValue] stringByAppendingString: @"/Contents/MacOS/Unreal Tournament 2004"]];
[task setArguments: [NSArray arrayWithObjects: @"-mod=ChaosUT2", @"-userlogo=../ChaosUT2/Help/ChaosUT2Logo.bmp", @"&", nil]];
[task launch];
[task autorelease];
//kill the application
[NSApp terminate: self];
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver: self];
[super dealloc];
}
@end