forked from sparkle-project/Sparkle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LVAutomaticUpdateDriver.m
63 lines (52 loc) · 2.14 KB
/
LVAutomaticUpdateDriver.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// LVAutomaticUpdateDriver.m
// Sparkle
//
// Created by Kelly Sutton on 5/13/13.
// Copyright 2013 Kelly Sutton. All rights reserved.
//
#import "LVAutomaticUpdateDriver.h"
#import "SUAutomaticUpdateAlert.h"
#import "SUHost.h"
#import "SUConstants.h"
#import "LVUpdateActivityProtocol.h"
@implementation LVAutomaticUpdateDriver
- (void)unarchiverDidFinish:(SUUnarchiver *)ua
{
[self performUpdateIfInactive];
}
- (void)performUpdateIfInactive
{
if ([updater.delegate conformsToProtocol:@protocol(LVUpdateActivityProtocol)]) {
id<LVUpdateActivityProtocol> updaterDelegate = (id<LVUpdateActivityProtocol>)updater.delegate;
NSDate *lastActiveDate = [updaterDelegate lastActivity];
// Make sure something hasn't happened between the time we asked for an update and we unarchived the update.
if (lastActiveDate && [lastActiveDate compare:[self timeAgoThreshold]] == NSOrderedAscending) {
[self installWithToolAndRelaunch:YES];
}
}
}
- (NSDate *)timeAgoThreshold
{
if ([updater.delegate conformsToProtocol:@protocol(LVUpdateActivityProtocol)]) {
id<LVUpdateActivityProtocol> updaterDelegate = (id<LVUpdateActivityProtocol>)updater.delegate;
return [[NSDate date] dateByAddingTimeInterval:-1 * (int)[updaterDelegate updateThreshold]];
}
else {
return [[NSDate date] dateByAddingTimeInterval:-1 * 5 * 60];
}
}
// Override the newer Sparkle DSA/Code-signing requirement. If our SSL cert is compromised, we've got bigger problems.
- (BOOL)validateUpdateDownloadedToPath:(NSString *)downloadedPath extractedToPath:(NSString *)extractedPath DSASignature:(NSString *)DSASignature publicDSAKey:(NSString *)publicDSAKey
{
return [[updateItem.fileURL scheme] isEqualToString:@"https"] && [[appcastURL scheme] isEqualToString:@"https"];
}
- (void)abortUpdateWithError:(NSError *)error
{
[super abortUpdateWithError:error];
if ([updater.delegate conformsToProtocol:@protocol(LVUpdateActivityProtocol)]) {
id<LVUpdateActivityProtocol> updaterDelegate = (id<LVUpdateActivityProtocol>)updater.delegate;
[updaterDelegate updateFailedWithError:error];
}
}
@end