diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index 0a022924..942caf53 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -498,9 +498,14 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; if (performedSecondStage) { self.performedStage2Installation = YES; - } - - void (^cleanupAndExit)(void) = ^{ + + dispatch_async(dispatch_get_main_queue(), ^{ + uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated; + + NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)]; + [self.communicator handleMessageWithIdentifier:SUInstallationFinishedStage2 data:sendData]; + }); + } else { SULog(@"Error: Failed to resume installer on stage 2 with error: %@", secondStageError); [self.installer cleanup]; self.installer = nil; @@ -508,28 +513,6 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; dispatch_async(dispatch_get_main_queue(), ^{ [self cleanupAndExitWithStatus:EXIT_FAILURE]; }); - }; - - // Let the other end know we canceled so they can fail gracefully without disturbing the user - BOOL installationCanceled = (!performedSecondStage && secondStageError.code == SUInstallationCanceledError); - if (performedSecondStage || installationCanceled) { - dispatch_async(dispatch_get_main_queue(), ^{ - uint8_t canceled = (uint8_t)installationCanceled; - uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated; - - uint8_t sendInfo[] = {canceled, targetTerminated}; - - NSData *sendData = [NSData dataWithBytes:sendInfo length:sizeof(sendInfo)]; - [self.communicator handleMessageWithIdentifier:SUInstallationFinishedStage2 data:sendData]; - - if (installationCanceled) { - cleanupAndExit(); - } - }); - } - - if (!performedSecondStage && !installationCanceled) { - cleanupAndExit(); } } diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 24396279..8a285fc8 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -263,30 +263,21 @@ } else if (identifier == SUInstallationFinishedStage2) { self.currentStage = identifier; - BOOL canceledInstallation = NO; - if (data.length >= sizeof(uint8_t)) { - canceledInstallation = (*(const uint8_t *)data.bytes == 0x1); + if (!self.startedInstalling) { + // It's possible we can start from resuming to stage 2 rather than doing stage 1 again, so we should notify to start installing if we haven't done so already + self.startedInstalling = YES; + [self.delegate installerDidStartInstalling]; } - if (canceledInstallation) { - [self.delegate installerIsRequestingAbortInstallWithError:nil]; - } else { - if (!self.startedInstalling) { - // It's possible we can start from resuming to stage 2 rather than doing stage 1 again, so we should notify to start installing if we haven't done so already - self.startedInstalling = YES; - [self.delegate installerDidStartInstalling]; - } - - BOOL hasTargetTerminated = NO; - if (data.length >= sizeof(uint8_t) * 2) { - hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes + 1); - } - - [self.delegate installerWillFinishInstallationAndRelaunch:self.willRelaunch]; - - if (!hasTargetTerminated) { - [self.delegate installerIsRequestingAppTermination]; - } + BOOL hasTargetTerminated = NO; + if (data.length >= sizeof(uint8_t)) { + hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes); + } + + [self.delegate installerWillFinishInstallationAndRelaunch:self.willRelaunch]; + + if (!hasTargetTerminated) { + [self.delegate installerIsRequestingAppTermination]; } } else if (identifier == SUInstallationFinishedStage3) { self.currentStage = identifier;