diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index a8df1a4d..9ae7eb1e 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -78,7 +78,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 self.willUpdateOnTermination = YES; - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationInvocation:)]) { BOOL relaunch = YES; @@ -88,8 +89,8 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [invocation setArgument:&relaunch atIndex:2]; [invocation setArgument:&showUI atIndex:3]; [invocation setTarget:self]; - - [updaterDelegate updater:(id)self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; + + [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationInvocation:invocation]; } // If this is marked as a critical update, we'll prompt the user to install it right away. @@ -118,9 +119,10 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 self.willUpdateOnTermination = NO; - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didCancelInstallUpdateOnQuit:)]) - [updaterDelegate updater:(id)self.updater didCancelInstallUpdateOnQuit:self.updateItem]; + [updaterDelegate updater:self.updater didCancelInstallUpdateOnQuit:self.updateItem]; } } @@ -215,9 +217,10 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } else { // Call delegate separately here because otherwise it won't know we stopped. // Normally this gets called by the superclass - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:(id)self.updater didAbortWithError:error]; + [updaterDelegate updater:self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index b4f65b22..2640f2eb 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -62,8 +62,9 @@ SUAppcast *appcast = [[SUAppcast alloc] init]; - [appcast setUserAgentString:[self.updater userAgentString]]; - [appcast setHttpHeaders:[self.updater httpHeaders]]; + id updater = self.updater; + [appcast setUserAgentString:[updater userAgentString]]; + [appcast setHttpHeaders:[updater httpHeaders]]; [appcast fetchAppcastFromURL:URL completionBlock:^(NSError *error) { if (error) { [self abortUpdateWithError:error]; @@ -76,10 +77,11 @@ - (id)versionComparator { id comparator = nil; - + id updater = self.updater; + // Give the delegate a chance to provide a custom version comparator - if ([[self.updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) { - comparator = [[self.updater delegate] versionComparatorForUpdater:(id)self.updater]; + if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)]) { + comparator = [[updater delegate] versionComparatorForUpdater:self.updater]; } // If we don't get a comparator from the delegate, use the default comparator @@ -149,8 +151,9 @@ - (void)appcastDidFinishLoading:(SUAppcast *)ac { - if ([[self.updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) { - [[self.updater delegate] updater:(id)self.updater didFinishLoadingAppcast:ac]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) { + [[updater delegate] updater:self.updater didFinishLoadingAppcast:ac]; } NSDictionary *userInfo = (ac != nil) ? @{ SUUpdaterAppcastNotificationKey: ac } : nil; @@ -159,15 +162,15 @@ SUAppcastItem *item = nil; // Now we have to find the best valid update in the appcast. - if ([[self.updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? + if ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it? { - item = [[self.updater delegate] bestValidUpdateInAppcast:ac forUpdater:(id)self.updater]; + item = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:self.updater]; } if (item != nil) // Does the delegate want to handle it? { if ([item isDeltaUpdate]) { - self.nonDeltaUpdateItem = [[self.updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:(id)self.updater]; + self.nonDeltaUpdateItem = [[updater delegate] bestValidUpdateInAppcast:[ac copyWithoutDeltaUpdates] forUpdater:self.updater]; } } else // If not, we'll take care of it ourselves. @@ -194,9 +197,11 @@ - (void)didFindValidUpdate { assert(self.updateItem); + + id updater = self.updater; - if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { - [[self.updater delegate] updater:(id)self.updater didFindValidUpdate:self.updateItem]; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { + [[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -207,8 +212,10 @@ - (void)didNotFindUpdate { - if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [[self.updater delegate] updaterDidNotFindUpdate:(id)self.updater]; + id updater = self.updater; + + if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { + [[updater delegate] updaterDidNotFindUpdate:self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; @@ -250,10 +257,12 @@ [[NSFileManager defaultManager] removeItemAtPath:appCachePath error:NULL]; } + id updater = self.updater; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]]; - [request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"]; - if ([[self.updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { - [[self.updater delegate] updater:(id)self.updater + [request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"]; + if ([[updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) { + [[updater delegate] updater:self.updater willDownloadUpdate:self.updateItem withRequest:request]; } @@ -299,9 +308,11 @@ if (!failingUrl) { failingUrl = [self.updateItem fileURL]; } + + id updater = self.updater; - if ([[self.updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) { - [[self.updater delegate] updater:(id)self.updater + if ([[updater delegate] respondsToSelector:@selector(updater:failedToDownloadUpdate:error:)]) { + [[updater delegate] updater:self.updater failedToDownloadUpdate:self.updateItem error:error]; } @@ -326,7 +337,8 @@ - (void)extractUpdate { - id unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.updater.decryptionPassword]; + id updater = self.updater; + id unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:updater.decryptionPassword]; BOOL success; if (!unarchiver) { @@ -427,7 +439,8 @@ - (BOOL)mayUpdateAndRestart { - return (!self.updater.delegate || ![self.updater.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [self.updater.delegate updaterShouldRelaunchApplication:(id)self.updater]); + id updater = self.updater; + return (!updater.delegate || ![updater.delegate respondsToSelector:@selector(updaterShouldRelaunchApplication:)] || [updater.delegate updaterShouldRelaunchApplication:self.updater]); } - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI @@ -452,8 +465,9 @@ } // Give the host app an opportunity to postpone the install and relaunch. + id updater = self.updater; static BOOL postponedOnce = NO; - id updaterDelegate = [self.updater delegate]; + id updaterDelegate = [updater delegate]; if (!postponedOnce && [updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)]) { NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[self class] instanceMethodSignatureForSelector:@selector(installWithToolAndRelaunch:)]]; @@ -461,17 +475,17 @@ [invocation setArgument:&relaunch atIndex:2]; [invocation setTarget:self]; postponedOnce = YES; - if ([updaterDelegate updater:(id)self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { + if ([updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvoking:invocation]) { return; } } if ([updaterDelegate respondsToSelector:@selector(updater:willInstallUpdate:)]) { - [updaterDelegate updater:(id)self.updater willInstallUpdate:self.updateItem]; + [updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; } - NSBundle *sparkleBundle = self.updater.sparkleBundle; + NSBundle *sparkleBundle = updater.sparkleBundle; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. @@ -515,7 +529,7 @@ self.relaunchPath = relaunchCopyTargetPath; // Set for backwards compatibility, in case any delegates modify it [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; if ([updaterDelegate respondsToSelector:@selector(updaterWillRelaunchApplication:)]) - [updaterDelegate updaterWillRelaunchApplication:(id)self.updater]; + [updaterDelegate updaterWillRelaunchApplication:self.updater]; NSString *relaunchToolPath = [[NSBundle bundleWithPath:self.relaunchPath] executablePath]; if (!relaunchToolPath || ![[NSFileManager defaultManager] fileExistsAtPath:self.relaunchPath]) { @@ -529,7 +543,7 @@ NSString *pathToRelaunch = [self.host bundlePath]; if ([updaterDelegate respondsToSelector:@selector(pathToRelaunchForUpdater:)]) { - NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:(id)self.updater]; + NSString *delegateRelaunchPath = [updaterDelegate pathToRelaunchForUpdater:self.updater]; if (delegateRelaunchPath != nil) { pathToRelaunch = delegateRelaunchPath; } @@ -599,9 +613,10 @@ } // Notify host app that update has aborted - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:(id)self.updater didAbortWithError:error]; + [updaterDelegate updater:self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUProbingUpdateDriver.m b/Sparkle/SUProbingUpdateDriver.m index 872225de..a5af1d39 100644 --- a/Sparkle/SUProbingUpdateDriver.m +++ b/Sparkle/SUProbingUpdateDriver.m @@ -16,10 +16,11 @@ - (void)didFindValidUpdate { - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didFindValidUpdate:)]) - [updaterDelegate updater:(id)self.updater didFindValidUpdate:self.updateItem]; + [updaterDelegate updater:self.updater didFindValidUpdate:self.updateItem]; NSDictionary *userInfo = (self.updateItem != nil) ? @{ SUUpdaterAppcastItemNotificationKey: self.updateItem } : nil; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification object:self.updater userInfo:userInfo]; [self abortUpdate]; @@ -27,10 +28,11 @@ - (void)didNotFindUpdate { - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [updaterDelegate updaterDidNotFindUpdate:(id)self.updater]; + [updaterDelegate updaterDidNotFindUpdate:self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 5a5e2300..fcd1c853 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -28,10 +28,11 @@ - (void)didNotFindUpdate { - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) { - [updaterDelegate updaterDidNotFindUpdate:(id)self.updater]; + [updaterDelegate updaterDidNotFindUpdate:self.updater]; } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; @@ -45,9 +46,10 @@ } else { // Call delegate separately here because otherwise it won't know we stopped. // Normally this gets called by the superclass - id updaterDelegate = [self.updater delegate]; + id updater = self.updater; + id updaterDelegate = [updater delegate]; if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:(id)self.updater didAbortWithError:error]; + [updaterDelegate updater:self.updater didAbortWithError:error]; } [self abortUpdate]; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 8fc57b76..6b602b44 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -56,8 +56,9 @@ - (void)didFindValidUpdate { - if ([[self.updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { - [[self.updater delegate] updater:(id)self.updater didFindValidUpdate:self.updateItem]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) { + [[updater delegate] updater:self.updater didFindValidUpdate:self.updateItem]; } if (self.automaticallyInstallUpdates) { @@ -70,8 +71,8 @@ }]; id versDisp = nil; - if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { - versDisp = [[self.updater delegate] versionDisplayerForUpdater:(id)self.updater]; + if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { + versDisp = [[updater delegate] versionDisplayerForUpdater:self.updater]; } [self.updateAlert setVersionDisplayer:versDisp]; @@ -92,8 +93,9 @@ - (void)didNotFindUpdate { - if ([[self.updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) - [[self.updater delegate] updaterDidNotFindUpdate:(id)self.updater]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) + [[updater delegate] updaterDidNotFindUpdate:self.updater]; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; if (!self.automaticallyInstallUpdates) { @@ -205,8 +207,10 @@ { if (self.download) { [self.download cancel]; - if ([[self.updater delegate] respondsToSelector:@selector(userDidCancelDownload:)]) { - [[self.updater delegate] userDidCancelDownload:(id)self.updater]; + + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(userDidCancelDownload:)]) { + [[updater delegate] userDidCancelDownload:self.updater]; } } [self abortUpdate]; @@ -293,8 +297,9 @@ - (void)showAlert:(NSAlert *)alert { - if ([[self.updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { - [[self.updater delegate] updaterWillShowModalAlert:(id)self.updater]; + id updater = self.updater; + if ([[updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) { + [[updater delegate] updaterWillShowModalAlert:self.updater]; } // When showing a modal alert we need to ensure that background applications @@ -304,8 +309,8 @@ [alert setIcon:[SUApplicationInfo bestIconForBundle:self.host.bundle]]; [alert runModal]; - if ([[self.updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) - [[self.updater delegate] updaterDidShowModalAlert:(id)self.updater]; + if ([[updater delegate] respondsToSelector:@selector(updaterDidShowModalAlert:)]) + [[updater delegate] updaterDidShowModalAlert:self.updater]; } @end diff --git a/Sparkle/SUUpdateDriver.h b/Sparkle/SUUpdateDriver.h index 05d9547e..7e132aa1 100644 --- a/Sparkle/SUUpdateDriver.h +++ b/Sparkle/SUUpdateDriver.h @@ -13,11 +13,14 @@ extern NSString *const SUUpdateDriverFinishedNotification; -@class SUHost; +@class SUHost, SUUpdater; @protocol SUUpdaterPrivate; @interface SUUpdateDriver : NSObject -@property (readonly, weak) id updater; +// We only have SUUpdater* forward declared intentionally (i.e, not #import'ing SUUpdater.h in the update drivers) +// This is so we can minimize what we can access using SUUpdaterPrivate +@property (readonly, weak) SUUpdater *updater; + @property (strong) SUHost *host; - (instancetype)initWithUpdater:(id)updater;