mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Make SUAppcastDelegate a formal protocol.
Synthesize more Objective C getters and setters using Objective C properties.
This commit is contained in:
1 parent
7e2d4b019e
commit
92bafa92bf
7 files changed
+35
-59
No files matched your search
+6
-5
@@ -9,26 +9,27 @@
|
||||
#ifndef SUAPPCAST_H
|
||||
#define SUAPPCAST_H
|
||||
|
||||
@protocol SUAppcastDelegate;
|
||||
|
||||
@class SUAppcastItem;
|
||||
@interface SUAppcast : NSObject<NSURLDownloadDelegate>
|
||||
{
|
||||
@private
|
||||
NSArray *items;
|
||||
NSString *userAgentString;
|
||||
id delegate;
|
||||
id<SUAppcastDelegate> delegate;
|
||||
NSString *downloadFilename;
|
||||
NSURLDownload *download;
|
||||
}
|
||||
@property (assign) id<SUAppcastDelegate> delegate;
|
||||
@property (copy) NSString *userAgentString;
|
||||
|
||||
- (void)fetchAppcastFromURL:(NSURL *)url;
|
||||
- (void)setDelegate:delegate;
|
||||
- (void)setUserAgentString:(NSString *)userAgentString;
|
||||
|
||||
- (NSArray *)items;
|
||||
|
||||
@end
|
||||
|
||||
@interface NSObject (SUAppcastDelegate)
|
||||
@protocol SUAppcastDelegate <NSObject>
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
|
||||
- (void)appcast:(SUAppcast *)appcast failedToLoadWithError:(NSError *)error;
|
||||
@end
|
||||
|
||||
+16
-33
@@ -33,38 +33,37 @@
|
||||
@end
|
||||
|
||||
@interface SUAppcast () <NSURLDownloadDelegate>
|
||||
@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
|
||||
@@ -12,9 +12,10 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "SUUpdateDriver.h"
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUAppcast.h"
|
||||
|
||||
@class SUAppcastItem, SUAppcast, SUUnarchiver, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver<NSURLDownloadDelegate, SUUnarchiverDelegate> {
|
||||
@class SUAppcastItem, SUHost;
|
||||
@interface SUBasicUpdateDriver : SUUpdateDriver<NSURLDownloadDelegate, SUUnarchiverDelegate, SUAppcastDelegate> {
|
||||
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;
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class SUHost;
|
||||
@interface SUSystemProfiler : NSObject {}
|
||||
@interface SUSystemProfiler : NSObject
|
||||
+ (SUSystemProfiler *)sharedSystemProfiler;
|
||||
- (NSMutableArray *)systemProfileArrayForHost:(SUHost *)host;
|
||||
@end
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
NSString *archivePath;
|
||||
SUHost *updateHost;
|
||||
}
|
||||
@property (assign)id<SUUnarchiverDelegate> delegate;
|
||||
@property (assign) id<SUUnarchiverDelegate> delegate;
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHost:(SUHost *)host;
|
||||
|
||||
|
||||
+1
-3
@@ -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;
|
||||
|
||||
|
||||
+7
-11
@@ -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
|
||||
Reference in new issue
Block a user