From 60d4f0574399c7343daf2493bb38c6fb2ae8ed9d Mon Sep 17 00:00:00 2001 From: Zorg Date: Wed, 21 Dec 2016 11:07:03 -0500 Subject: [PATCH 1/4] Add SUUnarchiverProtocol & remove runtime registration of unarchivers --- Sparkle.xcodeproj/project.pbxproj | 8 +- Sparkle/SUAutomaticUpdateDriver.h | 1 + Sparkle/SUAutomaticUpdateDriver.m | 2 +- Sparkle/SUBasicUpdateDriver.h | 5 +- Sparkle/SUBasicUpdateDriver.m | 9 +- Sparkle/SUBinaryDeltaUnarchiver.h | 12 ++- Sparkle/SUBinaryDeltaUnarchiver.m | 72 ++++++++------ Sparkle/SUDiskImageUnarchiver.h | 12 ++- Sparkle/SUDiskImageUnarchiver.m | 133 +++++++++++++------------- Sparkle/SUPipedUnarchiver.h | 12 ++- Sparkle/SUPipedUnarchiver.m | 151 +++++++++++++++--------------- Sparkle/SUUIBasedUpdateDriver.h | 1 + Sparkle/SUUIBasedUpdateDriver.m | 2 +- Sparkle/SUUnarchiver.h | 27 +----- Sparkle/SUUnarchiver.m | 97 ++++--------------- Sparkle/SUUnarchiverProtocol.h | 36 +++++++ Sparkle/SUUnarchiver_Private.h | 26 ----- Tests/SUUnarchiverTest.swift | 10 +- 18 files changed, 286 insertions(+), 330 deletions(-) create mode 100644 Sparkle/SUUnarchiverProtocol.h delete mode 100644 Sparkle/SUUnarchiver_Private.h diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index a9e8c6a6..a47dd397 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -104,7 +104,6 @@ 6102FE460E077FCE00F85D09 /* SUPipedUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE4A0E07803800F85D09 /* SUDiskImageUnarchiver.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */; settings = {ATTRIBUTES = (); }; }; 6102FE4B0E07803800F85D09 /* SUDiskImageUnarchiver.m in Sources */ = {isa = PBXBuildFile; fileRef = 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */; }; - 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */; settings = {ATTRIBUTES = (); }; }; 611142E910FB1BE5009810AA /* bspatch.h in Headers */ = {isa = PBXBuildFile; fileRef = 611142E810FB1BE5009810AA /* bspatch.h */; }; 61177A1F0D1112E900749C97 /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6117796E0D1112E000749C97 /* IOKit.framework */; }; 61180BCA0D64138900B4E0D1 /* SUWindowController.h in Headers */ = {isa = PBXBuildFile; fileRef = 61180BC80D64138900B4E0D1 /* SUWindowController.h */; settings = {ATTRIBUTES = (); }; }; @@ -176,6 +175,7 @@ 721CF1AA1AD7647000D9AC09 /* libxar.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D1AF5890FD7678C0065DB48 /* libxar.1.dylib */; }; 721CF1AB1AD764EB00D9AC09 /* libbz2.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 5D06E8FB0FD68D61005AE3F6 /* libbz2.dylib */; }; 7223E7631AD1AEFF008E3161 /* sais.c in Sources */ = {isa = PBXBuildFile; fileRef = 7223E7611AD1AEFF008E3161 /* sais.c */; }; + 722589D71E0AD86B005EA0B9 /* SUUnarchiverProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 722589D61E0AD86B005EA0B9 /* SUUnarchiverProtocol.h */; }; 722954B71D04ADAF00ECF9CA /* fileop.m in Sources */ = {isa = PBXBuildFile; fileRef = 722954B61D04ADAF00ECF9CA /* fileop.m */; }; 722954BC1D04AE1100ECF9CA /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7275F9C01B5F1F2900B1D19E /* SUFileManager.m */; }; 722954BD1D04AE3800ECF9CA /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; @@ -569,7 +569,6 @@ 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUPipedUnarchiver.h; sourceTree = ""; }; 6102FE480E07803800F85D09 /* SUDiskImageUnarchiver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUDiskImageUnarchiver.h; sourceTree = ""; }; 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUDiskImageUnarchiver.m; sourceTree = ""; }; - 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiver_Private.h; sourceTree = ""; }; 611142E810FB1BE5009810AA /* bspatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = bspatch.h; sourceTree = ""; }; 61131A050F846CE600E97AF6 /* da */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = da; path = da.lproj/Sparkle.strings; sourceTree = ""; }; 61131A090F846D0A00E97AF6 /* zh_CN */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.strings; name = zh_CN; path = zh_CN.lproj/Sparkle.strings; sourceTree = ""; }; @@ -675,6 +674,7 @@ 7210C7671B9A9A1500EB90AC /* SUUnarchiverTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SUUnarchiverTest.swift; sourceTree = ""; }; 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; + 722589D61E0AD86B005EA0B9 /* SUUnarchiverProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUnarchiverProtocol.h; sourceTree = ""; }; 722954B41D04ADAF00ECF9CA /* fileop */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = fileop; sourceTree = BUILT_PRODUCTS_DIR; }; 722954B61D04ADAF00ECF9CA /* fileop.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = fileop.m; sourceTree = ""; }; 722954C21D04E66F00ECF9CA /* SUFileOperationConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUFileOperationConstants.h; sourceTree = ""; }; @@ -1015,9 +1015,9 @@ 6102FE490E07803800F85D09 /* SUDiskImageUnarchiver.m */, 6102FE440E077FCE00F85D09 /* SUPipedUnarchiver.h */, 6129C0B90E0B79810062CE76 /* SUPipedUnarchiver.m */, + 722589D61E0AD86B005EA0B9 /* SUUnarchiverProtocol.h */, 61299A8B09CA790200B7442F /* SUUnarchiver.h */, 61299A8C09CA790200B7442F /* SUUnarchiver.m */, - 6102FE590E08C7EC00F85D09 /* SUUnarchiver_Private.h */, ); name = Unarchiving; sourceTree = ""; @@ -1268,6 +1268,7 @@ 61EF67590E25C5B400F754E0 /* SUHost.h in Headers */, 729924731DF3478A00DBCDF5 /* SUUpdateValidator.h in Headers */, 723B25301CEAB3A600909873 /* bscommon.h in Headers */, + 722589D71E0AD86B005EA0B9 /* SUUnarchiverProtocol.h in Headers */, 618FA5010DAE88B40026945C /* SUInstaller.h in Headers */, 55C14F06136EF6DB00649790 /* SULog.h in Headers */, 726F2CE51BC9C33D001971A4 /* SUOperatingSystem.h in Headers */, @@ -1281,7 +1282,6 @@ 61A2279C0D1CEE7600430CCD /* SUSystemProfiler.h in Headers */, 61B93A3C0DD02D7000DCD2F8 /* SUUIBasedUpdateDriver.h in Headers */, 61299A8D09CA790200B7442F /* SUUnarchiver.h in Headers */, - 6102FE5B0E08C7EC00F85D09 /* SUUnarchiver_Private.h in Headers */, 61B5FCDF09C52A9F00B25A18 /* SUUpdateAlert.h in Headers */, 610134730DD250470049ACDF /* SUUpdateDriver.h in Headers */, 612DCBAF0D488BC60015DBEA /* SUUpdatePermissionPrompt.h in Headers */, diff --git a/Sparkle/SUAutomaticUpdateDriver.h b/Sparkle/SUAutomaticUpdateDriver.h index 4dd90e8f..8893be2d 100644 --- a/Sparkle/SUAutomaticUpdateDriver.h +++ b/Sparkle/SUAutomaticUpdateDriver.h @@ -12,6 +12,7 @@ #import #import "SUBasicUpdateDriver.h" #import "SUAutomaticUpdateAlert.h" +#import "SUUnarchiverProtocol.h" @interface SUAutomaticUpdateDriver : SUBasicUpdateDriver diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 6727d0d9..f6d23b04 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -62,7 +62,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } -- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua +- (void)unarchiverDidFinish { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(systemWillPowerOff:) name:NSWorkspaceWillPowerOffNotification object:nil]; diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index 301b4bc5..7fac32f8 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -13,6 +13,7 @@ #import "SUUpdateDriver.h" #import "SUUnarchiver.h" #import "SUAppcast.h" +#import "SUUnarchiverProtocol.h" @class SUAppcastItem, SUHost; @interface SUBasicUpdateDriver : SUUpdateDriver @@ -37,8 +38,8 @@ - (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error; - (void)extractUpdate; -- (void)unarchiverDidFinish:(SUUnarchiver *)ua; -- (void)unarchiverDidFail:(SUUnarchiver *)ua; +- (void)unarchiverDidFinish; +- (void)unarchiverDidFail; - (void)failedToApplyDeltaUpdate; - (void)installWithToolAndRelaunch:(BOOL)relaunch; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 0c714d03..73cd75e2 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -316,7 +316,7 @@ - (void)extractUpdate { - SUUnarchiver *unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath withPassword:self.updater.decryptionPassword]; + id unarchiver = [SUUnarchiver unarchiverForPath:self.downloadPath updatingHostBundlePath:self.host.bundlePath decryptionPassword:self.updater.decryptionPassword delegate:self]; BOOL success; if (!unarchiver) { @@ -333,9 +333,8 @@ } if (!success) { - [self unarchiverDidFail:nil]; + [self unarchiverDidFail]; } else { - unarchiver.delegate = self; [unarchiver start]; } } @@ -349,14 +348,14 @@ [self downloadUpdate]; } -- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua +- (void)unarchiverDidFinish { assert(self.updateItem); [self installWithToolAndRelaunch:YES]; } -- (void)unarchiverDidFail:(SUUnarchiver *)__unused ua +- (void)unarchiverDidFail { // No longer needed self.updateValidator = nil; diff --git a/Sparkle/SUBinaryDeltaUnarchiver.h b/Sparkle/SUBinaryDeltaUnarchiver.h index 1e71cbe4..d7e0b7b6 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.h +++ b/Sparkle/SUBinaryDeltaUnarchiver.h @@ -9,11 +9,17 @@ #ifndef SUBINARYDELTAUNARCHIVER_H #define SUBINARYDELTAUNARCHIVER_H -#import -#import "SUUnarchiver.h" +#import +#import "SUUnarchiverProtocol.h" -@interface SUBinaryDeltaUnarchiver : SUUnarchiver +NS_ASSUME_NONNULL_BEGIN + +@interface SUBinaryDeltaUnarchiver : NSObject + +- (instancetype)initWithArchivePath:(NSString *)archivePath updateHostBundlePath:(NSString *)updateHostBundlePath delegate:(nullable id )delegate; @end +NS_ASSUME_NONNULL_END + #endif diff --git a/Sparkle/SUBinaryDeltaUnarchiver.m b/Sparkle/SUBinaryDeltaUnarchiver.m index 5ff34bd8..666bff83 100644 --- a/Sparkle/SUBinaryDeltaUnarchiver.m +++ b/Sparkle/SUBinaryDeltaUnarchiver.m @@ -6,16 +6,26 @@ // Copyright 2009 Mark Rowe. All rights reserved. // -#import "SUBinaryDeltaCommon.h" #import "SUBinaryDeltaUnarchiver.h" +#import "SUBinaryDeltaCommon.h" #import "SUBinaryDeltaApply.h" -#import "SUUnarchiver_Private.h" -#import "SUFileManager.h" -#import "SUHost.h" #import "SULog.h" +#import "SUFileManager.h" + +@interface SUBinaryDeltaUnarchiver () + +@property (nonatomic, copy, readonly) NSString *archivePath; +@property (nonatomic, copy, readonly) NSString *updateHostBundlePath; +@property (nonatomic, weak, readonly) id delegate; + +@end @implementation SUBinaryDeltaUnarchiver +@synthesize archivePath = _archivePath; +@synthesize updateHostBundlePath = _updateHostBundlePath; +@synthesize delegate = _delegate; + + (BOOL)canUnarchivePath:(NSString *)path { return [[path pathExtension] isEqualToString:@"delta"]; @@ -61,40 +71,44 @@ } } -- (void)applyBinaryDelta +- (instancetype)initWithArchivePath:(NSString *)archivePath updateHostBundlePath:(NSString *)updateHostBundlePath delegate:(id )delegate { - @autoreleasepool { - NSString *sourcePath = self.updateHostBundlePath; - NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]]; - - NSError *applyDiffError = nil; - BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, &applyDiffError); - if (success) { - [[self class] updateSpotlightImportersAtBundlePath:targetPath]; - - dispatch_async(dispatch_get_main_queue(), ^{ - [self notifyDelegateOfSuccess]; - }); - } - else { - SULog(@"Applying delta patch failed with error: %@", applyDiffError); - dispatch_async(dispatch_get_main_queue(), ^{ - [self notifyDelegateOfFailure]; - }); - } + self = [super init]; + if (self != nil) { + _archivePath = [archivePath copy]; + _updateHostBundlePath = [updateHostBundlePath copy]; + _delegate = delegate; } + return self; } - (void)start { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self applyBinaryDelta]; + @autoreleasepool { + NSString *sourcePath = self.updateHostBundlePath; + NSString *targetPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[sourcePath lastPathComponent]]; + + NSError *applyDiffError = nil; + BOOL success = applyBinaryDelta(sourcePath, targetPath, self.archivePath, NO, &applyDiffError); + + if (success) { + [[self class] updateSpotlightImportersAtBundlePath:targetPath]; + + dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate unarchiverDidFinish]; + }); + } + else { + SULog(@"Applying delta patch failed with error: %@", applyDiffError); + dispatch_async(dispatch_get_main_queue(), ^{ + [self.delegate unarchiverDidFail]; + }); + } + } }); } -+ (void)load -{ - [self registerImplementation:self]; -} +- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; } @end diff --git a/Sparkle/SUDiskImageUnarchiver.h b/Sparkle/SUDiskImageUnarchiver.h index 7a8e9167..d39f68b3 100644 --- a/Sparkle/SUDiskImageUnarchiver.h +++ b/Sparkle/SUDiskImageUnarchiver.h @@ -9,11 +9,17 @@ #ifndef SUDISKIMAGEUNARCHIVER_H #define SUDISKIMAGEUNARCHIVER_H -#import -#import "SUUnarchiver.h" +#import +#import "SUUnarchiverProtocol.h" -@interface SUDiskImageUnarchiver : SUUnarchiver +NS_ASSUME_NONNULL_BEGIN + +@interface SUDiskImageUnarchiver : NSObject + +- (instancetype)initWithArchivePath:(NSString *)archivePath decryptionPassword:(nullable NSString *)decryptionPassword delegate:(nullable id )delegate; @end +NS_ASSUME_NONNULL_END + #endif diff --git a/Sparkle/SUDiskImageUnarchiver.m b/Sparkle/SUDiskImageUnarchiver.m index e6f743e7..7c8fc441 100644 --- a/Sparkle/SUDiskImageUnarchiver.m +++ b/Sparkle/SUDiskImageUnarchiver.m @@ -7,12 +7,22 @@ // #import "SUDiskImageUnarchiver.h" -#import "SUUnarchiver_Private.h" #import "SULog.h" -#include + +@interface SUDiskImageUnarchiver () + +@property (nonatomic, copy, readonly) NSString *archivePath; +@property (nullable, nonatomic, copy, readonly) NSString *decryptionPassword; +@property (nonatomic, weak, readonly) id delegate; + +@end @implementation SUDiskImageUnarchiver +@synthesize archivePath = _archivePath; +@synthesize decryptionPassword = _decryptionPassword; +@synthesize delegate = _delegate; + + (BOOL)canUnarchivePath:(NSString *)path { return [[path pathExtension] isEqualToString:@"dmg"]; @@ -23,25 +33,25 @@ return NO; } -// Called on a non-main thread. -- (void)extractDMG +- (instancetype)initWithArchivePath:(NSString *)archivePath decryptionPassword:(nullable NSString *)decryptionPassword delegate:(nullable id )delegate { - @autoreleasepool { - [self extractDMGWithPassword:nil]; + self = [super init]; + if (self != nil) { + _archivePath = [archivePath copy]; + _decryptionPassword = [decryptionPassword copy]; + _delegate = delegate; } + return self; } // Called on a non-main thread. -- (void)extractDMGWithPassword:(NSString *)__unused password +- (void)extractDMG { - @autoreleasepool { + @autoreleasepool { BOOL mountedSuccessfully = NO; - - SULog(@"Extracting %@ as a DMG", self.archivePath); - + // get a unique mount point path NSString *mountPoint = nil; - FSRef tmpRef; NSFileManager *manager; NSError *error; NSArray *contents; @@ -49,33 +59,34 @@ // No, we cannot have them in the dispatch_async calls, as the goto "jump enters // lifetime of block which strongly captures a variable" dispatch_block_t delegateFailure = ^{ - [self notifyDelegateOfFailure]; + [self.delegate unarchiverDidFail]; }; dispatch_block_t delegateSuccess = ^{ - [self notifyDelegateOfSuccess]; + [self.delegate unarchiverDidFinish]; }; - do - { + do + { // Using NSUUID would make creating UUIDs be done in Cocoa, // and thus managed under ARC. Sadly, the class is in 10.8 and later. CFUUIDRef uuid = CFUUIDCreate(NULL); - if (uuid) - { + if (uuid) + { NSString *uuidString = CFBridgingRelease(CFUUIDCreateString(NULL, uuid)); - if (uuidString) - { + if (uuidString) + { mountPoint = [@"/Volumes" stringByAppendingPathComponent:uuidString]; } CFRelease(uuid); } - } - while (noErr == FSPathMakeRefWithOptions((const UInt8 *)[mountPoint fileSystemRepresentation], kFSPathMakeRefDoNotFollowLeafSymlink, &tmpRef, NULL)); - + } + // Note: this check does not follow symbolic links, which is what we want + while ([[NSURL fileURLWithPath:mountPoint] checkResourceIsReachableAndReturnError:NULL]); + NSData *promptData = nil; promptData = [NSData dataWithBytes:"yes\n" length:4]; - + NSMutableArray *arguments = [@[@"attach", self.archivePath, @"-mountpoint", mountPoint, /*@"-noverify",*/ @"-nobrowse", @"-noautoopen"] mutableCopy]; - + if (self.decryptionPassword) { NSMutableData *passwordData = [[self.decryptionPassword dataUsingEncoding:NSUTF8StringEncoding] mutableCopy]; // From the hdiutil docs: @@ -85,14 +96,14 @@ [passwordData appendData:[NSData dataWithBytes:"\0" length:1]]; [passwordData appendData:promptData]; promptData = passwordData; - + [arguments addObject:@"-stdinpass"]; } - + NSData *output = nil; NSInteger taskResult = -1; - @try - { + @try + { NSTask *task = [[NSTask alloc] init]; task.launchPath = @"/usr/bin/hdiutil"; task.currentDirectoryPath = @"/"; @@ -119,53 +130,59 @@ { goto reportError; } - - if (taskResult != 0) - { + + if (taskResult != 0) + { NSString *resultStr = output ? [[NSString alloc] initWithData:output encoding:NSUTF8StringEncoding] : nil; SULog(@"hdiutil failed with code: %ld data: <<%@>>", (long)taskResult, resultStr); goto reportError; } mountedSuccessfully = YES; - + // Now that we've mounted it, we need to copy out its contents. manager = [[NSFileManager alloc] init]; contents = [manager contentsOfDirectoryAtPath:mountPoint error:&error]; - if (error) - { + if (error) + { SULog(@"Couldn't enumerate contents of archive mounted at %@: %@", mountPoint, error); goto reportError; } - - for (NSString *item in contents) - { + + for (NSString *item in contents) + { NSString *fromPath = [mountPoint stringByAppendingPathComponent:item]; NSString *toPath = [[self.archivePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:item]; - + // We skip any files in the DMG which are not readable. if (![manager isReadableFileAtPath:fromPath]) { continue; } - + SULog(@"copyItemAtPath:%@ toPath:%@", fromPath, toPath); - - if (![manager copyItemAtPath:fromPath toPath:toPath error:&error]) - { + + if (![manager copyItemAtPath:fromPath toPath:toPath error:&error]) + { SULog(@"Couldn't copy item: %@ : %@", error, error.userInfo ? error.userInfo : @""); goto reportError; } } - + dispatch_async(dispatch_get_main_queue(), delegateSuccess); goto finally; - + reportError: dispatch_async(dispatch_get_main_queue(), delegateFailure); - + finally: if (mountedSuccessfully) { + NSTask *task = [[NSTask alloc] init]; + task.launchPath = @"/usr/bin/hdiutil"; + task.arguments = @[@"detach", mountPoint, @"-force"]; + task.standardOutput = [NSPipe pipe]; + task.standardError = [NSPipe pipe]; + @try { - [NSTask launchedTaskWithLaunchPath:@"/usr/bin/hdiutil" arguments:@[@"detach", mountPoint, @"-force"]]; + [task launch]; } @catch (NSException *exception) { SULog(@"Failed to unmount %@", mountPoint); SULog(@"Exception: %@", exception); @@ -179,28 +196,10 @@ - (void)start { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ - [self extractDMG]; + [self extractDMG]; }); } -+ (void)load -{ - [self registerImplementation:self]; -} - -- (BOOL)isEncrypted:(NSData *)resultData -{ - BOOL result = NO; - if(resultData) - { - NSString *data = [[NSString alloc] initWithData:resultData encoding:NSUTF8StringEncoding]; - - if ((data != nil) && !NSEqualRanges([data rangeOfString:@"passphrase-count"], NSMakeRange(NSNotFound, 0))) - { - result = YES; - } - } - return result; -} +- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; } @end diff --git a/Sparkle/SUPipedUnarchiver.h b/Sparkle/SUPipedUnarchiver.h index 7304ba0a..caec2b9e 100644 --- a/Sparkle/SUPipedUnarchiver.h +++ b/Sparkle/SUPipedUnarchiver.h @@ -9,11 +9,17 @@ #ifndef SUPIPEDUNARCHIVER_H #define SUPIPEDUNARCHIVER_H -#import -#import "SUUnarchiver.h" +#import +#import "SUUnarchiverProtocol.h" -@interface SUPipedUnarchiver : SUUnarchiver +NS_ASSUME_NONNULL_BEGIN + +@interface SUPipedUnarchiver : NSObject + +- (instancetype)initWithArchivePath:(NSString *)archivePath delegate:(nullable id )delegate; @end +NS_ASSUME_NONNULL_END + #endif diff --git a/Sparkle/SUPipedUnarchiver.m b/Sparkle/SUPipedUnarchiver.m index 0b0157c3..0b2a7b85 100644 --- a/Sparkle/SUPipedUnarchiver.m +++ b/Sparkle/SUPipedUnarchiver.m @@ -7,38 +7,56 @@ // #import "SUPipedUnarchiver.h" -#import "SUUnarchiver_Private.h" #import "SULog.h" +@interface SUPipedUnarchiver () + +@property (nonatomic, copy, readonly) NSString *archivePath; +@property (nonatomic, weak, readonly) id delegate; + +@end @implementation SUPipedUnarchiver -+ (SEL)selectorConformingToTypeOfPath:(NSString *)path +@synthesize archivePath = _archivePath; +@synthesize delegate = _delegate; + ++ (nullable NSArray *)commandAndArgumentsConformingToTypeOfPath:(NSString *)path { - static NSDictionary *typeSelectorDictionary; - if (!typeSelectorDictionary) - typeSelectorDictionary = @{ @".zip": @"extractZIP", - @".tar": @"extractTAR", - @".tar.gz": @"extractTGZ", - @".tgz": @"extractTGZ", - @".tar.bz2": @"extractTBZ", - @".tbz": @"extractTBZ", - @".tar.xz": @"extractTXZ", - @".txz": @"extractTXZ", - @".tar.lzma": @"extractTXZ"}; - + NSArray *extractTGZ = @[@"/usr/bin/tar", @"-zxC"]; + NSArray *extractTBZ = @[@"/usr/bin/tar", @"-jxC"]; + NSArray *extractTXZ = extractTGZ; + + NSDictionary *> *extractCommandDictionary = + @{ + @".zip" : @[@"/usr/bin/ditto", @"-x",@"-k",@"-"], + @".tar" : @[@"/usr/bin/tar", @"-xC"], + @".tar.gz" : extractTGZ, + @".tgz" : extractTGZ, + @".tar.bz2" : extractTBZ, + @".tbz" : extractTBZ, + @".tar.xz" : extractTXZ, + @".txz" : extractTXZ, + @".tar.lzma" : extractTXZ + }; + NSString *lastPathComponent = [path lastPathComponent]; - for (NSString *currentType in typeSelectorDictionary) - { - NSString *value = [typeSelectorDictionary objectForKey:currentType]; - assert(value); - - if ([currentType length] > [lastPathComponent length]) continue; + for (NSString *currentType in extractCommandDictionary) + { + NSArray *value = [extractCommandDictionary objectForKey:currentType]; + assert(value != nil); + + if ([currentType length] > [lastPathComponent length]) continue; if ([[lastPathComponent substringFromIndex:[lastPathComponent length] - [currentType length]] isEqualToString:currentType]) { - return NSSelectorFromString(value); + return value; } } - return NULL; + return nil; +} + ++ (BOOL)canUnarchivePath:(NSString *)path +{ + return ([self commandAndArgumentsConformingToTypeOfPath:path] != nil); } + (BOOL)unsafeIfArchiveIsNotValidated @@ -46,35 +64,50 @@ return NO; } -- (void)start +- (instancetype)initWithArchivePath:(NSString *)archivePath delegate:(nullable id )delegate { - [NSThread detachNewThreadSelector:[[self class] selectorConformingToTypeOfPath:self.archivePath] toTarget:self withObject:nil]; + self = [super init]; + if (self != nil) { + _archivePath = [archivePath copy]; + _delegate = delegate; + } + return self; } -+ (BOOL)canUnarchivePath:(NSString *)path +- (void)start { - return ([self selectorConformingToTypeOfPath:path] != nil); + NSArray *commandAndArguments = [[self class] commandAndArgumentsConformingToTypeOfPath:self.archivePath]; + assert(commandAndArguments != nil); + + NSString *command = commandAndArguments.firstObject; + assert(command != nil); + + NSArray *arguments = [commandAndArguments subarrayWithRange:NSMakeRange(1, commandAndArguments.count - 1)]; + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + [self extractArchivePipingDataToCommand:command arguments:arguments]; + }); } // This method abstracts the types that use a command line tool piping data from stdin. -- (void)extractArchivePipingDataToCommand:(NSString *)command args:(NSArray*)args +- (void)extractArchivePipingDataToCommand:(NSString *)command arguments:(NSArray*)args { // *** GETS CALLED ON NON-MAIN THREAD!!! - @autoreleasepool { - + @autoreleasepool { + NSString *destination = [self.archivePath stringByDeletingLastPathComponent]; SULog(@"Extracting using '%@' '%@' < '%@' '%@'", command, [args componentsJoinedByString:@"' '"], self.archivePath, destination); - + // Get the file size. NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:self.archivePath error:nil]; NSUInteger expectedLength = [[attributes objectForKey:NSFileSize] unsignedIntegerValue]; if (expectedLength > 0) { NSFileHandle *archiveInput = [NSFileHandle fileHandleForReadingAtPath:self.archivePath]; - + NSPipe *pipe = [NSPipe pipe]; NSFileHandle *archiveOutput = [pipe fileHandleForWriting]; - + NSTask *task = [[NSTask alloc] init]; [task setStandardInput:[pipe fileHandleForReading]]; [task setStandardError:[NSFileHandle fileHandleWithStandardError]]; @@ -82,7 +115,7 @@ [task setLaunchPath:command]; [task setArguments:[args arrayByAddingObject:destination]]; [task launch]; - + NSUInteger bytesRead = 0; do { NSData *data = [archiveInput readDataOfLength:256*1024]; @@ -93,19 +126,21 @@ bytesRead += len; [archiveOutput writeData:data]; dispatch_async(dispatch_get_main_queue(), ^{ - [self notifyDelegateOfProgress:(double)bytesRead / (double)expectedLength]; + if ([self.delegate respondsToSelector:@selector(unarchiverExtractedProgress:)]) { + [self.delegate unarchiverExtractedProgress:(double)bytesRead / (double)expectedLength]; + } }); } while(bytesRead < expectedLength); [archiveOutput closeFile]; - + [task waitUntilExit]; if ([task terminationStatus] == 0) { if (bytesRead == expectedLength) { dispatch_async(dispatch_get_main_queue(), ^{ - [self notifyDelegateOfSuccess]; + [self.delegate unarchiverDidFinish]; }); return; } else { @@ -117,51 +152,13 @@ } else { SULog(@"Extraction failed, archive '%@' is empty", self.archivePath); } - + dispatch_async(dispatch_get_main_queue(), ^{ - [self notifyDelegateOfFailure]; + [self.delegate unarchiverDidFail]; }); } } -- (void)extractTAR -{ - // *** GETS CALLED ON NON-MAIN THREAD!!! - - [self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-xC"]]; -} - -- (void)extractTGZ -{ - // *** GETS CALLED ON NON-MAIN THREAD!!! - - [self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-zxC"]]; -} - -- (void)extractTBZ -{ - // *** GETS CALLED ON NON-MAIN THREAD!!! - - [self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-jxC"]]; -} - -- (void)extractZIP -{ - // *** GETS CALLED ON NON-MAIN THREAD!!! - - [self extractArchivePipingDataToCommand:@"/usr/bin/ditto" args:@[@"-x",@"-k",@"-"]]; -} - -- (void)extractTXZ -{ - // *** GETS CALLED ON NON-MAIN THREAD!!! - - [self extractArchivePipingDataToCommand:@"/usr/bin/tar" args:@[@"-zxC"]]; -} - -+ (void)load -{ - [self registerImplementation:self]; -} +- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; } @end diff --git a/Sparkle/SUUIBasedUpdateDriver.h b/Sparkle/SUUIBasedUpdateDriver.h index 8148912b..1018ca99 100644 --- a/Sparkle/SUUIBasedUpdateDriver.h +++ b/Sparkle/SUUIBasedUpdateDriver.h @@ -12,6 +12,7 @@ #import #import "SUBasicUpdateDriver.h" #import "SUUpdateAlert.h" +#import "SUUnarchiverProtocol.h" @class SUStatusController; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 0a0ae572..58da9bab 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -225,7 +225,7 @@ [self.statusController setProgressValue:progress]; } -- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua +- (void)unarchiverDidFinish { if (self.automaticallyInstallUpdates) { [self installWithToolAndRelaunch:YES]; diff --git a/Sparkle/SUUnarchiver.h b/Sparkle/SUUnarchiver.h index e2f79f04..b732c313 100644 --- a/Sparkle/SUUnarchiver.h +++ b/Sparkle/SUUnarchiver.h @@ -6,34 +6,17 @@ // Copyright 2006 Andy Matuschak. All rights reserved. // -#ifndef SUUNARCHIVER_H -#define SUUNARCHIVER_H - #import -@class SUHost; +NS_ASSUME_NONNULL_BEGIN + +@protocol SUUnarchiverProtocol; @protocol SUUnarchiverDelegate; @interface SUUnarchiver : NSObject -@property (copy, readonly) NSString *archivePath; -@property (copy, readonly) NSString *updateHostBundlePath; -@property (copy, readonly) NSString *decryptionPassword; -@property (weak) id delegate; - -+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)host withPassword:(NSString *)decryptionPassword; - -+ (BOOL)unsafeIfArchiveIsNotValidated; - -- (void)start; ++ (nullable id )unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword delegate:(nullable id )delegate; @end -@protocol SUUnarchiverDelegate -- (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver; -- (void)unarchiverDidFail:(SUUnarchiver *)unarchiver; -@optional -- (void)unarchiver:(SUUnarchiver *)unarchiver extractedProgress:(double)progress; -@end - -#endif +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUUnarchiver.m b/Sparkle/SUUnarchiver.m index b12d0648..2d9b204c 100644 --- a/Sparkle/SUUnarchiver.m +++ b/Sparkle/SUUnarchiver.m @@ -6,94 +6,29 @@ // Copyright 2006 Andy Matuschak. All rights reserved. // - -#import "SUUpdater.h" - -#import "SUAppcast.h" -#import "SUAppcastItem.h" -#import "SUVersionComparisonProtocol.h" #import "SUUnarchiver.h" -#import "SUUnarchiver_Private.h" +#import "SUUnarchiverProtocol.h" +#import "SUPipedUnarchiver.h" +#import "SUDiskImageUnarchiver.h" +#import "SUBinaryDeltaUnarchiver.h" @implementation SUUnarchiver -@synthesize archivePath; -@synthesize updateHostBundlePath; -@synthesize delegate; -@synthesize decryptionPassword; - -+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)hostPath withPassword:(NSString *)decryptionPassword ++ (nullable id )unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)hostPath decryptionPassword:(nullable NSString *)decryptionPassword delegate:(nullable id )delegate { - for (id current in [self unarchiverImplementations]) { - if ([current canUnarchivePath:path]) { - return [[current alloc] initWithPath:path hostBundlePath:hostPath password:decryptionPassword]; - } + if ([SUPipedUnarchiver canUnarchivePath:path]) { + return [[SUPipedUnarchiver alloc] initWithArchivePath:path delegate:delegate]; + + } else if ([SUDiskImageUnarchiver canUnarchivePath:path]) { + return [[SUDiskImageUnarchiver alloc] initWithArchivePath:path decryptionPassword:decryptionPassword delegate:delegate]; + + } else if ([SUBinaryDeltaUnarchiver canUnarchivePath:path]) { + assert(hostPath != nil); + NSString *nonNullHostPath = hostPath; + return [[SUBinaryDeltaUnarchiver alloc] initWithArchivePath:path updateHostBundlePath:nonNullHostPath delegate:delegate]; + } return nil; } -- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; } - -- (void)start -{ - // No-op -} - -- (instancetype)initWithPath:(NSString *)path hostBundlePath:(NSString *)hostPath password:(NSString *)password -{ - if ((self = [super init])) - { - archivePath = [path copy]; - updateHostBundlePath = hostPath; - decryptionPassword = password; - } - return self; -} - -+ (BOOL)canUnarchivePath:(NSString *)__unused path -{ - return NO; -} - -+ (BOOL)unsafeIfArchiveIsNotValidated -{ - return NO; -} - -- (void)notifyDelegateOfProgress:(double)progress -{ - if ([self.delegate respondsToSelector:@selector(unarchiver:extractedProgress:)]) { - [self.delegate unarchiver:self extractedProgress:progress]; - } -} - -- (void)notifyDelegateOfSuccess -{ - if ([self.delegate respondsToSelector:@selector(unarchiverDidFinish:)]) { - [self.delegate unarchiverDidFinish:self]; - } -} - -- (void)notifyDelegateOfFailure -{ - if ([self.delegate respondsToSelector:@selector(unarchiverDidFail:)]) { - [self.delegate unarchiverDidFail:self]; - } -} - -static NSMutableArray *gUnarchiverImplementations; - -+ (void)registerImplementation:(Class)implementation -{ - if (!gUnarchiverImplementations) { - gUnarchiverImplementations = [[NSMutableArray alloc] init]; - } - [gUnarchiverImplementations addObject:implementation]; -} - -+ (NSArray *)unarchiverImplementations -{ - return [NSArray arrayWithArray:gUnarchiverImplementations]; -} - @end diff --git a/Sparkle/SUUnarchiverProtocol.h b/Sparkle/SUUnarchiverProtocol.h new file mode 100644 index 00000000..5a349877 --- /dev/null +++ b/Sparkle/SUUnarchiverProtocol.h @@ -0,0 +1,36 @@ +// +// SUUnarchiverProtocol.h +// Sparkle +// +// Created by Mayur Pawashe on 3/26/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol SUUnarchiverProtocol + ++ (BOOL)canUnarchivePath:(NSString *)path; + ++ (BOOL)unsafeIfArchiveIsNotValidated; + +- (void)start; + +- (NSString *)description; + +@end + +@protocol SUUnarchiverDelegate + +- (void)unarchiverDidFinish; + +- (void)unarchiverDidFail; + +@optional +- (void)unarchiverExtractedProgress:(double)progress; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUUnarchiver_Private.h b/Sparkle/SUUnarchiver_Private.h deleted file mode 100644 index c29d68cf..00000000 --- a/Sparkle/SUUnarchiver_Private.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// SUUnarchiver_Private.h -// Sparkle -// -// Created by Andy Matuschak on 6/17/08. -// Copyright 2008 Andy Matuschak. All rights reserved. -// - -#ifndef SUUNARCHIVER_PRIVATE_H -#define SUUNARCHIVER_PRIVATE_H - -#import -#import "SUUnarchiver.h" - -@interface SUUnarchiver (Private) -+ (void)registerImplementation:(Class)implementation; -+ (NSArray *)unarchiverImplementations; -+ (BOOL)canUnarchivePath:(NSString *)path; -- (instancetype)initWithPath:(NSString *)archive hostBundlePath:(NSString *)host; - -- (void)notifyDelegateOfProgress:(double)progress; -- (void)notifyDelegateOfSuccess; -- (void)notifyDelegateOfFailure; -@end - -#endif diff --git a/Tests/SUUnarchiverTest.swift b/Tests/SUUnarchiverTest.swift index 4e70bba8..9524f010 100644 --- a/Tests/SUUnarchiverTest.swift +++ b/Tests/SUUnarchiverTest.swift @@ -18,13 +18,13 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate { } - func unarchiverDidFail(_ unarchiver: SUUnarchiver!) + func unarchiverDidFail() { self.unarchivedResult = false self.unarchivedExpectation!.fulfill() } - func unarchiverDidFinish(_ unarchiver: SUUnarchiver!) + func unarchiverDidFinish() { self.unarchivedResult = true self.unarchivedExpectation!.fulfill() @@ -49,10 +49,8 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate self.unarchivedExpectation = super.expectation(description: "Unarchived Application (format: \(archiveExtension))") - let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password) - - unarchiver?.delegate = self - unarchiver?.start() + let unarchiver = SUUnarchiver.unarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, decryptionPassword: self.password, delegate: self) + unarchiver!.start() super.waitForExpectations(timeout: 7.0, handler: nil) From 7bc7a90a09ed07e7050d9d08494db626a6dae3a8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Wed, 21 Dec 2016 15:59:13 -0500 Subject: [PATCH 2/4] Fix UI update scheduler not prompting for install & relaunch --- Sparkle/SUBasicUpdateDriver.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index e4b0e39c..8b22cf33 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -342,8 +342,8 @@ return; } - assert(self.updateItem); - [self installWithToolAndRelaunch:YES]; + // This will call any of the subclass' implementation of -unarchiverDidFinish first + [self unarchiverDidFinish]; } progressBlock:nil]; } } From dd1bda50665f338c6e55b728cf2cdf3a8543fef9 Mon Sep 17 00:00:00 2001 From: Zorg Date: Wed, 21 Dec 2016 16:14:25 -0500 Subject: [PATCH 3/4] Some error reason is better than no reason --- Sparkle/SUBasicUpdateDriver.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 8b22cf33..3b568e73 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -333,8 +333,8 @@ } if (!success) { -#warning this is bad - [self unarchiverDidFail:nil]; + NSError *reason = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey: @"Failed to extract update."}]; + [self unarchiverDidFail:reason]; } else { [unarchiver unarchiveWithCompletionBlock:^(NSError *err){ if (err) { From 137b73af4e17dbedc4d19f479bfaa76cac36cbaf Mon Sep 17 00:00:00 2001 From: Zorg Date: Wed, 21 Dec 2016 16:39:33 -0500 Subject: [PATCH 4/4] Fix subclass compatibility and update schedule unarchiving behavior --- Sparkle/SUAutomaticUpdateDriver.m | 2 +- Sparkle/SUBasicUpdateDriver.h | 4 ++++ Sparkle/SUBasicUpdateDriver.m | 27 +++++++++++++++++---------- Sparkle/SUUIBasedUpdateDriver.m | 4 ++-- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index f6d23b04..6abb1294 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -62,7 +62,7 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } -- (void)unarchiverDidFinish +- (void)unarchiverDidFinish:(id)__unused ua { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(systemWillPowerOff:) name:NSWorkspaceWillPowerOffNotification object:nil]; diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index 0e61f5f3..97dc34e8 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -40,6 +40,10 @@ - (void)extractUpdate; - (void)failedToApplyDeltaUpdate; +// Needed to preserve compatibility to subclasses, even though our unarchiver code uses blocks now +- (void)unarchiver:(id)ua extractedProgress:(double)progress; +- (void)unarchiverDidFinish:(id)ua; + - (void)installWithToolAndRelaunch:(BOOL)relaunch; - (void)installWithToolAndRelaunch:(BOOL)relaunch displayingUserInterface:(BOOL)showUI; - (void)installerForHost:(SUHost *)host failedWithError:(NSError *)error; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 3b568e73..4e6d5d1f 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -334,17 +334,18 @@ if (!success) { NSError *reason = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:@{NSLocalizedDescriptionKey: @"Failed to extract update."}]; - [self unarchiverDidFail:reason]; + [self unarchiverDidFailWithError:reason]; } else { [unarchiver unarchiveWithCompletionBlock:^(NSError *err){ if (err) { - [self unarchiverDidFail:err]; + [self unarchiverDidFailWithError:err]; return; } - - // This will call any of the subclass' implementation of -unarchiverDidFinish first - [self unarchiverDidFinish]; - } progressBlock:nil]; + + [self unarchiverDidFinish:nil]; + } progressBlock:^(double progress) { + [self unarchiver:nil extractedProgress:progress]; + }]; } } @@ -357,14 +358,20 @@ [self downloadUpdate]; } -- (void)unarchiverDidFinish +// By default does nothing, can be overridden +- (void)unarchiver:(id)__unused ua extractedProgress:(double)__unused progress +{ +} + +// Note this method can be overridden (and is) +- (void)unarchiverDidFinish:(id)__unused ua { assert(self.updateItem); - + [self installWithToolAndRelaunch:YES]; } -- (void)unarchiverDidFail:(NSError *)err +- (void)unarchiverDidFailWithError:(NSError *)err { // No longer needed self.updateValidator = nil; @@ -373,7 +380,7 @@ [self failedToApplyDeltaUpdate]; return; } - + [self abortUpdateWithError:err]; } diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 58da9bab..caa3959a 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -216,7 +216,7 @@ [super extractUpdate]; } -- (void)unarchiver:(SUUnarchiver *)__unused ua extractedProgress:(double)progress +- (void)unarchiver:(id)__unused ua extractedProgress:(double)progress { // We do this here instead of in extractUpdate so that we only have a determinate progress bar for archives with progress. if ([self.statusController maxProgressValue] == 0.0) { @@ -225,7 +225,7 @@ [self.statusController setProgressValue:progress]; } -- (void)unarchiverDidFinish +- (void)unarchiverDidFinish:(id)__unused ua { if (self.automaticallyInstallUpdates) { [self installWithToolAndRelaunch:YES];