mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Take out lot of unnecessary installation code now
This commit is contained in:
1 parent
626e506cae
commit
bd352c7db5
5 files changed
+24
-99
No files matched your search
@@ -441,7 +441,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
}
|
||||
|
||||
NSError *firstStageError = nil;
|
||||
if (![installer performFirstStage:&firstStageError]) {
|
||||
if (![installer performInitialInstallation:&firstStageError]) {
|
||||
SULog(@"Error: Failed to start installer with error: %@", firstStageError);
|
||||
[self.installer cleanup];
|
||||
self.installer = nil;
|
||||
@@ -480,9 +480,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
return;
|
||||
}
|
||||
|
||||
NSError *secondStageError = nil;
|
||||
BOOL performedSecondStage = [self.installer performSecondStageAllowingUI:self.shouldShowUI error:&secondStageError];
|
||||
|
||||
BOOL performedSecondStage = self.shouldShowUI || [self.installer canInstallSilently];
|
||||
if (performedSecondStage) {
|
||||
self.performedStage2Installation = YES;
|
||||
|
||||
@@ -493,7 +491,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
[self.communicator handleMessageWithIdentifier:SUInstallationFinishedStage2 data:sendData];
|
||||
});
|
||||
} else {
|
||||
SULog(@"Error: Failed to resume installer on stage 2 with error: %@", secondStageError);
|
||||
SULog(@"Error: Failed to resume installer on stage 2 because installation cannot be installed silently");
|
||||
[self.installer cleanup];
|
||||
self.installer = nil;
|
||||
|
||||
@@ -518,9 +516,10 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
self.receivedUpdaterPong = NO;
|
||||
[self.communicator handleMessageWithIdentifier:SUUpdaterAlivePing data:[NSData data]];
|
||||
|
||||
// Launch our installer progress UI tool if only after a certain amount of time passes
|
||||
// Launch our installer progress UI tool if only after a certain amount of time passes,
|
||||
// and if our installer is silent (i.e, doesn't show progress on its own)
|
||||
__block BOOL shouldLaunchInstallerProgress = YES;
|
||||
if (self.shouldShowUI && ![self.installer displaysUserProgress]) {
|
||||
if (self.shouldShowUI && [self.installer canInstallSilently]) {
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUDisplayProgressTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
// Make sure we're still eligible for showing the installer progress
|
||||
// Also if the updater process is still alive, showing the progress should not be our duty
|
||||
@@ -541,7 +540,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
}
|
||||
|
||||
NSError *thirdStageError = nil;
|
||||
if (![self.installer performThirdStage:&thirdStageError]) {
|
||||
if (![self.installer performFinalInstallation:&thirdStageError]) {
|
||||
SULog(@"Failed to finalize installation with error: %@", thirdStageError);
|
||||
|
||||
[self.installer cleanup];
|
||||
|
||||
@@ -7,10 +7,7 @@
|
||||
//
|
||||
|
||||
#import <sys/stat.h>
|
||||
#import <Security/Security.h>
|
||||
#import "SUParameterAssert.h"
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
#import "SUFileManager.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
@@ -20,14 +17,12 @@
|
||||
@interface SUGuidedPackageInstaller ()
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *packagePath;
|
||||
@property (nonatomic) SUFileManager *fileManager;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUGuidedPackageInstaller
|
||||
|
||||
@synthesize packagePath = _packagePath;
|
||||
@synthesize fileManager = _fileManager;
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath
|
||||
{
|
||||
@@ -38,27 +33,12 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)performFirstStage:(NSError * __autoreleasing *)__unused error
|
||||
- (BOOL)performInitialInstallation:(NSError * __autoreleasing *)__unused error
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performSecondStageAllowingUI:(BOOL)allowsUI error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
if (!allowsUI && ![self canInstallSilently]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{NSLocalizedDescriptionKey : @"Guided installer cannot continue if showing UI is not allowed"}];
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
|
||||
// If we're root, we can allow using the authorization APIs
|
||||
self.fileManager = [SUFileManager defaultManager];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performThirdStage:(NSError * __autoreleasing *)error
|
||||
- (BOOL)performFinalInstallation:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// This command *must* be run as root
|
||||
NSString *installerPath = @"/usr/sbin/installer";
|
||||
@@ -88,19 +68,9 @@
|
||||
return success;
|
||||
}
|
||||
|
||||
- (BOOL)displaysUserProgress
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)isRootUser
|
||||
{
|
||||
return (geteuid() == 0);
|
||||
}
|
||||
|
||||
- (BOOL)canInstallSilently
|
||||
{
|
||||
return [self isRootUser];
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)cleanup
|
||||
|
||||
@@ -12,36 +12,22 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUInstallerProtocol <NSObject>
|
||||
|
||||
// Stage 1 is where any installation work can be done prior to user application being terminated and relaunched
|
||||
// No UI should occur during this stage (i.e, do not prompt for authorization prompts, show package installer apps, etc..)
|
||||
// Any installation work can be done prior to user application being terminated and relaunched
|
||||
// No UI should occur during this stage (i.e, do not show package installer apps, etc..)
|
||||
// Should be able to be called from non-main thread
|
||||
- (BOOL)performFirstStage:(NSError **)error;
|
||||
- (BOOL)performInitialInstallation:(NSError **)error;
|
||||
|
||||
// Stage 2 is where any further installation work can be done prior to the user application being terminated
|
||||
// If the authorizationEnvironment flag is nil, then this and the 3rd stage cannot request authorization if the updater has insufficient privileges to install
|
||||
// Otherwise if it's non-nil, then they can request authorization and they will use the environment that's passed.
|
||||
// The allowsUI flag indicates whether this and the 3rd stage can show UI or not, possibly affecting whether or not this stage succeeds.
|
||||
// Eg: This may be appropriate for first showing an authorization prompt before the user application is terminated (if the operation succeeds)
|
||||
// Any installation work after the user application has has been terminated. This is where the final installation work can be done.
|
||||
// After this stage is done, the user application may be relaunched.
|
||||
// Should be able to be called from non-main thread
|
||||
- (BOOL)performSecondStageAllowingUI:(BOOL)allowsUI error:(NSError **)error;
|
||||
|
||||
// Stage 3 occurs after the user application has has been terminated. This is where the final installation work can be done.
|
||||
// After this stage is done, the user application will be relaunched.
|
||||
// Should be able to be called from non-main thread
|
||||
- (BOOL)performThirdStage:(NSError **)error;
|
||||
|
||||
// Indicates whether or not this installer will show the user visible installation progress
|
||||
// Should be thread safe
|
||||
- (BOOL)displaysUserProgress;
|
||||
- (BOOL)performFinalInstallation:(NSError **)error;
|
||||
|
||||
// Indicates whether or not this installer can install the update silently in the background, without hindering the user
|
||||
// This should be considered after stage 1 and before stage 2 of the installation.
|
||||
// If this returns NO, then the second stage of the installation should fail if it is not allowed to show UI.
|
||||
// If this returns NO, then the installation can fail if the user did not directly request for the install to occur.
|
||||
// Should be thread safe
|
||||
- (BOOL)canInstallSilently;
|
||||
|
||||
// Cleans up work done from any of the previous stages. This should be invoked after stage 3 succeeds,
|
||||
// or after any one of the stages fails.
|
||||
// Cleans up work done from the initial or final installation (depending on how far installation gets)
|
||||
// Should be able to be called from non-main thread
|
||||
- (void)cleanup;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
return self;
|
||||
}
|
||||
|
||||
- (BOOL)performFirstStage:(NSError * __autoreleasing *)error
|
||||
- (BOOL)performInitialInstallation:(NSError * __autoreleasing *)error
|
||||
{
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:SUOpenUtilityPath]) {
|
||||
if (error != NULL) {
|
||||
@@ -47,17 +47,7 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performSecondStageAllowingUI:(BOOL)allowsUI error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
if (!allowsUI) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: @"Package installer cannot continue if showing UI is not allowed." }];
|
||||
}
|
||||
}
|
||||
return allowsUI;
|
||||
}
|
||||
|
||||
- (BOOL)performThirdStage:(NSError * __autoreleasing *)error
|
||||
- (BOOL)performFinalInstallation:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// Run installer using the "open" command to ensure it is launched in front of current application.
|
||||
// -W = wait until the app has quit.
|
||||
@@ -81,11 +71,6 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)displaysUserProgress
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)canInstallSilently
|
||||
{
|
||||
return NO;
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
@property (nonatomic, copy, readonly) NSString *installationPath;
|
||||
|
||||
// Properties that carry over from starting installation to resuming to cleaning up
|
||||
@property (nonatomic) SUFileManager *fileManager;
|
||||
@property (nonatomic) NSURL *tempOldDirectoryURL;
|
||||
@property (nonatomic) NSURL *tempNewDirectoryURL;
|
||||
|
||||
@@ -39,7 +38,6 @@
|
||||
@synthesize comparator = _comparator;
|
||||
@synthesize applicationPath = _applicationPath;
|
||||
@synthesize installationPath = _installationPath;
|
||||
@synthesize fileManager = _fileManager;
|
||||
@synthesize tempOldDirectoryURL = _tempOldDirectoryURL;
|
||||
@synthesize tempNewDirectoryURL = _tempNewDirectoryURL;
|
||||
|
||||
@@ -82,7 +80,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
SUFileManager *fileManager = self.fileManager;
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
|
||||
// Update the access time of our entire application before moving it into a temporary directory
|
||||
// The system periodically cleans up files by looking at the mod & access times, so we have to make sure they're up to date
|
||||
@@ -185,14 +183,13 @@
|
||||
}
|
||||
|
||||
// To carry over when we clean up the installation
|
||||
self.fileManager = fileManager;
|
||||
self.tempNewDirectoryURL = tempNewDirectoryURL;
|
||||
self.tempOldDirectoryURL = tempOldDirectoryURL;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performFirstStage:(NSError * __autoreleasing *)error
|
||||
- (BOOL)performInitialInstallation:(NSError * __autoreleasing *)error
|
||||
{
|
||||
BOOL allowDowngrades = SPARKLE_AUTOMATED_DOWNGRADES;
|
||||
|
||||
@@ -215,25 +212,13 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performSecondStageAllowingUI:(BOOL)allowsUI error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
self.fileManager = [SUFileManager defaultManager];
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)performThirdStage:(NSError * __autoreleasing *)error
|
||||
- (BOOL)performFinalInstallation:(NSError * __autoreleasing *)error
|
||||
{
|
||||
// Note: we must do most installation work in the third stage due to relying on our application sitting in temporary directories.
|
||||
// It must not be possible for our update to sit in temporary directories for a very long time.
|
||||
return [self startInstallationToURL:[NSURL fileURLWithPath:self.installationPath] fromUpdateAtURL:[NSURL fileURLWithPath:self.applicationPath] withHost:self.host error:error];
|
||||
}
|
||||
|
||||
- (BOOL)displaysUserProgress
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)canInstallSilently
|
||||
{
|
||||
return YES;
|
||||
@@ -241,7 +226,7 @@
|
||||
|
||||
- (void)cleanup
|
||||
{
|
||||
SUFileManager *fileManager = self.fileManager;
|
||||
SUFileManager *fileManager = [SUFileManager defaultManager];
|
||||
NSURL *tempOldDirectoryURL = self.tempOldDirectoryURL;
|
||||
NSURL *tempNewDirectoryURL = self.tempNewDirectoryURL;
|
||||
|
||||
|
||||
Reference in new issue
Block a user