mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Don't handle out of order messages
This commit is contained in:
1 parent
64c17df1e6
commit
e7fdfb9dc9
4 files changed
+65
-7
No files matched your search
Vendored
+7
-1
@@ -47,6 +47,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
@property (nonatomic) BOOL willCompleteInstallation;
|
||||
|
||||
@property (nonatomic) dispatch_queue_t installerQueue;
|
||||
@property (nonatomic) BOOL performedStage1Installation;
|
||||
@property (nonatomic) BOOL performedStage2Installation;
|
||||
@property (nonatomic) BOOL handledResumeInstallationToStage2;
|
||||
|
||||
@@ -69,6 +70,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
@synthesize installer = _installer;
|
||||
@synthesize willCompleteInstallation = _willCompleteInstallation;
|
||||
@synthesize installerQueue = _installerQueue;
|
||||
@synthesize performedStage1Installation = _performedStage1Installation;
|
||||
@synthesize performedStage2Installation = _performedStage2Installation;
|
||||
@synthesize handledResumeInstallationToStage2 = _handledResumeInstallationToStage2;
|
||||
|
||||
@@ -336,6 +338,10 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
}
|
||||
}];
|
||||
|
||||
self.performedStage1Installation = YES;
|
||||
|
||||
// Stage 2 can still be run before we finish installation
|
||||
// if the updater requests for it before the app is terminated
|
||||
[self finishInstallationAfterHostTermination];
|
||||
});
|
||||
});
|
||||
@@ -343,7 +349,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5;
|
||||
|
||||
- (void)performStage2InstallationIfNeeded
|
||||
{
|
||||
if (self.performedStage2Installation) {
|
||||
if (!self.performedStage1Installation || self.performedStage2Installation) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Vendored
+8
-3
@@ -10,21 +10,26 @@
|
||||
|
||||
@class SUHost;
|
||||
|
||||
// Order matters; higher stages have higher values.
|
||||
typedef NS_ENUM(int32_t, SUInstallerMessageType)
|
||||
{
|
||||
SUInstallerNotStarted = 0,
|
||||
SUExtractedArchiveWithProgress = 1,
|
||||
SUArchiveExtractionFailed = 2,
|
||||
SUValidationStarted = 3,
|
||||
SUInstallationStartedStage1 = 5,
|
||||
SUInstallationFinishedStage1 = 6,
|
||||
SUInstallationFinishedStage2 = 7
|
||||
SUInstallationStartedStage1 = 4,
|
||||
SUInstallationFinishedStage1 = 5,
|
||||
SUInstallationFinishedStage2 = 6
|
||||
};
|
||||
|
||||
// Order matters; higher stages have higher values
|
||||
typedef NS_ENUM(int32_t, SUUpdaterMessageType)
|
||||
{
|
||||
SUResumeInstallationToStage2 = 1
|
||||
};
|
||||
|
||||
BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInstallerMessageType newMessageType);
|
||||
|
||||
NSString *SUUpdateDriverServiceNameForHost(SUHost *host);
|
||||
|
||||
NSString *SUAutoUpdateServiceNameForHost(SUHost *host);
|
||||
Vendored
+27
@@ -9,6 +9,33 @@
|
||||
#import "SUMessageTypes.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
BOOL SUInstallerMessageTypeIsLegal(SUInstallerMessageType oldMessageType, SUInstallerMessageType newMessageType)
|
||||
{
|
||||
BOOL legal;
|
||||
switch (newMessageType) {
|
||||
case SUInstallerNotStarted:
|
||||
legal = (oldMessageType == SUInstallerNotStarted);
|
||||
break;
|
||||
case SUExtractedArchiveWithProgress:
|
||||
case SUArchiveExtractionFailed:
|
||||
legal = (oldMessageType == SUInstallerNotStarted || oldMessageType == SUExtractedArchiveWithProgress);
|
||||
break;
|
||||
case SUValidationStarted:
|
||||
legal = (oldMessageType == SUInstallerNotStarted || oldMessageType == SUExtractedArchiveWithProgress);
|
||||
break;
|
||||
case SUInstallationStartedStage1:
|
||||
legal = (oldMessageType == SUValidationStarted);
|
||||
break;
|
||||
case SUInstallationFinishedStage1:
|
||||
legal = (oldMessageType == SUInstallationStartedStage1);
|
||||
break;
|
||||
case SUInstallationFinishedStage2:
|
||||
legal = (oldMessageType == SUInstallationFinishedStage1);
|
||||
break;
|
||||
}
|
||||
return legal;
|
||||
}
|
||||
|
||||
NSString *SUUpdateDriverServiceNameForHost(SUHost *host)
|
||||
{
|
||||
return [NSString stringWithFormat:@"%@-sparkle-updater", host.bundle.bundleIdentifier];
|
||||
|
||||
Vendored
+23
-3
@@ -42,6 +42,8 @@
|
||||
@property (nonatomic) SULocalMessagePort *localPort;
|
||||
@property (nonatomic) SURemoteMessagePort *remotePort;
|
||||
|
||||
@property (nonatomic) SUInstallerMessageType currentStage;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUBasicUpdateDriver
|
||||
@@ -57,6 +59,7 @@
|
||||
|
||||
@synthesize localPort = _localPort;
|
||||
@synthesize remotePort = _remotePort;
|
||||
@synthesize currentStage = _currentStage;
|
||||
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)URL
|
||||
{
|
||||
@@ -312,20 +315,33 @@
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
if (!SUInstallerMessageTypeIsLegal(self.currentStage, identifier)) {
|
||||
SULog(@"Error: received out of order message with current stage: %d, requested stage: %d", self.currentStage, identifier);
|
||||
return;
|
||||
}
|
||||
|
||||
if (identifier == SUExtractedArchiveWithProgress) {
|
||||
if (data.length == sizeof(double)) {
|
||||
double progress = *(const double *)data.bytes;
|
||||
[self unarchiverExtractedProgress:progress];
|
||||
self.currentStage = identifier;
|
||||
}
|
||||
} else if (identifier == SUInstallationStartedStage1) {
|
||||
[self installerDidStart];
|
||||
} else if (identifier == SUArchiveExtractionFailed) {
|
||||
if ([self.updateItem isDeltaUpdate]) {
|
||||
[self failedToApplyDeltaUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
// Don't have to store current stage because we're going to abort
|
||||
|
||||
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) }]];
|
||||
|
||||
} else if (identifier == SUValidationStarted) {
|
||||
self.currentStage = identifier;
|
||||
} else if (identifier == SUInstallationStartedStage1) {
|
||||
self.currentStage = identifier;
|
||||
[self installerDidStart];
|
||||
|
||||
} else if (identifier == SUInstallationFinishedStage1) {
|
||||
self.remotePort = [[SURemoteMessagePort alloc] initWithServiceName:SUAutoUpdateServiceNameForHost(self.host) invalidationCallback:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@@ -340,9 +356,12 @@
|
||||
#warning put in a custom error
|
||||
[self abortUpdate];
|
||||
} else {
|
||||
self.currentStage = identifier;
|
||||
[self installerIsReadyForRelaunch];
|
||||
}
|
||||
} else if (identifier == SUInstallationFinishedStage2) {
|
||||
// Don't have to store current stage because we're severing our connection to the installer
|
||||
|
||||
[self.remotePort invalidate];
|
||||
self.remotePort = nil;
|
||||
|
||||
@@ -541,12 +560,13 @@
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
#warning should we try to really tell the installer to abort? If so, I need to handle this
|
||||
if (![self mayUpdateAndRestart])
|
||||
{
|
||||
[self abortUpdate];
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Give the host app an opportunity to postpone the install and relaunch.
|
||||
if (!self.postponedOnce && [self.updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)])
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user