2014-08-01 06:53:07 -04:00
//
// SUPlainInstaller . m
// Sparkle
//
// Created by Andy Matuschak on 4 / 10 / 08.
// Copyright 2008 Andy Matuschak . All rights reserved .
//
# import "SUPlainInstaller.h"
# import "SUPlainInstallerInternals.h"
# import "SUConstants.h"
# import "SUHost.h"
@ implementation SUPlainInstaller
+ ( void ) performInstallationToPath : ( NSString * ) installationPath fromPath : ( NSString * ) path host : ( SUHost * ) host delegate : ( id < SUInstallerDelegate > ) delegate versionComparator : ( id < SUVersionComparison > ) comparator
{
2014-09-03 12:47:40 -04:00
// Prevent malicious downgrades
if ( ! [ [ [ NSBundle bundleWithIdentifier : SUBundleIdentifier ] infoDictionary ] [ SUEnableAutomatedDowngradesKey ] boolValue ] ) {
if ( [ comparator compareVersion : [ host version ] toVersion : [ [ NSBundle bundleWithPath : path ] objectForInfoDictionaryKey : ( __bridge NSString * ) kCFBundleVersionKey ] ] = = NSOrderedDescending )
{
NSString * errorMessage = [ NSString stringWithFormat : @ "Sparkle Updater: Possible attack in progress! Attempting to \" upgrade \ " from %@ to %@. Aborting update." , [ host version ] , [ [ NSBundle bundleWithPath : path ] objectForInfoDictionaryKey : ( __bridge NSString * ) kCFBundleVersionKey ] ] ;
NSError * error = [ NSError errorWithDomain : SUSparkleErrorDomain code : SUDowngradeError userInfo : @ { NSLocalizedDescriptionKey : errorMessage } ] ;
[ self finishInstallationToPath : installationPath withResult : NO host : host error : error delegate : delegate ] ;
return ;
}
2014-08-01 06:53:07 -04:00
}
dispatch_async ( dispatch_get _global _queue ( DISPATCH_QUEUE _PRIORITY _DEFAULT , 0 ) , ^ {
NSError * error = nil ;
NSString * oldPath = [ host bundlePath ] ;
NSString * tempName = [ self temporaryNameForPath : [ host installationPath ] ] ;
BOOL result = [ self copyPathWithAuthentication : path overPath : installationPath temporaryName : tempName error : & error ] ;
if ( result ) {
BOOL haveOld = [ [ NSFileManager defaultManager ] fileExistsAtPath : oldPath ] ;
BOOL differentFromNew = ! [ oldPath isEqualToString : installationPath ] ;
if ( haveOld && differentFromNew ) {
[ self _movePathToTrash : oldPath ] ; // On success , trash old copy if there ' s still one due to renaming .
}
}
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
[ self finishInstallationToPath : installationPath withResult : result host : host error : error delegate : delegate ] ;
} ) ;
} ) ;
}
@ end