Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 76 lines (63 sloc) 3.192 kB
49e3d81 Major refactoring, yay.
andym authored
1 //
2 // SUPackageInstaller.m
3 // Sparkle
4 //
5 // Created by Andy Matuschak on 4/10/08.
6 // Copyright 2008 Andy Matuschak. All rights reserved.
7 //
8
9 #import "SUPackageInstaller.h"
43a0a7d @uliwitness Merge of changes from SVN repository:
uliwitness authored
10 #import <Cocoa/Cocoa.h>
bbcfe7e @uliwitness - More WIP creating finish_installation that waits
uliwitness authored
11 #import "SUConstants.h"
49e3d81 Major refactoring, yay.
andym authored
12
522ffb0 Add a conditional definition of NSAppKitVersionNumber10_4 to allow bu…
Stuart Morgan authored
13 #ifndef NSAppKitVersionNumber10_4
14 #define NSAppKitVersionNumber10_4 824
15 #endif
49e3d81 Major refactoring, yay.
andym authored
16
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
17 NSString *SUPackageInstallerCommandKey = @"SUPackageInstallerCommand";
18 NSString *SUPackageInstallerArgumentsKey = @"SUPackageInstallerArguments";
19 NSString *SUPackageInstallerHostKey = @"SUPackageInstallerHost";
20 NSString *SUPackageInstallerDelegateKey = @"SUPackageInstallerDelegate";
21
49e3d81 Major refactoring, yay.
andym authored
22 @implementation SUPackageInstaller
23
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
24 + (void)_finishInstallationWithInfo:(NSDictionary *)info
25 {
26 [self _finishInstallationWithResult:YES host:[info objectForKey:SUPackageInstallerHostKey] error:nil delegate:[info objectForKey:SUPackageInstallerDelegateKey]];
27 }
28
29 + (void)_performInstallationWithInfo:(NSDictionary *)info
49e3d81 Major refactoring, yay.
andym authored
30 {
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
31 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
32
33 NSTask *installer = [NSTask launchedTaskWithLaunchPath:[info objectForKey:SUPackageInstallerCommandKey] arguments:[info objectForKey:SUPackageInstallerArgumentsKey]];
34 [installer waitUntilExit];
35
36 // Known bug: if the installation fails or is canceled, Sparkle goes ahead and restarts, thinking everything is fine.
37 [self performSelectorOnMainThread:@selector(_finishInstallationWithInfo:) withObject:info waitUntilDone:NO];
38
39 [pool drain];
40 }
41
42 + (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
43 {
44 NSString *command;
45 NSArray *args;
49e3d81 Major refactoring, yay.
andym authored
46
d4c39a2 Fallback to Installer.app on 10.4
Peter Speck authored
47 if (floor(NSAppKitVersionNumber) == NSAppKitVersionNumber10_4) {
48 // 10.4 uses Installer.app because the "open" command in 10.4 doesn't support -W and -n
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
49 command = [[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.apple.installer"];
50 args = [NSArray arrayWithObjects:path, nil];
d4c39a2 Fallback to Installer.app on 10.4
Peter Speck authored
51 } else {
52 // 10.5 and later. Run installer using the "open" command to ensure it is launched in front of current application.
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
53 // The -W and -n options were added to the 'open' command in 10.5
54 // -W = wait until the app has quit.
55 // -n = Open another instance if already open.
56 // -b = app bundle identifier
57 command = @"/usr/bin/open";
58 args = [NSArray arrayWithObjects:@"-W", @"-n", @"-b", @"com.apple.installer", path, nil];
49e3d81 Major refactoring, yay.
andym authored
59 }
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
60 if (![[NSFileManager defaultManager] fileExistsAtPath:command])
49e3d81 Major refactoring, yay.
andym authored
61 {
0e99d4f @hofman Bug #402074: ".pkg installations should support asynchronous installa…
hofman authored
62 NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingInstallerToolError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find Apple's installer tool!" forKey:NSLocalizedDescriptionKey]];
63 [self _finishInstallationWithResult:NO host:host error:error delegate:delegate];
64 }
65 else
66 {
67 NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:command, SUPackageInstallerCommandKey, args, SUPackageInstallerArgumentsKey, host, SUPackageInstallerHostKey, delegate, SUPackageInstallerDelegateKey, nil];
68 if (synchronously)
69 [self _performInstallationWithInfo:info];
70 else
71 [NSThread detachNewThreadSelector:@selector(_performInstallationWithInfo:) toTarget:self withObject:info];
49e3d81 Major refactoring, yay.
andym authored
72 }
73 }
74
75 @end
Something went wrong with that request. Please try again.