diff --git a/Autoupdate/AppInstaller.m b/Autoupdate/AppInstaller.m index 4de79583..9a958d52 100644 --- a/Autoupdate/AppInstaller.m +++ b/Autoupdate/AppInstaller.m @@ -435,7 +435,7 @@ static const NSTimeInterval SUDisplayProgressTimeDelay = 0.7; dispatch_async(self.installerQueue, ^{ NSError *installerError = nil; - id installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationType updateDirectory:self.updateDirectoryPath versionComparator:[[SUStandardVersionComparator alloc] init] error:&installerError]; + id installer = [SUInstaller installerForHost:self.host expectedInstallationType:self.installationType updateDirectory:self.updateDirectoryPath error:&installerError]; if (installer == nil) { SULog(@"Error: Failed to create installer instance with error: %@", installerError); diff --git a/Autoupdate/SUInstaller.h b/Autoupdate/SUInstaller.h index 10c2e703..7fddd556 100644 --- a/Autoupdate/SUInstaller.h +++ b/Autoupdate/SUInstaller.h @@ -7,7 +7,6 @@ // #import -#import "SUVersionComparisonProtocol.h" #import "SPUInstallerProtocol.h" NS_ASSUME_NONNULL_BEGIN @@ -16,7 +15,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SUInstaller : NSObject -+ (nullable id)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory versionComparator:(id )comparator error:(NSError **)error; ++ (nullable id)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory error:(NSError **)error; + (nullable NSString *)installSourcePathInUpdateFolder:(NSString *)inUpdateFolder forHost:(SUHost *)host isPackage:(BOOL *)isPackagePtr isGuided:(nullable BOOL *)isGuidedPtr; diff --git a/Autoupdate/SUInstaller.m b/Autoupdate/SUInstaller.m index 12a47417..92941175 100644 --- a/Autoupdate/SUInstaller.m +++ b/Autoupdate/SUInstaller.m @@ -112,7 +112,7 @@ return newAppDownloadPath; } -+ (nullable id)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory versionComparator:(id )comparator error:(NSError * __autoreleasing *)error ++ (nullable id)installerForHost:(SUHost *)host expectedInstallationType:(NSString *)expectedInstallationType updateDirectory:(NSString *)updateDirectory error:(NSError * __autoreleasing *)error { BOOL isPackage = NO; BOOL isGuided = NO; @@ -165,7 +165,7 @@ installationPath = host.bundlePath; } - installer = [[SUPlainInstaller alloc] initWithHost:host bundlePath:newDownloadPath installationPath:installationPath versionComparator:comparator]; + installer = [[SUPlainInstaller alloc] initWithHost:host bundlePath:newDownloadPath installationPath:installationPath]; } } diff --git a/Autoupdate/SUPlainInstaller.h b/Autoupdate/SUPlainInstaller.h index 49bb6b3a..ce946e7f 100644 --- a/Autoupdate/SUPlainInstaller.h +++ b/Autoupdate/SUPlainInstaller.h @@ -18,8 +18,7 @@ @param host The current (old) bundle host @param bundlePath The path to the new bundle that will be installed. @param installationPath The path the new bundlePath will be installed to. - @param comparator The version comparator to use to prevent a downgrade from occurring. */ -- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath versionComparator:(id )comparator; +- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath; @end diff --git a/Autoupdate/SUPlainInstaller.m b/Autoupdate/SUPlainInstaller.m index 874b4301..5c0acd7e 100644 --- a/Autoupdate/SUPlainInstaller.m +++ b/Autoupdate/SUPlainInstaller.m @@ -13,6 +13,7 @@ #import "SULog.h" #import "SUErrors.h" #import "SUVersionComparisonProtocol.h" +#import "SUStandardVersionComparator.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -21,7 +22,6 @@ @interface SUPlainInstaller () @property (nonatomic, readonly) SUHost *host; -@property (nonatomic, readonly) id comparator; @property (nonatomic, copy, readonly) NSString *bundlePath; @property (nonatomic, copy, readonly) NSString *installationPath; @@ -34,20 +34,18 @@ @implementation SUPlainInstaller @synthesize host = _host; -@synthesize comparator = _comparator; @synthesize bundlePath = _bundlePath; @synthesize installationPath = _installationPath; @synthesize tempOldDirectoryURL = _tempOldDirectoryURL; @synthesize tempNewDirectoryURL = _tempNewDirectoryURL; -- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath versionComparator:(id )comparator +- (instancetype)initWithHost:(SUHost *)host bundlePath:(NSString *)bundlePath installationPath:(NSString *)installationPath { self = [super init]; if (self != nil) { _host = host; _bundlePath = [bundlePath copy]; _installationPath = [installationPath copy]; - _comparator = comparator; } return self; } @@ -198,7 +196,8 @@ NSString *hostVersion = [self.host version]; NSBundle *bundle = [NSBundle bundleWithPath:self.bundlePath]; NSString *updateVersion = [bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; - if (!updateVersion || [self.comparator compareVersion:hostVersion toVersion:updateVersion] == NSOrderedDescending) { + id comparator = [[SUStandardVersionComparator alloc] init]; + if (!updateVersion || [comparator compareVersion:hostVersion toVersion:updateVersion] == NSOrderedDescending) { NSString *errorMessage = [NSString stringWithFormat:@"For security reasons, updates that downgrade version of the application are not allowed. Refusing to downgrade app from version %@ to %@. Aborting update.", hostVersion, [bundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]]; *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDowngradeError userInfo:@{ NSLocalizedDescriptionKey: errorMessage }]; diff --git a/Tests/SUInstallerTest.m b/Tests/SUInstallerTest.m index 9d589aa2..15c9e085 100644 --- a/Tests/SUInstallerTest.m +++ b/Tests/SUInstallerTest.m @@ -11,7 +11,6 @@ #import "SUHost.h" #import "SUInstaller.h" #import "SPUInstallerProtocol.h" -#import "SUStandardVersionComparator.h" #import "SPUInstallationType.h" #import @@ -55,7 +54,7 @@ SUHost *host = [[SUHost alloc] initWithBundle:bundle]; NSError *installerError = nil; - id installer = [SUInstaller installerForHost:host expectedInstallationType:SPUInstallationTypeGuidedPackage updateDirectory:[path stringByDeletingLastPathComponent] versionComparator:[[SUStandardVersionComparator alloc] init] error:&installerError]; + id installer = [SUInstaller installerForHost:host expectedInstallationType:SPUInstallationTypeGuidedPackage updateDirectory:[path stringByDeletingLastPathComponent] error:&installerError]; if (installer == nil) { XCTFail(@"Installer is nil with error: %@", installerError);