diff --git a/Configurations/ed25519-Shared.xcconfig b/Configurations/ed25519-Shared.xcconfig index 91faa52d..22d08a7d 100644 --- a/Configurations/ed25519-Shared.xcconfig +++ b/Configurations/ed25519-Shared.xcconfig @@ -12,3 +12,6 @@ ALWAYS_SEARCH_USER_PATHS = NO // Disable Warnings - this is a third-party project, and we'll trust that the maintainers know what they're doing. WARNING_CFLAGS = $(inherited) -Wno-cast-qual -Wno-conversion -Wno-sign-conversion + +// Disable dead stores analyzer warning +CLANG_ANALYZER_DEADCODE_DEADSTORES = NO diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 4fd84ea3..91729ac5 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -161,6 +161,7 @@ 721D8A811D498B9B0032E472 /* Updater.app in Copy Tools */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 721D8A861D4ADFEB0032E472 /* SPULocalCacheDirectory.m in Sources */ = {isa = PBXBuildFile; fileRef = 721BC20D1D1CDE55002BC71E /* SPULocalCacheDirectory.m */; }; 721D8A871D4C5BF10032E472 /* SULog.m in Sources */ = {isa = PBXBuildFile; fileRef = 55C14F05136EF6DB00649790 /* SULog.m */; }; + 722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */ = {isa = PBXBuildFile; fileRef = 722545B526805FF80036465C /* testappcast_info_updates.xml */; }; 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */; }; 7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */ = {isa = PBXBuildFile; fileRef = 7229E1B71C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h */; }; 7229E1BA1C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m in Sources */ = {isa = PBXBuildFile; fileRef = 7229E1B81C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.m */; }; @@ -364,6 +365,15 @@ 72EB87EA1CB8798800C37F42 /* ShowInstallerProgress.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */; }; 72EB87EB1CB8859100C37F42 /* Updater.app in Copy Tools */ = {isa = PBXBuildFile; fileRef = 721C24451CB753E6005440CB /* Updater.app */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 72EB87EC1CB8887E00C37F42 /* SUStatus.xib in Resources */ = {isa = PBXBuildFile; fileRef = 55C14BD8136EF00C00649790 /* SUStatus.xib */; }; + 72EF30BE2675CF38008CE987 /* SPUAppcastItemStateResolver.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30BA2675CF38008CE987 /* SPUAppcastItemStateResolver.h */; settings = {ATTRIBUTES = (Private, ); }; }; + 72EF30BF2675CF38008CE987 /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */; }; + 72EF30C02675CF38008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; }; + 72EF30C12675CF38008CE987 /* SPUAppcastItemState.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30BD2675CF38008CE987 /* SPUAppcastItemState.h */; }; + 72EF30C22675CF67008CE987 /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */; }; + 72EF30C32675CF67008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; }; + 72EF30C42675CFA1008CE987 /* SPUAppcastItemState.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */; }; + 72EF30C52675CFA1008CE987 /* SPUAppcastItemStateResolver.m in Sources */ = {isa = PBXBuildFile; fileRef = 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */; }; + 72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = 72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */; settings = {ATTRIBUTES = (Private, ); }; }; 72F94F581CC44DE1002DEE68 /* SPUXPCServiceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F94F561CC44DE1002DEE68 /* SPUXPCServiceInfo.h */; }; 72F94F591CC44DE1002DEE68 /* SPUXPCServiceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F94F571CC44DE1002DEE68 /* SPUXPCServiceInfo.m */; }; 72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */ = {isa = PBXBuildFile; fileRef = 726E07B11CAF08D6001A286B /* SUInstallerLauncher.m */; }; @@ -948,6 +958,8 @@ 722194521D3BFEB7004C34FF /* SUInstallerAgentInitiationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SUInstallerAgentInitiationProtocol.h; path = Sparkle/InstallerProgress/SUInstallerAgentInitiationProtocol.h; sourceTree = SOURCE_ROOT; }; 7223E7611AD1AEFF008E3161 /* sais.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = sais.c; sourceTree = ""; }; 7223E7621AD1AEFF008E3161 /* sais.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sais.h; sourceTree = ""; }; + 722545B526805FF80036465C /* testappcast_info_updates.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = testappcast_info_updates.xml; sourceTree = ""; }; + 722545B72680699D0036465C /* SPUAppcastItemStateResolver+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "SPUAppcastItemStateResolver+Private.h"; sourceTree = ""; }; 722589B51E0A24B9005EA0B9 /* Security.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = Security.md; sourceTree = ""; }; 722589B61E0A24C6005EA0B9 /* Design Practices.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = "Design Practices.md"; sourceTree = ""; }; 7229E1B51C97C91100CB50D0 /* SPUUpdateDriver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdateDriver.h; sourceTree = ""; }; @@ -1262,6 +1274,11 @@ 72E45CF61B640DAE005C701A /* SUUpdateSettingsWindowController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = SUUpdateSettingsWindowController.xib; sourceTree = ""; }; 72E45CFB1B641961005C701A /* sparkletestcast.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = sparkletestcast.xml; sourceTree = ""; }; 72EB87E91CB8798800C37F42 /* ShowInstallerProgress.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ShowInstallerProgress.m; path = Sparkle/InstallerProgress/ShowInstallerProgress.m; sourceTree = SOURCE_ROOT; }; + 72EF30BA2675CF38008CE987 /* SPUAppcastItemStateResolver.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemStateResolver.h; sourceTree = ""; }; + 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemState.m; sourceTree = ""; }; + 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUAppcastItemStateResolver.m; sourceTree = ""; }; + 72EF30BD2675CF38008CE987 /* SPUAppcastItemState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUAppcastItemState.h; sourceTree = ""; }; + 72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SUAppcastItem+Private.h"; sourceTree = ""; }; 72F94ED51CC3441A002DEE68 /* ConfigInstallerLauncherDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigInstallerLauncherDebug.xcconfig; sourceTree = ""; }; 72F94ED61CC344A7002DEE68 /* ConfigDownloaderDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigDownloaderDebug.xcconfig; sourceTree = ""; }; 72F94EDA1CC36C37002DEE68 /* ConfigTestAppDebug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigTestAppDebug.xcconfig; sourceTree = ""; }; @@ -1669,6 +1686,7 @@ 5AF6C74E1AEA46D10014A3AB /* test.pkg */, 5AD0FA7E1C73F2E2004BCEFF /* testappcast.xml */, 725B3A81263FBF0C0041AB8E /* testappcast_minimumAutoupdateVersion.xml */, + 722545B526805FF80036465C /* testappcast_info_updates.xml */, 5F1510A11C96E591006E1629 /* testnamespaces.xml */, FA30773C24CBC295007BA37D /* testlocalizedreleasenotesappcast.xml */, 5A5DD41B249F0F4B0045EB3E /* test-relative-urls.xml */, @@ -1767,7 +1785,13 @@ 725DED72263D10C400E7FA8F /* SUAppcast+Private.h */, 61B5FB9509C4F04600B25A18 /* SUAppcast.m */, 61B5FC5309C5182000B25A18 /* SUAppcastItem.h */, + 72EF30C6267C716A008CE987 /* SUAppcastItem+Private.h */, 61B5FC5409C5182000B25A18 /* SUAppcastItem.m */, + 72EF30BD2675CF38008CE987 /* SPUAppcastItemState.h */, + 72EF30BB2675CF38008CE987 /* SPUAppcastItemState.m */, + 72EF30BA2675CF38008CE987 /* SPUAppcastItemStateResolver.h */, + 722545B72680699D0036465C /* SPUAppcastItemStateResolver+Private.h */, + 72EF30BC2675CF38008CE987 /* SPUAppcastItemStateResolver.m */, 721D588B25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.h */, 721D588C25BE59F900D23BEA /* SUPhasedUpdateGroupInfo.m */, 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */, @@ -2294,6 +2318,7 @@ 72B767D61C9C8B5C00A07552 /* SPUBasicUpdateDriver.h in Headers */, 72B767E21C9CE90A00A07552 /* SPUCoreBasedUpdateDriver.h in Headers */, 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */, + 72EF30C12675CF38008CE987 /* SPUAppcastItemState.h in Headers */, 7229E1BD1C98EFF200CB50D0 /* SPUDownloadDriver.h in Headers */, 7267E5FD1D3DD1B700D1BF90 /* SPUResumableUpdate.h in Headers */, 7267E5B61D3D8AEE00D1BF90 /* SPUInstallationInfo.h in Headers */, @@ -2309,6 +2334,8 @@ 7246E0A31C83B685003B4E75 /* SPUStandardUpdaterController.h in Headers */, 725CB95A1C7121830064365A /* SPUStandardUserDriver.h in Headers */, 726E4A371C89116000C57C6A /* SPUStandardUserDriverDelegate.h in Headers */, + 72EF30BE2675CF38008CE987 /* SPUAppcastItemStateResolver.h in Headers */, + 72EF30C7267C716A008CE987 /* SUAppcastItem+Private.h in Headers */, 726DF88E1C84277600188804 /* SPUUserUpdateState.h in Headers */, 72B767DA1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.h in Headers */, 7229E1B61C97C91100CB50D0 /* SPUUpdateDriver.h in Headers */, @@ -2922,6 +2949,7 @@ 5AF6C74F1AEA46D10014A3AB /* test.pkg in Resources */, 5AD0FA7F1C73F2E2004BCEFF /* testappcast.xml in Resources */, FA30773D24CBC295007BA37D /* testlocalizedreleasenotesappcast.xml in Resources */, + 722545B626805FF80036465C /* testappcast_info_updates.xml in Resources */, 5F1510A21C96E591006E1629 /* testnamespaces.xml in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -3227,6 +3255,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 72EF30C22675CF67008CE987 /* SPUAppcastItemState.m in Sources */, + 72EF30C32675CF67008CE987 /* SPUAppcastItemStateResolver.m in Sources */, 720AC2DC2618E8A500E25A3E /* SPUSecureCoding.m in Sources */, 720AC2C92618E89500E25A3E /* SUAppcastItem.m in Sources */, 720AC2A42618E85700E25A3E /* SPUInstallationInfo.m in Sources */, @@ -3325,6 +3355,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 72EF30C42675CFA1008CE987 /* SPUAppcastItemState.m in Sources */, + 72EF30C52675CFA1008CE987 /* SPUAppcastItemStateResolver.m in Sources */, 72464F701E1F31E000FB341C /* SUOperatingSystem.m in Sources */, 7267E5A81D3D8A9900D1BF90 /* AgentConnection.m in Sources */, 7267E5A21D3D8A7E00D1BF90 /* AppInstaller.m in Sources */, @@ -3388,6 +3420,7 @@ 7267E5B71D3D8AEE00D1BF90 /* SPUInstallationInfo.m in Sources */, 7267E5DF1D3D8FFA00D1BF90 /* SPUInstallationInputData.m in Sources */, 72B767CF1C9B924900A07552 /* SPUInstallerDriver.m in Sources */, + 72EF30BF2675CF38008CE987 /* SPUAppcastItemState.m in Sources */, 721BC20F1D1CDE55002BC71E /* SPULocalCacheDirectory.m in Sources */, 7267E5B21D3D8AD500D1BF90 /* SPUMessageTypes.m in Sources */, 72B3DECF1E23479000457642 /* SPUInformationalUpdate.m in Sources */, @@ -3400,6 +3433,7 @@ 723C8A551E2D60DB00C14942 /* SUTouchBarButtonGroup.m in Sources */, 72B767DB1C9CD2E400A07552 /* SPUUIBasedUpdateDriver.m in Sources */, 72DBA37E1D60CC34002594A8 /* SPUUpdatePermissionRequest.m in Sources */, + 72EF30C02675CF38008CE987 /* SPUAppcastItemStateResolver.m in Sources */, 61B5F8EE09C4CE3C00B25A18 /* SPUUpdater.m in Sources */, 720E217C1D0D00BF003A311C /* SPUUpdaterCycle.m in Sources */, 726E078E1CA891E9001A286B /* SPUUpdaterSettings.m in Sources */, diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 4b305e80..86423b2a 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -66,6 +66,10 @@ "An important update to %@ is ready to install" = "An important update to %@ is ready to install"; +"Unable to Check For Updates" = "Unable to Check For Updates"; + +"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version" = "The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version"; + /* the unit for bytes */ "B" = "B"; diff --git a/Sparkle/SPUAppcastItemState.h b/Sparkle/SPUAppcastItemState.h new file mode 100644 index 00000000..8dcb6e60 --- /dev/null +++ b/Sparkle/SPUAppcastItemState.h @@ -0,0 +1,28 @@ +// +// SPUAppcastItemState.h +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +// Appcast Item state that contains properties that depends on a host +@interface SPUAppcastItemState : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate informationalUpdate:(BOOL)informationalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK; + +@property (nonatomic, readonly) BOOL majorUpgrade; +@property (nonatomic, readonly) BOOL criticalUpdate; +@property (nonatomic, readonly) BOOL informationalUpdate; +@property (nonatomic, readonly) BOOL minimumOperatingSystemVersionIsOK; +@property (nonatomic, readonly) BOOL maximumOperatingSystemVersionIsOK; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemState.m b/Sparkle/SPUAppcastItemState.m new file mode 100644 index 00000000..6d6ee1fd --- /dev/null +++ b/Sparkle/SPUAppcastItemState.m @@ -0,0 +1,69 @@ +// +// SPUAppcastItemState.m +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUAppcastItemState.h" + + +#include "AppKitPrevention.h" + +#define SPUAppcastItemStateMajorUpgradeKey @"SPUAppcastItemStateMajorUpgrade" +#define SPUAppcastItemStateCriticalUpdateKey @"SPUAppcastItemStateCriticalUpdate" +#define SPUAppcastItemStateInformationalUpdateKey @"SPUAppcastItemStateInformationalUpdate" +#define SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey @"SPUAppcastItemStateMinimumOperatingSystemVersionIsOK" +#define SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey @"SPUAppcastItemStateMaximumOperatingSystemVersionIsOK" + +@interface SPUAppcastItemState () +@end + +@implementation SPUAppcastItemState + +@synthesize majorUpgrade = _majorUpgrade; +@synthesize criticalUpdate = _criticalUpdate; +@synthesize informationalUpdate = _informationalUpdate; +@synthesize minimumOperatingSystemVersionIsOK = _minimumOperatingSystemVersionIsOK; +@synthesize maximumOperatingSystemVersionIsOK = _maximumOperatingSystemVersionIsOK; + +- (instancetype)initWithMajorUpgrade:(BOOL)majorUpgrade criticalUpdate:(BOOL)criticalUpdate informationalUpdate:(BOOL)informationalUpdate minimumOperatingSystemVersionIsOK:(BOOL)minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:(BOOL)maximumOperatingSystemVersionIsOK +{ + self = [super init]; + if (self != nil) { + _majorUpgrade = majorUpgrade; + _criticalUpdate = criticalUpdate; + _informationalUpdate = informationalUpdate; + _minimumOperatingSystemVersionIsOK = minimumOperatingSystemVersionIsOK; + _maximumOperatingSystemVersionIsOK = maximumOperatingSystemVersionIsOK; + } + return self; +} + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (void)encodeWithCoder:(NSCoder *)encoder +{ + [encoder encodeBool:self.majorUpgrade forKey:SPUAppcastItemStateMajorUpgradeKey]; + [encoder encodeBool:self.criticalUpdate forKey:SPUAppcastItemStateCriticalUpdateKey]; + [encoder encodeBool:self.informationalUpdate forKey:SPUAppcastItemStateInformationalUpdateKey]; + [encoder encodeBool:self.minimumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey]; + [encoder encodeBool:self.maximumOperatingSystemVersionIsOK forKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey]; +} + +- (instancetype)initWithCoder:(NSCoder *)decoder +{ + BOOL majorUpgrade = [decoder decodeBoolForKey:SPUAppcastItemStateMajorUpgradeKey]; + BOOL criticalUpdate = [decoder decodeBoolForKey:SPUAppcastItemStateCriticalUpdateKey]; + BOOL informationalUpdate = [decoder decodeBoolForKey:SPUAppcastItemStateInformationalUpdateKey]; + BOOL minimumOperatingSystemVersionIsOK = [decoder decodeBoolForKey:SPUAppcastItemStateMinimumOperatingSystemVersionIsOKKey]; + BOOL maximumOperatingSystemVersionIsOK = [decoder decodeBoolForKey:SPUAppcastItemStateMaximumOperatingSystemVersionIsOKKey]; + + return [self initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate informationalUpdate:informationalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; +} + +@end diff --git a/Sparkle/SPUAppcastItemStateResolver+Private.h b/Sparkle/SPUAppcastItemStateResolver+Private.h new file mode 100644 index 00000000..4b1ec78b --- /dev/null +++ b/Sparkle/SPUAppcastItemStateResolver+Private.h @@ -0,0 +1,24 @@ +// +// SPUAppcastItemStateResolver+Private.h +// Sparkle +// +// Created by Mayur Pawashe on 6/20/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#ifndef SPUAppcastItemStateResolver_Private_h +#define SPUAppcastItemStateResolver_Private_h + +NS_ASSUME_NONNULL_BEGIN + +@interface SPUAppcastItemStateResolver () + +- (SPUAppcastItemState *)resolveStateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions minimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary; + ++ (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SPUAppcastItemStateResolver_Private_h */ diff --git a/Sparkle/SPUAppcastItemStateResolver.h b/Sparkle/SPUAppcastItemStateResolver.h new file mode 100644 index 00000000..d80f7b96 --- /dev/null +++ b/Sparkle/SPUAppcastItemStateResolver.h @@ -0,0 +1,37 @@ +// +// SPUAppcastItemStateResolver.h +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#if __has_feature(modules) +#if __has_warning("-Watimport-in-framework-header") +#pragma clang diagnostic ignored "-Watimport-in-framework-header" +#endif +@import Foundation; +#else +#import +#endif + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class SUStandardVersionComparator, SPUAppcastItemState; +@protocol SUVersionComparison; + +/*! + Private exposed class used to resolve Appcast Item properties that rely on external factors such as a host. + This resolver is used for constructing appcast items. + */ +SU_EXPORT @interface SPUAppcastItemStateResolver : NSObject + +- (instancetype)init NS_UNAVAILABLE; + +- (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUAppcastItemStateResolver.m b/Sparkle/SPUAppcastItemStateResolver.m new file mode 100644 index 00000000..0ce4f90c --- /dev/null +++ b/Sparkle/SPUAppcastItemStateResolver.m @@ -0,0 +1,120 @@ +// +// SPUAppcastItemStateResolver.m +// Sparkle +// +// Created by Mayur Pawashe on 5/31/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemStateResolver+Private.h" +#import "SPUAppcastItemState.h" +#import "SUVersionComparisonProtocol.h" +#import "SUStandardVersionComparator.h" +#import "SUConstants.h" +#import "SUOperatingSystem.h" + + +#include "AppKitPrevention.h" + +@interface SPUAppcastItemStateResolver () + +@property (nonatomic, readonly) NSString *hostVersion; +@property (nonatomic, readonly) id applicationVersionComparator; +@property (nonatomic, readonly) SUStandardVersionComparator *standardVersionComparator; + +@end + +@implementation SPUAppcastItemStateResolver + +@synthesize hostVersion = _hostVersion; +@synthesize applicationVersionComparator = _applicationVersionComparator; +@synthesize standardVersionComparator = _standardVersionComparator; + +- (instancetype)initWithHostVersion:(NSString *)hostVersion applicationVersionComparator:(id)applicationVersionComparator standardVersionComparator:(SUStandardVersionComparator *)standardVersionComparator +{ + self = [super init]; + if (self != nil) { + _hostVersion = [hostVersion copy]; + _applicationVersionComparator = applicationVersionComparator; + _standardVersionComparator = standardVersionComparator; + } + return self; +} + +- (BOOL)isMinimumOperatingSystemVersionOK:(NSString * _Nullable)minimumSystemVersion +{ + BOOL minimumVersionOK = YES; + if (minimumSystemVersion != nil && ![minimumSystemVersion isEqualToString:@""]) { + minimumVersionOK = [self.standardVersionComparator compareVersion:(NSString * _Nonnull)minimumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending; + } + return minimumVersionOK; +} + +- (BOOL)isMaximumOperatingSystemVersionOK:(NSString * _Nullable)maximumSystemVersion +{ + BOOL maximumVersionOK = YES; + if (maximumSystemVersion != nil && ![maximumSystemVersion isEqualToString:@""]) { + maximumVersionOK = [self.standardVersionComparator compareVersion:(NSString * _Nonnull)maximumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending; + } + return maximumVersionOK; +} + ++ (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator + { + return (minimumAutoupdateVersion.length == 0 || ([versionComparator compareVersion:hostVersion toVersion:(NSString * _Nonnull)minimumAutoupdateVersion] != NSOrderedAscending)); + } + +- (BOOL)isMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion + { + return [[self class] isMinimumAutoupdateVersionOK:minimumAutoupdateVersion hostVersion:self.hostVersion versionComparator:self.applicationVersionComparator]; + } + +- (BOOL)isCriticalUpdateWithCriticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary +{ + // Check if any critical update info is provided + if (criticalUpdateDictionary == nil) { + return NO; + } + + // If no critical version is supplied, then it is critical + NSString *criticalVersion = criticalUpdateDictionary[SUAppcastAttributeVersion]; + if (criticalVersion == nil || ![criticalVersion isKindOfClass:[NSString class]]) { + return YES; + } + + // Update is only critical when coming from previous versions + return ([self.applicationVersionComparator compareVersion:self.hostVersion toVersion:criticalVersion] == NSOrderedAscending); +} + +- (BOOL)isInformationalUpdateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions +{ + if (informationalUpdateVersions == nil) { + return NO; + } + + // Informational only update regardless of version the app is updating from + if (informationalUpdateVersions.count == 0) { + return YES; + } + + // Informational update only for a set of host versions we're updating from + return [informationalUpdateVersions containsObject:self.hostVersion]; +} + +- (SPUAppcastItemState *)resolveStateWithInformationalUpdateVersions:(NSSet * _Nullable)informationalUpdateVersions minimumOperatingSystemVersion:(NSString * _Nullable)minimumOperatingSystemVersion maximumOperatingSystemVersion:(NSString * _Nullable)maximumOperatingSystemVersion minimumAutoupdateVersion:(NSString * _Nullable)minimumAutoupdateVersion criticalUpdateDictionary:(NSDictionary * _Nullable)criticalUpdateDictionary +{ + BOOL informationalUpdate = [self isInformationalUpdateWithInformationalUpdateVersions:informationalUpdateVersions]; + + BOOL minimumOperatingSystemVersionIsOK = [self isMinimumOperatingSystemVersionOK:minimumOperatingSystemVersion]; + + BOOL maximumOperatingSystemVersionIsOK = [self isMaximumOperatingSystemVersionOK:maximumOperatingSystemVersion];; + + BOOL majorUpgrade = ![self isMinimumAutoupdateVersionOK:minimumAutoupdateVersion]; + + BOOL criticalUpdate = [self isCriticalUpdateWithCriticalUpdateDictionary:criticalUpdateDictionary]; + + return [[SPUAppcastItemState alloc] initWithMajorUpgrade:majorUpgrade criticalUpdate:criticalUpdate informationalUpdate:informationalUpdate minimumOperatingSystemVersionIsOK:minimumOperatingSystemVersionIsOK maximumOperatingSystemVersionIsOK:maximumOperatingSystemVersionIsOK]; +} + +@end diff --git a/Sparkle/SPUAutomaticUpdateDriver.m b/Sparkle/SPUAutomaticUpdateDriver.m index 90240adb..e501462d 100644 --- a/Sparkle/SPUAutomaticUpdateDriver.m +++ b/Sparkle/SPUAutomaticUpdateDriver.m @@ -83,12 +83,12 @@ SULog(SULogLevelError, @"Error: resumeDownloadedUpdate:completion: called on SPUAutomaticUpdateDriver"); } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem { self.updateItem = updateItem; - if (updateItem.isInformationOnlyUpdate || preventsAutoupdate) { - [self.coreDriver deferInformationalUpdate:updateItem secondaryUpdate:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + if (updateItem.isInformationOnlyUpdate || updateItem.majorUpgrade) { + [self.coreDriver deferInformationalUpdate:updateItem secondaryUpdate:secondaryUpdateItem]; [self abortUpdate]; } else { [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:YES]; @@ -139,7 +139,8 @@ - (void)abortUpdateWithError:(NSError *)error { - BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.isCriticalUpdate || self.updateItem.isInformationOnlyUpdate); + BOOL showNextUpdateImmediately = (error == nil || error.code == SUInstallationAuthorizeLaterError) && (!self.willInstallSilently || self.updateItem.criticalUpdate || self.updateItem.isInformationOnlyUpdate); + [self.coreDriver abortUpdateAndShowNextUpdateImmediately:showNextUpdateImmediately error:error]; } diff --git a/Sparkle/SPUBasicUpdateDriver.h b/Sparkle/SPUBasicUpdateDriver.h index afe99e8d..8ae1b888 100644 --- a/Sparkle/SPUBasicUpdateDriver.h +++ b/Sparkle/SPUBasicUpdateDriver.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SPUBasicUpdateDriverDelegate -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain; +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem systemDomain:(NSNumber * _Nullable)systemDomain; - (void)basicDriverIsRequestingAbortUpdateWithError:(nullable NSError *)error; diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index c0b2459a..859e9eb7 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -18,6 +18,8 @@ #import "SPUProbeInstallStatus.h" #import "SPUInstallationInfo.h" #import "SPUResumableUpdate.h" +#import "SPUAppcastItemState.h" +#import "SUAppcastItem+Private.h" #include "AppKitPrevention.h" @@ -79,7 +81,7 @@ } } -- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem *)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain +- (void)notifyResumableUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain { if (updateItem == nil) { [self.delegate basicDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUResumeAppcastError userInfo:@{ NSLocalizedDescriptionKey: SULocalizedString(@"Failed to resume installing update.", nil) }]]; @@ -88,7 +90,7 @@ [self notifyFinishLoadingAppcast]; SUAppcastItem *nonNullUpdateItem = updateItem; - [self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:NO systemDomain:systemDomain]; + [self notifyFoundValidUpdateWithAppcastItem:nonNullUpdateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } } @@ -137,7 +139,7 @@ } } -- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain +- (void)notifyFoundValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain { if (!self.aborted) { [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification @@ -148,16 +150,16 @@ [self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem]; } - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate systemDomain:systemDomain]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem systemDomain:systemDomain]; } } -- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem { - [self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem preventsAutoupdate:preventsAutoupdate systemDomain:nil]; + [self notifyFoundValidUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryAppcastItem systemDomain:nil]; } -- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult passesMinOSVersion:(BOOL)passesMinOSVersion passesMaxOSVersion:(BOOL)passesMaxOSVersion +- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult { if (!self.aborted) { if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) { @@ -185,11 +187,11 @@ break; case NSOrderedAscending: // This means a new update doesn't match the OS requirements - if (!passesMinOSVersion) { + if (!latestAppcastItem.minimumOperatingSystemVersionIsOK) { localizedDescription = SULocalizedString(@"Your macOS version is too old", nil); recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too old to install it. At least macOS %3$@ is required.", nil), [self.host name], latestAppcastItem.versionString, latestAppcastItem.minimumSystemVersion]; - } else if (!passesMaxOSVersion) { + } else if (!latestAppcastItem.maximumOperatingSystemVersionIsOK) { localizedDescription = SULocalizedString(@"Your macOS version is too new", nil); recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@.", nil), [self.host name], latestAppcastItem.versionString, latestAppcastItem.maximumSystemVersion]; diff --git a/Sparkle/SPUCoreBasedUpdateDriver.h b/Sparkle/SPUCoreBasedUpdateDriver.h index 85805166..a341b55f 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.h +++ b/Sparkle/SPUCoreBasedUpdateDriver.h @@ -7,8 +7,8 @@ // #import -#import "SPUUserUpdateState.h" #import "SPUUpdateDriver.h" +#import "SPUUserUpdateState.h" NS_ASSUME_NONNULL_BEGIN @@ -17,7 +17,7 @@ NS_ASSUME_NONNULL_BEGIN @protocol SPUCoreBasedUpdateDriverDelegate -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem; - (void)installerDidFinishPreparationAndWillInstallImmediately:(BOOL)willInstallImmediately silently:(BOOL)willInstallSilently; @@ -63,7 +63,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)downloadUpdateFromAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem inBackground:(BOOL)background; -- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem * _Nullable)secondaryUpdateItem; - (void)extractDownloadedUpdate; diff --git a/Sparkle/SPUCoreBasedUpdateDriver.m b/Sparkle/SPUCoreBasedUpdateDriver.m index 551fd2c2..de3f1d2d 100644 --- a/Sparkle/SPUCoreBasedUpdateDriver.m +++ b/Sparkle/SPUCoreBasedUpdateDriver.m @@ -32,7 +32,7 @@ @property (nonatomic, readonly) SPUInstallerDriver *installerDriver; @property (nonatomic, weak, readonly) id delegate; @property (nonatomic) SUAppcastItem *updateItem; -@property (nonatomic) SUAppcastItem *secondaryUpdateItem; +@property (nonatomic, nullable) SUAppcastItem *secondaryUpdateItem; @property (nonatomic) id resumableUpdate; @property (nonatomic) SPUDownloadedUpdate *downloadedUpdateForRemoval; @@ -149,7 +149,7 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate systemDomain:(NSNumber * _Nullable)systemDomain +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem systemDomain:(NSNumber * _Nullable)systemDomain { self.updateItem = updateItem; self.secondaryUpdateItem = secondaryUpdateItem; @@ -157,18 +157,18 @@ if (self.resumingInstallingUpdate) { assert(systemDomain != nil); [self.installerDriver resumeInstallingUpdateWithUpdateItem:updateItem systemDomain:systemDomain.boolValue]; - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } else { if (!self.preventsInstallerInteraction) { // Simple case - delegate allows interaction, so we should continue along - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } else { // Package type installations will always require installer interaction as long as we don't support running as root // If it's not a package type installation, we should be okay since we did an auth check before checking for updates above if (![updateItem.installationType isEqualToString:SPUInstallationTypeApplication]) { [self.delegate coreDriverIsRequestingAbortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNotAllowedInteractionError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"A new update is available but cannot be installed because interaction has been prevented."] }]]; } else { - [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } } } @@ -225,9 +225,9 @@ [self extractUpdate:downloadedUpdate]; } -- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)deferInformationalUpdate:(SUAppcastItem *)updateItem secondaryUpdate:(SUAppcastItem * _Nullable)secondaryUpdateItem { - self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem preventsAutoupdate:preventsAutoupdate]; + self.resumableUpdate = [[SPUInformationalUpdate alloc] initWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem]; } - (void)extractDownloadedUpdate diff --git a/Sparkle/SPUDownloadDriver.m b/Sparkle/SPUDownloadDriver.m index 46c449a2..b34bdc32 100644 --- a/Sparkle/SPUDownloadDriver.m +++ b/Sparkle/SPUDownloadDriver.m @@ -28,7 +28,7 @@ @property (nonatomic) id downloader; @property (nonatomic) NSXPCConnection *connection; @property (nonatomic, readonly) SUAppcastItem *updateItem; -@property (nonatomic, readonly) SUAppcastItem *secondaryUpdateItem; +@property (nonatomic, readonly, nullable) SUAppcastItem *secondaryUpdateItem; @property (nonatomic, readonly) SUHost *host; @property (nonatomic, copy) NSString *temporaryDirectory; @property (nonatomic, copy) NSString *downloadName; diff --git a/Sparkle/SPUDownloadedUpdate.m b/Sparkle/SPUDownloadedUpdate.m index f3d7b520..5107da89 100644 --- a/Sparkle/SPUDownloadedUpdate.m +++ b/Sparkle/SPUDownloadedUpdate.m @@ -33,9 +33,4 @@ return self; } -- (BOOL)preventsAutoupdate -{ - return NO; -} - @end diff --git a/Sparkle/SPUInformationalUpdate.h b/Sparkle/SPUInformationalUpdate.h index 0d54f99d..94998a27 100644 --- a/Sparkle/SPUInformationalUpdate.h +++ b/Sparkle/SPUInformationalUpdate.h @@ -13,7 +13,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUInformationalUpdate : NSObject -- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem; @end diff --git a/Sparkle/SPUInformationalUpdate.m b/Sparkle/SPUInformationalUpdate.m index e9eec62f..3f40a370 100644 --- a/Sparkle/SPUInformationalUpdate.m +++ b/Sparkle/SPUInformationalUpdate.m @@ -17,15 +17,13 @@ // because the property is declared in a protocol @synthesize updateItem = _updateItem; @synthesize secondaryUpdateItem = _secondaryUpdateItem; -@synthesize preventsAutoupdate = _preventsAutoupdate; -- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (instancetype)initWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem { self = [super init]; if (self != nil) { _updateItem = updateItem; _secondaryUpdateItem = secondaryUpdateItem; - _preventsAutoupdate = preventsAutoupdate; } return self; } diff --git a/Sparkle/SPUProbingUpdateDriver.m b/Sparkle/SPUProbingUpdateDriver.m index 71257a36..299e0958 100644 --- a/Sparkle/SPUProbingUpdateDriver.m +++ b/Sparkle/SPUProbingUpdateDriver.m @@ -54,7 +54,7 @@ [self.basicDriver resumeUpdate:resumableUpdate completion:completionBlock]; } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem secondaryAppcastItem:(SUAppcastItem *)__unused secondaryAppcastItem preventsAutoupdate:(BOOL)__unused preventsAutoupdate systemDomain:(NSNumber * _Nullable)__unused systemDomain +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)__unused appcastItem secondaryAppcastItem:(SUAppcastItem * _Nullable)__unused secondaryAppcastItem systemDomain:(NSNumber * _Nullable)__unused systemDomain { // Stop as soon as we have an answer [self abortUpdate]; diff --git a/Sparkle/SPUResumableUpdate.h b/Sparkle/SPUResumableUpdate.h index 895a80c8..1b138587 100644 --- a/Sparkle/SPUResumableUpdate.h +++ b/Sparkle/SPUResumableUpdate.h @@ -16,7 +16,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) SUAppcastItem *updateItem; @property (nonatomic, readonly, nullable) SUAppcastItem *secondaryUpdateItem; -@property (nonatomic, readonly) BOOL preventsAutoupdate; @end diff --git a/Sparkle/SPUSkippedUpdate.h b/Sparkle/SPUSkippedUpdate.h index 40259373..ebf44aad 100644 --- a/Sparkle/SPUSkippedUpdate.h +++ b/Sparkle/SPUSkippedUpdate.h @@ -24,7 +24,7 @@ NS_ASSUME_NONNULL_BEGIN + (void)clearSkippedUpdateForHost:(SUHost *)host; -+ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade; ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host; // At least one of minorVersion or majorVersion should be non-nil - (instancetype)initWithMinorVersion:(nullable NSString *)minorVersion majorVersion:(nullable NSString *)majorVersion; diff --git a/Sparkle/SPUSkippedUpdate.m b/Sparkle/SPUSkippedUpdate.m index e8791413..c3d61bed 100644 --- a/Sparkle/SPUSkippedUpdate.m +++ b/Sparkle/SPUSkippedUpdate.m @@ -49,9 +49,9 @@ [host setObject:nil forUserDefaultsKey:SUSkippedMajorVersionKey]; } -+ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host majorUpgrade:(BOOL)majorUpgrade ++ (void)skipUpdate:(SUAppcastItem *)updateItem host:(SUHost *)host { - if (majorUpgrade) { + if (updateItem.majorUpgrade) { NSString *majorVersion = updateItem.minimumAutoupdateVersion; assert(majorVersion != nil); diff --git a/Sparkle/SPUStandardUpdaterController.m b/Sparkle/SPUStandardUpdaterController.m index 4238c167..6537b599 100644 --- a/Sparkle/SPUStandardUpdaterController.m +++ b/Sparkle/SPUStandardUpdaterController.m @@ -14,6 +14,7 @@ #import "SPUStandardUserDriver.h" #import "SUConstants.h" #import "SULog.h" +#import "SULocalizations.h" #import static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; @@ -89,9 +90,8 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // Delay the alert four seconds so it doesn't show RIGHT as the app launches, but also doesn't interrupt the user once they really get to work. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ NSAlert *alert = [[NSAlert alloc] init]; - alert.messageText = @"Unable to Check For Updates"; - alert.informativeText = @"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version."; - [alert addButtonWithTitle:@"OK"]; + alert.messageText = SULocalizedString(@"Unable to Check For Updates", nil); + alert.informativeText = SULocalizedString(@"The update checker failed to start correctly. You should contact the app developer to report this issue and verify that you have the latest version.", nil); [alert runModal]; }); } diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index d4ccb24f..3275958a 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -19,6 +19,7 @@ #import "SULocalizations.h" #import "SUApplicationInfo.h" #import "SUOperatingSystem.h" +#import "SPUUserUpdateState.h" #import diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index dc2ce766..7f6ad5fd 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -157,7 +157,7 @@ { // Informational downloads shouldn't be presented as updates to be downloaded // Neither should items that prevent auto updating - if (!resumableUpdate.updateItem.isInformationOnlyUpdate && !resumableUpdate.preventsAutoupdate) { + if (!resumableUpdate.updateItem.isInformationOnlyUpdate && !resumableUpdate.updateItem.majorUpgrade) { self.resumingDownloadedUpdate = YES; } [self.coreDriver resumeUpdate:resumableUpdate completion:completionBlock]; @@ -170,7 +170,7 @@ } } -- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem *)secondaryUpdateItem preventsAutoupdate:(BOOL)preventsAutoupdate +- (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryUpdateItem { if (self.userInitiated) { [SPUSkippedUpdate clearSkippedUpdateForHost:self.host]; @@ -179,9 +179,7 @@ id updaterDelegate = self.updaterDelegate; SPUUserUpdateStage stage; - if (updateItem.isInformationOnlyUpdate) { - stage = SPUUserUpdateStageInformational; - } else if (self.resumingDownloadedUpdate) { + if (self.resumingDownloadedUpdate) { stage = SPUUserUpdateStageDownloaded; } else if (self.resumingInstallingUpdate) { stage = SPUUserUpdateStageInstalling; @@ -189,16 +187,14 @@ stage = SPUUserUpdateStageNotDownloaded; } - BOOL majorUpgrade = preventsAutoupdate; - - SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated majorUpgrade:majorUpgrade]; + SPUUserUpdateState *state = [[SPUUserUpdateState alloc] initWithStage:stage userInitiated:self.userInitiated]; [self.userDriver showUpdateFoundWithAppcastItem:updateItem state:state reply:^(SPUUserUpdateChoice userChoice) { dispatch_async(dispatch_get_main_queue(), ^{ // Rule out invalid choices SPUUserUpdateChoice validatedChoice; - if (stage == SPUUserUpdateStageInformational && userChoice == SPUUserUpdateChoiceInstall) { + if (updateItem.isInformationOnlyUpdate && userChoice == SPUUserUpdateChoiceInstall) { validatedChoice = SPUUserUpdateChoiceDismiss; } else { validatedChoice = userChoice; @@ -216,14 +212,11 @@ case SPUUserUpdateStageNotDownloaded: [self.coreDriver downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:NO]; break; - case SPUUserUpdateStageInformational: - assert(false); - break; } break; } case SPUUserUpdateChoiceSkip: { - [SPUSkippedUpdate skipUpdate:updateItem host:self.host majorUpgrade:majorUpgrade]; + [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; @@ -232,7 +225,6 @@ switch (stage) { case SPUUserUpdateStageDownloaded: case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageInformational: // Informational updates can be resumed too, so make sure we check // self.resumingDownloadedUpdate instead of the stage we pass to user driver if (self.resumingDownloadedUpdate) { @@ -252,8 +244,7 @@ case SPUUserUpdateChoiceDismiss: { switch (stage) { case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageInformational: { + case SPUUserUpdateStageNotDownloaded: { [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; break; } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index a15299a6..c8086eb5 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -60,29 +60,30 @@ SU_EXPORT @protocol SPUUserDriver * * @param appcastItem The Appcast Item containing information that reflects the new update. * - * @param state The current state of the update. + * @param state The current state of the user update. * The state.stage values are: - * SPUUserUpdateStateNotDownloaded - Update has not been downloaded yet. - * SPUUserUpdateStateDownloaded - Update has already been downloaded but not started installing yet. - * SPUUserUpdateStateInstalling - Update has been downloaded and already started installing. - * SPUUserUpdateStateInformational - Update is only informational and has no download. You can direct the user to the infoURL property of the appcastItem in their web browser. Use this to check if an update is informational, instead of using the informationOnlyUpdate property of the appcast item. + * SPUUpdateStateNotDownloaded - Update has not been downloaded yet. + * SPUUpdateStateDownloaded - Update has already been downloaded but not started installing yet. + * SPUUpdateStateInstalling - Update has been downloaded and already started installing. * * state.userInitiated indicates if the update was initiated by the user or if it was automatically scheduled in the background. - * state.majorUpgrade indicates if the update is a major or paid upgrade. * - * Additionally, you may want to check the criticalUpdate property of the appcastItem to let the user know if the update is critical. + * Additionally, these properties on the appcastItem are of importance: + * appcastItem.informationOnlyUpdate indicates if the update is only informational and should not be downloaded. You can direct the user to the infoURL property of the appcastItem in their web browser. Sometimes information only updates are used as a fallback in case a bad update is shipped, so you'll want to support this case. + * appcastItem.majorUpgrade indicates if the update is a major or paid upgrade. + * appcastItem.criticalUpdate indicates if the update is a critical update. * * @param reply * A reply of SPUUserUpdateChoiceInstall begins or resumes downloading or installing the update. - * If the state.stage is SPUUserUpdateStateInstalling, this may send a quit event to the application and relaunch it immediately (in this state, this behaves as a fast "install and Relaunch"). + * If the state.stage is SPUUserUpdateStateInstalling, this may send a quit event to the application and relaunch it immediately (in this state, this behaves as a fast "install and Relaunch"). Do not use this reply if appcastItem.informationOnlyUpdate is YES. * * A reply of SPUUserUpdateChoiceDismiss dismisses the update for the time being. The user may be reminded of the update at a later point. * If the state.stage is SPUUserUpdateStateDownloaded, the downloaded update is kept after dismissing until the next time an update is shown to the user. * If the state.stage is SPUUserUpdateStateInstalling, the installing update is also preserved after dismissing. In this state however, the update will also still be installed after the application is terminated. * * A reply of SPUUserUpdateChoiceSkip skips this particular version and won't notify the user again, unless they initiate an update check themselves. - * If state.majorUpgrade is YES, the major update and any minor updates to that major release are skipped. - * If the state.stage is SPUUserUpdateStateInstalling, the installation is also canceled when the update is skipped. + * If appcastItem.majorUpgrade is YES, the major update and any future minor updates to that major release are skipped. + * If the state.stage is SPUUpdateStateInstalling, the installation is also canceled when the update is skipped. */ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply; diff --git a/Sparkle/SPUUserUpdateState+Private.h b/Sparkle/SPUUserUpdateState+Private.h index 90e732c4..578fc98d 100644 --- a/Sparkle/SPUUserUpdateState+Private.h +++ b/Sparkle/SPUUserUpdateState+Private.h @@ -9,11 +9,13 @@ #ifndef SPUUserUpdateState_Private_h #define SPUUserUpdateState_Private_h +#import "SPUUserUpdateState.h" + NS_ASSUME_NONNULL_BEGIN @interface SPUUserUpdateState (Private) -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade; +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated; @end diff --git a/Sparkle/SPUUserUpdateState.h b/Sparkle/SPUUserUpdateState.h index 6b1dec52..ec13c621 100644 --- a/Sparkle/SPUUserUpdateState.h +++ b/Sparkle/SPUUserUpdateState.h @@ -31,15 +31,15 @@ typedef NS_ENUM(NSInteger, SPUUserUpdateChoice) { typedef NS_ENUM(NSInteger, SPUUserUpdateStage) { SPUUserUpdateStageNotDownloaded, SPUUserUpdateStageDownloaded, - SPUUserUpdateStageInstalling, - SPUUserUpdateStageInformational + SPUUserUpdateStageInstalling }; SU_EXPORT @interface SPUUserUpdateState : NSObject +- (instancetype)init NS_UNAVAILABLE; + @property (nonatomic, readonly) SPUUserUpdateStage stage; @property (nonatomic, readonly) BOOL userInitiated; -@property (nonatomic, readonly) BOOL majorUpgrade; @end diff --git a/Sparkle/SPUUserUpdateState.m b/Sparkle/SPUUserUpdateState.m index 935f6766..32654807 100644 --- a/Sparkle/SPUUserUpdateState.m +++ b/Sparkle/SPUUserUpdateState.m @@ -15,20 +15,22 @@ #define SPUUserUpdateStateStageKey @"SPUUserUpdateStateStage" #define SPUUserUpdateStateUserInitiatedKey @"SPUUserUpdateStateUserInitiated" #define SPUUserUpdateStateMajorUpgradeKey @"SPUUserUpdateStateMajorUpgrade" +#define SPUUserUpdateStateCriticalUpdateKey @"SPUUserUpdateStateCriticalUpdate" + +@interface SPUUserUpdateState () +@end @implementation SPUUserUpdateState @synthesize stage = _stage; @synthesize userInitiated = _userInitiated; -@synthesize majorUpgrade = _majorUpgrade; -- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated majorUpgrade:(BOOL)majorUpgrade +- (instancetype)initWithStage:(SPUUserUpdateStage)stage userInitiated:(BOOL)userInitiated { self = [super init]; if (self != nil) { _stage = stage; _userInitiated = userInitiated; - _majorUpgrade = majorUpgrade; } return self; } @@ -37,16 +39,14 @@ { [encoder encodeInteger:self.stage forKey:SPUUserUpdateStateStageKey]; [encoder encodeBool:self.userInitiated forKey:SPUUserUpdateStateUserInitiatedKey]; - [encoder encodeBool:self.majorUpgrade forKey:SPUUserUpdateStateMajorUpgradeKey]; } - (instancetype)initWithCoder:(NSCoder *)decoder { SPUUserUpdateStage stage = [decoder decodeIntegerForKey:SPUUserUpdateStateStageKey]; BOOL userInitiated = [decoder decodeBoolForKey:SPUUserUpdateStateUserInitiatedKey]; - BOOL majorUpgrade = [decoder decodeBoolForKey:SPUUserUpdateStateMajorUpgradeKey]; - return [self initWithStage:stage userInitiated:userInitiated majorUpgrade:majorUpgrade]; + return [self initWithStage:stage userInitiated:userInitiated]; } + (BOOL)supportsSecureCoding diff --git a/Sparkle/SUAppcast+Private.h b/Sparkle/SUAppcast+Private.h index c3fea632..30a22e71 100644 --- a/Sparkle/SUAppcast+Private.h +++ b/Sparkle/SUAppcast+Private.h @@ -6,8 +6,6 @@ // Copyright © 2021 Sparkle Project. All rights reserved. // -NS_ASSUME_NONNULL_BEGIN - #if __has_feature(modules) #if __has_warning("-Watimport-in-framework-header") #pragma clang diagnostic ignored "-Watimport-in-framework-header" @@ -17,9 +15,13 @@ NS_ASSUME_NONNULL_BEGIN #import #endif +NS_ASSUME_NONNULL_BEGIN + +@class SPUAppcastItemStateResolver; + @interface SUAppcast (Private) -- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL error:(NSError * __autoreleasing *)error; +- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver error:(NSError * __autoreleasing *)error; - (SUAppcast *)copyByFilteringItems:(BOOL (^)(SUAppcastItem *))filterBlock; diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 9f5de4ba..c3d927cc 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -9,7 +9,9 @@ #import "SUExport.h" #import "SUAppcast.h" #import "SUAppcast+Private.h" +#import "SPUAppcastItemState.h" #import "SUAppcastItem.h" +#import "SUAppcastItem+Private.h" #import "SUVersionComparisonProtocol.h" #import "SUConstants.h" #import "SULog.h" @@ -29,11 +31,11 @@ @synthesize items = _items; -- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL error:(NSError * __autoreleasing *)error +- (nullable instancetype)initWithXMLData:(NSData *)xmlData relativeToURL:(NSURL * _Nullable)relativeURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver error:(NSError * __autoreleasing *)error { self = [super init]; if (self != nil) { - _items = [self parseAppcastItemsFromXMLData:xmlData relativeToURL:relativeURL error:error]; + _items = [self parseAppcastItemsFromXMLData:xmlData relativeToURL:relativeURL stateResolver:stateResolver error:error]; if (_items == nil) { return nil; } @@ -71,7 +73,7 @@ } } --(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData relativeToURL:(NSURL * _Nullable)appcastURL error:(NSError *__autoreleasing*)errorp { +-(NSArray *)parseAppcastItemsFromXMLData:(NSData *)appcastData relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver error:(NSError *__autoreleasing*)errorp { if (errorp) { *errorp = nil; } @@ -118,10 +120,10 @@ for (NSString *name in nodesDict) { node = [self bestNodeInNodes:[nodesDict objectForKey:name]]; - if ([name isEqualToString:SURSSElementEnclosure]) { - // enclosure is flattened as a separate dictionary for some reason - NSDictionary *encDict = [self attributesOfNode:(NSXMLElement *)node]; - [dict setObject:encDict forKey:name]; + if ([name isEqualToString:SURSSElementEnclosure] || [name isEqualToString:SUAppcastElementCriticalUpdate]) { + // These are flattened as a separate dictionary for some reason + NSDictionary *innerDict = [self attributesOfNode:(NSXMLElement *)node]; + [dict setObject:innerDict forKey:name]; } else if ([name isEqualToString:SURSSElementPubDate]) { // We don't want to parse and create a NSDate instance - @@ -152,6 +154,19 @@ } } [dict setObject:tags forKey:name]; + } + else if ([name isEqualToString:SUAppcastElementInformationalUpdate]) { + NSMutableSet *informationalUpdateVersions = [NSMutableSet set]; + NSEnumerator *childEnum = [[node children] objectEnumerator]; + for (NSXMLNode *child in childEnum) { + if ([child.name isEqualToString:SUAppcastAttributeVersion]) { + NSString *version = child.stringValue; + if (version != nil) { + [informationalUpdateVersions addObject:version]; + } + } + } + [dict setObject:[informationalUpdateVersions copy] forKey:name]; } else if (name != nil) { // add all other values as strings @@ -163,7 +178,8 @@ } NSString *errString; - SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict relativeToURL:appcastURL failureReason:&errString]; + SUAppcastItem *anItem = [[SUAppcastItem alloc] initWithDictionary:dict relativeToURL:appcastURL stateResolver:stateResolver failureReason:&errString]; + if (anItem) { [appcastItems addObject:anItem]; } diff --git a/Sparkle/SUAppcastDriver.h b/Sparkle/SUAppcastDriver.h index cc142d72..4aebb9c5 100644 --- a/Sparkle/SUAppcastDriver.h +++ b/Sparkle/SUAppcastDriver.h @@ -17,8 +17,8 @@ NS_ASSUME_NONNULL_BEGIN - (void)didFailToFetchAppcastWithError:(NSError *)error; - (void)didFinishLoadingAppcast:(SUAppcast *)appcast; -- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem *)secondaryAppcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; -- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult passesMinOSVersion:(BOOL)passesMinOSVersion passesMaxOSVersion:(BOOL)passesMaxOSVersion; +- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem secondaryAppcastItem:(SUAppcastItem * _Nullable)secondaryAppcastItem; +- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult; @end diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index 61358cc0..82834df5 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -10,6 +10,7 @@ #import "SUAppcast.h" #import "SUAppcast+Private.h" #import "SUAppcastItem.h" +#import "SUAppcastItem+Private.h" #import "SUVersionComparisonProtocol.h" #import "SUStandardVersionComparator.h" #import "SUOperatingSystem.h" @@ -23,6 +24,9 @@ #import "SPUDownloadData.h" #import "SULocalizations.h" #import "SUErrors.h" +#import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemStateResolver+Private.h" +#import "SPUAppcastItemState.h" #include "AppKitPrevention.h" @@ -30,7 +34,7 @@ @interface SUAppcastDriver () @property (nonatomic, readonly) SUHost *host; -@property (nullable, nonatomic, readonly, weak) id updater; +@property (nonatomic, readonly, weak) id updater; @property (nullable, nonatomic, readonly, weak) id updaterDelegate; @property (nullable, nonatomic, readonly, weak) id delegate; @property (nonatomic) SPUDownloadDriver *downloadDriver; @@ -72,8 +76,10 @@ - (void)downloadDriverDidDownloadData:(SPUDownloadData *)downloadData { + SPUAppcastItemStateResolver *stateResolver = [[SPUAppcastItemStateResolver alloc] initWithHostVersion:self.host.version applicationVersionComparator:[self versionComparator] standardVersionComparator:[SUStandardVersionComparator defaultComparator]]; + NSError *appcastError = nil; - SUAppcast *appcast = [[SUAppcast alloc] initWithXMLData:downloadData.data relativeToURL:downloadData.URL error:&appcastError]; + SUAppcast *appcast = [[SUAppcast alloc] initWithXMLData:downloadData.data relativeToURL:downloadData.URL stateResolver:stateResolver error:&appcastError]; if (appcast == nil) { NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while parsing the update feed.", nil) forKey:NSLocalizedDescriptionKey]; @@ -195,51 +201,39 @@ if ([self isItemNewer:finalPrimaryItem]) { // We found a suitable update - BOOL preventsAutoupdate = ![[self class] isItemMinimumAutoupdateVersionOK:finalPrimaryItem.minimumAutoupdateVersion hostVersion:self.host.version versionComparator:applicationVersionComparator]; - - [self.delegate didFindValidUpdateWithAppcastItem:finalPrimaryItem secondaryAppcastItem:finalSecondaryItem preventsAutoupdate:preventsAutoupdate]; + [self.delegate didFindValidUpdateWithAppcastItem:finalPrimaryItem secondaryAppcastItem:finalSecondaryItem]; } else { // Find the latest appcast item even if it fails min/max OS test // We want to inform the user if an update requires a different OS version // We only need to do this if an update is being checked by the user manually SUAppcastItem *notFoundPrimaryItem; NSComparisonResult hostToLatestAppcastItemComparisonResult; - BOOL passesMinOSVersion; - BOOL passesMaxOSVersion; if (!background) { notFoundPrimaryItem = [self retrieveBestAppcastItemFromAppcast:macOSAppcast versionComparator:applicationVersionComparator secondaryUpdate:nil]; hostToLatestAppcastItemComparisonResult = [applicationVersionComparator compareVersion:self.host.version toVersion:notFoundPrimaryItem.versionString]; - - SUStandardVersionComparator *standardVersionComparator = [[SUStandardVersionComparator alloc] init]; - - passesMinOSVersion = [[self class] isItemMinimumOperatingSystemVersionOK:notFoundPrimaryItem versionComparator:standardVersionComparator]; - - passesMaxOSVersion = [[self class] isItemMaximumOperatingSystemVersionOK:notFoundPrimaryItem versionComparator:standardVersionComparator]; } else { notFoundPrimaryItem = nil; hostToLatestAppcastItemComparisonResult = 0; - passesMinOSVersion = YES; - passesMaxOSVersion = YES; } - [self.delegate didNotFindUpdateWithLatestAppcastItem:notFoundPrimaryItem hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult passesMinOSVersion:passesMinOSVersion passesMaxOSVersion:passesMaxOSVersion]; + [self.delegate didNotFindUpdateWithLatestAppcastItem:notFoundPrimaryItem hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult]; } } // This method is used by unit tests -+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion { NSDate *currentDate = [NSDate date]; - BOOL hostPassesSkippedMajorVersion = [self isItemMinimumAutoupdateVersionOK:skippedUpdate.majorVersion hostVersion:hostVersion versionComparator:versionComparator]; + BOOL hostPassesSkippedMajorVersion = [SPUAppcastItemStateResolver isMinimumAutoupdateVersionOK:skippedUpdate.majorVersion hostVersion:hostVersion versionComparator:versionComparator]; return [appcast copyByFilteringItems:^(SUAppcastItem *item) { - BOOL passesOSVersion = (!testOSVersion || [self isItemMinimumAndMaximumOperatingSystemVersionOK:item]); + BOOL passesOSVersion = (!testOSVersion || (item.minimumOperatingSystemVersionIsOK && item.maximumOperatingSystemVersionIsOK)); - BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate]; + BOOL passesPhasedRollout = [self itemIsReadyForPhasedRollout:item phasedUpdateGroup:phasedUpdateGroup currentDate:currentDate hostVersion:hostVersion versionComparator:versionComparator]; - BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || hostVersion == nil || versionComparator == nil || [self isItemMinimumAutoupdateVersionOK:item.minimumAutoupdateVersion hostVersion:hostVersion versionComparator:versionComparator]); + BOOL passesMinimumAutoupdateVersion = (!testMinimumAutoupdateVersion || !item.majorUpgrade); BOOL passesSkippedUpdates = (versionComparator == nil || hostVersion == nil || ![self item:item containsSkippedUpdate:skippedUpdate hostPassesSkippedMajorVersion:hostPassesSkippedMajorVersion versionComparator:versionComparator]); @@ -275,51 +269,18 @@ return item; } -+ (BOOL)isItemMinimumOperatingSystemVersionOK:(SUAppcastItem *)ui versionComparator:(SUStandardVersionComparator *)versionComparator -{ - BOOL minimumVersionOK = YES; - NSString *minimumSystemVersion = ui.minimumSystemVersion; - if (minimumSystemVersion != nil && ![minimumSystemVersion isEqualToString:@""]) { - minimumVersionOK = [versionComparator compareVersion:minimumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedDescending; - } - return minimumVersionOK; -} - -// We don't want to use delegate's comparator for comparing OS versions -+ (BOOL)isItemMaximumOperatingSystemVersionOK:(SUAppcastItem *)ui versionComparator:(SUStandardVersionComparator *)versionComparator -{ - BOOL maximumVersionOK = YES; - NSString *maximumSystemVersion = ui.maximumSystemVersion; - if (maximumSystemVersion != nil && ![maximumSystemVersion isEqualToString:@""]) { - maximumVersionOK = [versionComparator compareVersion:maximumSystemVersion toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending; - } - return maximumVersionOK; -} - -+ (BOOL)isItemMinimumAndMaximumOperatingSystemVersionOK:(SUAppcastItem *)ui -{ - SUStandardVersionComparator *versionComparator = [[SUStandardVersionComparator alloc] init]; - - return [self isItemMinimumOperatingSystemVersionOK:ui versionComparator:versionComparator] && [self isItemMaximumOperatingSystemVersionOK:ui versionComparator:versionComparator]; -} - -+ (BOOL)isItemMinimumAutoupdateVersionOK:(NSString * _Nullable)minimumAutoupdateVersion hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator - { - return (minimumAutoupdateVersion.length == 0 || ([versionComparator compareVersion:hostVersion toVersion:(NSString * _Nonnull)minimumAutoupdateVersion] != NSOrderedAscending)); - } - - (id)versionComparator { id comparator = nil; // Give the delegate a chance to provide a custom version comparator if ([self.updaterDelegate respondsToSelector:@selector((versionComparatorForUpdater:))]) { - comparator = [self.updaterDelegate versionComparatorForUpdater:(id _Nonnull)self.updater]; + comparator = [self.updaterDelegate versionComparatorForUpdater:self.updater]; } // If we don't get a comparator from the delegate, use the default comparator - if (!comparator) { - comparator = [[SUStandardVersionComparator alloc] init]; + if (comparator == nil) { + comparator = [SUStandardVersionComparator defaultComparator]; } return comparator; @@ -351,9 +312,9 @@ return NO; } -+ (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate ++ (BOOL)itemIsReadyForPhasedRollout:(SUAppcastItem *)ui phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup currentDate:(NSDate *)currentDate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator { - if (phasedUpdateGroup == nil || [ui isCriticalUpdate]) { + if (phasedUpdateGroup == nil || ui.criticalUpdate) { return YES; } diff --git a/Sparkle/SUAppcastItem+Private.h b/Sparkle/SUAppcastItem+Private.h new file mode 100644 index 00000000..c7db2590 --- /dev/null +++ b/Sparkle/SUAppcastItem+Private.h @@ -0,0 +1,40 @@ +// +// SUAppcastItem+Private.h +// Sparkle +// +// Created by Mayur Pawashe on 4/30/21. +// Copyright © 2021 Sparkle Project. All rights reserved. +// + +#ifndef SUAppcastItem_Private_h +#define SUAppcastItem_Private_h + +#if __has_feature(modules) +#if __has_warning("-Watimport-in-framework-header") +#pragma clang diagnostic ignored "-Watimport-in-framework-header" +#endif +@import Foundation; +#else +#import +#endif + +NS_ASSUME_NONNULL_BEGIN + +// Available in SPUAppcastItemStateResolver.h (a private exposed header) +@class SPUAppcastItemStateResolver; + +@interface SUAppcastItem (Private) + +/*! + Initializes with data from a dictionary provided by the RSS class and state resolver + + This initializer method is intended to be marked "private" and discouraged from public usage. + This method is available however. Talk to us to describe your use case and if you need to construct appcast items yourself. + */ +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; + +@end + +NS_ASSUME_NONNULL_END + +#endif /* SUAppcastItem_Private_h */ diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index b1fce84d..4d3efba1 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -29,6 +29,7 @@ #endif @class SUSignatures; +@class SPUAppcastItemState; NS_ASSUME_NONNULL_BEGIN @@ -54,16 +55,22 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; @property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate; +@property (getter=isMajorUpgrade, readonly) BOOL majorUpgrade; @property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; +@property (nonatomic, readonly) BOOL minimumOperatingSystemVersionIsOK; +@property (nonatomic, readonly) BOOL maximumOperatingSystemVersionIsOK; + // Returns the dictionary representing the appcast item; this might be useful later for extensions. @property (readonly, copy) NSDictionary *propertiesDictionary; -// Initializes with data from a dictionary provided by the RSS class. -- (instancetype)initWithDictionary:(NSDictionary *)dict; -- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; -- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error; +- (instancetype)init NS_UNAVAILABLE; + +// Deprecated initializers +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case."); +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString * _Nullable __autoreleasing *_Nullable)error __deprecated_msg("Properties that depend on the system or application version are not supported when used with this initializer. The designated initializer is available in SUAppcastItem+Private.h. Please first explore other APIs or contact us to describe your use case."); @end diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 519ff1c7..b7aaee47 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -12,6 +12,9 @@ #import "SUConstants.h" #import "SUSignatures.h" #import "SPUInstallationType.h" +#import "SPUAppcastItemState.h" +#import "SPUAppcastItemStateResolver.h" +#import "SPUAppcastItemStateResolver+Private.h" #include "AppKitPrevention.h" @@ -30,6 +33,22 @@ static NSString *SUAppcastItemTitleKey = @"title"; static NSString *SUAppcastItemVersionStringKey = @"versionString"; static NSString *SUAppcastItemPropertiesKey = @"propertiesDictionary"; static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationType"; +static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; + +@interface SUAppcastItem () + +// Auxillary appcast item state that needs to be evaluated based on the host state +// This may be nil if the client creates an SUAppcastItem with a deprecated initializer +// In that case we will need to fallback to safe behavior +@property (nonatomic, readonly, nullable) SPUAppcastItemState *state; + +// Indicates if we have any critical information. Used as a fallback if state is nil +@property (nonatomic, readonly) BOOL hasCriticalInformation; + +// Indicates the versions we update from that are informational-only +@property (nonatomic, readonly, nullable) NSSet *informationalUpdateVersions; + +@end @implementation SUAppcastItem @@ -51,6 +70,9 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT @synthesize installationType = _installationType; @synthesize minimumAutoupdateVersion = _minimumAutoupdateVersion; @synthesize phasedRolloutInterval = _phasedRolloutInterval; +@synthesize state = _state; +@synthesize hasCriticalInformation = _hasCriticalInformation; +@synthesize informationalUpdateVersions = _informationalUpdateVersions; + (BOOL)supportsSecureCoding { @@ -79,6 +101,9 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT return nil; } + SPUAppcastItemState *state = [decoder decodeObjectOfClass:[SPUAppcastItemState class] forKey:SUAppcastItemStateKey]; + _state = state; + _installationType = [installationType copy]; _itemDescription = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionKey] copy]; @@ -150,6 +175,10 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT [encoder encodeObject:self.minimumAutoupdateVersion forKey:SUAppcastElementMinimumAutoupdateVersion]; } + if (self.state != nil) { + [encoder encodeObject:self.state forKey:SUAppcastItemStateKey]; + } + if (self.releaseNotesURL != nil) { [encoder encodeObject:self.releaseNotesURL forKey:SUAppcastItemReleaseNotesURLKey]; } @@ -187,7 +216,38 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT - (BOOL)isCriticalUpdate { - return [(NSArray *)[self.propertiesDictionary objectForKey:SUAppcastElementTags] containsObject:SUAppcastElementCriticalUpdate]; + if (self.state != nil) { + return self.state.criticalUpdate; + } else { + return self.hasCriticalInformation; + } +} + +- (BOOL)isMajorUpgrade +{ + if (self.state != nil) { + return self.state.majorUpgrade; + } else { + return NO; + } +} + +- (BOOL)minimumOperatingSystemVersionIsOK +{ + if (self.state != nil) { + return self.state.minimumOperatingSystemVersionIsOK; + } else { + return YES; + } +} + +- (BOOL)maximumOperatingSystemVersionIsOK +{ + if (self.state != nil) { + return self.state.maximumOperatingSystemVersionIsOK; + } else { + return YES; + } } - (BOOL)isMacOsUpdate @@ -211,20 +271,44 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT - (BOOL)isInformationOnlyUpdate { - return self.infoURL && !self.fileURL; + if (self.state != nil) { + return self.state.informationalUpdate; + } else { + return (self.informationalUpdateVersions != nil && self.informationalUpdateVersions.count == 0); + } } -- (instancetype)initWithDictionary:(NSDictionary *)dict +// Initializer used for making delta items +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL state:(SPUAppcastItemState * _Nullable)state { - return [self initWithDictionary:dict relativeToURL:nil failureReason:nil]; + return [self initWithDictionary:dict relativeToURL:nil stateResolver:nil resolvedState:state failureReason:nil]; } -- (instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString *__autoreleasing *)error +// Exported public initializer +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver *)stateResolver failureReason:(NSString *__autoreleasing *)error { - return [self initWithDictionary:dict relativeToURL:nil failureReason:error]; + return [self initWithDictionary:dict relativeToURL:appcastURL stateResolver:stateResolver resolvedState:nil failureReason:error]; } +// Deprecated +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict +{ + return [self initWithDictionary:dict relativeToURL:nil stateResolver:nil resolvedState:nil failureReason:nil]; +} + +// Deprecated +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict failureReason:(NSString *__autoreleasing *)error +{ + return [self initWithDictionary:dict relativeToURL:nil stateResolver:nil resolvedState:nil failureReason:error]; +} + +// Deprecated - (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL failureReason:(NSString *__autoreleasing *)error +{ + return [self initWithDictionary:dict relativeToURL:appcastURL stateResolver:nil resolvedState:nil failureReason:error]; +} + +- (nullable instancetype)initWithDictionary:(NSDictionary *)dict relativeToURL:(NSURL * _Nullable)appcastURL stateResolver:(SPUAppcastItemStateResolver * _Nullable)stateResolver resolvedState:(SPUAppcastItemState * _Nullable)resolvedState failureReason:(NSString *__autoreleasing *)error { self = [super init]; if (self) { @@ -287,6 +371,15 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT } return nil; } + + if (theInfoURL != nil) { + // If enclosure doesn't exist, the update must be an informational update + // Otherwise check presence of informational update element + _informationalUpdateVersions = (enclosure != nil) ? [dict objectForKey:SUAppcastElementInformationalUpdate] : [NSSet set]; + } else { + // Not an informational update + _informationalUpdateVersions = nil; + } NSString *enclosureURLString = [enclosure objectForKey:SURSSAttributeURL]; if (!enclosureURLString && !theInfoURL) { @@ -324,6 +417,30 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT _maximumSystemVersion = [(NSString *)[dict objectForKey:SUAppcastElementMaximumSystemVersion] copy]; _minimumAutoupdateVersion = [(NSString *)[dict objectForKey:SUAppcastElementMinimumAutoupdateVersion] copy]; + // Grab critical update information + NSDictionary * _Nullable criticalUpdateDictionaryFromAppcast = (NSDictionary *)[dict objectForKey:SUAppcastElementCriticalUpdate]; + NSArray *tags = [dict objectForKey:SUAppcastElementTags]; + + NSDictionary * _Nullable criticalUpdateDictionary; + if (criticalUpdateDictionaryFromAppcast != nil) { + criticalUpdateDictionary = criticalUpdateDictionaryFromAppcast; + } else if ([tags isKindOfClass:[NSArray class]] && [tags containsObject:SUAppcastElementCriticalUpdate]) { + // Legacy path where critical update used to be a tag without a specified version + criticalUpdateDictionary = @{}; + } else { + // No critical info present + criticalUpdateDictionary = nil; + } + + _hasCriticalInformation = (criticalUpdateDictionary != nil); + + if (stateResolver != nil) { + _state = [(SPUAppcastItemStateResolver * _Nonnull)stateResolver resolveStateWithInformationalUpdateVersions:_informationalUpdateVersions minimumOperatingSystemVersion:_minimumSystemVersion maximumOperatingSystemVersion:_maximumSystemVersion minimumAutoupdateVersion:_minimumAutoupdateVersion criticalUpdateDictionary:criticalUpdateDictionary]; + } else { + // Note state still may be nil if a deprecated initializer is used + _state = resolvedState; + } + NSString* rolloutIntervalString = [(NSString *)[dict objectForKey:SUAppcastElementPhasedRolloutInterval] copy]; if (rolloutIntervalString != nil) { _phasedRolloutInterval = @(rolloutIntervalString.integerValue); @@ -396,7 +513,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT NSMutableDictionary *fakeAppCastDict = [dict mutableCopy]; [fakeAppCastDict removeObjectForKey:SUAppcastElementDeltas]; [fakeAppCastDict setObject:deltaDictionary forKey:SURSSElementEnclosure]; - SUAppcastItem *deltaItem = [[SUAppcastItem alloc] initWithDictionary:fakeAppCastDict]; + SUAppcastItem *deltaItem = [[SUAppcastItem alloc] initWithDictionary:fakeAppCastDict relativeToURL:appcastURL state:_state]; if (deltaItem != nil) { [deltas setObject:deltaItem forKey:deltaFrom]; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 46327f0c..a1e65b66 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -85,6 +85,7 @@ extern NSString *const SUAppcastElementMaximumSystemVersion; extern NSString *const SUAppcastElementReleaseNotesLink; extern NSString *const SUAppcastElementTags; extern NSString *const SUAppcastElementPhasedRolloutInterval; +extern NSString *const SUAppcastElementInformationalUpdate; extern NSString *const SURSSAttributeURL; extern NSString *const SURSSAttributeLength; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 94a4fda4..0a60324e 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -79,6 +79,7 @@ NSString *const SUAppcastElementMaximumSystemVersion = @"sparkle:maximumSystemVe NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink"; NSString *const SUAppcastElementTags = @"sparkle:tags"; NSString *const SUAppcastElementPhasedRolloutInterval = @"sparkle:phasedRolloutInterval"; +NSString *const SUAppcastElementInformationalUpdate = @"sparkle:informationalUpdate"; NSString *const SURSSAttributeURL = @"url"; NSString *const SURSSAttributeLength = @"length"; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index c3da0893..518039bf 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -93,12 +93,12 @@ NS_ASSUME_NONNULL_BEGIN return [self isValidVersion:[self _version]]; } -- (BOOL)isValidVersion:(NSString *)version +- (BOOL)isValidVersion:(NSString * _Nullable)version { return (version != nil && version.length != 0); } -- (NSString *)_version +- (NSString * _Nullable)_version { NSString *version = [self objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; return ([self isValidVersion:version] ? version : nil); diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index ea74240b..965ca601 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -29,6 +29,7 @@ #import "SUTouchBarForwardDeclarations.h" #import "SUTouchBarButtonGroup.h" #import "SPUXPCServiceInfo.h" +#import "SPUUserUpdateState.h" static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDENTIFIER ".SUUpdateAlert"; @@ -94,7 +95,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE _completionBlock = [block copy]; SPUUpdaterSettings *updaterSettings = [[SPUUpdaterSettings alloc] initWithHostBundle:host.bundle]; - _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && updaterSettings.automaticallyChecksForUpdates && state.stage != SPUUserUpdateStageInformational; + _allowsAutomaticUpdates = updaterSettings.allowsAutomaticUpdates && updaterSettings.automaticallyChecksForUpdates && !item.informationOnlyUpdate; [self setShouldCascadeWindows:NO]; } return self; @@ -140,7 +141,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (IBAction)skipThisVersion:(id)__unused sender { - if (self.state.majorUpgrade) { + if (self.updateItem.majorUpgrade) { NSAlert *alert = [[NSAlert alloc] init]; alert.alertStyle = NSAlertStyleInformational; alert.informativeText = SULocalizedString(@"Skipping this major upgrade will opt out of alerts for future updates.", nil); @@ -340,7 +341,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE [self.window setLevel:NSFloatingWindowLevel]; // This means the window will float over all other apps, if our app is switched out ?! } - if (self.state.stage == SPUUserUpdateStageInformational) { + if (self.updateItem.informationOnlyUpdate) { [self.installButton setTitle:SULocalizedString(@"Learn More...", @"Alternate title for 'Install Update' button when there's no download in RSS feed.")]; [self.installButton setAction:@selector(openInfoURL:)]; } @@ -382,7 +383,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE self.laterButton.title = SULocalizedString(@"Install on Quit", @"Alternate title for 'Remind Me Later' button when downloaded updates can be resumed"); } - if ([self.updateItem isCriticalUpdate] && !self.state.majorUpgrade) { + if (self.updateItem.criticalUpdate && !self.updateItem.majorUpgrade) { self.skipButton.hidden = YES; self.laterButton.hidden = YES; } @@ -408,7 +409,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE - (NSString *)titleText { - if ([self.updateItem isCriticalUpdate]) + if (self.updateItem.criticalUpdate) { return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil), [self.host name]]; } @@ -437,9 +438,9 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE // We display a different summary depending on if it's an "info-only" item, or a "critical update" item, or if we've already downloaded the update and just need to relaunch NSString *finalString = nil; - if (self.state.stage == SPUUserUpdateStageInformational) { + if (self.updateItem.informationOnlyUpdate) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. Would you like to learn more about this update on the web?", @"Description text for SUUpdateAlert when the update informational with no download."), self.host.name, updateItemVersion, hostVersion]; - } else if ([self.updateItem isCriticalUpdate]) { + } else if (self.updateItem.criticalUpdate) { if (self.state.stage == SPUUserUpdateStageNotDownloaded) { finalString = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is now available--you have %@. This is an important update; would you like to download it now?", @"Description text for SUUpdateAlert when the critical update is downloadable."), self.host.name, updateItemVersion, hostVersion]; } else { diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index c8d8447f..abca9f52 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -136,22 +136,16 @@ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { - switch (state.stage) { - case SPUUserUpdateStageInformational: - // Todo: show user interface for this - NSLog(@"Found info URL: %@", appcastItem.infoURL); - - // Remove UI from user initiated check - [self removeUpdateButton]; - - reply(SPUUserUpdateChoiceDismiss); - - break; - case SPUUserUpdateStageNotDownloaded: - case SPUUserUpdateStageDownloaded: - case SPUUserUpdateStageInstalling: - [self showUpdateWithAppcastItem:appcastItem reply:reply]; - break; + if (appcastItem.informationOnlyUpdate) { + // Todo: show user interface for this + NSLog(@"Found info URL: %@", appcastItem.infoURL); + + // Remove UI from user initiated check + [self removeUpdateButton]; + + reply(SPUUserUpdateChoiceDismiss); + } else { + [self showUpdateWithAppcastItem:appcastItem reply:reply]; } } diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index d602ba7b..f78862d1 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -7,12 +7,14 @@ desc Sat, 26 Jul 2014 15:20:11 +0000 - + Version 3.0 86400 + + + + + For unit test only + + + Version 2.0 + desc + Sat, 26 Jul 2014 15:20:11 +0000 + + + + + Version 3.0 + + + 2.5 + 2.4 + + http://sparkle-project.org + + + + Version 4.0 + Sat, 26 Jul 2014 15:20:13 +0000 + + + http://sparkle-project.org + + + + + + + + + Version 5.0 + 5.0 + http://sparkle-project.org + + + diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index dfc8110a..d3c25fd9 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -17,7 +17,11 @@ class SUAppcastTest: XCTestCase { do { let testData = try Data(contentsOf: testURL) - let appcast = try SUAppcast(xmlData: testData, relativeTo: nil) + let versionComparator = SUStandardVersionComparator.default() + let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual(4, items.count) @@ -31,7 +35,7 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual("Version 3.0", items[1].title) XCTAssertNil(items[1].itemDescription) XCTAssertNil(items[1].dateString) - XCTAssertFalse(items[1].isCriticalUpdate) + XCTAssertTrue(items[1].isCriticalUpdate) XCTAssertEqual(items[1].phasedRolloutInterval, 86400) XCTAssertEqual("Version 4.0", items[2].title) @@ -45,7 +49,7 @@ class SUAppcastTest: XCTestCase { XCTAssertFalse(items[3].isCriticalUpdate) // Test best appcast item & a delta update item - let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: nil, versionComparator: nil, testOSVersion: true, testMinimumAutoupdateVersion: false) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: false) let supportedAppcastItems = supportedAppcast.items @@ -72,22 +76,135 @@ class SUAppcastTest: XCTestCase { } } + func testCriticalUpdateVersion() { + let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast", withExtension: "xml")! + + do { + let testData = try Data(contentsOf: testURL) + + let versionComparator = SUStandardVersionComparator.default() + + // If critical update version is 1.5 and host version is 1.0, update should be marked critical + do { + let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + XCTAssertTrue(appcast.items[0].isCriticalUpdate) + } + + // If critical update version is 1.5 and host version is 1.5, update should not be marked critical + do { + let hostVersion = "1.5" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + XCTAssertFalse(appcast.items[0].isCriticalUpdate) + } + + // If critical update version is 1.5 and host version is 1.6, update should not be marked critical + do { + let hostVersion = "1.6" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + XCTAssertFalse(appcast.items[0].isCriticalUpdate) + } + } catch let err as NSError { + NSLog("%@", err) + XCTFail(err.localizedDescription) + } + } + + func testInformationalUpdateVersions() { + let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_info_updates", withExtension: "xml")! + + do { + let testData = try Data(contentsOf: testURL) + + let versionComparator = SUStandardVersionComparator.default() + + // Test informational updates from version 1.0 + do { + let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertFalse(appcast.items[0].isInformationOnlyUpdate) + XCTAssertFalse(appcast.items[1].isInformationOnlyUpdate) + XCTAssertTrue(appcast.items[2].isInformationOnlyUpdate) + XCTAssertTrue(appcast.items[3].isInformationOnlyUpdate) + + // Test delta updates inheriting informational only updates + do { + let deltaUpdate = appcast.items[2].deltaUpdates!["2.0"] as! SUAppcastItem + XCTAssertTrue(deltaUpdate.isInformationOnlyUpdate) + } + } + + // Test informational updates from version 2.4 + do { + let hostVersion = "2.4" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertTrue(appcast.items[1].isInformationOnlyUpdate) + } + + // Test informational updates from version 2.5 + do { + let hostVersion = "2.5" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertTrue(appcast.items[1].isInformationOnlyUpdate) + } + + // Test informational updates from version 2.6 + do { + let hostVersion = "2.6" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertFalse(appcast.items[1].isInformationOnlyUpdate) + } + + } catch let err as NSError { + NSLog("%@", err) + XCTFail(err.localizedDescription) + } + } + func testMinimumAutoupdateVersion() { let testURL = Bundle(for: SUAppcastTest.self).url(forResource: "testappcast_minimumAutoupdateVersion", withExtension: "xml")! do { let testData = try Data(contentsOf: testURL) - let appcast = try SUAppcast(xmlData: testData, relativeTo: nil) - - XCTAssertEqual(2, appcast.items.count) - let versionComparator = SUStandardVersionComparator() + do { + // Test appcast without a filter + + let hostVersion = "1.0" + + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + + XCTAssertEqual(2, appcast.items.count) + } + // Because 3.0 has minimum autoupdate version of 2.0, we should be offered 2.0 do { let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(1, supportedAppcast.items.count) @@ -101,6 +218,9 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -114,6 +234,9 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "2.5" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + let supportedAppcast = SUAppcastDriver.filterSupportedAppcast(appcast, phasedUpdateGroup: nil, skippedUpdate: nil, hostVersion: hostVersion, versionComparator: versionComparator, testOSVersion: true, testMinimumAutoupdateVersion: true) XCTAssertEqual(2, supportedAppcast.items.count) @@ -127,6 +250,9 @@ class SUAppcastTest: XCTestCase { do { let hostVersion = "1.0" + let stateResolver = SPUAppcastItemStateResolver(hostVersion: hostVersion, applicationVersionComparator: versionComparator, standardVersionComparator: versionComparator) + let appcast = try SUAppcast(xmlData: testData, relativeTo: nil, stateResolver: stateResolver) + // There should be no items if 2.0 is skipped from 1.0 and 3.0 fails minimum autoupdate version do { let skippedUpdate = SPUSkippedUpdate(minorVersion: "2.0", majorVersion: nil) @@ -249,9 +375,12 @@ class SUAppcastTest: XCTestCase { let testFileUrl = URL(fileURLWithPath: testFile) XCTAssertNotNil(testFileUrl) - do { + do { let testFileData = try Data(contentsOf: testFileUrl) - let appcast = try SUAppcast(xmlData: testFileData, relativeTo: testFileUrl) + + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default(), standardVersionComparator: SUStandardVersionComparator.default()) + + let appcast = try SUAppcast(xmlData: testFileData, relativeTo: testFileUrl, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual("https://sparkle-project.org/#localized_notes_link_works", items[0].releaseNotesURL!.absoluteString) } catch let err as NSError { @@ -265,7 +394,9 @@ class SUAppcastTest: XCTestCase { let testData = NSData(contentsOfFile: testFile)! do { - let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: nil) + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default(), standardVersionComparator: SUStandardVersionComparator.default()) + + let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: nil, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual(2, items.count) @@ -287,7 +418,9 @@ class SUAppcastTest: XCTestCase { do { let baseURL = URL(string: "https://fake.sparkle-project.org/updates/index.xml")! - let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL) + let stateResolver = SPUAppcastItemStateResolver(hostVersion: "1.0", applicationVersionComparator: SUStandardVersionComparator.default(), standardVersionComparator: SUStandardVersionComparator.default()) + + let appcast = try SUAppcast(xmlData: testData as Data, relativeTo: baseURL, stateResolver: stateResolver) let items = appcast.items XCTAssertEqual(2, items.count) diff --git a/Tests/Sparkle Unit Tests-Bridging-Header.h b/Tests/Sparkle Unit Tests-Bridging-Header.h index a4376798..d0e9251e 100644 --- a/Tests/Sparkle Unit Tests-Bridging-Header.h +++ b/Tests/Sparkle Unit Tests-Bridging-Header.h @@ -20,6 +20,7 @@ #import "SPUSkippedUpdate.h" #import "SUSignatures.h" #import "SPUInstallationType.h" +#import "SPUAppcastItemStateResolver.h" NS_ASSUME_NONNULL_BEGIN @@ -39,7 +40,7 @@ static const char *SUAppleQuarantineIdentifier = "com.apple.quarantine"; + (SUAppcastItem *)bestItemFromAppcastItems:(NSArray *)appcastItems getDeltaItem:(SUAppcastItem *_Nullable __autoreleasing *_Nullable)deltaItem withHostVersion:(NSString *)hostVersion comparator:(id)comparator; -+ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString * _Nullable)hostVersion versionComparator:(id _Nullable)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; ++ (SUAppcast *)filterSupportedAppcast:(SUAppcast *)appcast phasedUpdateGroup:(NSNumber * _Nullable)phasedUpdateGroup skippedUpdate:(SPUSkippedUpdate * _Nullable)skippedUpdate hostVersion:(NSString *)hostVersion versionComparator:(id)versionComparator testOSVersion:(BOOL)testOSVersion testMinimumAutoupdateVersion:(BOOL)testMinimumAutoupdateVersion; @end diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index c557864f..7e22b4b4 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -99,29 +99,30 @@ - (void)showUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem state:(SPUUserUpdateState *)state reply:(void (^)(SPUUserUpdateChoice))reply { - switch (state.stage) { - case SPUUserUpdateStageNotDownloaded: - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; - reply(SPUUserUpdateChoiceInstall); - break; - case SPUUserUpdateStageDownloaded: - [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; - reply(SPUUserUpdateChoiceInstall); - break; - case SPUUserUpdateStageInstalling: - if (self.deferInstallation) { - if (self.verbose) { - fprintf(stderr, "Deferring Installation.\n"); - } - reply(SPUUserUpdateChoiceDismiss); - } else { + if (appcastItem.informationOnlyUpdate) { + fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); + reply(SPUUserUpdateChoiceDismiss); + } else { + switch (state.stage) { + case SPUUserUpdateStageNotDownloaded: + [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"new"]; reply(SPUUserUpdateChoiceInstall); - } - break; - case SPUUserUpdateStageInformational: - fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); - reply(SPUUserUpdateChoiceDismiss); - break; + break; + case SPUUserUpdateStageDownloaded: + [self showUpdateWithAppcastItem:appcastItem updateAdjective:@"downloaded"]; + reply(SPUUserUpdateChoiceInstall); + break; + case SPUUserUpdateStageInstalling: + if (self.deferInstallation) { + if (self.verbose) { + fprintf(stderr, "Deferring Installation.\n"); + } + reply(SPUUserUpdateChoiceDismiss); + } else { + reply(SPUUserUpdateChoiceInstall); + } + break; + } } }