diff --git a/Installation XPC Service/SUXPCInstaller.h b/Installation XPC Service/SUXPCInstaller.h index 52cdd1f0..0d179a0b 100644 --- a/Installation XPC Service/SUXPCInstaller.h +++ b/Installation XPC Service/SUXPCInstaller.h @@ -15,7 +15,7 @@ + (BOOL)copyPathContent:(NSString *)src toDirectory:(NSString *)dstDir error:(NSError **)outError; // dstDir will be created if absent -+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments completionHandler:(void (^)(void))completionHandler; ++ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments; + (void)launchTaskWithPath:(NSString *)launchPath arguments:(NSArray *)arguments diff --git a/Installation XPC Service/SUXPCInstaller.m b/Installation XPC Service/SUXPCInstaller.m index 6027620f..5bea603a 100644 --- a/Installation XPC Service/SUXPCInstaller.m +++ b/Installation XPC Service/SUXPCInstaller.m @@ -154,17 +154,16 @@ return (nil == error); } -+ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments completionHandler:(void (^)(void))completionHandler ++ (void)launchTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments { - void (^handler)(int, NSData *) = completionHandler != nil ? ^(int r, NSData *d) { completionHandler(); } : nil; [self launchTaskWithPath:path arguments:arguments environment:nil currentDirectoryPath:nil inputData:nil waitForTaskResult:NO - waitUntilDone:NO - completionHandler:handler]; + waitUntilDone:YES + completionHandler:nil]; } + (void)launchTaskWithPath:(NSString *)launchPath diff --git a/SUAppDelegate.h b/SUAppDelegate.h new file mode 100644 index 00000000..0036dd26 --- /dev/null +++ b/SUAppDelegate.h @@ -0,0 +1,19 @@ +// +// SUAppDelegate.h +// Sparkle +// +// Created by Dmytro Tretiakov on 8/1/14. +// +// + +#import + +@class SUUpdater; +@class SUUpdaterQueue; + +@interface SUAppDelegate : NSObject + +@property (nonatomic, retain) IBOutlet SUUpdater *updater; +@property (nonatomic, retain) SUUpdaterQueue *updaterQueue; + +@end diff --git a/SUAppDelegate.m b/SUAppDelegate.m new file mode 100644 index 00000000..5b1f2655 --- /dev/null +++ b/SUAppDelegate.m @@ -0,0 +1,27 @@ +// +// SUAppDelegate.m +// Sparkle +// +// Created by Dmytro Tretiakov on 8/1/14. +// +// + +#import "SUAppDelegate.h" +#import + +@implementation SUAppDelegate + +- (void)dealloc +{ + self.updater = nil; + self.updaterQueue = nil; + [super dealloc]; +} + +- (void)applicationDidFinishLaunching:(NSNotification *)notification +{ + self.updaterQueue = [[[SUUpdaterQueue alloc] init] autorelease]; + [self.updaterQueue addUpdater:self.updater]; +} + +@end diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 67da9326..b50e2979 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -55,8 +55,14 @@ static NSString * const kSUAutomaticUpdateParamName = @"autoupdate"; #endif // SPARKLE_IS_COMPATIBLE_WITH_DEVMATE // ------------------------------------------------------------------- +- (BOOL)shouldShowUI +{ + return showErrors; +} + - (void)unarchiverDidFinish:(SUUnarchiver *)ua { + showErrors = YES; alert = [[SUAutomaticUpdateAlert alloc] initWithAppcastItem:updateItem host:host delegate:self]; // If the app is a menubar app or the like, we need to focus it first and alter the @@ -95,19 +101,13 @@ static NSString * const kSUAutomaticUpdateParamName = @"autoupdate"; case SUDoNotInstallChoice: [host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; break; } } - (BOOL)shouldInstallSynchronously { return postponingInstallation; } -- (void)installWithToolAndRelaunch:(BOOL)relaunch -{ - showErrors = YES; - [super installWithToolAndRelaunch:relaunch]; -} - - (void)applicationWillTerminate:(NSNotification *)note { [self installWithToolAndRelaunch:NO]; @@ -118,7 +118,7 @@ static NSString * const kSUAutomaticUpdateParamName = @"autoupdate"; if (showErrors) [super abortUpdateWithError:error]; else - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortGotError]; } @end diff --git a/SUBasicUpdateDriver.h b/SUBasicUpdateDriver.h index 1a32b2b0..1d18ddf3 100644 --- a/SUBasicUpdateDriver.h +++ b/SUBasicUpdateDriver.h @@ -49,11 +49,9 @@ - (void)installWithToolAndRelaunch:(BOOL)relaunch; - (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error; - -- (void)installWithToolAndRelaunch:(BOOL)relaunch; - (void)cleanUpDownload; -- (void)abortUpdate; +- (void)abortUpdate:(SUUpdateAbortReason)reason; - (void)abortUpdateWithError:(NSError *)error; @end diff --git a/SUBasicUpdateDriver.m b/SUBasicUpdateDriver.m index b2e018ee..1bc916e2 100644 --- a/SUBasicUpdateDriver.m +++ b/SUBasicUpdateDriver.m @@ -355,7 +355,7 @@ NSArray *SUGetAllDevMateURLHosts(void) if (![updater mayUpdateAndRestart]) { - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortForbiddenByDelegate]; return; } @@ -376,22 +376,35 @@ NSArray *SUGetAllDevMateURLHosts(void) if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)]) [[updater delegate] updater:updater willInstallUpdate:updateItem]; - BOOL isAlreadyInstalled = NO; - if ([[updater delegate] respondsToSelector:@selector(updater:overrideInstallUpdate:downloadPath:)]) + SUFinishUpdateTask finishTasks = SUFinishUpdateWithDefaultInstallation; + + BOOL shouldRelaunch = YES; + if ([[updater delegate] respondsToSelector:@selector(updater:overrideInstallUpdate:downloadPath:shouldRelaunch:)] && + [[updater delegate] updater:updater overrideInstallUpdate:updateItem downloadPath:tempDir shouldRelaunch:&shouldRelaunch]) { - isAlreadyInstalled = [[updater delegate] updater:updater overrideInstallUpdate:updateItem downloadPath:tempDir]; + finishTasks = finishTasks & (~SUFinishUpdateWithInstall); + relaunch = relaunch && shouldRelaunch; + } + if (!relaunch) + { + finishTasks = finishTasks & (~SUFinishUpdateWithRelaunch); } + if (SUFinishUpdateAbort == finishTasks) + { + [self abortUpdate:SUUpdateAbortTasksFinished]; + return; + } + // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. NSString *relaunchPathToCopy = [SPARKLE_BUNDLE pathForResource:@"finish_installation" ofType:@"app"]; NSString *targetPath = [[host appSupportPath] stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]]; // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. NSError *error = nil; -#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] attributes: [NSDictionary dictionary]]; -#else - [[NSFileManager defaultManager] createDirectoryAtPath: [targetPath stringByDeletingLastPathComponent] withIntermediateDirectories: YES attributes: [NSDictionary dictionary] error: &error]; -#endif + [[NSFileManager defaultManager] createDirectoryAtPath:[targetPath stringByDeletingLastPathComponent] + withIntermediateDirectories:YES + attributes:[NSDictionary dictionary] + error:&error]; // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. BOOL copiedRelaunchTool = NO; @@ -403,21 +416,37 @@ NSArray *SUGetAllDevMateURLHosts(void) { copiedRelaunchTool = [SUPlainInstaller copyPathWithAuthentication:relaunchPathToCopy overPath:targetPath temporaryName:nil error:&error]; } - [self finishRelaunchAfterSuccessfulCopying:copiedRelaunchTool fromPath:relaunchPathToCopy toPath:targetPath isInstalled:isAlreadyInstalled relaunch:relaunch]; + [self finishRelaunchAfterSuccessfulCopying:copiedRelaunchTool fromPath:relaunchPathToCopy toPath:targetPath finishTaskMask:finishTasks]; } -- (void)finishRelaunchAfterSuccessfulCopying:(BOOL)copiedRelaunchTool fromPath:(NSString *)relaunchPathToCopy toPath:(NSString *)targetPath isInstalled:(BOOL)isInstalled relaunch:(BOOL)relaunch +- (void)finishRelaunchAfterSuccessfulCopying:(BOOL)copiedRelaunchTool fromPath:(NSString *)relaunchPathToCopy toPath:(NSString *)targetPath finishTaskMask:(SUFinishUpdateTask)taskMask { - NSError *error = nil; - if( copiedRelaunchTool ) + if (copiedRelaunchTool) + { relaunchPath = [targetPath retain]; + } else + { [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]]]; + } - [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; - if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication:)]) - [[updater delegate] updaterWillRelaunchApplication:updater]; + NSString *pathToRelaunch = @""; + BOOL shouldFinishUpdateWithRelaunch = (taskMask & SUFinishUpdateWithRelaunch) != 0; + if (shouldFinishUpdateWithRelaunch) + { + [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self]; + if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication:)]) + { + [[updater delegate] updaterWillRelaunchApplication:updater]; + } + + pathToRelaunch = [host bundlePath]; + if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) + { + pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; + } + } if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath]) { @@ -425,23 +454,29 @@ NSArray *SUGetAllDevMateURLHosts(void) [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]]]; // We intentionally don't abandon the update here so that the host won't initiate another. return; - } - - NSString *pathToRelaunch = [host bundlePath]; - if ([[updater delegate] respondsToSelector:@selector(pathToRelaunchForUpdater:)]) - pathToRelaunch = [[updater delegate] pathToRelaunchForUpdater:updater]; + } + NSString *relaunchToolPath = [relaunchPath stringByAppendingPathComponent: @"/Contents/MacOS/finish_installation"]; - NSArray *arguments = [NSArray arrayWithObjects:[host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], tempDir, relaunch ? @"1" : @"0", isInstalled ? @"1" : @"0", nil]; + NSArray *arguments = [NSArray arrayWithObjects: + [host bundlePath], + pathToRelaunch, + [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], + tempDir, + [NSString stringWithFormat:@"%lu", taskMask], + nil]; + if (SUShouldUseXPCInstaller()) { - [SUXPCInstaller launchTaskWithLaunchPath:relaunchToolPath arguments:arguments completionHandler:^{ - [NSApp terminate:self]; - }]; + [SUXPCInstaller launchTaskWithLaunchPath:relaunchToolPath arguments:arguments]; } else { [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:arguments]; - [NSApp terminate:self]; + } + + if (shouldFinishUpdateWithRelaunch) + { + [NSApp terminate:nil]; } } @@ -473,12 +508,12 @@ NSArray *SUGetAllDevMateURLHosts(void) [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]]]; } -- (void)abortUpdate +- (void)abortUpdate:(SUUpdateAbortReason)reason { [[self retain] autorelease]; // In case the notification center was the last one holding on to us. [self cleanUpDownload]; [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super abortUpdate]; + [super abortUpdate:reason]; } - (void)abortUpdateWithError:(NSError *)error @@ -489,7 +524,7 @@ NSArray *SUGetAllDevMateURLHosts(void) SULog(@"Sparkle Error (continued): %@", [error localizedFailureReason]); if (download) [download cancel]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortGotError]; } - (void)dealloc diff --git a/SUConstants.h b/SUConstants.h index 6612515e..c0ed8e83 100644 --- a/SUConstants.h +++ b/SUConstants.h @@ -39,6 +39,28 @@ extern NSString *const SUUpdaterWillRestartNotification; extern NSString *const SUTechnicalErrorInformationKey; +// ----------------------------------------------------------------------------- +// Typedefs: +// ----------------------------------------------------------------------------- + +typedef NS_OPTIONS(NSUInteger, SUFinishUpdateTask) +{ + SUFinishUpdateAbort = 0, + SUFinishUpdateWithInstall = 1 << 0, + SUFinishUpdateWithRelaunch = 1 << 1, + SUFinishUpdateWithDefaultInstallation = SUFinishUpdateWithInstall | SUFinishUpdateWithRelaunch +}; + +typedef NS_ENUM(NSUInteger, SUUpdateAbortReason) +{ + SUUpdateAbortUndefined = 0, + SUUpdateAbortForbiddenByDelegate, + SUUpdateAbortTasksFinished, // installed and relaunched by delegate + SUUpdateAbortCanceledByUser, + SUUpdateAbortDidNotFind, + SUUpdateAbortGotError +}; + // ----------------------------------------------------------------------------- // PList keys:: // ----------------------------------------------------------------------------- diff --git a/SUProbingUpdateDriver.m b/SUProbingUpdateDriver.m index 64bd5b56..f14710fc 100644 --- a/SUProbingUpdateDriver.m +++ b/SUProbingUpdateDriver.m @@ -17,14 +17,14 @@ { if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) [[updater delegate] updater:updater didFindValidUpdate:updateItem]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortTasksFinished]; } - (void)didNotFindUpdate { if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) [[updater delegate] updaterDidNotFindUpdate:updater]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortDidNotFind]; } @end diff --git a/SUScheduledUpdateDriver.m b/SUScheduledUpdateDriver.m index 2d4b0750..f0d3d0fc 100644 --- a/SUScheduledUpdateDriver.m +++ b/SUScheduledUpdateDriver.m @@ -15,6 +15,11 @@ @implementation SUScheduledUpdateDriver +- (BOOL)shouldShowUI +{ + return showErrors; +} + - (void)didFindValidUpdate { showErrors = YES; // We only start showing errors after we present the UI for the first time. @@ -25,7 +30,7 @@ { if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)]) [[updater delegate] updaterDidNotFindUpdate:updater]; - [self abortUpdate]; // Don't tell the user that no update was found; this was a scheduled update. + [self abortUpdate:SUUpdateAbortDidNotFind]; // Don't tell the user that no update was found; this was a scheduled update. } - (void)abortUpdateWithError:(NSError *)error @@ -33,7 +38,7 @@ if (showErrors) [super abortUpdateWithError:error]; else - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortGotError]; } @end diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index 673ac615..86f1f1a4 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -17,6 +17,11 @@ @implementation SUUIBasedUpdateDriver +- (BOOL)shouldShowUI +{ + return YES; +} + - (void)didFindValidUpdate { updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem host:host]; @@ -53,7 +58,7 @@ NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up-to-date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [host name], [host displayVersion]]; [self showModalAlert:alert]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortDidNotFind]; } - (void)applicationDidBecomeActive:(NSNotification *)aNotification @@ -83,16 +88,16 @@ case SUOpenInfoURLChoice: [[NSWorkspace sharedWorkspace] openURL: [updateItem infoURL]]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; break; case SUSkipThisVersionChoice: [host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; break; case SURemindMeLaterChoice: - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; break; } } @@ -129,7 +134,7 @@ { if (download) [download cancel]; - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; } - (void)extractUpdate @@ -206,6 +211,7 @@ - (void)abortUpdateWithError:(NSError *)error { + abortReason = SUUpdateAbortGotError; NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"Update Error!", nil) defaultButton:SULocalizedString(@"Cancel Update", nil) alternateButton:nil @@ -215,7 +221,7 @@ [super abortUpdateWithError:error]; } -- (void)abortUpdate +- (void)abortUpdate:(SUUpdateAbortReason)reason { if (statusController) { @@ -223,11 +229,18 @@ [statusController autorelease]; statusController = nil; } - [super abortUpdate]; + [super abortUpdate:reason]; } - (void)showModalAlert:(NSAlert *)alert { + if ([[updater delegate] respondsToSelector:@selector(updater:mayShowModalAlert:)] && + ![[updater delegate] updater:updater mayShowModalAlert:alert]) + { + // delegate forbids to show this alert! + return; + } + if ([[updater delegate] respondsToSelector:@selector(updaterWillShowModalAlert:)]) [[updater delegate] updaterWillShowModalAlert: updater]; diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 9e8a73e2..82bfe69a 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -20,15 +20,17 @@ extern NSString * const SUUpdateDriverFinishedNotification; SUUpdater *updater; NSURL *appcastURL; - BOOL finished; + SUUpdateAbortReason abortReason; } -- initWithUpdater:(SUUpdater *)updater; +- (id)initWithUpdater:(SUUpdater *)updater; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; -- (void)abortUpdate; +- (void)abortUpdate:(SUUpdateAbortReason)reason; - (BOOL)finished; - (SUHost*)host; - (void)setHost:(SUHost*)newHost; +- (SUUpdateAbortReason)abortReason; +- (BOOL)shouldShowUI; // can change it's value @end diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index e1bae4ee..662e5c6a 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -23,17 +23,31 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)h { + abortReason = SUUpdateAbortUndefined; appcastURL = [URL copy]; host = [h retain]; } -- (void)abortUpdate +- (void)abortUpdate:(SUUpdateAbortReason)reason { - [self setValue:[NSNumber numberWithBool:YES] forKey:@"finished"]; + abortReason = reason; [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self]; } -- (BOOL)finished { return finished; } +- (BOOL)finished +{ + return abortReason != SUUpdateAbortUndefined; +} + +- (SUUpdateAbortReason)abortReason +{ + return abortReason; +} + +- (BOOL)shouldShowUI +{ + return NO; +} - (void)dealloc { diff --git a/SUUpdater.h b/SUUpdater.h index b09cf902..b1728f9d 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -85,7 +85,7 @@ @interface NSObject (SUUpdaterDelegateInformalProtocol) // Use this to keep Sparkle from popping up e.g. while your setup assistant is showing: -- (BOOL)updaterMayCheckForUpdates:(SUUpdater *)bundle; +- (BOOL)updaterMayCheckForUpdates:(SUUpdater *)updater; // This method allows you to add extra parameters to the appcast URL, potentially based on whether or not Sparkle will also be sending along the system profile. This method should return an array of dictionaries with keys: "key", "value", "displayKey", "displayValue", the latter two being specifically for display to the user. - (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile; @@ -113,7 +113,7 @@ - (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update; // Override to handle update manually -- (BOOL)updater:(SUUpdater *)updater overrideInstallUpdate:(SUAppcastItem *)update downloadPath:(NSString *)downloadPath; +- (BOOL)updater:(SUUpdater *)updater overrideInstallUpdate:(SUAppcastItem *)update downloadPath:(NSString *)downloadPath shouldRelaunch:(BOOL *)outShouldRelaunch; // Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue. // This is not called if the user didn't relaunch on the previous update, in that case it will immediately @@ -140,8 +140,9 @@ // Called before and after, respectively, an updater shows a modal alert window, to give the host // the opportunity to hide attached windows etc. that may get in the way: --(void) updaterWillShowModalAlert:(SUUpdater *)updater; --(void) updaterDidShowModalAlert:(SUUpdater *)updater; +- (BOOL)updater:(SUUpdater *)updater mayShowModalAlert:(NSAlert *)alertToShow; +- (void)updaterWillShowModalAlert:(SUUpdater *)updater; +- (void)updaterDidShowModalAlert:(SUUpdater *)updater; @end diff --git a/SUUpdater.m b/SUUpdater.m index c8d6b13e..17b03986 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -7,6 +7,7 @@ // #import "SUUpdater.h" +#import "SUUpdater_Private.h" #import "SUHost.h" #import "SUUpdatePermissionPrompt.h" @@ -21,7 +22,8 @@ #include -@interface SUUpdater (Private) +@interface SUUpdater () + - (id)initForBundle:(NSBundle *)bundle; - (void)startUpdateCycle; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; @@ -32,8 +34,8 @@ - (void)updateDriverDidFinish:(NSNotification *)note; - (NSURL *)parameterizedFeedURL; --(void) notifyWillShowModalAlert; --(void) notifyDidShowModalAlert; +-(void)notifyWillShowModalAlert; +-(void)notifyDidShowModalAlert; @end @@ -107,13 +109,30 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault BOOL hasPublicDSAKey = [host publicDSAKey] != nil; BOOL isMainBundle = [bundle isEqualTo:[NSBundle mainBundle]]; BOOL hostIsCodeSigned = [SUCodeSigningVerifier hostApplicationIsCodeSigned]; - if (!isMainBundle && !hasPublicDSAKey) { + NSAlert *warnAlert = nil; + if (!isMainBundle && !hasPublicDSAKey) + { + warnAlert = [NSAlert alertWithMessageText:SULocalizedString(@"Insecure update error!", nil) + defaultButton:SULocalizedString(@"OK", nil) + alternateButton:nil + otherButton:nil + informativeTextWithFormat:SULocalizedString(@"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + } + else if (isMainBundle && !(hasPublicDSAKey || hostIsCodeSigned)) + { + warnAlert = [NSAlert alertWithMessageText:SULocalizedString(@"Insecure update error!", nil) + defaultButton:SULocalizedString(@"OK", nil) + alternateButton:nil + otherButton:nil + informativeTextWithFormat:SULocalizedString(@"For security reasons, you need to code sign your application or sign your updates with a DSA key. See Sparkle's documentation for more information.", nil)]; + } + + if (warnAlert != nil && + (![[self delegate] respondsToSelector:@selector(updater:mayShowModalAlert:)] || + [[self delegate] updater:self mayShowModalAlert:warnAlert])) + { [self notifyWillShowModalAlert]; - NSRunAlertPanel(@"Insecure update error!", @"For security reasons, you need to sign your updates with a DSA key. See Sparkle's documentation for more information.", @"OK", nil, nil); - [self notifyDidShowModalAlert]; - } else if (isMainBundle && !(hasPublicDSAKey || hostIsCodeSigned)) { - [self notifyWillShowModalAlert]; - NSRunAlertPanel(@"Insecure update error!", @"For security reasons, you need to code sign your application or sign your updates with a DSA key. See Sparkle's documentation for more information.", @"OK", nil, nil); + [warnAlert runModal]; [self notifyDidShowModalAlert]; } #endif @@ -204,9 +223,15 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault - (void)updateDriverDidFinish:(NSNotification *)note { - if ([note object] == driver && [driver finished]) + if ([note object] == driver && (!driver || [driver finished])) { - [driver release]; driver = nil; + if ([[self delegate] respondsToSelector:@selector(updaterDidEndUpdateProcess:)]) + { + [[self delegate] updaterDidEndUpdateProcess:self]; + } + + [driver release]; + driver = nil; [self scheduleNextUpdateCheck]; } } @@ -336,6 +361,11 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault if ([self updateInProgress]) { return; } if (checkTimer) { [checkTimer invalidate]; [checkTimer release]; checkTimer = nil; } // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. + if ([[self delegate] respondsToSelector:@selector(updaterWillStartUpdateProcess:)]) + { + [[self delegate] updaterWillStartUpdateProcess:self]; + } + SUClearLog(); SULog( @"===== %@ =====", [[NSFileManager defaultManager] displayNameAtPath: [[NSBundle mainBundle] bundlePath]] ); @@ -345,7 +375,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault if( [delegate respondsToSelector: @selector(updaterMayCheckForUpdates:)] && ![delegate updaterMayCheckForUpdates: self] ) { - [self scheduleNextUpdateCheck]; + [self updateDriverDidFinish:nil]; return; } @@ -354,7 +384,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault // If we're not given a driver at all, just schedule the next update check and bail. if (!driver) { - [self scheduleNextUpdateCheck]; + [self updateDriverDidFinish:nil]; return; } @@ -362,7 +392,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault if( theFeedURL ) // Use a NIL URL to cancel quietly. [driver checkForUpdatesAtURL: theFeedURL host:host]; else - [driver abortUpdate]; + [driver abortUpdate:SUUpdateAbortGotError]; } - (void)registerAsObserver @@ -580,7 +610,9 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault } - (id)delegate { return delegate; } +- (SUHost *)host { return host; } - (NSBundle *)hostBundle { return [host bundle]; } +- (SUBasicUpdateDriver *)driver { return (SUBasicUpdateDriver *)driver; } #pragma mark - DevMate Interaction diff --git a/SUUpdaterQueue.h b/SUUpdaterQueue.h new file mode 100644 index 00000000..90f686f7 --- /dev/null +++ b/SUUpdaterQueue.h @@ -0,0 +1,21 @@ +// +// SUUpdaterQueue.h +// Sparkle +// +// Created by Dmytro Tretiakov on 7/31/14. +// +// + +#import + +@class SUUpdater; + +@interface SUUpdaterQueue : NSObject + +- (void)addUpdater:(SUUpdater *)updater; +- (void)removeUpdater:(SUUpdater *)updater; + +- (void)checkForUpdates; +- (void)checkForUpdatesInBackground; + +@end diff --git a/SUUpdaterQueue.m b/SUUpdaterQueue.m new file mode 100644 index 00000000..c64f0a56 --- /dev/null +++ b/SUUpdaterQueue.m @@ -0,0 +1,393 @@ +// +// SUUpdaterQueue.m +// Sparkle +// +// Created by Dmytro Tretiakov on 7/31/14. +// +// + +#import "SUUpdaterQueue.h" +#import "SUUpdater.h" +#import "SUUpdater_Private.h" +#import "SUConstants.h" +#import "SUUserInitiatedUpdateDriver.h" + +@interface SUDelegateProxy : NSProxy + +@property (nonatomic, assign) id realDelegate; +@property (nonatomic, assign) SUUpdaterQueue *updaterQueue; + +@end + +@implementation SUDelegateProxy + ++ (BOOL)shouldRedirectToUpdaterQueue:(SEL)aSelector +{ + if (nil == aSelector) + return NO; + + static NSSet *sSelectorsToRedirect = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sSelectorsToRedirect = [[NSSet alloc] initWithObjects: + NSStringFromSelector(@selector(updaterWillStartUpdateProcess:)), + NSStringFromSelector(@selector(updaterDidEndUpdateProcess:)), + NSStringFromSelector(@selector(updaterMayCheckForUpdates:)), + NSStringFromSelector(@selector(updater:mayShowModalAlert:)), + nil]; + }); + + return [sSelectorsToRedirect containsObject:NSStringFromSelector(aSelector)]; +} + +- (NSMethodSignature *)methodSignatureForSelector:(SEL)selector +{ + NSMethodSignature *signature = [self.realDelegate methodSignatureForSelector:selector]; + if (!signature) + { + signature = [self.updaterQueue methodSignatureForSelector:selector]; + } + if (!signature) + { + signature = [self methodSignatureForSelector:selector]; + } + return signature; +} + +- (BOOL)respondsToSelector:(SEL)aSelector +{ + BOOL result = NO; + + if ([SUDelegateProxy shouldRedirectToUpdaterQueue:aSelector]) + { + result = YES; + } + else + { + result = [self.realDelegate respondsToSelector:aSelector]; + } + + return result; +} + +- (void)forwardInvocation:(NSInvocation *)anInvocation +{ + if ([SUDelegateProxy shouldRedirectToUpdaterQueue:[anInvocation selector]]) + { + [anInvocation invokeWithTarget:self.updaterQueue]; + } + else if ([self.realDelegate respondsToSelector:anInvocation.selector]) + { + [anInvocation invokeWithTarget:self.realDelegate]; + } +} + +- (BOOL)isKindOfClass:(Class)aClass +{ + if (self.realDelegate) + return [self.realDelegate isKindOfClass:aClass]; + return NO; +} + +@end + +#pragma mark - + +@interface SUUpdaterQueue () +{ + NSMutableArray *_updaters; + NSMutableDictionary *_delegatesMap; +} + +@property (readonly) NSMutableArray *updaters; +@property (readonly) NSMutableDictionary *delegatesMap; +@property (retain) SUUpdater *currentUpdater; +@property (assign) BOOL currentUpdaterInProcess; +@property (assign) BOOL shouldContinueCheck; +@property (nonatomic, retain) NSMutableArray *resultUIDrivers; + +@end + +@implementation SUUpdaterQueue + +- (void)dealloc +{ + for (SUUpdater *updater in self.updaters) + { + [self removeUpdater:updater]; + } + [_updaters release]; + [_delegatesMap release]; + self.currentUpdater = nil; + self.resultUIDrivers = nil; + + [super dealloc]; +} + +- (NSMutableArray *)updaters +{ + if (nil == _updaters) + { + @synchronized (self) + { + _updaters = _updaters ? : [[NSMutableArray alloc] init]; + } + } + + return [[_updaters retain] autorelease]; +} + +- (NSMutableDictionary *)delegatesMap +{ + if (nil == _delegatesMap) + { + @synchronized (self) + { + _delegatesMap = _delegatesMap ? : [[NSMutableDictionary alloc] init]; + } + } + + return [[_delegatesMap retain] autorelease]; +} + +#pragma mark - + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if ([object isKindOfClass:[SUUpdater class]]) + { + [self updateUpdaterDelegate:object]; + } +} + +- (void)updateUpdaterDelegate:(SUUpdater *)updater +{ + if ([SUDelegateProxy class] == [[updater delegate] class] && + self == [[updater delegate] updaterQueue]) + { + return; + } + + @synchronized (self.delegatesMap) + { + id realDelegate = [updater delegate]; + SUDelegateProxy *proxy = [[SUDelegateProxy alloc] autorelease]; + proxy.realDelegate = realDelegate; + proxy.updaterQueue = self; + [updater setDelegate:proxy]; + + NSString *updaterKey = [self mapKeyForUpdater:updater]; + [self.delegatesMap setObject:proxy forKey:updaterKey]; + } +} + +- (NSString *)mapKeyForUpdater:(SUUpdater *)updater +{ + return [NSString stringWithFormat:@"%p", updater]; +} + +- (id)realDelegateForUpdater:(SUUpdater *)updater +{ + if (nil == updater) + return nil; + + id delegate = nil; + @synchronized (self.delegatesMap) + { + delegate = [self.delegatesMap objectForKey:[self mapKeyForUpdater:updater]]; + } + + return delegate; +} + +#pragma mark - + +- (void)addUpdater:(SUUpdater *)updater +{ + if (nil == updater) + return; + + if ([updater updateInProgress]) + { + NSLog(@"Could not add updater while it's in progress"); + return; + } + + NSMutableArray *updaters = self.updaters; + @synchronized (updaters) + { + //if (![updaters containsObject:updater]) + { + [self updateUpdaterDelegate:updater]; + [updater addObserver:self forKeyPath:@"delegate" options:NSKeyValueObservingOptionNew context:NULL]; + [self.updaters addObject:updater]; + } + } +} + +- (void)removeUpdater:(SUUpdater *)updater +{ + if (nil == updater) + return; + + if (updater == self.currentUpdater && self.currentUpdaterInProcess) + { + NSLog(@"Could not remove updater while it's in progress."); + return; + } + + NSMutableArray *updaters = self.updaters; + @synchronized (updaters) + { + if ([updaters containsObject:updater]) + { + [updater removeObserver:self forKeyPath:@"delegate"]; + id realDelegate = nil; + NSString *updaterKey = [self mapKeyForUpdater:updater]; + + @synchronized (self.delegatesMap) + { + realDelegate = [[self.delegatesMap objectForKey:updaterKey] realDelegate]; + [self.delegatesMap removeObjectForKey:updaterKey]; + } + + [updater setDelegate:realDelegate]; + [updaters removeObject:updater]; + } + } +} + +#pragma mark - + +- (void)performCheckForUpdates:(NSString *)selectorName +{ + NSUInteger index = 0; + self.shouldContinueCheck = YES; + self.resultUIDrivers = [NSMutableArray array]; + do + { + // in case if some of queued updaters is already in process + while (self.currentUpdaterInProcess) + { + [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.5f]]; + } + + if (!self.shouldContinueCheck) + break; + + @synchronized (self.updaters) + { + self.currentUpdater = index < [self.updaters count] ? [self.updaters objectAtIndex:index] : nil; + index++; + } + + if (nil == self.currentUpdater) + break; + + self.currentUpdaterInProcess = YES; + [self.currentUpdater performSelectorOnMainThread:NSSelectorFromString(selectorName) + withObject:nil + waitUntilDone:YES]; + } + while (YES); + + if (SUUpdateAbortDidNotFind == [[self.resultUIDrivers lastObject] abortReason]) + { + SUBasicUpdateDriver *driver = nil; + if ([self.resultUIDrivers count] > 1) + { + SUUpdater *mainUpdater = [SUUpdater sharedUpdater]; + driver = [[[SUUserInitiatedUpdateDriver alloc] initWithUpdater:mainUpdater] autorelease]; + [driver setHost:[mainUpdater host]]; + } + else + { + driver = [self.resultUIDrivers lastObject]; + } + + [driver performSelectorOnMainThread:@selector(didNotFindUpdate) withObject:nil waitUntilDone:YES]; + } + self.resultUIDrivers = nil; +} + +- (void)checkForUpdates +{ + [self performSelectorInBackground:@selector(performCheckForUpdates:) + withObject:NSStringFromSelector(@selector(checkForUpdates:))]; +} + +- (void)checkForUpdatesInBackground +{ + [self performSelectorInBackground:@selector(performCheckForUpdates:) + withObject:NSStringFromSelector(@selector(checkForUpdatesInBackground))]; +} + +#pragma mark - + +- (void)updaterWillStartUpdateProcess:(SUUpdater *)updater +{ + if ((nil != updater && nil == self.currentUpdater) || + (self.currentUpdater == updater)) + { + self.currentUpdater = updater; + self.currentUpdaterInProcess = YES; + } +} + +- (void)updaterDidEndUpdateProcess:(SUUpdater *)updater +{ + if (self.currentUpdater == updater) + { + self.currentUpdater = nil; + self.currentUpdaterInProcess = NO; + + SUBasicUpdateDriver *driver = [updater driver]; + do + { + if (![driver shouldShowUI]) + break; + + if (SUUpdateAbortGotError == [driver abortReason]) + { + self.resultUIDrivers = nil; + self.shouldContinueCheck = NO; + break; + } + + [self.resultUIDrivers addObject:driver]; + } + while (NO); + } +} + +- (BOOL)updaterMayCheckForUpdates:(SUUpdater *)updater +{ + BOOL result = NO; + if (updater != nil && updater == self.currentUpdater) + { + id realDelegate = [SUDelegateProxy class] == [[updater delegate] class] ? [[updater delegate] realDelegate] : [updater delegate]; + result = ![realDelegate respondsToSelector:_cmd] || [realDelegate updaterMayCheckForUpdates:updater]; + } + + return result; +} + +- (BOOL)updater:(SUUpdater *)updater mayShowModalAlert:(NSAlert *)alertToShow +{ + BOOL result = YES; + + if (updater != nil && updater == self.currentUpdater && self.shouldContinueCheck) + { + if (SUUpdateAbortGotError != [[updater driver] abortReason]) + result = NO; + } + else + { + id realDelegate = [SUDelegateProxy class] == [[updater delegate] class] ? [[updater delegate] realDelegate] : [updater delegate]; + result = ![realDelegate respondsToSelector:_cmd] || [realDelegate updater:updater mayShowModalAlert:alertToShow]; + } + + return result; +} + +@end diff --git a/SUUpdater_Private.h b/SUUpdater_Private.h index 0a9edcd5..924c8f2c 100644 --- a/SUUpdater_Private.h +++ b/SUUpdater_Private.h @@ -8,9 +8,19 @@ #import "SUUpdater.h" #import "SUCodeSigningVerifier.h" +#import "SUBasicUpdateDriver.h" @interface SUUpdater (Private) - (BOOL)mayUpdateAndRestart; +- (SUHost *)host; +- (SUBasicUpdateDriver *)driver; + +@end + +@interface NSObject (SUPrivateUpdaterDelegateInformalProtocol) + +- (void)updaterWillStartUpdateProcess:(SUUpdater *)updater; +- (void)updaterDidEndUpdateProcess:(SUUpdater *)updater; @end diff --git a/SUUserInitiatedUpdateDriver.m b/SUUserInitiatedUpdateDriver.m index 276b032b..7bb6359a 100644 --- a/SUUserInitiatedUpdateDriver.m +++ b/SUUserInitiatedUpdateDriver.m @@ -50,7 +50,7 @@ { if (isCanceled) { - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; return; } [self closeCheckingWindow]; @@ -63,17 +63,17 @@ [super abortUpdateWithError:error]; } -- (void)abortUpdate +- (void)abortUpdate:(SUUpdateAbortReason)reason { [self closeCheckingWindow]; - [super abortUpdate]; + [super abortUpdate:reason]; } - (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error { if (isCanceled) { - [self abortUpdate]; + [self abortUpdate:SUUpdateAbortCanceledByUser]; return; } [super appcast:ac failedToLoadWithError:error]; diff --git a/Sparkle.h b/Sparkle.h index 08dd5777..1662e7d8 100644 --- a/Sparkle.h +++ b/Sparkle.h @@ -13,6 +13,7 @@ // there are name-space collisions) so we can list all of them to start with: #import +#import #import #import diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index c803f923..1b55118b 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -16,6 +16,9 @@ 3330768F190A5CB8005602B2 /* Sparkle.strings in Resources */ = {isa = PBXBuildFile; fileRef = 61AAE8220A321A7F00D8810D /* Sparkle.strings */; }; 338A79F11919191500EDD837 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; 338A79F319193CDC00EDD837 /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; + 33C07AAD198B887F0039242D /* SUAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C07AAC198B887F0039242D /* SUAppDelegate.m */; }; + 33C3934C198A825600C29D9D /* SUUpdaterQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 33C3934A198A825600C29D9D /* SUUpdaterQueue.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 33C3934D198A825600C29D9D /* SUUpdaterQueue.m in Sources */ = {isa = PBXBuildFile; fileRef = 33C3934B198A825600C29D9D /* SUUpdaterQueue.m */; }; 33D081831888446F00394A94 /* libDMCore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 33D081821888446E00394A94 /* libDMCore.a */; }; 3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; }; 525A2790133D6AE900FD8D70 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 525A278F133D6AE900FD8D70 /* Cocoa.framework */; }; @@ -251,6 +254,10 @@ 0867D6A5FE840307C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = ""; }; 3329F06D18FBFBA800556010 /* ResourceRules.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ResourceRules.plist; sourceTree = ""; }; 33307690190A5D8B005602B2 /* install_service.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = install_service.pch; sourceTree = ""; }; + 33C07AAB198B887F0039242D /* SUAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAppDelegate.h; sourceTree = ""; }; + 33C07AAC198B887F0039242D /* SUAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAppDelegate.m; sourceTree = ""; }; + 33C3934A198A825600C29D9D /* SUUpdaterQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterQueue.h; sourceTree = ""; }; + 33C3934B198A825600C29D9D /* SUUpdaterQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterQueue.m; sourceTree = ""; }; 33CE69761934D1F8009D5956 /* ReleaseNotes.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = ReleaseNotes.rtf; sourceTree = ""; }; 33D081821888446E00394A94 /* libDMCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libDMCore.a; path = External/libDMCore.a; sourceTree = ""; }; 3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionDisplayProtocol.h; sourceTree = ""; }; @@ -812,6 +819,8 @@ 61B5F92409C4CFC900B25A18 /* main.m */, 61B5F90409C4CEE200B25A18 /* Test Application-Info.plist */, 618E9CFC0E7328F1004646D8 /* dsa_pub.pem */, + 33C07AAB198B887F0039242D /* SUAppDelegate.h */, + 33C07AAC198B887F0039242D /* SUAppDelegate.m */, ); name = "Test Application Sources"; sourceTree = ""; @@ -854,6 +863,8 @@ 61B5F8E309C4CE3C00B25A18 /* SUUpdater.h */, 6158A1C4137904B300487EC1 /* SUUpdater_Private.h */, 61B5F8E409C4CE3C00B25A18 /* SUUpdater.m */, + 33C3934A198A825600C29D9D /* SUUpdaterQueue.h */, + 33C3934B198A825600C29D9D /* SUUpdaterQueue.m */, 61CFB2C20E38496B007A1735 /* Drivers */, 61CFB2C10E384958007A1735 /* Support */, ); @@ -953,6 +964,7 @@ 61F83F740DBFE141006FDD30 /* SUBasicUpdateDriver.h in Headers */, 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */, 61B93B270DD0FDD300DCD2F8 /* SUAutomaticUpdateDriver.h in Headers */, + 33C3934C198A825600C29D9D /* SUUpdaterQueue.h in Headers */, 61B93C090DD112FF00DCD2F8 /* SUScheduledUpdateDriver.h in Headers */, 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */, 6101347B0DD2541A0049ACDF /* SUProbingUpdateDriver.h in Headers */, @@ -1047,7 +1059,7 @@ name = "Sparkle Unit Tests"; productName = "Sparkle Unit Tests"; productReference = 612279D90DB5470200AB99EA /* Sparkle Unit Tests.octest */; - productType = "com.apple.product-type.bundle"; + productType = "com.apple.product-type.bundle.ocunit-test"; }; 61B5F90109C4CEE200B25A18 /* Sparkle Test App */ = { isa = PBXNativeTarget; @@ -1370,6 +1382,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 33C07AAD198B887F0039242D /* SUAppDelegate.m in Sources */, 61B5F93009C4CFDC00B25A18 /* main.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1393,6 +1406,7 @@ buildActionMask = 2147483647; files = ( 61B5F8EE09C4CE3C00B25A18 /* SUUpdater.m in Sources */, + 33C3934D198A825600C29D9D /* SUUpdaterQueue.m in Sources */, 61B5F8EF09C4CE3C00B25A18 /* SUPlainInstallerInternals.m in Sources */, 61B5FBB709C4FAFF00B25A18 /* SUAppcast.m in Sources */, 61B5FC6F09C51F4900B25A18 /* SUAppcastItem.m in Sources */, diff --git a/Test Application/English.lproj/MainMenu.nib/classes.nib b/Test Application/English.lproj/MainMenu.nib/classes.nib deleted file mode 100644 index 14196291..00000000 --- a/Test Application/English.lproj/MainMenu.nib/classes.nib +++ /dev/null @@ -1,43 +0,0 @@ - - - - - IBClasses - - - CLASS - FirstResponder - LANGUAGE - ObjC - SUPERCLASS - NSObject - - - CLASS - NSObject - LANGUAGE - ObjC - - - ACTIONS - - checkForUpdates - id - - CLASS - SUUpdater - LANGUAGE - ObjC - OUTLETS - - delegate - id - - SUPERCLASS - NSObject - - - IBVersion - 1 - - diff --git a/Test Application/English.lproj/MainMenu.nib/designable.nib b/Test Application/English.lproj/MainMenu.nib/designable.nib index 72437679..909c2225 100644 --- a/Test Application/English.lproj/MainMenu.nib/designable.nib +++ b/Test Application/English.lproj/MainMenu.nib/designable.nib @@ -2,17 +2,25 @@ 1050 - 10A432 - 732 - 1038 - 437.00 + 14A298i + 6185.11 + 1326.11 + 743.00 com.apple.InterfaceBuilder.CocoaPlugin - 732 + 6185.11 - - - + + NSButton + NSButtonCell + NSCustomObject + NSMenu + NSMenuItem + NSTextField + NSTextFieldCell + NSUserDefaultsController + NSView + NSWindowTemplate com.apple.InterfaceBuilder.CocoaPlugin @@ -40,10 +48,10 @@ View - {1.79769e+308, 1.79769e+308} + {213, 107} - + 256 @@ -51,18 +59,19 @@ 268 {{21, 112}, {225, 18}} + YES - -2080244224 + -2080374784 0 Automatically check for updates - LucidaGrande + YES 13 1044 - 1211912703 + 1211912448 2 NSImage @@ -76,20 +85,22 @@ 200 25 + NO 268 {{21, 92}, {228, 18}} + YES - -2080244224 + -2080374784 0 Automatically download updates - 1211912703 + 1211912448 2 @@ -98,20 +109,22 @@ 200 25 + NO 268 {{21, 72}, {224, 18}} + YES - -2080244224 + -2080374784 0 Send system profile information - 1211912703 + 1211912448 2 @@ -120,20 +133,22 @@ 200 25 + NO 268 {{21, 52}, {152, 18}} + YES - -2080244224 + -2080374784 0 Has launched before - 1211912703 + 1211912448 2 @@ -142,21 +157,23 @@ 200 25 + NO 268 {{20, 136}, {106, 17}} + YES - 67239488 + 67108928 272630784 Debug options: - LucidaGrande-Bold + YES 13 - 16 + 2072 @@ -178,15 +195,18 @@ + NO + 1 268 {{17, 20}, {157, 17}} + YES - 68288064 + 68157504 272630784 Check for updates every @@ -194,6 +214,8 @@ + NO + 1 @@ -202,7 +224,7 @@ YES - 68288064 + 68157504 272630784 seconds @@ -210,15 +232,18 @@ + NO + 1 268 {{179, 18}, {56, 22}} + YES - -1804468671 + -1804599231 272630784 @@ -240,14 +265,17 @@ + NO + 1 {313, 173} - + - {{0, 0}, {1680, 1028}} + {{0, 0}, {1680, 1027}} {213, 129} - {1.79769e+308, 1.79769e+308} + {10000000000000, 10000000000000} + YES MainMenu @@ -267,6 +295,7 @@ NSMenuMixedState submenuAction: + NewApplication @@ -327,6 +356,7 @@ submenuAction: + Services @@ -406,6 +436,7 @@ submenuAction: + File @@ -438,6 +469,7 @@ submenuAction: + Open Recent @@ -543,6 +575,7 @@ submenuAction: + Edit @@ -651,6 +684,7 @@ submenuAction: + Find @@ -717,6 +751,7 @@ submenuAction: + Spelling @@ -762,6 +797,7 @@ submenuAction: + Window @@ -818,6 +854,7 @@ submenuAction: + Help @@ -839,12 +876,63 @@ SUUpdater + + SUAppDelegate + YES + + + delegate + + + + 266 + + + + terminate: + + + + 139 + + + + orderFrontStandardAboutPanel: + + + + 142 + + + + hideOtherApplications: + + + + 146 + + + + hide: + + + + 152 + + + + unhideAllApplications: + + + + 153 + performMiniaturize: @@ -893,46 +981,6 @@ 127 - - - terminate: - - - - 139 - - - - orderFrontStandardAboutPanel: - - - - 142 - - - - hideOtherApplications: - - - - 146 - - - - hide: - - - - 152 - - - - unhideAllApplications: - - - - 153 - cut: @@ -1086,20 +1134,12 @@ 208 - - value: values.SUHasLaunchedBefore - - - - - - value: values.SUHasLaunchedBefore - value - values.SUHasLaunchedBefore - 2 - + + delegate + + - 225 + 267 @@ -1149,6 +1189,22 @@ 261 + + + value: values.SUHasLaunchedBefore + + + + + + value: values.SUHasLaunchedBefore + value + values.SUHasLaunchedBefore + 2 + + + 225 + value: updateCheckInterval @@ -1165,6 +1221,14 @@ 263 + + + updater + + + + 265 + @@ -1752,175 +1816,110 @@ + + 264 + + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - {{0, 672}, {313, 173}} com.apple.InterfaceBuilder.CocoaPlugin {{0, 672}, {313, 173}} - - - {213, 107} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{258, 684}, {362, 20}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - {{270, 481}, {242, 203}} com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - 263 + 267 @@ -1931,706 +1930,25 @@ - - NSObject - - IBProjectSource - SUAppcast.h - - - - NSObject - - IBProjectSource - SUAutomaticUpdateAlert.h - - - - NSObject - - IBProjectSource - SUInstaller.h - - - - NSObject - - IBProjectSource - SUUnarchiver.h - - - - NSObject - - IBProjectSource - SUUpdateAlert.h - - - - NSObject - - IBProjectSource - SUUpdatePermissionPrompt.h - - - - NSObject - - IBProjectSource - SUUpdater.h - - - - NSObject - - IBUserSource - - - - - SUUpdater - NSObject - - checkForUpdates: - id - - - delegate - id - - - - - SUUpdater - NSObject - - IBUserSource - - - - - - - NSActionCell - NSCell - - IBFrameworkSource - AppKit.framework/Headers/NSActionCell.h - - - - NSApplication - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSApplication.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSApplicationScripting.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSColorPanel.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSHelpManager.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSPageLayout.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSUserInterfaceItemSearching.h - - - - NSBrowser - NSControl - - IBFrameworkSource - AppKit.framework/Headers/NSBrowser.h - - - - NSButton - NSControl - - IBFrameworkSource - AppKit.framework/Headers/NSButton.h - - - - NSButtonCell - NSActionCell - - IBFrameworkSource - AppKit.framework/Headers/NSButtonCell.h - - - - NSCell - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSCell.h - - - - NSControl - NSView - - IBFrameworkSource - AppKit.framework/Headers/NSControl.h - - - - NSController - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSController.h - - - - NSDocument - NSObject - - id - id - id - id - id - id - - - IBFrameworkSource - AppKit.framework/Headers/NSDocument.h - - - - NSDocument - - IBFrameworkSource - AppKit.framework/Headers/NSDocumentScripting.h - - - - NSDocumentController - NSObject - - id - id - id - id - - - IBFrameworkSource - AppKit.framework/Headers/NSDocumentController.h - - - - NSFormatter - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFormatter.h - - - - NSMatrix - NSControl - - IBFrameworkSource - AppKit.framework/Headers/NSMatrix.h - - - - NSMenu - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSMenu.h - - - - NSMenuItem - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSMenuItem.h - - - - NSMovieView - NSView - - IBFrameworkSource - AppKit.framework/Headers/NSMovieView.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSAccessibility.h - - - - NSObject - - - - NSObject - - - - NSObject - - - - NSObject - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSDictionaryController.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSDragging.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSFontManager.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSFontPanel.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSKeyValueBinding.h - - - - NSObject - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSNibLoading.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSOutlineView.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSPasteboard.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSSavePanel.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSTableView.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSToolbarItem.h - - - - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSView.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSArchiver.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSClassDescription.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSError.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSFileManager.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueCoding.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyValueObserving.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSKeyedArchiver.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSObject.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSObjectScripting.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSPortCoder.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSRunLoop.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptClassDescription.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptKeyValueCoding.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptObjectSpecifiers.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSScriptWhoseTests.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSThread.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURL.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURLConnection.h - - - - NSObject - - IBFrameworkSource - Foundation.framework/Headers/NSURLDownload.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebDownload.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebEditingDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebFrameLoadDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebJavaPlugIn.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebPlugin.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebPluginContainer.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebPolicyDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebResourceLoadDelegate.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebScriptObject.h - - - - NSObject - - IBFrameworkSource - WebKit.framework/Headers/WebUIDelegate.h - - - - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSInterfaceStyle.h - - - - NSResponder - NSObject - - IBFrameworkSource - AppKit.framework/Headers/NSResponder.h - - - - NSTableView - NSControl - - - - NSText - NSView - - IBFrameworkSource - AppKit.framework/Headers/NSText.h - - - - NSTextField - NSControl - - IBFrameworkSource - AppKit.framework/Headers/NSTextField.h - - - - NSTextFieldCell - NSActionCell - - IBFrameworkSource - AppKit.framework/Headers/NSTextFieldCell.h - - - - NSUserDefaultsController - NSController - - IBFrameworkSource - AppKit.framework/Headers/NSUserDefaultsController.h - - - - NSView - - IBFrameworkSource - AppKit.framework/Headers/NSClipView.h - - - - NSView - - - - NSView - - IBFrameworkSource - AppKit.framework/Headers/NSRulerView.h - - - - NSView - NSResponder - - - - NSWindow - - IBFrameworkSource - AppKit.framework/Headers/NSDrawer.h - - - - NSWindow - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSWindow.h - - - - NSWindow - - IBFrameworkSource - AppKit.framework/Headers/NSWindowScripting.h - - - - WebView - NSView - - id - id - id - id - id - id - id - id - id - id - id - - - IBFrameworkSource - WebKit.framework/Headers/WebView.h - - 0 + IBCocoaFramework + NO com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - + + com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 + YES - ../../Sparkle.xcodeproj 3 + + {12, 12} + {10, 2} + {15, 15} + diff --git a/Test Application/English.lproj/MainMenu.nib/info.nib b/Test Application/English.lproj/MainMenu.nib/info.nib deleted file mode 100644 index 09d03620..00000000 --- a/Test Application/English.lproj/MainMenu.nib/info.nib +++ /dev/null @@ -1,21 +0,0 @@ - - - - - IBFramework Version - 667 - IBLastKnownRelativeProjectPath - ../../Sparkle.xcodeproj - IBOldestOS - 5 - IBOpenObjects - - 2 - 57 - - IBSystem Version - 9D34 - targetFramework - IBCocoaFramework - - diff --git a/Test Application/English.lproj/MainMenu.nib/keyedobjects.nib b/Test Application/English.lproj/MainMenu.nib/keyedobjects.nib index bd3d4a2e..e996fb21 100644 Binary files a/Test Application/English.lproj/MainMenu.nib/keyedobjects.nib and b/Test Application/English.lproj/MainMenu.nib/keyedobjects.nib differ diff --git a/finish_installation.m b/finish_installation.m index 59c2ba1f..9dc14ad0 100644 --- a/finish_installation.m +++ b/finish_installation.m @@ -14,65 +14,73 @@ @interface TerminationListener : NSObject { - const char *hostpath; - const char *executablepath; - pid_t parentprocessid; - const char *folderpath; - NSString *selfPath; - NSString *installationPath; - NSTimer *watchdogTimer; - NSTimer *longInstallationTimer; - SUHost *host; - BOOL shouldRelaunch; - BOOL alreadyInstalled; + const char *hostpath; + const char *executablepath; + pid_t parentprocessid; + const char *folderpath; + NSString *selfPath; + NSString *installationPath; + NSTimer *watchdogTimer; + NSTimer *longInstallationTimer; + SUHost *host; + SUFinishUpdateTask finishTasks; } -- (void) parentHasQuit; +- (void)parentHasQuit; -- (void) relaunch; -- (void) install; +- (void)relaunch; +- (void)install; -- (SUHost *) host; +- (SUHost *)host; -- (void) showAppIconInDock:(NSTimer *)aTimer; -- (void) watchdog:(NSTimer *)aTimer; +- (void)showAppIconInDock:(NSTimer *)aTimer; +- (void)watchdog:(NSTimer *)aTimer; @end @implementation TerminationListener -- (id) initWithHostPath:(const char *)inhostpath executablePath:(const char *)execpath parentProcessId:(pid_t)ppid folderPath: (const char*)infolderpath shouldRelaunch:(BOOL)relaunch -selfPath: (NSString*)inSelfPath alreadyInstalled:(BOOL)inalreadyInstalled +- (id)initWithHostPath:(const char *)inhostpath + executablePath:(const char *)execpath + parentProcessId:(pid_t)ppid + folderPath:(const char*)infolderpath + finishTasksMask:(SUFinishUpdateTask)tasks + selfPath:(NSString*)inSelfPath { - if( !(self = [super init]) ) + self = [super init]; + if (nil == self) return nil; - hostpath = inhostpath; - executablepath = execpath; + + hostpath = inhostpath; + executablepath = execpath; parentprocessid = ppid; - folderpath = infolderpath; - selfPath = [inSelfPath retain]; - shouldRelaunch = relaunch; - alreadyInstalled = inalreadyInstalled; + folderpath = infolderpath; + finishTasks = tasks; + selfPath = [inSelfPath retain]; if (NULL != hostpath) { NSString *bundlePath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:hostpath length:strlen(hostpath)]; NSBundle *theBundle = [NSBundle bundleWithPath:bundlePath]; - host = [[SUHost alloc] initWithBundle: theBundle]; + host = [[SUHost alloc] initWithBundle:theBundle]; } - BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already + BOOL alreadyTerminated = (getppid() == 1); // ppid is launchd (1) => parent terminated already - if( alreadyTerminated ) + if (alreadyTerminated) + { [self parentHasQuit]; + } else + { watchdogTimer = [[NSTimer scheduledTimerWithTimeInterval:CHECK_FOR_PARENT_TO_QUIT_TIME target:self selector:@selector(watchdog:) userInfo:nil repeats:YES] retain]; + } return self; } --(void) dealloc +- (void)dealloc { [longInstallationTimer invalidate]; [longInstallationTimer release]; @@ -93,20 +101,23 @@ selfPath: (NSString*)inSelfPath alreadyInstalled:(BOOL)inalreadyInstalled } --(void) parentHasQuit +- (void)parentHasQuit { [watchdogTimer invalidate]; - longInstallationTimer = [[NSTimer scheduledTimerWithTimeInterval: LONG_INSTALLATION_TIME - target: self selector: @selector(showAppIconInDock:) - userInfo:nil repeats:NO] retain]; + longInstallationTimer = [[NSTimer scheduledTimerWithTimeInterval:LONG_INSTALLATION_TIME + target:self + selector:@selector(showAppIconInDock:) + userInfo:nil + repeats:NO] + retain]; - if( folderpath && !alreadyInstalled ) + if (folderpath && (SUFinishUpdateWithInstall & finishTasks)) [self install]; else [self relaunch]; } -- (void) watchdog:(NSTimer *)aTimer +- (void)watchdog:(NSTimer *)aTimer { ProcessSerialNumber psn; if (GetProcessForPID(parentprocessid, &psn) == procNotFound) @@ -115,89 +126,91 @@ selfPath: (NSString*)inSelfPath alreadyInstalled:(BOOL)inalreadyInstalled - (void)showAppIconInDock:(NSTimer *)aTimer; { - ProcessSerialNumber psn = { 0, kCurrentProcess }; - TransformProcessType( &psn, kProcessTransformToForegroundApplication ); + ProcessSerialNumber psn = { 0, kCurrentProcess }; + TransformProcessType(&psn, kProcessTransformToForegroundApplication); } - -- (void) relaunch +- (void)relaunch { - if (shouldRelaunch) + if (SUFinishUpdateWithRelaunch & finishTasks) { - NSString *appPath = nil; - if( !folderpath || strcmp(executablepath, hostpath) != 0 ) + NSString *appPath = nil; + if (!folderpath || strcmp(executablepath, hostpath) != 0) appPath = [[NSFileManager defaultManager] stringWithFileSystemRepresentation:executablepath length:strlen(executablepath)]; else appPath = installationPath; - [[NSWorkspace sharedWorkspace] openFile: appPath]; + [[NSWorkspace sharedWorkspace] openFile:appPath]; } if (folderpath) { NSError *theError = nil; - if( ![SUPlainInstaller _removeFileAtPath: [SUInstaller updateFolder] error: &theError] ) - SULog( @"Couldn't remove update folder: %@.", theError ); + if (![SUPlainInstaller _removeFileAtPath:[SUInstaller updateFolder] error:&theError]) + SULog(@"Couldn't remove update folder: %@.", theError); } -#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_4 - [[NSFileManager defaultManager] removeFileAtPath: selfPath handler: nil]; -#else - [[NSFileManager defaultManager] removeItemAtPath: selfPath error: NULL]; -#endif + [[NSFileManager defaultManager] removeItemAtPath:selfPath error:NULL]; exit(EXIT_SUCCESS); } -- (void) install +- (void)install { + if (0 == (SUFinishUpdateWithInstall & finishTasks)) + return; + installationPath = [[host installationPath] copy]; // Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them. - if (shouldRelaunch) { - SUStatusController* statusCtl = [[SUStatusController alloc] initWithHost: host]; // We quit anyway after we've installed, so leak this for now. - [statusCtl setButtonTitle: SULocalizedString(@"Cancel Update",@"") target: nil action: Nil isDefault: NO]; - [statusCtl beginActionWithTitle: SULocalizedString(@"Installing update...",@"") - maxProgressValue: 0 statusText: @""]; - [statusCtl showWindow: self]; + if (SUFinishUpdateWithRelaunch & finishTasks) + { + SUStatusController *statusCtl = [[SUStatusController alloc] initWithHost:host]; // We quit anyway after we've installed, so leak this for now. + [statusCtl setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:nil isDefault:NO]; + [statusCtl beginActionWithTitle:SULocalizedString(@"Installing update...", @"") + maxProgressValue:0 + statusText:@""]; + [statusCtl showWindow:self]; } - [SUInstaller installFromUpdateFolder: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: folderpath length: strlen(folderpath)] - overHost: host - installationPath: installationPath - delegate: self synchronously: NO - versionComparator: [SUStandardVersionComparator defaultComparator]]; + NSString *updateFolder =[[NSFileManager defaultManager] stringWithFileSystemRepresentation:folderpath length:strlen(folderpath)]; + [SUInstaller installFromUpdateFolder:updateFolder + overHost:host + installationPath:installationPath + delegate:self + synchronously:NO + versionComparator:[SUStandardVersionComparator defaultComparator]]; } -- (void) installerFinishedForHost:(SUHost *)aHost +- (void)installerFinishedForHost:(SUHost *)aHost { [self relaunch]; } -- (void) installerForHost:(SUHost *)host failedWithError:(NSError *)error +- (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error { // Perhaps a poor assumption but: if we're not relaunching, we assume we shouldn't be showing any UI either. Because non-relaunching installations are kicked off without any user interaction, we shouldn't be interrupting them. - if (shouldRelaunch) - NSRunAlertPanel( @"", @"%@", @"OK", @"", @"", [error localizedDescription] ); + if (SUFinishUpdateWithRelaunch & finishTasks) + NSRunAlertPanel(@"", @"%@", @"OK", @"", @"", [error localizedDescription]); exit(EXIT_FAILURE); } -- (SUHost *) host +- (SUHost *)host { return host; } @end -int main (int argc, const char * argv[]) +int main(int argc, const char * argv[]) { - if( argc < 5 || argc > 7 ) + if (argc < 6) return EXIT_FAILURE; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //ProcessSerialNumber psn = { 0, kCurrentProcess }; //TransformProcessType( &psn, kProcessTransformToForegroundApplication ); - [[NSApplication sharedApplication] activateIgnoringOtherApps: YES]; + [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; #if 0 // Cmdline tool NSString* selfPath = nil; @@ -209,19 +222,19 @@ int main (int argc, const char * argv[]) selfPath = [selfPath stringByAppendingPathComponent: [[NSFileManager defaultManager] stringWithFileSystemRepresentation: argv[0] length: strlen(argv[0])]]; } #else - NSString* selfPath = [[NSBundle mainBundle] bundlePath]; + NSString *selfPath = [[NSBundle mainBundle] bundlePath]; #endif [NSApplication sharedApplication]; NSConnection *connection = [[[NSConnection alloc] init] autorelease]; - TerminationListener *listener = [[[TerminationListener alloc] initWithHostPath: (argc > 1) ? argv[1] : NULL - executablePath: (argc > 2) ? argv[2] : NULL - parentProcessId: (argc > 3) ? atoi(argv[3]) : 0 - folderPath: (argc > 4) ? argv[4] : NULL - shouldRelaunch: (argc > 5) ? atoi(argv[5]) : 1 - selfPath: selfPath - alreadyInstalled: (argc > 6) ? atoi(argv[6]) : 0] autorelease]; + TerminationListener *listener = [[[TerminationListener alloc] initWithHostPath:argv[1] + executablePath:argv[2] + parentProcessId:atoi(argv[3]) + folderPath:argv[4] + finishTasksMask:atoi(argv[5]) + selfPath:selfPath] + autorelease]; [connection setRootObject:listener]; if (![connection registerName:[NSString stringWithFormat:@"Sparkle %@", [[[listener host] bundle] bundleIdentifier]]])