From 92bafa92bf190c4976d3457b577eb6defe4908e3 Mon Sep 17 00:00:00 2001 From: "C.W. Betts" Date: Sun, 9 Feb 2014 14:25:02 -0700 Subject: [PATCH] Make SUAppcastDelegate a formal protocol. Synthesize more Objective C getters and setters using Objective C properties. --- SUAppcast.h | 11 +++++----- SUAppcast.m | 49 ++++++++++++++----------------------------- SUBasicUpdateDriver.h | 8 +++---- SUSystemProfiler.h | 2 +- SUUnarchiver.h | 2 +- SUUpdater.h | 4 +--- SUUpdater.m | 18 +++++++--------- 7 files changed, 35 insertions(+), 59 deletions(-) diff --git a/SUAppcast.h b/SUAppcast.h index 0fbc6e8a..71a04efe 100644 --- a/SUAppcast.h +++ b/SUAppcast.h @@ -9,26 +9,27 @@ #ifndef SUAPPCAST_H #define SUAPPCAST_H +@protocol SUAppcastDelegate; + @class SUAppcastItem; @interface SUAppcast : NSObject { @private NSArray *items; NSString *userAgentString; - id delegate; + id delegate; NSString *downloadFilename; NSURLDownload *download; } +@property (assign) id delegate; +@property (copy) NSString *userAgentString; - (void)fetchAppcastFromURL:(NSURL *)url; -- (void)setDelegate:delegate; -- (void)setUserAgentString:(NSString *)userAgentString; - (NSArray *)items; - @end -@interface NSObject (SUAppcastDelegate) +@protocol SUAppcastDelegate - (void)appcastDidFinishLoading:(SUAppcast *)appcast; - (void)appcast:(SUAppcast *)appcast failedToLoadWithError:(NSError *)error; @end diff --git a/SUAppcast.m b/SUAppcast.m index fb3c9ed8..61b2115f 100644 --- a/SUAppcast.m +++ b/SUAppcast.m @@ -33,38 +33,37 @@ @end @interface SUAppcast () +@property (copy) NSString *downloadFilename; +@property (retain) NSURLDownload *download; +@property (copy) NSArray *items; - (void)reportError:(NSError *)error; - (NSXMLNode *)bestNodeInNodes:(NSArray *)nodes; @end @implementation SUAppcast +@synthesize downloadFilename; +@synthesize delegate; +@synthesize userAgentString; +@synthesize download; +@synthesize items; - (void)dealloc { - [items release]; - items = nil; - [userAgentString release]; - userAgentString = nil; - [downloadFilename release]; - downloadFilename = nil; - [download release]; - download = nil; + self.items = nil; + self.userAgentString = nil; + self.downloadFilename = nil; + self.download = nil; [super dealloc]; } -- (NSArray *)items -{ - return items; -} - - (void)fetchAppcastFromURL:(NSURL *)url { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0]; if (userAgentString) [request setValue:userAgentString forHTTPHeaderField:@"User-Agent"]; - download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; + self.download = [[[NSURLDownload alloc] initWithRequest:request delegate:self] autorelease]; } - (void)download:(NSURLDownload *)aDownload decideDestinationWithSuggestedFilename:(NSString *)filename @@ -79,8 +78,7 @@ - (void)download:(NSURLDownload *)aDownload didCreateDestination:(NSString *)path { - [downloadFilename release]; - downloadFilename = [path copy]; + self.downloadFilename = path; } - (void)downloadDidFinish:(NSURLDownload *)aDownload @@ -105,8 +103,7 @@ document = [[[NSXMLDocument alloc] initWithContentsOfURL:[NSURL fileURLWithPath:downloadFilename] options:options error:&error] autorelease]; [[NSFileManager defaultManager] removeItemAtPath:downloadFilename error:nil]; - [downloadFilename release]; - downloadFilename = nil; + self.downloadFilename = nil; } else { @@ -216,7 +213,7 @@ { NSSortDescriptor *sort = [[[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO] autorelease]; [appcastItems sortUsingDescriptors:[NSArray arrayWithObject:sort]]; - items = [appcastItems copy]; + self.items = appcastItems; } if (failed) @@ -279,18 +276,4 @@ return [nodes objectAtIndex:i]; } -- (void)setUserAgentString:(NSString *)uas -{ - if (uas != userAgentString) - { - [userAgentString release]; - userAgentString = [uas copy]; - } -} - -- (void)setDelegate:del -{ - delegate = del; -} - @end diff --git a/SUBasicUpdateDriver.h b/SUBasicUpdateDriver.h index 39a648a5..63b9d012 100644 --- a/SUBasicUpdateDriver.h +++ b/SUBasicUpdateDriver.h @@ -12,9 +12,10 @@ #import #import "SUUpdateDriver.h" #import "SUUnarchiver.h" +#import "SUAppcast.h" -@class SUAppcastItem, SUAppcast, SUUnarchiver, SUHost; -@interface SUBasicUpdateDriver : SUUpdateDriver { +@class SUAppcastItem, SUHost; +@interface SUBasicUpdateDriver : SUUpdateDriver { SUAppcastItem *updateItem; SUAppcastItem *nonDeltaUpdateItem; @@ -27,9 +28,6 @@ - (void)checkForUpdatesAtURL:(NSURL *)URL host:(SUHost *)host; -- (void)appcastDidFinishLoading:(SUAppcast *)ac; -- (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error; - - (BOOL)isItemNewer:(SUAppcastItem *)ui; - (BOOL)hostSupportsItem:(SUAppcastItem *)ui; - (BOOL)itemContainsSkippedVersion:(SUAppcastItem *)ui; diff --git a/SUSystemProfiler.h b/SUSystemProfiler.h index 0835087d..124f6691 100644 --- a/SUSystemProfiler.h +++ b/SUSystemProfiler.h @@ -12,7 +12,7 @@ #import @class SUHost; -@interface SUSystemProfiler : NSObject {} +@interface SUSystemProfiler : NSObject + (SUSystemProfiler *)sharedSystemProfiler; - (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host; @end diff --git a/SUUnarchiver.h b/SUUnarchiver.h index d9bc666b..f0d47317 100644 --- a/SUUnarchiver.h +++ b/SUUnarchiver.h @@ -17,7 +17,7 @@ NSString *archivePath; SUHost *updateHost; } -@property (assign)id delegate; +@property (assign) id delegate; + (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host; diff --git a/SUUpdater.h b/SUUpdater.h index 929d863a..4c54a918 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -24,6 +24,7 @@ SUHost *host; IBOutlet id delegate; } +@property (assign) id delegate; + (SUUpdater *)sharedUpdater; + (SUUpdater *)updaterForBundle:(NSBundle *)bundle; @@ -31,9 +32,6 @@ - (NSBundle *)hostBundle; -- (void)setDelegate:(id)delegate; -- (id)delegate; - - (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyChecks; - (BOOL)automaticallyChecksForUpdates; diff --git a/SUUpdater.m b/SUUpdater.m index 379bf54c..29aaacf3 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -29,6 +29,7 @@ NSString *const SUUpdaterAppcastItemNotificationKey = @"SUUpdaterAppcastItemNoti NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotificationKey"; @interface SUUpdater () +@property NSTimer *checkTimer; - (id)initForBundle:(NSBundle *)bundle; - (void)startUpdateCycle; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; @@ -45,6 +46,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @end @implementation SUUpdater +@synthesize delegate; +@synthesize checkTimer; #pragma mark Initialization @@ -208,8 +211,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault if (checkTimer) { [checkTimer invalidate]; - [checkTimer release]; // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. - checkTimer = nil; + self.checkTimer = nil; // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. } if (![self automaticallyChecksForUpdates]) return; @@ -226,7 +228,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault delayUntilCheck = (updateCheckInterval - intervalSinceCheck); // It hasn't been long enough. else delayUntilCheck = 0; // We're overdue! Run one now. - checkTimer = [[NSTimer scheduledTimerWithTimeInterval:delayUntilCheck target:self selector:@selector(checkForUpdatesInBackground) userInfo:nil repeats:NO] retain]; // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. + self.checkTimer = [NSTimer scheduledTimerWithTimeInterval:delayUntilCheck target:self selector:@selector(checkForUpdatesInBackground) userInfo:nil repeats:NO]; // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. } @@ -316,7 +318,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)d { if ([self updateInProgress]) { return; } - if (checkTimer) { [checkTimer invalidate]; [checkTimer release]; checkTimer = nil; } // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. + if (checkTimer) { [checkTimer invalidate]; self.checkTimer = nil; } // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. SUClearLog(); SULog( @"===== %@ =====", [[NSFileManager defaultManager] displayNameAtPath: [[NSBundle mainBundle] bundlePath]] ); @@ -540,7 +542,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault { [self unregisterAsObserver]; [host release]; - if (checkTimer) { [checkTimer invalidate]; [checkTimer release]; checkTimer = nil; } // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. + if (checkTimer) { [checkTimer invalidate]; [checkTimer release]; self.checkTimer = nil; } // UK 2009-03-16 Timer is non-repeating, may have invalidated itself, so we had to retain it. [super dealloc]; } @@ -551,17 +553,11 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault return YES; } -- (void)setDelegate:aDelegate -{ - delegate = aDelegate; -} - - (BOOL)updateInProgress { return driver && ([driver finished] == NO); } -- (id)delegate { return delegate; } - (NSBundle *)hostBundle { return [host bundle]; } @end