From c623480f72fc2adc5f061708d96fc0e5d5ef924e Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Wed, 8 Mar 2017 10:57:59 +0100 Subject: [PATCH 1/2] when generating the appcast, if an .html file exists of the same name as the archive, then it will be linked in as the releaseNotesLink --- generate_appcast/ArchiveItem.swift | 16 ++++++++++++++++ generate_appcast/FeedXML.swift | 13 +++++++++++++ 2 files changed, 29 insertions(+) diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index 2152bcd2..c172a5af 100644 --- a/generate_appcast/ArchiveItem.swift +++ b/generate_appcast/ArchiveItem.swift @@ -118,6 +118,22 @@ class ArchiveItem: CustomStringConvertible { var fileSize : Int64 { return (self.archiveFileAttributes[.size] as! NSNumber).int64Value; } + + var releaseNotesPath : URL { + let basename = self.archivePath.deletingPathExtension(); + let releaseNotes = basename.appendingPathExtension("html"); + return releaseNotes; + } + + var releaseNotesURL : URL? { + guard let escapedFilename = self.releaseNotesPath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else { + return nil; + } + if let relative = self.feedURL { + return URL(string: escapedFilename, relativeTo: relative) + } + return URL(string: escapedFilename) + } let mimeType = "application/octet-stream"; } diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index 4492a999..64a064e4 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -110,6 +110,19 @@ 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) { + 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!); + } + } + var enclosure = findElement(name: "enclosure", parent: item); if nil == enclosure { enclosure = XMLElement.element(withName: "enclosure") as? XMLElement; From ac8c37096eba9e09b5b8813fbc20d7cfaa2e2615 Mon Sep 17 00:00:00 2001 From: Brett Walker Date: Sat, 11 Mar 2017 12:09:53 +0100 Subject: [PATCH 2/2] ignore .html files when scanning for archives --- generate_appcast/Unarchive.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generate_appcast/Unarchive.swift b/generate_appcast/Unarchive.swift index 60e6f906..69537559 100644 --- a/generate_appcast/Unarchive.swift +++ b/generate_appcast/Unarchive.swift @@ -50,7 +50,7 @@ func unarchiveUpdates(archivesSourceDir: URL) throws -> [ArchiveItem] { let dir = try fileManager.contentsOfDirectory(atPath: archivesSourceDir.path); var running = 0; - for item in dir.filter({ !$0.hasPrefix(".") && !$0.hasSuffix(".delta") && !$0.hasSuffix(".xml") }) { + for item in dir.filter({ !$0.hasPrefix(".") && !$0.hasSuffix(".delta") && !$0.hasSuffix(".xml") && !$0.hasSuffix(".html") }) { let itemPath = archivesSourceDir.appendingPathComponent(item); let archiveDestDir = archivesDestDir.appendingPathComponent(itemPath.lastPathComponent);