forked from sparkle-project/Sparkle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SUPackageInstaller.m
69 lines (59 loc) · 2.76 KB
/
SUPackageInstaller.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
64
65
66
67
68
69
//
// SUPackageInstaller.m
// Sparkle
//
// Created by Andy Matuschak on 4/10/08.
// Copyright 2008 Andy Matuschak. All rights reserved.
//
#import "SUPackageInstaller.h"
#import <Cocoa/Cocoa.h>
#import "SUConstants.h"
static NSString * const SUPackageInstallerCommandKey = @"SUPackageInstallerCommand";
static NSString * const SUPackageInstallerArgumentsKey = @"SUPackageInstallerArguments";
static NSString * const SUPackageInstallerHostKey = @"SUPackageInstallerHost";
static NSString * const SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate";
static NSString * const SUPackageInstallerInstallationPathKey = @"SUPackageInstallerInstallationPathKey";
@implementation SUPackageInstaller
+ (void)finishInstallationWithInfo:(NSDictionary *)info
{
[self finishInstallationToPath:info[SUPackageInstallerInstallationPathKey] withResult:YES host:info[SUPackageInstallerHostKey] error:nil delegate:info[SUPackageInstallerDelegateKey]];
}
+ (void)performInstallationWithInfo:(NSDictionary *)info
{
@autoreleasepool {
NSTask *installer = [NSTask launchedTaskWithLaunchPath:info[SUPackageInstallerCommandKey] arguments:info[SUPackageInstallerArgumentsKey]];
[installer waitUntilExit];
// Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
dispatch_async(dispatch_get_main_queue(), ^{
[self finishInstallationWithInfo:info];
});
}
}
+ (void)performInstallationToPath:(NSString *)installationPath fromPath:(NSString *)path host:(SUHost *)host delegate:(id <SUInstallerDelegate>)delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>) __unused comparator
{
NSString *command;
NSArray *args;
// Run installer using the "open" command to ensure it is launched in front of current application.
// -W = wait until the app has quit.
// -n = Open another instance if already open.
// -b = app bundle identifier
command = @"/usr/bin/open";
args = @[@"-W", @"-n", @"-b", @"com.apple.installer", path];
if (![[NSFileManager defaultManager] fileExistsAtPath:command])
{
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:@{NSLocalizedDescriptionKey: @"Couldn't find Apple's installer tool!"}];
[self finishInstallationToPath:installationPath withResult:NO host:host error:error delegate:delegate];
}
else
{
NSDictionary *info = @{SUPackageInstallerCommandKey: command, SUPackageInstallerArgumentsKey: args, SUPackageInstallerHostKey: host, SUPackageInstallerDelegateKey: delegate, SUPackageInstallerInstallationPathKey: installationPath};
if (synchronously)
[self performInstallationWithInfo:info];
else {
dispatch_async(dispatch_get_global_queue(0, 0), ^{
[self performInstallationWithInfo:info];
});
}
}
}
@end