From d7dbbe4bb94a2cf76db165039d91ed3ee2e1e2f0 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sun, 2 Feb 2014 14:15:28 -0700 Subject: [PATCH] Implementing formal protocols for most Sparkle delegates. --- SUAutomaticUpdateAlert.h | 8 +++++--- SUAutomaticUpdateAlert.m | 2 +- SUBinaryDeltaUnarchiver.h | 3 +-- SUDSAVerifier.h | 2 +- SUDiskImageUnarchiver.h | 3 +-- SUHost.h | 2 +- SUHost.m | 13 ++++++------- SUInstaller.h | 2 +- SUPackageInstaller.h | 2 +- SUPipedUnarchiver.h | 4 +--- SUPlainInstaller.h | 2 +- SUUnarchiver.h | 8 ++++---- SUUnarchiver.m | 6 +----- SUUpdateAlert.h | 7 ++++--- SUUpdateAlert.m | 8 ++------ SUUpdateDriver.h | 3 +-- SUUpdateDriver.m | 16 ++++------------ SUUpdater.m | 2 +- 18 files changed, 37 insertions(+), 56 deletions(-) diff --git a/SUAutomaticUpdateAlert.h b/SUAutomaticUpdateAlert.h index dc2183e5..aacb4cf2 100644 --- a/SUAutomaticUpdateAlert.h +++ b/SUAutomaticUpdateAlert.h @@ -11,6 +11,8 @@ #import "SUWindowController.h" +@protocol SUAutomaticUpdateAlertDelegateProtocol; + typedef enum { SUInstallNowChoice, @@ -21,18 +23,18 @@ typedef enum @class SUAppcastItem, SUHost; @interface SUAutomaticUpdateAlert : SUWindowController { SUAppcastItem *updateItem; - id delegate; + id delegate; SUHost *host; } -- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:delegate; +- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)hostBundle delegate:(id)delegate; - (IBAction)installNow:sender; - (IBAction)installLater:sender; - (IBAction)doNotInstall:sender; @end -@interface NSObject (SUAutomaticUpdateAlertDelegateProtocol) +@protocol SUAutomaticUpdateAlertDelegateProtocol - (void)automaticUpdateAlert:(SUAutomaticUpdateAlert *)aua finishedWithChoice:(SUAutomaticInstallationChoice)choice; @end diff --git a/SUAutomaticUpdateAlert.m b/SUAutomaticUpdateAlert.m index bf5bc767..2a7c2afa 100644 --- a/SUAutomaticUpdateAlert.m +++ b/SUAutomaticUpdateAlert.m @@ -12,7 +12,7 @@ @implementation SUAutomaticUpdateAlert -- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:del; +- (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost delegate:(id)del { self = [super initWithHost:aHost windowNibName:@"SUAutomaticUpdateAlert"]; if (self) diff --git a/SUBinaryDeltaUnarchiver.h b/SUBinaryDeltaUnarchiver.h index 2f2e7651..1e71cbe4 100644 --- a/SUBinaryDeltaUnarchiver.h +++ b/SUBinaryDeltaUnarchiver.h @@ -12,8 +12,7 @@ #import #import "SUUnarchiver.h" -@interface SUBinaryDeltaUnarchiver : SUUnarchiver { -} +@interface SUBinaryDeltaUnarchiver : SUUnarchiver @end diff --git a/SUDSAVerifier.h b/SUDSAVerifier.h index 814e4c59..fb03de27 100644 --- a/SUDSAVerifier.h +++ b/SUDSAVerifier.h @@ -11,7 +11,7 @@ #import -@interface SUDSAVerifier : NSObject {} +@interface SUDSAVerifier : NSObject + (BOOL)validatePath:(NSString *)path withEncodedDSASignature:(NSString *)encodedSignature withPublicDSAKey:(NSString *)pkeyString; @end diff --git a/SUDiskImageUnarchiver.h b/SUDiskImageUnarchiver.h index 44c71504..7a8e9167 100644 --- a/SUDiskImageUnarchiver.h +++ b/SUDiskImageUnarchiver.h @@ -12,8 +12,7 @@ #import #import "SUUnarchiver.h" -@interface SUDiskImageUnarchiver : SUUnarchiver { -} +@interface SUDiskImageUnarchiver : SUUnarchiver @end diff --git a/SUHost.h b/SUHost.h index 58244ecf..bb1d5d43 100644 --- a/SUHost.h +++ b/SUHost.h @@ -17,11 +17,11 @@ NSString *defaultsDomain; BOOL usesStandardUserDefaults; } +@property (retain, readonly) NSBundle *bundle; + (NSString *)systemVersionString; - (id)initWithBundle:(NSBundle *)aBundle; -- (NSBundle *)bundle; - (NSString *)bundlePath; - (NSString *)appSupportPath; - (NSString *)installationPath; diff --git a/SUHost.m b/SUHost.m index c3412081..fae26cc4 100644 --- a/SUHost.m +++ b/SUHost.m @@ -12,15 +12,19 @@ #import // For statfs for isRunningOnReadOnlyVolume #import "SULog.h" +@interface SUHost () +@property (retain, readwrite) NSBundle *bundle; +@end @implementation SUHost +@synthesize bundle; - (id)initWithBundle:(NSBundle *)aBundle { if ((self = [super init])) { if (aBundle == nil) aBundle = [NSBundle mainBundle]; - bundle = [aBundle retain]; + self.bundle = aBundle; if (![bundle bundleIdentifier]) SULog(@"Sparkle Error: the bundle being updated at %@ has no CFBundleIdentifier! This will cause preference read/write to not work properly.", bundle); @@ -37,17 +41,12 @@ - (void)dealloc { [defaultsDomain release]; - [bundle release]; + self.bundle = nil; [super dealloc]; } - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@, %@>", [self class], [self bundlePath], [self installationPath]]; } -- (NSBundle *)bundle -{ - return bundle; -} - - (NSString *)bundlePath { return [bundle bundlePath]; diff --git a/SUInstaller.h b/SUInstaller.h index c62a6aa2..ff368b9d 100644 --- a/SUInstaller.h +++ b/SUInstaller.h @@ -13,7 +13,7 @@ #import "SUVersionComparisonProtocol.h" @class SUHost; -@interface SUInstaller : NSObject { } +@interface SUInstaller : NSObject + (NSString *) appPathInUpdateFolder:(NSString *)updateFolder forHost:(SUHost *)host; + (void) installFromUpdateFolder:(NSString *)updateFolder overHost:(SUHost *)host installationPath:(NSString *)installationPath delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; + (void) finishInstallationToPath:(NSString *)installationPath withResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate; diff --git a/SUPackageInstaller.h b/SUPackageInstaller.h index 5b69095f..04b500ee 100644 --- a/SUPackageInstaller.h +++ b/SUPackageInstaller.h @@ -16,7 +16,7 @@ #import "SUVersionComparisonProtocol.h" #import "SUPlainInstaller.h" -@interface SUPackageInstaller : SUPlainInstaller { } +@interface SUPackageInstaller : SUPlainInstaller @end #endif diff --git a/SUPipedUnarchiver.h b/SUPipedUnarchiver.h index b13a0b3a..7304ba0a 100644 --- a/SUPipedUnarchiver.h +++ b/SUPipedUnarchiver.h @@ -12,9 +12,7 @@ #import #import "SUUnarchiver.h" -@interface SUPipedUnarchiver : SUUnarchiver { - -} +@interface SUPipedUnarchiver : SUUnarchiver @end diff --git a/SUPlainInstaller.h b/SUPlainInstaller.h index e75f0401..939d260d 100644 --- a/SUPlainInstaller.h +++ b/SUPlainInstaller.h @@ -19,7 +19,7 @@ @class SUHost; -@interface SUPlainInstaller : SUInstaller { } +@interface SUPlainInstaller : SUInstaller + (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id )comparator; @end diff --git a/SUUnarchiver.h b/SUUnarchiver.h index c726d174..370e2e09 100644 --- a/SUUnarchiver.h +++ b/SUUnarchiver.h @@ -10,21 +10,21 @@ #define SUUNARCHIVER_H @class SUHost; +@protocol SUUnarchiverDelegate; @interface SUUnarchiver : NSObject { - id delegate; + id delegate; NSString *archivePath; SUHost *updateHost; } +@property (assign)id delegate; + (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host; -- (void)setDelegate:delegate; - (void)start; - @end -@interface NSObject (SUUnarchiverDelegate) +@protocol SUUnarchiverDelegate - (void)unarchiver:(SUUnarchiver *)unarchiver extractedLength:(unsigned long)length; - (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver; - (void)unarchiverDidFail:(SUUnarchiver *)unarchiver; diff --git a/SUUnarchiver.m b/SUUnarchiver.m index ca437b4a..3073b63b 100644 --- a/SUUnarchiver.m +++ b/SUUnarchiver.m @@ -16,6 +16,7 @@ #import "SUUnarchiver_Private.h" @implementation SUUnarchiver +@synthesize delegate; + (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host { @@ -31,11 +32,6 @@ - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], archivePath]; } -- (void)setDelegate:del -{ - delegate = del; -} - - (void)start { // No-op diff --git a/SUUpdateAlert.h b/SUUpdateAlert.h index 5bf9032d..c10a8aac 100644 --- a/SUUpdateAlert.h +++ b/SUUpdateAlert.h @@ -12,6 +12,7 @@ #import "SUWindowController.h" #import "SUVersionDisplayProtocol.h" +@protocol SUUpdateAlertDelegate; typedef enum { @@ -25,7 +26,7 @@ typedef enum @interface SUUpdateAlert : SUWindowController { SUAppcastItem *updateItem; SUHost *host; - id delegate; + id delegate; id versionDisplayer; IBOutlet WebView *releaseNotesView; @@ -36,9 +37,9 @@ typedef enum NSProgressIndicator *releaseNotesSpinner; BOOL webViewFinishedLoading; } +@property (assign) id delegate; - (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host; -- (void)setDelegate:delegate; - (IBAction)installUpdate:sender; - (IBAction)skipThisVersion:sender; @@ -48,7 +49,7 @@ typedef enum @end -@interface NSObject (SUUpdateAlertDelegate) +@protocol SUUpdateAlertDelegate - (void)updateAlert:(SUUpdateAlert *)updateAlert finishedWithChoice:(SUUpdateAlertChoice)updateChoice; - (void)updateAlert:(SUUpdateAlert *)updateAlert shouldAllowAutoUpdate: (BOOL*)shouldAllowAutoUpdate; @end diff --git a/SUUpdateAlert.m b/SUUpdateAlert.m index 2ef5158b..a2bd6b11 100644 --- a/SUUpdateAlert.m +++ b/SUUpdateAlert.m @@ -18,7 +18,7 @@ #import "SUConstants.h" -@interface WebView (SUTenFiveProperty) +@interface WebView () -(void) setDrawsBackground: (BOOL)state; @@ -26,6 +26,7 @@ @implementation SUUpdateAlert +@synthesize delegate; - (id)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost { @@ -348,9 +349,4 @@ return webViewMenuItems; } -- (void)setDelegate:del -{ - delegate = del; -} - @end diff --git a/SUUpdateDriver.h b/SUUpdateDriver.h index 85d68bb5..4daecba9 100644 --- a/SUUpdateDriver.h +++ b/SUUpdateDriver.h @@ -23,14 +23,13 @@ extern NSString * const SUUpdateDriverFinishedNotification; BOOL finished; BOOL isInterruptible; } +@property (retain) SUHost *host; - initWithUpdater:(SUUpdater *)updater; - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; - (void)abortUpdate; - (BOOL)isInterruptible; - (BOOL)finished; -- (SUHost*)host; -- (void)setHost:(SUHost*)newHost; @end diff --git a/SUUpdateDriver.m b/SUUpdateDriver.m index 51b365da..0bc16963 100644 --- a/SUUpdateDriver.m +++ b/SUUpdateDriver.m @@ -12,6 +12,9 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; @implementation SUUpdateDriver + +@synthesize host; + - initWithUpdater:(SUUpdater *)anUpdater { if ((self = [super init])) @@ -39,20 +42,9 @@ NSString * const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished"; - (void)dealloc { - [host release]; + self.host = nil; [appcastURL release]; [super dealloc]; } -- (SUHost*)host -{ - return host; -} - -- (void)setHost:(SUHost*)newHost -{ - [host release]; - host = [newHost retain]; -} - @end diff --git a/SUUpdater.m b/SUUpdater.m index 19162776..379bf54c 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -28,7 +28,7 @@ NSString *const SUUpdaterWillRelaunchApplicationNotification = @"SUUpdaterWillRe NSString *const SUUpdaterAppcastItemNotificationKey = @"SUUpdaterAppcastItemNotificationKey"; NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotificationKey"; -@interface SUUpdater (Private) +@interface SUUpdater () - (id)initForBundle:(NSBundle *)bundle; - (void)startUpdateCycle; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver;