Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 138 lines (108 sloc) 3.674 kb
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
1 //
2 // SMAppDelegate.m
3 // SimDeploy
4 //
5 // Created by Jerry Jones on 12/30/11.
ea7818f @jerryhjones Change __MyCompany__
jerryhjones authored
6 // Copyright (c) 2011 Spaceman Labs. All rights reserved.
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
7 //
8
9 #import "SMAppDelegate.h"
7fc3ed7 @jerryhjones Hooked up lots of new UI.
jerryhjones authored
10 #import "PFMoveApplication.h"
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
11
12 @implementation SMAppDelegate
13
14 @synthesize window = _window;
15 @synthesize viewController;
16
17 - (void)dealloc
18 {
fcb28b1 @jerryhjones Start cleaning up weird stray windows when URL launches the app.
jerryhjones authored
19 self.window = nil;
20 self.viewController = nil;
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
21 [super dealloc];
22 }
23
a917905 @jerryhjones Drag and Drop
jerryhjones authored
24 - (void)applicationWillFinishLaunching:(NSNotification *)aNotification
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
25 {
e040f0b @jerryhjones Mixed up #ifdef and #ifndef - now we actually avoid moving to the applic...
jerryhjones authored
26 #ifndef DEBUG
7fc3ed7 @jerryhjones Hooked up lots of new UI.
jerryhjones authored
27 PFMoveToApplicationsFolderIfNecessary();
7d37117 @jerryhjones Only attempt to move to applications folder when not running in debug.
jerryhjones authored
28 #endif
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
29 [[NSAppleEventManager sharedAppleEventManager] setEventHandler:self andSelector:@selector(handleURLEvent:withReplyEvent:) forEventClass:kInternetEventClass andEventID:kAEGetURL];
30 }
31
a917905 @jerryhjones Drag and Drop
jerryhjones authored
32 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
33 {
fa8e066 @jerryhjones Add "Clean Install" box.
jerryhjones authored
34 [SMSimDeployer defaultDeployer];
a917905 @jerryhjones Drag and Drop
jerryhjones authored
35 }
36
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
37 - (void)applicationWillTerminate:(NSNotification *)aNotification
38 {
39 [[SMSimDeployer defaultDeployer] cleanup];
40 }
41
42 - (void)handleURLEvent:(NSAppleEventDescriptor*)event withReplyEvent:(NSAppleEventDescriptor*)replyEvent
43 {
44 NSString *urlString = [[event paramDescriptorForKeyword:keyDirectObject] stringValue];
45 NSURL *url = [NSURL URLWithString:urlString];
46
47 NSMutableDictionary *queryParams = [NSMutableDictionary dictionary];
48 NSArray *components = [[url query] componentsSeparatedByString:@"&"];
49
50 for (NSString *component in components) {
51 NSArray *pair = [component componentsSeparatedByString:@"="];
52
53 [queryParams setObject:[[pair objectAtIndex:1] stringByReplacingPercentEscapesUsingEncoding: NSMacOSRomanStringEncoding]
54 forKey:[pair objectAtIndex:0]];
55 }
56
57 NSString *fetchLocation = [queryParams objectForKey:@"url"];
a3f9270 @jerryhjones Support URL's lacking http://
jerryhjones authored
58
313870f @jerryhjones Stray window stuff all fixed up.
jerryhjones authored
59 if (nil != fetchLocation) {
a3f9270 @jerryhjones Support URL's lacking http://
jerryhjones authored
60 if (NO == [fetchLocation hasPrefix:@"http://"]) {
61 fetchLocation = [NSString stringWithFormat:@"http://%@", fetchLocation];
62 }
63
313870f @jerryhjones Stray window stuff all fixed up.
jerryhjones authored
64 [self.viewController downloadURLAtLocation:fetchLocation];
65 }
66
a917905 @jerryhjones Drag and Drop
jerryhjones authored
67 }
68
69 // Handle a file dropped on the dock icon
70 - (BOOL)application:(NSApplication *)sender openFile:(NSString *)path
71 {
8e48c22 @jerryhjones Support .zip drag and drop
jerryhjones authored
72 if ([path hasSuffix:@".zip"]) {
4c33847 @jerryhjones Fixed a couple leaks.
jerryhjones authored
73 SMAppModel *app = [[SMSimDeployer defaultDeployer] unzipAppArchiveAtPath:path];
8e48c22 @jerryhjones Support .zip drag and drop
jerryhjones authored
74 if (nil != app) {
75 [self.viewController setupAppInfoViewWithApp:app];
76 return YES;
77 }
78 }
79
a917905 @jerryhjones Drag and Drop
jerryhjones authored
80 NSBundle *bundle = [NSBundle bundleWithPath:path];
4c33847 @jerryhjones Fixed a couple leaks.
jerryhjones authored
81 SMAppModel *appModel = [[[SMAppModel alloc] initWithBundle:bundle] autorelease];
a917905 @jerryhjones Drag and Drop
jerryhjones authored
82
83 if (nil == appModel) {
ada52c6 @jerryhjones Improved error checking for invalid file types.
jerryhjones authored
84 [self.viewController errorWithTitle:NSLocalizedString(@"Not a Valid Application", nil)
85 message:NSLocalizedString(@"The provided file did not contain a valid simulator build.", nil)];
86
a917905 @jerryhjones Drag and Drop
jerryhjones authored
87 }
88
4c33847 @jerryhjones Fixed a couple leaks.
jerryhjones authored
89 if (nil != appModel) {
4bab1a4 @jerryhjones Updated UI.
jerryhjones authored
90 [self.viewController setupAppInfoViewWithApp:appModel];
a917905 @jerryhjones Drag and Drop
jerryhjones authored
91 return YES;
92 }
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
93
a917905 @jerryhjones Drag and Drop
jerryhjones authored
94 return YES;
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
95 }
96
c65e78e @jerryhjones Close app when last window is closed.
jerryhjones authored
97 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
98 {
99 return YES;
100 }
101
2bb2ef7 @jerryhjones Add ability to use the "open file" menu.
jerryhjones authored
102 - (IBAction)openDocument:(id)sender
103 {
104 NSOpenPanel *panel = [NSOpenPanel openPanel];
105 panel.delegate = self;
106 [panel setAllowsMultipleSelection:NO];
107
108 [panel beginSheetModalForWindow:[NSApp mainWindow]
109 completionHandler:^(NSInteger result) {
110 if (NSFileHandlingPanelOKButton == result) {
111 NSArray *urls = [panel URLs];
112 NSURL *url = [urls lastObject];
113 NSString *path = [url path];
114 [self application:nil openFile:path];
115 }
116 }];
117 }
118
119 - (BOOL)panel:(id)sender shouldEnableURL:(NSURL *)url
120 {
121
122 NSString *filename = [url lastPathComponent];
123 if ([filename hasSuffix:@".zip"] || [filename hasSuffix:@".app"]) {
124 return YES;
125 }
126
127 // Allow Directories to be opened
128 BOOL directory = NO;
129 [[NSFileManager defaultManager] fileExistsAtPath:[url path] isDirectory:&directory];
130 if (directory) {
131 return YES;
132 }
133
134 return NO;
135 }
136
6549c9c @jerryhjones Simple Deploy
jerryhjones authored
137 @end
Something went wrong with that request. Please try again.