diff --git a/.travis.yml b/.travis.yml index 2267c6ec..bfec1ffe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode8.2 +osx_image: xcode9 before_install: - brew update script: make ci diff --git a/CHANGELOG b/CHANGELOG index d2d44059..6e472e0a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,27 @@ +# 1.18.1 + + * Add optional updaterDidRelaunchApplication: method on SUUpdaterDelegate (#1115) (App Tyrant) + * Implemented sparkle:os attribute as documented (Memphiz) + * Additional termination detection in case kpoll fails. (fujisoft) + * Included bin files in CocoaPods installation (Keith Smiley) + * Updated Dutch localization (Eitot) + * Updated German localization (Eitot) + * Updated Japanese translation (1024jp) + * Updated Portuguese translation (Victor) + * Updated to Xcode 9/Swift 4 + + # 1.18.0 + + * Name of the host app is used in authorization prompt (the `SPARKLE_RELAUNCH_TOOL_NAME` setting is now obsolete) + * More detailed progress bar for package installers (Kornel Lesiński) + * Disabled the keyboard shortcut for the install button for scheduled updates to avoid accidental installs. (George Nachman) + * generate_appcast tool adds release notes if there's an .html file with the same base name as the archive (Brett Walker) + * Added `sparkle:shortVersionString` to the enclosure, #1032 (Brett Walker) + * Fixed Japanese localization (1024jp) + * Fixed escaping of system profile URLs + * Added more logging in various failure cases (Kornel Lesiński) + * Better error message for quarantined apps that can't be updated + # 1.17.0 * Added Touch Bar support (Bi11) diff --git a/Configurations/ConfigCommon.xcconfig b/Configurations/ConfigCommon.xcconfig index cdbf12b2..96707f0c 100644 --- a/Configurations/ConfigCommon.xcconfig +++ b/Configurations/ConfigCommon.xcconfig @@ -16,8 +16,8 @@ SPARKLE_AUTOMATED_DOWNGRADES = 0 SPARKLE_NORMALIZE_INSTALLED_APPLICATION_NAME = 0 SPARKLE_VERSION_MAJOR = 1 -SPARKLE_VERSION_MINOR = 17 -SPARKLE_VERSION_PATCH = 0 +SPARKLE_VERSION_MINOR = 18 +SPARKLE_VERSION_PATCH = 1 SPARKLE_VERSION = $(SPARKLE_VERSION_MAJOR).$(SPARKLE_VERSION_MINOR).$(SPARKLE_VERSION_PATCH) CURRENT_PROJECT_VERSION = $(SPARKLE_VERSION) diff --git a/Configurations/ConfigSwift.xcconfig b/Configurations/ConfigSwift.xcconfig index 8e0862f9..95c45171 100644 --- a/Configurations/ConfigSwift.xcconfig +++ b/Configurations/ConfigSwift.xcconfig @@ -1 +1,2 @@ -SWIFT_VERSION = 3.0 +SWIFT_VERSION = 4.0 +SWIFT_SWIFT3_OBJC_INFERENCE = Off; diff --git a/README.markdown b/README.markdown index 32b308ee..58c7e5f4 100644 --- a/README.markdown +++ b/README.markdown @@ -33,18 +33,24 @@ Secure and reliable software update framework for Cocoa developers. * Build: Xcode 7 and 10.8 SDK or greater * HTTPS server for serving updates (see [App Transport Security](http://sparkle-project.org/documentation/app-transport-security/)) -## API +## Usage + +See [getting started guide](https://sparkle-project.org/documentation/). No code is necessary, but a bit of Xcode configuration is required. + +## Development + +### API symbols Sparkle is built with `-fvisibility=hidden -fvisibility-inlines-hidden` which means no symbols are exported by default. If you are adding a symbol to the public API you must decorate the declaration with the `SU_EXPORT` macro (grep the source code for examples). -## Building the distribution package +### Building the distribution package `cd` to the root of the Sparkle source tree and run `make release`. Sparkle-*VERSION*.tar.bz2 will be created in a temporary directory and revealed in Finder after the build has completed. Alternatively, build the Distribution scheme in the Xcode UI. -## Code of Conduct +### Code of Conduct We pledge to have an open and welcoming environment. See our [Code of Conduct](CODE_OF_CONDUCT.md). diff --git a/Sparkle.podspec b/Sparkle.podspec index 16e7378d..9235af49 100644 --- a/Sparkle.podspec +++ b/Sparkle.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Sparkle" - s.version = "1.17.0" + s.version = "1.18.1" s.summary = "A software update framework for macOS" s.description = "Sparkle is an easy-to-use software update framework for Cocoa developers." s.homepage = "http://sparkle-project.org" @@ -22,6 +22,7 @@ Pod::Spec.new do |s| s.source = { :http => "https://github.com/sparkle-project/Sparkle/releases/download/#{s.version}/Sparkle-#{s.version}.tar.bz2" } s.source_files = 'Sparkle.framework/Versions/A/Headers/*.h' + s.preserve_paths = 'bin/*' s.public_header_files = 'Sparkle.framework/Versions/A/Headers/*.h' s.vendored_frameworks = 'Sparkle.framework' s.xcconfig = { diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 359b11a9..5851f3e6 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 46; + objectVersion = 47; objects = { /* Begin PBXAggregateTarget section */ @@ -474,7 +474,7 @@ 14732BBF1960F0AC00593899 /* test_app_only_dsa_pub.pem */ = {isa = PBXFileReference; lastKnownFileType = text; path = test_app_only_dsa_pub.pem; sourceTree = ""; }; 14732BC11960F3B200593899 /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = SOURCE_ROOT; usesTabs = 1; }; 14732BC31960F3FF00593899 /* generate_keys */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = generate_keys; sourceTree = ""; }; - 14732BC41960F3FF00593899 /* sign_update */ = {isa = PBXFileReference; fileEncoding = 1; lastKnownFileType = text.script.sh; path = sign_update; sourceTree = ""; }; + 14732BC41960F3FF00593899 /* sign_update */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = sign_update; sourceTree = ""; }; 14732BC91960F70A00593899 /* make-release-package.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "make-release-package.sh"; sourceTree = ""; }; 14732BD219610A1800593899 /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 147D6D9E1B66DC3C006607AB /* CheckLocalizations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = CheckLocalizations.swift; path = Sparkle/CheckLocalizations.swift; sourceTree = SOURCE_ROOT; }; @@ -794,7 +794,7 @@ 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 = ""; }; 72E45CFD1B641D0D005C701A /* test_app_only_dsa_priv_dont_ever_do_this_for_real.pem */ = {isa = PBXFileReference; fileEncoding = 1; lastKnownFileType = text; path = test_app_only_dsa_priv_dont_ever_do_this_for_real.pem; sourceTree = ""; }; - 72E45DDC1B65C3BD005C701A /* sign_update */ = {isa = PBXFileReference; fileEncoding = 1; lastKnownFileType = text.script.sh; name = sign_update; path = bin/sign_update; sourceTree = SOURCE_ROOT; }; + 72E45DDC1B65C3BD005C701A /* sign_update */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; name = sign_update; path = bin/sign_update; sourceTree = SOURCE_ROOT; }; 767B61AA1972D488004E0C3C /* SUGuidedPackageInstaller.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUGuidedPackageInstaller.h; sourceTree = ""; }; 767B61AB1972D488004E0C3C /* SUGuidedPackageInstaller.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUGuidedPackageInstaller.m; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = ""; }; @@ -1047,7 +1047,6 @@ 1495006D195FBBBD00BC5B5B /* Sparkle */ = { isa = PBXGroup; children = ( - 720767D01E2E3DD300F9A850 /* AppKitPrevention.h */, 61299B3909CB055000B7442F /* Appcast Support */, 55C14BD5136EEFD000649790 /* Autoupdate */, 089C1665FE841158C02AAC07 /* Framework Resources */, @@ -1056,6 +1055,7 @@ 6101354A0DD25B7F0049ACDF /* Unarchiving */, 61F83F6E0DBFE07A006FDD30 /* Update Control */, 61299B3A09CB056100B7442F /* User Interface */, + 720767D01E2E3DD300F9A850 /* AppKitPrevention.h */, ); path = Sparkle; sourceTree = ""; @@ -1632,11 +1632,11 @@ TargetAttributes = { 5AA96C541E0AE0DB00CA4346 = { CreatedOnToolsVersion = 8.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; ProvisioningStyle = Automatic; }; 612279D80DB5470200AB99EA = { - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; TestTargetID = 8DC2EF4F0486A6940098B216; }; 722954B31D04ADAF00ECF9CA = { @@ -1650,7 +1650,7 @@ }; }; buildConfigurationList = 1DEB91B108733DA50010E9CD /* Build configuration list for PBXProject "Sparkle" */; - compatibilityVersion = "Xcode 3.2"; + compatibilityVersion = "Xcode 6.3"; developmentRegion = English; hasScannedForEncodings = 1; knownRegions = ( @@ -1878,8 +1878,8 @@ 55C14F22136EF86000649790 /* SUStandardVersionComparator.m in Sources */, 55C14F20136EF84300649790 /* SUStatusController.m in Sources */, 55C14F23136EF86700649790 /* SUSystemProfiler.m in Sources */, - 720767CF1E2DC37400F9A850 /* TerminationListener.m in Sources */, E1EC2A301E21667000245715 /* SUTouchBarButtonGroup.m in Sources */, + 720767CF1E2DC37400F9A850 /* TerminationListener.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sparkle.xcodeproj/xcshareddata/xcschemes/generate_appcast.xcscheme b/Sparkle.xcodeproj/xcshareddata/xcschemes/generate_appcast.xcscheme new file mode 100644 index 00000000..06b35333 --- /dev/null +++ b/Sparkle.xcodeproj/xcshareddata/xcschemes/generate_appcast.xcscheme @@ -0,0 +1,93 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Sparkle/Autoupdate/Autoupdate.m b/Sparkle/Autoupdate/Autoupdate.m index 0849ba0d..44cf3a59 100644 --- a/Sparkle/Autoupdate/Autoupdate.m +++ b/Sparkle/Autoupdate/Autoupdate.m @@ -136,7 +136,7 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; self.statusController = [[SUStatusController alloc] initWithHost:host]; [self.statusController setButtonTitle:SULocalizedString(@"Cancel Update", @"") target:nil action:Nil isDefault:NO]; [self.statusController beginActionWithTitle:SULocalizedString(@"Installing update...", @"") - maxProgressValue: 0 statusText: @""]; + maxProgressValue:100 statusText: @""]; [self.statusController showWindow:self]; } @@ -151,8 +151,14 @@ static const NSTimeInterval SUTerminationTimeDelay = 0.5; return; } + void(^progressBlock)(double) = ^(double progress){ + dispatch_async(dispatch_get_main_queue(), ^(){ + self.statusController.progressValue = progress * 100.0; + }); + }; + NSError *finalInstallationError = nil; - if (![installer performFinalInstallation:&finalInstallationError]) { + if (![installer performFinalInstallationProgressBlock:progressBlock error:&finalInstallationError]) { NSError *underlyingError = [finalInstallationError.userInfo objectForKey:NSUnderlyingErrorKey]; dispatch_async(dispatch_get_main_queue(), ^{ if (underlyingError == nil || underlyingError.code != SUInstallationCancelledError) { diff --git a/Sparkle/Autoupdate/TerminationListener.m b/Sparkle/Autoupdate/TerminationListener.m index 8c20fd07..5948fb51 100644 --- a/Sparkle/Autoupdate/TerminationListener.m +++ b/Sparkle/Autoupdate/TerminationListener.m @@ -116,6 +116,11 @@ if ([self terminated]) { [self invokeCompletionWithSuccess:YES]; } + dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ + if ([self terminated]) { + [self invokeCompletionWithSuccess:YES]; + } + }); } static void noteExitKQueueCallback(CFFileDescriptorRef file, CFOptionFlags __unused callBackTypes, void *info) diff --git a/Sparkle/CheckLocalizations.swift b/Sparkle/CheckLocalizations.swift index 431e8348..0f8e4e82 100755 --- a/Sparkle/CheckLocalizations.swift +++ b/Sparkle/CheckLocalizations.swift @@ -2,21 +2,21 @@ import Foundation -func die(msg: String) { +func die(_ msg: String) { print("ERROR: \(msg)") exit(1) } -extension NSXMLElement { +extension XMLElement { convenience init(name: String, attributes: [String: String], stringValue string: String? = nil) { self.init(name: name, stringValue: string) - setAttributesWithDictionary(attributes) + setAttributesWith(attributes) } } -let ud = NSUserDefaults.standardUserDefaults() -let sparkleRoot = ud.objectForKey("root") as? String -let htmlPath = ud.objectForKey("htmlPath") as? String +let ud = UserDefaults.standard +let sparkleRoot = ud.object(forKey: "root") as? String +let htmlPath = ud.object(forKey: "htmlPath") as? String if sparkleRoot == nil || htmlPath == nil { die("Missing arguments") } @@ -29,36 +29,36 @@ if enStringsDict == nil { let enStringsDictKeys = enStringsDict!.allKeys let dirPath = NSString(string: sparkleRoot! + "/Sparkle") -let dirContents = try! NSFileManager.defaultManager().contentsOfDirectoryAtPath(dirPath as String) +let dirContents = try! FileManager.default.contentsOfDirectory(atPath: dirPath as String) let css = "body { font-family: sans-serif; font-size: 10pt; }" + "h1 { font-size: 12pt; }" + ".missing { background-color: #FFBABA; color: #D6010E; white-space: pre; }" + ".unused { background-color: #BDE5F8; color: #00529B; white-space: pre; }" + ".unlocalized { background-color: #FEEFB3; color: #9F6000; white-space: pre; }" -var html = NSXMLDocument(rootElement: NSXMLElement(name: "html")) -html.DTD = NSXMLDTD() -html.DTD!.name = html.rootElement()!.name +var html = XMLDocument(rootElement: XMLElement(name: "html")) +html.dtd = XMLDTD() +html.dtd!.name = html.rootElement()!.name html.characterEncoding = "UTF-8" -html.documentContentKind = NSXMLDocumentContentKind.XHTMLKind -var body = NSXMLElement(name: "body") -var head = NSXMLElement(name: "head") +html.documentContentKind = XMLDocument.ContentKind.xhtml +var body = XMLElement(name: "body") +var head = XMLElement(name: "head") html.rootElement()!.addChild(head) html.rootElement()!.addChild(body) -head.addChild(NSXMLElement(name: "meta", attributes: ["charset": html.characterEncoding!])) -head.addChild(NSXMLElement(name: "title", stringValue: "Sparkle Localizations Report")) -head.addChild(NSXMLElement(name: "style", stringValue: css)) +head.addChild(XMLElement(name: "meta", attributes: ["charset": html.characterEncoding!])) +head.addChild(XMLElement(name: "title", stringValue: "Sparkle Localizations Report")) +head.addChild(XMLElement(name: "style", stringValue: css)) -let locale = NSLocale.currentLocale() +let locale = Locale.current for dirEntry in dirContents { if NSString(string: dirEntry).pathExtension != "lproj" || dirEntry == "en.lproj" { continue } - let lang = locale.displayNameForKey(NSLocaleLanguageCode, value: NSString(string: dirEntry).stringByDeletingPathExtension) - body.addChild(NSXMLElement(name: "h1", stringValue: "\(dirEntry) (\(lang!))")) + let lang = (locale as NSLocale).displayName(forKey: NSLocale.Key.languageCode, value: NSString(string: dirEntry).deletingPathExtension) + body.addChild(XMLElement(name: "h1", stringValue: "\(dirEntry) (\(lang!))")) - let stringsPath = NSString(string: dirPath.stringByAppendingPathComponent(dirEntry)).stringByAppendingPathComponent("Sparkle.strings") + let stringsPath = NSString(string: dirPath.appendingPathComponent(dirEntry)).appendingPathComponent("Sparkle.strings") let stringsDict = NSDictionary(contentsOfFile: stringsPath) if stringsDict == nil { die("Invalid strings file \(dirEntry)") @@ -70,10 +70,10 @@ for dirEntry in dirContents { var unused: [String] = [] for key in enStringsDictKeys { - let str = stringsDict?.objectForKey(key) as? String + let str = stringsDict?.object(forKey: key) as? String if str == nil { missing.append(key as! String) - } else if let enStr = enStringsDict?.objectForKey(key) as? String { + } else if let enStr = enStringsDict?.object(forKey: key) as? String { if enStr == str { unlocalized.append(key as! String) } @@ -82,7 +82,7 @@ for dirEntry in dirContents { let stringsDictKeys = stringsDict!.allKeys for key in stringsDictKeys { - if enStringsDict?.objectForKey(key) == nil { + if enStringsDict?.object(forKey: key) == nil { unused.append(key as! String) } } @@ -90,12 +90,12 @@ for dirEntry in dirContents { let sorter = { (s1: String, s2: String) -> Bool in return s1 < s2 } - missing.sortInPlace(sorter) - unlocalized.sortInPlace(sorter) - unused.sortInPlace(sorter) + missing.sort(by: sorter) + unlocalized.sort(by: sorter) + unused.sort(by: sorter) let addRow = { (prefix: String, cssClass: String, key: String) -> Void in - body.addChild(NSXMLElement(name: "span", attributes: ["class": cssClass], stringValue: [prefix, key].joinWithSeparator(" ") + "\n")) + body.addChild(XMLElement(name: "span", attributes: ["class": cssClass], stringValue: [prefix, key].joined(separator: " ") + "\n")) } for key in missing { @@ -110,6 +110,6 @@ for dirEntry in dirContents { } var err: NSError? -if !html.XMLData.writeToFile(htmlPath!, atomically: true) { - die("Can't write report: \(err)") +if !((try? html.xmlData.write(to: URL(fileURLWithPath: htmlPath!), options: [.atomic])) != nil) { + die("Can't write report: \(err!)") } diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 9ed52c9e..5c861ddd 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -27,6 +27,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (strong, readonly) NSURL *fileURL; @property (nonatomic, readonly) uint64_t contentLength; @property (copy, readonly) NSString *versionString; +@property (copy, readonly) NSString *osString; @property (copy, readonly) NSString *displayVersionString; @property (copy, readonly) NSDictionary *deltaUpdates; @property (strong, readonly) NSURL *infoURL; @@ -37,6 +38,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (getter=isDeltaUpdate, readonly) BOOL deltaUpdate; @property (getter=isCriticalUpdate, readonly) BOOL criticalUpdate; +@property (getter=isMacOsUpdate, readonly) BOOL macOsUpdate; @property (getter=isInformationOnlyUpdate, readonly) BOOL informationOnlyUpdate; // Returns the dictionary provided in initWithDictionary; this might be useful later for extensions. diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 1f9ed7a1..c4293034 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -23,6 +23,7 @@ @property (copy, readwrite) NSString *maximumSystemVersion; @property (strong, readwrite) NSURL *fileURL; @property (copy, readwrite) NSString *versionString; +@property (copy, readwrite) NSString *osString; @property (copy, readwrite) NSString *displayVersionString; @property (copy, readwrite) NSDictionary *deltaUpdates; @property (strong, readwrite) NSURL *infoURL; @@ -43,6 +44,7 @@ @synthesize releaseNotesURL; @synthesize title; @synthesize versionString; +@synthesize osString; @synthesize propertiesDictionary; - (BOOL)isDeltaUpdate @@ -56,6 +58,11 @@ return [[self.propertiesDictionary objectForKey:SUAppcastElementTags] containsObject:SUAppcastElementCriticalUpdate]; } +- (BOOL)isMacOsUpdate +{ + return self.osString == nil || [self.osString isEqualToString:SUAppcastAttributeValueMacOS]; +} + - (BOOL)isInformationOnlyUpdate { return self.infoURL && !self.fileURL; @@ -150,8 +157,9 @@ } if (enclosure) { self.DSASignature = [enclosure objectForKey:SUAppcastAttributeDSASignature]; + self.osString = [enclosure objectForKey:SUAppcastAttributeOsType]; } - + self.versionString = newVersion; self.minimumSystemVersion = [dict objectForKey:SUAppcastElementMinimumSystemVersion]; self.maximumSystemVersion = [dict objectForKey:SUAppcastElementMaximumSystemVersion]; diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 44fb18fd..c88aaeaf 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -29,7 +29,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 @interface SUAutomaticUpdateDriver () @property (assign) BOOL postponingInstallation; -@property (assign) BOOL showErrors; @property (assign) BOOL willUpdateOnTermination; @property (assign) BOOL isTerminating; @property (strong) SUAutomaticUpdateAlert *alert; @@ -40,7 +39,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 @implementation SUAutomaticUpdateDriver @synthesize postponingInstallation; -@synthesize showErrors; @synthesize willUpdateOnTermination; @synthesize isTerminating; @synthesize alert; @@ -202,7 +200,6 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [self stopUpdatingOnTermination]; } - self.showErrors = YES; [super installWithToolAndRelaunch:relaunch displayingUserInterface:showUI]; } @@ -231,21 +228,4 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 } } -- (void)abortUpdateWithError:(NSError *)error -{ - if (self.showErrors) { - [super abortUpdateWithError:error]; - } else { - // Call delegate separately here because otherwise it won't know we stopped. - // Normally this gets called by the superclass - id updater = self.updater; - id updaterDelegate = [updater delegate]; - if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; - } - - [self abortUpdate]; - } -} - @end diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 669b063e..1a091382 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -56,7 +56,7 @@ [super checkForUpdatesAtURL:URL host:aHost]; if ([aHost isRunningOnReadOnlyVolume]) { - [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again.", nil), [aHost name]] }]]; + [self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SURunningFromDiskImageError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"%1$@ can't be updated, because it was opened from a read-only or a temporary location. Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again.", nil), [aHost name]] }]]; return; } @@ -115,12 +115,15 @@ + (BOOL)hostSupportsItem:(SUAppcastItem *)ui { + BOOL osOK = [ui isMacOsUpdate]; if (([ui minimumSystemVersion] == nil || [[ui minimumSystemVersion] isEqualToString:@""]) && - ([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { return YES; } + ([ui maximumSystemVersion] == nil || [[ui maximumSystemVersion] isEqualToString:@""])) { + return osOK; + } BOOL minimumVersionOK = TRUE; BOOL maximumVersionOK = TRUE; - + id versionComparator = [[SUStandardVersionComparator alloc] init]; // Check minimum and maximum System Version @@ -131,7 +134,7 @@ maximumVersionOK = [versionComparator compareVersion:[ui maximumSystemVersion] toVersion:[SUOperatingSystem systemVersionString]] != NSOrderedAscending; } - return minimumVersionOK && maximumVersionOK; + return minimumVersionOK && maximumVersionOK && osOK; } - (BOOL)isItemNewer:(SUAppcastItem *)ui @@ -496,17 +499,36 @@ } NSBundle *sparkleBundle = updater.sparkleBundle; + if (!sparkleBundle) { + SULog(SULogLevelError, @"Sparkle bundle is gone?"); + return; + } // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. - NSString *const relaunchToolName = @"" SPARKLE_RELAUNCH_TOOL_NAME; - NSString *const relaunchToolSourcePath = [sparkleBundle pathForResource:relaunchToolName ofType:@"app"]; + NSString *const relaunchToolSourceName = @"" SPARKLE_RELAUNCH_TOOL_NAME; + NSString *const relaunchToolSourcePath = [sparkleBundle pathForResource:relaunchToolSourceName ofType:@"app"]; NSString *relaunchCopyTargetPath = nil; NSError *error = nil; BOOL copiedRelaunchPath = NO; + if (!relaunchToolSourceName || ![relaunchToolSourceName length]) { + SULog(SULogLevelError, @"SPARKLE_RELAUNCH_TOOL_NAME not configued"); + } + + if (!relaunchToolSourcePath) { + SULog(SULogLevelError, @"Sparkle.framework is damaged. %@ is missing", relaunchToolSourceName); + } + if (relaunchToolSourcePath) { - relaunchCopyTargetPath = [[self appCachePath] stringByAppendingPathComponent:[relaunchToolSourcePath lastPathComponent]]; + NSString *hostBundleBaseName = [[self.host.bundlePath lastPathComponent] stringByDeletingPathExtension]; + if (!hostBundleBaseName) { + SULog(SULogLevelError, @"Unable to get bundlePath"); + hostBundleBaseName = @"Sparkle"; + } + NSString *relaunchCopyBaseName = [NSString stringWithFormat:@"%@ (Autoupdate).app", hostBundleBaseName]; + + relaunchCopyTargetPath = [[self appCachePath] stringByAppendingPathComponent:relaunchCopyBaseName]; SUFileManager *fileManager = [SUFileManager defaultManager]; @@ -559,6 +581,9 @@ } } + //Set relaunching flag. + [self.host setBool:YES forUserDefaultsKey:SUUpdateRelaunchingMarkerKey]; + [NSTask launchedTaskWithLaunchPath:relaunchToolPath arguments:@[[self.host bundlePath], pathToRelaunch, [NSString stringWithFormat:@"%d", [[NSProcessInfo processInfo] processIdentifier]], diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index 33abaab6..5ff8fb01 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -21,6 +21,8 @@ extern const NSTimeInterval SUDefaultUpdateCheckInterval; extern NSString *const SUBundleIdentifier; +extern NSString *const SUAppcastAttributeValueMacOS; + // ----------------------------------------------------------------------------- // Notifications: // ----------------------------------------------------------------------------- @@ -33,6 +35,7 @@ extern NSString *const SUTechnicalErrorInformationKey; extern NSString *const SUFeedURLKey; extern NSString *const SUHasLaunchedBeforeKey; +extern NSString *const SUUpdateRelaunchingMarkerKey; extern NSString *const SUShowReleaseNotesKey; extern NSString *const SUSkippedVersionKey; extern NSString *const SUScheduledCheckIntervalKey; @@ -47,7 +50,6 @@ extern NSString *const SUEnableSystemProfilingKey; extern NSString *const SUSendProfileInfoKey; extern NSString *const SULastProfileSubmitDateKey; extern NSString *const SUPromptUserOnFirstLaunchKey; -extern NSString *const SUKeepDownloadOnFailedInstallKey; extern NSString *const SUDefaultsDomainKey; extern NSString *const SUEnableJavaScriptKey; extern NSString *const SUFixedHTMLDisplaySizeKey __attribute__((deprecated("This key is obsolete and has no effect."))); @@ -64,6 +66,9 @@ extern NSString *const SUAppcastAttributeDeltaFrom; extern NSString *const SUAppcastAttributeDSASignature; extern NSString *const SUAppcastAttributeShortVersionString; extern NSString *const SUAppcastAttributeVersion; +extern NSString *const SUAppcastAttributeOsType; + + extern NSString *const SUAppcastElementCriticalUpdate; extern NSString *const SUAppcastElementDeltas; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 5e883f6f..fc4e8e67 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -21,9 +21,12 @@ const NSTimeInterval SUDefaultUpdateCheckInterval = DEBUG ? 60 : (60 * 60 * 24); NSString *const SUBundleIdentifier = @SPARKLE_BUNDLE_IDENTIFIER; +NSString *const SUAppcastAttributeValueMacOS = @"macos"; + NSString *const SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation"; NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore"; +NSString *const SUUpdateRelaunchingMarkerKey = @"SUUpdateRelaunchingMarker"; NSString *const SUFeedURLKey = @"SUFeedURL"; NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes"; NSString *const SUSkippedVersionKey = @"SUSkippedVersion"; @@ -41,7 +44,6 @@ NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate"; NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch"; NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript"; NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize"; -NSString *const SUKeepDownloadOnFailedInstallKey = @"SUKeepDownloadOnFailedInstall"; NSString *const SUDefaultsDomainKey = @"SUDefaultsDomain"; NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain"; @@ -54,6 +56,7 @@ NSString *const SUAppcastAttributeDeltaFrom = @"sparkle:deltaFrom"; NSString *const SUAppcastAttributeDSASignature = @"sparkle:dsaSignature"; NSString *const SUAppcastAttributeShortVersionString = @"sparkle:shortVersionString"; NSString *const SUAppcastAttributeVersion = @"sparkle:version"; +NSString *const SUAppcastAttributeOsType = @"sparkle:os"; NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate"; NSString *const SUAppcastElementDeltas = @"sparkle:deltas"; diff --git a/Sparkle/SUFileManager.h b/Sparkle/SUFileManager.h index 9434566b..817bad9d 100644 --- a/Sparkle/SUFileManager.h +++ b/Sparkle/SUFileManager.h @@ -146,6 +146,7 @@ NS_ASSUME_NONNULL_BEGIN /** * Runs an installer package (pkg) in a headless mode using /usr/sbin/installer * @param packageURL A URL pointing to the package to execute. The item at this URL must exist. + * @param progressBlock Callback that takes double value (0..1 range) notifying how far the installation has progressed * @param error If an error occurs, upon returns contains an NSError object that describes the problem. If you are not interested in possible errors, you may pass in NULL. * @return YES if the installer ran the package successfully, otherwise NO with a populated error object * @@ -153,7 +154,7 @@ NS_ASSUME_NONNULL_BEGIN * an initial authorization prompt if the calling process does not have root privileges. In other words, root privileges are required to use this method, and the file manager instance must have been created by allowing authorization. * An error can occur if the package is unable to be ran by the installer, or if the installer reports a non-zero exit status code. */ -- (BOOL)executePackageAtURL:(NSURL *)packageURL error:(NSError *_Nullable*_Nullable)error; +- (BOOL)executePackageAtURL:(NSURL *)packageURL progressBlock:(nullable void(^)(double))progressBlock error:(NSError *_Nullable*_Nullable)error; NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUFileManager.m b/Sparkle/SUFileManager.m index 562aadd2..72890937 100644 --- a/Sparkle/SUFileManager.m +++ b/Sparkle/SUFileManager.m @@ -143,7 +143,11 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return YES; } -- (BOOL)_authorizeAndExecuteCommand:(char *)command sourcePath:(char *)sourcePath destinationPath:(char *)destinationPath error:(NSError * __autoreleasing *)error +- (BOOL)_authorizeAndExecuteCommand:(char *)command sourcePath:(char *)sourcePath destinationPath:(char *)destinationPath error:(NSError * __autoreleasing *)error { + return [self _authorizeAndExecuteCommand:command sourcePath:sourcePath destinationPath:destinationPath lineCallback:nil error:error]; +} + +- (BOOL)_authorizeAndExecuteCommand:(char *)command sourcePath:(char *)sourcePath destinationPath:(char *)destinationPath lineCallback:(void(^)(NSString*))lineCallback error:(NSError * __autoreleasing *)error { NSError *acquireError = nil; if (![self _acquireAuthorizationWithError:&acquireError]) { @@ -170,7 +174,10 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { if (runStatus != errAuthorizationSuccess) { #pragma clang diagnostic pop if (error != NULL) { - *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Failed to run authorization tool %@ (%d).", [NSString stringWithCString:toolPath encoding:NSUTF8StringEncoding], (int)runStatus] }]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcstring-format-directive" + *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUAuthenticationFailure userInfo:@{ NSLocalizedDescriptionKey:[NSString stringWithFormat:@"Failed to run authorization tool %@ (error code %d).", [NSString stringWithCString:toolPath encoding:NSUTF8StringEncoding], (int)runStatus] }]; +#pragma clang diagnostic pop } return NO; } @@ -184,6 +191,11 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return NO; } + if (lineCallback) { + NSFileHandle *pipeHandle = [[NSFileHandle alloc] initWithFileDescriptor:fileno(pipe) closeOnDealloc:NO]; + [self parseLines:pipeHandle lineCallback:lineCallback]; + } + pid_t childPid = (int32_t)CFSwapInt32LittleToHost(pidData); int status = 0; @@ -204,6 +216,28 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { return YES; } +- (void)parseLines:(NSFileHandle *)pipeHandle lineCallback:(void(^)(NSString *))lineCallback { + __block NSMutableData *line = [NSMutableData new]; + pipeHandle.readabilityHandler = ^(NSFileHandle *handle){ + NSData *data = handle.availableData; + NSUInteger length = data.length; + if (!length) { + return; + } + const char *bytes = data.bytes; + for(NSUInteger i = 0; i < length; i++) { + if (bytes[i] == '\n') { + NSData *dataToEOL = [data subdataWithRange:NSMakeRange(0, i)]; + [line appendData:dataToEOL]; + NSString *fullLine = [[NSString alloc] initWithData:line encoding:NSUTF8StringEncoding]; + lineCallback(fullLine); + line = [[data subdataWithRange:NSMakeRange(i+1, length-i-1)] mutableCopy]; + break; + } + } + }; +} + - (void)dealloc { if (_auth != NULL) { @@ -924,7 +958,7 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } // Unlike other methods, authorization is required to execute this method successfully -- (BOOL)executePackageAtURL:(NSURL *)packageURL error:(NSError * __autoreleasing *)error +- (BOOL)executePackageAtURL:(NSURL *)packageURL progressBlock:(void(^)(double))progressBlock error:(NSError * __autoreleasing *)error { if (![self _itemExistsAtURL:packageURL]) { if (error != NULL) { @@ -942,7 +976,11 @@ static BOOL SUMakeRefFromURL(NSURL *url, FSRef *ref, NSError **error) { } NSError *executeError = nil; - BOOL success = [self _authorizeAndExecuteCommand:SUFileOpInstallCommand sourcePath:path destinationPath:NULL error:&executeError]; + BOOL success = [self _authorizeAndExecuteCommand:SUFileOpInstallCommand sourcePath:path destinationPath:NULL lineCallback:^(NSString *line){ + if ([line hasPrefix:@"installer:%"]) { + progressBlock([[line substringFromIndex:11] doubleValue]/100.0); + } + } error:&executeError]; if (!success && error != NULL) { NSString* errorMessage = @"Failed to execute package installer."; diff --git a/Sparkle/SUGuidedPackageInstaller.m b/Sparkle/SUGuidedPackageInstaller.m index cea993a2..9c8e6e50 100644 --- a/Sparkle/SUGuidedPackageInstaller.m +++ b/Sparkle/SUGuidedPackageInstaller.m @@ -42,11 +42,11 @@ return YES; } -- (BOOL)performFinalInstallation:(NSError * __autoreleasing *)error +- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))progressBlock error:(NSError * __autoreleasing *)error { SUFileManager *fileManager = [SUFileManager fileManagerWithAuthorizationToolPath:self.fileOperationToolPath]; - return [fileManager executePackageAtURL:[NSURL fileURLWithPath:self.packagePath] error:error]; + return [fileManager executePackageAtURL:[NSURL fileURLWithPath:self.packagePath] progressBlock:progressBlock error:error]; } - (BOOL)canInstallSilently diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h old mode 100644 new mode 100755 diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m old mode 100644 new mode 100755 index 13dfe144..fe7345cd --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -82,7 +82,7 @@ name = [self objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleNameKey]; if (name && name.length > 0) return name; - return [[[NSFileManager defaultManager] displayNameAtPath:[self.bundle bundlePath]] stringByDeletingPathExtension]; + return [[[NSFileManager defaultManager] displayNameAtPath:[self bundlePath]] stringByDeletingPathExtension]; } - (NSString *__nonnull)version @@ -127,7 +127,12 @@ if (!keyPath) { return nil; } - return [NSString stringWithContentsOfFile:keyPath encoding:NSASCIIStringEncoding error:nil]; + NSError *error = nil; + key = [NSString stringWithContentsOfFile:keyPath encoding:NSASCIIStringEncoding error:&error]; + if (error) { + SULog(SULogLevelError, @"Error loading %@: %@", keyPath, error); + } + return key; } - (NSString * __nullable)publicDSAKeyFileKey diff --git a/Sparkle/SUInstallerProtocol.h b/Sparkle/SUInstallerProtocol.h index 4e07bbd2..75312c47 100644 --- a/Sparkle/SUInstallerProtocol.h +++ b/Sparkle/SUInstallerProtocol.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN // Any installation work after the user application has been terminated. This is where the final installation work can be done. // After this stage is done, the user application may be relaunched. // Should be able to be called from non-main thread -- (BOOL)performFinalInstallation:(NSError **)error; +- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))cb error:(NSError **)error; // Indicates whether or not this installer can install the update silently in the background, without hindering the user // Should be thread safe diff --git a/Sparkle/SULog.m b/Sparkle/SULog.m index 1e816b75..7faa0a6d 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -43,8 +43,8 @@ void SULog(SULogLevel level, NSString *format, ...) // Act the same way os_log() does; don't log to stderr if a terminal device is attached if (!isatty(STDERR_FILENO)) { options |= ASL_OPT_STDERR; - } - + } + NSString *displayName = [[NSFileManager defaultManager] displayNameAtPath:mainBundle.bundlePath]; client = asl_open([displayName stringByAppendingString:@" [Sparkle]"].UTF8String, SPARKLE_BUNDLE_IDENTIFIER, options); queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL); @@ -77,10 +77,10 @@ void SULog(SULogLevel level, NSString *format, ...) // See docs for OS_LOG_TYPE_ERROR os_log_error(logger, "%{public}@", logMessage); break; - } + } #pragma clang diagnostic pop return; -} + } // Otherwise use ASL // Make sure we do not async, because if we async, the log may not be delivered deterministically diff --git a/Sparkle/SUPackageInstaller.m b/Sparkle/SUPackageInstaller.m index 92654742..251a0561 100644 --- a/Sparkle/SUPackageInstaller.m +++ b/Sparkle/SUPackageInstaller.m @@ -49,7 +49,7 @@ static NSString *SUOpenUtilityPath = @"/usr/bin/open"; return YES; } -- (BOOL)performFinalInstallation:(NSError * __autoreleasing *)error +- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))__unused cb error:(NSError *__autoreleasing*)error { // Run installer using the "open" command to ensure it is launched in front of current application. // -W = wait until the app has quit. diff --git a/Sparkle/SUPlainInstaller.m b/Sparkle/SUPlainInstaller.m index 81ee5cfd..a7fd0281 100644 --- a/Sparkle/SUPlainInstaller.m +++ b/Sparkle/SUPlainInstaller.m @@ -61,7 +61,7 @@ return trimmedVersion.length > 0 ? trimmedVersion : nil; } -- (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL *)newURL withHost:(SUHost *)host fileOperationToolPath:(NSString *)fileOperationToolPath error:(NSError * __autoreleasing *)error +- (BOOL)performInstallationToURL:(NSURL *)installationURL fromUpdateAtURL:(NSURL *)newURL withHost:(SUHost *)host fileOperationToolPath:(NSString *)fileOperationToolPath progressBlock:(nullable void(^)(double))progress error:(NSError * __autoreleasing *)error { if (installationURL == nil || newURL == nil) { // this really shouldn't happen but just in case @@ -71,7 +71,11 @@ } return NO; } - + + if (progress) { + progress(1/10.0); + } + SUFileManager *fileManager = [SUFileManager fileManagerWithAuthorizationToolPath:fileOperationToolPath]; // Create a temporary directory for our new app that resides on our destination's volume @@ -82,7 +86,11 @@ SULog(SULogLevelError, @"Failed to make new temp directory"); return NO; } - + + if (progress) { + progress(2/10.0); + } + // Move the new app to our temporary directory NSString *newURLLastPathComponent = newURL.lastPathComponent; NSURL *newTempURL = [tempNewDirectoryURL URLByAppendingPathComponent:newURLLastPathComponent]; @@ -91,7 +99,11 @@ [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; return NO; } - + + if (progress) { + progress(3/10.0); + } + // Release our new app from quarantine, fix its owner and group IDs, and update its modification time while it's at our temporary destination // We must leave moving the app to its destination as the final step in installing it, so that // it's not possible our new app can be left in an incomplete state at the final destination @@ -101,7 +113,11 @@ // Not big enough of a deal to fail the entire installation SULog(SULogLevelError, @"Failed to release quarantine at %@ with error %@", newTempURL.path, quarantineError); } - + + if (progress) { + progress(4/10.0); + } + NSURL *oldURL = [NSURL fileURLWithPath:host.bundlePath]; if (oldURL == nil) { // this really shouldn't happen but just in case @@ -119,11 +135,19 @@ return NO; } + if (progress) { + progress(5/10.0); + } + if (![fileManager updateModificationAndAccessTimeOfItemAtURL:newTempURL error:error]) { // Not a fatal error, but a pretty unfortunate one SULog(SULogLevelError, @"Failed to update modification and access time of new app at %@", newTempURL.path); } - + + if (progress) { + progress(6/10.0); + } + // Decide on a destination name we should use for the older app when we move it around the file system NSString *oldDestinationName = nil; if (SPARKLE_APPEND_VERSION_NUMBER) { @@ -145,7 +169,11 @@ [fileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; return NO; } - + + if (progress) { + progress(7/10.0); + } + // Move the old app to the temporary directory NSURL *oldTempURL = [tempOldDirectoryURL URLByAppendingPathComponent:oldDestinationNameWithPathExtension]; if (![fileManager moveItemAtURL:oldURL toURL:oldTempURL error:error]) { @@ -157,7 +185,11 @@ return NO; } - + + if (progress) { + progress(8/10.0); + } + // Move the new app to its final destination if (![fileManager moveItemAtURL:newTempURL toURL:installationURL error:error]) { SULog(SULogLevelError, @"Failed to move new app at %@ to final destination %@", newTempURL.path, installationURL.path); @@ -171,14 +203,22 @@ return NO; } - + + if (progress) { + progress(9/10.0); + } + // From here on out, we don't really need to bring up authorization if we haven't done so prior SUFileManager *constrainedFileManager = [fileManager fileManagerByPreservingAuthorizationRights]; // Cleanup [constrainedFileManager removeItemAtURL:tempOldDirectoryURL error:NULL]; [constrainedFileManager removeItemAtURL:tempNewDirectoryURL error:NULL]; - + + if (progress) { + progress(10/10.0); + } + return YES; } @@ -207,9 +247,9 @@ return YES; } -- (BOOL)performFinalInstallation:(NSError * __autoreleasing *)error +- (BOOL)performFinalInstallationProgressBlock:(nullable void(^)(double))cb error:(NSError *__autoreleasing*)error { - return [self performInstallationToURL:[NSURL fileURLWithPath:self.installationPath] fromUpdateAtURL:[NSURL fileURLWithPath:self.bundlePath] withHost:self.host fileOperationToolPath:self.fileOperationToolPath error:error]; + return [self performInstallationToURL:[NSURL fileURLWithPath:self.installationPath] fromUpdateAtURL:[NSURL fileURLWithPath:self.bundlePath] withHost:self.host fileOperationToolPath:self.fileOperationToolPath progressBlock:cb error:error]; } - (BOOL)canInstallSilently diff --git a/Sparkle/SUScheduledUpdateDriver.m b/Sparkle/SUScheduledUpdateDriver.m index 18f4826c..a7a840db 100644 --- a/Sparkle/SUScheduledUpdateDriver.m +++ b/Sparkle/SUScheduledUpdateDriver.m @@ -12,13 +12,17 @@ @interface SUScheduledUpdateDriver () -@property (assign) BOOL showErrors; - @end @implementation SUScheduledUpdateDriver -@synthesize showErrors; +- (instancetype)initWithUpdater:(id)anUpdater +{ + if ((self = [super initWithUpdater:anUpdater])) { + self.showErrors = NO; + } + return self; +} - (void)didFindValidUpdate { @@ -39,25 +43,8 @@ [self abortUpdate]; // Don't tell the user that no update was found; this was a scheduled update. } -- (void)abortUpdateWithError:(NSError *)error -{ - if (self.showErrors) { - [super abortUpdateWithError:error]; - } else { - // Call delegate separately here because otherwise it won't know we stopped. - // Normally this gets called by the superclass - id updater = self.updater; - id updaterDelegate = [updater delegate]; - if ([updaterDelegate respondsToSelector:@selector(updater:didAbortWithError:)]) { - [updaterDelegate updater:self.updater didAbortWithError:error]; - } - - [self abortUpdate]; - } -} - - (BOOL)shouldDisableKeyboardShortcutForInstallButton { return YES; } - + @end diff --git a/Sparkle/SUUIBasedUpdateDriver.h b/Sparkle/SUUIBasedUpdateDriver.h index 69f34459..0c9f3914 100644 --- a/Sparkle/SUUIBasedUpdateDriver.h +++ b/Sparkle/SUUIBasedUpdateDriver.h @@ -15,6 +15,7 @@ @class SUStatusController; @interface SUUIBasedUpdateDriver : SUBasicUpdateDriver +@property (assign) BOOL showErrors; - (void)showAlert:(NSAlert *)alert; - (IBAction)cancelDownload:(id)sender; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 5e1de6f3..0400e5aa 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -45,11 +45,13 @@ @synthesize statusController; @synthesize updateAlert; +@synthesize showErrors; - (instancetype)initWithUpdater:(id)anUpdater { if ((self = [super initWithUpdater:anUpdater])) { self.automaticallyInstallUpdates = NO; + self.showErrors = YES; } return self; } @@ -293,11 +295,13 @@ - (void)abortUpdateWithError:(NSError *)error { - NSAlert *alert = [[NSAlert alloc] init]; - alert.messageText = SULocalizedString(@"Update Error!", nil); - alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]]; - [alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)]; - [self showAlert:alert]; + if (self.showErrors) { + NSAlert *alert = [[NSAlert alloc] init]; + alert.messageText = SULocalizedString(@"Update Error!", nil); + alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]]; + [alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)]; + [self showAlert:alert]; + } [super abortUpdateWithError:error]; } diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 679f1b79..a4744755 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -179,15 +179,30 @@ SU_EXPORT @interface SUUpdater : NSObject @property (nonatomic, copy) NSString *decryptionPassword; /*! - Checks for updates and, if available, immediately downloads and installs them. + This function ignores normal update schedule, ignores user preferences, + and interrupts users with an unwanted immediate app update. + + WARNING: this function should not be used in regular apps. This function + is a user-unfriendly hack only for very special cases, like unstable + rapidly-changing beta builds that would not run correctly if they were + even one day out of date. + + Instead of this function you should set `SUAutomaticallyUpdate` to `YES`, + which will gracefully install updates when the app quits. + + For UI-less/daemon apps that aren't usually quit, instead of this function, + you can use the delegate method + SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation: + to immediately start installation when an update was found. + A progress dialog is shown but the user will never be prompted to read the release notes. + This function will cause update to be downloaded twice if automatic updates are + enabled. + You may want to respond to the userDidCancelDownload delegate method in case the user clicks the "Cancel" button while the update is downloading. - - If you are writing a UI-less background application, you probably want to instead use - SUUpdaterDelegate::updater:willInstallUpdateOnQuit:immediateInstallationInvocation: */ - (void)installUpdatesIfAvailable; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 8aae8e91..3bad95ac 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -208,6 +208,14 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults if (!hasLaunchedBefore) { [self.host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey]; } + // Relanching from app update? + else if ([self.host boolForUserDefaultsKey:SUUpdateRelaunchingMarkerKey]) { + if ([self.delegate respondsToSelector:@selector(updaterDidRelaunchApplication:)]) { + [self.delegate updaterDidRelaunchApplication:self]; + } + //Reset flag back to NO. + [self.host setBool:NO forUserDefaultsKey:SUUpdateRelaunchingMarkerKey]; + } if (shouldPrompt) { NSArray *> *profileInfo = [SUSystemProfiler systemProfileArrayForHost:self.host]; @@ -483,6 +491,13 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults return [self.host boolForKey:SUSendProfileInfoKey]; } +static NSString *escapeURLComponent(NSString *str) { + return [[[[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] + stringByReplacingOccurrencesOfString:@"=" withString:@"%3d"] + stringByReplacingOccurrencesOfString:@"&" withString:@"%26"] + stringByReplacingOccurrencesOfString:@"+" withString:@"%2b"]; +} + - (NSURL *)parameterizedFeedURL { NSURL *baseFeedURL = [self feedURL]; @@ -512,7 +527,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults // Build up the parameterized URL. NSMutableArray *parameterStrings = [NSMutableArray array]; for (NSDictionary *currentProfileInfo in parameters) { - [parameterStrings addObject:[NSString stringWithFormat:@"%@=%@", [[[currentProfileInfo objectForKey:@"key"] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], [[[currentProfileInfo objectForKey:@"value"] description] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; + [parameterStrings addObject:[NSString stringWithFormat:@"%@=%@", escapeURLComponent([[currentProfileInfo objectForKey:@"key"] description]), escapeURLComponent([[currentProfileInfo objectForKey:@"value"] description])]]; } NSString *separatorCharacter = @"?"; diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index 39249ac4..dbc14024 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -192,6 +192,13 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; */ - (void)updaterWillRelaunchApplication:(SUUpdater *)updater; +/*! + Called immediately after relaunching. SUUpdater delegate must be set before applicationDidFinishLaunching: to catch this event. + + \param updater The SUUpdater instance. + */ +- (void)updaterDidRelaunchApplication:(SUUpdater *)updater; + /*! Returns an object that compares version numbers to determine their arithmetic relation to each other. diff --git a/Sparkle/ar.lproj/Sparkle.strings b/Sparkle/ar.lproj/Sparkle.strings index c8f6d535..e163944d 100644 --- a/Sparkle/ar.lproj/Sparkle.strings +++ b/Sparkle/ar.lproj/Sparkle.strings @@ -1,6 +1,6 @@ "%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?" = "تم تنزيل %1$@ %2$@ وهو جاهز للاستخدام، هل ترغب بتثبيت التحديث وإعادة تشغيل %1$@ الآن؟"; -"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again." = "لا يمكن تحديث %1$@ إذا شُغّل من وحدة تخزين للقراءة فقط كصورة قرص أو قارئ الأقراص الضوئية. انقل %1$@ إلى مجلد التطبيقات وأعد تشغيله من هناك ثم حاول مجددًا."; +"%1$@ can't be updated, because it was opened from a read-only or a temporary location. Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again." = "لا يمكن تحديث %1$@ إذا شُغّل من وحدة تخزين للقراءة فقط كصورة قرص أو قارئ الأقراص الضوئية. انقل %1$@ إلى مجلد التطبيقات وأعد تشغيله من هناك ثم حاول مجددًا."; "%@ %@ is currently the newest version available." = "الإصدار %2$@ هو أحدث إصدار متوفر حاليًا لتطبيق %1$@"; diff --git a/Sparkle/cs.lproj/Sparkle.strings b/Sparkle/cs.lproj/Sparkle.strings index 251d007f..aef9bb98 100644 --- a/Sparkle/cs.lproj/Sparkle.strings +++ b/Sparkle/cs.lproj/Sparkle.strings @@ -1,6 +1,6 @@ "%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?" = "%1$@ %2$@ byl instalován a je připraven k použití po příštím spuštění. Přejete si aplikaci %1$@ nyní nainstalovat a znovu spustit?"; -"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again." = "Aplikace %1$@ nemůže být aktualizována, protože je spuštěna z média na které nelze zapisovat. Může to být CD/DVD-ROM, obraz disku nebo jen nemáte právo zápisu na disk. Přesuňte aplikaci %1$@ do vaší složky Aplikace, spusťte ji z tohoto umístěni znovu."; +"%1$@ can't be updated, because it was opened from a read-only or a temporary location. Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again." = "Aplikace %1$@ nemůže být aktualizována, protože je spuštěna z média na které nelze zapisovat. Může to být CD/DVD-ROM, obraz disku nebo jen nemáte právo zápisu na disk. Přesuňte aplikaci %1$@ do vaší složky Aplikace, spusťte ji z tohoto umístěni znovu."; "%@ %@ is currently the newest version available." = "%1$@ %2$@ je nejnovější dostupná verze"; diff --git a/Sparkle/da.lproj/Sparkle.strings b/Sparkle/da.lproj/Sparkle.strings index 0e18c057..46ec942a 100644 --- a/Sparkle/da.lproj/Sparkle.strings +++ b/Sparkle/da.lproj/Sparkle.strings @@ -1,6 +1,6 @@ "%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?" = "%1$@ %2$@ er hentet og klar til brug! Vil du installere og genstarte %1$@ nu?"; -"%1$@ can't be updated when it's running from a read-only volume like a disk image or an optical drive. Move %1$@ to your Applications folder, relaunch it from there, and try again." = "%1$@ kan ikke opdateres når det køres fra en kun læsbar enhed. Flyt %1$@ til mappen Programmer, genstart derfra og prøv igen."; +"%1$@ can't be updated, because it was opened from a read-only or a temporary location. Use Finder to copy %1$@ to the Applications folder, relaunch it from there, and try again." = "%1$@ kan ikke opdateres når det køres fra en kun læsbar enhed. Flyt %1$@ til mappen Programmer, genstart derfra og prøv igen."; "%@ %@ is currently the newest version available." = "%1$@ %2$@ er den aktuelle version."; diff --git a/Sparkle/de.lproj/SUAutomaticUpdateAlert.xib b/Sparkle/de.lproj/SUAutomaticUpdateAlert.xib index 53f2e062..b83ef8c9 100644 --- a/Sparkle/de.lproj/SUAutomaticUpdateAlert.xib +++ b/Sparkle/de.lproj/SUAutomaticUpdateAlert.xib @@ -57,9 +57,9 @@