From a453afa29a88e12e5527e143e2b97f5aa6a47622 Mon Sep 17 00:00:00 2001 From: Uli Kusterer Date: Tue, 8 Dec 2009 19:02:10 +0100 Subject: [PATCH] Delegate can now control how version numbers are formatted/displayed to the user, so we can e.g. exclude build numbers or whatever makes sense for a particular application. --- SUUIBasedUpdateDriver.m | 5 +++++ SUUpdateAlert.h | 5 +++++ SUUpdateAlert.m | 9 ++++++++- SUUpdater.h | 33 ++++++++++++++++++++++++++++++++- SUVersionDisplayProtocol.h | 27 +++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 SUVersionDisplayProtocol.h diff --git a/SUUIBasedUpdateDriver.m b/SUUIBasedUpdateDriver.m index b658808f5..b5552546b 100644 --- a/SUUIBasedUpdateDriver.m +++ b/SUUIBasedUpdateDriver.m @@ -20,6 +20,11 @@ - (void)didFindValidUpdate updateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:updateItem host:host]; [updateAlert setDelegate:self]; + id versDisp = nil; + if ([[updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) + versDisp = [[updater delegate] versionDisplayerForUpdater: updater]; + [updateAlert setVersionDisplayer: versDisp]; + if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)]) [[updater delegate] updater:updater didFindValidUpdate:updateItem]; diff --git a/SUUpdateAlert.h b/SUUpdateAlert.h index 5530c75ae..2cf73218e 100644 --- a/SUUpdateAlert.h +++ b/SUUpdateAlert.h @@ -10,6 +10,8 @@ #define SUUPDATEALERT_H #import "SUWindowController.h" +#import "SUVersionDisplayProtocol.h" + typedef enum { @@ -24,6 +26,7 @@ typedef enum SUAppcastItem *updateItem; SUHost *host; id delegate; + id versionDisplayer; IBOutlet WebView *releaseNotesView; IBOutlet NSTextField *description; @@ -39,6 +42,8 @@ typedef enum - (IBAction)skipThisVersion:sender; - (IBAction)remindMeLater:sender; +- (void)setVersionDisplayer: (id)disp; + @end @interface NSObject (SUUpdateAlertDelegate) diff --git a/SUUpdateAlert.m b/SUUpdateAlert.m index 38b8d6e94..fe8cc1714 100644 --- a/SUUpdateAlert.m +++ b/SUUpdateAlert.m @@ -48,6 +48,11 @@ - (void)dealloc [super dealloc]; } +- (void)setVersionDisplayer: (id)disp +{ + versionDisplayer = disp; +} + - (void)endWithSelection:(SUUpdateAlertChoice)choice { [releaseNotesView stopLoading:self]; @@ -233,11 +238,13 @@ - (NSString *)descriptionText NSString *updateItemVersion = [updateItem displayVersionString]; NSString *hostVersion = [host displayVersion]; // Display more info if the version strings are the same; useful for betas. - if ([updateItemVersion isEqualToString:hostVersion]) + if( !versionDisplayer && [updateItemVersion isEqualToString:hostVersion] ) { updateItemVersion = [updateItemVersion stringByAppendingFormat:@" (%@)", [updateItem versionString]]; hostVersion = [hostVersion stringByAppendingFormat:@" (%@)", [host version]]; } + else + [versionDisplayer formatVersion: &updateItemVersion andVersion: &hostVersion]; return [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to download it now?", nil), [host name], updateItemVersion, hostVersion]; } diff --git a/SUUpdater.h b/SUUpdater.h index 140e4fad9..43691847d 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -9,10 +9,27 @@ #ifndef SUUPDATER_H #define SUUPDATER_H +// ----------------------------------------------------------------------------- +// Headers: +// ----------------------------------------------------------------------------- + #import "SUVersionComparisonProtocol.h" +#import "SUVersionDisplayProtocol.h" + + +// ----------------------------------------------------------------------------- +// Forwards: +// ----------------------------------------------------------------------------- @class SUUpdateDriver, SUAppcastItem, SUHost, SUAppcast; -@interface SUUpdater : NSObject { + + +// ----------------------------------------------------------------------------- +// SUUpdater: +// ----------------------------------------------------------------------------- + +@interface SUUpdater : NSObject +{ NSTimer *checkTimer; SUUpdateDriver *driver; @@ -73,6 +90,11 @@ @end + +// ----------------------------------------------------------------------------- +// SUUpdater Delegate: +// ----------------------------------------------------------------------------- + @interface NSObject (SUUpdaterDelegateInformalProtocol) // Use this to keep Sparkle from popping up e.g. while your setup assistant is showing: @@ -119,11 +141,20 @@ // If you don't implement this method or return nil, the standard version comparator will be used. - (id )versionComparatorForUpdater:(SUUpdater *)updater; +// This method allows you to provide a custom version comparator. +// If you don't implement this method or return nil, the standard version comparator will be used. +- (id )versionDisplayerForUpdater:(SUUpdater *)updater; + // Returns the path which is used to relaunch the client after the update is installed. By default, the path of the host bundle. - (NSString *)pathToRelaunchForUpdater:(SUUpdater *)updater; @end + +// ----------------------------------------------------------------------------- +// Constants: +// ----------------------------------------------------------------------------- + // Define some minimum intervals to avoid DOS-like checking attacks. These are in seconds. #ifdef DEBUG && 0 #define SU_MIN_CHECK_INTERVAL 60 diff --git a/SUVersionDisplayProtocol.h b/SUVersionDisplayProtocol.h new file mode 100644 index 000000000..368b9c9f4 --- /dev/null +++ b/SUVersionDisplayProtocol.h @@ -0,0 +1,27 @@ +// +// SUVersionDisplayProtocol.h +// EyeTV +// +// Created by Uli Kusterer on 08.12.09. +// Copyright 2009 Elgato Systems GmbH. All rights reserved. +// + +#import + + +/*! + @protocol + @abstract Implement this protocol to apply special formatting to the two + version numbers. +*/ +@protocol SUVersionDisplay + +/*! + @method + @abstract An abstract method to format two version strings. + @discussion You get both so you can display important distinguishing + information, but leave out unnecessary/confusing parts. +*/ +-(void) formatVersion: (NSString**)inOutVersionA andVersion: (NSString**)inOutVersionB; + +@end