diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index ea06c896..a5d518b1 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -697,6 +697,13 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification return [self.updaterSettings sendsSystemProfile]; } +static NSString *escapeURLComponent(NSString *str) { + return [[[[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] + stringByReplacingOccurrencesOfString:@"=" withString:@"%3d"] + stringByReplacingOccurrencesOfString:@"&" withString:@"%26"] + stringByReplacingOccurrencesOfString:@"+" withString:@"%2b"]; +} + // Precondition: The feed URL should be valid - (NSURL * _Nullable)parameterizedFeedURL { @@ -734,7 +741,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification // 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/SUHost.m b/Sparkle/SUHost.m index 90c96e4c..d9a5d3e7 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -144,7 +144,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/SULog.m b/Sparkle/SULog.m index 08576ae9..1f304519 100644 --- a/Sparkle/SULog.m +++ b/Sparkle/SULog.m @@ -44,8 +44,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); @@ -78,10 +78,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/SUUpdater.m b/Sparkle/SUUpdater.m index 1e67a020..aa8f6a8e 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -61,7 +61,7 @@ static NSMutableDictionary *sharedUpdaters = nil; { self = [super init]; if (bundle == nil) bundle = [NSBundle mainBundle]; - + id updater = [sharedUpdaters objectForKey:[NSValue valueWithNonretainedObject:bundle]]; if (updater) { @@ -79,7 +79,7 @@ static NSMutableDictionary *sharedUpdaters = nil; // See -[SUUpdater _standardUserDriverRequestsPathToRelaunch] and -[SUUpdater _pathToRelaunchForUpdater:] implemented below which resolves this _userDriver = [[SPUStandardUserDriver alloc] initWithHostBundle:bundle delegate:self]; _updater = [[SPUUpdater alloc] initWithHostBundle:bundle applicationBundle:bundle userDriver:_userDriver delegate:self]; - + NSError *updaterError = nil; if (![_updater startUpdater:&updaterError]) { SULog(SULogLevelError, @"Error: Failed to start updater with error: %@", updaterError); @@ -185,7 +185,7 @@ static NSMutableDictionary *sharedUpdaters = nil; { [self.updater checkForUpdates]; } - + - (BOOL)validateMenuItem:(NSMenuItem *)item { if ([item action] == @selector(checkForUpdates:)) { @@ -225,7 +225,7 @@ static NSMutableDictionary *sharedUpdaters = nil; self.loggedInstallUpdatesIfAvailableWarning = YES; } - + [self checkForUpdatesInBackground]; } @@ -357,6 +357,13 @@ static NSMutableDictionary *sharedUpdaters = nil; } } +static NSString *escapeURLComponent(NSString *str) { + return [[[[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding] + stringByReplacingOccurrencesOfString:@"=" withString:@"%3d"] + stringByReplacingOccurrencesOfString:@"&" withString:@"%26"] + stringByReplacingOccurrencesOfString:@"+" withString:@"%2b"]; +} + - (BOOL)updater:(SPUUpdater *)__unused updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)item untilInvokingBlock:(void (^)(void))installHandler { BOOL shouldPostponeRelaunch = NO; @@ -368,9 +375,9 @@ static NSMutableDictionary *sharedUpdaters = nil; // This invocation will retain self, but this instance is kept alive forever by our singleton pattern anyway [invocation setTarget:self]; - + self.postponedInstallHandler = installHandler; - + shouldPostponeRelaunch = [self.delegate updater:self shouldPostponeRelaunchForUpdate:item untilInvoking:invocation]; } diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index c172a5af..4cee60bf 100644 --- a/generate_appcast/ArchiveItem.swift +++ b/generate_appcast/ArchiveItem.swift @@ -119,14 +119,45 @@ class ArchiveItem: CustomStringConvertible { return (self.archiveFileAttributes[.size] as! NSNumber).int64Value; } - var releaseNotesPath : URL { - let basename = self.archivePath.deletingPathExtension(); + private var releaseNotesPath : URL? { + var basename = self.archivePath.deletingPathExtension(); + if basename.pathExtension == "tar" { // tar.gz + basename = basename.deletingPathExtension(); + } let releaseNotes = basename.appendingPathExtension("html"); + if !FileManager.default.fileExists(atPath: releaseNotes.path) { + return nil; + } return releaseNotes; } + private func getReleaseNotesAsHTMLFragment(_ path: URL) -> String? { + if let html = try? String(contentsOf: path) { + if html.utf8.count < 1000 && + !html.localizedCaseInsensitiveContains(" XMLElement { return element; } let element = XMLElement(name: name); + linebreak(parent); parent.addChild(element); return element; } @@ -69,7 +70,9 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { channel = channelNodes[0] as! XMLElement; } else { channel = XMLElement(name: "channel"); + linebreak(channel); channel.addChild(XMLElement.element(withName: "title", stringValue: appBaseName) as! XMLElement); + linebreak(root); root.addChild(channel); } @@ -102,6 +105,13 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement); } + if let html = update.releaseNotesHTML { + let descElement = findOrCreateElement(name: "description", parent: item); + let cdata = XMLNode(kind:.text, options:.nodeIsCDATA); + cdata.stringValue = html; + descElement.setChildren([cdata]); + } + var minVer = findElement(name: "sparkle:minimumSystemVersion", parent: item); if nil == minVer { minVer = XMLElement.element(withName: "sparkle:minimumSystemVersion", uri: sparkleNS) as? XMLElement; @@ -111,16 +121,13 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { minVer?.setChildren([text(update.minimumSystemVersion)]); let relElement = findElement(name: "sparkle:releaseNotesLink", parent: item); - if nil == relElement { - if FileManager.default.fileExists(atPath: update.releaseNotesPath.path) { + if let url = update.releaseNotesURL { + if nil == relElement { linebreak(item); - item.addChild(XMLElement.element(withName:"sparkle:releaseNotesLink", stringValue: (update.releaseNotesURL?.absoluteString)!) as! XMLElement); - } - } else { - if !FileManager.default.fileExists(atPath: update.releaseNotesPath.path) { - let childIndex = relElement?.index; - item.removeChild(at: childIndex!); + item.addChild(XMLElement.element(withName:"sparkle:releaseNotesLink", stringValue: url.absoluteString) as! XMLElement); } + } else if let childIndex = relElement?.index { + item.removeChild(at: childIndex); } var enclosure = findElement(name: "enclosure", parent: item);