| 1 | // |
|---|
| 2 | // SUPlainInstaller.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 "SUPlainInstaller.h" |
|---|
| 10 | #import "SUPlainInstallerInternals.h" |
|---|
| 11 | #import "SUHost.h" |
|---|
| 12 | |
|---|
| 13 | NSString *SUInstallerPathKey = @"SUInstallerPath"; |
|---|
| 14 | NSString *SUInstallerHostKey = @"SUInstallerHost"; |
|---|
| 15 | NSString *SUInstallerDelegateKey = @"SUInstallerDelegate"; |
|---|
| 16 | NSString *SUInstallerVersionComparatorKey = @"SUInstallerVersionComparator"; |
|---|
| 17 | |
|---|
| 18 | @implementation SUPlainInstaller |
|---|
| 19 | |
|---|
| 20 | + (void)installPath:(NSString *)path overHost:(SUHost *)bundle delegate:delegate versionComparator:(id <SUVersionComparison>)comparator |
|---|
| 21 | { |
|---|
| 22 | NSError *error; |
|---|
| 23 | BOOL result = YES; |
|---|
| 24 | |
|---|
| 25 | // Prevent malicious downgrades: |
|---|
| 26 | if ([comparator compareVersion:[bundle version] toVersion:[[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]] == NSOrderedDescending) |
|---|
| 27 | { |
|---|
| 28 | NSString * errorMessage = [NSString stringWithFormat:@"Sparkle Updater: Possible attack in progress! Attempting to \"upgrade\" from %@ to %@. Aborting update.", [bundle version], [[NSBundle bundleWithPath:path] objectForInfoDictionaryKey:@"CFBundleVersion"]]; |
|---|
| 29 | result = NO; |
|---|
| 30 | error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:[NSDictionary dictionaryWithObject:errorMessage forKey:NSLocalizedDescriptionKey]]; |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | if (result) |
|---|
| 34 | result = [self copyPathWithAuthentication:path overPath:[bundle bundlePath] error:&error]; |
|---|
| 35 | [self _finishInstallationWithResult:result host:bundle error:error delegate:delegate]; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | + (void)_performInstallationWithInfo:(NSDictionary *)info |
|---|
| 39 | { |
|---|
| 40 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; |
|---|
| 41 | |
|---|
| 42 | [self installPath:[info objectForKey:SUInstallerPathKey] overHost:[info objectForKey:SUInstallerHostKey] delegate:[info objectForKey:SUInstallerDelegateKey] versionComparator:[info objectForKey:SUInstallerVersionComparatorKey]]; |
|---|
| 43 | |
|---|
| 44 | [pool drain]; |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | + (void)performInstallationWithPath:(NSString *)path host:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator |
|---|
| 48 | { |
|---|
| 49 | NSDictionary *info = [NSDictionary dictionaryWithObjectsAndKeys:path, SUInstallerPathKey, host, SUInstallerHostKey, delegate, SUInstallerDelegateKey, comparator, SUInstallerVersionComparatorKey, nil]; |
|---|
| 50 | if (synchronously) |
|---|
| 51 | [self _performInstallationWithInfo:info]; |
|---|
| 52 | else |
|---|
| 53 | [NSThread detachNewThreadSelector:@selector(_performInstallationWithInfo:) toTarget:self withObject:info]; |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | @end |
|---|