mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-22 04:30:47 +00:00
Reduce code size and make codebase more consistent (#2305)
This commit is contained in:
203 files changed
+4058
-3474
No files matched your search
@@ -19,7 +19,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SPUInstallerAgentProtocol;
|
||||
|
||||
@interface AgentConnection : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface AgentConnection : NSObject
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier delegate:(id<AgentConnectionDelegate>)delegate;
|
||||
|
||||
|
||||
@@ -16,20 +16,16 @@
|
||||
|
||||
@interface AgentConnection () <NSXPCListenerDelegate, SUInstallerAgentInitiationProtocol>
|
||||
|
||||
@property (nonatomic) NSXPCListener *xpcListener;
|
||||
@property (nonatomic, nullable) NSXPCConnection *activeConnection;
|
||||
@property (nonatomic, nullable) id<SPUInstallerAgentProtocol> agent;
|
||||
@property (nonatomic, weak) id<AgentConnectionDelegate> delegate;
|
||||
@property (nonatomic) BOOL connected;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AgentConnection
|
||||
{
|
||||
NSXPCListener *_xpcListener;
|
||||
NSXPCConnection *_activeConnection;
|
||||
__weak id<AgentConnectionDelegate> _delegate;
|
||||
}
|
||||
|
||||
@synthesize xpcListener = _xpcListener;
|
||||
@synthesize activeConnection = _activeConnection;
|
||||
@synthesize agent = _agent;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize connected = _connected;
|
||||
@synthesize invalidationError = _invalidationError;
|
||||
|
||||
@@ -48,23 +44,23 @@
|
||||
|
||||
- (void)startListener
|
||||
{
|
||||
[self.xpcListener resume];
|
||||
[_xpcListener resume];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
self.delegate = nil;
|
||||
_delegate = nil;
|
||||
|
||||
[self.activeConnection invalidate];
|
||||
self.activeConnection = nil;
|
||||
[_activeConnection invalidate];
|
||||
_activeConnection = nil;
|
||||
|
||||
[self.xpcListener invalidate];
|
||||
self.xpcListener = nil;
|
||||
[_xpcListener invalidate];
|
||||
_xpcListener = nil;
|
||||
}
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
if (self.activeConnection != nil) {
|
||||
if (_activeConnection != nil) {
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
@@ -74,24 +70,30 @@
|
||||
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUInstallerAgentProtocol)];
|
||||
|
||||
self.activeConnection = newConnection;
|
||||
_activeConnection = newConnection;
|
||||
|
||||
__weak AgentConnection *weakSelf = self;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
newConnection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.activeConnection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_activeConnection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
newConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.delegate agentConnectionDidInvalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_delegate agentConnectionDidInvalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[newConnection resume];
|
||||
|
||||
self.agent = newConnection.remoteObjectProxy;
|
||||
_agent = newConnection.remoteObjectProxy;
|
||||
|
||||
return YES;
|
||||
}
|
||||
@@ -99,10 +101,10 @@
|
||||
- (void)connectionDidInitiateWithReply:(void (^)(void))acknowledgement
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.connected = YES;
|
||||
self->_connected = YES;
|
||||
|
||||
[self.delegate agentConnectionDidInitiate];
|
||||
self.delegate = nil;
|
||||
[self->_delegate agentConnectionDidInitiate];
|
||||
self->_delegate = nil;
|
||||
});
|
||||
|
||||
acknowledgement();
|
||||
@@ -111,7 +113,7 @@
|
||||
- (void)connectionWillInvalidateWithError:(NSError *)error
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.invalidationError = error;
|
||||
self->_invalidationError = error;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface AppInstaller : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface AppInstaller : NSObject
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName;
|
||||
|
||||
|
||||
+151
-173
@@ -43,73 +43,48 @@
|
||||
static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
@interface AppInstaller () <NSXPCListenerDelegate, SUInstallerCommunicationProtocol, AgentConnectionDelegate>
|
||||
|
||||
@property (nonatomic) NSXPCListener* xpcListener;
|
||||
@property (nonatomic) NSXPCConnection *activeConnection;
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> communicator;
|
||||
@property (nonatomic) AgentConnection *agentConnection;
|
||||
@property (nonatomic) BOOL receivedUpdaterPong;
|
||||
|
||||
@property (nonatomic, strong) TerminationListener *terminationListener;
|
||||
|
||||
@property (nonatomic) SUUpdateValidator *updateValidator;
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *hostBundleIdentifier;
|
||||
@property (nonatomic, readonly) NSString *homeDirectory;
|
||||
@property (nonatomic, readonly) NSString *userName;
|
||||
@property (nonatomic) SUHost *host;
|
||||
@property (nonatomic, copy) NSString *updateDirectoryPath;
|
||||
@property (nonatomic, copy) NSString *downloadName;
|
||||
@property (nonatomic, copy) NSString *decryptionPassword;
|
||||
@property (nonatomic, strong) SUSignatures *signatures;
|
||||
@property (nonatomic, copy) NSString *relaunchPath;
|
||||
@property (nonatomic, copy) NSString *installationType;
|
||||
@property (nonatomic, assign) BOOL shouldRelaunch;
|
||||
@property (nonatomic, assign) BOOL shouldShowUI;
|
||||
|
||||
@property (nonatomic) id<SUInstallerProtocol> installer;
|
||||
@property (nonatomic) BOOL willCompleteInstallation;
|
||||
@property (nonatomic) BOOL receivedInstallationData;
|
||||
@property (nonatomic) BOOL finishedValidation;
|
||||
@property (nonatomic) BOOL agentInitiatedConnection;
|
||||
|
||||
@property (nonatomic) dispatch_queue_t installerQueue;
|
||||
@property (nonatomic) BOOL performedStage1Installation;
|
||||
@property (nonatomic) BOOL performedStage2Installation;
|
||||
@property (nonatomic) BOOL performedStage3Installation;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AppInstaller
|
||||
{
|
||||
NSXPCListener* _xpcListener;
|
||||
NSXPCConnection *_activeConnection;
|
||||
id<SUInstallerCommunicationProtocol> _communicator;
|
||||
AgentConnection *_agentConnection;
|
||||
|
||||
@synthesize xpcListener = _xpcListener;
|
||||
@synthesize activeConnection = _activeConnection;
|
||||
@synthesize communicator = _communicator;
|
||||
@synthesize agentConnection = _agentConnection;
|
||||
@synthesize receivedUpdaterPong = _receivedUpdaterPong;
|
||||
@synthesize hostBundleIdentifier = _hostBundleIdentifier;
|
||||
@synthesize homeDirectory = _homeDirectory;
|
||||
@synthesize userName = _userName;
|
||||
@synthesize terminationListener = _terminationListener;
|
||||
@synthesize updateValidator = _updateValidator;
|
||||
@synthesize host = _host;
|
||||
@synthesize updateDirectoryPath = _updateDirectoryPath;
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize decryptionPassword = _decryptionPassword;
|
||||
@synthesize signatures = _signatures;
|
||||
@synthesize relaunchPath = _relaunchPath;
|
||||
@synthesize installationType = _installationType;
|
||||
@synthesize shouldRelaunch = _shouldRelaunch;
|
||||
@synthesize shouldShowUI = _shouldShowUI;
|
||||
@synthesize installer = _installer;
|
||||
@synthesize willCompleteInstallation = _willCompleteInstallation;
|
||||
@synthesize receivedInstallationData = _receivedInstallationData;
|
||||
@synthesize installerQueue = _installerQueue;
|
||||
@synthesize performedStage1Installation = _performedStage1Installation;
|
||||
@synthesize performedStage2Installation = _performedStage2Installation;
|
||||
@synthesize performedStage3Installation = _performedStage3Installation;
|
||||
@synthesize finishedValidation = _finishedValidation;
|
||||
@synthesize agentInitiatedConnection = _agentInitiatedConnection;
|
||||
TerminationListener *_terminationListener;
|
||||
|
||||
SUUpdateValidator *_updateValidator;
|
||||
|
||||
NSString *_hostBundleIdentifier;
|
||||
NSString *_homeDirectory;
|
||||
NSString *_userName;
|
||||
SUHost *_host;
|
||||
NSString *_updateDirectoryPath;
|
||||
NSString *_downloadName;
|
||||
NSString *_decryptionPassword;
|
||||
SUSignatures *_signatures;
|
||||
NSString *_relaunchPath;
|
||||
NSString *_installationType;
|
||||
|
||||
id<SUInstallerProtocol> _installer;
|
||||
|
||||
dispatch_queue_t _installerQueue;
|
||||
|
||||
BOOL _shouldRelaunch;
|
||||
BOOL _shouldShowUI;
|
||||
|
||||
BOOL _receivedUpdaterPong;
|
||||
|
||||
BOOL _willCompleteInstallation;
|
||||
BOOL _receivedInstallationData;
|
||||
BOOL _finishedValidation;
|
||||
BOOL _agentInitiatedConnection;
|
||||
|
||||
BOOL _performedStage1Installation;
|
||||
BOOL _performedStage2Installation;
|
||||
BOOL _performedStage3Installation;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)hostBundleIdentifier homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName
|
||||
{
|
||||
@@ -132,68 +107,71 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
- (BOOL)listener:(NSXPCListener *)__unused listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection
|
||||
{
|
||||
if (self.activeConnection != nil) {
|
||||
if (_activeConnection != nil) {
|
||||
SULog(SULogLevelDefault, @"Rejecting multiple connections...");
|
||||
[newConnection invalidate];
|
||||
return NO;
|
||||
}
|
||||
|
||||
self.activeConnection = newConnection;
|
||||
_activeConnection = newConnection;
|
||||
|
||||
newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
newConnection.exportedObject = self;
|
||||
|
||||
newConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
__weak AppInstaller *weakSelf = self;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
newConnection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.activeConnection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_activeConnection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
newConnection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
AppInstaller *strongSelf = weakSelf;
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
if (strongSelf.activeConnection != nil && !strongSelf.willCompleteInstallation) {
|
||||
if (strongSelf->_activeConnection != nil && !strongSelf->_willCompleteInstallation) {
|
||||
[strongSelf cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Invalidation on remote port being called, and installation is not close enough to completion!" }]];
|
||||
}
|
||||
strongSelf.communicator = nil;
|
||||
strongSelf.activeConnection = nil;
|
||||
strongSelf->_communicator = nil;
|
||||
strongSelf->_activeConnection = nil;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[newConnection resume];
|
||||
|
||||
self.communicator = newConnection.remoteObjectProxy;
|
||||
_communicator = newConnection.remoteObjectProxy;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
{
|
||||
[self.xpcListener resume];
|
||||
[self.agentConnection startListener];
|
||||
[_xpcListener resume];
|
||||
[_agentConnection startListener];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(FIRST_UPDATER_MESSAGE_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!self.receivedInstallationData) {
|
||||
if (!self->_receivedInstallationData) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout: installation data was never received" }]];
|
||||
}
|
||||
|
||||
if (!self.agentConnection.connected) {
|
||||
if (!self->_agentConnection.connected) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout: agent connection was never initiated" }]];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)extractAndInstallUpdate
|
||||
- (void)extractAndInstallUpdate SPU_OBJC_DIRECT
|
||||
{
|
||||
[self.communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]];
|
||||
[_communicator handleMessageWithIdentifier:SPUExtractionStarted data:[NSData data]];
|
||||
|
||||
NSString *archivePath = [self.updateDirectoryPath stringByAppendingPathComponent:self.downloadName];
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.decryptionPassword expectingInstallationType:self.installationType];
|
||||
NSString *archivePath = [_updateDirectoryPath stringByAppendingPathComponent:_downloadName];
|
||||
id<SUUnarchiverProtocol> unarchiver = [SUUnarchiver unarchiverForPath:archivePath updatingHostBundlePath:_host.bundlePath decryptionPassword:_decryptionPassword expectingInstallationType:_installationType];
|
||||
|
||||
NSError *unarchiverError = nil;
|
||||
BOOL success = NO;
|
||||
@@ -202,14 +180,14 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
success = NO;
|
||||
} else {
|
||||
self.updateValidator = [[SUUpdateValidator alloc] initWithDownloadPath:archivePath signatures:self.signatures host:self.host];
|
||||
_updateValidator = [[SUUpdateValidator alloc] initWithDownloadPath:archivePath signatures:_signatures host:_host];
|
||||
|
||||
// Delta & package updates will require validation before extraction
|
||||
// Normal application updates are a bit more lenient allowing developers to change one of apple dev ID or EdDSA keys
|
||||
BOOL needsPrevalidation = [[unarchiver class] mustValidateBeforeExtraction] || ![self.installationType isEqualToString:SPUInstallationTypeApplication];
|
||||
BOOL needsPrevalidation = [[unarchiver class] mustValidateBeforeExtraction] || ![_installationType isEqualToString:SPUInstallationTypeApplication];
|
||||
|
||||
if (needsPrevalidation) {
|
||||
success = [self.updateValidator validateDownloadPathWithError:&unarchiverError];
|
||||
success = [_updateValidator validateDownloadPathWithError:&unarchiverError];
|
||||
} else {
|
||||
success = YES;
|
||||
}
|
||||
@@ -223,18 +201,18 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
if (error != nil) {
|
||||
[self unarchiverDidFailWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to unarchive %@", archivePath], NSUnderlyingErrorKey: (NSError * _Nonnull)error }]];
|
||||
} else {
|
||||
[self.communicator handleMessageWithIdentifier:SPUValidationStarted data:[NSData data]];
|
||||
[self->_communicator handleMessageWithIdentifier:SPUValidationStarted data:[NSData data]];
|
||||
|
||||
NSError *validationError = nil;
|
||||
BOOL validationSuccess = [self.updateValidator validateWithUpdateDirectory:self.updateDirectoryPath error:&validationError];
|
||||
BOOL validationSuccess = [self->_updateValidator validateWithUpdateDirectory:self->_updateDirectoryPath error:&validationError];
|
||||
|
||||
if (!validationSuccess) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Update validation was a failure", NSUnderlyingErrorKey: validationError }]];
|
||||
} else {
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationStartedStage1 data:[NSData data]];
|
||||
[self->_communicator handleMessageWithIdentifier:SPUInstallationStartedStage1 data:[NSData data]];
|
||||
|
||||
self.finishedValidation = YES;
|
||||
if (self.agentInitiatedConnection) {
|
||||
self->_finishedValidation = YES;
|
||||
if (self->_agentInitiatedConnection) {
|
||||
[self retrieveProcessIdentifierAndStartInstallation];
|
||||
}
|
||||
}
|
||||
@@ -245,60 +223,60 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
uint64_t progressValue = CFSwapInt64HostToLittle(*(uint64_t *)&progress);
|
||||
NSData *data = [NSData dataWithBytes:&progressValue length:sizeof(progressValue)];
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUExtractedArchiveWithProgress data:data];
|
||||
[self->_communicator handleMessageWithIdentifier:SPUExtractedArchiveWithProgress data:data];
|
||||
}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)clearUpdateDirectory
|
||||
- (void)clearUpdateDirectory SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.updateDirectoryPath != nil) {
|
||||
if (_updateDirectoryPath != nil) {
|
||||
NSError *theError = nil;
|
||||
if (![[[SUFileManager alloc] init] removeItemAtURL:[NSURL fileURLWithPath:self.updateDirectoryPath] error:&theError]) {
|
||||
if (![[[SUFileManager alloc] init] removeItemAtURL:[NSURL fileURLWithPath:_updateDirectoryPath] error:&theError]) {
|
||||
SULog(SULogLevelError, @"Couldn't remove update folder: %@.", theError);
|
||||
}
|
||||
self.updateDirectoryPath = nil;
|
||||
_updateDirectoryPath = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFailWithError:(NSError *)error
|
||||
- (void)unarchiverDidFailWithError:(NSError *)error SPU_OBJC_DIRECT
|
||||
{
|
||||
SULog(SULogLevelError, @"Failed to unarchive file");
|
||||
SULogError(error);
|
||||
|
||||
// No longer need update validator until next possible extraction (eg: if initial delta update fails)
|
||||
self.updateValidator = nil;
|
||||
_updateValidator = nil;
|
||||
|
||||
// Client could try update again with different inputs
|
||||
// Eg: one common case is if a delta update fails, client may want to fall back to regular update
|
||||
// We really only need to set updateDirectoryPath to nil since that's the field we check if we've received installation data,
|
||||
// but may as well set other fields to nil too
|
||||
[self clearUpdateDirectory];
|
||||
self.downloadName = nil;
|
||||
self.decryptionPassword = nil;
|
||||
self.signatures = nil;
|
||||
self.relaunchPath = nil;
|
||||
self.host = nil;
|
||||
_downloadName = nil;
|
||||
_decryptionPassword = nil;
|
||||
_signatures = nil;
|
||||
_relaunchPath = nil;
|
||||
_host = nil;
|
||||
|
||||
NSData *archivedError = SPUArchiveRootObjectSecurely(error);
|
||||
[self.communicator handleMessageWithIdentifier:SPUArchiveExtractionFailed data:archivedError != nil ? archivedError : [NSData data]];
|
||||
[_communicator handleMessageWithIdentifier:SPUArchiveExtractionFailed data:archivedError != nil ? archivedError : [NSData data]];
|
||||
}
|
||||
|
||||
- (void)agentConnectionDidInitiate
|
||||
{
|
||||
self.agentInitiatedConnection = YES;
|
||||
if (self.finishedValidation) {
|
||||
_agentInitiatedConnection = YES;
|
||||
if (_finishedValidation) {
|
||||
[self retrieveProcessIdentifierAndStartInstallation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)agentConnectionDidInvalidate
|
||||
{
|
||||
if (!self.finishedValidation || !self.agentInitiatedConnection) {
|
||||
if (!_finishedValidation || !_agentInitiatedConnection) {
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{ NSLocalizedDescriptionKey: @"Error: Agent connection invalidated before installation began" }];
|
||||
|
||||
NSError *agentError = self.agentConnection.invalidationError;
|
||||
NSError *agentError = _agentConnection.invalidationError;
|
||||
if (agentError != nil) {
|
||||
userInfo[NSUnderlyingErrorKey] = agentError;
|
||||
}
|
||||
@@ -307,21 +285,21 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)retrieveProcessIdentifierAndStartInstallation
|
||||
- (void)retrieveProcessIdentifierAndStartInstallation SPU_OBJC_DIRECT
|
||||
{
|
||||
// We use the relaunch path for the bundle to listen for termination instead of the host path
|
||||
// For a plug-in this makes a big difference; we want to wait until the app hosting the plug-in terminates
|
||||
// Otherwise for an app, the relaunch path and host path should be identical
|
||||
|
||||
[self.agentConnection.agent registerApplicationBundlePath:self.relaunchPath reply:^(NSNumber * _Nullable processIdentifier) {
|
||||
[_agentConnection.agent registerApplicationBundlePath:_relaunchPath reply:^(NSNumber * _Nullable processIdentifier) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.terminationListener = [[TerminationListener alloc] initWithProcessIdentifier:processIdentifier];
|
||||
self->_terminationListener = [[TerminationListener alloc] initWithProcessIdentifier:processIdentifier];
|
||||
[self startInstallation];
|
||||
});
|
||||
}];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(RETRIEVE_PROCESS_IDENTIFIER_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (self.terminationListener == nil) {
|
||||
if (self->_terminationListener == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Timeout error: failed to retreive process identifier from agent" }]];
|
||||
}
|
||||
});
|
||||
@@ -329,11 +307,11 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
if (identifier == SPUInstallationData && self.updateDirectoryPath == nil) {
|
||||
if (identifier == SPUInstallationData && _updateDirectoryPath == nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Mark that we have received the installation data
|
||||
// Do not rely on eg: self.updateDirectoryPath != nil because we may set it to nil again if an early stage fails (i.e, archive extraction)
|
||||
self.receivedInstallationData = YES;
|
||||
// Do not rely on eg: self->_updateDirectoryPath != nil because we may set it to nil again if an early stage fails (i.e, archive extraction)
|
||||
self->_receivedInstallationData = YES;
|
||||
|
||||
SPUInstallationInputData *installationData = (SPUInstallationInputData *)SPUUnarchiveRootObjectSecurely(data, [SPUInstallationInputData class]);
|
||||
if (installationData == nil) {
|
||||
@@ -350,8 +328,8 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:installationData.hostBundlePath];
|
||||
|
||||
NSString *bundleIdentifier = hostBundle.bundleIdentifier;
|
||||
if (bundleIdentifier == nil || ![bundleIdentifier isEqualToString:self.hostBundleIdentifier]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to match host bundle identifiers %@ and %@", self.hostBundleIdentifier, bundleIdentifier] }]];
|
||||
if (bundleIdentifier == nil || ![bundleIdentifier isEqualToString:self->_hostBundleIdentifier]) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Failed to match host bundle identifiers %@ and %@", self->_hostBundleIdentifier, bundleIdentifier] }]];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -409,23 +387,23 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
// Carry these properities separately rather than using the SUInstallationInputData object
|
||||
// Some of our properties may slightly differ than our input and we don't want to make the mistake of using one of those
|
||||
self.installationType = installationType;
|
||||
self.relaunchPath = installationData.relaunchPath;
|
||||
self.downloadName = installationData.downloadName;
|
||||
self.signatures = installationData.signatures;
|
||||
self.updateDirectoryPath = cacheInstallationPath;
|
||||
self.host = [[SUHost alloc] initWithBundle:hostBundle];
|
||||
self->_installationType = installationType;
|
||||
self->_relaunchPath = installationData.relaunchPath;
|
||||
self->_downloadName = installationData.downloadName;
|
||||
self->_signatures = installationData.signatures;
|
||||
self->_updateDirectoryPath = cacheInstallationPath;
|
||||
self->_host = [[SUHost alloc] initWithBundle:hostBundle];
|
||||
|
||||
[self extractAndInstallUpdate];
|
||||
});
|
||||
} else if (identifier == SPUSentUpdateAppcastItemData) {
|
||||
SUAppcastItem *updateItem = (SUAppcastItem *)SPUUnarchiveRootObjectSecurely(data, [SUAppcastItem class]);
|
||||
if (updateItem != nil) {
|
||||
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:[self.installer canInstallSilently]];
|
||||
SPUInstallationInfo *installationInfo = [[SPUInstallationInfo alloc] initWithAppcastItem:updateItem canSilentlyInstall:[_installer canInstallSilently]];
|
||||
|
||||
NSData *archivedData = SPUArchiveRootObjectSecurely(installationInfo);
|
||||
if (archivedData != nil) {
|
||||
[self.agentConnection.agent registerInstallationInfoData:archivedData];
|
||||
[_agentConnection.agent registerInstallationInfoData:archivedData];
|
||||
}
|
||||
}
|
||||
} else if (identifier == SPUResumeInstallationToStage2 && data.length == sizeof(uint8_t) * 2) {
|
||||
@@ -435,21 +413,21 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// This flag has an impact on interactive type installations and showing UI progress during non-interactive installations
|
||||
self.shouldShowUI = (BOOL)showsUI;
|
||||
self->_shouldShowUI = (BOOL)showsUI;
|
||||
// Don't test if the application was alive initially, leave that to the progress agent if we decide to relaunch
|
||||
self.shouldRelaunch = (BOOL)relaunch;
|
||||
self->_shouldRelaunch = (BOOL)relaunch;
|
||||
|
||||
if (self.performedStage1Installation) {
|
||||
if (self->_performedStage1Installation) {
|
||||
// Resume the installation if we aren't done with stage 2 yet, and remind the client we are prepared to relaunch
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
if (!self.performedStage2Installation) {
|
||||
dispatch_async(self->_installerQueue, ^{
|
||||
if (!self->_performedStage2Installation) {
|
||||
[self performStage2Installation];
|
||||
} else if (!self.performedStage3Installation) {
|
||||
} else if (!self->_performedStage3Installation) {
|
||||
// If we already performed the 2nd stage, re-purpose this request to re-try sending another termination signal
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Don't check if the target is already terminated, leave that to the progress agent
|
||||
// We could be slightly off if there were multiple instances running
|
||||
[self.agentConnection.agent sendTerminationSignal];
|
||||
[self->_agentConnection.agent sendTerminationSignal];
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -460,19 +438,19 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
[self cleanupAndExitWithStatus:0 error:nil];
|
||||
});
|
||||
} else if (identifier == SPUUpdaterAlivePong) {
|
||||
self.receivedUpdaterPong = YES;
|
||||
_receivedUpdaterPong = YES;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startInstallation
|
||||
- (void)startInstallation SPU_OBJC_DIRECT
|
||||
{
|
||||
self.willCompleteInstallation = YES;
|
||||
_willCompleteInstallation = YES;
|
||||
|
||||
self.installerQueue = dispatch_queue_create("org.sparkle-project.sparkle.installer", DISPATCH_QUEUE_SERIAL);
|
||||
_installerQueue = dispatch_queue_create("org.sparkle-project.sparkle.installer", DISPATCH_QUEUE_SERIAL);
|
||||
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
dispatch_async(_installerQueue, ^{
|
||||
NSError *installerError = nil;
|
||||
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationType updateDirectory:self.updateDirectoryPath homeDirectory:self.homeDirectory userName:self.userName error:&installerError];
|
||||
id <SUInstallerProtocol> installer = [SUInstaller installerForHost:self->_host expectedInstallationType:self->_installationType updateDirectory:self->_updateDirectoryPath homeDirectory:self->_homeDirectory userName:self->_userName error:&installerError];
|
||||
|
||||
if (installer == nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@@ -483,7 +461,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
NSError *firstStageError = nil;
|
||||
if (![installer performInitialInstallation:&firstStageError]) {
|
||||
self.installer = nil;
|
||||
self->_installer = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to start installer", NSUnderlyingErrorKey: firstStageError }]];
|
||||
@@ -494,17 +472,17 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
uint8_t canPerformSilentInstall = (uint8_t)[installer canInstallSilently];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.installer = installer;
|
||||
self->_installer = installer;
|
||||
|
||||
uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated;
|
||||
uint8_t targetTerminated = (uint8_t)self->_terminationListener.terminated;
|
||||
|
||||
uint8_t sendInformation[] = {canPerformSilentInstall, targetTerminated};
|
||||
|
||||
NSData *sendData = [NSData dataWithBytes:sendInformation length:sizeof(sendInformation)];
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData];
|
||||
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage1 data:sendData];
|
||||
|
||||
self.performedStage1Installation = YES;
|
||||
self->_performedStage1Installation = YES;
|
||||
|
||||
// Stage 2 can still be run before we finish installation
|
||||
// if the updater requests for it before the app is terminated
|
||||
@@ -513,24 +491,24 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)performStage2Installation
|
||||
- (void)performStage2Installation SPU_OBJC_DIRECT
|
||||
{
|
||||
BOOL canPerformSecondStage = self.shouldShowUI || [self.installer canInstallSilently];
|
||||
BOOL canPerformSecondStage = _shouldShowUI || [_installer canInstallSilently];
|
||||
if (canPerformSecondStage) {
|
||||
self.performedStage2Installation = YES;
|
||||
_performedStage2Installation = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
uint8_t targetTerminated = (uint8_t)self.terminationListener.terminated;
|
||||
uint8_t targetTerminated = (uint8_t)self->_terminationListener.terminated;
|
||||
|
||||
NSData *sendData = [NSData dataWithBytes:&targetTerminated length:sizeof(targetTerminated)];
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
|
||||
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage2 data:sendData];
|
||||
|
||||
// Don't check if the target is already terminated, leave that to the progress agent
|
||||
// We could be slightly off if there were multiple instances running
|
||||
[self.agentConnection.agent sendTerminationSignal];
|
||||
[self->_agentConnection.agent sendTerminationSignal];
|
||||
});
|
||||
} else {
|
||||
self.installer = nil;
|
||||
_installer = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Failed to resume installer on stage 2 because installation cannot be installed silently" }]];
|
||||
@@ -538,9 +516,9 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)finishInstallationAfterHostTermination
|
||||
- (void)finishInstallationAfterHostTermination SPU_OBJC_DIRECT
|
||||
{
|
||||
[self.terminationListener startListeningWithCompletion:^(BOOL success) {
|
||||
[_terminationListener startListeningWithCompletion:^(BOOL success) {
|
||||
if (!success) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to listen for application termination" }]];
|
||||
return;
|
||||
@@ -549,38 +527,38 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
// Show 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 shouldShowUIProgress = YES;
|
||||
if (self.shouldShowUI && [self.installer canInstallSilently]) {
|
||||
if (self->_shouldShowUI && [self->_installer canInstallSilently]) {
|
||||
// Ask the updater if it is still alive
|
||||
// If they are, we will receive a pong response back
|
||||
// Reset if we received a pong just to be on the safe side
|
||||
self.receivedUpdaterPong = NO;
|
||||
[self.communicator handleMessageWithIdentifier:SPUUpdaterAlivePing data:[NSData data]];
|
||||
self->_receivedUpdaterPong = NO;
|
||||
[self->_communicator handleMessageWithIdentifier:SPUUpdaterAlivePing data:[NSData data]];
|
||||
|
||||
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
|
||||
// if the communicator object is nil, the updater definitely isn't alive. However, if it is not nil,
|
||||
// this does not necessarily mean the updater is alive, so we should also check if we got a recent response back from the updater
|
||||
if (shouldShowUIProgress && (!self.receivedUpdaterPong || self.communicator == nil)) {
|
||||
[self.agentConnection.agent showProgress];
|
||||
if (shouldShowUIProgress && (!self->_receivedUpdaterPong || self->_communicator == nil)) {
|
||||
[self->_agentConnection.agent showProgress];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
dispatch_async(self.installerQueue, ^{
|
||||
if (!self.performedStage2Installation) {
|
||||
dispatch_async(self->_installerQueue, ^{
|
||||
if (!self->_performedStage2Installation) {
|
||||
[self performStage2Installation];
|
||||
}
|
||||
|
||||
if (!self.performedStage2Installation) {
|
||||
if (!self->_performedStage2Installation) {
|
||||
// We failed and we're going to exit shortly
|
||||
return;
|
||||
}
|
||||
|
||||
NSError *thirdStageError = nil;
|
||||
if (![self.installer performFinalInstallationProgressBlock:nil error:&thirdStageError]) {
|
||||
[self.installer performCleanup];
|
||||
self.installer = nil;
|
||||
if (![self->_installer performFinalInstallationProgressBlock:nil error:&thirdStageError]) {
|
||||
[self->_installer performCleanup];
|
||||
self->_installer = nil;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SPUInstallerError userInfo:@{ NSLocalizedDescriptionKey: @"Failed to finalize installation", NSUnderlyingErrorKey: thirdStageError }]];
|
||||
@@ -588,23 +566,23 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
return;
|
||||
}
|
||||
|
||||
self.performedStage3Installation = YES;
|
||||
self->_performedStage3Installation = YES;
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Make sure to stop our displayed progress before we move onto cleanup & relaunch
|
||||
// This will also stop the agent from broadcasting the status info service, which we want to do before
|
||||
// we relaunch the app because the relaunched app could check the service upon launch..
|
||||
[self.agentConnection.agent stopProgress];
|
||||
[self->_agentConnection.agent stopProgress];
|
||||
shouldShowUIProgress = NO;
|
||||
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallationFinishedStage3 data:[NSData data]];
|
||||
[self->_communicator handleMessageWithIdentifier:SPUInstallationFinishedStage3 data:[NSData data]];
|
||||
|
||||
if (self.shouldRelaunch) {
|
||||
if (self->_shouldRelaunch) {
|
||||
// This will also signal to the agent that it will terminate soon
|
||||
[self.agentConnection.agent relaunchApplication];
|
||||
[self->_agentConnection.agent relaunchApplication];
|
||||
}
|
||||
|
||||
[self.installer performCleanup];
|
||||
[self->_installer performCleanup];
|
||||
|
||||
[self cleanupAndExitWithStatus:EXIT_SUCCESS error:nil];
|
||||
});
|
||||
@@ -619,20 +597,20 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7;
|
||||
|
||||
NSData *errorData = SPUArchiveRootObjectSecurely((NSError * _Nonnull)error);
|
||||
if (errorData != nil) {
|
||||
[self.communicator handleMessageWithIdentifier:SPUInstallerError data:errorData];
|
||||
[_communicator handleMessageWithIdentifier:SPUInstallerError data:errorData];
|
||||
}
|
||||
}
|
||||
|
||||
// It's nice to tell the other end we're invalidating
|
||||
|
||||
[self.activeConnection invalidate];
|
||||
self.activeConnection = nil;
|
||||
[_activeConnection invalidate];
|
||||
_activeConnection = nil;
|
||||
|
||||
[self.xpcListener invalidate];
|
||||
self.xpcListener = nil;
|
||||
[_xpcListener invalidate];
|
||||
_xpcListener = nil;
|
||||
|
||||
[self.agentConnection invalidate];
|
||||
self.agentConnection = nil;
|
||||
[_agentConnection invalidate];
|
||||
_agentConnection = nil;
|
||||
|
||||
[self clearUpdateDirectory];
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFil
|
||||
|
||||
SPUDeltaArchiveHeader *header = [sparkleArchive readHeader];
|
||||
if (header == nil) {
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
NSError *archiveError = sparkleArchive.error;
|
||||
if (archiveError != nil && [archiveError.domain isEqualToString:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN] && archiveError.code == SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC) {
|
||||
// Retry with XAR archive if the magic value is unexpected
|
||||
@@ -35,7 +36,9 @@ id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFil
|
||||
*outHeader = xarHeader;
|
||||
}
|
||||
return xarArchive;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (outHeader != NULL) {
|
||||
*outHeader = nil;
|
||||
}
|
||||
@@ -56,7 +59,9 @@ id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFil
|
||||
@synthesize clonedRelativePath = _clonedRelativePath;
|
||||
@synthesize sourcePath = _sourcePath;
|
||||
@synthesize commands = _commands;
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
@synthesize xarContext = _xarContext;
|
||||
#endif
|
||||
@synthesize mode = _mode;
|
||||
@synthesize codedDataLength = _codedDataLength;
|
||||
|
||||
@@ -103,9 +108,6 @@ id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFil
|
||||
return self;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
||||
|
||||
- (unsigned char *)beforeTreeHash
|
||||
{
|
||||
return _beforeTreeHash;
|
||||
@@ -116,6 +118,4 @@ id<SPUDeltaArchiveProtocol> SPUDeltaArchiveReadPatchAndHeader(NSString *patchFil
|
||||
return _afterTreeHash;
|
||||
}
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@end
|
||||
@@ -24,7 +24,7 @@ typedef NS_ENUM(uint8_t, SPUDeltaItemCommands) {
|
||||
};
|
||||
|
||||
// Represents header for our archive
|
||||
@interface SPUDeltaArchiveHeader : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUDeltaArchiveHeader : NSObject
|
||||
|
||||
- (instancetype)initWithCompression:(SPUDeltaCompressionMode)compression compressionLevel:(uint8_t)compressionLevel fileSystemCompression:(bool)fileSystemCompression majorVersion:(uint16_t)majorVersion minorVersion:(uint16_t)minorVersion beforeTreeHash:(const unsigned char *)beforeTreeHash afterTreeHash:(const unsigned char *)afterTreeHash;
|
||||
|
||||
@@ -39,7 +39,7 @@ typedef NS_ENUM(uint8_t, SPUDeltaItemCommands) {
|
||||
@end
|
||||
|
||||
// Represents an item we read or write to in our delta archive
|
||||
@interface SPUDeltaArchiveItem : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUDeltaArchiveItem : NSObject
|
||||
|
||||
- (instancetype)initWithRelativeFilePath:(NSString *)relativeFilePath commands:(SPUDeltaItemCommands)commands mode:(uint16_t)mode;
|
||||
|
||||
@@ -58,8 +58,10 @@ typedef NS_ENUM(uint8_t, SPUDeltaItemCommands) {
|
||||
@property (nonatomic) uint16_t mode;
|
||||
|
||||
// Private properties
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
// xar_file context for Xar delta archiver
|
||||
@property (nonatomic, nullable) const void *xarContext;
|
||||
#endif
|
||||
// Tracking length of item's data in data section, when encoding items and when extracting items
|
||||
@property (nonatomic) uint64_t codedDataLength;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUAppcastItem;
|
||||
|
||||
@interface SPUInstallationInfo : NSObject <NSSecureCoding>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUInstallationInfo : NSObject <NSSecureCoding>
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)appcastItem canSilentlyInstall:(BOOL)canSilentyInstall;
|
||||
|
||||
|
||||
@@ -52,9 +52,9 @@ static NSString *SUSystemDomainKey = @"SUSystemDomain";
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.appcastItem forKey:SUAppcastItemKey];
|
||||
[coder encodeBool:self.canSilentlyInstall forKey:SUCanSilentlyInstallKey];
|
||||
[coder encodeBool:self.systemDomain forKey:SUSystemDomainKey];
|
||||
[coder encodeObject:_appcastItem forKey:SUAppcastItemKey];
|
||||
[coder encodeBool:_canSilentlyInstall forKey:SUCanSilentlyInstallKey];
|
||||
[coder encodeBool:_systemDomain forKey:SUSystemDomainKey];
|
||||
}
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUInstallationInputData : NSObject <NSSecureCoding>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUInstallationInputData : NSObject <NSSecureCoding>
|
||||
|
||||
/*
|
||||
* relaunchPath - path to application bundle to relaunch and listen for termination
|
||||
|
||||
@@ -87,14 +87,14 @@ static NSString *SUInstallationTypeKey = @"SUInstallationType";
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.relaunchPath forKey:SURelaunchPathKey];
|
||||
[coder encodeObject:self.hostBundlePath forKey:SUHostBundlePathKey];
|
||||
[coder encodeObject:self.updateDirectoryPath forKey:SUUpdateDirectoryPathKey];
|
||||
[coder encodeObject:self.installationType forKey:SUInstallationTypeKey];
|
||||
[coder encodeObject:self.downloadName forKey:SUDownloadNameKey];
|
||||
[coder encodeObject:self.signatures forKey:SUSignaturesKey];
|
||||
if (self.decryptionPassword != nil) {
|
||||
[coder encodeObject:self.decryptionPassword forKey:SUDecryptionPasswordKey];
|
||||
[coder encodeObject:_relaunchPath forKey:SURelaunchPathKey];
|
||||
[coder encodeObject:_hostBundlePath forKey:SUHostBundlePathKey];
|
||||
[coder encodeObject:_updateDirectoryPath forKey:SUUpdateDirectoryPathKey];
|
||||
[coder encodeObject:_installationType forKey:SUInstallationTypeKey];
|
||||
[coder encodeObject:_downloadName forKey:SUDownloadNameKey];
|
||||
[coder encodeObject:_signatures forKey:SUSignaturesKey];
|
||||
if (_decryptionPassword != nil) {
|
||||
[coder encodeObject:_decryptionPassword forKey:SUDecryptionPasswordKey];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
(P number of blobs where P <= M commands)
|
||||
(Indexes for data blobs correspond to indexes for a filtered list of applicable commands (EXTRACT_FILE, BINARY_DIFF_FILE) that have data content)
|
||||
*/
|
||||
@interface SPUSparkleDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUSparkleDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
|
||||
|
||||
+182
-165
@@ -7,12 +7,15 @@
|
||||
//
|
||||
|
||||
#import "SPUSparkleDeltaArchive.h"
|
||||
#import <bzlib.h>
|
||||
#import <sys/stat.h>
|
||||
#import <CommonCrypto/CommonDigest.h>
|
||||
#import "SUBinaryDeltaCommon.h"
|
||||
#import <compression.h>
|
||||
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
#import <bzlib.h>
|
||||
#endif
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
#define SPARKLE_DELTA_FORMAT_MAGIC "spk!"
|
||||
@@ -28,39 +31,26 @@ typedef struct
|
||||
bool fileSystemCompression : 1;
|
||||
} SparkleDeltaArchiveMetadata;
|
||||
|
||||
@interface SPUSparkleDeltaArchive ()
|
||||
|
||||
@property (nonatomic) FILE *file;
|
||||
@property (nonatomic) BZFILE *bzipFile;
|
||||
@property (nonatomic) compression_stream compressionStream;
|
||||
@property (nonatomic) BOOL initializedCompressionStream;
|
||||
@property (nonatomic, readonly) NSString *patchFile;
|
||||
@property (nonatomic) SPUDeltaCompressionMode compression;
|
||||
@property (nonatomic, readonly) BOOL writeMode;
|
||||
@property (nonatomic) NSError *error;
|
||||
@property (nonatomic) void *partialChunkBuffer;
|
||||
@property (nonatomic) void *compressionBuffer;
|
||||
|
||||
@property (nonatomic) NSMutableArray<SPUDeltaArchiveItem *> *writableItems;
|
||||
|
||||
@end
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
||||
|
||||
@implementation SPUSparkleDeltaArchive
|
||||
{
|
||||
FILE *_file;
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
BZFILE *_bzipFile;
|
||||
#endif
|
||||
NSString *_patchFile;
|
||||
NSError *_error;
|
||||
void *_partialChunkBuffer;
|
||||
void *_compressionBuffer;
|
||||
NSMutableArray<SPUDeltaArchiveItem *> *_writableItems;
|
||||
|
||||
compression_stream _compressionStream;
|
||||
SPUDeltaCompressionMode _compression;
|
||||
|
||||
BOOL _initializedCompressionStream;
|
||||
BOOL _writeMode;
|
||||
}
|
||||
|
||||
@synthesize file = _file;
|
||||
@synthesize bzipFile = _bzipFile;
|
||||
@synthesize compressionStream = _compressionStream;
|
||||
@synthesize initializedCompressionStream = _initializedCompressionStream;
|
||||
@synthesize patchFile = _patchFile;
|
||||
@synthesize compression = _compression;
|
||||
@synthesize writeMode = _writeMode;
|
||||
@synthesize writableItems = _writableItems;
|
||||
@synthesize error = _error;
|
||||
@synthesize partialChunkBuffer = _partialChunkBuffer;
|
||||
@synthesize compressionBuffer = _compressionBuffer;
|
||||
|
||||
+ (BOOL)maySupportSafeExtraction
|
||||
{
|
||||
@@ -94,42 +84,45 @@ typedef struct
|
||||
|
||||
- (void)close
|
||||
{
|
||||
if (self.bzipFile != NULL) {
|
||||
if (!self.writeMode) {
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
if (_bzipFile != NULL) {
|
||||
if (!_writeMode) {
|
||||
int bzerror = 0;
|
||||
BZ2_bzReadClose(&bzerror, self.bzipFile);
|
||||
BZ2_bzReadClose(&bzerror, _bzipFile);
|
||||
}
|
||||
|
||||
self.bzipFile = NULL;
|
||||
} else if (self.initializedCompressionStream) {
|
||||
_bzipFile = NULL;
|
||||
} else
|
||||
#endif
|
||||
if (_initializedCompressionStream) {
|
||||
compression_stream_destroy(&_compressionStream);
|
||||
self.initializedCompressionStream = NO;
|
||||
_initializedCompressionStream = NO;
|
||||
}
|
||||
|
||||
if (self.file != NULL) {
|
||||
fclose(self.file);
|
||||
self.file = NULL;
|
||||
if (_file != NULL) {
|
||||
fclose(_file);
|
||||
_file = NULL;
|
||||
}
|
||||
|
||||
free(self.partialChunkBuffer);
|
||||
self.partialChunkBuffer = NULL;
|
||||
free(_partialChunkBuffer);
|
||||
_partialChunkBuffer = NULL;
|
||||
|
||||
free(self.compressionBuffer);
|
||||
self.compressionBuffer = NULL;
|
||||
free(_compressionBuffer);
|
||||
_compressionBuffer = NULL;
|
||||
}
|
||||
|
||||
- (BOOL)createBuffers
|
||||
- (BOOL)createBuffers SPU_OBJC_DIRECT
|
||||
{
|
||||
self.partialChunkBuffer = calloc(1, PARTIAL_IO_CHUNK_SIZE);
|
||||
if (self.partialChunkBuffer == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to calloc() %d bytes for partial chunk buffer.", PARTIAL_IO_CHUNK_SIZE] }];
|
||||
_partialChunkBuffer = calloc(1, PARTIAL_IO_CHUNK_SIZE);
|
||||
if (_partialChunkBuffer == NULL) {
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to calloc() %d bytes for partial chunk buffer.", PARTIAL_IO_CHUNK_SIZE] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (self.initializedCompressionStream) {
|
||||
self.compressionBuffer = calloc(1, COMPRESSION_BUFFER_SIZE);
|
||||
if (self.compressionBuffer == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to calloc() %d bytes for compression buffer.", COMPRESSION_BUFFER_SIZE] }];
|
||||
if (_initializedCompressionStream) {
|
||||
_compressionBuffer = calloc(1, COMPRESSION_BUFFER_SIZE);
|
||||
if (_compressionBuffer == NULL) {
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to calloc() %d bytes for compression buffer.", COMPRESSION_BUFFER_SIZE] }];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@@ -137,48 +130,53 @@ typedef struct
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)_readBuffer:(void *)buffer length:(int32_t)length
|
||||
- (BOOL)_readBuffer:(void *)buffer length:(int32_t)length SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
switch (self.compression) {
|
||||
switch (_compression) {
|
||||
case SPUDeltaCompressionModeNone: {
|
||||
if (fread(buffer, (size_t)length, 1, self.file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %d uncompressed bytes from archive.", length] }];
|
||||
if (fread(buffer, (size_t)length, 1, _file) < 1) {
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %d uncompressed bytes from archive.", length] }];
|
||||
return NO;
|
||||
} else {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
case SPUDeltaCompressionModeBzip2: {
|
||||
case SPUDeltaCompressionModeBzip2:
|
||||
{
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
int bzerror = 0;
|
||||
int bytesRead = BZ2_bzRead(&bzerror, self.bzipFile, buffer, length);
|
||||
int bytesRead = BZ2_bzRead(&bzerror, _bzipFile, buffer, length);
|
||||
|
||||
switch (bzerror) {
|
||||
case BZ_OK:
|
||||
case BZ_STREAM_END:
|
||||
if (bytesRead < length) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:0 userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Only %d out of %d expected bytes were read from the bz2 archive.", bytesRead, length] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:0 userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Only %d out of %d expected bytes were read from the bz2 archive.", bytesRead, length] }];
|
||||
return NO;
|
||||
} else {
|
||||
return YES;
|
||||
}
|
||||
case BZ_IO_ERROR:
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Encountered unexpected IO error when reading compressed bytes from bz2 archive." }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Encountered unexpected IO error when reading compressed bytes from bz2 archive." }];
|
||||
return NO;
|
||||
default:
|
||||
self.error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:bzerror userInfo:@{ NSLocalizedDescriptionKey: @"Encountered unexpected error when reading compressed bytes from bz2 archive." }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:bzerror userInfo:@{ NSLocalizedDescriptionKey: @"Encountered unexpected error when reading compressed bytes from bz2 archive." }];
|
||||
return NO;
|
||||
}
|
||||
#else
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
case SPUDeltaCompressionModeZLIB: {
|
||||
FILE *file = self.file;
|
||||
void *compressionBuffer = self.compressionBuffer;
|
||||
FILE *file = _file;
|
||||
void *compressionBuffer = _compressionBuffer;
|
||||
|
||||
_compressionStream.dst_ptr = buffer;
|
||||
_compressionStream.dst_size = (size_t)length;
|
||||
@@ -190,7 +188,7 @@ typedef struct
|
||||
size_t bytesRead = fread(compressionBuffer, 1, COMPRESSION_BUFFER_SIZE, file);
|
||||
if (bytesRead < COMPRESSION_BUFFER_SIZE) {
|
||||
if (feof(file) == 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %d compressed raw bytes from archive.", length] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %d compressed raw bytes from archive.", length] }];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@@ -202,13 +200,13 @@ typedef struct
|
||||
|
||||
compression_status status = compression_stream_process(&_compressionStream, feof(file) != 0 ? COMPRESSION_STREAM_FINALIZE : 0);
|
||||
if (status == COMPRESSION_STATUS_ERROR) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %d compressed bytes.", length] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %d compressed bytes.", length] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (status == COMPRESSION_STATUS_END && _compressionStream.dst_size > 0) {
|
||||
// We're expecting more bytes but we can't read any more bytes
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:-1 userInfo:@{ NSLocalizedDescriptionKey: @"Failed to decompress and read bytes because we reached EOF" }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:-1 userInfo:@{ NSLocalizedDescriptionKey: @"Failed to decompress and read bytes because we reached EOF" }];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@@ -239,44 +237,44 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
- (nullable SPUDeltaArchiveHeader *)readHeader
|
||||
{
|
||||
NSString *patchFile = self.patchFile;
|
||||
NSString *patchFile = _patchFile;
|
||||
|
||||
char patchFilePath[PATH_MAX + 1] = {0};
|
||||
if (![patchFile getFileSystemRepresentation:patchFilePath maxLength:sizeof(patchFilePath) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open and represent as a file system representation: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open and represent as a file system representation: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
FILE *file = fopen(patchFilePath, "rb");
|
||||
if (file == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch file for writing value due to io error: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch file for writing value due to io error: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.file = file;
|
||||
_file = file;
|
||||
|
||||
char magic[5] = {0};
|
||||
if (fread(magic, sizeof(magic) - 1, 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read magic value from patch file: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read magic value from patch file: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (strncmp(magic, SPARKLE_DELTA_FORMAT_MAGIC, sizeof(magic) - 1) != 0) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Patch file does not have '%@' magic value", @SPARKLE_DELTA_FORMAT_MAGIC] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_MAGIC userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Patch file does not have '%@' magic value", @SPARKLE_DELTA_FORMAT_MAGIC] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
SPUDeltaCompressionMode compression = 0;
|
||||
if (fread(&compression, sizeof(compression), 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read compression value from patch file: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read compression value from patch file: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.compression = compression;
|
||||
_compression = compression;
|
||||
|
||||
SparkleDeltaArchiveMetadata metadata = {0};
|
||||
if (fread(&metadata, sizeof(metadata), 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read compression level value from patch file: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read compression level value from patch file: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -284,40 +282,45 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
case SPUDeltaCompressionModeNone:
|
||||
break;
|
||||
case SPUDeltaCompressionModeBzip2: {
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
int bzerror = 0;
|
||||
|
||||
BZFILE *bzipFile = BZ2_bzReadOpen(&bzerror, file, 0, 0, NULL, 0);
|
||||
if (bzipFile == NULL) {
|
||||
switch (bzerror) {
|
||||
case BZ_IO_ERROR:
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch as bz2 file due to io error: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch as bz2 file due to io error: %@", patchFile] }];
|
||||
break;
|
||||
default:
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:bzerror userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch as bz2 file: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:bzerror userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch as bz2 file: %@", patchFile] }];
|
||||
break;
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.bzipFile = bzipFile;
|
||||
_bzipFile = bzipFile;
|
||||
|
||||
break;
|
||||
#else
|
||||
_error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:-1 userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open patch as bz2 file because bzip2 support is disabled" }];
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
case SPUDeltaCompressionModeZLIB: {
|
||||
if (compression_stream_init(&_compressionStream, COMPRESSION_STREAM_DECODE, _compressionAlgorithmForMode(compression)) != COMPRESSION_STATUS_OK) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open compression stream for reading" }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open compression stream for reading" }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.initializedCompressionStream = YES;
|
||||
_initializedCompressionStream = YES;
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_COMPRESSION_VALUE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Compression value read %d is not recognized.", compression] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_COMPRESSION_VALUE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Compression value read %d is not recognized.", compression] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -348,9 +351,9 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
return [[SPUDeltaArchiveHeader alloc] initWithCompression:compression compressionLevel:metadata.compressionLevel fileSystemCompression:metadata.fileSystemCompression majorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeTreeHash afterTreeHash:afterTreeHash];
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)_readRelativeFilePaths
|
||||
- (NSArray<NSString *> *)_readRelativeFilePaths SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -366,7 +369,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char *fileTableData = calloc(1, filePathSectionSize);
|
||||
if (fileTableData == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to calloc() %llu bytes for relative file paths.", filePathSectionSize] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to calloc() %llu bytes for relative file paths.", filePathSectionSize] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
@@ -393,7 +396,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
if (fileTableData[index] == '\0') {
|
||||
NSString *relativePath = [fileManager stringWithFileSystemRepresentation:&fileTableData[currentStartIndex] length:index - currentStartIndex];
|
||||
if (relativePath == nil) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path cannot be decoded as a file system representation: %@", relativePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path cannot be decoded as a file system representation: %@", relativePath] }];
|
||||
|
||||
free(fileTableData);
|
||||
return nil;
|
||||
@@ -425,7 +428,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
if (relativeFilePaths.count > UINT32_MAX) {
|
||||
// Very unlikely but we should guard against this
|
||||
// Clones rely on 32-bit indexes
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_TOO_MANY_FILES userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"There are too many file entries to apply a patch for (more than %u)", UINT32_MAX] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_TOO_MANY_FILES userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"There are too many file entries to apply a patch for (more than %u)", UINT32_MAX] }];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -464,7 +467,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
}
|
||||
|
||||
if ((NSUInteger)cloneRelativePathIndex >= relativeFilePaths.count) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CLONE_LOOKUP userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Index %u is past relative path table bounds of length %lu", cloneRelativePathIndex, (unsigned long)relativeFilePaths.count] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CLONE_LOOKUP userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Index %u is past relative path table bounds of length %lu", cloneRelativePathIndex, (unsigned long)relativeFilePaths.count] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -525,7 +528,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
}
|
||||
}
|
||||
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -563,13 +566,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char itemFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![itemFilePath getFileSystemRepresentation:itemFilePathString maxLength:sizeof(itemFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path to extract cannot be decoded and expressed as a file system representation: %@", itemFilePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path to extract cannot be decoded and expressed as a file system representation: %@", itemFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
FILE *outputFile = fopen(itemFilePathString, "wb");
|
||||
if (outputFile == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to fopen() %@", itemFilePath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to fopen() %@", itemFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -580,14 +583,14 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
while (bytesLeftoverToCopy > 0) {
|
||||
uint64_t currentBlockSize = (bytesLeftoverToCopy >= PARTIAL_IO_CHUNK_SIZE) ? PARTIAL_IO_CHUNK_SIZE : bytesLeftoverToCopy;
|
||||
|
||||
void *tempBuffer = self.partialChunkBuffer;
|
||||
void *tempBuffer = _partialChunkBuffer;
|
||||
|
||||
if (![self _readBuffer:tempBuffer length:(int32_t)currentBlockSize]) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (fwrite(tempBuffer, currentBlockSize, 1, outputFile) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to fwrite() %llu bytes during extraction.", currentBlockSize] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to fwrite() %llu bytes during extraction.", currentBlockSize] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -597,12 +600,12 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
fclose(outputFile);
|
||||
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
if ((commands & SPUDeltaItemCommandExtract) != 0 && chmod(itemFilePathString, mode) != 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to chmod() mode %d on %@", mode, itemFilePath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to chmod() mode %d on %@", mode, itemFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
} else {
|
||||
@@ -610,13 +613,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
if (PARTIAL_IO_CHUNK_SIZE < decodedLength) {
|
||||
// Something is seriously wrong
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CHUNK_SIZE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"PARTIAL_IO_CHUNK_SIZE (%d) < decodedLength (%llu)", PARTIAL_IO_CHUNK_SIZE, decodedLength] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CHUNK_SIZE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"PARTIAL_IO_CHUNK_SIZE (%d) < decodedLength (%llu)", PARTIAL_IO_CHUNK_SIZE, decodedLength] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
if (decodedLength > PATH_MAX) {
|
||||
// Link is too long
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_LINK_TOO_LONG userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Decoded length for link (%llu) is too long.", decodedLength] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_LINK_TOO_LONG userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Decoded length for link (%llu) is too long.", decodedLength] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -628,7 +631,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
NSString *destinationPath = [fileManager stringWithFileSystemRepresentation:buffer length:decodedLength];
|
||||
|
||||
if (destinationPath == nil) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Destination path for link %@ cannot be created in a file system representation: %@",itemFilePath, destinationPath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Destination path for link %@ cannot be created in a file system representation: %@",itemFilePath, destinationPath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -636,13 +639,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
NSError *createLinkError = nil;
|
||||
if (![fileManager createSymbolicLinkAtPath:itemFilePath withDestinationPath:destinationPath error:&createLinkError]) {
|
||||
self.error = createLinkError;
|
||||
_error = createLinkError;
|
||||
return NO;
|
||||
}
|
||||
|
||||
char itemFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![itemFilePath getFileSystemRepresentation:itemFilePathString maxLength:sizeof(itemFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Link path to extract cannot be decoded and expressed as a file system representation: %@", itemFilePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Link path to extract cannot be decoded and expressed as a file system representation: %@", itemFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -654,7 +657,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
} else if (S_ISDIR(mode)) {
|
||||
NSError *createDirectoryError = nil;
|
||||
if (![fileManager createDirectoryAtPath:itemFilePath withIntermediateDirectories:NO attributes:@{NSFilePosixPermissions: @(mode)} error:&createDirectoryError]) {
|
||||
self.error = createDirectoryError;
|
||||
_error = createDirectoryError;
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@@ -662,34 +665,39 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)_writeBuffer:(void *)buffer length:(int32_t)length
|
||||
- (BOOL)_writeBuffer:(void *)buffer length:(int32_t)length SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
switch (self.compression) {
|
||||
switch (_compression) {
|
||||
case SPUDeltaCompressionModeNone: {
|
||||
BOOL success = (fwrite(buffer, (size_t)length, 1, self.file) == 1);
|
||||
BOOL success = (fwrite(buffer, (size_t)length, 1, _file) == 1);
|
||||
if (!success) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d uncompressed bytes.", length] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d uncompressed bytes.", length] }];
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
case SPUDeltaCompressionModeBzip2: {
|
||||
case SPUDeltaCompressionModeBzip2:
|
||||
{
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
int bzerror = 0;
|
||||
BZ2_bzWrite(&bzerror, self.bzipFile, buffer, length);
|
||||
BZ2_bzWrite(&bzerror, _bzipFile, buffer, length);
|
||||
switch (bzerror) {
|
||||
case BZ_OK:
|
||||
return YES;
|
||||
case BZ_IO_ERROR:
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d compressed bz2 bytes due to io error.", length] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d compressed bz2 bytes due to io error.", length] }];
|
||||
return NO;
|
||||
default:
|
||||
self.error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:bzerror userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d compressed bz2 bytes.", length] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:bzerror userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d compressed bz2 bytes.", length] }];
|
||||
return NO;
|
||||
}
|
||||
#else
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
@@ -698,21 +706,21 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
_compressionStream.src_ptr = buffer;
|
||||
_compressionStream.src_size = (size_t)length;
|
||||
|
||||
FILE *file = self.file;
|
||||
void *compressionBuffer = self.compressionBuffer;
|
||||
FILE *file = _file;
|
||||
void *compressionBuffer = _compressionBuffer;
|
||||
while (_compressionStream.src_size > 0) {
|
||||
// Reset destination buffer
|
||||
_compressionStream.dst_ptr = compressionBuffer;
|
||||
_compressionStream.dst_size = COMPRESSION_BUFFER_SIZE;
|
||||
|
||||
if (compression_stream_process(&_compressionStream, 0) == COMPRESSION_STATUS_ERROR) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d compressed bytes.", length] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %d compressed bytes.", length] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
size_t compressedBytesWritten = (size_t)(_compressionStream.dst_ptr - (uint8_t *)compressionBuffer);
|
||||
if (compressedBytesWritten > 0 && fwrite(compressionBuffer, compressedBytesWritten, 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %zu compressed bytes.", compressedBytesWritten] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to write %zu compressed bytes.", compressedBytesWritten] }];
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
@@ -725,31 +733,31 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
- (void)writeHeader:(SPUDeltaArchiveHeader *)header
|
||||
{
|
||||
char patchFilePath[PATH_MAX + 1] = {0};
|
||||
if (![self.patchFile getFileSystemRepresentation:patchFilePath maxLength:sizeof(patchFilePath) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open header and represent as a file system representation: %@", self.patchFile] }];
|
||||
if (![_patchFile getFileSystemRepresentation:patchFilePath maxLength:sizeof(patchFilePath) - 1]) {
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open header and represent as a file system representation: %@", _patchFile] }];
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *file = fopen(patchFilePath, "wb");
|
||||
if (file == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch file for writing: %@", self.patchFile] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open patch file for writing: %@", _patchFile] }];
|
||||
return;
|
||||
}
|
||||
|
||||
self.file = file;
|
||||
_file = file;
|
||||
|
||||
char magic[] = SPARKLE_DELTA_FORMAT_MAGIC;
|
||||
if (fwrite(magic, sizeof(magic) - 1, 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write magic value due to io error" }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write magic value due to io error" }];
|
||||
return;
|
||||
}
|
||||
|
||||
SPUDeltaCompressionMode compression = (header.compression == SPUDeltaCompressionModeDefault) ? SPUDeltaCompressionModeLZMA : header.compression;
|
||||
|
||||
self.compression = compression;
|
||||
_compression = compression;
|
||||
|
||||
if (fwrite(&compression, sizeof(compression), 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write compression value due to io error" }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write compression value due to io error" }];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -757,13 +765,19 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
uint8_t compressionLevel = 0;
|
||||
switch (compression) {
|
||||
case SPUDeltaCompressionModeBzip2:
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
// Only 1 - 9 are valid, 0 is a special case for using default 9
|
||||
if (header.compressionLevel <= 0 || header.compressionLevel > 9) {
|
||||
compressionLevel = 9;
|
||||
} else {
|
||||
compressionLevel = header.compressionLevel;
|
||||
}
|
||||
|
||||
break;
|
||||
#else
|
||||
_error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:-1 userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write bzip2 patch because bzip2 support is disabled" }];
|
||||
return;
|
||||
#endif
|
||||
// Some supported formats below have a documented level even though it's not customizable
|
||||
// Let's record them in the archive
|
||||
case SPUDeltaCompressionModeLZMA:
|
||||
@@ -782,7 +796,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
SparkleDeltaArchiveMetadata metadata = {.compressionLevel = compressionLevel, .fileSystemCompression = header.fileSystemCompression};
|
||||
|
||||
if (fwrite(&metadata, sizeof(metadata), 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write metadata value due to io error" }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write metadata value due to io error" }];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -790,6 +804,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
case SPUDeltaCompressionModeNone:
|
||||
break;
|
||||
case SPUDeltaCompressionModeBzip2: {
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
int bzerror = 0;
|
||||
// Compression level can be 1 - 9
|
||||
int blockSize100k = (int)compressionLevel;
|
||||
@@ -798,17 +813,18 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
if (bzipFile == NULL) {
|
||||
switch (bzerror) {
|
||||
case BZ_IO_ERROR:
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open bz2 stream for writing due to io error" }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open bz2 stream for writing due to io error" }];
|
||||
break;
|
||||
default:
|
||||
self.error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:bzerror userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open bz2 stream for writing" }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_BZIP2_ERROR_DOMAIN code:bzerror userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open bz2 stream for writing" }];
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
self.bzipFile = bzipFile;
|
||||
_bzipFile = bzipFile;
|
||||
#endif
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -817,12 +833,12 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
case SPUDeltaCompressionModeZLIB: {
|
||||
if (compression_stream_init(&_compressionStream, COMPRESSION_STREAM_ENCODE, _compressionAlgorithmForMode(compression)) != COMPRESSION_STATUS_OK) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open compression stream for writing" }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Failed to open compression stream for writing" }];
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
self.initializedCompressionStream = YES;
|
||||
_initializedCompressionStream = YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -843,16 +859,16 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
- (void)addItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
[self.writableItems addObject:item];
|
||||
[_writableItems addObject:item];
|
||||
}
|
||||
|
||||
- (void)finishEncodingItems
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSMutableArray<SPUDeltaArchiveItem *> *writableItems = self.writableItems;
|
||||
NSMutableArray<SPUDeltaArchiveItem *> *writableItems = _writableItems;
|
||||
|
||||
// Build relative path table for tracking file clones
|
||||
NSMutableDictionary<NSString *, NSNumber *> *relativePathToIndexTable = [NSMutableDictionary dictionary];
|
||||
@@ -884,7 +900,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
if (relativePathToIndexTable.count > UINT32_MAX) {
|
||||
// Very unlikely but we should guard against this
|
||||
// Clones rely on 32-bit indexes
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_TOO_MANY_FILES userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"There are too many file entries to create a patch for (more than %u)", UINT32_MAX] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_TOO_MANY_FILES userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"There are too many file entries to create a patch for (more than %u)", UINT32_MAX] }];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -895,7 +911,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char relativePathString[PATH_MAX + 1] = {0};
|
||||
if (![relativePath getFileSystemRepresentation:relativePathString maxLength:sizeof(relativePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path cannot be retrieved and expressed as a file system representation: %@", relativePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path cannot be retrieved and expressed as a file system representation: %@", relativePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -904,14 +920,14 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
for (NSString *clonedPathEntry in newClonedPathEntries) {
|
||||
char relativePathString[PATH_MAX + 1] = {0};
|
||||
if (![clonedPathEntry getFileSystemRepresentation:relativePathString maxLength:sizeof(relativePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone cannot be retrieved and expressed as a file system representation: %@", clonedPathEntry] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone cannot be retrieved and expressed as a file system representation: %@", clonedPathEntry] }];
|
||||
break;
|
||||
}
|
||||
|
||||
totalPathLength += strlen(relativePathString) + 1;
|
||||
}
|
||||
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -926,7 +942,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char pathBuffer[PATH_MAX + 1] = {0};
|
||||
if (![relativePath getFileSystemRepresentation:pathBuffer maxLength:PATH_MAX]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path cannot be encoded and expressed as a file system representation: %@", relativePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path cannot be encoded and expressed as a file system representation: %@", relativePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -937,7 +953,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
for (NSString *clonedPathEntry in newClonedPathEntries) {
|
||||
char pathBuffer[PATH_MAX + 1] = {0};
|
||||
if (![clonedPathEntry getFileSystemRepresentation:pathBuffer maxLength:PATH_MAX]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone cannot be encoded and expressed as a file system representation: %@", clonedPathEntry] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative path for clone cannot be encoded and expressed as a file system representation: %@", clonedPathEntry] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -946,7 +962,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
}
|
||||
}
|
||||
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -969,13 +985,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char sourcePathString[PATH_MAX + 1] = {0};
|
||||
if (![sourcePath getFileSystemRepresentation:sourcePathString maxLength:sizeof(sourcePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding cloned binary diff item: %@", sourcePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding cloned binary diff item: %@", sourcePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
struct stat fileInfo = {0};
|
||||
if (lstat(sourcePathString, &fileInfo) != 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", sourcePath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", sourcePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1002,7 +1018,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
NSNumber *relativePathIndex = relativePathToIndexTable[clonedRelativePath];
|
||||
if (relativePathIndex == nil) {
|
||||
// We have quite a problem here
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CLONE_LOOKUP userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative file path index for %@ could not be located", clonedRelativePath] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_BAD_CLONE_LOOKUP userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Relative file path index for %@ could not be located", clonedRelativePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1017,13 +1033,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char itemFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![itemPath getFileSystemRepresentation:itemFilePathString maxLength:sizeof(itemFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding cloned binary diff item: %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding cloned binary diff item: %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
struct stat fileInfo = {0};
|
||||
if (lstat(itemFilePathString, &fileInfo) != 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1043,13 +1059,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char sourceFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![sourcePath getFileSystemRepresentation:sourceFilePathString maxLength:sizeof(sourceFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding items: %@", sourcePath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding items: %@", sourcePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
struct stat sourceFileInfo = {0};
|
||||
if (lstat(sourceFilePathString, &sourceFileInfo) != 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", sourcePath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", sourcePath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1085,13 +1101,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
char itemFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![itemPath getFileSystemRepresentation:itemFilePathString maxLength:sizeof(itemFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding items: %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path cannot be decoded and expressed as a file system representation while encoding items: %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
struct stat itemFileInfo = {0};
|
||||
if (lstat(itemFilePathString, &itemFileInfo) != 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to lstat() on %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1105,7 +1121,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
} else if (S_ISLNK(extractMode)) {
|
||||
off_t fileSize = itemFileInfo.st_size;
|
||||
if (fileSize > UINT16_MAX) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_LINK_TOO_LONG userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Link path has a destination that is too long: %llu bytes", fileSize] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_ARCHIVE_ERROR_CODE_LINK_TOO_LONG userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Link path has a destination that is too long: %llu bytes", fileSize] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1125,7 +1141,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
}
|
||||
}
|
||||
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1136,7 +1152,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
}
|
||||
|
||||
// Encode all of our file contents
|
||||
void *tempBuffer = self.partialChunkBuffer;
|
||||
void *tempBuffer = _partialChunkBuffer;
|
||||
for (SPUDeltaArchiveItem *item in writableItems) {
|
||||
SPUDeltaItemCommands commands = item.commands;
|
||||
if ((commands & SPUDeltaItemCommandExtract) != 0 || (commands & SPUDeltaItemCommandBinaryDiff) != 0) {
|
||||
@@ -1151,13 +1167,13 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
if (totalItemSize > 0) {
|
||||
char itemFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![itemPath getFileSystemRepresentation:itemFilePathString maxLength:sizeof(itemFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path to finish encoding cannot be decoded and expressed as a file system representation: %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Path to finish encoding cannot be decoded and expressed as a file system representation: %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
FILE *inputFile = fopen(itemFilePathString, "rb");
|
||||
if (inputFile == NULL) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open file for reading while encoding items: %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to open file for reading while encoding items: %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1166,7 +1182,7 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
uint64_t currentBlockSize = (bytesLeftoverToCopy >= PARTIAL_IO_CHUNK_SIZE) ? PARTIAL_IO_CHUNK_SIZE : bytesLeftoverToCopy;
|
||||
|
||||
if (fread(tempBuffer, currentBlockSize, 1, inputFile) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %llu chunk bytes while encoding items", currentBlockSize] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read %llu chunk bytes while encoding items", currentBlockSize] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1179,21 +1195,21 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
fclose(inputFile);
|
||||
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (S_ISLNK(extractMode)) {
|
||||
char itemFilePathString[PATH_MAX + 1] = {0};
|
||||
if (![itemPath getFileSystemRepresentation:itemFilePathString maxLength:sizeof(itemFilePathString) - 1]) {
|
||||
self.error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Link path to finish encoding cannot be decoded and expressed as a file system representation: %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadInvalidFileNameError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Link path to finish encoding cannot be decoded and expressed as a file system representation: %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
char linkDestination[PATH_MAX + 1] = {0};
|
||||
ssize_t linkDestinationLength = readlink(itemFilePathString, linkDestination, PATH_MAX);
|
||||
if (linkDestinationLength < 0) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to readlink() file at %@", itemPath] }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to readlink() file at %@", itemPath] }];
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1206,16 +1222,19 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
// Close up and write final data to compressed streams
|
||||
|
||||
if (self.bzipFile != NULL) {
|
||||
#if SPARKLE_BUILD_BZIP2_DELTA_SUPPORT
|
||||
if (_bzipFile != NULL) {
|
||||
int bzerror = 0;
|
||||
BZ2_bzWriteClose64(&bzerror, self.bzipFile, 0, NULL, NULL, NULL, NULL);
|
||||
BZ2_bzWriteClose64(&bzerror, _bzipFile, 0, NULL, NULL, NULL, NULL);
|
||||
if (bzerror == BZ_IO_ERROR) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write and close bzip2 file due to IO error" }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write and close bzip2 file due to IO error" }];
|
||||
return;
|
||||
}
|
||||
} else if (self.initializedCompressionStream) {
|
||||
void *compressionBuffer = self.compressionBuffer;
|
||||
FILE *file = self.file;
|
||||
} else
|
||||
#endif
|
||||
if (_initializedCompressionStream) {
|
||||
void *compressionBuffer = _compressionBuffer;
|
||||
FILE *file = _file;
|
||||
|
||||
_compressionStream.src_size = 0;
|
||||
|
||||
@@ -1225,14 +1244,14 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
|
||||
compression_status status = compression_stream_process(&_compressionStream, COMPRESSION_STREAM_FINALIZE);
|
||||
if (status == COMPRESSION_STATUS_ERROR) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write final bits of Compression based file" }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_COMPRESSION_ERROR_DOMAIN code:COMPRESSION_STATUS_ERROR userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write final bits of Compression based file" }];
|
||||
return;
|
||||
}
|
||||
|
||||
size_t compressedBytesToWrite = (size_t)(_compressionStream.dst_ptr - (uint8_t *)compressionBuffer);
|
||||
if (compressedBytesToWrite > 0) {
|
||||
if (fwrite(compressionBuffer, compressedBytesToWrite, 1, file) < 1) {
|
||||
self.error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write and close Compression based file due to io error" }];
|
||||
_error = [NSError errorWithDomain:NSPOSIXErrorDomain code:errno userInfo:@{ NSLocalizedDescriptionKey: @"Failed to write and close Compression based file due to io error" }];
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1246,5 +1265,3 @@ static compression_algorithm _compressionAlgorithmForMode(SPUDeltaCompressionMod
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#import "SPUDeltaArchiveProtocol.h"
|
||||
@@ -14,11 +16,13 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Legacy container format for binary delta archives
|
||||
@interface SPUXarDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUXarDeltaArchive : NSObject <SPUDeltaArchiveProtocol>
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile;
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile SPU_OBJC_DIRECT;
|
||||
- (instancetype)initWithPatchFileForReading:(NSString *)patchFile SPU_OBJC_DIRECT;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
|
||||
#import "SPUXarDeltaArchive.h"
|
||||
#include <xar/xar.h>
|
||||
#include "SUBinaryDeltaCommon.h"
|
||||
@@ -45,22 +47,15 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE 3
|
||||
#define SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE 4
|
||||
|
||||
@interface SPUXarDeltaArchive ()
|
||||
|
||||
@property (nonatomic) xar_t x;
|
||||
@property (nonatomic, readonly) int32_t xarMode;
|
||||
@property (nonatomic, readonly) NSMutableDictionary<NSString *, NSValue *> *fileTable;
|
||||
@property (nonatomic, readonly) NSString *patchFile;
|
||||
@property (nonatomic) NSError *error;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUXarDeltaArchive
|
||||
{
|
||||
NSMutableDictionary<NSString *, NSValue *> *_fileTable;
|
||||
NSString *_patchFile;
|
||||
|
||||
xar_t _x;
|
||||
int32_t _xarMode;
|
||||
}
|
||||
|
||||
@synthesize x = _x;
|
||||
@synthesize xarMode = _xarMode;
|
||||
@synthesize patchFile = _patchFile;
|
||||
@synthesize fileTable = _fileTable;
|
||||
@synthesize error = _error;
|
||||
|
||||
- (instancetype)initWithPatchFileForWriting:(NSString *)patchFile
|
||||
@@ -91,9 +86,9 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
|
||||
- (void)close
|
||||
{
|
||||
if (self.x != NULL) {
|
||||
xar_close(self.x);
|
||||
self.x = NULL;
|
||||
if (_x != NULL) {
|
||||
xar_close(_x);
|
||||
_x = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,18 +100,18 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
|
||||
- (nullable SPUDeltaArchiveHeader *)readHeader
|
||||
{
|
||||
NSString *patchFile = self.patchFile;
|
||||
NSString *patchFile = _patchFile;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
// Sparkle's XAR delta archives have been superceded by Sparkle's own format
|
||||
xar_t x = xar_open(patchFile.fileSystemRepresentation, READ);
|
||||
#pragma clang diagnostic pop
|
||||
if (x == NULL) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for reading: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for reading: %@", patchFile] }];
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.x = x;
|
||||
_x = x;
|
||||
|
||||
uint16_t majorDiffVersion = SUBinaryDeltaMajorVersionFirst;
|
||||
uint16_t minorDiffVersion = 0;
|
||||
@@ -124,7 +119,7 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
NSString *expectedAfterHash = nil;
|
||||
|
||||
xar_subdoc_t subdoc;
|
||||
for (subdoc = xar_subdoc_first(self.x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
for (subdoc = xar_subdoc_first(_x); subdoc; subdoc = xar_subdoc_next(subdoc)) {
|
||||
if (strcmp(xar_subdoc_name(subdoc), BINARY_DELTA_ATTRIBUTES_KEY) == 0) {
|
||||
{
|
||||
// available in version 2.0 or later
|
||||
@@ -177,7 +172,7 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
|
||||
- (void)writeHeader:(SPUDeltaArchiveHeader *)header
|
||||
{
|
||||
NSString *patchFile = self.patchFile;
|
||||
NSString *patchFile = _patchFile;
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
@@ -185,11 +180,11 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
xar_t x = xar_open(patchFile.fileSystemRepresentation, WRITE);
|
||||
#pragma clang diagnostic pop
|
||||
if (x == NULL) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for writing: %@", patchFile] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_OPEN_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to xar_open() file for writing: %@", patchFile] }];
|
||||
return;
|
||||
}
|
||||
|
||||
self.x = x;
|
||||
_x = x;
|
||||
|
||||
SPUDeltaCompressionMode compression = (header.compression == SPUDeltaCompressionModeDefault ? SPUDeltaCompressionModeBzip2 : header.compression);
|
||||
|
||||
@@ -218,7 +213,7 @@ extern char *xar_get_safe_path(xar_file_t f) __attribute__((weak_import));
|
||||
case SPUDeltaCompressionModeLZFSE:
|
||||
case SPUDeltaCompressionModeLZ4:
|
||||
case SPUDeltaCompressionModeZLIB: {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Version 2 patches only support bzip2 compression."] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_UNSUPPORTED_COMPRESSION_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Version 2 patches only support bzip2 compression."] }];
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -281,7 +276,7 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
|
||||
- (void)addItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -290,9 +285,9 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
SPUDeltaItemCommands commands = item.commands;
|
||||
uint16_t mode = item.mode;
|
||||
|
||||
xar_file_t newFile = _xarAddFile(self.fileTable, self.x, relativeFilePath, filePath);
|
||||
xar_file_t newFile = _xarAddFile(_fileTable, _x, relativeFilePath, filePath);
|
||||
if (newFile == NULL) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_ADD_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to add xar file entry: %@", relativeFilePath] }];
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_ADD_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to add xar file entry: %@", relativeFilePath] }];
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -320,13 +315,13 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
|
||||
- (void)enumerateItems:(void (^)(SPUDeltaArchiveItem *, BOOL *))itemHandler
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
BOOL exitedEarly = NO;
|
||||
xar_iter_t iter = xar_iter_new();
|
||||
for (xar_file_t file = xar_file_first(self.x, iter); file; file = xar_file_next(iter)) {
|
||||
for (xar_file_t file = xar_file_first(_x, iter); file; file = xar_file_next(iter)) {
|
||||
char *pathCString;
|
||||
#if HAS_XAR_GET_SAFE_PATH
|
||||
#pragma clang diagnostic push
|
||||
@@ -397,7 +392,7 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
|
||||
- (BOOL)extractItem:(SPUDeltaArchiveItem *)item
|
||||
{
|
||||
if (self.error != nil) {
|
||||
if (_error != nil) {
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -405,8 +400,8 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
assert(item.xarContext != NULL);
|
||||
|
||||
xar_file_t file = item.xarContext;
|
||||
if (xar_extract_tofile(self.x, file, item.itemFilePath.fileSystemRepresentation) != 0) {
|
||||
self.error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to extract xar file entry to %@", item.itemFilePath] }];
|
||||
if (xar_extract_tofile(_x, file, item.itemFilePath.fileSystemRepresentation) != 0) {
|
||||
_error = [NSError errorWithDomain:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_DOMAIN code:SPARKLE_DELTA_XAR_ARCHIVE_ERROR_CODE_EXTRACT_FAILURE userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to extract xar file entry to %@", item.itemFilePath] }];
|
||||
return NO;
|
||||
}
|
||||
|
||||
@@ -414,3 +409,5 @@ static xar_file_t _xarAddFile(NSMutableDictionary<NSString *, NSValue *> *fileTa
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -29,42 +29,47 @@
|
||||
extern int bsdiff(int argc, const char **argv);
|
||||
|
||||
@interface CreateBinaryDeltaOperation : NSOperation
|
||||
@property (copy) NSString *relativePath;
|
||||
@property (copy) NSString *clonedRelativePath;
|
||||
@property (strong) NSString *resultPath;
|
||||
@property (strong) NSNumber *oldPermissions;
|
||||
@property (strong) NSNumber *permissions;
|
||||
@property (nonatomic) BOOL changingPermissions;
|
||||
@property (strong) NSString *_fromPath;
|
||||
@property (strong) NSString *_toPath;
|
||||
- (id)initWithRelativePath:(NSString *)relativePath clonedRelativePath:(NSString *)clonedRelativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree oldPermissions:(NSNumber *)oldPermissions newPermissions:(NSNumber *)permissions changingPermissions:(BOOL)changingPermissions;
|
||||
|
||||
@property (nonatomic, copy, readonly) NSString *relativePath;
|
||||
@property (nonatomic, copy, readonly) NSString *clonedRelativePath;
|
||||
@property (nonatomic, readonly) NSString *resultPath;
|
||||
@property (nonatomic, readonly) NSNumber *oldPermissions;
|
||||
@property (nonatomic, readonly) NSNumber *permissions;
|
||||
@property (nonatomic, readonly) NSString *fromPath;
|
||||
@property (nonatomic, readonly) BOOL changingPermissions;
|
||||
|
||||
- (id)initWithRelativePath:(NSString *)relativePath clonedRelativePath:(NSString *)clonedRelativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree oldPermissions:(NSNumber *)oldPermissions newPermissions:(NSNumber *)permissions changingPermissions:(BOOL)changingPermissions SPU_OBJC_DIRECT;
|
||||
|
||||
@end
|
||||
|
||||
@implementation CreateBinaryDeltaOperation
|
||||
{
|
||||
NSString *_toPath;
|
||||
}
|
||||
|
||||
@synthesize relativePath = _relativePath;
|
||||
@synthesize clonedRelativePath = _clonedRelativePath;
|
||||
@synthesize resultPath = _resultPath;
|
||||
@synthesize oldPermissions = _oldPermissions;
|
||||
@synthesize permissions = _permissions;
|
||||
@synthesize fromPath = _fromPath;
|
||||
@synthesize changingPermissions = _changingPermissions;
|
||||
@synthesize _fromPath = _fromPath;
|
||||
@synthesize _toPath = _toPath;
|
||||
|
||||
- (id)initWithRelativePath:(NSString *)relativePath clonedRelativePath:(NSString *)clonedRelativePath oldTree:(NSString *)oldTree newTree:(NSString *)newTree oldPermissions:(NSNumber *)oldPermissions newPermissions:(NSNumber *)permissions changingPermissions:(BOOL)changingPermissions
|
||||
{
|
||||
if ((self = [super init])) {
|
||||
self.relativePath = relativePath;
|
||||
self.clonedRelativePath = clonedRelativePath;
|
||||
self.oldPermissions = oldPermissions;
|
||||
self.permissions = permissions;
|
||||
self.changingPermissions = changingPermissions;
|
||||
_relativePath = [relativePath copy];
|
||||
_clonedRelativePath = [clonedRelativePath copy];
|
||||
_oldPermissions = oldPermissions;
|
||||
_permissions = permissions;
|
||||
_changingPermissions = changingPermissions;
|
||||
|
||||
if (clonedRelativePath == nil) {
|
||||
self._fromPath = [oldTree stringByAppendingPathComponent:relativePath];
|
||||
_fromPath = [oldTree stringByAppendingPathComponent:relativePath];
|
||||
} else {
|
||||
self._fromPath = [oldTree stringByAppendingPathComponent:clonedRelativePath];
|
||||
_fromPath = [oldTree stringByAppendingPathComponent:clonedRelativePath];
|
||||
}
|
||||
self._toPath = [newTree stringByAppendingPathComponent:relativePath];
|
||||
_toPath = [newTree stringByAppendingPathComponent:relativePath];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -72,10 +77,11 @@ extern int bsdiff(int argc, const char **argv);
|
||||
- (void)main
|
||||
{
|
||||
NSString *temporaryFile = temporaryFilename(@"BinaryDelta");
|
||||
const char *argv[] = { "/usr/bin/bsdiff", [self._fromPath fileSystemRepresentation], [self._toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation] };
|
||||
const char *argv[] = { "/usr/bin/bsdiff", [_fromPath fileSystemRepresentation], [_toPath fileSystemRepresentation], [temporaryFile fileSystemRepresentation] };
|
||||
int result = bsdiff(4, argv);
|
||||
if (!result)
|
||||
self.resultPath = temporaryFile;
|
||||
if (result == 0) {
|
||||
_resultPath = temporaryFile;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -704,7 +710,17 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
if (majorVersion >= SUBinaryDeltaMajorVersion3) {
|
||||
archive = [[SPUSparkleDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile];
|
||||
} else {
|
||||
#if SPARKLE_BUILD_LEGACY_DELTA_SUPPORT
|
||||
archive = [[SPUXarDeltaArchive alloc] initWithPatchFileForWriting:temporaryFile];
|
||||
#else
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
}
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:NSCocoaErrorDomain code:NSFileReadUnknownError userInfo:@{ NSLocalizedDescriptionKey: @"Support for creating legacy delta updates is disabled" }];
|
||||
}
|
||||
return NO;
|
||||
#endif
|
||||
}
|
||||
|
||||
SPUDeltaArchiveHeader *header = [[SPUDeltaArchiveHeader alloc] initWithCompression:compression compressionLevel:compressionLevel fileSystemCompression:foundFilesystemCompression majorVersion:majorVersion minorVersion:minorVersion beforeTreeHash:beforeHash afterTreeHash:afterHash];
|
||||
@@ -918,7 +934,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
|
||||
BOOL deltaOperationsFailed = NO;
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
NSString *resultPath = operation.resultPath;
|
||||
if (resultPath == nil) {
|
||||
if (verbose) {
|
||||
fprintf(stderr, "\n");
|
||||
@@ -952,7 +968,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
|
||||
SPUDeltaArchiveItem *item = [[SPUDeltaArchiveItem alloc] initWithRelativeFilePath:relativePath commands:commands mode:mode.unsignedShortValue];
|
||||
item.itemFilePath = resultPath;
|
||||
item.sourcePath = operation._fromPath;
|
||||
item.sourcePath = operation.fromPath;
|
||||
item.clonedRelativePath = clonedRelativePath;
|
||||
|
||||
[archive addItem:item];
|
||||
@@ -972,7 +988,7 @@ BOOL createBinaryDelta(NSString *source, NSString *destination, NSString *patchF
|
||||
|
||||
// Clean up operations after the archive has finished encoding
|
||||
for (CreateBinaryDeltaOperation *operation in deltaOperations) {
|
||||
NSString *resultPath = [operation resultPath];
|
||||
NSString *resultPath = operation.resultPath;
|
||||
if (resultPath != nil) {
|
||||
unlink(resultPath.fileSystemRepresentation);
|
||||
}
|
||||
|
||||
@@ -14,10 +14,15 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
SPU_OBJC_DIRECT_MEMBERS
|
||||
#endif
|
||||
@interface SUBinaryDeltaUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath updateHostBundlePath:(NSString *)updateHostBundlePath;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -16,17 +16,11 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUBinaryDeltaUnarchiver ()
|
||||
|
||||
@property (nonatomic, copy, readonly) NSString *archivePath;
|
||||
@property (nonatomic, copy, readonly) NSString *updateHostBundlePath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUBinaryDeltaUnarchiver
|
||||
|
||||
@synthesize archivePath = _archivePath;
|
||||
@synthesize updateHostBundlePath = _updateHostBundlePath;
|
||||
{
|
||||
NSString *_archivePath;
|
||||
NSString *_updateHostBundlePath;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
@@ -43,7 +37,11 @@
|
||||
// We used to invoke mdimport on the bundle but this is not a very good approach.
|
||||
// There's no need to do that for non-delta updates and for updates that contain no mdimporters.
|
||||
// Moreover, updating the timestamp on the mdimporter bundles is what developers have to do anyway when shipping their new update outside of Sparkle
|
||||
// Note: this is used from unit tests
|
||||
+ (void)updateSpotlightImportersAtBundlePath:(NSString *)targetPath
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
SPU_OBJC_DIRECT
|
||||
#endif
|
||||
{
|
||||
NSURL *targetURL = [NSURL fileURLWithPath:targetPath];
|
||||
// Only recurse if it's actually a directory. Don't recurse into a
|
||||
@@ -95,17 +93,17 @@
|
||||
|
||||
- (void)extractDeltaWithNotifier:(SUUnarchiverNotifier *)notifier
|
||||
{
|
||||
NSString *sourcePath = self.updateHostBundlePath;
|
||||
NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
NSString *sourcePath = _updateHostBundlePath;
|
||||
NSString *targetPath = [[_archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]];
|
||||
|
||||
NSError *applyDiffError = nil;
|
||||
BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, ^(double progress){
|
||||
BOOL success = applyBinaryDelta(sourcePath, targetPath, _archivePath, NO, ^(double progress){
|
||||
[notifier notifyProgress:progress];
|
||||
|
||||
}, &applyDiffError);
|
||||
|
||||
if (success) {
|
||||
[[self class] updateSpotlightImportersAtBundlePath:targetPath];
|
||||
[SUBinaryDeltaUnarchiver updateSpotlightImportersAtBundlePath:targetPath];
|
||||
[notifier notifySuccess];
|
||||
}
|
||||
else {
|
||||
@@ -113,6 +111,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; }
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _archivePath]; }
|
||||
|
||||
@end
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
SPU_OBJC_DIRECT_MEMBERS
|
||||
#endif
|
||||
@interface SUCodeSigningVerifier : NSObject
|
||||
|
||||
+ (BOOL)codeSignatureAtBundleURL:(NSURL *)oldBundleURL matchesSignatureAtBundleURL:(NSURL *)newBundleURL error:(NSError **)error;
|
||||
|
||||
@@ -209,22 +209,8 @@ static id valueOrNSNull(id value) {
|
||||
return value ? value : [NSNull null];
|
||||
}
|
||||
|
||||
+ (NSDictionary *)codeSignatureInfoAtBundleURL:(NSURL *)bundlePath {
|
||||
NSDictionary *info = nil;
|
||||
SecStaticCodeRef code = NULL;
|
||||
OSStatus result = SecStaticCodeCreateWithPath((__bridge CFURLRef)bundlePath, kSecCSDefaultFlags, &code);
|
||||
if (result != noErr) {
|
||||
SULog(SULogLevelError, @"Failed to get static code %d", result);
|
||||
goto finally;
|
||||
}
|
||||
info = [self codeSignatureInfoForCode:code];
|
||||
|
||||
finally:
|
||||
if (code) CFRelease(code);
|
||||
return info;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)codeSignatureInfoForCode:(SecStaticCodeRef)code {
|
||||
+ (NSDictionary *)codeSignatureInfoForCode:(SecStaticCodeRef)code SPU_OBJC_DIRECT
|
||||
{
|
||||
CFDictionaryRef signingInfo = nil;
|
||||
const SecCSFlags flags = (SecCSFlags) (kSecCSSigningInformation | kSecCSRequirementInformation | kSecCSDynamicInformation | kSecCSContentInformation);
|
||||
if (SecCodeCopySigningInformation(code, flags, &signingInfo) == noErr) {
|
||||
@@ -241,7 +227,8 @@ finally:
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (NSDictionary *)logSigningInfoForCode:(SecStaticCodeRef)code label:(NSString*)label {
|
||||
+ (NSDictionary *)logSigningInfoForCode:(SecStaticCodeRef)code label:(NSString*)label SPU_OBJC_DIRECT
|
||||
{
|
||||
NSDictionary *relevantInfo = [self codeSignatureInfoForCode:code];
|
||||
SULog(SULogLevelDefault, @"%@: %@", label, relevantInfo);
|
||||
return relevantInfo;
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_DMG_SUPPORT
|
||||
|
||||
#ifndef SUDISKIMAGEUNARCHIVER_H
|
||||
#define SUDISKIMAGEUNARCHIVER_H
|
||||
|
||||
@@ -14,12 +16,16 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUDiskImageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUDiskImageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath decryptionPassword:(nullable NSString *)decryptionPassword;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_DMG_SUPPORT
|
||||
|
||||
#import "SUDiskImageUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SULog.h"
|
||||
@@ -13,17 +15,11 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUDiskImageUnarchiver ()
|
||||
|
||||
@property (nonatomic, copy, readonly) NSString *archivePath;
|
||||
@property (nullable, nonatomic, copy, readonly) NSString *decryptionPassword;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUDiskImageUnarchiver
|
||||
|
||||
@synthesize archivePath = _archivePath;
|
||||
@synthesize decryptionPassword = _decryptionPassword;
|
||||
{
|
||||
NSString *_archivePath;
|
||||
NSString *_decryptionPassword;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
@@ -54,7 +50,7 @@
|
||||
}
|
||||
|
||||
// Called on a non-main thread.
|
||||
- (void)extractDMGWithNotifier:(SUUnarchiverNotifier *)notifier
|
||||
- (void)extractDMGWithNotifier:(SUUnarchiverNotifier *)notifier SPU_OBJC_DIRECT
|
||||
{
|
||||
@autoreleasepool {
|
||||
BOOL mountedSuccessfully = NO;
|
||||
@@ -84,10 +80,10 @@
|
||||
|
||||
NSData *promptData = [NSData dataWithBytes:"yes\n" length:4];
|
||||
|
||||
NSMutableArray *arguments = [@[@"attach", self.archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen"] mutableCopy];
|
||||
NSMutableArray *arguments = [@[@"attach", _archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen"] mutableCopy];
|
||||
|
||||
if (self.decryptionPassword) {
|
||||
NSMutableData *passwordData = [[self.decryptionPassword dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];
|
||||
if (_decryptionPassword) {
|
||||
NSMutableData *passwordData = [[_decryptionPassword dataUsingEncoding:NSUTF8StringEncoding] mutableCopy];
|
||||
// From the hdiutil docs:
|
||||
// read a null-terminated passphrase from standard input
|
||||
//
|
||||
@@ -136,17 +132,24 @@
|
||||
|
||||
[inputPipe.fileHandleForWriting writeData:promptData];
|
||||
|
||||
if (@available(macOS 10.15, *)) {
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (@available(macOS 10.15, *))
|
||||
#endif
|
||||
{
|
||||
if (![inputPipe.fileHandleForWriting writeData:promptData error:&error]) {
|
||||
goto reportError;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
else
|
||||
{
|
||||
@try {
|
||||
[inputPipe.fileHandleForWriting writeData:promptData];
|
||||
} @catch (NSException *) {
|
||||
goto reportError;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
[inputPipe.fileHandleForWriting closeFile];
|
||||
|
||||
@@ -181,7 +184,7 @@
|
||||
for (NSString *item in contents)
|
||||
{
|
||||
NSString *fromPath = [mountPoint stringByAppendingPathComponent:item];
|
||||
NSString *toPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item];
|
||||
NSString *toPath = [[_archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item];
|
||||
|
||||
itemsCopied += 1.0;
|
||||
[notifier notifyProgress:0.5 + itemsCopied/(totalItems*2.0)];
|
||||
@@ -219,11 +222,13 @@
|
||||
SULog(SULogLevelError, @"Error: %@", launchCleanupError);
|
||||
}
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Can't mount DMG %@", self.archivePath);
|
||||
SULog(SULogLevelError, @"Can't mount DMG %@", _archivePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; }
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _archivePath]; }
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -6,16 +6,22 @@
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUUnarchiverProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// An unarchiver for flat packages that doesn't really do any unarchiving
|
||||
@interface SUFlatPackageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUFlatPackageUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithFlatPackagePath:(NSString *)flatPackagePath expectingInstallationType:(NSString *)installationType;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright © 2021 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import "SUFlatPackageUnarchiver.h"
|
||||
#import "SUUnarchiverNotifier.h"
|
||||
#import "SPUInstallationType.h"
|
||||
@@ -14,17 +16,11 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUFlatPackageUnarchiver ()
|
||||
|
||||
@property (nonatomic, readonly) NSString *flatPackagePath;
|
||||
@property (nonatomic, readonly) NSString *expectedInstallationType;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUFlatPackageUnarchiver
|
||||
|
||||
@synthesize flatPackagePath = _flatPackagePath;
|
||||
@synthesize expectedInstallationType = _expectedInstallationType;
|
||||
{
|
||||
NSString *_flatPackagePath;
|
||||
NSString *_expectedInstallationType;
|
||||
}
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
@@ -52,16 +48,18 @@
|
||||
|
||||
// Flat packages must use guided package installs, not interactive
|
||||
BOOL isDirectory = NO;
|
||||
if (![self.expectedInstallationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not have guided installation type but %@ instead", self.expectedInstallationType]}]];
|
||||
} else if (![[NSFileManager defaultManager] fileExistsAtPath:self.flatPackagePath isDirectory:&isDirectory] || isDirectory) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not exist at %@", self.flatPackagePath]}]];
|
||||
if (![_expectedInstallationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not have guided installation type but %@ instead", _expectedInstallationType]}]];
|
||||
} else if (![[NSFileManager defaultManager] fileExistsAtPath:_flatPackagePath isDirectory:&isDirectory] || isDirectory) {
|
||||
[notifier notifyFailureWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Flat package does not exist at %@", _flatPackagePath]}]];
|
||||
} else {
|
||||
[notifier notifyProgress:1.0];
|
||||
[notifier notifySuccess];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.flatPackagePath]; }
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _flatPackagePath]; }
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -16,11 +16,15 @@ The installer package is installed using macOS's built-in command line installer
|
||||
A guided installation can be started by applications other than the application being replaced. This is particularly useful where helper applications or agents are used.
|
||||
*/
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerProtocol.h"
|
||||
|
||||
@interface SUGuidedPackageInstaller : NSObject <SUInstallerProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUGuidedPackageInstaller : NSObject <SUInstallerProtocol>
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright 2010 Dragon Systems Software Limited. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <sys/stat.h>
|
||||
#import "SUGuidedPackageInstaller.h"
|
||||
#import "SUErrors.h"
|
||||
@@ -13,19 +15,12 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUGuidedPackageInstaller ()
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *packagePath;
|
||||
@property (nonatomic, readonly, copy) NSString *homeDirectory;
|
||||
@property (nonatomic, readonly, copy) NSString *userName;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUGuidedPackageInstaller
|
||||
|
||||
@synthesize packagePath = _packagePath;
|
||||
@synthesize homeDirectory = _homeDirectory;
|
||||
@synthesize userName = _userName;
|
||||
{
|
||||
NSString *_packagePath;
|
||||
NSString *_homeDirectory;
|
||||
NSString *_userName;
|
||||
}
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName
|
||||
{
|
||||
@@ -50,9 +45,9 @@
|
||||
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
task.launchPath = installerPath;
|
||||
task.arguments = @[@"-pkg", self.packagePath, @"-target", @"/"];
|
||||
task.arguments = @[@"-pkg", _packagePath, @"-target", @"/"];
|
||||
// Set the $HOME and $USER variables so pre/post install scripts reference the correct user environment
|
||||
task.environment = @{@"HOME": self.homeDirectory, @"USER": self.userName};
|
||||
task.environment = @{@"HOME": _homeDirectory, @"USER": _userName};
|
||||
task.standardError = nil;
|
||||
task.standardOutput = nil;
|
||||
|
||||
@@ -93,3 +88,5 @@
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -13,11 +13,15 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SUHost;
|
||||
|
||||
@interface SUInstaller : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUInstaller : NSObject
|
||||
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName error:(NSError **)error;
|
||||
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr;
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr
|
||||
#endif
|
||||
;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
@implementation SUInstaller
|
||||
|
||||
+ (BOOL)isAliasFolderAtPath:(NSString *)path
|
||||
+ (BOOL)isAliasFolderAtPath:(NSString *)path SPU_OBJC_DIRECT
|
||||
{
|
||||
NSNumber *aliasFlag = nil;
|
||||
[[NSURL fileURLWithPath:path] getResourceValue:&aliasFlag forKey:NSURLIsAliasFileKey error:nil];
|
||||
@@ -31,7 +31,10 @@
|
||||
return aliasFlag.boolValue && directoryFlag.boolValue;
|
||||
}
|
||||
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr
|
||||
+ (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:(BOOL *)isPackagePtr isGuided:(BOOL *)isGuidedPtr
|
||||
#endif
|
||||
{
|
||||
NSParameterAssert(inUpdateFolder);
|
||||
NSParameterAssert(host);
|
||||
@@ -41,23 +44,31 @@
|
||||
*newAppDownloadPath = nil,
|
||||
*bundleFileName = [[host bundlePath] lastPathComponent],
|
||||
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
NSString *fallbackPackagePath = nil;
|
||||
|
||||
BOOL isPackage = NO;
|
||||
BOOL isGuided = YES;
|
||||
NSString *fallbackPackagePath = nil;
|
||||
#endif
|
||||
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:inUpdateFolder];
|
||||
NSString *bundleFileNameNoExtension = [bundleFileName stringByDeletingPathExtension];
|
||||
|
||||
while ((currentFile = [dirEnum nextObject])) {
|
||||
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
||||
NSString *currentFilename = [currentFile lastPathComponent];
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
NSString *currentExtension = [currentFile pathExtension];
|
||||
NSString *currentFilenameNoExtension = [currentFilename stringByDeletingPathExtension];
|
||||
#endif
|
||||
if ([currentFilename isEqualToString:bundleFileName] ||
|
||||
[currentFilename isEqualToString:alternateBundleFileName]) // We found one!
|
||||
{
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage = NO;
|
||||
#endif
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
} else if ([currentExtension isEqualToString:@"pkg"] ||
|
||||
[currentExtension isEqualToString:@"mpkg"]) {
|
||||
if ([currentFilenameNoExtension isEqualToString:bundleFileNameNoExtension]) {
|
||||
@@ -68,12 +79,15 @@
|
||||
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
||||
fallbackPackagePath = currentPath;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
||||
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
||||
NSString *hostBundleIdentifier = host.bundle.bundleIdentifier;
|
||||
if (incomingBundle && [incomingBundle.bundleIdentifier isEqualToString:hostBundleIdentifier]) {
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage = NO;
|
||||
#endif
|
||||
newAppDownloadPath = currentPath;
|
||||
break;
|
||||
}
|
||||
@@ -84,6 +98,7 @@
|
||||
[dirEnum skipDescendents];
|
||||
}
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
// We don't have a valid path. Try to use the fallback package.
|
||||
|
||||
if (newAppDownloadPath == nil && fallbackPackagePath != nil) {
|
||||
@@ -105,18 +120,33 @@
|
||||
*isPackagePtr = isPackage;
|
||||
if (isGuidedPtr)
|
||||
*isGuidedPtr = isGuided;
|
||||
|
||||
#endif
|
||||
|
||||
if (!newAppDownloadPath) {
|
||||
SULog(SULogLevelError, @"Searched %@ for %@.(app|pkg)", inUpdateFolder, bundleFileNameNoExtension);
|
||||
SULog(SULogLevelError, @"Searched %@ for %@.(app%@)", inUpdateFolder, bundleFileNameNoExtension,
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
@"|pkg"
|
||||
#else
|
||||
@""
|
||||
#endif
|
||||
);
|
||||
}
|
||||
return newAppDownloadPath;
|
||||
}
|
||||
|
||||
+ (nullable id<SUInstallerProtocol>)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory homeDirectory:(NSString *)homeDirectory userName:(NSString *)userName error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
BOOL isPackage = NO;
|
||||
BOOL isGuided = NO;
|
||||
NSString *newDownloadPath = [self installSourcePathInUpdateFolder:updateDirectory forHost:host isPackage:&isPackage isGuided:&isGuided];
|
||||
#endif
|
||||
|
||||
NSString *newDownloadPath = [self installSourcePathInUpdateFolder:updateDirectory forHost:host
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
isPackage:&isPackage isGuided:&isGuided
|
||||
#endif
|
||||
];
|
||||
|
||||
if (newDownloadPath == nil) {
|
||||
if (error != NULL) {
|
||||
@@ -129,6 +159,7 @@
|
||||
// We shouldn't implicitly trust the installation type fed into here from the appcast because the installation type helps us determine
|
||||
// ahead of time whether or not this installer tool should be ran as root or not
|
||||
id <SUInstallerProtocol> installer = nil;
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
if (isPackage && isGuided) {
|
||||
if (![expectedInstallationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
if (error != NULL) {
|
||||
@@ -145,7 +176,9 @@
|
||||
} else {
|
||||
installer = [[SUPackageInstaller alloc] initWithPackagePath:newDownloadPath];
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
if (![expectedInstallationType isEqualToString:SPUInstallationTypeApplication]) {
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Found regular application update but expected '%@=%@' from the appcast item enclosure instead", SUAppcastAttributeInstallationType, expectedInstallationType] }];
|
||||
|
||||
@@ -6,14 +6,18 @@
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerProtocol.h"
|
||||
|
||||
// This is the deprecated package installation type, aka the "interactive" package installer
|
||||
// For a more supported package installation, see SUGuidedPackageInstaller
|
||||
|
||||
@interface SUPackageInstaller : NSObject <SUInstallerProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUPackageInstaller : NSObject <SUInstallerProtocol>
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -6,6 +6,8 @@
|
||||
// Copyright 2008 Andy Matuschak. All rights reserved.
|
||||
//
|
||||
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
|
||||
#import "SUPackageInstaller.h"
|
||||
#import "SUConstants.h"
|
||||
#import "SUErrors.h"
|
||||
@@ -14,18 +16,13 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUPackageInstaller ()
|
||||
|
||||
@property (nonatomic, readonly, copy) NSString *packagePath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUPackageInstaller
|
||||
{
|
||||
NSString *_packagePath;
|
||||
}
|
||||
|
||||
static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
|
||||
@synthesize packagePath = _packagePath;
|
||||
|
||||
- (instancetype)initWithPackagePath:(NSString *)packagePath
|
||||
{
|
||||
self = [super init];
|
||||
@@ -52,7 +49,7 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
// -W = wait until the app has quit.
|
||||
// -n = Open another instance if already open.
|
||||
// -b = app bundle identifier
|
||||
NSArray *args = @[@"-W", @"-n", @"-b", @"com.apple.installer", self.packagePath];
|
||||
NSArray *args = @[@"-W", @"-n", @"-b", @"com.apple.installer", _packagePath];
|
||||
|
||||
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
|
||||
@try {
|
||||
@@ -80,3 +77,5 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -14,10 +14,12 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUPipedUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUPipedUnarchiver : NSObject <SUUnarchiverProtocol>
|
||||
|
||||
- (instancetype)initWithArchivePath:(NSString *)archivePath;
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
@@ -14,17 +14,12 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUPipedUnarchiver ()
|
||||
|
||||
@property (nonatomic, copy, readonly) NSString *archivePath;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUPipedUnarchiver
|
||||
{
|
||||
NSString *_archivePath;
|
||||
}
|
||||
|
||||
@synthesize archivePath = _archivePath;
|
||||
|
||||
+ (nullable NSArray <NSString *> *)commandAndArgumentsConformingToTypeOfPath:(NSString *)path
|
||||
static NSArray <NSString *> * _Nullable _commandAndArgumentsConformingToTypeOfPath(NSString *path)
|
||||
{
|
||||
NSArray <NSString *> *extractTGZ = @[@"/usr/bin/tar", @"-zxC"];
|
||||
NSArray <NSString *> *extractTBZ = @[@"/usr/bin/tar", @"-jxC"];
|
||||
@@ -55,7 +50,7 @@
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path
|
||||
{
|
||||
return ([self commandAndArgumentsConformingToTypeOfPath:path] != nil);
|
||||
return _commandAndArgumentsConformingToTypeOfPath(path) != nil;
|
||||
}
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction
|
||||
@@ -74,7 +69,7 @@
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock
|
||||
{
|
||||
NSArray <NSString *> *commandAndArguments = [[self class] commandAndArgumentsConformingToTypeOfPath:self.archivePath];
|
||||
NSArray <NSString *> *commandAndArguments = _commandAndArgumentsConformingToTypeOfPath(_archivePath);
|
||||
assert(commandAndArguments != nil);
|
||||
|
||||
NSString *command = commandAndArguments.firstObject;
|
||||
@@ -89,26 +84,26 @@
|
||||
}
|
||||
|
||||
// This method abstracts the types that use a command line tool piping data from stdin.
|
||||
- (void)extractArchivePipingDataToCommand:(NSString *)command arguments:(NSArray*)args notifier:(SUUnarchiverNotifier *)notifier
|
||||
- (void)extractArchivePipingDataToCommand:(NSString *)command arguments:(NSArray*)args notifier:(SUUnarchiverNotifier *)notifier SPU_OBJC_DIRECT
|
||||
{
|
||||
// *** GETS CALLED ON NON-MAIN THREAD!!!
|
||||
@autoreleasepool {
|
||||
NSString *destination = [self.archivePath stringByDeletingLastPathComponent];
|
||||
NSString *destination = [_archivePath stringByDeletingLastPathComponent];
|
||||
|
||||
SULog(SULogLevelDefault, @"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination);
|
||||
SULog(SULogLevelDefault, @"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], _archivePath, destination);
|
||||
|
||||
// Get the file size.
|
||||
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil];
|
||||
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:_archivePath error:nil];
|
||||
NSUInteger expectedLength = [(NSNumber *)[attributes objectForKey:NSFileSize] unsignedIntegerValue];
|
||||
|
||||
if (expectedLength == 0) {
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, archive '%@' is empty", self.archivePath]}];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Extraction failed, archive '%@' is empty", _archivePath]}];
|
||||
|
||||
[notifier notifyFailureWithError:error];
|
||||
return;
|
||||
}
|
||||
|
||||
NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:self.archivePath];
|
||||
NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:_archivePath];
|
||||
|
||||
NSPipe *pipe = [NSPipe pipe];
|
||||
NSTask *task = [[NSTask alloc] init];
|
||||
@@ -127,16 +122,29 @@
|
||||
NSFileHandle *archiveOutput = [pipe fileHandleForWriting];
|
||||
NSUInteger bytesWritten = 0;
|
||||
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
BOOL hasIOErrorMethods;
|
||||
if (@available(macOS 10.15, *)) {
|
||||
hasIOErrorMethods = YES;
|
||||
} else {
|
||||
hasIOErrorMethods = NO;
|
||||
}
|
||||
#endif
|
||||
|
||||
do {
|
||||
NSData *data;
|
||||
if (hasIOErrorMethods) {
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (!hasIOErrorMethods) {
|
||||
@try {
|
||||
data = [archiveInput readDataOfLength:256*1024];
|
||||
} @catch (NSException *exception) {
|
||||
SULog(SULogLevelError, @"Failed to read data from archive with exception reason %@", exception.reason);
|
||||
data = nil;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
NSError *readError = nil;
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpartial-availability"
|
||||
@@ -145,13 +153,6 @@
|
||||
if (data == nil) {
|
||||
SULog(SULogLevelError, @"Failed to read data from archive with error %@", readError);
|
||||
}
|
||||
} else {
|
||||
@try {
|
||||
data = [archiveInput readDataOfLength:256*1024];
|
||||
} @catch (NSException *exception) {
|
||||
SULog(SULogLevelError, @"Failed to read data from archive with exception reason %@", exception.reason);
|
||||
data = nil;
|
||||
}
|
||||
}
|
||||
|
||||
NSUInteger len = [data length];
|
||||
@@ -160,7 +161,18 @@
|
||||
}
|
||||
|
||||
NSError *writeError = nil;
|
||||
if (hasIOErrorMethods) {
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (!hasIOErrorMethods) {
|
||||
@try {
|
||||
[archiveOutput writeData:data];
|
||||
} @catch (NSException *exception) {
|
||||
SULog(SULogLevelError, @"Failed to write data to pipe with exception reason %@", exception.reason);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wpartial-availability"
|
||||
if (![archiveOutput writeData:data error:&writeError]) {
|
||||
@@ -168,13 +180,6 @@
|
||||
SULog(SULogLevelError, @"Failed to write data to pipe with error %@", writeError);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
@try {
|
||||
[archiveOutput writeData:data];
|
||||
} @catch (NSException *exception) {
|
||||
SULog(SULogLevelError, @"Failed to write data to pipe with exception reason %@", exception.reason);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bytesWritten += len;
|
||||
@@ -183,23 +188,37 @@
|
||||
}
|
||||
while(bytesWritten < expectedLength);
|
||||
|
||||
if (@available(macOS 10.15, *)) {
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (@available(macOS 10.15, *))
|
||||
#endif
|
||||
{
|
||||
NSError *archiveOutputCloseError = nil;
|
||||
if (![archiveOutput closeAndReturnError:&archiveOutputCloseError]) {
|
||||
SULog(SULogLevelError, @"Failed to close pipe with error %@", archiveOutputCloseError);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
else
|
||||
{
|
||||
[archiveOutput closeFile];
|
||||
}
|
||||
#endif
|
||||
|
||||
if (@available(macOS 10.15, *)) {
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
if (@available(macOS 10.15, *))
|
||||
#endif
|
||||
{
|
||||
NSError *archiveInputCloseError = nil;
|
||||
if (![archiveInput closeAndReturnError:&archiveInputCloseError]) {
|
||||
SULog(SULogLevelError, @"Failed to close archive input with error %@", archiveInputCloseError);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_15
|
||||
else
|
||||
{
|
||||
[archiveInput closeFile];
|
||||
}
|
||||
#endif
|
||||
|
||||
[task waitUntilExit];
|
||||
|
||||
@@ -221,6 +240,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; }
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], _archivePath]; }
|
||||
|
||||
@end
|
||||
@@ -12,7 +12,7 @@
|
||||
@class SUHost;
|
||||
@protocol SUVersionComparison;
|
||||
|
||||
@interface SUPlainInstaller : NSObject <SUInstallerProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUPlainInstaller : NSObject <SUInstallerProtocol>
|
||||
|
||||
/**
|
||||
@param host The current (old) bundle host
|
||||
|
||||
@@ -18,25 +18,15 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUPlainInstaller ()
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, copy, readonly) NSString *bundlePath;
|
||||
@property (nonatomic, copy, readonly) NSString *installationPath;
|
||||
|
||||
@property (nonatomic) NSURL *temporaryOldDirectory;
|
||||
// We get an obj-c warning if we use 'newTemporaryDirectory' name about new + ownership stuff, so use 'temporaryNewDirectory' instead
|
||||
@property (nonatomic) NSURL *temporaryNewDirectory;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUPlainInstaller
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize bundlePath = _bundlePath;
|
||||
@synthesize installationPath = _installationPath;
|
||||
@synthesize temporaryOldDirectory = _temporaryOldDirectory;
|
||||
@synthesize temporaryNewDirectory = _temporaryNewDirectory;
|
||||
{
|
||||
SUHost *_host;
|
||||
NSString *_bundlePath;
|
||||
NSString *_installationPath;
|
||||
NSURL *_temporaryOldDirectory;
|
||||
// We get an obj-c warning if we use 'newTemporaryDirectory' name about new + ownership stuff, so use 'temporaryNewDirectory' instead
|
||||
NSURL *_temporaryNewDirectory;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath
|
||||
{
|
||||
@@ -49,23 +39,7 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
// Returns the bundle version from the specified host that is appropriate to use as a filename, or nil if we're unable to retrieve one
|
||||
- (NSString *)bundleVersionAppropriateForFilenameFromHost:(SUHost *)host
|
||||
{
|
||||
NSString *bundleVersion = [host objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
|
||||
NSString *trimmedVersion = @"";
|
||||
|
||||
if (bundleVersion != nil) {
|
||||
NSMutableCharacterSet *validCharacters = [NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[validCharacters formUnionWithCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@".-()"]];
|
||||
|
||||
trimmedVersion = [bundleVersion stringByTrimmingCharactersInSet:[validCharacters invertedSet]];
|
||||
}
|
||||
|
||||
return trimmedVersion.length > 0 ? trimmedVersion : nil;
|
||||
}
|
||||
|
||||
- (BOOL)startInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL *)newURL withHost:(SUHost *)host progressBlock:(nullable void(^)(double))progress error:(NSError * __autoreleasing *)error
|
||||
- (BOOL)startInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL *)newURL withHost:(SUHost *)host progressBlock:(nullable void(^)(double))progress error:(NSError * __autoreleasing *)error SPU_OBJC_DIRECT
|
||||
{
|
||||
if (installationURL == nil || newURL == nil) {
|
||||
// this really shouldn't happen but just in case
|
||||
@@ -123,7 +97,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
self.temporaryNewDirectory = tempNewDirectoryURL;
|
||||
_temporaryNewDirectory = tempNewDirectoryURL;
|
||||
|
||||
if (progress) {
|
||||
progress(3/10.0);
|
||||
@@ -222,7 +196,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
self.temporaryOldDirectory = tempOldDirectoryURL;
|
||||
_temporaryOldDirectory = tempOldDirectoryURL;
|
||||
|
||||
if (progress) {
|
||||
progress(9/10.0);
|
||||
@@ -289,9 +263,9 @@
|
||||
{
|
||||
// Prevent malicious downgrades
|
||||
// Note that we may not be able to do this for package installations, hence this code being done here
|
||||
NSString *hostVersion = [self.host version];
|
||||
NSString *hostVersion = [_host version];
|
||||
|
||||
NSBundle *bundle = [NSBundle bundleWithPath:self.bundlePath];
|
||||
NSBundle *bundle = [NSBundle bundleWithPath:_bundlePath];
|
||||
SUHost *updateHost = [[SUHost alloc] initWithBundle:bundle];
|
||||
NSString *updateVersion = [updateHost objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey];
|
||||
|
||||
@@ -314,19 +288,19 @@
|
||||
{
|
||||
// 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.bundlePath] withHost:self.host progressBlock:cb error:error];
|
||||
return [self startInstallationToURL:[NSURL fileURLWithPath:_installationPath] fromUpdateAtURL:[NSURL fileURLWithPath:_bundlePath] withHost:_host progressBlock:cb error:error];
|
||||
}
|
||||
|
||||
- (void)performCleanup
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
if (self.temporaryNewDirectory != nil) {
|
||||
[fileManager removeItemAtURL:self.temporaryNewDirectory error:NULL];
|
||||
if (_temporaryNewDirectory != nil) {
|
||||
[fileManager removeItemAtURL:_temporaryNewDirectory error:NULL];
|
||||
}
|
||||
|
||||
if (self.temporaryOldDirectory != nil) {
|
||||
[fileManager removeItemAtURL:self.temporaryOldDirectory error:NULL];
|
||||
if (_temporaryOldDirectory != nil) {
|
||||
[fileManager removeItemAtURL:_temporaryOldDirectory error:NULL];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
@class SUSignatures;
|
||||
@class SUPublicKeys;
|
||||
|
||||
@interface SUSignatureVerifier : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUSignatureVerifier : NSObject
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicKeys:(SUPublicKeys *)pkeys error:(NSError * __autoreleasing *)error;
|
||||
|
||||
|
||||
@@ -16,21 +16,19 @@
|
||||
#import "SULog.h"
|
||||
#import "SUSignatures.h"
|
||||
#import "SUErrors.h"
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
#endif
|
||||
#import "ed25519.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUSignatureVerifier ()
|
||||
@property (readonly) SUPublicKeys *pubKeys;
|
||||
@end
|
||||
|
||||
@implementation SUSignatureVerifier {
|
||||
@implementation SUSignatureVerifier
|
||||
{
|
||||
SUPublicKeys *_pubKeys;
|
||||
}
|
||||
|
||||
@synthesize pubKeys = _pubKeys;
|
||||
|
||||
+ (BOOL)validatePath:(NSString *)path withSignatures:(SUSignatures *)signatures withPublicKeys:(SUPublicKeys *)pkeys error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
SUSignatureVerifier *verifier = [(SUSignatureVerifier *)[self alloc] initWithPublicKeys:pkeys];
|
||||
@@ -54,9 +52,10 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (SecKeyRef)dsaSecKeyRef {
|
||||
|
||||
NSData *data = [self.pubKeys.dsaPubKey dataUsingEncoding:NSASCIIStringEncoding];
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
- (SecKeyRef)dsaSecKeyRef SPU_OBJC_DIRECT
|
||||
{
|
||||
NSData *data = [_pubKeys.dsaPubKey dataUsingEncoding:NSASCIIStringEncoding];
|
||||
if (!self || !data.length) {
|
||||
SULog(SULogLevelError, @"Could not read public DSA key");
|
||||
return nil;
|
||||
@@ -89,6 +88,7 @@
|
||||
CFRelease(items);
|
||||
return dsaPubKeySecKey;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (BOOL)verifyFileAtPath:(NSString *)path signatures:(SUSignatures *)signatures error:(NSError * __autoreleasing *)error
|
||||
{
|
||||
@@ -106,7 +106,7 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
switch (self.pubKeys.ed25519PubKeyStatus) {
|
||||
switch (_pubKeys.ed25519PubKeyStatus) {
|
||||
case SUSigningInputStatusAbsent:
|
||||
if (signatures.ed25519SignatureStatus != SUSigningInputStatusAbsent) {
|
||||
SULog(SULogLevelDefault, @"The update has an EdDSA signature, but it won't be used, because the old app doesn't have an EdDSA public key");
|
||||
@@ -165,11 +165,14 @@
|
||||
|
||||
return NO;
|
||||
}
|
||||
if (ed25519_verify(signatures.ed25519Signature, data.bytes, data.length, self.pubKeys.ed25519PubKey)) {
|
||||
if (ed25519_verify(signatures.ed25519Signature, data.bytes, data.length, _pubKeys.ed25519PubKey)) {
|
||||
SULog(SULogLevelDefault, @"OK: EdDSA signature is correct");
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
// No need to check DSA when EdDSA verification succeeded, unless a DSA signature is provided and it's
|
||||
// erroneously invalid
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusInvalid) {
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusInvalid)
|
||||
#endif
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
} else {
|
||||
@@ -177,9 +180,11 @@
|
||||
|
||||
SULog(SULogLevelError, @"%@", message);
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusAbsent) {
|
||||
SULog(SULogLevelDefault, @"DSA signature won't be checked, because EdDSA verification has already failed");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (error != NULL) {
|
||||
*error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUValidationError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
@@ -192,7 +197,8 @@
|
||||
break;
|
||||
}
|
||||
|
||||
switch (self.pubKeys.dsaPubKeyStatus) {
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
switch (_pubKeys.dsaPubKeyStatus) {
|
||||
case SUSigningInputStatusAbsent:
|
||||
if (signatures.dsaSignatureStatus != SUSigningInputStatusAbsent) {
|
||||
SULog(SULogLevelDefault, @"The update has a DSA signature, but it can't be used, because the old app doesn't have a DSA public key");
|
||||
@@ -235,6 +241,7 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (error != NULL) {
|
||||
// Use generic failure
|
||||
@@ -244,7 +251,8 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL)verifyDSASignatureOfStream:(NSInputStream *)stream dsaSignature:(NSData *)dsaSignature error:(NSError * __autoreleasing *)outError
|
||||
#if SPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
- (BOOL)verifyDSASignatureOfStream:(NSInputStream *)stream dsaSignature:(NSData *)dsaSignature error:(NSError * __autoreleasing *)outError SPU_OBJC_DIRECT
|
||||
{
|
||||
if (!stream || !dsaSignature) {
|
||||
SULog(SULogLevelError, @"Invalid arguments to verifyStream");
|
||||
@@ -301,10 +309,7 @@
|
||||
return cleanup();
|
||||
}
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
||||
dataVerifyTransform = SecVerifyTransformCreate(dsaPubKeySecKey, (__bridge CFDataRef)dsaSignature, &error);
|
||||
#pragma clang diagnostic pop
|
||||
if (!dataVerifyTransform) {
|
||||
SULog(SULogLevelError, @"Could not understand format of the signature: %@; Signature data: %@", error, dsaSignature);
|
||||
if (outError != NULL) {
|
||||
@@ -368,5 +373,6 @@
|
||||
cleanup();
|
||||
return result.boolValue;
|
||||
}
|
||||
#endif
|
||||
|
||||
@end
|
||||
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUUnarchiverProtocol;
|
||||
|
||||
@interface SUUnarchiver : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUUnarchiver : NSObject
|
||||
|
||||
+ (nullable id <SUUnarchiverProtocol>)unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword expectingInstallationType:(NSString *)installationType;
|
||||
|
||||
|
||||
@@ -23,17 +23,24 @@
|
||||
if ([SUPipedUnarchiver canUnarchivePath:path]) {
|
||||
return [[SUPipedUnarchiver alloc] initWithArchivePath:path];
|
||||
|
||||
} else if ([SUDiskImageUnarchiver canUnarchivePath:path]) {
|
||||
}
|
||||
#if SPARKLE_BUILD_DMG_SUPPORT
|
||||
else if ([SUDiskImageUnarchiver canUnarchivePath:path]) {
|
||||
return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path decryptionPassword:decryptionPassword];
|
||||
|
||||
} else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) {
|
||||
}
|
||||
#endif
|
||||
else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) {
|
||||
assert(hostPath != nil);
|
||||
NSString *nonNullHostPath = hostPath;
|
||||
return [[SUBinaryDeltaUnarchiver alloc] initWithArchivePath:path updateHostBundlePath:nonNullHostPath];
|
||||
} else if ([SUFlatPackageUnarchiver canUnarchivePath:path]) {
|
||||
}
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
else if ([SUFlatPackageUnarchiver canUnarchivePath:path]) {
|
||||
// Flat packages are only supported for guided packaage installs
|
||||
return [[SUFlatPackageUnarchiver alloc] initWithFlatPackagePath:path expectingInstallationType:installationType];
|
||||
}
|
||||
#endif
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUUnarchiverNotifier : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUUnarchiverNotifier : NSObject
|
||||
|
||||
- (instancetype)initWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock;
|
||||
|
||||
|
||||
@@ -13,17 +13,11 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUUnarchiverNotifier ()
|
||||
|
||||
@property (nonatomic, readonly, copy) void (^completionBlock)(NSError * _Nullable);
|
||||
@property (nonatomic, readonly, copy) void (^ _Nullable progressBlock)(double);
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUUnarchiverNotifier
|
||||
|
||||
@synthesize completionBlock = _completionBlock;
|
||||
@synthesize progressBlock = _progressBlock;
|
||||
{
|
||||
void (^_completionBlock)(NSError * _Nullable);
|
||||
void (^ _Nullable _progressBlock)(double);
|
||||
}
|
||||
|
||||
- (instancetype)initWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock
|
||||
{
|
||||
@@ -40,13 +34,13 @@
|
||||
- (void)notifySuccess
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.completionBlock(nil);
|
||||
self->_completionBlock(nil);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)notifyFailureWithError:(NSError * _Nullable)reason
|
||||
{
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey];
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:@"An error occurred while extracting the archive. Please try again later." forKey:NSLocalizedDescriptionKey];
|
||||
if (reason) {
|
||||
[userInfo setObject:(NSError * _Nonnull)reason forKey:NSUnderlyingErrorKey];
|
||||
}
|
||||
@@ -54,15 +48,15 @@
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:userInfo];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.completionBlock(error);
|
||||
self->_completionBlock(error);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)notifyProgress:(double)progress
|
||||
{
|
||||
if (self.progressBlock != nil) {
|
||||
if (_progressBlock != nil) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.progressBlock(progress);
|
||||
self->_progressBlock(progress);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,8 +12,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol SUUnarchiverProtocol <NSObject>
|
||||
|
||||
+ (BOOL)canUnarchivePath:(NSString *)path;
|
||||
|
||||
+ (BOOL)mustValidateBeforeExtraction;
|
||||
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface StatusInfo : NSObject <SUStatusInfoProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface StatusInfo : NSObject <SUStatusInfoProtocol>
|
||||
|
||||
- (instancetype)initWithHostBundleIdentifier:(NSString *)bundleIdentifier;
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
{
|
||||
NSXPCListener *_xpcListener;
|
||||
NSMutableDictionary *_pendingReplies;
|
||||
|
||||
NSUInteger _pendingReplyCounter;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface TerminationListener : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface TerminationListener : NSObject
|
||||
|
||||
- (instancetype)initWithProcessIdentifier:(NSNumber * _Nullable)processIdentifier;
|
||||
|
||||
|
||||
@@ -16,19 +16,14 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface TerminationListener ()
|
||||
|
||||
@property (nonatomic, readonly, nullable) NSNumber *processIdentifier;
|
||||
@property (nonatomic) BOOL watchedTermination;
|
||||
@property (nonatomic, copy) void (^completionBlock)(BOOL);
|
||||
|
||||
@end
|
||||
|
||||
@implementation TerminationListener
|
||||
|
||||
@synthesize completionBlock = _completionBlock;
|
||||
@synthesize processIdentifier = _processIdentifier;
|
||||
@synthesize watchedTermination = _watchedTermination;
|
||||
{
|
||||
NSNumber *_processIdentifier;
|
||||
|
||||
void (^_completionBlock)(BOOL);
|
||||
|
||||
BOOL _watchedTermination;
|
||||
}
|
||||
|
||||
- (instancetype)initWithProcessIdentifier:(NSNumber * _Nullable)processIdentifier
|
||||
{
|
||||
@@ -42,22 +37,22 @@
|
||||
|
||||
- (BOOL)terminated
|
||||
{
|
||||
return (self.watchedTermination || self.processIdentifier == nil) ? YES : (kill(self.processIdentifier.intValue, 0) != 0);
|
||||
return (_watchedTermination || _processIdentifier == nil) ? YES : (kill(_processIdentifier.intValue, 0) != 0);
|
||||
}
|
||||
|
||||
- (void)invokeCompletionWithSuccess:(BOOL)success
|
||||
- (void)invokeCompletionWithSuccess:(BOOL)success SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.completionBlock != nil) {
|
||||
self.completionBlock(success);
|
||||
self.completionBlock = nil;
|
||||
if (_completionBlock != nil) {
|
||||
_completionBlock(success);
|
||||
_completionBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)startListeningWithCompletion:(void (^)(BOOL))completionBlock
|
||||
{
|
||||
self.completionBlock = completionBlock;
|
||||
_completionBlock = [completionBlock copy];
|
||||
|
||||
if (self.processIdentifier == nil) {
|
||||
if (_processIdentifier == nil) {
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
return;
|
||||
}
|
||||
@@ -66,7 +61,7 @@
|
||||
// As described in https://developer.apple.com/library/mac/technotes/tn2050/_index.html#//apple_ref/doc/uid/DTS10003081-CH1-SUBSECTION10
|
||||
// By using kqueues, we can stay away from using AppKit in case we ever decide to abandon it
|
||||
|
||||
pid_t processIdentifier = self.processIdentifier.intValue;
|
||||
pid_t processIdentifier = _processIdentifier.intValue;
|
||||
int queue = kqueue();
|
||||
if (queue == -1) {
|
||||
SULog(SULogLevelError, @"Failed to create kqueue() due to error %d: %@", errno, @(strerror(errno)));
|
||||
@@ -124,7 +119,7 @@ static void noteExitKQueueCallback(CFFileDescriptorRef file, CFOptionFlags __unu
|
||||
kevent(CFFileDescriptorGetNativeDescriptor(file), NULL, 0, &event, 1, NULL);
|
||||
|
||||
TerminationListener *self = CFBridgingRelease(info);
|
||||
self.watchedTermination = YES;
|
||||
self->_watchedTermination = YES;
|
||||
[self invokeCompletionWithSuccess:YES];
|
||||
}
|
||||
|
||||
|
||||
@@ -3,4 +3,4 @@
|
||||
#include "ConfigSwift.xcconfig"
|
||||
|
||||
SWIFT_OBJC_BRIDGING_HEADER = $(PRODUCT_NAME)/Bridging-Header.h
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_TOOL=1
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_EXTERNALLY=1
|
||||
@@ -1,15 +1,55 @@
|
||||
// Common
|
||||
|
||||
SPARKLE_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle
|
||||
SPARKLE_RELAUNCH_TOOL_NAME = Autoupdate
|
||||
SPARKLE_INSTALLER_PROGRESS_TOOL_NAME = Updater
|
||||
|
||||
// Set to 1 or 0 to bundle or not bundle provided XPC Services in Sparkle framework
|
||||
// Set to 1 or 0 to build and bundle the provided XPC Services in Sparkle framework
|
||||
// (Note for testing purposes for sandboxed apps, disabling all XPC services and then re-enabling them
|
||||
// may not work on the same login session due to a system caching issue. See comments for setting FRAMEWORK_VERSION for more info)
|
||||
SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE = 1
|
||||
// Embedding the downloader service also enables building legacy WebKit1 support
|
||||
SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE = 1
|
||||
SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE = 0
|
||||
SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE = 0
|
||||
|
||||
// Set to 0 to disable building legacy 1.x SUUpdater stub
|
||||
SPARKLE_BUILD_LEGACY_SUUPDATER = 1
|
||||
|
||||
// Set to 0 to not build legacy DSA signing support (useful for migrating to EdDSA)
|
||||
SPARKLE_BUILD_LEGACY_DSA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build legacy / xar based delta update support
|
||||
SPARKLE_BUILD_LEGACY_DELTA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build bzip2 support for version 3 delta based updates
|
||||
SPARKLE_BUILD_BZIP2_DELTA_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build support for package (pkg) based installations
|
||||
SPARKLE_BUILD_PACKAGE_SUPPORT = 1
|
||||
|
||||
// Set to 0 to not build support for extracting updates from disk images (dmgs)
|
||||
SPARKLE_BUILD_DMG_SUPPORT = 1
|
||||
|
||||
// Set to 0 to only build all non-UI bits (which means client uses a custom SPUUserDriver)
|
||||
SPARKLE_BUILD_UI_BITS = 1
|
||||
|
||||
// Set to 0 to not use and copy localization / string files to framework
|
||||
SPARKLE_COPY_LOCALIZATIONS = 1
|
||||
|
||||
// Compilation flags for Swift tools and unit tests
|
||||
// If SPARKLE_BUILD_LEGACY_DELTA_SUPPORT is set to 0, remove -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT
|
||||
// If SPARKLE_BUILD_PACKAGE_SUPPORT is set to 0, remove -DSPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
// If SPARKLE_BUILD_DMG_SUPPORT is set to 0, remove -DSPARKLE_BUILD_DMG_SUPPORT
|
||||
OTHER_SWIFT_FLAGS_COMMON = -DSPARKLE_BUILD_LEGACY_DSA_SUPPORT -DSPARKLE_BUILD_PACKAGE_SUPPORT -DSPARKLE_BUILD_DMG_SUPPORT
|
||||
|
||||
// Minimum supported macOS version
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.13
|
||||
|
||||
// Supported architectures
|
||||
ARCHS = $(ARCHS_STANDARD)
|
||||
|
||||
// Default Sparkle names
|
||||
SPARKLE_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle
|
||||
SPARKLE_RELAUNCH_TOOL_NAME = Autoupdate
|
||||
SPARKLE_INSTALLER_PROGRESS_TOOL_NAME = Updater
|
||||
|
||||
// Set these if you want to use custom name for the XPC Services
|
||||
// For the Installer one in particular, this name may show up in an authorization prompt
|
||||
// when installing an update that requires authorization.
|
||||
@@ -26,9 +66,6 @@ INSTALLER_STATUS_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.InstallerStatus
|
||||
INSTALLER_LAUNCHER_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.InstallerLauncher
|
||||
DOWNLOADER_BUNDLE_ID = ${XPC_SERVICE_BUNDLE_ID_PREFIX}.Downloader
|
||||
|
||||
// Set to 0 to only build all non-UI bits
|
||||
SPARKLE_BUILD_UI_BITS = 1
|
||||
|
||||
// If your app file on disk is named "MyApp 1.1b4", Sparkle usually updates it
|
||||
// in place, giving you an app named 1.1b4 that is actually 1.2. Turn the
|
||||
// following on to always reset the name back to "MyApp"
|
||||
@@ -55,12 +92,10 @@ ALWAYS_SEARCH_USER_PATHS = NO
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES
|
||||
GCC_SYMBOLS_PRIVATE_EXTERN = YES
|
||||
GCC_INLINES_ARE_PRIVATE_EXTERN = YES
|
||||
ARCHS = $(ARCHS_STANDARD)
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.13
|
||||
PRODUCT_NAME = ${TARGET_NAME}
|
||||
PRODUCT_BUNDLE_IDENTIFIER = org.sparkle-project.Sparkle.${PRODUCT_NAME:rfc1034identifier}
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_BUILD_UI_BITS=$(SPARKLE_BUILD_UI_BITS) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" MARKETING_VERSION=\"$(MARKETING_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_NAME=\"${INSTALLER_LAUNCHER_NAME}\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" INSTALLER_CONNECTION_NAME=\"${INSTALLER_CONNECTION_NAME}\" INSTALLER_CONNECTION_BUNDLE_ID=\"${INSTALLER_CONNECTION_BUNDLE_ID}\" INSTALLER_STATUS_NAME=\"${INSTALLER_STATUS_NAME}\" INSTALLER_STATUS_BUNDLE_ID=\"${INSTALLER_STATUS_BUNDLE_ID}\" DOWNLOADER_NAME=\"${DOWNLOADER_NAME}\" DOWNLOADER_BUNDLE_ID=\"${DOWNLOADER_BUNDLE_ID}\"
|
||||
GCC_PREPROCESSOR_DEFINITIONS_COMMON = SPU_OBJC_DIRECT=__attribute__((objc_direct)) SPU_OBJC_DIRECT_MEMBERS=__attribute__((objc_direct_members)) SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME=$(SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME) SPARKLE_BUILD_UI_BITS=$(SPARKLE_BUILD_UI_BITS) SPARKLE_COPY_LOCALIZATIONS=$(SPARKLE_COPY_LOCALIZATIONS) SPARKLE_BUILD_LEGACY_SUUPDATER=$(SPARKLE_BUILD_LEGACY_SUUPDATER) SPARKLE_BUILD_PACKAGE_SUPPORT=$(SPARKLE_BUILD_PACKAGE_SUPPORT) SPARKLE_BUILD_DMG_SUPPORT=$(SPARKLE_BUILD_DMG_SUPPORT) SPARKLE_BUILD_LEGACY_DELTA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DELTA_SUPPORT) SPARKLE_BUILD_BZIP2_DELTA_SUPPORT=$(SPARKLE_BUILD_BZIP2_DELTA_SUPPORT) SPARKLE_BUILD_LEGACY_DSA_SUPPORT=$(SPARKLE_BUILD_LEGACY_DSA_SUPPORT) SPARKLE_BUNDLE_IDENTIFIER=\"$(SPARKLE_BUNDLE_IDENTIFIER)\" CURRENT_PROJECT_VERSION=\"$(CURRENT_PROJECT_VERSION)\" MARKETING_VERSION=\"$(MARKETING_VERSION)\" SPARKLE_RELAUNCH_TOOL_NAME=\"$(SPARKLE_RELAUNCH_TOOL_NAME)\" SPARKLE_INSTALLER_PROGRESS_TOOL_NAME=\"$(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)\" SPARKLE_ICON_NAME=\"$(SPARKLE_ICON_NAME)\" INSTALLER_LAUNCHER_NAME=\"${INSTALLER_LAUNCHER_NAME}\" INSTALLER_LAUNCHER_BUNDLE_ID=\"${INSTALLER_LAUNCHER_BUNDLE_ID}\" INSTALLER_LAUNCHER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE) INSTALLER_CONNECTION_NAME=\"${INSTALLER_CONNECTION_NAME}\" INSTALLER_CONNECTION_BUNDLE_ID=\"${INSTALLER_CONNECTION_BUNDLE_ID}\" INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE) INSTALLER_STATUS_NAME=\"${INSTALLER_STATUS_NAME}\" INSTALLER_STATUS_BUNDLE_ID=\"${INSTALLER_STATUS_BUNDLE_ID}\" INSTALLER_STATUS_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE) DOWNLOADER_NAME=\"${DOWNLOADER_NAME}\" DOWNLOADER_BUNDLE_ID=\"${DOWNLOADER_BUNDLE_ID}\" DOWNLOADER_XPC_SERVICE_EMBEDDED=$(SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE)
|
||||
|
||||
CODE_SIGN_IDENTITY = -
|
||||
SDKROOT = macosx
|
||||
@@ -114,8 +149,5 @@ GCC_WARN_UNUSED_LABEL = YES
|
||||
GCC_WARN_UNUSED_PARAMETER = YES
|
||||
GCC_WARN_UNUSED_VARIABLE = YES
|
||||
|
||||
// These should be removed once the conversion to ARC is complete
|
||||
WARNING_CFLAGS_EXTRA = -Wno-custom-atomic-properties -Wno-implicit-atomic-properties
|
||||
|
||||
// Turn on all warnings, then disable a few which are almost impossible to avoid
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-arc-repeated-use-of-weak -Wno-auto-import -Wno-gnu-zero-variadic-macro-arguments -Wno-format-non-iso -Wno-direct-ivar-access $(WARNING_CFLAGS_EXTRA)
|
||||
WARNING_CFLAGS = -Wall -Weverything -Wno-unused-macros -Wno-gnu-statement-expression -Wno-auto-import -Wno-gnu-zero-variadic-macro-arguments -Wno-format-non-iso -Wno-direct-ivar-access -Werror=undef
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ConfigCommonDebug.xcconfig"
|
||||
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON)
|
||||
OTHER_SWIFT_FLAGS = $(OTHER_SWIFT_FLAGS_COMMON)
|
||||
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
|
||||
@@ -13,5 +13,6 @@ DEBUG_INFORMATION_FORMAT = dwarf
|
||||
ENABLE_TESTABILITY = YES
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON) DEBUG=1
|
||||
OTHER_SWIFT_FLAGS = $(OTHER_SWIFT_FLAGS_COMMON)
|
||||
ONLY_ACTIVE_ARCH = YES
|
||||
COPY_PHASE_STRIP = NO
|
||||
@@ -12,6 +12,7 @@ GCC_OPTIMIZATION_LEVEL = s
|
||||
DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
|
||||
GCC_GENERATE_DEBUGGING_SYMBOLS = YES
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS_COMMON) DEBUG=0
|
||||
OTHER_SWIFT_FLAGS = $(OTHER_SWIFT_FLAGS_COMMON)
|
||||
DEAD_CODE_STRIPPING = YES
|
||||
GCC_TREAT_WARNINGS_AS_ERRORS = NO
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES
|
||||
|
||||
@@ -5,4 +5,4 @@ WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${DOWNLOADER_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${DOWNLOADER_NAME}
|
||||
CODE_SIGN_ENTITLEMENTS = Downloader/${DOWNLOADER_BUNDLE_ID}.entitlements
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_DOWNLOADER_SERVICE=1
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "ConfigFramework.xcconfig"
|
||||
|
||||
// Strip all non-global symbols (including debug symbols)
|
||||
STRIP_STYLE = non-global
|
||||
@@ -4,3 +4,4 @@ INFOPLIST_FILE = InstallerConnection/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_CONNECTION_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_CONNECTION_NAME}
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
@@ -4,3 +4,4 @@ INFOPLIST_FILE = InstallerLauncher/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_LAUNCHER_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_LAUNCHER_NAME}
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
@@ -2,6 +2,6 @@
|
||||
|
||||
INFOPLIST_FILE = Sparkle/InstallerProgress/InstallerProgress-Info.plist
|
||||
PRODUCT_NAME = $(SPARKLE_INSTALLER_PROGRESS_TOOL_NAME)
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE=0
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE=0 BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
@@ -4,3 +4,4 @@ INFOPLIST_FILE = InstallerStatus/Info.plist
|
||||
WRAPPER_EXTENSION = xpc
|
||||
PRODUCT_BUNDLE_IDENTIFIER = ${INSTALLER_STATUS_BUNDLE_ID}
|
||||
PRODUCT_NAME = ${INSTALLER_STATUS_NAME}
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE=0 BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
@@ -3,3 +3,4 @@
|
||||
PRODUCT_NAME = $(SPARKLE_RELAUNCH_TOOL_NAME)
|
||||
SKIP_INSTALL = YES
|
||||
CLANG_ENABLE_MODULES = NO
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
@@ -11,4 +11,4 @@ FRAMEWORK_SEARCH_PATHS = $(inherited) $(DEVELOPER_FRAMEWORKS_DIR)
|
||||
LD_RUNPATH_SEARCH_PATHS = @loader_path/../Frameworks
|
||||
CLANG_ENABLE_MODULES = YES
|
||||
SWIFT_OBJC_BRIDGING_HEADER = Tests/Sparkle Unit Tests-Bridging-Header.h
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_TESTS=1
|
||||
GCC_PREPROCESSOR_DEFINITIONS = $(GCC_PREPROCESSOR_DEFINITIONS) BUILDING_SPARKLE_TESTS=1 BUILDING_SPARKLE_SOURCES_EXTERNALLY=1
|
||||
Executable
+58
@@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
|
||||
FRAMEWORK_PATH="${TARGET_BUILD_DIR}"/"${FULL_PRODUCT_NAME}"
|
||||
|
||||
# Remove any unused XPC Services
|
||||
|
||||
removedservices=0
|
||||
|
||||
if [[ "$SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${INSTALLER_LAUNCHER_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${DOWNLOADER_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${INSTALLER_STATUS_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${INSTALLER_CONNECTION_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$removedservices" -eq 4 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"
|
||||
rm -rf "${FRAMEWORK_PATH}"/"XPCServices"
|
||||
fi
|
||||
|
||||
# Remove any unused nibs
|
||||
|
||||
if [[ "$SPARKLE_BUILD_UI_BITS" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/Resources"/"SUStatus.nib"
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/Resources"/"Base.lproj/SUUpdateAlert.nib"
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/Resources"/"Base.lproj/SUUpdatePermissionPrompt.nib"
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/Resources"/"ReleaseNotesColorStyle.css"
|
||||
fi
|
||||
|
||||
# Remove localization files if requested
|
||||
|
||||
if [[ "$SPARKLE_COPY_LOCALIZATIONS" -eq 0 ]]; then
|
||||
for dir in "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/Resources"/*; do
|
||||
base=$(basename "$dir")
|
||||
if [[ "$base" =~ .*".lproj" ]]; then
|
||||
if [[ "$base" = "Base.lproj" ]]; then
|
||||
rm -rf "$dir/Sparkle.strings"
|
||||
# Remove Base.lproj if it's empty and the nibs have been stripped out already
|
||||
rmdir "$dir"
|
||||
else
|
||||
rm -rf "$dir"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
fi
|
||||
@@ -1,30 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
FRAMEWORK_PATH="${TARGET_BUILD_DIR}"/"${FULL_PRODUCT_NAME}"
|
||||
|
||||
removedservices=0
|
||||
|
||||
if [[ "$SPARKLE_EMBED_INSTALLER_LAUNCHER_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${INSTALLER_LAUNCHER_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$SPARKLE_EMBED_DOWNLOADER_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${DOWNLOADER_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$SPARKLE_EMBED_INSTALLER_STATUS_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${INSTALLER_STATUS_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$SPARKLE_EMBED_INSTALLER_CONNECTION_XPC_SERVICE" -eq 0 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"/"${INSTALLER_CONNECTION_NAME}.xpc"
|
||||
removedservices=$((removedservices+1))
|
||||
fi
|
||||
|
||||
if [[ "$removedservices" -eq 4 ]]; then
|
||||
rm -rf "${FRAMEWORK_PATH}"/"Versions/"${FRAMEWORK_VERSION}"/XPCServices"
|
||||
rm -rf "${FRAMEWORK_PATH}"/"XPCServices"
|
||||
fi
|
||||
@@ -36,6 +36,12 @@ Two software components should not directly know about each other. Preferrably t
|
||||
|
||||
See `Documentation/graph-of-sparkle.png` for a graph of how the code looks like currently. This was generated via [objc_dep](https://github.com/nst/objc_dep) (great tool). Note that there are no red edges which would mean that two nodes know of each other.
|
||||
|
||||
## Attributes
|
||||
## Attributes & Code Size
|
||||
|
||||
`nonatomic` should really be used wherever possible with regards to obj-c properties (`atomic` is a bad default). `readonly` should be used wherever possible as well, which also implies that only ivar access should be used in initializers. `NS_ASSUME_NONNULL_BEGIN` and `NS_ASSUME_NONNULL_END` should be used around new headers whenever possible. AppKit prevention guards should be used for any non-UI class whenever possible.
|
||||
Instance variables and instance variable access should be used for private members (declared in `@implementation` block) whenever possible over properties. Preferring instance variables over properties for internal usage can significantly reduce code size. Instance variables should also be ordered by having the larger sized data members declared first.
|
||||
|
||||
`SPU_OBJC_DIRECT_MEMBERS` should be used for any internal class in Sparkle and `SPU_OBJC_DIRECT` should be used for any other internal methods to Sparkle that doesn't need to utilize the Obj-C runtime to reduce code size. Note these attributes should not be used for *any* class or method that is exported to the developer (this includes private headers / APIs we carefully decided to expose too). For internal methods and classes that are also used by our Swift tools or unit tests, we may not expose them as direct specifically when building for those targets.
|
||||
|
||||
`nonatomic` should really be used wherever possible with regards to obj-c properties (`atomic` is a bad default). `readonly` should be used wherever possible as well, which also implies that only ivar access should be used in initializers. `NS_ASSUME_NONNULL_BEGIN` and `NS_ASSUME_NONNULL_END` should be used around new headers whenever possible. AppKit prevention guards should be used for any non-UI class whenever possible.
|
||||
|
||||
Sparkle has several feature flags in ConfigCommon.xcconfig (e.g. `SPARKLE_BUILD_LEGACY_SUUPDATER`, `SPARKLE_BUILD_LEGACY_DSA_SUPPORT`, `SPARKLE_BUILD_UI_BITS`, etc). This allows disabling any combination of these features and building Sparkle with a more minimal feature set. These flags (with the exception for stripping UI bits, localizations, or XPC Services) are for disabling features that are legacy or not recommended to use for most applications. Note when altering these flags, `OTHER_SWIFT_FLAGS_COMMON` may need to be updated appropriately too.
|
||||
@@ -12,7 +12,7 @@
|
||||
@protocol SPUDownloaderDelegate;
|
||||
|
||||
// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
|
||||
@interface SPUDownloader : NSObject <SPUDownloaderProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUDownloader : NSObject <SPUDownloaderProtocol>
|
||||
|
||||
// Due to XPC remote object reasons, this delegate is strongly referenced
|
||||
// Invoke cleanup when done with this instance
|
||||
|
||||
+72
-79
@@ -25,31 +25,24 @@ typedef NS_ENUM(NSUInteger, SPUDownloadMode)
|
||||
static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
|
||||
@interface SPUDownloader () <NSURLSessionDownloadDelegate>
|
||||
|
||||
// Delegate is intentionally strongly referenced; see header
|
||||
@property (nonatomic) id <SPUDownloaderDelegate> delegate;
|
||||
@property (nonatomic) NSURLSessionDownloadTask *download;
|
||||
@property (nonatomic) NSURLSession *downloadSession;
|
||||
@property (nonatomic, copy) NSString *bundleIdentifier;
|
||||
@property (nonatomic, copy) NSString *desiredFilename;
|
||||
@property (nonatomic, copy) NSString *downloadFilename;
|
||||
@property (nonatomic) BOOL disabledAutomaticTermination;
|
||||
@property (nonatomic) SPUDownloadMode mode;
|
||||
@property (nonatomic) BOOL receivedExpectedBytes;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUDownloader
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize download = _download;
|
||||
@synthesize downloadSession = _downloadSession;
|
||||
@synthesize bundleIdentifier = _bundleIdentifier;
|
||||
@synthesize desiredFilename = _desiredFilename;
|
||||
@synthesize downloadFilename = _downloadFilename;
|
||||
@synthesize disabledAutomaticTermination = _disabledAutomaticTermination;
|
||||
@synthesize mode = _mode;
|
||||
@synthesize receivedExpectedBytes = _receivedExpectedBytes;
|
||||
{
|
||||
NSURLSessionDownloadTask *_download;
|
||||
NSURLSession *_downloadSession;
|
||||
NSString *_bundleIdentifier;
|
||||
NSString *_desiredFilename;
|
||||
NSString *_downloadFilename;
|
||||
|
||||
// Delegate is intentionally strongly referenced; see header
|
||||
id <SPUDownloaderDelegate> _delegate;
|
||||
|
||||
SPUDownloadMode _mode;
|
||||
|
||||
BOOL _disabledAutomaticTermination;
|
||||
BOOL _receivedExpectedBytes;
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id <SPUDownloaderDelegate>)delegate
|
||||
{
|
||||
@@ -60,14 +53,14 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startDownloadWithRequest:(NSURLRequest *)request
|
||||
- (void)startDownloadWithRequest:(NSURLRequest *)request SPU_OBJC_DIRECT
|
||||
{
|
||||
self.downloadSession = [NSURLSession
|
||||
_downloadSession = [NSURLSession
|
||||
sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]
|
||||
delegate:self
|
||||
delegateQueue:[NSOperationQueue mainQueue]];
|
||||
self.download = [self.downloadSession downloadTaskWithRequest:request];
|
||||
[self.download resume];
|
||||
_download = [_downloadSession downloadTaskWithRequest:request];
|
||||
[_download resume];
|
||||
}
|
||||
|
||||
// Don't implement dealloc - make the client call cleanup, which is the only way to remove the reference cycle from the delegate anyway
|
||||
@@ -75,14 +68,14 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
- (void)startPersistentDownloadWithRequest:(NSURLRequest *)request bundleIdentifier:(NSString *)bundleIdentifier desiredFilename:(NSString *)desiredFilename
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.download == nil && self.delegate != nil) {
|
||||
if (self->_download == nil && self->_delegate != nil) {
|
||||
// Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks
|
||||
[[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason];
|
||||
self.disabledAutomaticTermination = YES;
|
||||
self->_disabledAutomaticTermination = YES;
|
||||
|
||||
self.mode = SPUDownloadModePersistent;
|
||||
self.desiredFilename = desiredFilename;
|
||||
self.bundleIdentifier = bundleIdentifier;
|
||||
self->_mode = SPUDownloadModePersistent;
|
||||
self->_desiredFilename = desiredFilename;
|
||||
self->_bundleIdentifier = [bundleIdentifier copy];
|
||||
|
||||
[self startDownloadWithRequest:request];
|
||||
}
|
||||
@@ -92,26 +85,26 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
- (void)startTemporaryDownloadWithRequest:(NSURLRequest *)request
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.download == nil && self.delegate != nil) {
|
||||
if (self->_download == nil && self->_delegate != nil) {
|
||||
// Prevent service from automatically terminating while downloading the update asynchronously without any reply blocks
|
||||
[[NSProcessInfo processInfo] disableAutomaticTermination:SUDownloadingReason];
|
||||
self.disabledAutomaticTermination = YES;
|
||||
self->_disabledAutomaticTermination = YES;
|
||||
|
||||
self.mode = SPUDownloadModeTemporary;
|
||||
self->_mode = SPUDownloadModeTemporary;
|
||||
[self startDownloadWithRequest:request];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)enableAutomaticTermination
|
||||
- (void)enableAutomaticTermination SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.disabledAutomaticTermination) {
|
||||
if (_disabledAutomaticTermination) {
|
||||
[[NSProcessInfo processInfo] enableAutomaticTermination:SUDownloadingReason];
|
||||
self.disabledAutomaticTermination = NO;
|
||||
_disabledAutomaticTermination = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)rootPersistentDownloadCachePathForBundleIdentifier:(NSString *)bundleIdentifier
|
||||
- (NSString *)rootPersistentDownloadCachePathForBundleIdentifier:(NSString *)bundleIdentifier SPU_OBJC_DIRECT
|
||||
{
|
||||
return [[SPULocalCacheDirectory cachePathForBundleIdentifier:bundleIdentifier] stringByAppendingPathComponent:@"PersistentDownloads"];
|
||||
}
|
||||
@@ -133,19 +126,19 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
});
|
||||
}
|
||||
|
||||
- (void)_cleanup
|
||||
- (void)_cleanup SPU_OBJC_DIRECT
|
||||
{
|
||||
[self enableAutomaticTermination];
|
||||
[self.download cancel];
|
||||
[self.downloadSession finishTasksAndInvalidate];
|
||||
self.download = nil;
|
||||
self.downloadSession = nil;
|
||||
self.delegate = nil;
|
||||
[_download cancel];
|
||||
[_downloadSession finishTasksAndInvalidate];
|
||||
_download = nil;
|
||||
_downloadSession = nil;
|
||||
_delegate = nil;
|
||||
|
||||
if (self.mode == SPUDownloadModeTemporary && self.downloadFilename != nil)
|
||||
if (_mode == SPUDownloadModeTemporary && _downloadFilename != nil)
|
||||
{
|
||||
[[NSFileManager defaultManager] removeItemAtPath:self.downloadFilename error:NULL];
|
||||
self.downloadFilename = nil;
|
||||
[[NSFileManager defaultManager] removeItemAtPath:_downloadFilename error:NULL];
|
||||
_downloadFilename = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,17 +158,17 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
{
|
||||
NSString *message = [NSString stringWithFormat:@"A network error occurred while downloading %@. %@ (%ld)", downloadTask.originalRequest.URL.absoluteString, [NSHTTPURLResponse localizedStringForStatusCode:statusCode], (long)statusCode];
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: message }];
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
[_delegate downloaderDidFailWithError:error];
|
||||
}
|
||||
else if (self.mode == SPUDownloadModeTemporary)
|
||||
else if (_mode == SPUDownloadModeTemporary)
|
||||
{
|
||||
self.downloadFilename = location.path;
|
||||
_downloadFilename = location.path;
|
||||
[self downloadDidFinish]; // file is already in a system temp dir
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove our old caches path so we don't start accumulating files in there
|
||||
NSString *rootPersistentDownloadCachePath = [self rootPersistentDownloadCachePathForBundleIdentifier:self.bundleIdentifier];
|
||||
NSString *rootPersistentDownloadCachePath = [self rootPersistentDownloadCachePathForBundleIdentifier:_bundleIdentifier];
|
||||
|
||||
[SPULocalCacheDirectory removeOldItemsInDirectory:rootPersistentDownloadCachePath];
|
||||
|
||||
@@ -183,23 +176,23 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
if (tempDir == nil)
|
||||
{
|
||||
// Okay, something's really broken with this user's file structure.
|
||||
[self.download cancel];
|
||||
self.download = nil;
|
||||
[_download cancel];
|
||||
_download = nil;
|
||||
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a temporary directory for the update download at %@.", tempDir] }];
|
||||
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
[_delegate downloaderDidFailWithError:error];
|
||||
} else {
|
||||
NSString *downloadFileName = self.desiredFilename;
|
||||
NSString *downloadFileName = _desiredFilename;
|
||||
NSString *downloadFileNameDirectory = [tempDir stringByAppendingPathComponent:downloadFileName];
|
||||
|
||||
NSError *createError = nil;
|
||||
if (![[NSFileManager defaultManager] createDirectoryAtPath:downloadFileNameDirectory withIntermediateDirectories:NO attributes:nil error:&createError]) {
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUTemporaryDirectoryError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Can't make a download file name %@ directory inside temporary directory for the update download at %@.", downloadFileName, downloadFileNameDirectory] }];
|
||||
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
[_delegate downloaderDidFailWithError:error];
|
||||
} else {
|
||||
NSString *name = self.download.response.suggestedFilename;
|
||||
NSString *name = _download.response.suggestedFilename;
|
||||
if (!name) {
|
||||
name = location.lastPathComponent; // This likely contains nothing useful to identify the file (e.g. CFNetworkDownload_87LVIz.tmp)
|
||||
}
|
||||
@@ -207,11 +200,11 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
NSString *fromPath = location.path; // suppress moveItemAtPath: non-null warning
|
||||
NSError *error = nil;
|
||||
if ([[NSFileManager defaultManager] moveItemAtPath:fromPath toPath:toPath error:&error]) {
|
||||
self.downloadFilename = toPath;
|
||||
[self.delegate downloaderDidSetDestinationName:name temporaryDirectory:downloadFileNameDirectory];
|
||||
_downloadFilename = toPath;
|
||||
[_delegate downloaderDidSetDestinationName:name temporaryDirectory:downloadFileNameDirectory];
|
||||
[self downloadDidFinish];
|
||||
} else {
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
[_delegate downloaderDidFailWithError:error];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -221,33 +214,33 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
- (void)URLSession:(NSURLSession *)__unused session downloadTask:(NSURLSessionDownloadTask *)__unused downloadTask didWriteData:(int64_t)bytesWritten totalBytesWritten:(int64_t)__unused totalBytesWritten totalBytesExpectedToWrite:(int64_t)totalBytesExpectedToWrite
|
||||
{
|
||||
|
||||
if (self.mode == SPUDownloadModePersistent && totalBytesExpectedToWrite > 0 && !self.receivedExpectedBytes) {
|
||||
self.receivedExpectedBytes = YES;
|
||||
[self.delegate downloaderDidReceiveExpectedContentLength:totalBytesExpectedToWrite];
|
||||
if (_mode == SPUDownloadModePersistent && totalBytesExpectedToWrite > 0 && !_receivedExpectedBytes) {
|
||||
_receivedExpectedBytes = YES;
|
||||
[_delegate downloaderDidReceiveExpectedContentLength:totalBytesExpectedToWrite];
|
||||
}
|
||||
|
||||
if (self.mode == SPUDownloadModePersistent && bytesWritten >= 0) {
|
||||
[self.delegate downloaderDidReceiveDataOfLength:(uint64_t)bytesWritten];
|
||||
if (_mode == SPUDownloadModePersistent && bytesWritten >= 0) {
|
||||
[_delegate downloaderDidReceiveDataOfLength:(uint64_t)bytesWritten];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish
|
||||
- (void)downloadDidFinish SPU_OBJC_DIRECT
|
||||
{
|
||||
assert(self.downloadFilename != nil);
|
||||
assert(_downloadFilename != nil);
|
||||
|
||||
SPUDownloadData *downloadData = nil;
|
||||
if (self.mode == SPUDownloadModeTemporary) {
|
||||
NSData *data = [NSData dataWithContentsOfFile:self.downloadFilename];
|
||||
if (_mode == SPUDownloadModeTemporary) {
|
||||
NSData *data = [NSData dataWithContentsOfFile:_downloadFilename];
|
||||
if (data != nil) {
|
||||
NSURLResponse *response = self.download.response;
|
||||
NSURLResponse *response = _download.response;
|
||||
assert(response != nil);
|
||||
|
||||
NSURL *responseURL = response.URL;
|
||||
if (responseURL == nil) {
|
||||
responseURL = self.download.currentRequest.URL;
|
||||
responseURL = _download.currentRequest.URL;
|
||||
}
|
||||
if (responseURL == nil) {
|
||||
responseURL = self.download.originalRequest.URL;
|
||||
responseURL = _download.originalRequest.URL;
|
||||
}
|
||||
assert(responseURL != nil);
|
||||
|
||||
@@ -255,29 +248,29 @@ static NSString *SUDownloadingReason = @"Downloading update related file";
|
||||
}
|
||||
}
|
||||
|
||||
self.download = nil;
|
||||
_download = nil;
|
||||
|
||||
switch (self.mode) {
|
||||
switch (_mode) {
|
||||
case SPUDownloadModeTemporary:
|
||||
if (downloadData != nil) {
|
||||
[self.delegate downloaderDidFinishWithTemporaryDownloadData:downloadData];
|
||||
[_delegate downloaderDidFinishWithTemporaryDownloadData:downloadData];
|
||||
} else {
|
||||
[self.delegate downloaderDidFailWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read temporary downloaded data from %@", self.downloadFilename]}]];
|
||||
[_delegate downloaderDidFailWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read temporary downloaded data from %@", _downloadFilename]}]];
|
||||
}
|
||||
|
||||
[self _cleanup];
|
||||
break;
|
||||
case SPUDownloadModePersistent:
|
||||
[self.delegate downloaderDidFinishWithTemporaryDownloadData:nil];
|
||||
[_delegate downloaderDidFinishWithTemporaryDownloadData:nil];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)URLSession:(NSURLSession *)__unused session task:(NSURLSessionTask *)__unused task didCompleteWithError:(NSError *)error
|
||||
{
|
||||
self.download = nil;
|
||||
_download = nil;
|
||||
if (error != nil) {
|
||||
[self.delegate downloaderDidFailWithError:error];
|
||||
[_delegate downloaderDidFailWithError:error];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
|
||||
@interface SUInstallerConnection : NSObject <SUInstallerConnectionProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUInstallerConnection : NSObject <SUInstallerConnectionProtocol>
|
||||
|
||||
// Due to XPC reasons, this delegate is strongly referenced, until it's invalidated
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate remote:(BOOL)remote;
|
||||
|
||||
@@ -14,26 +14,20 @@
|
||||
static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection Keep Alive";
|
||||
|
||||
@interface SUInstallerConnection () <SUInstallerCommunicationProtocol>
|
||||
|
||||
// Intentionally not weak for XPC reasons
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> delegate;
|
||||
|
||||
@property (nonatomic) BOOL disabledAutomaticTermination;
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUInstallerConnection
|
||||
{
|
||||
NSXPCConnection *_connection;
|
||||
// Intentionally not weak for XPC reasons
|
||||
id<SUInstallerCommunicationProtocol> _delegate;
|
||||
|
||||
void (^_invalidationBlock)(void);
|
||||
|
||||
BOOL _disabledAutomaticTermination;
|
||||
BOOL _remote;
|
||||
}
|
||||
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize disabledAutomaticTermination = _disabledAutomaticTermination;
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
@synthesize connection = _connection;
|
||||
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate remote:(BOOL)remote
|
||||
{
|
||||
self = [super init];
|
||||
@@ -50,17 +44,17 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)enableAutomaticTermination
|
||||
- (void)enableAutomaticTermination SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.disabledAutomaticTermination) {
|
||||
if (_disabledAutomaticTermination) {
|
||||
[[NSProcessInfo processInfo] enableAutomaticTermination:SUInstallerConnectionKeepAliveReason];
|
||||
self.disabledAutomaticTermination = NO;
|
||||
_disabledAutomaticTermination = NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
- (void)_setInvalidationHandler:(void (^)(void))invalidationHandler SPU_OBJC_DIRECT
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
_invalidationBlock = [invalidationHandler copy];
|
||||
|
||||
// No longer needed because of invalidation callback
|
||||
[self enableAutomaticTermination];
|
||||
@@ -77,36 +71,39 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
- (void)_setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain SPU_OBJC_DIRECT
|
||||
{
|
||||
NSXPCConnectionOptions options = systemDomain ? NSXPCConnectionPrivileged : 0;
|
||||
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:options];
|
||||
|
||||
connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
connection.exportedObject = self.delegate;
|
||||
connection.exportedObject = _delegate;
|
||||
|
||||
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerCommunicationProtocol)];
|
||||
|
||||
self.connection = connection;
|
||||
_connection = connection;
|
||||
|
||||
__weak SUInstallerConnection *weakSelf = self;
|
||||
self.connection.interruptionHandler = ^{
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
_connection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.connection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_connection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.connection.invalidationHandler = ^{
|
||||
_connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SUInstallerConnection *strongSelf = weakSelf;
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
strongSelf.connection = nil;
|
||||
strongSelf->_connection = nil;
|
||||
[strongSelf _invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[self.connection resume];
|
||||
[_connection resume];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
@@ -124,22 +121,22 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K
|
||||
{
|
||||
if (_remote) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[(id<SUInstallerCommunicationProtocol>)self.connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
[(id<SUInstallerCommunicationProtocol>)self->_connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
});
|
||||
} else {
|
||||
[(id<SUInstallerCommunicationProtocol>)self.connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
[(id<SUInstallerCommunicationProtocol>)_connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_invalidate
|
||||
- (void)_invalidate SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
if (_invalidationBlock != nil) {
|
||||
_invalidationBlock();
|
||||
_invalidationBlock = nil;
|
||||
}
|
||||
|
||||
// Break the retain cycle
|
||||
self.delegate = nil;
|
||||
_delegate = nil;
|
||||
|
||||
[self enableAutomaticTermination];
|
||||
}
|
||||
@@ -148,8 +145,8 @@ static NSString *SUInstallerConnectionKeepAliveReason = @"Installer Connection K
|
||||
- (void)invalidate
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
[self->_connection invalidate];
|
||||
self->_connection = nil;
|
||||
|
||||
[self _invalidate];
|
||||
});
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerConnectionProtocol.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SUXPCInstallerConnection : NSObject <SUInstallerConnectionProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUXPCInstallerConnection : NSObject <SUInstallerConnectionProtocol>
|
||||
|
||||
// Due to XPC reasons, this delegate is strongly referenced, until it's invalidated
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate;
|
||||
@@ -19,3 +21,5 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
|
||||
#endif
|
||||
@@ -6,24 +6,21 @@
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED
|
||||
|
||||
#import "SUXPCInstallerConnection.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUXPCInstallerConnection ()
|
||||
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
@property (nonatomic) id<SUInstallerCommunicationProtocol> delegate; // intentionally not weak for XPC reasons
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUXPCInstallerConnection
|
||||
|
||||
@synthesize connection = _connection;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
{
|
||||
NSXPCConnection *_connection;
|
||||
// Intentionally not weak for XPC reasons
|
||||
id<SUInstallerCommunicationProtocol> _delegate;
|
||||
|
||||
void (^_invalidationBlock)(void);
|
||||
}
|
||||
|
||||
- (instancetype)initWithDelegate:(id<SUInstallerCommunicationProtocol>)delegate
|
||||
{
|
||||
@@ -32,14 +29,17 @@
|
||||
_connection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_CONNECTION_BUNDLE_ID];
|
||||
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerConnectionProtocol)];
|
||||
|
||||
__weak SUXPCInstallerConnection *weakSelf = self;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
_connection.invalidationHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
};
|
||||
|
||||
_connection.interruptionHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
[weakSelf.connection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf invokeInvalidation];
|
||||
[strongSelf->_connection invalidate];
|
||||
}
|
||||
};
|
||||
|
||||
_delegate = delegate;
|
||||
@@ -54,39 +54,41 @@
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
_invalidationBlock = [invalidationHandler copy];
|
||||
|
||||
__weak SUXPCInstallerConnection *weakSelf = self;
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy setInvalidationHandler:^{
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[(id<SUInstallerConnectionProtocol>)_connection.remoteObjectProxy setInvalidationHandler:^{
|
||||
[weakSelf invokeInvalidation];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy setServiceName:serviceName systemDomain:systemDomain];
|
||||
[(id<SUInstallerConnectionProtocol>)_connection.remoteObjectProxy setServiceName:serviceName systemDomain:systemDomain];
|
||||
}
|
||||
|
||||
- (void)handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
[(id<SUInstallerConnectionProtocol>)_connection.remoteObjectProxy handleMessageWithIdentifier:identifier data:data];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
[(id<SUInstallerConnectionProtocol>)self.connection.remoteObjectProxy invalidate];
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
[(id<SUInstallerConnectionProtocol>)_connection.remoteObjectProxy invalidate];
|
||||
[_connection invalidate];
|
||||
_connection = nil;
|
||||
}
|
||||
|
||||
- (void)invokeInvalidation
|
||||
- (void)invokeInvalidation SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
if (_invalidationBlock != nil) {
|
||||
_invalidationBlock();
|
||||
_invalidationBlock = nil;
|
||||
}
|
||||
// Break our retain cycle
|
||||
self.delegate = nil;
|
||||
_delegate = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -9,10 +9,18 @@
|
||||
#ifndef SUInstallerLauncher_Private_h
|
||||
#define SUInstallerLauncher_Private_h
|
||||
|
||||
#if defined(BUILDING_SPARKLE_SOURCES_EXTERNALLY)
|
||||
// Ignore incorrect warning
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
|
||||
#import "SUExport.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#pragma clang diagnostic pop
|
||||
#else
|
||||
#import <Sparkle/SUExport.h>
|
||||
|
||||
// Chances are clients will need this too
|
||||
#import <Sparkle/SPUInstallationType.h>
|
||||
#endif
|
||||
|
||||
@class NSString;
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
@implementation SUInstallerLauncher
|
||||
|
||||
- (BOOL)submitProgressToolAtPath:(NSString *)progressToolPath withHostBundle:(NSBundle *)hostBundle inSystemDomainForInstaller:(BOOL)inSystemDomainForInstaller
|
||||
- (BOOL)submitProgressToolAtPath:(NSString *)progressToolPath withHostBundle:(NSBundle *)hostBundle inSystemDomainForInstaller:(BOOL)inSystemDomainForInstaller SPU_OBJC_DIRECT
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
return (submittedJob == true);
|
||||
}
|
||||
|
||||
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle updaterIdentifier:(NSString *)updaterIdentifier userName:(NSString *)userName homeDirectory:(NSString *)homeDirectory authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain rootUser:(BOOL)rootUser
|
||||
- (SUInstallerLauncherStatus)submitInstallerAtPath:(NSString *)installerPath withHostBundle:(NSBundle *)hostBundle updaterIdentifier:(NSString *)updaterIdentifier userName:(NSString *)userName homeDirectory:(NSString *)homeDirectory authorizationPrompt:(NSString *)authorizationPrompt inSystemDomain:(BOOL)systemDomain rootUser:(BOOL)rootUser SPU_OBJC_DIRECT
|
||||
{
|
||||
SUFileManager *fileManager = [[SUFileManager alloc] init];
|
||||
|
||||
@@ -208,15 +208,19 @@
|
||||
tempIconDestinationURL = [NSURL fileURLWithPath:path];
|
||||
|
||||
CGImageDestinationRef imageDestination = NULL;
|
||||
if (@available(macOS 11, *)) {
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
|
||||
if (@available(macOS 11, *))
|
||||
#endif
|
||||
{
|
||||
CFStringRef uti = (__bridge CFStringRef)[UTTypePNG identifier];
|
||||
imageDestination = CGImageDestinationCreateWithURL((CFURLRef)tempIconDestinationURL, uti, 1, NULL);
|
||||
} else {
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
|
||||
imageDestination = CGImageDestinationCreateWithURL((CFURLRef)tempIconDestinationURL, kUTTypePNG, 1, NULL);
|
||||
#pragma clang diagnostic pop
|
||||
}
|
||||
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_11_0
|
||||
else
|
||||
{
|
||||
imageDestination = CGImageDestinationCreateWithURL((CFURLRef)tempIconDestinationURL, kUTTypePNG, 1, NULL);
|
||||
}
|
||||
#endif
|
||||
if (imageDestination != NULL) {
|
||||
CGImageDestinationAddImageFromSource(imageDestination, imageSource, imageIndex, (CFDictionaryRef)@{});
|
||||
if (CGImageDestinationFinalize(imageDestination)) {
|
||||
@@ -310,7 +314,7 @@
|
||||
return status;
|
||||
}
|
||||
|
||||
- (NSString *)pathForBundledTool:(NSString *)toolName extension:(NSString *)extension fromBundle:(NSBundle *)bundle
|
||||
- (NSString *)pathForBundledTool:(NSString *)toolName extension:(NSString *)extension fromBundle:(NSBundle *)bundle SPU_OBJC_DIRECT
|
||||
{
|
||||
// If the path extension is empty, we don't want to add a "." at the end
|
||||
NSString *nameWithExtension = (extension.length > 0) ? [toolName stringByAppendingPathExtension:extension] : toolName;
|
||||
@@ -370,14 +374,21 @@ BOOL SPUSystemNeedsAuthorizationAccessForBundlePath(NSString *bundlePath)
|
||||
return needsAuthorization;
|
||||
}
|
||||
|
||||
static BOOL SPUUsesSystemDomainForBundlePath(NSString *path, NSString *installationType, BOOL rootUser)
|
||||
static BOOL SPUUsesSystemDomainForBundlePath(NSString *path, BOOL rootUser
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
, NSString *installationType
|
||||
#endif
|
||||
)
|
||||
{
|
||||
if (!rootUser) {
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
if ([installationType isEqualToString:SPUInstallationTypeGuidedPackage]) {
|
||||
return YES;
|
||||
} else if ([installationType isEqualToString:SPUInstallationTypeInteractivePackage]) {
|
||||
return NO;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
return SPUSystemNeedsAuthorizationAccessForBundlePath(path);
|
||||
}
|
||||
} else {
|
||||
@@ -396,7 +407,11 @@ static BOOL SPUUsesSystemDomainForBundlePath(NSString *path, NSString *installat
|
||||
// and that is not necessarily related to a preflight test. It's more related to being ran under a root / different user from the active GUI session
|
||||
BOOL rootUser = (geteuid() == 0);
|
||||
|
||||
BOOL inSystemDomain = SPUUsesSystemDomainForBundlePath(hostBundlePath, installationType, rootUser);
|
||||
BOOL inSystemDomain = SPUUsesSystemDomainForBundlePath(hostBundlePath, rootUser
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
, installationType
|
||||
#endif
|
||||
);
|
||||
|
||||
NSBundle *hostBundle = [NSBundle bundleWithPath:hostBundlePath];
|
||||
if (hostBundle == nil) {
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#import "SUInstallerStatusProtocol.h"
|
||||
|
||||
// This object implements the protocol which we have defined. It provides the actual behavior for the service. It is 'exported' by the service to make it available to the process hosting the service over an NSXPCConnection.
|
||||
@interface SUInstallerStatus : NSObject <SUInstallerStatusProtocol>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUInstallerStatus : NSObject <SUInstallerStatusProtocol>
|
||||
|
||||
- (instancetype)initWithRemote:(BOOL)remote;
|
||||
|
||||
|
||||
@@ -11,21 +11,15 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUInstallerStatus ()
|
||||
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUInstallerStatus
|
||||
{
|
||||
NSXPCConnection *_connection;
|
||||
|
||||
void (^_invalidationBlock)(void);
|
||||
|
||||
BOOL _remote;
|
||||
}
|
||||
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
@synthesize connection = _connection;
|
||||
|
||||
- (instancetype)initWithRemote:(BOOL)remote
|
||||
{
|
||||
self = [super init];
|
||||
@@ -39,39 +33,42 @@
|
||||
{
|
||||
if (_remote) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
self->_invalidationBlock = [invalidationHandler copy];
|
||||
});
|
||||
} else {
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
_invalidationBlock = [invalidationHandler copy];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_setServiceName:(NSString *)serviceName
|
||||
- (void)_setServiceName:(NSString *)serviceName SPU_OBJC_DIRECT
|
||||
{
|
||||
NSXPCConnection *connection = [[NSXPCConnection alloc] initWithMachServiceName:serviceName options:(NSXPCConnectionOptions)0];
|
||||
|
||||
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUStatusInfoProtocol)];
|
||||
|
||||
self.connection = connection;
|
||||
_connection = connection;
|
||||
|
||||
__weak SUInstallerStatus *weakSelf = self;
|
||||
self.connection.interruptionHandler = ^{
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
_connection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.connection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_connection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
self.connection.invalidationHandler = ^{
|
||||
_connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SUInstallerStatus *strongSelf = weakSelf;
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
strongSelf.connection = nil;
|
||||
strongSelf->_connection = nil;
|
||||
[strongSelf _invokeInvalidationBlock];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[self.connection resume];
|
||||
[_connection resume];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName
|
||||
@@ -89,10 +86,10 @@
|
||||
{
|
||||
if (_remote) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[(id<SUStatusInfoProtocol>)self.connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
[(id<SUStatusInfoProtocol>)self->_connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
});
|
||||
} else {
|
||||
[(id<SUStatusInfoProtocol>)self.connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
[(id<SUStatusInfoProtocol>)_connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,18 +97,18 @@
|
||||
{
|
||||
if (_remote) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[(id<SUStatusInfoProtocol>)self.connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
[(id<SUStatusInfoProtocol>)self->_connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
});
|
||||
} else {
|
||||
[(id<SUStatusInfoProtocol>)self.connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
[(id<SUStatusInfoProtocol>)_connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)_invokeInvalidationBlock
|
||||
- (void)_invokeInvalidationBlock SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
if (_invalidationBlock != nil) {
|
||||
_invalidationBlock();
|
||||
_invalidationBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,8 +116,8 @@
|
||||
- (void)invalidate
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
[self->_connection invalidate];
|
||||
self->_connection = nil;
|
||||
|
||||
[self _invokeInvalidationBlock];
|
||||
});
|
||||
|
||||
@@ -6,9 +6,13 @@
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if INSTALLER_STATUS_XPC_SERVICE_EMBEDDED
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "SUInstallerStatusProtocol.h"
|
||||
|
||||
@interface SUXPCInstallerStatus : NSObject <SUInstallerStatusProtocol>
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -6,22 +6,19 @@
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#if INSTALLER_STATUS_XPC_SERVICE_EMBEDDED
|
||||
|
||||
#import "SUXPCInstallerStatus.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SUXPCInstallerStatus ()
|
||||
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
@property (nonatomic, copy) void (^invalidationBlock)(void);
|
||||
|
||||
@end
|
||||
|
||||
@implementation SUXPCInstallerStatus
|
||||
|
||||
@synthesize connection = _connection;
|
||||
@synthesize invalidationBlock = _invalidationBlock;
|
||||
{
|
||||
NSXPCConnection *_connection;
|
||||
|
||||
void (^_invalidationBlock)(void);
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
@@ -30,14 +27,17 @@
|
||||
_connection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_STATUS_BUNDLE_ID];
|
||||
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerStatusProtocol)];
|
||||
|
||||
__weak SUXPCInstallerStatus *weakSelf = self;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
_connection.invalidationHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
};
|
||||
|
||||
_connection.interruptionHandler = ^{
|
||||
[weakSelf invokeInvalidation];
|
||||
[weakSelf.connection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf invokeInvalidation];
|
||||
[strongSelf->_connection invalidate];
|
||||
}
|
||||
};
|
||||
|
||||
[_connection resume];
|
||||
@@ -47,42 +47,44 @@
|
||||
|
||||
- (void)setInvalidationHandler:(void (^)(void))invalidationHandler
|
||||
{
|
||||
self.invalidationBlock = invalidationHandler;
|
||||
_invalidationBlock = [invalidationHandler copy];
|
||||
|
||||
__weak SUXPCInstallerStatus *weakSelf = self;
|
||||
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy setInvalidationHandler:^{
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[(id<SUInstallerStatusProtocol>)_connection.remoteObjectProxy setInvalidationHandler:^{
|
||||
[weakSelf invokeInvalidation];
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setServiceName:(NSString *)serviceName
|
||||
{
|
||||
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy setServiceName:serviceName];
|
||||
[(id<SUInstallerStatusProtocol>)_connection.remoteObjectProxy setServiceName:serviceName];
|
||||
}
|
||||
|
||||
- (void)probeStatusInfoWithReply:(void (^)(NSData * _Nullable installationInfoData))reply
|
||||
{
|
||||
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
[(id<SUInstallerStatusProtocol>)_connection.remoteObjectProxy probeStatusInfoWithReply:reply];
|
||||
}
|
||||
|
||||
- (void)probeStatusConnectivityWithReply:(void (^)(void))reply
|
||||
{
|
||||
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
[(id<SUInstallerStatusProtocol>)_connection.remoteObjectProxy probeStatusConnectivityWithReply:reply];
|
||||
}
|
||||
|
||||
- (void)invalidate
|
||||
{
|
||||
[(id<SUInstallerStatusProtocol>)self.connection.remoteObjectProxy invalidate];
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
[(id<SUInstallerStatusProtocol>)_connection.remoteObjectProxy invalidate];
|
||||
[_connection invalidate];
|
||||
_connection = nil;
|
||||
}
|
||||
|
||||
- (void)invokeInvalidation
|
||||
{
|
||||
if (self.invalidationBlock != nil) {
|
||||
self.invalidationBlock();
|
||||
self.invalidationBlock = nil;
|
||||
if (_invalidationBlock != nil) {
|
||||
_invalidationBlock();
|
||||
_invalidationBlock = nil;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -165,6 +165,12 @@
|
||||
721D8A861D4ADFEB0032E472 /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; };
|
||||
721D8A871D4C5BF10032E472 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; };
|
||||
722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */ = {isa = PBXBuildFile; fileRef = 722545B526805FF80036465C /* testappcast_info_updates.xml */; };
|
||||
72266A872946359600645376 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
72266A88294635BA00645376 /* SUAppcastDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72B767C91C9B707000A07552 /* SUAppcastDriver.m */; };
|
||||
72266A89294636FB00645376 /* SUStandardVersionComparator.m in Sources */ = {isa = PBXBuildFile; fileRef = 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */; };
|
||||
72266A8A2946493C00645376 /* SUCodeSigningVerifier.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5991D3D8A5A00D1BF90 /* SUCodeSigningVerifier.m */; };
|
||||
72266A8B29464CEA00645376 /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; };
|
||||
72266A8C29464D0200645376 /* SUSignatures.m in Sources */ = {isa = PBXBuildFile; fileRef = EA1E286D22B665E8004AA304 /* SUSignatures.m */; };
|
||||
7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */; };
|
||||
7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B71C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h */; };
|
||||
7229E1BA1C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7229E1B81C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m */; };
|
||||
@@ -194,8 +200,6 @@
|
||||
723C8A561E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */ = {isa = PBXBuildFile; fileRef = 723C8A531E2D60DB00C14942 /* SUTouchBarButtonGroup.m */; };
|
||||
723EDC3F26885A8E000BCBA4 /* testappcast_channels.xml in Resources */ = {isa = PBXBuildFile; fileRef = 723EDC3E26885A8E000BCBA4 /* testappcast_channels.xml */; };
|
||||
72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
|
||||
72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
|
||||
72464F721E1F327C00FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
|
||||
72464F7C1E2097F600FB341C /* SUOperatingSystem.m in Sources */ = {isa = PBXBuildFile; fileRef = 726F2CE41BC9C33D001971A4 /* SUOperatingSystem.m */; };
|
||||
72464F7E1E21ED8C00FB341C /* SUHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 61EF67550E25B58D00F754E0 /* SUHost.m */; };
|
||||
7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7246E0A11C83B685003B4E75 /* SPUStandardUpdaterController.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -420,8 +424,6 @@
|
||||
72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */; };
|
||||
72F9EBE21D517E2F004AC8B6 /* SUUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EBE01D517E2F004AC8B6 /* SUUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
72F9EBE31D517E2F004AC8B6 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EBE11D517E2F004AC8B6 /* SUUpdater.m */; };
|
||||
72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
72F9EC3F1D5E823F004AC8B6 /* SPUUpdaterTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC3D1D5E823F004AC8B6 /* SPUUpdaterTimer.h */; };
|
||||
72F9EC401D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */; };
|
||||
72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
@@ -1003,7 +1005,7 @@
|
||||
61F3AC1215C22D4A00260CA2 /* th */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = th; path = th.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
61F614540E24A12D009F47E7 /* it */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = it; path = it.lproj/Sparkle.strings; sourceTree = "<group>"; };
|
||||
7202DC99269ABD3500737EC4 /* testappcast_phasedRollout.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_phasedRollout.xml; sourceTree = "<group>"; };
|
||||
72045CE426FEE708004F96E5 /* strip-xpc-services.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "strip-xpc-services.sh"; sourceTree = "<group>"; };
|
||||
72045CE426FEE708004F96E5 /* strip-framework.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "strip-framework.sh"; sourceTree = "<group>"; };
|
||||
7205C43E1E13049400E370AE /* generate_appcast */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = generate_appcast; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
7205C4401E13049400E370AE /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||
7205C4461E1304C300E370AE /* Bridging-Header.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
@@ -1324,6 +1326,7 @@
|
||||
729F7EAD273F1840004592DC /* SPUUserAgent+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUUserAgent+Private.h"; sourceTree = "<group>"; };
|
||||
729F7EAE273F1840004592DC /* SPUUserAgent+Private.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "SPUUserAgent+Private.m"; sourceTree = "<group>"; };
|
||||
729F7ECD27409076004592DC /* SparkleTestCodeSignApp_bad_extraneous.zip */ = {isa = PBXFileReference; lastKnownFileType = archive.zip; path = SparkleTestCodeSignApp_bad_extraneous.zip; sourceTree = "<group>"; };
|
||||
72A40F082956120D007C7DD5 /* ConfigFrameworkRelease.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigFrameworkRelease.xcconfig; sourceTree = "<group>"; };
|
||||
72A450511C69A68900D67EEA /* SUUpdatePermissionResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdatePermissionResponse.h; sourceTree = "<group>"; };
|
||||
72A450521C69A68900D67EEA /* SUUpdatePermissionResponse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdatePermissionResponse.m; sourceTree = "<group>"; };
|
||||
72A4A23F1BB6567D00E7820D /* SUFileManagerTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUFileManagerTest.swift; sourceTree = "<group>"; };
|
||||
@@ -2422,6 +2425,7 @@
|
||||
72F94ED61CC344A7002DEE68 /* ConfigDownloaderDebug.xcconfig */,
|
||||
FA1941D10D94A70100DD942E /* ConfigFramework.xcconfig */,
|
||||
FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */,
|
||||
72A40F082956120D007C7DD5 /* ConfigFrameworkRelease.xcconfig */,
|
||||
724BB37E1D31D1EA005D534A /* ConfigInstallerConnection.xcconfig */,
|
||||
724BB37F1D31D1EA005D534A /* ConfigInstallerConnectionDebug.xcconfig */,
|
||||
726E07C11CAF1E79001A286B /* ConfigInstallerLauncher.xcconfig */,
|
||||
@@ -2451,7 +2455,7 @@
|
||||
EA1E285922B6622E004AA304 /* ed25519-Shared.xcconfig */,
|
||||
14732BC91960F70A00593899 /* make-release-package.sh */,
|
||||
14652F7919A93E5F00959E44 /* set-git-version-info.sh */,
|
||||
72045CE426FEE708004F96E5 /* strip-xpc-services.sh */,
|
||||
72045CE426FEE708004F96E5 /* strip-framework.sh */,
|
||||
720C192827127A3800740C8E /* release-move-tag.sh */,
|
||||
720B4C2325EBFAFD005A0592 /* link-tools.sh */,
|
||||
146EC84E19A68CF8004A50C5 /* Sparkle.podspec */,
|
||||
@@ -2826,7 +2830,7 @@
|
||||
8DC2EF520486A6940098B216 /* Resources */,
|
||||
142E0E0319A6A24100E4312B /* Copy Tools */,
|
||||
72045CDF26FEE51D004F96E5 /* Copy XPC Services */,
|
||||
72045CE626FEE8CC004F96E5 /* Strip XPC Services */,
|
||||
72045CE626FEE8CC004F96E5 /* Strip Framework */,
|
||||
8DC2EF540486A6940098B216 /* Sources */,
|
||||
8DC2EF560486A6940098B216 /* Frameworks */,
|
||||
6131B1910DDCDE32005215F0 /* Run Script: Set Git Version Info */,
|
||||
@@ -3217,7 +3221,7 @@
|
||||
shellScript = "\"$SRCROOT/Configurations/set-git-version-info.sh\"\n";
|
||||
showEnvVarsInLog = 0;
|
||||
};
|
||||
72045CE626FEE8CC004F96E5 /* Strip XPC Services */ = {
|
||||
72045CE626FEE8CC004F96E5 /* Strip Framework */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
alwaysOutOfDate = 1;
|
||||
buildActionMask = 2147483647;
|
||||
@@ -3227,14 +3231,14 @@
|
||||
);
|
||||
inputPaths = (
|
||||
);
|
||||
name = "Strip XPC Services";
|
||||
name = "Strip Framework";
|
||||
outputFileListPaths = (
|
||||
);
|
||||
outputPaths = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
shellPath = /bin/sh;
|
||||
shellScript = "\"$SRCROOT/Configurations/strip-xpc-services.sh\"\n";
|
||||
shellScript = "\"$SRCROOT/Configurations/strip-framework.sh\"\n";
|
||||
};
|
||||
720B4C2125EBFAA5005A0592 /* Run Script: Link Tools */ = {
|
||||
isa = PBXShellScriptBuildPhase;
|
||||
@@ -3296,6 +3300,12 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72266A8C29464D0200645376 /* SUSignatures.m in Sources */,
|
||||
72266A8B29464CEA00645376 /* SUHost.m in Sources */,
|
||||
72266A8A2946493C00645376 /* SUCodeSigningVerifier.m in Sources */,
|
||||
72266A89294636FB00645376 /* SUStandardVersionComparator.m in Sources */,
|
||||
72266A88294635BA00645376 /* SUAppcastDriver.m in Sources */,
|
||||
72266A872946359600645376 /* SUFileManager.m in Sources */,
|
||||
725EE488277D398100D820CE /* SPUDeltaArchive.m in Sources */,
|
||||
725EE483277C767A00D820CE /* SPUXarDeltaArchive.m in Sources */,
|
||||
7269E4982648D3460088C213 /* SPUSkippedUpdate.m in Sources */,
|
||||
@@ -3417,7 +3427,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
724BB3731D31D0B7005D534A /* main.m in Sources */,
|
||||
72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */,
|
||||
724BB3711D31D0B7005D534A /* SUInstallerConnection.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -3427,7 +3436,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
724BB39A1D333832005D534A /* main.m in Sources */,
|
||||
72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */,
|
||||
724BB3981D333832005D534A /* SUInstallerStatus.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -3445,7 +3453,6 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72464F7E1E21ED8C00FB341C /* SUHost.m in Sources */,
|
||||
72464F711E1F326A00FB341C /* SUOperatingSystem.m in Sources */,
|
||||
726E07B41CAF08D6001A286B /* main.m in Sources */,
|
||||
721D8A7B1D4963190032E472 /* SPULocalCacheDirectory.m in Sources */,
|
||||
7267E5E11D3D901600D1BF90 /* SPUMessageTypes.m in Sources */,
|
||||
@@ -3462,7 +3469,6 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72464F721E1F327C00FB341C /* SUOperatingSystem.m in Sources */,
|
||||
723B5DA71CF7AB0100365F95 /* main.m in Sources */,
|
||||
72E539121D68C3FA0092CE5E /* SPUDownloadData.m in Sources */,
|
||||
723B5DA91CF7AB0100365F95 /* SPUDownloader.m in Sources */,
|
||||
@@ -4112,7 +4118,7 @@
|
||||
};
|
||||
1DEB91AF08733DA50010E9CD /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
baseConfigurationReference = FA1941D10D94A70100DD942E /* ConfigFramework.xcconfig */;
|
||||
baseConfigurationReference = 72A40F082956120D007C7DD5 /* ConfigFrameworkRelease.xcconfig */;
|
||||
buildSettings = {
|
||||
};
|
||||
name = Release;
|
||||
|
||||
Vendored
+9
-9
@@ -1,20 +1,20 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21208.1" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21208.1"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SUUpdateAlert">
|
||||
<connections>
|
||||
<outlet property="automaticallyInstallUpdatesButton" destination="117" id="o2H-xw-Qv8"/>
|
||||
<outlet property="descriptionField" destination="101" id="9oA-2S-eXN"/>
|
||||
<outlet property="installButton" destination="76" id="176"/>
|
||||
<outlet property="laterButton" destination="22" id="177"/>
|
||||
<outlet property="releaseNotesBoxView" destination="89" id="FhX-K4-uzH"/>
|
||||
<outlet property="releaseNotesContainerView" destination="fKC-QA-GZa" id="BYw-MA-Z5h"/>
|
||||
<outlet property="skipButton" destination="23" id="178"/>
|
||||
<outlet property="_automaticallyInstallUpdatesButton" destination="117" id="IBi-aO-qkM"/>
|
||||
<outlet property="_descriptionField" destination="101" id="JkK-Xy-kns"/>
|
||||
<outlet property="_installButton" destination="76" id="GVS-sG-rgG"/>
|
||||
<outlet property="_laterButton" destination="22" id="dk6-u6-yYI"/>
|
||||
<outlet property="_releaseNotesBoxView" destination="89" id="kwH-2g-hlh"/>
|
||||
<outlet property="_releaseNotesContainerView" destination="fKC-QA-GZa" id="j3k-Pl-zNb"/>
|
||||
<outlet property="_skipButton" destination="23" id="PPe-jC-Pvc"/>
|
||||
<outlet property="window" destination="5" id="69"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
|
||||
+12
-12
@@ -8,17 +8,17 @@
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="SUUpdatePermissionPrompt">
|
||||
<connections>
|
||||
<outlet property="anonymousInfoDisclosureButton" destination="JW6-0z-Ud3" id="8Ac-kJ-T5e"/>
|
||||
<outlet property="automaticallyDownloadUpdatesView" destination="37T-Ef-DtX" id="7VP-FF-3iP"/>
|
||||
<outlet property="cancelButton" destination="cFC-wV-H3j" id="L2P-Ux-4Vn"/>
|
||||
<outlet property="checkButton" destination="sMh-ha-r7R" id="2O6-G4-etk"/>
|
||||
<outlet property="infoChoiceView" destination="ov1-yV-Uol" id="A1X-Y9-Hnh"/>
|
||||
<outlet property="moreInfoView" destination="39" id="127"/>
|
||||
<outlet property="placeholderHeightLayoutConstraint" destination="yis-HR-OIe" id="odJ-KG-SRB"/>
|
||||
<outlet property="placeholderView" destination="AGr-V0-0al" id="piB-Wg-PJx"/>
|
||||
<outlet property="promptView" destination="Yrl-Dt-Qvb" id="2a4-nD-uDx"/>
|
||||
<outlet property="responseView" destination="0CP-x7-YFK" id="fE5-5k-8Uf"/>
|
||||
<outlet property="stackView" destination="qNw-uD-4Bg" id="DxM-SL-1Xl"/>
|
||||
<outlet property="_anonymousInfoDisclosureButton" destination="JW6-0z-Ud3" id="grm-Uj-KJs"/>
|
||||
<outlet property="_automaticallyDownloadUpdatesView" destination="37T-Ef-DtX" id="Ojd-zE-6Kd"/>
|
||||
<outlet property="_cancelButton" destination="cFC-wV-H3j" id="B1o-H0-cr1"/>
|
||||
<outlet property="_checkButton" destination="sMh-ha-r7R" id="2Oc-EC-EcG"/>
|
||||
<outlet property="_infoChoiceView" destination="ov1-yV-Uol" id="RSd-bn-7bu"/>
|
||||
<outlet property="_moreInfoView" destination="39" id="ceJ-4H-FHd"/>
|
||||
<outlet property="_placeholderHeightLayoutConstraint" destination="yis-HR-OIe" id="npL-hg-wRq"/>
|
||||
<outlet property="_placeholderView" destination="AGr-V0-0al" id="UnQ-rl-QSS"/>
|
||||
<outlet property="_promptView" destination="Yrl-Dt-Qvb" id="qbO-fw-1YD"/>
|
||||
<outlet property="_responseView" destination="0CP-x7-YFK" id="AcW-Md-hSP"/>
|
||||
<outlet property="_stackView" destination="qNw-uD-4Bg" id="EIt-kn-pJ0"/>
|
||||
<outlet property="window" destination="5" id="126"/>
|
||||
</connections>
|
||||
</customObject>
|
||||
@@ -357,7 +357,7 @@ Gw
|
||||
<font key="font" metaFont="smallSystem"/>
|
||||
</buttonCell>
|
||||
<connections>
|
||||
<binding destination="-2" name="value" keyPath="self.automaticallyDownloadUpdates" id="V01-B1-yEx"/>
|
||||
<binding destination="-2" name="value" keyPath="automaticallyDownloadUpdates" id="5Me-7t-mMu"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
|
||||
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@protocol InstallerProgressDelegate;
|
||||
|
||||
@interface InstallerProgressAppController : NSObject <NSApplicationDelegate>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface InstallerProgressAppController : NSObject <NSApplicationDelegate>
|
||||
|
||||
- (instancetype)initWithApplication:(NSApplication *)application arguments:(NSArray<NSString *> *)arguments delegate:(id<InstallerProgressDelegate>)delegate;
|
||||
|
||||
|
||||
+67
-78
@@ -30,44 +30,30 @@
|
||||
static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
|
||||
@interface InstallerProgressAppController () <NSApplicationDelegate, SPUInstallerAgentProtocol>
|
||||
|
||||
@property (nonatomic, readonly) NSApplication *application;
|
||||
@property (nonatomic, weak) id<InstallerProgressDelegate> delegate;
|
||||
@property (nonatomic, readonly) NSXPCConnection *connection;
|
||||
@property (nonatomic) BOOL connected;
|
||||
@property (nonatomic) BOOL repliedToRegistration;
|
||||
@property (nonatomic, readonly) SUHost *oldHost;
|
||||
@property (nonatomic, readonly) BOOL shouldRelaunchHostBundle;
|
||||
@property (nonatomic, readonly) NSString *oldHostBundlePath;
|
||||
@property (nonatomic, readonly) BOOL systemDomain;
|
||||
@property (nonatomic) StatusInfo *statusInfo;
|
||||
@property (nonatomic) BOOL submittedLauncherJob;
|
||||
@property (nonatomic) BOOL willTerminate;
|
||||
@property (nonatomic) BOOL applicationInitiallyAlive;
|
||||
@property (nonatomic) NSBundle *applicationBundle;
|
||||
@property (nonatomic) NSString *normalizedPath;
|
||||
|
||||
@end
|
||||
|
||||
#define CONNECTION_ACKNOWLEDGEMENT_TIMEOUT 7ull
|
||||
|
||||
@implementation InstallerProgressAppController
|
||||
|
||||
@synthesize application = _application;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize connection = _connection;
|
||||
@synthesize connected = _connected;
|
||||
@synthesize repliedToRegistration = _repliedToRegistration;
|
||||
@synthesize oldHost = _oldHost;
|
||||
@synthesize shouldRelaunchHostBundle = _shouldRelaunchHostBundle;
|
||||
@synthesize oldHostBundlePath = _oldHostBundlePath;
|
||||
@synthesize systemDomain = _systemDomain;
|
||||
@synthesize statusInfo = _statusInfo;
|
||||
@synthesize submittedLauncherJob = _submittedLauncherJob;
|
||||
@synthesize willTerminate = _willTerminate;
|
||||
@synthesize applicationInitiallyAlive = _applicationInitiallyAlive;
|
||||
@synthesize applicationBundle = _applicationBundle;
|
||||
@synthesize normalizedPath = _normalizedPath;
|
||||
{
|
||||
NSApplication *_application;
|
||||
NSXPCConnection *_connection;
|
||||
SUHost *_oldHost;
|
||||
NSString *_oldHostBundlePath;
|
||||
StatusInfo *_statusInfo;
|
||||
NSBundle *_applicationBundle;
|
||||
NSString *_normalizedPath;
|
||||
|
||||
__weak id<InstallerProgressDelegate> _delegate;
|
||||
|
||||
BOOL _connected;
|
||||
BOOL _repliedToRegistration;
|
||||
BOOL _shouldRelaunchHostBundle;
|
||||
BOOL _systemDomain;
|
||||
BOOL _submittedLauncherJob;
|
||||
BOOL _willTerminate;
|
||||
BOOL _applicationInitiallyAlive;
|
||||
}
|
||||
|
||||
- (instancetype)initWithApplication:(NSApplication *)application arguments:(NSArray<NSString *> *)arguments delegate:(id<InstallerProgressDelegate>)delegate
|
||||
{
|
||||
@@ -126,25 +112,28 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
|
||||
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerAgentInitiationProtocol)];
|
||||
|
||||
__weak InstallerProgressAppController *weakSelf = self;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
_connection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.connection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_connection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
_connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
InstallerProgressAppController *strongSelf = weakSelf;
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
int exitStatus = (strongSelf.repliedToRegistration ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
int exitStatus = (strongSelf->_repliedToRegistration ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
NSError *registrationError;
|
||||
if (!strongSelf.repliedToRegistration) {
|
||||
if (!strongSelf->_repliedToRegistration) {
|
||||
registrationError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAgentInvalidationError userInfo:@{ NSLocalizedDescriptionKey: @"Error: Agent Invalidating without having the chance to reply to installer" }];
|
||||
} else {
|
||||
registrationError = nil;
|
||||
}
|
||||
if (!strongSelf.willTerminate) {
|
||||
if (!strongSelf->_willTerminate) {
|
||||
[strongSelf cleanupAndExitWithStatus:exitStatus error:registrationError];
|
||||
}
|
||||
}
|
||||
@@ -156,22 +145,22 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
|
||||
- (void)run
|
||||
{
|
||||
[self.application run];
|
||||
[_application run];
|
||||
}
|
||||
|
||||
- (void)startConnection
|
||||
- (void)startConnection SPU_OBJC_DIRECT
|
||||
{
|
||||
[self.statusInfo startListener];
|
||||
[_statusInfo startListener];
|
||||
|
||||
[self.connection resume];
|
||||
[(id<SUInstallerAgentInitiationProtocol>)self.connection.remoteObjectProxy connectionDidInitiateWithReply:^{
|
||||
[_connection resume];
|
||||
[(id<SUInstallerAgentInitiationProtocol>)_connection.remoteObjectProxy connectionDidInitiateWithReply:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.connected = YES;
|
||||
self->_connected = YES;
|
||||
});
|
||||
}];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(CONNECTION_ACKNOWLEDGEMENT_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!self.connected) {
|
||||
if (!self->_connected) {
|
||||
SULog(SULogLevelError, @"Timeout error: failed to receive acknowledgement from installer");
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:nil];
|
||||
}
|
||||
@@ -189,11 +178,11 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
SULog(SULogLevelError, @"Agent failed..");
|
||||
SULogError(error);
|
||||
|
||||
[(id<SUInstallerAgentInitiationProtocol>)self.connection.remoteObjectProxy connectionWillInvalidateWithError:error];
|
||||
[(id<SUInstallerAgentInitiationProtocol>)_connection.remoteObjectProxy connectionWillInvalidateWithError:error];
|
||||
}
|
||||
|
||||
[self.statusInfo invalidate];
|
||||
[self.connection invalidate];
|
||||
[_statusInfo invalidate];
|
||||
[_connection invalidate];
|
||||
|
||||
// Remove the agent bundle; it is assumed this bundle is in a temporary/cache/support directory
|
||||
NSError *theError = nil;
|
||||
@@ -217,7 +206,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
exit(status);
|
||||
}
|
||||
|
||||
- (NSArray<NSRunningApplication *> *)runningApplicationsWithBundle:(NSBundle *)bundle
|
||||
- (NSArray<NSRunningApplication *> *)runningApplicationsWithBundle:(NSBundle *)bundle SPU_OBJC_DIRECT
|
||||
{
|
||||
// Resolve symlinks otherwise when we compare file paths, we may not realize two paths that are represented differently are the same
|
||||
NSArray<NSString *> *bundlePathComponents = bundle.bundlePath.stringByResolvingSymlinksInPath.pathComponents;
|
||||
@@ -262,7 +251,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
- (void)registerApplicationBundlePath:(NSString *)applicationBundlePath reply:(void (^)(NSNumber *))reply
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (applicationBundlePath != nil && !self.willTerminate) {
|
||||
if (applicationBundlePath != nil && !self->_willTerminate) {
|
||||
NSBundle *applicationBundle = [NSBundle bundleWithPath:applicationBundlePath];
|
||||
if (applicationBundle == nil) {
|
||||
[self cleanupAndExitWithStatus:EXIT_FAILURE error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUAgentInvalidationError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Error: Encountered invalid path for waiting termination: %@", applicationBundlePath] }]];
|
||||
@@ -271,12 +260,12 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
// Compute normalized path that we may use later for relaunching the application
|
||||
// We compute normalized path from progress agent instead of trusting or having the installer
|
||||
// pass it to us
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME && [applicationBundle.bundlePath isEqualToString:self.oldHostBundlePath]) {
|
||||
NSString *normalizedPath = SUNormalizedInstallationPath(self.oldHost);
|
||||
if (SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME && [applicationBundle.bundlePath isEqualToString:self->_oldHostBundlePath]) {
|
||||
NSString *normalizedPath = SUNormalizedInstallationPath(self->_oldHost);
|
||||
// We only use normalized path if it doesn't already exist
|
||||
// Check the installer which has the same logic
|
||||
if (![[NSFileManager defaultManager] fileExistsAtPath:normalizedPath]) {
|
||||
self.normalizedPath = SUNormalizedInstallationPath(self.oldHost);
|
||||
self->_normalizedPath = SUNormalizedInstallationPath(self->_oldHost);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,9 +282,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
|
||||
reply(processIdentifier);
|
||||
|
||||
self.repliedToRegistration = YES;
|
||||
self.applicationBundle = applicationBundle;
|
||||
self.applicationInitiallyAlive = (processIdentifier != nil);
|
||||
self->_repliedToRegistration = YES;
|
||||
self->_applicationBundle = applicationBundle;
|
||||
self->_applicationInitiallyAlive = (processIdentifier != nil);
|
||||
} else {
|
||||
assert(false);
|
||||
}
|
||||
@@ -305,12 +294,12 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
- (void)registerInstallationInfoData:(NSData *)installationInfoData
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.statusInfo.installationInfoData == nil && installationInfoData != nil) {
|
||||
if (self->_statusInfo.installationInfoData == nil && installationInfoData != nil) {
|
||||
SPUInstallationInfo *installationInfo = (SPUInstallationInfo *)SPUUnarchiveRootObjectSecurely(installationInfoData, [SPUInstallationInfo class]);
|
||||
|
||||
if (installationInfo != nil) {
|
||||
installationInfo.systemDomain = self.systemDomain;
|
||||
self.statusInfo.installationInfoData = SPUArchiveRootObjectSecurely(installationInfo);
|
||||
installationInfo.systemDomain = self->_systemDomain;
|
||||
self->_statusInfo.installationInfoData = SPUArchiveRootObjectSecurely(installationInfo);
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Error: Failed to decode initial installation info from installer: %@", installationInfoData);
|
||||
}
|
||||
@@ -321,9 +310,9 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
- (void)sendTerminationSignal
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.willTerminate && self.applicationBundle != nil) {
|
||||
if (!self->_willTerminate && self->_applicationBundle != nil) {
|
||||
// Note we are sending an Apple quit event, which gives the application or user a chance to delay or cancel the request, which is what we desire
|
||||
for (NSRunningApplication *runningApplication in [self runningApplicationsWithBundle:self.applicationBundle]) {
|
||||
for (NSRunningApplication *runningApplication in [self runningApplicationsWithBundle:self->_applicationBundle]) {
|
||||
[runningApplication terminate];
|
||||
}
|
||||
}
|
||||
@@ -333,15 +322,15 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
- (void)relaunchApplication
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.willTerminate && self.applicationBundle != nil && self.applicationInitiallyAlive) {
|
||||
if (!self->_willTerminate && self->_applicationBundle != nil && self->_applicationInitiallyAlive) {
|
||||
NSString *pathToRelaunch;
|
||||
if (self.normalizedPath != nil) {
|
||||
pathToRelaunch = self.normalizedPath;
|
||||
} else if (self.shouldRelaunchHostBundle) {
|
||||
// Use self.oldHostBundlePath because it was computed before self.oldHost could have been removed
|
||||
pathToRelaunch = self.oldHostBundlePath;
|
||||
if (self->_normalizedPath != nil) {
|
||||
pathToRelaunch = self->_normalizedPath;
|
||||
} else if (self->_shouldRelaunchHostBundle) {
|
||||
// Use self->_oldHostBundlePath because it was computed before self->_oldHost could have been removed
|
||||
pathToRelaunch = self->_oldHostBundlePath;
|
||||
} else {
|
||||
pathToRelaunch = self.applicationBundle.bundlePath;
|
||||
pathToRelaunch = self->_applicationBundle.bundlePath;
|
||||
}
|
||||
|
||||
// We should at least make sure we're opening a bundle
|
||||
@@ -358,7 +347,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
// Delay termination for a little bit to better increase the chance the updated application when relaunched will be the frontmost application
|
||||
// This is related to macOS activation issues when terminating a frontmost application happens right before launching another app
|
||||
|
||||
self.willTerminate = YES;
|
||||
self->_willTerminate = YES;
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(SUTerminationTimeDelay * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self cleanupAndExitWithStatus:EXIT_SUCCESS error:nil];
|
||||
});
|
||||
@@ -369,18 +358,18 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
- (void)showProgress
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (!self.willTerminate) {
|
||||
if (!self->_willTerminate) {
|
||||
// Show app icon in the dock
|
||||
ProcessSerialNumber psn = { 0, kCurrentProcess };
|
||||
TransformProcessType(&psn, kProcessTransformToForegroundApplication);
|
||||
|
||||
// Note: the application icon needs to be set after showing the icon in the dock
|
||||
self.application.applicationIconImage = [SUApplicationInfo bestIconForHost:self.oldHost];
|
||||
self->_application.applicationIconImage = [SUApplicationInfo bestIconForHost:self->_oldHost];
|
||||
|
||||
// Activate ourselves otherwise we will probably be in the background
|
||||
[self.application activateIgnoringOtherApps:YES];
|
||||
[self->_application activateIgnoringOtherApps:YES];
|
||||
|
||||
[self.delegate installerProgressShouldDisplayWithHost:self.oldHost];
|
||||
[self->_delegate installerProgressShouldDisplayWithHost:self->_oldHost];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -389,13 +378,13 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.3;
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Dismiss any UI immediately
|
||||
[self.delegate installerProgressShouldStop];
|
||||
self.delegate = nil;
|
||||
[self->_delegate installerProgressShouldStop];
|
||||
self->_delegate = nil;
|
||||
|
||||
// No need to broadcast status service anymore
|
||||
// In fact we shouldn't when we decide to relaunch the update
|
||||
[self.statusInfo invalidate];
|
||||
self.statusInfo = nil;
|
||||
[self->_statusInfo invalidate];
|
||||
self->_statusInfo = nil;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+36
-21
@@ -12,21 +12,14 @@
|
||||
#import "SUHost.h"
|
||||
#import "SULocalizations.h"
|
||||
|
||||
@interface ShowInstallerProgress ()
|
||||
|
||||
@property (nonatomic) SUStatusController *statusController;
|
||||
|
||||
@end
|
||||
|
||||
@implementation ShowInstallerProgress
|
||||
{
|
||||
SUStatusController *_statusController;
|
||||
NSString *_updatingString;
|
||||
NSString *_cancelUpdateTitle;
|
||||
NSString *_installingUpdateTitle;
|
||||
}
|
||||
|
||||
@synthesize statusController = _statusController;
|
||||
|
||||
- (void)loadLocalizationStringsFromHost:(SUHost *)host
|
||||
{
|
||||
// Try to retrieve localization strings from the old bundle if possible
|
||||
@@ -34,6 +27,7 @@
|
||||
// (which will be after the update is trusted)
|
||||
// If we fail to load localizations in any way, we default to English
|
||||
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
NSBundle *hostSparkleBundle;
|
||||
{
|
||||
NSURL *hostSparkleURL = [host.bundle.privateFrameworksURL URLByAppendingPathComponent:@"Sparkle.framework" isDirectory:YES];
|
||||
@@ -43,55 +37,76 @@
|
||||
hostSparkleBundle = [NSBundle bundleWithURL:hostSparkleURL];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NSString *updatingString;
|
||||
{
|
||||
NSString *updatingFormatStringFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Updating %@", @"Sparkle", hostSparkleBundle, nil) : nil;
|
||||
|
||||
NSString *hostNameFromBundle = host.name;
|
||||
NSString *hostName = (hostNameFromBundle != nil) ? hostNameFromBundle : @"";
|
||||
|
||||
if (updatingFormatStringFromBundle != nil) {
|
||||
// Replacing the %@ will be a bit safer than using +[NSString stringWithFormat:]
|
||||
updatingString = [updatingFormatStringFromBundle stringByReplacingOccurrencesOfString:@"%@" withString:hostName];
|
||||
} else {
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
{
|
||||
NSString *updatingFormatStringFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Updating %@", @"Sparkle", hostSparkleBundle, nil) : nil;
|
||||
|
||||
if (updatingFormatStringFromBundle != nil) {
|
||||
// Replacing the %@ will be a bit safer than using +[NSString stringWithFormat:]
|
||||
updatingString = [updatingFormatStringFromBundle stringByReplacingOccurrencesOfString:@"%@" withString:hostName];
|
||||
} else {
|
||||
updatingString = [@"Updating " stringByAppendingString:hostName];
|
||||
}
|
||||
}
|
||||
#else
|
||||
{
|
||||
updatingString = [@"Updating " stringByAppendingString:hostName];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
_updatingString = updatingString;
|
||||
|
||||
NSString *cancelUpdateTitle;
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
{
|
||||
NSString *cancelUpdateTitleFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Cancel Update", @"Sparkle", hostSparkleBundle, @"") : nil;
|
||||
cancelUpdateTitle = (cancelUpdateTitleFromBundle != nil) ? cancelUpdateTitleFromBundle : @"Cancel Update";
|
||||
}
|
||||
|
||||
#else
|
||||
{
|
||||
cancelUpdateTitle = @"Cancel Update";
|
||||
}
|
||||
#endif
|
||||
_cancelUpdateTitle = cancelUpdateTitle;
|
||||
|
||||
NSString *installingUpdateTitle;
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
{
|
||||
NSString *installingUpdateTitleFromBundle = (hostSparkleBundle != nil) ? SULocalizedStringFromTableInBundle(@"Installing update…", @"Sparkle", hostSparkleBundle, @"") : nil;
|
||||
installingUpdateTitle = (installingUpdateTitleFromBundle != nil) ? installingUpdateTitleFromBundle : @"Installing update…";
|
||||
}
|
||||
#else
|
||||
{
|
||||
installingUpdateTitle = @"Installing update…";
|
||||
}
|
||||
#endif
|
||||
|
||||
_installingUpdateTitle = installingUpdateTitle;
|
||||
}
|
||||
|
||||
- (void)installerProgressShouldDisplayWithHost:(SUHost *)host
|
||||
{
|
||||
self.statusController = [[SUStatusController alloc] initWithHost:host windowTitle:_updatingString centerPointValue:nil minimizable:NO closable:NO];
|
||||
_statusController = [[SUStatusController alloc] initWithHost:host windowTitle:_updatingString centerPointValue:nil minimizable:NO closable:NO];
|
||||
|
||||
[self.statusController setButtonTitle:_cancelUpdateTitle target:nil action:nil isDefault:NO];
|
||||
[self.statusController beginActionWithTitle:_installingUpdateTitle maxProgressValue:0 statusText:@""];
|
||||
[_statusController setButtonTitle:_cancelUpdateTitle target:nil action:nil isDefault:NO];
|
||||
|
||||
[self.statusController showWindow:self];
|
||||
[_statusController beginActionWithTitle:_installingUpdateTitle maxProgressValue:0 statusText:@""];
|
||||
|
||||
[_statusController showWindow:self];
|
||||
}
|
||||
|
||||
- (void)installerProgressShouldStop
|
||||
{
|
||||
[self.statusController close];
|
||||
self.statusController = nil;
|
||||
[_statusController close];
|
||||
_statusController = nil;
|
||||
}
|
||||
|
||||
@end
|
||||
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
// Appcast Item state that contains properties that depends on a host
|
||||
@interface SPUAppcastItemState : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUAppcastItemState : NSObject
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
|
||||
|
||||
Vendored
+5
-5
@@ -48,11 +48,11 @@
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)encoder
|
||||
{
|
||||
[encoder encodeBool:self.majorUpgrade forKey:SPUAppcastItemStateMajorUpgradeKey];
|
||||
[encoder encodeBool:self.criticalUpdate forKey:SPUAppcastItemStateCriticalUpdateKey];
|
||||
[encoder encodeBool:self.informationalUpdate forKey:SPUAppcastItemStateInformationalUpdateKey];
|
||||
[encoder encodeBool:self.minimumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey];
|
||||
[encoder encodeBool:self.maximumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey];
|
||||
[encoder encodeBool:_majorUpgrade forKey:SPUAppcastItemStateMajorUpgradeKey];
|
||||
[encoder encodeBool:_criticalUpdate forKey:SPUAppcastItemStateCriticalUpdateKey];
|
||||
[encoder encodeBool:_informationalUpdate forKey:SPUAppcastItemStateInformationalUpdateKey];
|
||||
[encoder encodeBool:_minimumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey];
|
||||
[encoder encodeBool:_maximumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey];
|
||||
}
|
||||
|
||||
- (instancetype)initWithCoder:(NSCoder *)decoder
|
||||
|
||||
+8
@@ -8,7 +8,15 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#if defined(BUILDING_SPARKLE_SOURCES_EXTERNALLY)
|
||||
// Ignore incorrect warning
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
|
||||
#import "SUExport.h"
|
||||
#pragma clang diagnostic pop
|
||||
#else
|
||||
#import <Sparkle/SUExport.h>
|
||||
#endif
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
||||
+11
-18
@@ -17,19 +17,12 @@
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SPUAppcastItemStateResolver ()
|
||||
|
||||
@property (nonatomic, readonly) NSString *hostVersion;
|
||||
@property (nonatomic, readonly) id<SUVersionComparison> applicationVersionComparator;
|
||||
@property (nonatomic, readonly) SUStandardVersionComparator *standardVersionComparator;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUAppcastItemStateResolver
|
||||
|
||||
@synthesize hostVersion = _hostVersion;
|
||||
@synthesize applicationVersionComparator = _applicationVersionComparator;
|
||||
@synthesize standardVersionComparator = _standardVersionComparator;
|
||||
{
|
||||
NSString *_hostVersion;
|
||||
id<SUVersionComparison> _applicationVersionComparator;
|
||||
SUStandardVersionComparator *_standardVersionComparator;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id<SUVersionComparison>)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator
|
||||
{
|
||||
@@ -46,7 +39,7 @@
|
||||
{
|
||||
BOOL minimumVersionOK = YES;
|
||||
if (minimumSystemVersion != nil && ![minimumSystemVersion isEqualToString:@""]) {
|
||||
minimumVersionOK = [self.standardVersionComparator compareVersion:(NSString * _Nonnull)minimumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending;
|
||||
minimumVersionOK = [_standardVersionComparator compareVersion:(NSString * _Nonnull)minimumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending;
|
||||
}
|
||||
return minimumVersionOK;
|
||||
}
|
||||
@@ -55,7 +48,7 @@
|
||||
{
|
||||
BOOL maximumVersionOK = YES;
|
||||
if (maximumSystemVersion != nil && ![maximumSystemVersion isEqualToString:@""]) {
|
||||
maximumVersionOK = [self.standardVersionComparator compareVersion:(NSString * _Nonnull)maximumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending;
|
||||
maximumVersionOK = [_standardVersionComparator compareVersion:(NSString * _Nonnull)maximumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending;
|
||||
}
|
||||
return maximumVersionOK;
|
||||
}
|
||||
@@ -67,7 +60,7 @@
|
||||
|
||||
- (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion
|
||||
{
|
||||
return [[self class] isMinimumAutoupdateVersionOK:minimumAutoupdateVersion hostVersion:self.hostVersion versionComparator:self.applicationVersionComparator];
|
||||
return [[self class] isMinimumAutoupdateVersionOK:minimumAutoupdateVersion hostVersion:_hostVersion versionComparator:_applicationVersionComparator];
|
||||
}
|
||||
|
||||
- (BOOL)isCriticalUpdateWithCriticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary
|
||||
@@ -84,7 +77,7 @@
|
||||
}
|
||||
|
||||
// Update is only critical when coming from previous versions
|
||||
return ([self.applicationVersionComparator compareVersion:self.hostVersion toVersion:criticalVersion] == NSOrderedAscending);
|
||||
return ([_applicationVersionComparator compareVersion:_hostVersion toVersion:criticalVersion] == NSOrderedAscending);
|
||||
}
|
||||
|
||||
- (BOOL)isInformationalUpdateWithInformationalUpdateVersions:(NSSet<NSString *> * _Nullable)informationalUpdateVersions
|
||||
@@ -98,7 +91,7 @@
|
||||
return YES;
|
||||
}
|
||||
|
||||
NSString *hostVersion = self.hostVersion;
|
||||
NSString *hostVersion = _hostVersion;
|
||||
|
||||
// Informational update only for a set of host versions we're updating from
|
||||
if ([informationalUpdateVersions containsObject:hostVersion]) {
|
||||
@@ -108,7 +101,7 @@
|
||||
// If an informational update version has a '<' prefix, this is an informational update if
|
||||
// hostVersion < this info update version
|
||||
for (NSString *informationalUpdateVersion in informationalUpdateVersions) {
|
||||
if ([informationalUpdateVersion hasPrefix:@"<"] && [self.applicationVersionComparator compareVersion:hostVersion toVersion:[informationalUpdateVersion substringFromIndex:1]] == NSOrderedAscending) {
|
||||
if ([informationalUpdateVersion hasPrefix:@"<"] && [_applicationVersionComparator compareVersion:hostVersion toVersion:[informationalUpdateVersion substringFromIndex:1]] == NSOrderedAscending) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@class SUHost;
|
||||
@protocol SPUUpdaterDelegate, SPUUserDriver;
|
||||
|
||||
@interface SPUAutomaticUpdateDriver : NSObject <SPUUpdateDriver>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUAutomaticUpdateDriver : NSObject <SPUUpdateDriver>
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater userDriver:(id <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate;
|
||||
|
||||
|
||||
Vendored
+27
-29
@@ -20,24 +20,19 @@
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SPUAutomaticUpdateDriver () <SPUCoreBasedUpdateDriverDelegate>
|
||||
|
||||
@property (nonatomic, readonly, weak) id updater;
|
||||
@property (nonatomic, readonly, weak) id<SPUUserDriver> userDriver;
|
||||
@property (nonatomic, readonly, weak, nullable) id updaterDelegate;
|
||||
@property (nonatomic, readonly) SPUCoreBasedUpdateDriver *coreDriver;
|
||||
@property (nonatomic) SUAppcastItem* updateItem;
|
||||
@property (nonatomic) BOOL willInstallSilently;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUAutomaticUpdateDriver
|
||||
|
||||
@synthesize updater = _updater;
|
||||
@synthesize userDriver = _userDriver;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize coreDriver = _coreDriver;
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize willInstallSilently = _willInstallSilently;
|
||||
{
|
||||
SPUCoreBasedUpdateDriver *_coreDriver;
|
||||
SUAppcastItem* _updateItem;
|
||||
|
||||
__weak id _updater;
|
||||
__weak id<SPUUserDriver> _userDriver;
|
||||
__weak id _updaterDelegate;
|
||||
|
||||
BOOL _willInstallSilently;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater userDriver:(id <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate
|
||||
{
|
||||
@@ -54,7 +49,7 @@
|
||||
|
||||
- (void)setCompletionHandler:(SPUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.coreDriver setCompletionHandler:completionBlock];
|
||||
[_coreDriver setCompletionHandler:completionBlock];
|
||||
}
|
||||
|
||||
- (void)setUpdateShownHandler:(void (^)(void))updateShownHandler
|
||||
@@ -63,12 +58,12 @@
|
||||
|
||||
- (void)setUpdateWillInstallHandler:(void (^)(void))updateWillInstallHandler
|
||||
{
|
||||
[self.coreDriver setUpdateWillInstallHandler:updateWillInstallHandler];
|
||||
[_coreDriver setUpdateWillInstallHandler:updateWillInstallHandler];
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders
|
||||
{
|
||||
[self.coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:YES requiresSilentInstall:YES];
|
||||
[_coreDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:YES requiresSilentInstall:YES];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdate
|
||||
@@ -85,13 +80,13 @@
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
_updateItem = updateItem;
|
||||
|
||||
if (updateItem.isInformationOnlyUpdate || updateItem.majorUpgrade) {
|
||||
[self.coreDriver deferInformationalUpdate:updateItem secondaryUpdate:secondaryUpdateItem];
|
||||
[_coreDriver deferInformationalUpdate:updateItem secondaryUpdate:secondaryUpdateItem];
|
||||
[self abortUpdate];
|
||||
} else {
|
||||
[self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:YES];
|
||||
[_coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:YES];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,16 +97,19 @@
|
||||
|
||||
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
|
||||
{
|
||||
self.willInstallSilently = willInstallSilently;
|
||||
_willInstallSilently = willInstallSilently;
|
||||
|
||||
if (!willInstallImmediately) {
|
||||
BOOL installationHandledByDelegate = NO;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = self.updaterDelegate;
|
||||
if (self.willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
|
||||
__weak SPUAutomaticUpdateDriver *weakSelf = self;
|
||||
installationHandledByDelegate = [updaterDelegate updater:self.updater willInstallUpdateOnQuit:self.updateItem immediateInstallationBlock:^{
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
if (_willInstallSilently && [updaterDelegate respondsToSelector:@selector(updater:willInstallUpdateOnQuit:immediateInstallationBlock:)]) {
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
installationHandledByDelegate = [updaterDelegate updater:_updater willInstallUpdateOnQuit:_updateItem immediateInstallationBlock:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[weakSelf.coreDriver finishInstallationWithResponse:SPUUserUpdateChoiceInstall displayingUserInterface:NO];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil) {
|
||||
[strongSelf->_coreDriver finishInstallationWithResponse:SPUUserUpdateChoiceInstall displayingUserInterface:NO];
|
||||
}
|
||||
});
|
||||
}];
|
||||
}
|
||||
@@ -141,9 +139,9 @@
|
||||
|
||||
- (void)abortUpdateWithError:(NSError *)error
|
||||
{
|
||||
BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.criticalUpdate || self.updateItem.isInformationOnlyUpdate);
|
||||
BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!_willInstallSilently || _updateItem.criticalUpdate || _updateItem.isInformationOnlyUpdate);
|
||||
|
||||
[self.coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error];
|
||||
[_coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error];
|
||||
}
|
||||
|
||||
@end
|
||||
Vendored
+1
-1
@@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
@interface SPUBasicUpdateDriver : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUBasicUpdateDriver : NSObject
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host updateCheck:(SPUUpdateCheck)updateCheck updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id <SPUBasicUpdateDriverDelegate>)delegate;
|
||||
|
||||
|
||||
Vendored
+90
-74
@@ -25,29 +25,23 @@
|
||||
|
||||
@interface SPUBasicUpdateDriver () <SUAppcastDriverDelegate>
|
||||
|
||||
@property (nonatomic, weak, readonly) id<SPUBasicUpdateDriverDelegate> delegate;
|
||||
@property (nonatomic, readonly) SUAppcastDriver *appcastDriver;
|
||||
@property (nonatomic, copy) SPUUpdateDriverCompletion completionBlock;
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, readonly) SPUUpdateCheck updateCheck;
|
||||
@property (nonatomic, readonly, weak) id updater; // if we didn't have legacy support, I'd remove this..
|
||||
@property (nullable, nonatomic, readonly, weak) id <SPUUpdaterDelegate>updaterDelegate;
|
||||
|
||||
@property (nonatomic) BOOL aborted;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUBasicUpdateDriver
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize updateCheck = _updateCheck;
|
||||
@synthesize updater = _updater;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize appcastDriver = _appcastDriver;
|
||||
@synthesize completionBlock = _completionBlock;
|
||||
@synthesize aborted = _aborted;
|
||||
{
|
||||
SUAppcastDriver *_appcastDriver;
|
||||
SUHost *_host;
|
||||
|
||||
SPUUpdateDriverCompletion _completionBlock;
|
||||
|
||||
SPUUpdateCheck _updateCheck;
|
||||
|
||||
__weak id _updater;
|
||||
__weak id <SPUUpdaterDelegate> _updaterDelegate;
|
||||
__weak id<SPUBasicUpdateDriverDelegate> _delegate;
|
||||
|
||||
BOOL _aborted;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host updateCheck:(SPUUpdateCheck)updateCheck updater:(id)updater updaterDelegate:(id <SPUUpdaterDelegate>)updaterDelegate delegate:(id <SPUBasicUpdateDriverDelegate>)delegate
|
||||
{
|
||||
@@ -66,27 +60,31 @@
|
||||
|
||||
- (void)setCompletionHandler:(SPUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
self.completionBlock = completionBlock;
|
||||
_completionBlock = [completionBlock copy];
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background
|
||||
{
|
||||
if ([self.host isRunningOnReadOnlyVolume]) {
|
||||
NSString *hostName = self.host.name;
|
||||
if ([self.host isRunningTranslocated]) {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningTranslocated userInfo:@{ NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithFormat:SULocalizedString(@"Quit %1$@, move it into your Applications folder, relaunch it from there and try again.", nil), hostName], NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can’t be updated if it’s running from the location it was downloaded to.", nil), hostName], }]];
|
||||
if ([_host isRunningOnReadOnlyVolume]) {
|
||||
NSString *hostName = _host.name;
|
||||
id<SPUBasicUpdateDriverDelegate> delegate = _delegate;
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
NSBundle *sparkleBundle = SUSparkleBundle();
|
||||
#endif
|
||||
if ([_host isRunningTranslocated]) {
|
||||
[delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningTranslocated userInfo:@{ NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"Quit %1$@, move it into your Applications folder, relaunch it from there and try again.", SPARKLE_TABLE, sparkleBundle, nil), hostName], NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%1$@ can’t be updated if it’s running from the location it was downloaded to.", SPARKLE_TABLE, sparkleBundle, nil), hostName], }]];
|
||||
} else {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can’t be updated, because it was opened from a read-only or a temporary location.", nil), hostName], NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithFormat:SULocalizedString(@"Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again.", nil), hostName] }]];
|
||||
[delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%1$@ can’t be updated, because it was opened from a read-only or a temporary location.", SPARKLE_TABLE, sparkleBundle, nil), hostName], NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again.", SPARKLE_TABLE, sparkleBundle, nil), hostName] }]];
|
||||
}
|
||||
} else {
|
||||
[self.appcastDriver loadAppcastFromURL:appcastURL userAgent:userAgent httpHeaders:httpHeaders inBackground:background];
|
||||
[_appcastDriver loadAppcastFromURL:appcastURL userAgent:userAgent httpHeaders:httpHeaders inBackground:background];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain
|
||||
- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain SPU_OBJC_DIRECT
|
||||
{
|
||||
if (updateItem == nil) {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]];
|
||||
[_delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"Failed to resume installing update.", SPARKLE_TABLE, SUSparkleBundle(), nil) }]];
|
||||
} else {
|
||||
// Kind of lying, but triggering the notification so drivers can know when to stop showing initial fetching progress
|
||||
[self notifyFinishLoadingAppcast];
|
||||
@@ -98,7 +96,7 @@
|
||||
|
||||
- (void)resumeInstallingUpdate
|
||||
{
|
||||
NSString *hostBundleIdentifier = self.host.bundle.bundleIdentifier;
|
||||
NSString *hostBundleIdentifier = _host.bundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
[SPUProbeInstallStatus probeInstallerUpdateItemForHostBundleIdentifier:hostBundleIdentifier completion:^(SPUInstallationInfo * _Nullable installationInfo) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
@@ -114,57 +112,66 @@
|
||||
|
||||
- (void)didFailToFetchAppcastWithError:(NSError *)error
|
||||
{
|
||||
if (!self.aborted) {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:error];
|
||||
if (!_aborted) {
|
||||
[_delegate basicDriverIsRequestingAbortUpdateWithError:error];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyFinishLoadingAppcast
|
||||
- (void)notifyFinishLoadingAppcast SPU_OBJC_DIRECT
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(basicDriverDidFinishLoadingAppcast)]) {
|
||||
[self.delegate basicDriverDidFinishLoadingAppcast];
|
||||
id<SPUBasicUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(basicDriverDidFinishLoadingAppcast)]) {
|
||||
[delegate basicDriverDidFinishLoadingAppcast];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)didFinishLoadingAppcast:(SUAppcast *)appcast
|
||||
{
|
||||
if (!self.aborted) {
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updater:didFinishLoadingAppcast:))]) {
|
||||
[self.updaterDelegate updater:self.updater didFinishLoadingAppcast:appcast];
|
||||
if (!_aborted) {
|
||||
id <SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
if ([updaterDelegate respondsToSelector:@selector((updater:didFinishLoadingAppcast:))]) {
|
||||
[updaterDelegate updater:_updater didFinishLoadingAppcast:appcast];
|
||||
}
|
||||
|
||||
[self notifyFinishLoadingAppcast];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain resuming:(BOOL)resuming
|
||||
- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain resuming:(BOOL)resuming SPU_OBJC_DIRECT
|
||||
{
|
||||
if (!self.aborted) {
|
||||
if (!_aborted) {
|
||||
id<SPUBasicUpdateDriverDelegate> delegate = _delegate;
|
||||
id <SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
id updater = _updater;
|
||||
|
||||
if (!resuming) {
|
||||
#if SPARKLE_BUILD_PACKAGE_SUPPORT
|
||||
// interactive pkg based updates are not supported under root user
|
||||
if ([updateItem.installationType isEqualToString:SPUInstallationTypeInteractivePackage] && geteuid() == 0) {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationRootInteractiveError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Interactive based packages cannot be installed as the root user.", nil) }]];
|
||||
[delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationRootInteractiveError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"Interactive based packages cannot be installed as the root user.", SPARKLE_TABLE, SUSparkleBundle(), nil) }]];
|
||||
return;
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
// Give the delegate a chance to bail
|
||||
|
||||
NSError *shouldNotProceedError = nil;
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(updater:shouldProceedWithUpdate:updateCheck:error:)] && ![self.updaterDelegate updater:self.updater shouldProceedWithUpdate:updateItem updateCheck:self.updateCheck error:&shouldNotProceedError]) {
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:shouldNotProceedError];
|
||||
if ([updaterDelegate respondsToSelector:@selector(updater:shouldProceedWithUpdate:updateCheck:error:)] && ![updaterDelegate updater:updater shouldProceedWithUpdate:updateItem updateCheck:_updateCheck error:&shouldNotProceedError]) {
|
||||
[delegate basicDriverIsRequestingAbortUpdateWithError:shouldNotProceedError];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
|
||||
object:self.updater
|
||||
object:updater
|
||||
userInfo:@{ SUUpdaterAppcastItemNotificationKey: updateItem }];
|
||||
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updater:didFindValidUpdate:))]) {
|
||||
[self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem];
|
||||
if ([updaterDelegate respondsToSelector:@selector((updater:didFindValidUpdate:))]) {
|
||||
[updaterDelegate updater:updater didFindValidUpdate:updateItem];
|
||||
}
|
||||
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain];
|
||||
[delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,26 +182,30 @@
|
||||
|
||||
- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult background:(BOOL)background
|
||||
{
|
||||
if (!self.aborted) {
|
||||
if (!_aborted) {
|
||||
NSString *localizedDescription;
|
||||
NSString *recoverySuggestion;
|
||||
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
NSBundle *sparkleBundle = SUSparkleBundle();
|
||||
#endif
|
||||
|
||||
SPUNoUpdateFoundReason reason;
|
||||
if (latestAppcastItem != nil) {
|
||||
switch (hostToLatestAppcastItemComparisonResult) {
|
||||
case NSOrderedDescending:
|
||||
// This means the user is a 'newer than latest' version. give a slight hint to the user instead of wrongly claiming this version is identical to the latest feed version.
|
||||
localizedDescription = SULocalizedString(@"You’re up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
localizedDescription = SULocalizedStringFromTableInBundle(@"You’re up-to-date!", SPARKLE_TABLE, sparkleBundle, "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.\n(You are currently running version %@.)", nil), [self.host name], latestAppcastItem.displayVersionString, [self.host displayVersion]];
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%@ %@ is currently the newest version available.\n(You are currently running version %@.)", SPARKLE_TABLE, sparkleBundle, nil), [_host name], latestAppcastItem.displayVersionString, [_host displayVersion]];
|
||||
|
||||
reason = SPUNoUpdateFoundReasonOnNewerThanLatestVersion;
|
||||
break;
|
||||
case NSOrderedSame:
|
||||
// No new update is available and we're on the latest
|
||||
localizedDescription = SULocalizedString(@"You’re up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
localizedDescription = SULocalizedStringFromTableInBundle(@"You’re up-to-date!", SPARKLE_TABLE, sparkleBundle, "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%@ %@ is currently the newest version available.", SPARKLE_TABLE, sparkleBundle, nil), [_host name], [_host displayVersion]];
|
||||
|
||||
reason = SPUNoUpdateFoundReasonOnLatestVersion;
|
||||
break;
|
||||
@@ -202,22 +213,22 @@
|
||||
// A new update is available but cannot be installed
|
||||
|
||||
if (!latestAppcastItem.minimumOperatingSystemVersionIsOK) {
|
||||
localizedDescription = SULocalizedString(@"Your macOS version is too old", nil);
|
||||
localizedDescription = SULocalizedStringFromTableInBundle(@"Your macOS version is too old", SPARKLE_TABLE, sparkleBundle, nil);
|
||||
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too old to install it. At least macOS %3$@ is required.", nil), [self.host name], latestAppcastItem.displayVersionString, latestAppcastItem.minimumSystemVersion];
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%1$@ %2$@ is available but your macOS version is too old to install it. At least macOS %3$@ is required.", SPARKLE_TABLE, sparkleBundle, nil), [_host name], latestAppcastItem.displayVersionString, latestAppcastItem.minimumSystemVersion];
|
||||
|
||||
reason = SPUNoUpdateFoundReasonSystemIsTooOld;
|
||||
} else if (!latestAppcastItem.maximumOperatingSystemVersionIsOK) {
|
||||
localizedDescription = SULocalizedString(@"Your macOS version is too new", nil);
|
||||
localizedDescription = SULocalizedStringFromTableInBundle(@"Your macOS version is too new", SPARKLE_TABLE, sparkleBundle, nil);
|
||||
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@.", nil), [self.host name], latestAppcastItem.displayVersionString, latestAppcastItem.maximumSystemVersion];
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@.", SPARKLE_TABLE, sparkleBundle, nil), [_host name], latestAppcastItem.displayVersionString, latestAppcastItem.maximumSystemVersion];
|
||||
|
||||
reason = SPUNoUpdateFoundReasonSystemIsTooNew;
|
||||
} else {
|
||||
// We shouldn't realistically get here
|
||||
localizedDescription = SULocalizedString(@"You’re up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
localizedDescription = SULocalizedStringFromTableInBundle(@"You’re up-to-date!", SPARKLE_TABLE, sparkleBundle, "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%@ %@ is currently the newest version available.", SPARKLE_TABLE, sparkleBundle, nil), [_host name], [_host displayVersion]];
|
||||
|
||||
reason = SPUNoUpdateFoundReasonUnknown;
|
||||
}
|
||||
@@ -228,13 +239,13 @@
|
||||
// We will need to assume the user is up to date if the feed doen't have any applicable update items
|
||||
// There could be update items on channels the updater is not subscribed to for example. But we can't tell the user about them.
|
||||
// There could also only be update items available for other platforms or none at all.
|
||||
localizedDescription = SULocalizedString(@"You’re up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
|
||||
localizedDescription = SULocalizedStringFromTableInBundle(@"You’re up-to-date!", SPARKLE_TABLE, sparkleBundle, "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
|
||||
recoverySuggestion = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"%@ %@ is currently the newest version available.", SPARKLE_TABLE, sparkleBundle, nil), [_host name], [_host displayVersion]];
|
||||
|
||||
reason = SPUNoUpdateFoundReasonOnLatestVersion;
|
||||
}
|
||||
|
||||
NSString *recoveryOption = SULocalizedString(@"OK", nil);
|
||||
NSString *recoveryOption = SULocalizedStringFromTableInBundle(@"OK", SPARKLE_TABLE, sparkleBundle, nil);
|
||||
|
||||
NSMutableDictionary *userInfo =
|
||||
[NSMutableDictionary dictionaryWithDictionary:@{
|
||||
@@ -255,26 +266,31 @@
|
||||
code:SUNoUpdateError
|
||||
userInfo:[userInfo copy]];
|
||||
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:error:))]) {
|
||||
[self.updaterDelegate updaterDidNotFindUpdate:self.updater error:notFoundError];
|
||||
} else if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) {
|
||||
[self.updaterDelegate updaterDidNotFindUpdate:self.updater];
|
||||
id <SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
id updater = _updater;
|
||||
|
||||
if (updater != nil) {
|
||||
if ([updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:error:))]) {
|
||||
[updaterDelegate updaterDidNotFindUpdate:updater error:notFoundError];
|
||||
} else if ([updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) {
|
||||
[updaterDelegate updaterDidNotFindUpdate:updater];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:updater userInfo:userInfo];
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater userInfo:userInfo];
|
||||
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
|
||||
[_delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)abortUpdateAndShowNextUpdateImmediately:(BOOL)shouldShowUpdateImmediately resumableUpdate:(id<SPUResumableUpdate> _Nullable)resumableUpdate error:(nullable NSError *)error
|
||||
{
|
||||
self.aborted = YES;
|
||||
_aborted = YES;
|
||||
|
||||
[self.appcastDriver cleanup:^{
|
||||
if (self.completionBlock != nil) {
|
||||
self.completionBlock(shouldShowUpdateImmediately, resumableUpdate, error);
|
||||
self.completionBlock = nil;
|
||||
[_appcastDriver cleanup:^{
|
||||
if (self->_completionBlock != nil) {
|
||||
self->_completionBlock(shouldShowUpdateImmediately, resumableUpdate, error);
|
||||
self->_completionBlock = nil;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
@interface SPUCoreBasedUpdateDriver : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUCoreBasedUpdateDriver : NSObject
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updateCheck:(SPUUpdateCheck)updateCheck updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id<SPUCoreBasedUpdateDriverDelegate>)delegate;
|
||||
|
||||
|
||||
Vendored
+130
-124
@@ -27,43 +27,28 @@
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SPUCoreBasedUpdateDriver () <SPUBasicUpdateDriverDelegate, SPUDownloadDriverDelegate, SPUInstallerDriverDelegate>
|
||||
|
||||
@property (nonatomic, readonly) SPUBasicUpdateDriver *basicDriver;
|
||||
@property (nonatomic) SPUDownloadDriver *downloadDriver;
|
||||
@property (nonatomic, readonly) SPUInstallerDriver *installerDriver;
|
||||
@property (nonatomic, weak, readonly) id<SPUCoreBasedUpdateDriverDelegate> delegate;
|
||||
@property (nonatomic) SUAppcastItem *updateItem;
|
||||
@property (nonatomic, nullable) SUAppcastItem *secondaryUpdateItem;
|
||||
@property (nonatomic) id<SPUResumableUpdate> resumableUpdate;
|
||||
@property (nonatomic) SPUDownloadedUpdate *downloadedUpdateForRemoval;
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic) BOOL resumingInstallingUpdate;
|
||||
@property (nonatomic) BOOL silentInstall;
|
||||
@property (nonatomic, readonly, weak) id updater; // if we didn't have legacy support, I'd remove this..
|
||||
@property (nullable, nonatomic, readonly, weak) id <SPUUpdaterDelegate>updaterDelegate;
|
||||
@property (nonatomic) NSString *userAgent;
|
||||
@property (nonatomic, nullable) NSDictionary *httpHeaders;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUCoreBasedUpdateDriver
|
||||
|
||||
@synthesize basicDriver = _basicDriver;
|
||||
@synthesize downloadDriver = _downloadDriver;
|
||||
@synthesize installerDriver = _installerDriver;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize secondaryUpdateItem = _secondaryUpdateItem;
|
||||
@synthesize host = _host;
|
||||
@synthesize resumingInstallingUpdate = _resumingInstallingUpdate;
|
||||
@synthesize silentInstall = _silentInstall;
|
||||
@synthesize updater = _updater;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize userAgent = _userAgent;
|
||||
@synthesize httpHeaders = _httpHeaders;
|
||||
@synthesize resumableUpdate = _resumableUpdate;
|
||||
@synthesize downloadedUpdateForRemoval = _downloadedUpdateForRemoval;
|
||||
{
|
||||
SPUBasicUpdateDriver *_basicDriver;
|
||||
SPUDownloadDriver *_downloadDriver;
|
||||
SPUInstallerDriver *_installerDriver;
|
||||
SUAppcastItem *_updateItem;
|
||||
SUAppcastItem * _Nullable _secondaryUpdateItem;
|
||||
id<SPUResumableUpdate> _resumableUpdate;
|
||||
SPUDownloadedUpdate *_downloadedUpdateForRemoval;
|
||||
SUHost *_host;
|
||||
NSString *_userAgent;
|
||||
NSDictionary * _Nullable _httpHeaders;
|
||||
|
||||
__weak id _updater; // if we didn't have legacy support, I'd remove this..
|
||||
__weak id <SPUUpdaterDelegate> _updaterDelegate;
|
||||
__weak id<SPUCoreBasedUpdateDriverDelegate> _delegate;
|
||||
|
||||
BOOL _resumingInstallingUpdate;
|
||||
BOOL _silentInstall;
|
||||
}
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updateCheck:(SPUUpdateCheck)updateCheck updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate delegate:(id<SPUCoreBasedUpdateDriverDelegate>)delegate
|
||||
{
|
||||
@@ -86,90 +71,95 @@
|
||||
|
||||
- (void)setCompletionHandler:(SPUUpdateDriverCompletion)completionBlock
|
||||
{
|
||||
[self.basicDriver setCompletionHandler:completionBlock];
|
||||
[_basicDriver setCompletionHandler:completionBlock];
|
||||
}
|
||||
|
||||
- (void)setUpdateWillInstallHandler:(void (^)(void))updateWillInstallHandler
|
||||
{
|
||||
[self.installerDriver setUpdateWillInstallHandler:updateWillInstallHandler];
|
||||
[_installerDriver setUpdateWillInstallHandler:updateWillInstallHandler];
|
||||
}
|
||||
|
||||
- (void)checkForUpdatesAtAppcastURL:(NSURL *)appcastURL withUserAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background requiresSilentInstall:(BOOL)silentInstall
|
||||
{
|
||||
self.userAgent = userAgent;
|
||||
self.httpHeaders = httpHeaders;
|
||||
self.silentInstall = silentInstall;
|
||||
_userAgent = [userAgent copy];
|
||||
_httpHeaders = httpHeaders;
|
||||
_silentInstall = silentInstall;
|
||||
|
||||
[self.basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:background];
|
||||
[_basicDriver checkForUpdatesAtAppcastURL:appcastURL withUserAgent:userAgent httpHeaders:httpHeaders inBackground:background];
|
||||
}
|
||||
|
||||
- (void)resumeInstallingUpdate
|
||||
{
|
||||
self.resumingInstallingUpdate = YES;
|
||||
self.silentInstall = NO;
|
||||
_resumingInstallingUpdate = YES;
|
||||
_silentInstall = NO;
|
||||
|
||||
[self.basicDriver resumeInstallingUpdate];
|
||||
[_basicDriver resumeInstallingUpdate];
|
||||
}
|
||||
|
||||
- (void)resumeUpdate:(id<SPUResumableUpdate>)resumableUpdate
|
||||
{
|
||||
self.resumableUpdate = resumableUpdate;
|
||||
self.silentInstall = NO;
|
||||
_resumableUpdate = resumableUpdate;
|
||||
_silentInstall = NO;
|
||||
|
||||
[self.basicDriver resumeUpdate:resumableUpdate];
|
||||
[_basicDriver resumeUpdate:resumableUpdate];
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFinishLoadingAppcast
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(basicDriverDidFinishLoadingAppcast)]) {
|
||||
[self.delegate basicDriverDidFinishLoadingAppcast];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(basicDriverDidFinishLoadingAppcast)]) {
|
||||
[delegate basicDriverDidFinishLoadingAppcast];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
self.secondaryUpdateItem = secondaryUpdateItem;
|
||||
_updateItem = updateItem;
|
||||
_secondaryUpdateItem = secondaryUpdateItem;
|
||||
|
||||
if (self.resumingInstallingUpdate) {
|
||||
if (_resumingInstallingUpdate) {
|
||||
assert(systemDomain != nil);
|
||||
[self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem systemDomain:systemDomain.boolValue];
|
||||
[_installerDriver resumeInstallingUpdateWithUpdateItem:updateItem systemDomain:systemDomain.boolValue];
|
||||
}
|
||||
|
||||
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem];
|
||||
[_delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem];
|
||||
}
|
||||
|
||||
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem inBackground:(BOOL)background
|
||||
- (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem inBackground:(BOOL)background SPU_OBJC_DIRECT
|
||||
{
|
||||
self.downloadDriver = [[SPUDownloadDriver alloc] initWithUpdateItem:updateItem secondaryUpdateItem:secondaryUpdateItem host:self.host userAgent:self.userAgent httpHeaders:self.httpHeaders inBackground:background delegate:self];
|
||||
_downloadDriver = [[SPUDownloadDriver alloc] initWithUpdateItem:updateItem secondaryUpdateItem:secondaryUpdateItem host:_host userAgent:_userAgent httpHeaders:_httpHeaders inBackground:background delegate:self];
|
||||
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updater:willDownloadUpdate:withRequest:))]) {
|
||||
[self.updaterDelegate updater:self.updater
|
||||
willDownloadUpdate:updateItem
|
||||
withRequest:self.downloadDriver.request];
|
||||
id updater = _updater;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector((updater:willDownloadUpdate:withRequest:))]) {
|
||||
[updaterDelegate updater:updater willDownloadUpdate:updateItem withRequest:_downloadDriver.request];
|
||||
}
|
||||
|
||||
[self.downloadDriver downloadFile];
|
||||
[_downloadDriver downloadFile];
|
||||
}
|
||||
|
||||
- (void)downloadDriverWillBeginDownload
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverWillBeginDownload)]) {
|
||||
[self.delegate downloadDriverWillBeginDownload];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverWillBeginDownload)]) {
|
||||
[delegate downloadDriverWillBeginDownload];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveExpectedContentLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverDidReceiveExpectedContentLength:)]) {
|
||||
[delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveDataOfLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveDataOfLength:length];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverDidReceiveDataOfLength:)]) {
|
||||
[delegate downloadDriverDidReceiveDataOfLength:length];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,73 +169,80 @@
|
||||
// We could restrict this to when the appcast was downloaded in the background,
|
||||
// but it shouldn't matter.
|
||||
if (downloadedUpdate.updateItem.phasedRolloutInterval != nil) {
|
||||
[SUPhasedUpdateGroupInfo setNewUpdateGroupIdentifierForHost:self.host];
|
||||
[SUPhasedUpdateGroupInfo setNewUpdateGroupIdentifierForHost:_host];
|
||||
}
|
||||
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(updater:didDownloadUpdate:)]) {
|
||||
[self.updaterDelegate updater:self.updater didDownloadUpdate:self.updateItem];
|
||||
id updater = _updater;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector(updater:didDownloadUpdate:)]) {
|
||||
[updaterDelegate updater:updater didDownloadUpdate:_updateItem];
|
||||
}
|
||||
|
||||
self.resumableUpdate = downloadedUpdate;
|
||||
_resumableUpdate = downloadedUpdate;
|
||||
[self extractUpdate:downloadedUpdate];
|
||||
}
|
||||
|
||||
- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem * _Nullable)secondaryUpdateItem
|
||||
{
|
||||
self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem];
|
||||
_resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem];
|
||||
}
|
||||
|
||||
- (void)extractDownloadedUpdate
|
||||
{
|
||||
assert(self.resumableUpdate != nil);
|
||||
[self extractUpdate:self.resumableUpdate];
|
||||
assert(_resumableUpdate != nil);
|
||||
[self extractUpdate:_resumableUpdate];
|
||||
}
|
||||
|
||||
- (void)clearDownloadedUpdate
|
||||
{
|
||||
id<NSObject> downloadedUpdateObject = (self.resumableUpdate != nil) ? self.resumableUpdate : self.downloadedUpdateForRemoval;
|
||||
id<NSObject> downloadedUpdateObject = (_resumableUpdate != nil) ? _resumableUpdate : _downloadedUpdateForRemoval;
|
||||
assert(downloadedUpdateObject != nil);
|
||||
|
||||
if (downloadedUpdateObject != nil && [downloadedUpdateObject isKindOfClass:[SPUDownloadedUpdate class]]) {
|
||||
if (self.downloadDriver == nil) {
|
||||
self.downloadDriver = [[SPUDownloadDriver alloc] initWithHost:self.host];
|
||||
if (_downloadDriver == nil) {
|
||||
_downloadDriver = [[SPUDownloadDriver alloc] initWithHost:_host];
|
||||
}
|
||||
|
||||
SPUDownloadedUpdate *downloadedUpdate = (SPUDownloadedUpdate *)downloadedUpdateObject;
|
||||
[self.downloadDriver removeDownloadedUpdate:downloadedUpdate];
|
||||
[_downloadDriver removeDownloadedUpdate:downloadedUpdate];
|
||||
}
|
||||
|
||||
// Clear any type of resumable update
|
||||
self.resumableUpdate = nil;
|
||||
_resumableUpdate = nil;
|
||||
}
|
||||
|
||||
- (void)extractUpdate:(SPUDownloadedUpdate *)downloadedUpdate
|
||||
- (void)extractUpdate:(SPUDownloadedUpdate *)downloadedUpdate SPU_OBJC_DIRECT
|
||||
{
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(updater:willExtractUpdate:)]) {
|
||||
[self.updaterDelegate updater:self.updater willExtractUpdate:self.updateItem];
|
||||
id updater = _updater;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector(updater:willExtractUpdate:)]) {
|
||||
[updaterDelegate updater:updater willExtractUpdate:_updateItem];
|
||||
}
|
||||
|
||||
// Now we have to extract the downloaded archive.
|
||||
if ([self.delegate respondsToSelector:@selector(coreDriverDidStartExtractingUpdate)]) {
|
||||
[self.delegate coreDriverDidStartExtractingUpdate];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(coreDriverDidStartExtractingUpdate)]) {
|
||||
[delegate coreDriverDidStartExtractingUpdate];
|
||||
}
|
||||
|
||||
[self.installerDriver extractDownloadedUpdate:downloadedUpdate silently:self.silentInstall completion:^(NSError * _Nullable error) {
|
||||
[_installerDriver extractDownloadedUpdate:downloadedUpdate silently:_silentInstall completion:^(NSError * _Nullable error) {
|
||||
if (error != nil) {
|
||||
if (error.code != SUInstallationAuthorizeLaterError) {
|
||||
[self clearDownloadedUpdate];
|
||||
}
|
||||
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
[self->_delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
} else {
|
||||
// If the installer started properly, we can't use the downloaded update archive anymore
|
||||
// Especially if the installer fails later and we try resuming the update with a missing archive file
|
||||
// We must clear the download after the installer begins using it however (in -installerDidStartInstalling)
|
||||
self.downloadedUpdateForRemoval = downloadedUpdate;
|
||||
self.resumableUpdate = nil;
|
||||
self->_downloadedUpdateForRemoval = downloadedUpdate;
|
||||
self->_resumableUpdate = nil;
|
||||
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(updater:didExtractUpdate:)]) {
|
||||
[self.updaterDelegate updater:self.updater didExtractUpdate:self.updateItem];
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector(updater:didExtractUpdate:)]) {
|
||||
[updaterDelegate updater:updater didExtractUpdate:self->_updateItem];
|
||||
}
|
||||
}
|
||||
}];
|
||||
@@ -253,31 +250,33 @@
|
||||
|
||||
- (void)downloadDriverDidFailToDownloadFileWithError:(NSError *)error
|
||||
{
|
||||
if ([self.updateItem isDeltaUpdate]) {
|
||||
if ([_updateItem isDeltaUpdate]) {
|
||||
SULog(SULogLevelError, @"Failed to download delta update. Falling back to regular update...");
|
||||
SULogError(error);
|
||||
|
||||
[self fallBackAndDownloadRegularUpdate];
|
||||
} else {
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updater:failedToDownloadUpdate:error:))]) {
|
||||
id updater = _updater;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector((updater:failedToDownloadUpdate:error:))]) {
|
||||
NSError *errorToReport = [error.userInfo objectForKey:NSUnderlyingErrorKey];
|
||||
if (errorToReport == nil) {
|
||||
errorToReport = error;
|
||||
}
|
||||
|
||||
[self.updaterDelegate updater:self.updater
|
||||
failedToDownloadUpdate:self.updateItem
|
||||
error:errorToReport];
|
||||
[updaterDelegate updater:updater failedToDownloadUpdate:_updateItem error:errorToReport];
|
||||
}
|
||||
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
[_delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)installerDidStartInstallingWithApplicationTerminated:(BOOL)applicationTerminated
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(installerDidStartInstallingWithApplicationTerminated:)]) {
|
||||
[self.delegate installerDidStartInstallingWithApplicationTerminated:applicationTerminated];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(installerDidStartInstallingWithApplicationTerminated:)]) {
|
||||
[delegate installerDidStartInstallingWithApplicationTerminated:applicationTerminated];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -289,49 +288,56 @@
|
||||
|
||||
- (void)installerDidExtractUpdateWithProgress:(double)progress
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(installerDidExtractUpdateWithProgress:)]) {
|
||||
[self.delegate installerDidExtractUpdateWithProgress:progress];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(installerDidExtractUpdateWithProgress:)]) {
|
||||
[delegate installerDidExtractUpdateWithProgress:progress];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently
|
||||
{
|
||||
[self.delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently];
|
||||
[_delegate installerDidFinishPreparationAndWillInstallImmediately:willInstallImmediately silently:willInstallSilently];
|
||||
}
|
||||
|
||||
- (void)finishInstallationWithResponse:(SPUUserUpdateChoice)response displayingUserInterface:(BOOL)displayingUserInterface
|
||||
{
|
||||
switch (response) {
|
||||
case SPUUserUpdateChoiceDismiss:
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:nil];
|
||||
[_delegate coreDriverIsRequestingAbortUpdateWithError:nil];
|
||||
break;
|
||||
case SPUUserUpdateChoiceSkip:
|
||||
[self.installerDriver cancelUpdate];
|
||||
[_installerDriver cancelUpdate];
|
||||
break;
|
||||
case SPUUserUpdateChoiceInstall:
|
||||
[self.installerDriver installWithToolAndRelaunch:YES displayingUserInterface:displayingUserInterface];
|
||||
[_installerDriver installWithToolAndRelaunch:YES displayingUserInterface:displayingUserInterface];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)installerWillFinishInstallationAndRelaunch:(BOOL)relaunch
|
||||
{
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updater:willInstallUpdate:))]) {
|
||||
[self.updaterDelegate updater:self.updater willInstallUpdate:self.updateItem];
|
||||
}
|
||||
id updater = _updater;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
|
||||
if (relaunch) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
if ([self.updaterDelegate respondsToSelector:@selector((updaterWillRelaunchApplication:))]) {
|
||||
[self.updaterDelegate updaterWillRelaunchApplication:self.updater];
|
||||
if (updater != nil) {
|
||||
if ([updaterDelegate respondsToSelector:@selector((updater:willInstallUpdate:))]) {
|
||||
[updaterDelegate updater:updater willInstallUpdate:_updateItem];
|
||||
}
|
||||
|
||||
if (relaunch) {
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:updater];
|
||||
if ([updaterDelegate respondsToSelector:@selector((updaterWillRelaunchApplication:))]) {
|
||||
[updaterDelegate updaterWillRelaunchApplication:updater];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)installerDidFinishInstallationAndRelaunched:(BOOL)relaunched acknowledgement:(void(^)(void))acknowledgement
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(installerDidFinishInstallationAndRelaunched:acknowledgement:)]) {
|
||||
[self.delegate installerDidFinishInstallationAndRelaunched:relaunched acknowledgement:acknowledgement];
|
||||
id<SPUCoreBasedUpdateDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(installerDidFinishInstallationAndRelaunched:acknowledgement:)]) {
|
||||
[delegate installerDidFinishInstallationAndRelaunched:relaunched acknowledgement:acknowledgement];
|
||||
} else {
|
||||
acknowledgement();
|
||||
}
|
||||
@@ -339,25 +345,25 @@
|
||||
|
||||
- (void)installerIsRequestingAbortInstallWithError:(nullable NSError *)error
|
||||
{
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
[_delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error
|
||||
{
|
||||
// A delegate may want to handle this type of error specially
|
||||
[self.delegate basicDriverIsRequestingAbortUpdateWithError:error];
|
||||
[_delegate basicDriverIsRequestingAbortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)fallBackAndDownloadRegularUpdate
|
||||
- (void)fallBackAndDownloadRegularUpdate SPU_OBJC_DIRECT
|
||||
{
|
||||
SUAppcastItem *secondaryUpdateItem = self.secondaryUpdateItem;
|
||||
SUAppcastItem *secondaryUpdateItem = _secondaryUpdateItem;
|
||||
assert(secondaryUpdateItem != nil);
|
||||
|
||||
BOOL backgroundDownload = self.downloadDriver.inBackground;
|
||||
BOOL backgroundDownload = _downloadDriver.inBackground;
|
||||
|
||||
// Fall back to the non-delta update. Note that we don't want to trigger another update was found event.
|
||||
self.updateItem = secondaryUpdateItem;
|
||||
self.secondaryUpdateItem = nil;
|
||||
_updateItem = secondaryUpdateItem;
|
||||
_secondaryUpdateItem = nil;
|
||||
|
||||
[self downloadUpdateFromAppcastItem:secondaryUpdateItem secondaryAppcastItem:nil inBackground:backgroundDownload];
|
||||
}
|
||||
@@ -371,16 +377,16 @@
|
||||
|
||||
- (void)abortUpdateAndShowNextUpdateImmediately:(BOOL)shouldShowUpdateImmediately error:(nullable NSError *)error
|
||||
{
|
||||
[self.installerDriver abortInstall];
|
||||
[_installerDriver abortInstall];
|
||||
|
||||
void (^basicDriverAbort)(void) = ^{
|
||||
id<SPUResumableUpdate> resumableUpdate = (error == nil || error.code == SUInstallationAuthorizeLaterError) ? self.resumableUpdate : nil;
|
||||
id<SPUResumableUpdate> resumableUpdate = (error == nil || error.code == SUInstallationAuthorizeLaterError) ? self->_resumableUpdate : nil;
|
||||
|
||||
[self.basicDriver abortUpdateAndShowNextUpdateImmediately:shouldShowUpdateImmediately resumableUpdate:resumableUpdate error:error];
|
||||
[self->_basicDriver abortUpdateAndShowNextUpdateImmediately:shouldShowUpdateImmediately resumableUpdate:resumableUpdate error:error];
|
||||
};
|
||||
|
||||
if (self.downloadDriver != nil) {
|
||||
[self.downloadDriver cleanup:^{
|
||||
if (_downloadDriver != nil) {
|
||||
[_downloadDriver cleanup:^{
|
||||
basicDriverAbort();
|
||||
}];
|
||||
} else {
|
||||
|
||||
Vendored
+1
-1
@@ -8,7 +8,7 @@
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifdef BUILDING_SPARKLE_DOWNLOADER_SERVICE
|
||||
#if defined(BUILDING_SPARKLE_SOURCES_EXTERNALLY)
|
||||
// Ignore incorrect warning
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wquoted-include-in-framework-header"
|
||||
|
||||
Vendored
+6
-6
@@ -42,15 +42,15 @@ static NSString *SPUDownloadMIMETypeKey = @"SPUDownloadMIMEType";
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.data forKey:SPUDownloadDataKey];
|
||||
[coder encodeObject:self.URL forKey:SPUDownloadURLKey];
|
||||
[coder encodeObject:_data forKey:SPUDownloadDataKey];
|
||||
[coder encodeObject:_URL forKey:SPUDownloadURLKey];
|
||||
|
||||
if (self.textEncodingName != nil) {
|
||||
[coder encodeObject:self.textEncodingName forKey:SPUDownloadTextEncodingKey];
|
||||
if (_textEncodingName != nil) {
|
||||
[coder encodeObject:_textEncodingName forKey:SPUDownloadTextEncodingKey];
|
||||
}
|
||||
|
||||
if (self.MIMEType != nil) {
|
||||
[coder encodeObject:self.MIMEType forKey:SPUDownloadMIMETypeKey];
|
||||
if (_MIMEType != nil) {
|
||||
[coder encodeObject:_MIMEType forKey:SPUDownloadMIMETypeKey];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+3
@@ -34,6 +34,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
#ifndef BUILDING_SPARKLE_TESTS
|
||||
SPU_OBJC_DIRECT_MEMBERS
|
||||
#endif
|
||||
@interface SPUDownloadDriver : NSObject
|
||||
|
||||
- (instancetype)initWithRequestURL:(NSURL *)requestURL host:(SUHost *)host userAgent:(NSString * _Nullable)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
|
||||
|
||||
Vendored
+77
-73
@@ -18,41 +18,36 @@
|
||||
#import "SUErrors.h"
|
||||
#import "SPUDownloadedUpdate.h"
|
||||
#import "SPUDownloadData.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
@interface SPUDownloadDriver () <SPUDownloaderDelegate>
|
||||
|
||||
@property (nonatomic) id<SPUDownloaderProtocol> downloader;
|
||||
@property (nonatomic) NSXPCConnection *connection;
|
||||
@property (nonatomic, readonly) SUAppcastItem *updateItem;
|
||||
@property (nonatomic, readonly, nullable) SUAppcastItem *secondaryUpdateItem;
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, copy) NSString *temporaryDirectory;
|
||||
@property (nonatomic, copy) NSString *downloadName;
|
||||
@property (nonatomic, weak) id<SPUDownloadDriverDelegate> delegate;
|
||||
@property (nonatomic) BOOL retrievedDownloadResult;
|
||||
@property (nonatomic) uint64_t expectedContentLength;
|
||||
@property (nonatomic) BOOL cleaningUp;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUDownloadDriver
|
||||
{
|
||||
id<SPUDownloaderProtocol> _downloader;
|
||||
#if DOWNLOADER_XPC_SERVICE_EMBEDDED
|
||||
NSXPCConnection *_connection;
|
||||
#endif
|
||||
SUAppcastItem *_updateItem;
|
||||
SUAppcastItem * _Nullable _secondaryUpdateItem;
|
||||
SUHost *_host;
|
||||
NSString *_temporaryDirectory;
|
||||
NSString *_downloadName;
|
||||
|
||||
__weak id<SPUDownloadDriverDelegate> _delegate;
|
||||
|
||||
uint64_t _expectedContentLength;
|
||||
|
||||
BOOL _retrievedDownloadResult;
|
||||
BOOL _cleaningUp;
|
||||
}
|
||||
|
||||
@synthesize downloader = _downloader;
|
||||
@synthesize connection = _connection;
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize secondaryUpdateItem = _secondaryUpdateItem;
|
||||
@synthesize request = _request;
|
||||
@synthesize inBackground = _inBackground;
|
||||
@synthesize host = _host;
|
||||
@synthesize temporaryDirectory = _temporaryDirectory;
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize retrievedDownloadResult = _retrievedDownloadResult;
|
||||
@synthesize expectedContentLength = _expectedContentLength;
|
||||
@synthesize cleaningUp = _cleaningUp;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host
|
||||
{
|
||||
@@ -60,9 +55,8 @@
|
||||
if (self != nil) {
|
||||
_host = host;
|
||||
|
||||
if (!SPUXPCServiceIsEnabled(SUEnableDownloaderServiceKey)) {
|
||||
_downloader = [[SPUDownloader alloc] initWithDelegate:self];
|
||||
} else {
|
||||
#if DOWNLOADER_XPC_SERVICE_EMBEDDED
|
||||
if (SPUXPCServiceIsEnabled(SUEnableDownloaderServiceKey)) {
|
||||
_connection = [[NSXPCConnection alloc] initWithServiceName:@DOWNLOADER_BUNDLE_ID];
|
||||
_connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUDownloaderProtocol)];
|
||||
_connection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SPUDownloaderDelegate)];
|
||||
@@ -70,38 +64,42 @@
|
||||
|
||||
_downloader = _connection.remoteObjectProxy;
|
||||
|
||||
__weak SPUDownloadDriver *weakSelf = self;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
|
||||
_connection.interruptionHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SPUDownloadDriver *strongSelf = weakSelf;
|
||||
if (strongSelf != nil && !strongSelf.retrievedDownloadResult) {
|
||||
[strongSelf.connection invalidate];
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil && !strongSelf->_retrievedDownloadResult) {
|
||||
[strongSelf->_connection invalidate];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
_connection.invalidationHandler = ^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SPUDownloadDriver *strongSelf = weakSelf;
|
||||
if (strongSelf != nil && !strongSelf.retrievedDownloadResult && !strongSelf.cleaningUp) {
|
||||
strongSelf.downloader = nil;
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil && !strongSelf->_retrievedDownloadResult && !strongSelf->_cleaningUp) {
|
||||
strongSelf->_downloader = nil;
|
||||
|
||||
SULog(SULogLevelError, @"Connection to update downloader was invalidated");
|
||||
|
||||
NSDictionary *userInfo =
|
||||
@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil),
|
||||
NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"An error occurred while downloading the update. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil),
|
||||
};
|
||||
|
||||
NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo];
|
||||
|
||||
[strongSelf.delegate downloadDriverDidFailToDownloadFileWithError:downloadError];
|
||||
[strongSelf->_delegate downloadDriverDidFailToDownloadFileWithError:downloadError];
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
[_connection resume];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
_downloader = [[SPUDownloader alloc] initWithDelegate:self];
|
||||
}
|
||||
}
|
||||
return self;
|
||||
@@ -149,54 +147,57 @@
|
||||
|
||||
- (void)downloadFile
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverWillBeginDownload)]) {
|
||||
[self.delegate downloadDriverWillBeginDownload];
|
||||
id<SPUDownloadDriverDelegate> delegate = _delegate;
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverWillBeginDownload)]) {
|
||||
[delegate downloadDriverWillBeginDownload];
|
||||
}
|
||||
|
||||
if (self.updateItem != nil) {
|
||||
NSString *desiredFilename = [NSString stringWithFormat:@"%@ %@", [self.host name], [self.updateItem versionString]];
|
||||
if (_updateItem != nil) {
|
||||
NSString *desiredFilename = [NSString stringWithFormat:@"%@ %@", [_host name], [_updateItem versionString]];
|
||||
|
||||
NSString *bundleIdentifier = self.host.bundle.bundleIdentifier;
|
||||
NSString *bundleIdentifier = _host.bundle.bundleIdentifier;
|
||||
assert(bundleIdentifier != nil);
|
||||
|
||||
[self.downloader startPersistentDownloadWithRequest:self.request bundleIdentifier:bundleIdentifier desiredFilename:desiredFilename];
|
||||
[_downloader startPersistentDownloadWithRequest:_request bundleIdentifier:bundleIdentifier desiredFilename:desiredFilename];
|
||||
} else {
|
||||
[self.downloader startTemporaryDownloadWithRequest:self.request];
|
||||
[_downloader startTemporaryDownloadWithRequest:_request];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)removeDownloadedUpdate:(SPUDownloadedUpdate *)downloadedUpdate
|
||||
{
|
||||
NSString *bundleIdentifier = self.host.bundle.bundleIdentifier;
|
||||
NSString *bundleIdentifier = _host.bundle.bundleIdentifier;
|
||||
assert(bundleIdentifier != nil);
|
||||
|
||||
if (bundleIdentifier != nil) {
|
||||
// Grab eg "0bCSun8tj" from org.sparkle-project.Sparkle/PersistentDownloads/0bCSun8tj/Sparkle Test App 2.0/
|
||||
NSString *tempDirectoryName = downloadedUpdate.temporaryDirectory.stringByDeletingLastPathComponent.lastPathComponent;
|
||||
|
||||
[self.downloader removeDownloadDirectory:tempDirectoryName bundleIdentifier:bundleIdentifier];
|
||||
[_downloader removeDownloadDirectory:tempDirectoryName bundleIdentifier:bundleIdentifier];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cleanup:(void (^)(void))completionHandler
|
||||
{
|
||||
void (^cleanupBlock)(void) = ^{
|
||||
self.cleaningUp = YES;
|
||||
self->_cleaningUp = YES;
|
||||
|
||||
if (self.connection != nil) {
|
||||
[self.connection invalidate];
|
||||
self.connection = nil;
|
||||
#if DOWNLOADER_XPC_SERVICE_EMBEDDED
|
||||
if (self->_connection != nil) {
|
||||
[self->_connection invalidate];
|
||||
self->_connection = nil;
|
||||
}
|
||||
self.downloadName = nil;
|
||||
self.downloader = nil;
|
||||
#endif
|
||||
self->_downloadName = nil;
|
||||
self->_downloader = nil;
|
||||
|
||||
completionHandler();
|
||||
};
|
||||
|
||||
if (self.downloader == nil) {
|
||||
if (_downloader == nil) {
|
||||
cleanupBlock();
|
||||
} else {
|
||||
[self.downloader cleanup:^{
|
||||
[_downloader cleanup:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
cleanupBlock();
|
||||
});
|
||||
@@ -207,23 +208,24 @@
|
||||
- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)downloadData
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.retrievedDownloadResult = YES;
|
||||
self->_retrievedDownloadResult = YES;
|
||||
|
||||
if (self.updateItem != nil) {
|
||||
if (self.expectedContentLength > 0 && self.updateItem.contentLength > 0 && self.expectedContentLength != self.updateItem.contentLength) {
|
||||
SULog(SULogLevelError, @"Warning: Downloader's expected content length (%llu) != Appcast item's length (%llu)", self.expectedContentLength, self.updateItem.contentLength);
|
||||
id<SPUDownloadDriverDelegate> delegate = self->_delegate;
|
||||
if (self->_updateItem != nil) {
|
||||
if (self->_expectedContentLength > 0 && self->_updateItem.contentLength > 0 && self->_expectedContentLength != self->_updateItem.contentLength) {
|
||||
SULog(SULogLevelError, @"Warning: Downloader's expected content length (%llu) != Appcast item's length (%llu)", self->_expectedContentLength, self->_updateItem.contentLength);
|
||||
}
|
||||
|
||||
SPUDownloadedUpdate *downloadedUpdate = [[SPUDownloadedUpdate alloc] initWithAppcastItem:self.updateItem secondaryAppcastItem:self.secondaryUpdateItem downloadName:self.downloadName temporaryDirectory:self.temporaryDirectory];
|
||||
SPUDownloadedUpdate *downloadedUpdate = [[SPUDownloadedUpdate alloc] initWithAppcastItem:self->_updateItem secondaryAppcastItem:self->_secondaryUpdateItem downloadName:self->_downloadName temporaryDirectory:self->_temporaryDirectory];
|
||||
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidDownloadUpdate:)]) {
|
||||
[self.delegate downloadDriverDidDownloadUpdate:downloadedUpdate];
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverDidDownloadUpdate:)]) {
|
||||
[delegate downloadDriverDidDownloadUpdate:downloadedUpdate];
|
||||
}
|
||||
} else {
|
||||
assert(downloadData != nil);
|
||||
SPUDownloadData *nonNullDownloadData = downloadData;
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidDownloadData:)]) {
|
||||
[self.delegate downloadDriverDidDownloadData:nonNullDownloadData];
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverDidDownloadData:)]) {
|
||||
[delegate downloadDriverDidDownloadData:nonNullDownloadData];
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -232,15 +234,15 @@
|
||||
- (void)downloaderDidFailWithError:(NSError *)error
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.retrievedDownloadResult = YES;
|
||||
self->_retrievedDownloadResult = YES;
|
||||
|
||||
NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey];
|
||||
if (!failingUrl) {
|
||||
failingUrl = [self.updateItem fileURL];
|
||||
failingUrl = [self->_updateItem fileURL];
|
||||
}
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while downloading the update. Please try again later.", nil),
|
||||
NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"An error occurred while downloading the update. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil),
|
||||
NSUnderlyingErrorKey: error,
|
||||
}];
|
||||
if (failingUrl) {
|
||||
@@ -248,15 +250,15 @@
|
||||
}
|
||||
|
||||
NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo];
|
||||
[self.delegate downloadDriverDidFailToDownloadFileWithError:downloadError];
|
||||
[self->_delegate downloadDriverDidFailToDownloadFileWithError:downloadError];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)downloaderDidSetDestinationName:(NSString *)destinationName temporaryDirectory:(NSString *)temporaryDirectory
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.downloadName = destinationName;
|
||||
self.temporaryDirectory = temporaryDirectory;
|
||||
self->_downloadName = destinationName;
|
||||
self->_temporaryDirectory = temporaryDirectory;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -264,14 +266,15 @@
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// Fallback to appcast item's content length if we don't get the length from HTTP header
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveExpectedContentLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength > 0 ? (uint64_t)expectedContentLength : self.updateItem.contentLength];
|
||||
id<SPUDownloadDriverDelegate> delegate = self->_delegate;
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverDidReceiveExpectedContentLength:)]) {
|
||||
[delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength > 0 ? (uint64_t)expectedContentLength : self->_updateItem.contentLength];
|
||||
}
|
||||
|
||||
// Reset expected content length from downloader
|
||||
// Later we verify if the total length matches with the content length from the appcast
|
||||
if (expectedContentLength > 0) {
|
||||
self.expectedContentLength = (uint64_t)expectedContentLength;
|
||||
self->_expectedContentLength = (uint64_t)expectedContentLength;
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -279,8 +282,9 @@
|
||||
- (void)downloaderDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveDataOfLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveDataOfLength:length];
|
||||
id<SPUDownloadDriverDelegate> delegate = self->_delegate;
|
||||
if ([delegate respondsToSelector:@selector(downloadDriverDidReceiveDataOfLength:)]) {
|
||||
[delegate downloadDriverDidReceiveDataOfLength:length];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUDownloadedUpdate : NSObject <SPUResumableUpdate>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUDownloadedUpdate : NSObject <SPUResumableUpdate>
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryItem downloadName:(NSString *)downloadName temporaryDirectory:(NSString *)temporaryDirectory;
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -11,7 +11,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUInformationalUpdate : NSObject <SPUResumableUpdate>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUInformationalUpdate : NSObject <SPUResumableUpdate>
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem;
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -27,7 +27,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
@interface SPUInstallerDriver : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUInstallerDriver : NSObject
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater updaterDelegate:(nullable id<SPUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SPUInstallerDriverDelegate>)delegate;
|
||||
|
||||
|
||||
Vendored
+155
-141
@@ -25,66 +25,49 @@
|
||||
#import "SUXPCInstallerConnection.h"
|
||||
#import "SPUDownloadedUpdate.h"
|
||||
#import "SPUInstallationType.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
#define FIRST_INSTALLER_MESSAGE_TIMEOUT 7ull
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_SUUPDATER
|
||||
@interface NSObject (PrivateDelegateMethods)
|
||||
|
||||
- (nullable NSString *)_pathToRelaunchForUpdater:(SPUUpdater *)updater;
|
||||
|
||||
@end
|
||||
#endif
|
||||
|
||||
@interface SPUInstallerDriver () <SUInstallerCommunicationProtocol>
|
||||
|
||||
@property (nonatomic, readonly) SUHost *host;
|
||||
@property (nonatomic, readonly) NSBundle *applicationBundle;
|
||||
@property (nonatomic, weak, readonly) id<SPUInstallerDriverDelegate> delegate;
|
||||
@property (nonatomic) SPUInstallerMessageType currentStage;
|
||||
|
||||
@property (nonatomic) id<SUInstallerConnectionProtocol> installerConnection;
|
||||
|
||||
@property (nonatomic) NSUInteger extractionAttempts;
|
||||
@property (nonatomic) BOOL postponedOnce;
|
||||
@property (nonatomic, weak, readonly) id updater;
|
||||
@property (nonatomic, weak, readonly) id<SPUUpdaterDelegate> updaterDelegate;
|
||||
@property (nonatomic) BOOL relaunch;
|
||||
|
||||
@property (nonatomic) BOOL systemDomain;
|
||||
|
||||
@property (nonatomic) SUAppcastItem *updateItem;
|
||||
@property (nonatomic, copy) NSString *downloadName;
|
||||
@property (nonatomic, copy) NSString *temporaryDirectory;
|
||||
|
||||
@property (nonatomic) BOOL aborted;
|
||||
@property (nonatomic, nullable) NSError *installerError;
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUInstallerDriver
|
||||
{
|
||||
SUHost *_host;
|
||||
NSBundle *_applicationBundle;
|
||||
id<SUInstallerConnectionProtocol> _installerConnection;
|
||||
SUAppcastItem *_updateItem;
|
||||
NSString *_downloadName;
|
||||
NSString *_temporaryDirectory;
|
||||
NSError *_installerError;
|
||||
|
||||
__weak id _updater;
|
||||
__weak id<SPUUpdaterDelegate> _updaterDelegate;
|
||||
__weak id<SPUInstallerDriverDelegate> _delegate;
|
||||
|
||||
void (^_updateWillInstallHandler)(void);
|
||||
|
||||
SPUInstallerMessageType _currentStage;
|
||||
NSUInteger _extractionAttempts;
|
||||
|
||||
BOOL _postponedOnce;
|
||||
BOOL _relaunch;
|
||||
BOOL _systemDomain;
|
||||
BOOL _aborted;
|
||||
}
|
||||
|
||||
@synthesize host = _host;
|
||||
@synthesize applicationBundle = _applicationBundle;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize currentStage = _currentStage;
|
||||
@synthesize installerConnection = _installerConnection;
|
||||
@synthesize extractionAttempts = _extractionAttempts;
|
||||
@synthesize postponedOnce = _postponedOnce;
|
||||
@synthesize updater = _updater;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize relaunch = _relaunch;
|
||||
@synthesize systemDomain = _systemDomain;
|
||||
@synthesize updateItem = _updateItem;
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize temporaryDirectory = _temporaryDirectory;
|
||||
@synthesize aborted = _aborted;
|
||||
@synthesize installerError = _installerError;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater updaterDelegate:(id<SPUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SPUInstallerDriverDelegate>)delegate
|
||||
{
|
||||
self = [super init];
|
||||
@@ -103,7 +86,7 @@
|
||||
_updateWillInstallHandler = [updateWillInstallHandler copy];
|
||||
}
|
||||
|
||||
- (void)_reportInstallerError:(nullable NSError *)currentInstallerError genericErrorCode:(NSInteger)genericErrorCode genericUserInfo:(NSDictionary *)genericUserInfo
|
||||
- (void)_reportInstallerError:(nullable NSError *)currentInstallerError genericErrorCode:(NSInteger)genericErrorCode genericUserInfo:(NSDictionary *)genericUserInfo SPU_OBJC_DIRECT
|
||||
{
|
||||
// First see if there is a good custom error we can show
|
||||
// We only check for signing validation errors and installation errors due to not having write permission currently
|
||||
@@ -113,7 +96,7 @@
|
||||
if (underlyingError != nil) {
|
||||
if (underlyingError.code == SUValidationError) {
|
||||
NSDictionary *userInfo = @{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"The update is improperly signed and could not be validated. Please try again later or contact the app developer.", nil),
|
||||
NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"The update is improperly signed and could not be validated. Please try again later or contact the app developer.", SPARKLE_TABLE, SUSparkleBundle(), nil),
|
||||
NSUnderlyingErrorKey: (NSError * _Nonnull)currentInstallerError
|
||||
};
|
||||
|
||||
@@ -123,18 +106,25 @@
|
||||
if (secondUnderlyingError != nil && [secondUnderlyingError.domain isEqualToString:NSCocoaErrorDomain] && secondUnderlyingError.code == NSFileWriteNoPermissionError) {
|
||||
// Note: these error strings will only surface for external app updaters like sparkle-cli (i.e, updaters that update other app bundles)
|
||||
|
||||
#if SPARKLE_COPY_LOCALIZATIONS
|
||||
NSBundle *sparkleBundle = SUSparkleBundle();
|
||||
#endif
|
||||
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:@{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"The installation failed due to not having permission to write the new update.", nil),
|
||||
NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"The installation failed due to not having permission to write the new update.", SPARKLE_TABLE, sparkleBundle, nil),
|
||||
NSUnderlyingErrorKey: (NSError * _Nonnull)currentInstallerError
|
||||
}];
|
||||
|
||||
// macOS 13 and later introduce a policy where Gatekeeper can block app modifications if the apps have different Team IDs
|
||||
if (@available(macOS 13, *)) {
|
||||
#if !defined(MAC_OS_VERSION_13_0) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_VERSION_13_0
|
||||
if (@available(macOS 13, *))
|
||||
#endif
|
||||
{
|
||||
NSBundle *mainBundle = [NSBundle mainBundle];
|
||||
if (![mainBundle isEqual:self.host.bundle]) {
|
||||
if (![mainBundle isEqual:_host.bundle]) {
|
||||
SUHost *mainBundleHost = [[SUHost alloc] initWithBundle:mainBundle];
|
||||
|
||||
userInfo[NSLocalizedRecoverySuggestionErrorKey] = [NSString stringWithFormat:SULocalizedString(@"You may need to allow modifications from %1$@ in System Settings under Privacy & Security and App Management to install future updates.", nil), mainBundleHost.name];
|
||||
userInfo[NSLocalizedRecoverySuggestionErrorKey] = [NSString stringWithFormat:SULocalizedStringFromTableInBundle(@"You may need to allow modifications from %1$@ in System Settings under Privacy & Security and App Management to install future updates.", SPARKLE_TABLE, sparkleBundle, nil), mainBundleHost.name];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,56 +147,59 @@
|
||||
installerError = [NSError errorWithDomain:SUSparkleErrorDomain code:genericErrorCode userInfo:userInfo];
|
||||
}
|
||||
|
||||
[self.delegate installerIsRequestingAbortInstallWithError:installerError];
|
||||
[_delegate installerIsRequestingAbortInstallWithError:installerError];
|
||||
}
|
||||
|
||||
- (void)setUpConnection
|
||||
- (void)setUpConnection SPU_OBJC_DIRECT
|
||||
{
|
||||
if (self.installerConnection != nil) {
|
||||
if (_installerConnection != nil) {
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *hostBundleIdentifier = self.host.bundle.bundleIdentifier;
|
||||
NSString *hostBundleIdentifier = _host.bundle.bundleIdentifier;
|
||||
assert(hostBundleIdentifier != nil);
|
||||
|
||||
if (!SPUXPCServiceIsEnabled(SUEnableInstallerConnectionServiceKey)) {
|
||||
self.installerConnection = [[SUInstallerConnection alloc] initWithDelegate:self remote:NO];
|
||||
} else {
|
||||
self.installerConnection = [[SUXPCInstallerConnection alloc] initWithDelegate:self];
|
||||
#if INSTALLER_CONNECTION_XPC_SERVICE_EMBEDDED
|
||||
if (SPUXPCServiceIsEnabled(SUEnableInstallerConnectionServiceKey)) {
|
||||
_installerConnection = [[SUXPCInstallerConnection alloc] initWithDelegate:self];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
_installerConnection = [[SUInstallerConnection alloc] initWithDelegate:self remote:NO];
|
||||
}
|
||||
|
||||
__weak SPUInstallerDriver *weakSelf = self;
|
||||
[self.installerConnection setInvalidationHandler:^{
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[_installerConnection setInvalidationHandler:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
SPUInstallerDriver *strongSelf = weakSelf;
|
||||
if (strongSelf.installerConnection != nil && !strongSelf.aborted) {
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil && strongSelf->_installerConnection != nil && !strongSelf->_aborted) {
|
||||
NSDictionary *genericUserInfo = @{
|
||||
NSLocalizedDescriptionKey: SULocalizedString(@"An error occurred while running the updater. Please try again later.", nil),
|
||||
NSLocalizedDescriptionKey: SULocalizedStringFromTableInBundle(@"An error occurred while running the updater. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil),
|
||||
NSLocalizedFailureReasonErrorKey:@"The remote port connection was invalidated from the updater. For additional details, please check Console logs for "@SPARKLE_RELAUNCH_TOOL_NAME". If your application is sandboxed, please also ensure Installer Connection & Status entitlements are correctly set up: https://sparkle-project.org/documentation/sandboxing/"
|
||||
};
|
||||
|
||||
[strongSelf _reportInstallerError:strongSelf.installerError genericErrorCode:SUInstallationError genericUserInfo:genericUserInfo];
|
||||
[strongSelf _reportInstallerError:strongSelf->_installerError genericErrorCode:SUInstallationError genericUserInfo:genericUserInfo];
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
||||
NSString *serviceName = SPUInstallerServiceNameForBundleIdentifier(hostBundleIdentifier);
|
||||
NSString *installationType = self.updateItem.installationType;
|
||||
NSString *installationType = _updateItem.installationType;
|
||||
assert(installationType != nil);
|
||||
|
||||
[self.installerConnection setServiceName:serviceName systemDomain:self.systemDomain];
|
||||
[_installerConnection setServiceName:serviceName systemDomain:_systemDomain];
|
||||
}
|
||||
|
||||
// This can be called multiple times (eg: if a delta update fails, this may be called again with a regular update item)
|
||||
- (void)extractDownloadedUpdate:(SPUDownloadedUpdate *)downloadedUpdate silently:(BOOL)silently completion:(void (^)(NSError * _Nullable))completionHandler
|
||||
{
|
||||
self.updateItem = downloadedUpdate.updateItem;
|
||||
self.temporaryDirectory = downloadedUpdate.temporaryDirectory;
|
||||
self.downloadName = downloadedUpdate.downloadName;
|
||||
_updateItem = downloadedUpdate.updateItem;
|
||||
_temporaryDirectory = downloadedUpdate.temporaryDirectory;
|
||||
_downloadName = downloadedUpdate.downloadName;
|
||||
|
||||
self.currentStage = SPUInstallerNotStarted;
|
||||
_currentStage = SPUInstallerNotStarted;
|
||||
|
||||
if (self.installerConnection == nil) {
|
||||
if (_installerConnection == nil) {
|
||||
[self launchAutoUpdateSilently:silently completion:completionHandler];
|
||||
} else {
|
||||
// The Install tool is already alive; just send out installation input data again
|
||||
@@ -217,49 +210,59 @@
|
||||
|
||||
- (void)resumeInstallingUpdateWithUpdateItem:(SUAppcastItem *)updateItem systemDomain:(BOOL)systemDomain
|
||||
{
|
||||
self.updateItem = updateItem;
|
||||
self.systemDomain = systemDomain;
|
||||
_updateItem = updateItem;
|
||||
_systemDomain = systemDomain;
|
||||
}
|
||||
|
||||
- (void)sendInstallationData
|
||||
- (void)sendInstallationData SPU_OBJC_DIRECT
|
||||
{
|
||||
NSString *pathToRelaunch = self.applicationBundle.bundlePath;
|
||||
NSString *pathToRelaunch = _applicationBundle.bundlePath;
|
||||
|
||||
#if SPARKLE_BUILD_DMG_SUPPORT || SPARKLE_BUILD_LEGACY_SUUPDATER
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
id updater = _updater;
|
||||
#endif
|
||||
|
||||
#if SPARKLE_BUILD_LEGACY_SUUPDATER
|
||||
// Give the delegate one more chance for determining the path to relaunch via a private API used by SUUpdater
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(_pathToRelaunchForUpdater:)]) {
|
||||
NSString *relaunchPath = [(NSObject *)self.updaterDelegate _pathToRelaunchForUpdater:self.updater];
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector(_pathToRelaunchForUpdater:)]) {
|
||||
NSString *relaunchPath = [(NSObject *)updaterDelegate _pathToRelaunchForUpdater:updater];
|
||||
if (relaunchPath != nil) {
|
||||
pathToRelaunch = relaunchPath;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
NSString *decryptionPassword = nil;
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(decryptionPasswordForUpdater:)]) {
|
||||
decryptionPassword = [self.updaterDelegate decryptionPasswordForUpdater:self.updater];
|
||||
#if SPARKLE_BUILD_DMG_SUPPORT
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector(decryptionPasswordForUpdater:)]) {
|
||||
decryptionPassword = [updaterDelegate decryptionPasswordForUpdater:updater];
|
||||
}
|
||||
#endif
|
||||
|
||||
SPUInstallationInputData *installationData = [[SPUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:self.host.bundlePath updateDirectoryPath:self.temporaryDirectory downloadName:self.downloadName installationType:self.updateItem.installationType signatures:self.updateItem.signatures decryptionPassword:decryptionPassword];
|
||||
SPUInstallationInputData *installationData = [[SPUInstallationInputData alloc] initWithRelaunchPath:pathToRelaunch hostBundlePath:_host.bundlePath updateDirectoryPath:_temporaryDirectory downloadName:_downloadName installationType:_updateItem.installationType signatures:_updateItem.signatures decryptionPassword:decryptionPassword];
|
||||
|
||||
NSData *archivedData = SPUArchiveRootObjectSecurely(installationData);
|
||||
if (archivedData == nil) {
|
||||
[self.delegate installerIsRequestingAbortInstallWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:@"An error occurred while encoding the installer parameters. Please try again later." }]];
|
||||
[_delegate installerIsRequestingAbortInstallWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:@"An error occurred while encoding the installer parameters. Please try again later." }]];
|
||||
return;
|
||||
}
|
||||
|
||||
[self.installerConnection handleMessageWithIdentifier:SPUInstallationData data:archivedData];
|
||||
[_installerConnection handleMessageWithIdentifier:SPUInstallationData data:archivedData];
|
||||
|
||||
self.currentStage = SPUInstallerNotStarted;
|
||||
_currentStage = SPUInstallerNotStarted;
|
||||
|
||||
// If the number of extractions attempts stays the same, then we've waited too long and should abort the installation
|
||||
// The extraction attempts is incremented when we receive an extraction should start message from the installer
|
||||
// This also handles the case when a delta extraction fails and tries to re-try another extraction attempt later
|
||||
// We will also want to make sure current stage is still SUInstallerNotStarted because it may not be due to resumability
|
||||
NSUInteger currentExtractionAttempts = self.extractionAttempts;
|
||||
__weak SPUInstallerDriver *weakSelf = self;
|
||||
NSUInteger currentExtractionAttempts = _extractionAttempts;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(FIRST_INSTALLER_MESSAGE_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
SPUInstallerDriver *strongSelf = weakSelf;
|
||||
if (strongSelf != nil && strongSelf.currentStage == SPUInstallerNotStarted && currentExtractionAttempts == self.extractionAttempts) {
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
if (strongSelf != nil && strongSelf->_currentStage == SPUInstallerNotStarted && currentExtractionAttempts == strongSelf->_extractionAttempts) {
|
||||
SULog(SULogLevelError, @"Timeout: Installer never started archive extraction");
|
||||
[strongSelf.delegate installerIsRequestingAbortInstallWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while starting the installer. Please try again later.", nil) }]];
|
||||
[strongSelf->_delegate installerIsRequestingAbortInstallWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedStringFromTableInBundle(@"An error occurred while starting the installer. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil) }]];
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -271,48 +274,50 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)_handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data
|
||||
- (void)_handleMessageWithIdentifier:(int32_t)identifier data:(NSData *)data SPU_OBJC_DIRECT
|
||||
{
|
||||
if (!SPUInstallerMessageTypeIsLegal(self.currentStage, identifier)) {
|
||||
SULog(SULogLevelError, @"Error: received out of order message with current stage: %d, requested stage: %d", self.currentStage, identifier);
|
||||
if (!SPUInstallerMessageTypeIsLegal(_currentStage, identifier)) {
|
||||
SULog(SULogLevelError, @"Error: received out of order message with current stage: %d, requested stage: %d", _currentStage, identifier);
|
||||
return;
|
||||
}
|
||||
|
||||
id<SPUInstallerDriverDelegate> delegate = _delegate;
|
||||
|
||||
if (identifier == SPUExtractionStarted) {
|
||||
self.extractionAttempts++;
|
||||
self.currentStage = identifier;
|
||||
[self.delegate installerDidStartExtracting];
|
||||
_extractionAttempts++;
|
||||
_currentStage = identifier;
|
||||
[delegate installerDidStartExtracting];
|
||||
} else if (identifier == SPUExtractedArchiveWithProgress) {
|
||||
if (data.length == sizeof(double) && sizeof(double) == sizeof(uint64_t)) {
|
||||
uint64_t progressValue = CFSwapInt64LittleToHost(*(const uint64_t *)data.bytes);
|
||||
double progress = *(double *)&progressValue;
|
||||
[self.delegate installerDidExtractUpdateWithProgress:progress];
|
||||
self.currentStage = identifier;
|
||||
[delegate installerDidExtractUpdateWithProgress:progress];
|
||||
_currentStage = identifier;
|
||||
}
|
||||
} else if (identifier == SPUArchiveExtractionFailed) {
|
||||
// If this is a delta update, there must be a regular update we can fall back to
|
||||
if ([self.updateItem isDeltaUpdate]) {
|
||||
[self.delegate installerDidFailToApplyDeltaUpdate];
|
||||
if ([_updateItem isDeltaUpdate]) {
|
||||
[delegate installerDidFailToApplyDeltaUpdate];
|
||||
} else {
|
||||
// Don't have to store current stage because we're going to abort
|
||||
NSDictionary *genericUserInfo = @{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) };
|
||||
NSDictionary *genericUserInfo = @{ NSLocalizedDescriptionKey:SULocalizedStringFromTableInBundle(@"An error occurred while extracting the archive. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil) };
|
||||
|
||||
NSError *unarchivedError = (NSError *)SPUUnarchiveRootObjectSecurely(data, [NSError class]);
|
||||
[self _reportInstallerError:unarchivedError genericErrorCode:SUUnarchivingError genericUserInfo:genericUserInfo];
|
||||
}
|
||||
} else if (identifier == SPUValidationStarted) {
|
||||
self.currentStage = identifier;
|
||||
_currentStage = identifier;
|
||||
} else if (identifier == SPUInstallationStartedStage1) {
|
||||
self.currentStage = identifier;
|
||||
_currentStage = identifier;
|
||||
} else if (identifier == SPUInstallationFinishedStage1) {
|
||||
self.currentStage = identifier;
|
||||
_currentStage = identifier;
|
||||
|
||||
// Let the installer keep a copy of the appcast item data
|
||||
// We may want to ask for it later (note the updater can relaunch without the app necessarily having relaunched)
|
||||
NSData *updateItemData = SPUArchiveRootObjectSecurely(self.updateItem);
|
||||
NSData *updateItemData = SPUArchiveRootObjectSecurely(_updateItem);
|
||||
|
||||
if (updateItemData != nil) {
|
||||
[self.installerConnection handleMessageWithIdentifier:SPUSentUpdateAppcastItemData data:updateItemData];
|
||||
[_installerConnection handleMessageWithIdentifier:SPUSentUpdateAppcastItemData data:updateItemData];
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Error: Archived data to send for appcast item is nil");
|
||||
}
|
||||
@@ -327,47 +332,47 @@
|
||||
hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes + 1);
|
||||
}
|
||||
|
||||
[self.delegate installerDidFinishPreparationAndWillInstallImmediately:hasTargetTerminated silently:canInstallSilently];
|
||||
[delegate installerDidFinishPreparationAndWillInstallImmediately:hasTargetTerminated silently:canInstallSilently];
|
||||
} else if (identifier == SPUInstallationFinishedStage2) {
|
||||
self.currentStage = identifier;
|
||||
_currentStage = identifier;
|
||||
|
||||
BOOL hasTargetTerminated = NO;
|
||||
if (data.length >= sizeof(uint8_t)) {
|
||||
hasTargetTerminated = (BOOL)*((const uint8_t *)data.bytes);
|
||||
}
|
||||
|
||||
[self.delegate installerWillFinishInstallationAndRelaunch:self.relaunch];
|
||||
[delegate installerWillFinishInstallationAndRelaunch:_relaunch];
|
||||
|
||||
[self.delegate installerDidStartInstallingWithApplicationTerminated:hasTargetTerminated];
|
||||
[delegate installerDidStartInstallingWithApplicationTerminated:hasTargetTerminated];
|
||||
} else if (identifier == SPUInstallationFinishedStage3) {
|
||||
self.currentStage = identifier;
|
||||
_currentStage = identifier;
|
||||
|
||||
[self.installerConnection invalidate];
|
||||
self.installerConnection = nil;
|
||||
[_installerConnection invalidate];
|
||||
_installerConnection = nil;
|
||||
|
||||
[self.delegate installerDidFinishInstallationAndRelaunched:self.relaunch acknowledgement:^{
|
||||
[delegate installerDidFinishInstallationAndRelaunched:_relaunch acknowledgement:^{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.delegate installerIsRequestingAbortInstallWithError:nil];
|
||||
[delegate installerIsRequestingAbortInstallWithError:nil];
|
||||
});
|
||||
}];
|
||||
} else if (identifier == SPUUpdaterAlivePing) {
|
||||
// Don't update the current stage; a ping request has no effect on that.
|
||||
[self.installerConnection handleMessageWithIdentifier:SPUUpdaterAlivePong data:[NSData data]];
|
||||
[_installerConnection handleMessageWithIdentifier:SPUUpdaterAlivePong data:[NSData data]];
|
||||
} else if (identifier == SPUInstallerError) {
|
||||
// Don't update the current stage; an installation error has no effect on that.
|
||||
self.installerError = (NSError *)SPUUnarchiveRootObjectSecurely(data, [NSError class]);
|
||||
_installerError = (NSError *)SPUUnarchiveRootObjectSecurely(data, [NSError class]);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)launchAutoUpdateSilently:(BOOL)silently completion:(void (^)(NSError *_Nullable))completionHandler
|
||||
- (void)launchAutoUpdateSilently:(BOOL)silently completion:(void (^)(NSError *_Nullable))completionHandler SPU_OBJC_DIRECT
|
||||
{
|
||||
id<SUInstallerLauncherProtocol> installerLauncher = nil;
|
||||
id<SUInstallerLauncherProtocol> installerLauncher;
|
||||
|
||||
#if INSTALLER_LAUNCHER_XPC_SERVICE_EMBEDDED
|
||||
__block BOOL retrievedLaunchStatus = NO;
|
||||
NSXPCConnection *launcherConnection = nil;
|
||||
|
||||
if (!SPUXPCServiceIsEnabled(SUEnableInstallerLauncherServiceKey)) {
|
||||
installerLauncher = [[SUInstallerLauncher alloc] init];
|
||||
} else {
|
||||
if (SPUXPCServiceIsEnabled(SUEnableInstallerLauncherServiceKey)) {
|
||||
launcherConnection = [[NSXPCConnection alloc] initWithServiceName:@INSTALLER_LAUNCHER_BUNDLE_ID];
|
||||
launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)];
|
||||
|
||||
@@ -392,7 +397,7 @@
|
||||
if (!retrievedLaunchStatus) {
|
||||
#pragma clang diagnostic pop
|
||||
NSError *error =
|
||||
[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while connecting to the installer. Please try again later.", nil) }];
|
||||
[NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedStringFromTableInBundle(@"An error occurred while connecting to the installer. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil) }];
|
||||
|
||||
completionHandler(error);
|
||||
|
||||
@@ -409,16 +414,20 @@
|
||||
[launcherConnection resume];
|
||||
|
||||
installerLauncher = launcherConnection.remoteObjectProxy;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
installerLauncher = [[SUInstallerLauncher alloc] init];
|
||||
}
|
||||
|
||||
// Our driver (automatic or UI based) has a say if interaction is allowed as well
|
||||
// An automatic driver may disallow interaction but the updater could try again later for a UI based driver that does allow interaction
|
||||
BOOL driverAllowsInteraction = !silently;
|
||||
|
||||
NSString *hostBundlePath = self.host.bundle.bundlePath;
|
||||
NSString *hostBundlePath = _host.bundle.bundlePath;
|
||||
assert(hostBundlePath != nil);
|
||||
|
||||
NSString *installationType = self.updateItem.installationType;
|
||||
NSString *installationType = _updateItem.installationType;
|
||||
assert(installationType != nil);
|
||||
|
||||
// The installer launcher could be in a XPC service, so we don't want to do localization in there
|
||||
@@ -428,7 +437,7 @@
|
||||
|
||||
SUHost *mainBundleHost = [[SUHost alloc] initWithBundle:[NSBundle mainBundle]];
|
||||
NSString *mainBundleName = mainBundleHost.name;
|
||||
NSString *hostName = self.host.name;
|
||||
NSString *hostName = _host.name;
|
||||
|
||||
// Changing this authorization prompt is a little complicated because the
|
||||
// Auth database retains and caches the right we use, and there isn't a good way
|
||||
@@ -450,13 +459,15 @@
|
||||
|
||||
[installerLauncher launchInstallerWithHostBundlePath:hostBundlePath updaterIdentifier:mainBundleIdentifier authorizationPrompt:authorizationPrompt installationType:installationType allowingDriverInteraction:driverAllowsInteraction completion:^(SUInstallerLauncherStatus result, BOOL systemDomain) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
#if INSTALLER_LAUNCHER_XPC_SERVICE_EMBEDDED
|
||||
retrievedLaunchStatus = YES;
|
||||
[launcherConnection invalidate];
|
||||
#endif
|
||||
|
||||
switch (result) {
|
||||
case SUInstallerLauncherFailure:
|
||||
SULog(SULogLevelError, @"Error: Failed to gain authorization required to update target");
|
||||
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while launching the installer. Please try again later.", nil) }]);
|
||||
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedStringFromTableInBundle(@"An error occurred while launching the installer. Please try again later.", SPARKLE_TABLE, SUSparkleBundle(), nil) }]);
|
||||
break;
|
||||
case SUInstallerLauncherCanceled:
|
||||
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationCanceledError userInfo:nil]);
|
||||
@@ -465,7 +476,7 @@
|
||||
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationAuthorizeLaterError userInfo:nil]);
|
||||
break;
|
||||
case SUInstallerLauncherSuccess:
|
||||
self.systemDomain = systemDomain;
|
||||
self->_systemDomain = systemDomain;
|
||||
[self setUpConnection];
|
||||
[self sendInstallationData];
|
||||
completionHandler(nil);
|
||||
@@ -475,28 +486,31 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (BOOL)mayUpdateAndRestart
|
||||
- (BOOL)mayUpdateAndRestart SPU_OBJC_DIRECT
|
||||
{
|
||||
return (!self.updaterDelegate || ![self.updaterDelegate respondsToSelector:@selector((updaterShouldRelaunchApplication:))] || [self.updaterDelegate updaterShouldRelaunchApplication:self.updater]);
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
return (!updaterDelegate || ![updaterDelegate respondsToSelector:@selector((updaterShouldRelaunchApplication:))] || [updaterDelegate updaterShouldRelaunchApplication:_updater]);
|
||||
}
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI
|
||||
{
|
||||
assert(self.updateItem);
|
||||
assert(_updateItem);
|
||||
|
||||
if (![self mayUpdateAndRestart])
|
||||
{
|
||||
[self.delegate installerIsRequestingAbortInstallWithError:nil];
|
||||
[_delegate installerIsRequestingAbortInstallWithError:nil];
|
||||
return;
|
||||
}
|
||||
|
||||
// Give the host app an opportunity to postpone the install and relaunch.
|
||||
if (!self.postponedOnce)
|
||||
if (!_postponedOnce)
|
||||
{
|
||||
if ([self.updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvokingBlock:)]) {
|
||||
self.postponedOnce = YES;
|
||||
__weak SPUInstallerDriver *weakSelf = self;
|
||||
if ([self.updaterDelegate updater:self.updater shouldPostponeRelaunchForUpdate:self.updateItem untilInvokingBlock:^{
|
||||
id updater = _updater;
|
||||
id<SPUUpdaterDelegate> updaterDelegate = _updaterDelegate;
|
||||
if (updater != nil && [updaterDelegate respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvokingBlock:)]) {
|
||||
_postponedOnce = YES;
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
if ([updaterDelegate updater:updater shouldPostponeRelaunchForUpdate:_updateItem untilInvokingBlock:^{
|
||||
[weakSelf installWithToolAndRelaunch:relaunch displayingUserInterface:showUI];
|
||||
}]) {
|
||||
return;
|
||||
@@ -512,14 +526,14 @@
|
||||
[self setUpConnection];
|
||||
|
||||
// For resumability, we'll assume we are far enough for the installation to continue
|
||||
self.currentStage = SPUInstallationFinishedStage1;
|
||||
_currentStage = SPUInstallationFinishedStage1;
|
||||
|
||||
self.relaunch = relaunch;
|
||||
_relaunch = relaunch;
|
||||
|
||||
uint8_t response[2] = {(uint8_t)relaunch, (uint8_t)showUI};
|
||||
NSData *responseData = [NSData dataWithBytes:response length:sizeof(response)];
|
||||
|
||||
[self.installerConnection handleMessageWithIdentifier:SPUResumeInstallationToStage2 data:responseData];
|
||||
[_installerConnection handleMessageWithIdentifier:SPUResumeInstallationToStage2 data:responseData];
|
||||
|
||||
// the installer will send us SPUInstallationFinishedStage2 when stage 2 is done
|
||||
}
|
||||
@@ -529,19 +543,19 @@
|
||||
// Set up connection to the installer if one is not set up already
|
||||
[self setUpConnection];
|
||||
|
||||
self.aborted = YES;
|
||||
_aborted = YES;
|
||||
|
||||
[self.installerConnection handleMessageWithIdentifier:SPUCancelInstallation data:[NSData data]];
|
||||
[_installerConnection handleMessageWithIdentifier:SPUCancelInstallation data:[NSData data]];
|
||||
|
||||
[self.delegate installerIsRequestingAbortInstallWithError:nil];
|
||||
[_delegate installerIsRequestingAbortInstallWithError:nil];
|
||||
}
|
||||
|
||||
- (void)abortInstall
|
||||
{
|
||||
self.aborted = YES;
|
||||
if (self.installerConnection != nil) {
|
||||
[self.installerConnection invalidate];
|
||||
self.installerConnection = nil;
|
||||
_aborted = YES;
|
||||
if (_installerConnection != nil) {
|
||||
[_installerConnection invalidate];
|
||||
_installerConnection = nil;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -10,7 +10,7 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPULocalCacheDirectory : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPULocalCacheDirectory : NSObject
|
||||
|
||||
// Returns a path to a suitable cache directory to create specifically for Sparkle
|
||||
// Intermediate directories to this path may not exist yet
|
||||
|
||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SPUInstallationInfo;
|
||||
|
||||
@interface SPUProbeInstallStatus : NSObject
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUProbeInstallStatus : NSObject
|
||||
|
||||
+ (void)probeInstallerInProgressForHostBundleIdentifier:(NSString *)hostBundleIdentifier completion:(void (^)(BOOL))completionHandler;
|
||||
|
||||
|
||||
Vendored
+15
-19
@@ -27,12 +27,14 @@
|
||||
|
||||
+ (void)probeInstallerInProgressForHostBundleIdentifier:(NSString *)hostBundleIdentifier completion:(void (^)(BOOL))completionHandler
|
||||
{
|
||||
id<SUInstallerStatusProtocol> installerStatus = nil;
|
||||
BOOL usesXPC = SPUXPCServiceIsEnabled(SUEnableInstallerStatusServiceKey);
|
||||
if (!usesXPC) {
|
||||
installerStatus = [[SUInstallerStatus alloc] initWithRemote:NO];
|
||||
} else {
|
||||
id<SUInstallerStatusProtocol> installerStatus;
|
||||
#if INSTALLER_STATUS_XPC_SERVICE_EMBEDDED
|
||||
if (SPUXPCServiceIsEnabled(SUEnableInstallerStatusServiceKey)) {
|
||||
installerStatus = [[SUXPCInstallerStatus alloc] init];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
installerStatus = [[SUInstallerStatus alloc] initWithRemote:NO];
|
||||
}
|
||||
|
||||
__block BOOL handledCompletion = NO;
|
||||
@@ -76,11 +78,7 @@
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(PROBE_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!handledCompletion) {
|
||||
#pragma clang diagnostic pop
|
||||
if (usesXPC) {
|
||||
SULog(SULogLevelError, @"Timed out while probing installer progress. Please see https://sparkle-project.org/documentation/sandboxing/#testing for potential cause.");
|
||||
} else {
|
||||
SULog(SULogLevelError, @"Timed out while probing installer progress");
|
||||
}
|
||||
SULog(SULogLevelError, @"Timed out while probing installer progress. If your app is sandboxed, please see https://sparkle-project.org/documentation/sandboxing/#testing for the potential cause.");
|
||||
completionHandler(NO);
|
||||
handledCompletion = YES;
|
||||
}
|
||||
@@ -91,11 +89,13 @@
|
||||
+ (void)probeInstallerUpdateItemForHostBundleIdentifier:(NSString *)hostBundleIdentifier completion:(void (^)(SPUInstallationInfo * _Nullable))completionHandler
|
||||
{
|
||||
id<SUInstallerStatusProtocol> installerStatus = nil;
|
||||
BOOL usesXPC = SPUXPCServiceIsEnabled(SUEnableInstallerStatusServiceKey);
|
||||
if (!usesXPC) {
|
||||
installerStatus = [[SUInstallerStatus alloc] initWithRemote:NO];
|
||||
} else {
|
||||
#if INSTALLER_STATUS_XPC_SERVICE_EMBEDDED
|
||||
if (SPUXPCServiceIsEnabled(SUEnableInstallerStatusServiceKey)) {
|
||||
installerStatus = [[SUXPCInstallerStatus alloc] init];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
installerStatus = [[SUInstallerStatus alloc] initWithRemote:NO];
|
||||
}
|
||||
|
||||
__block BOOL handledCompletion = NO;
|
||||
@@ -145,11 +145,7 @@
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(PROBE_TIMEOUT * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
if (!handledCompletion) {
|
||||
#pragma clang diagnostic pop
|
||||
if (usesXPC) {
|
||||
SULog(SULogLevelDefault, @"Timed out while probing installer info data. Please see https://sparkle-project.org/documentation/sandboxing/#testing for potential cause.");
|
||||
} else {
|
||||
SULog(SULogLevelDefault, @"Timed out while probing installer info data");
|
||||
}
|
||||
SULog(SULogLevelDefault, @"Timed out while probing installer info data. If your app is sandboxed, please see https://sparkle-project.org/documentation/sandboxing/#testing for the potential cause.");
|
||||
completionHandler(nil);
|
||||
handledCompletion = YES;
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@class SUHost;
|
||||
@protocol SPUUpdaterDelegate;
|
||||
|
||||
@interface SPUProbingUpdateDriver : NSObject <SPUUpdateDriver>
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SPUProbingUpdateDriver : NSObject <SPUUpdateDriver>
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host updater:(id)updater updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate;
|
||||
|
||||
|
||||
Loaded 100 of 203 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user