~tcurdt/sparkle/devel

« back to all changes in this revision

Viewing changes to SUBasicUpdateDriver.m

  • Committer: Andy Matuschak
  • Date: 2008-06-29 05:28:14 UTC
  • Revision ID: andy@andymatuschak.org-20080629052814-j3qbetfmmrxm132j
Improved delegate names and made SUProbingUpdateDriver use SUUpdater's delegate methods instead of dumbly having its own.

IF YOU ARE IMPLEMENTING ANY DELEGATE METHODS TO A SPARKLE CLASS, CHECK THESE DIFFS AND ENSURE THAT THE SELECTORS YOU'RE IMPLEMENTING HAVEN'T CHANGED. There's a pretty good chance they have. But for good reason, I promise!

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
 
59
59
- (void)appcastDidFinishLoading:(SUAppcast *)ac
60
60
{
61
 
        if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
62
 
                [delegate appcastDidFinishLoading:ac];
 
61
        if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHostBundle:)])
 
62
                [delegate appcastDidFinishLoading:ac forHostBundle:hostBundle];
63
63
        
64
64
        NSArray* updates = [ac items];
65
65
        if ([updates count] > 0)
66
66
                [[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey];
67
67
        
68
68
        // Now we have to find the best valid update in the appcast.
69
 
        if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:)]) // Does the delegate want to handle it?
 
69
        if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHostBundle:)]) // Does the delegate want to handle it?
70
70
        {
71
 
                updateItem = [delegate bestValidUpdateInAppcast:ac];
 
71
                updateItem = [delegate bestValidUpdateInAppcast:ac forHostBundle:hostBundle];
72
72
        }
73
73
        else // If not, we'll take care of it ourselves.
74
74
        {
97
97
 
98
98
- (void)didFindValidUpdate
99
99
{
100
 
        if ([delegate respondsToSelector:@selector(didFindValidUpdate:)])
101
 
                [delegate didFindValidUpdate:updateItem];
 
100
        if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHostBundle:)])
 
101
                [delegate didFindValidUpdate:updateItem toHostBundle:hostBundle];
102
102
        [self downloadUpdate];
103
103
}
104
104
 
105
105
- (void)didNotFindUpdate
106
106
{
 
107
        if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)])
 
108
                [delegate didNotFindUpdateToHostBundle:hostBundle];
107
109
        [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [hostBundle name]] forKey:NSLocalizedDescriptionKey]]];
108
110
}
109
111
 
190
192
 
191
193
- (void)installUpdate
192
194
{
193
 
        if ([delegate respondsToSelector:@selector(updateWillInstall:)])
194
 
                [delegate updateWillInstall:updateItem];
 
195
        if ([delegate respondsToSelector:@selector(updateWillInstall:toHostBundle:)])
 
196
                [delegate updateWillInstall:updateItem toHostBundle:hostBundle];
195
197
        // Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
196
198
        NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]]  pathForResource:@"relaunch" ofType:@""];
197
199
        NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
213
215
{
214
216
        // Give the host app an opportunity to postpone the relaunch.
215
217
        static BOOL postponedOnce = NO;
216
 
        if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:untilInvoking:)])
 
218
        if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHostBundle:untilInvoking:)])
217
219
        {
218
220
                NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]];
219
221
                [invocation setSelector:@selector(relaunchHostApp)];
220
222
                [invocation setTarget:self];
221
223
                postponedOnce = YES;
222
 
                if ([delegate shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation])
 
224
                if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHostBundle:hostBundle untilInvoking:invocation])
223
225
                        return;
224
226
        }
225
227