-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorDirectory.m
executable file
·140 lines (84 loc) · 3.77 KB
/
CorDirectory.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// CorDirectory.m
// CorTool
//
// Created by Frigid on 3/8/10.
// Copyright 2010 OmniGreat Software Co.. All rights reserved.
//
#import "CorDirectory.h"
@implementation CorDirectory
- (NSBundle *)findCCApp
{
NSBundle *CCApp = nil;
NSString *CCAppPath = nil;
NSString *Key = [[[NSString alloc] initWithString:@"CorCCAppPath"] autorelease];
NSString *DefaultCCAppPath = [[NSUserDefaults standardUserDefaults] stringForKey:Key];
if (DefaultCCAppPath != nil && [[[[NSFileManager alloc] init] autorelease] fileExistsAtPath: DefaultCCAppPath])
{
CCAppPath = [[[NSString alloc] initWithString:DefaultCCAppPath] autorelease];
}
else
{
CCAppPath = [self findNewCCAppPathAllowDefault: YES];
if (CCAppPath == nil)
[NSApp terminate: NULL];
}
CCApp = [[[NSBundle alloc] initWithPath:CCAppPath] autorelease];
return CCApp;
}
- (NSString *)findNewCCAppPathAllowDefault: (BOOL)AllowDefault
{
NSString *CCAppPath = nil;
NSString *Key = [[[NSString alloc] initWithString:@"CorCCAppPath"] autorelease];
NSArray *DefaultApps = [[[NSArray alloc] initWithObjects: @"/Applications/Cortex Command b23.app", @"/Applications/Cortex Command.app", nil] autorelease];
for (int i = 0; i < [DefaultApps count]; i++)
{
NSString *DefaultPath = [DefaultApps objectAtIndex: i];
if (AllowDefault && [[[[NSFileManager alloc] init] autorelease] fileExistsAtPath: DefaultPath])
CCAppPath = DefaultPath;
}
if (CCAppPath == nil)
{
if (AllowDefault == YES)
{
NSAlert *Alert = [NSAlert alertWithMessageText:@"Select a Cortex Command App"
defaultButton: @"OK"
alternateButton: nil
otherButton: nil
informativeTextWithFormat: @"You need to select the Cortex Command app file that you would like to modify."];
[Alert runModal];
}
while (TRUE)
{
NSOpenPanel *OpenDlg = [NSOpenPanel openPanel];
[OpenDlg setCanChooseFiles:YES];
[OpenDlg setAllowsMultipleSelection:NO];
[OpenDlg setTitle: @"Select a Cortex Command App to Modify"];
if ([OpenDlg runModalForDirectory: @"/Applications" file:NULL types: [NSArray arrayWithObject: @"app"]] == NSOKButton)
CCAppPath = [OpenDlg filename];
else
CCAppPath = nil;
NSLog(@"%@", CCAppPath);
if (CCAppPath == nil || [[[[[NSBundle alloc] initWithPath:CCAppPath] autorelease] bundleIdentifier] isEqualToString: @"com.datarealms.cortexcommand"])
break;
NSAlert *Alert = [[NSAlert alloc] init];
[Alert addButtonWithTitle:@"OK"];
[Alert setMessageText:@"Not a Cortex Command App"];
[Alert setInformativeText:@"You must select a proper Cortex Command application bundle for CorTool to modify."];
[Alert setAlertStyle:NSWarningAlertStyle];
[Alert runModal];
[Alert release];
}
}
if (CCAppPath != nil)
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:CCAppPath forKey:Key];
[defaults synchronize];
}
return CCAppPath;
}
- (void)findNewCCApp
{
}
@end