Implemented updaters queue.

This commit is contained in:
Dmytro Tretiakov committed 2014-08-07 16:03:02 +03:00
1 parent 1c09a01ef9
commit 48ab89338b
26 files changed
+956 -1083

No files matched your search

+1 -1
View File
@@ -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
+3 -4
View File
@@ -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
+19
View File
@@ -0,0 +1,19 @@
//
// SUAppDelegate.h
// Sparkle
//
// Created by Dmytro Tretiakov on 8/1/14.
//
//
#import <Foundation/Foundation.h>
@class SUUpdater;
@class SUUpdaterQueue;
@interface SUAppDelegate : NSObject
@property (nonatomic, retain) IBOutlet SUUpdater *updater;
@property (nonatomic, retain) SUUpdaterQueue *updaterQueue;
@end
+27
View File
@@ -0,0 +1,27 @@
//
// SUAppDelegate.m
// Sparkle
//
// Created by Dmytro Tretiakov on 8/1/14.
//
//
#import "SUAppDelegate.h"
#import <Sparkle/Sparkle.h>
@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
+8 -8
View File
@@ -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
+1 -3
View File
@@ -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
+64 -29
View File
@@ -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
+22
View File
@@ -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::
// -----------------------------------------------------------------------------
+2 -2
View File
@@ -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
+7 -2
View File
@@ -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
+20 -7
View File
@@ -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];
+5 -3
View File
@@ -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
+17 -3
View File
@@ -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
{
+5 -4
View File
@@ -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
+46 -14
View File
@@ -7,6 +7,7 @@
//
#import "SUUpdater.h"
#import "SUUpdater_Private.h"
#import "SUHost.h"
#import "SUUpdatePermissionPrompt.h"
@@ -21,7 +22,8 @@
#include <SystemConfiguration/SystemConfiguration.h>
@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
+21
View File
@@ -0,0 +1,21 @@
//
// SUUpdaterQueue.h
// Sparkle
//
// Created by Dmytro Tretiakov on 7/31/14.
//
//
#import <Foundation/Foundation.h>
@class SUUpdater;
@interface SUUpdaterQueue : NSObject
- (void)addUpdater:(SUUpdater *)updater;
- (void)removeUpdater:(SUUpdater *)updater;
- (void)checkForUpdates;
- (void)checkForUpdatesInBackground;
@end
+393
View File
@@ -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
+10
View File
@@ -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
+4 -4
View File
@@ -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];
+1
View File
@@ -13,6 +13,7 @@
// there are name-space collisions) so we can list all of them to start with:
#import <Sparkle/SUUpdater.h>
#import <Sparkle/SUUpdaterQueue.h>
#import <Sparkle/SUAppcast.h>
#import <Sparkle/SUAppcastItem.h>
+15 -1
View File
@@ -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 = "<absolute>"; };
3329F06D18FBFBA800556010 /* ResourceRules.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = ResourceRules.plist; sourceTree = "<group>"; };
33307690190A5D8B005602B2 /* install_service.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = install_service.pch; sourceTree = "<group>"; };
33C07AAB198B887F0039242D /* SUAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUAppDelegate.h; sourceTree = "<group>"; };
33C07AAC198B887F0039242D /* SUAppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUAppDelegate.m; sourceTree = "<group>"; };
33C3934A198A825600C29D9D /* SUUpdaterQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdaterQueue.h; sourceTree = "<group>"; };
33C3934B198A825600C29D9D /* SUUpdaterQueue.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterQueue.m; sourceTree = "<group>"; };
33CE69761934D1F8009D5956 /* ReleaseNotes.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = ReleaseNotes.rtf; sourceTree = "<group>"; };
33D081821888446E00394A94 /* libDMCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libDMCore.a; path = External/libDMCore.a; sourceTree = "<group>"; };
3772FEA813DE0B6B00F79537 /* SUVersionDisplayProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUVersionDisplayProtocol.h; sourceTree = "<group>"; };
@@ -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 = "<group>";
@@ -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 */,
-43
View File
@@ -1,43 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBClasses</key>
<array>
<dict>
<key>CLASS</key>
<string>FirstResponder</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
<dict>
<key>CLASS</key>
<string>NSObject</string>
<key>LANGUAGE</key>
<string>ObjC</string>
</dict>
<dict>
<key>ACTIONS</key>
<dict>
<key>checkForUpdates</key>
<string>id</string>
</dict>
<key>CLASS</key>
<string>SUUpdater</string>
<key>LANGUAGE</key>
<string>ObjC</string>
<key>OUTLETS</key>
<dict>
<key>delegate</key>
<string>id</string>
</dict>
<key>SUPERCLASS</key>
<string>NSObject</string>
</dict>
</array>
<key>IBVersion</key>
<string>1</string>
</dict>
</plist>
File diff suppressed because it is too large. Load diff
-21
View File
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBFramework Version</key>
<string>667</string>
<key>IBLastKnownRelativeProjectPath</key>
<string>../../Sparkle.xcodeproj</string>
<key>IBOldestOS</key>
<integer>5</integer>
<key>IBOpenObjects</key>
<array>
<integer>2</integer>
<integer>57</integer>
</array>
<key>IBSystem Version</key>
<string>9D34</string>
<key>targetFramework</key>
<string>IBCocoaFramework</string>
</dict>
</plist>
Binary file not shown.
+92 -79
View File
@@ -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]]])