Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 333 lines (282 sloc) 15.547 kB
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
1 //
2 // SUBasicUpdateDriver.m
3 // Sparkle
4 //
5 // Created by Andy Matuschak on 4/23/08.
6 // Copyright 2008 Andy Matuschak. All rights reserved.
7 //
8
9 #import "SUBasicUpdateDriver.h"
10
f815eec @andymatuschak Fixes 243884
andymatuschak authored
11 #import "SUHost.h"
de9be8b @andymatuschak Fixes 244428
andymatuschak authored
12 #import "SUDSAVerifier.h"
f815eec @andymatuschak Fixes 243884
andymatuschak authored
13 #import "SUInstaller.h"
14 #import "SUStandardVersionComparator.h"
15 #import "SUUnarchiver.h"
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
16
17 @implementation SUBasicUpdateDriver
18
478e0a5 @andymatuschak Fixed a potential security vulnerability in which the download is tra…
andymatuschak authored
19 - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)aHost
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
20 {
478e0a5 @andymatuschak Fixed a potential security vulnerability in which the download is tra…
andymatuschak authored
21 [super checkForUpdatesAtURL:URL host:aHost];
3146ffb @andymatuschak Fixes 248929, 244738
andymatuschak authored
22 if ([aHost isRunningOnReadOnlyVolume])
8b3d15b @andymatuschak Moved the check for whether the host is running from a disk image to …
andymatuschak authored
23 {
3146ffb @andymatuschak Fixes 248929, 244738
andymatuschak authored
24 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] forKey:NSLocalizedDescriptionKey]]];
8b3d15b @andymatuschak Moved the check for whether the host is running from a disk image to …
andymatuschak authored
25 return;
26 }
27
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
28 SUAppcast *appcast = [[SUAppcast alloc] init];
29 CFRetain(appcast); // We'll manage the appcast's memory ourselves so we don't have to make it an IV to support GC.
30 [appcast release];
31
32 [appcast setDelegate:self];
7ce078e @andymatuschak Fixes 356328
andymatuschak authored
33 NSString *userAgent = [NSString stringWithFormat: @"%@/%@ Sparkle/%@", [aHost name], [aHost displayVersion], ([SPARKLE_BUNDLE objectForInfoDictionaryKey:@"CFBundleVersion"] ?: nil)];
34 NSData * cleanedAgent = [userAgent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
d1c5460 @j3r3miah [cleanedAgent bytes] is not null-terminated so stringWithCString prod…
j3r3miah authored
35 userAgent = [[[NSString alloc] initWithData:cleanedAgent encoding:NSASCIIStringEncoding] autorelease];
7ce078e @andymatuschak Fixes 356328
andymatuschak authored
36 [appcast setUserAgentString:userAgent];
478e0a5 @andymatuschak Fixed a potential security vulnerability in which the download is tra…
andymatuschak authored
37 [appcast fetchAppcastFromURL:URL];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
38 }
39
aaa60d2 @andymatuschak Fixed 244761
andymatuschak authored
40 - (id <SUVersionComparison>)_versionComparator
41 {
42 id <SUVersionComparison> comparator = nil;
43
44 // Give the delegate a chance to provide a custom version comparator
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
45 if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)])
46 comparator = [[updater delegate] versionComparatorForUpdater:updater];
aaa60d2 @andymatuschak Fixed 244761
andymatuschak authored
47
48 // If we don't get a comparator from the delegate, use the default comparator
49 if (!comparator)
50 comparator = [SUStandardVersionComparator defaultComparator];
51
52 return comparator;
53 }
54
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
55 - (BOOL)isItemNewer:(SUAppcastItem *)ui
56 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
57 return [[self _versionComparator] compareVersion:[host version] toVersion:[ui versionString]] == NSOrderedAscending;
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
58 }
59
60 - (BOOL)hostSupportsItem:(SUAppcastItem *)ui
61 {
62 if ([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) { return YES; }
de9be8b @andymatuschak Fixes 244428
andymatuschak authored
63 return [[SUStandardVersionComparator defaultComparator] compareVersion:[ui minimumSystemVersion] toVersion:[SUHost systemVersionString]] != NSOrderedDescending;
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
64 }
65
66 - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui
67 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
68 NSString *skippedVersion = [host objectForUserDefaultsKey:SUSkippedVersionKey];
1264a6b @andymatuschak Sparkle now finds the newest update in an appcast for which the host …
andymatuschak authored
69 if (skippedVersion == nil) { return NO; }
aaa60d2 @andymatuschak Fixed 244761
andymatuschak authored
70 return [[self _versionComparator] compareVersion:[ui versionString] toVersion:skippedVersion] != NSOrderedDescending;
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
71 }
72
73 - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
74 {
75 return [self hostSupportsItem:ui] && [self isItemNewer:ui] && ![self itemContainsSkippedVersion:ui];
76 }
77
78 - (void)appcastDidFinishLoading:(SUAppcast *)ac
79 {
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
80 if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)])
81 [[updater delegate] updater:updater didFinishLoadingAppcast:ac];
d201803 @andymatuschak More fixes for 258060
andymatuschak authored
82
83 SUAppcastItem *item = nil;
84
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
85 // Now we have to find the best valid update in the appcast.
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
86 if ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it?
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
87 {
d201803 @andymatuschak More fixes for 258060
andymatuschak authored
88 item = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:updater];
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
89 }
90 else // If not, we'll take care of it ourselves.
91 {
92 // Find the first update we can actually use.
251706d @andymatuschak Fixed a serious bug which could cause a server to DDoS'd in the case …
andymatuschak authored
93 NSEnumerator *updateEnumerator = [[ac items] objectEnumerator];
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
94 do {
d201803 @andymatuschak More fixes for 258060
andymatuschak authored
95 item = [updateEnumerator nextObject];
96 } while (item && ![self hostSupportsItem:item]);
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
97 }
d201803 @andymatuschak More fixes for 258060
andymatuschak authored
98
99 updateItem = [item retain];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
100 CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
101 if (updateItem == nil) { [self didNotFindUpdate]; return; }
102
103 if ([self itemContainsValidUpdate:updateItem])
104 [self didFindValidUpdate];
105 else
106 [self didNotFindUpdate];
107 }
108
109 - (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
110 {
111 CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
112 [self abortUpdateWithError:error];
113 }
114
115 - (void)didFindValidUpdate
116 {
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
117 if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
118 [[updater delegate] updater:updater didFindValidUpdate:updateItem];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
119 [self downloadUpdate];
120 }
121
122 - (void)didNotFindUpdate
123 {
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
124 if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
125 [[updater delegate] updaterDidNotFindUpdate:updater];
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
126 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
127 }
128
129 - (void)downloadUpdate
130 {
131 download = [[NSURLDownload alloc] initWithRequest:[NSURLRequest requestWithURL:[updateItem fileURL]] delegate:self];
132 }
133
134 - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name
135 {
136 // If name ends in .txt, the server probably has a stupid MIME configuration. We'll give the developer the benefit of the doubt and chop that off.
137 if ([[name pathExtension] isEqualToString:@"txt"])
138 name = [name stringByDeletingPathExtension];
139
140 // We create a temporary directory in /tmp and stick the file there.
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
141 // Not using a GUID here because hdiutil (for DMGs) for some reason chokes on GUIDs. Too long? I really have no idea.
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
142 NSString *prefix = [NSString stringWithFormat:@"%@ %@ Update", [host name], [host version]];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
143 NSString *tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:prefix];
144 int cnt=1;
7071142 @andymatuschak Improving Sparkle's robustness against apps without a CFBundleVersion.
andymatuschak authored
145 while ([[NSFileManager defaultManager] fileExistsAtPath:tempDir] && cnt <= 999)
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
146 {
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
147 tempDir = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ %d", prefix, cnt++]];
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
148 }
149
150 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
151 BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir attributes:nil];
54299d7 added #ifdef's for Tiger support
August Joki authored
152 #else
f2a7b4b Fixed deprecated APIs to use replacements.
August Joki authored
153 BOOL success = [[NSFileManager defaultManager] createDirectoryAtPath:tempDir withIntermediateDirectories:YES attributes:nil error:NULL];
54299d7 added #ifdef's for Tiger support
August Joki authored
154 #endif
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
155 if (!success)
156 {
157 // Okay, something's really broken with /tmp
158 [download cancel];
159 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.",tempDir] forKey:NSLocalizedDescriptionKey]]];
160 }
161
162 downloadPath = [[tempDir stringByAppendingPathComponent:name] retain];
163 [download setDestination:downloadPath allowOverwrite:YES];
164 }
165
166 - (void)downloadDidFinish:(NSURLDownload *)d
167 {
7e9fc0f @andymatuschak Changed the security policy once more:
andymatuschak authored
168 // New in Sparkle 1.5: we're now checking signatures on all non-secure downloads, where "secure" is defined as both the appcast and the download being transmitted over SSL.
478e0a5 @andymatuschak Fixed a potential security vulnerability in which the download is tra…
andymatuschak authored
169 NSURL *downloadURL = [[d request] URL];
799b002 @andymatuschak Fixing Bug #338324: "Unsigned updates delivered over https fail"
andymatuschak authored
170 if (!(([[downloadURL scheme] isEqualToString:@"https"] && [[appcastURL scheme] isEqualToString:@"https"]) ||
171 ([downloadURL isFileURL] && [appcastURL isFileURL])))
1d3ab8d @andymatuschak Alright, guys. No more Mr. Nice Sparklepants. Sparkle now requires ei…
andymatuschak authored
172 {
799b002 @andymatuschak Fixing Bug #338324: "Unsigned updates delivered over https fail"
andymatuschak authored
173 if (![host publicDSAKey] || ![SUDSAVerifier validatePath:downloadPath withEncodedDSASignature:[updateItem DSASignature] withPublicDSAKey:[host publicDSAKey]])
1d3ab8d @andymatuschak Alright, guys. No more Mr. Nice Sparklepants. Sparkle now requires ei…
andymatuschak authored
174 {
1509564 @andymatuschak Fixing Bug #400536: @"The update is improperly signed." does not loca…
andymatuschak authored
175 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUSignatureError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, @"The update is improperly signed.", NSLocalizedFailureReasonErrorKey, nil]]];
1d3ab8d @andymatuschak Alright, guys. No more Mr. Nice Sparklepants. Sparkle now requires ei…
andymatuschak authored
176 return;
177 }
178 }
179
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
180 [self extractUpdate];
181 }
182
183 - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error
184 {
49f717c @andymatuschak Fixes #230173 by removing partially downloaded files on download error.
andymatuschak authored
185 // Get rid of what we've downloaded so far, if anything.
186 if (downloadPath != nil)
187 [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[downloadPath stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[downloadPath lastPathComponent]] tag:NULL];
8dfd93e @andymatuschak Made the error displayed on download failure human-friendly.
andymatuschak authored
188 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
189 }
190
c9bd132 @andymatuschak Fixes 246469
andymatuschak authored
191 - (BOOL)download:(NSURLDownload *)download shouldDecodeSourceDataOfMIMEType:(NSString *)encodingType
192 {
0af86bb @andymatuschak Hopefully actually fixing 246469: it seems that while Cocoa documents…
andymatuschak authored
193 // We don't want the download system to extract our gzips.
194 // Note that we use a substring matching here instead of direct comparison because the docs say "application/gzip" but the system *uses* "application/x-gzip". This is a documentation bug.
898216a @andymatuschak Final fix for 246469 (I hope). Fixed a mind-bogglingly stupid typo wh…
andymatuschak authored
195 return ([encodingType rangeOfString:@"gzip"].location == NSNotFound);
c9bd132 @andymatuschak Fixes 246469
andymatuschak authored
196 }
197
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
198 - (void)extractUpdate
1d3ab8d @andymatuschak Alright, guys. No more Mr. Nice Sparklepants. Sparkle now requires ei…
andymatuschak authored
199 {
58a05e2 @andymatuschak Fixes 243533 (for real this time, I hope)
andymatuschak authored
200 SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:downloadPath];
441a538 @andymatuschak Oops! Fixed a warning that caused Sparkle not to compile. Made the un…
andymatuschak authored
201 if (!unarchiver)
202 {
203 NSLog(@"Sparkle Error: No valid unarchiver for %@!", downloadPath);
204 [self unarchiverDidFail:nil];
764bed3 @andymatuschak Okay, *really* fixing the bug this time. Thanks for watching my back,…
andymatuschak authored
205 return;
441a538 @andymatuschak Oops! Fixed a warning that caused Sparkle not to compile. Made the un…
andymatuschak authored
206 }
3daa88d @andymatuschak --fixes lp:242525 --fixes lp:242561 --fixes lp:242564
andymatuschak authored
207 CFRetain(unarchiver); // Manage this memory manually so we don't have to make it an IV.
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
208 [unarchiver setDelegate:self];
93ea93d @andymatuschak Fixes 236695
andymatuschak authored
209 [unarchiver start];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
210 }
211
212 - (void)unarchiverDidFinish:(SUUnarchiver *)ua
213 {
441a538 @andymatuschak Oops! Fixed a warning that caused Sparkle not to compile. Made the un…
andymatuschak authored
214 if (ua) { CFRelease(ua); }
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
215 [self installUpdate];
216 }
217
218 - (void)unarchiverDidFail:(SUUnarchiver *)ua
219 {
441a538 @andymatuschak Oops! Fixed a warning that caused Sparkle not to compile. Made the un…
andymatuschak authored
220 if (ua) { CFRelease(ua); }
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
221 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:[NSDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey]]];
222 }
223
6d8f5be @andymatuschak Merging in David Smith's branch to fix bug #230123. We now copy the r…
andymatuschak authored
224 - (BOOL)shouldInstallSynchronously { return NO; }
225
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
226 - (void)installUpdate
227 {
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
228 if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)])
229 [[updater delegate] updater:updater willInstallUpdate:updateItem];
6d8f5be @andymatuschak Merging in David Smith's branch to fix bug #230123. We now copy the r…
andymatuschak authored
230 // Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
231 NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
232 NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
233 // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems.
234 NSError *error = nil;
235 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
54299d7 added #ifdef's for Tiger support
August Joki authored
236 [[NSFileManager defaultManager] removeFileAtPath:targetPath handler:nil];
237 if ([[NSFileManager defaultManager] copyPath:relaunchPathToCopy toPath:targetPath handler:nil])
238 #else
f2a7b4b Fixed deprecated APIs to use replacements.
August Joki authored
239 [[NSFileManager defaultManager] removeItemAtPath:targetPath error:NULL];
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
240 if ([[NSFileManager defaultManager] copyItemAtPath:relaunchPathToCopy toPath:targetPath error:&error])
54299d7 added #ifdef's for Tiger support
August Joki authored
241 #endif
6d8f5be @andymatuschak Merging in David Smith's branch to fix bug #230123. We now copy the r…
andymatuschak authored
242 relaunchPath = [targetPath retain];
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
243 else
244 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil), NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't copy relauncher (%@) to temporary path (%@)! %@", relaunchPathToCopy, targetPath, (error ? [error localizedDescription] : @"")], NSLocalizedFailureReasonErrorKey, nil]]];
6d8f5be @andymatuschak Merging in David Smith's branch to fix bug #230123. We now copy the r…
andymatuschak authored
245
9a0acca @andymatuschak More security tidbits!
andymatuschak authored
246 [SUInstaller installFromUpdateFolder:[downloadPath stringByDeletingLastPathComponent] overHost:host delegate:self synchronously:[self shouldInstallSynchronously] versionComparator:[self _versionComparator]];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
247 }
248
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
249 - (void)installerFinishedForHost:(SUHost *)aHost
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
250 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
251 if (aHost != host) { return; }
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
252 [self relaunchHostApp];
253 }
254
255 - (void)relaunchHostApp
256 {
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
257 // Give the host app an opportunity to postpone the relaunch.
258 static BOOL postponedOnce = NO;
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
259 if (!postponedOnce && [[updater delegate] respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)])
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
260 {
261 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]];
262 [invocation setSelector:@selector(relaunchHostApp)];
263 [invocation setTarget:self];
264 postponedOnce = YES;
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
265 if ([[updater delegate] updater:updater shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation])
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
266 return;
267 }
46f9b4a @andymatuschak Fixes 242566
andymatuschak authored
268
269 [self cleanUp]; // Clean up the download and extracted files.
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
270
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
271 [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
84be00b @andymatuschak Fixes 258991
andymatuschak authored
272 if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication:)])
b3f3944 @andymatuschak Fixes 244857
andymatuschak authored
273 [[updater delegate] updaterWillRelaunchApplication:updater];
5c32832 @andymatuschak Fixes bug 228446
andymatuschak authored
274
1c7fb59 @andymatuschak Killed one of the two remaining @try/@catch blocks in my code. I'll g…
andymatuschak authored
275 if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
276 {
277 // Note that we explicitly use the host app's name here, since updating plugin for Mail relaunches Mail, not just the plugin.
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
278 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURelaunchError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:[NSString stringWithFormat:SULocalizedString(@"An error occurred while relaunching %1$@, but the new version will be available next time you run %1$@.", nil), [host name]], NSLocalizedDescriptionKey, [NSString stringWithFormat:@"Couldn't find the relauncher (expected to find it at %@)", relaunchPath], NSLocalizedFailureReasonErrorKey, nil]]];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
279 // We intentionally don't abandon the update here so that the host won't initiate another.
1c7fb59 @andymatuschak Killed one of the two remaining @try/@catch blocks in my code. I'll g…
andymatuschak authored
280 return;
281 }
282
e249e3c @andymatuschak Fixes 253187
andymatuschak authored
283 NSString *pathToRelaunch = [host bundlePath];
284 if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)])
285 pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater];
286 [NSTask launchedTaskWithLaunchPath:relaunchPath arguments:[NSArray arrayWithObjects:pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], nil]];
1c7fb59 @andymatuschak Killed one of the two remaining @try/@catch blocks in my code. I'll g…
andymatuschak authored
287
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
288 [NSApp terminate:self];
289 }
290
46f9b4a @andymatuschak Fixes 242566
andymatuschak authored
291 - (void)cleanUp
292 {
7316a00 @andymatuschak Removed SL-deprecated NSFileManager methods. Left the old ones around…
andymatuschak authored
293 #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
54299d7 added #ifdef's for Tiger support
August Joki authored
294 [[NSFileManager defaultManager] removeFileAtPath:[downloadPath stringByDeletingLastPathComponent] handler:nil];
295 #else
296 [[NSFileManager defaultManager] removeItemAtPath:[downloadPath stringByDeletingLastPathComponent] error:NULL];
297 #endif
46f9b4a @andymatuschak Fixes 242566
andymatuschak authored
298 }
299
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
300 - (void)installerForHost:(SUHost *)aHost failedWithError:(NSError *)error
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
301 {
98832c4 @andymatuschak Beginnings of insane SUHost-based refactoring to get rid of NSBundle+…
andymatuschak authored
302 if (aHost != host) { return; }
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
303 [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:[NSDictionary dictionaryWithObjectsAndKeys:SULocalizedString(@"An error occurred while installing the update. Please try again later.", nil), NSLocalizedDescriptionKey, [error localizedDescription], NSLocalizedFailureReasonErrorKey, nil]]];
304 }
305
306 - (void)abortUpdate
307 {
308 [[NSNotificationCenter defaultCenter] removeObserver:self];
309 [super abortUpdate];
310 }
311
312 - (void)abortUpdateWithError:(NSError *)error
313 {
314 if ([error code] != SUNoUpdateError) // Let's not bother logging this.
315 NSLog(@"Sparkle Error: %@", [error localizedDescription]);
316 if ([error localizedFailureReason])
317 NSLog(@"Sparkle Error (continued): %@", [error localizedFailureReason]);
0a4bc65 @andymatuschak No longer leaking the NSURLDownload of the update archive.
andymatuschak authored
318 if (download)
319 [download cancel];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
320 [self abortUpdate];
321 }
322
323 - (void)dealloc
324 {
46312a2 @andymatuschak Fixes 258060
andymatuschak authored
325 [updateItem release];
0a4bc65 @andymatuschak No longer leaking the NSURLDownload of the update archive.
andymatuschak authored
326 [download release];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
327 [downloadPath release];
6d8f5be @andymatuschak Merging in David Smith's branch to fix bug #230123. We now copy the r…
andymatuschak authored
328 [relaunchPath release];
bc3be9a Touched practically every line of code in a super-monster-awesome ref…
andym authored
329 [super dealloc];
330 }
331
332 @end
Something went wrong with that request. Please try again.