diff --git a/generate_appcast/ArchiveItem.swift b/generate_appcast/ArchiveItem.swift index f2b969e6..9cc5300e 100644 --- a/generate_appcast/ArchiveItem.swift +++ b/generate_appcast/ArchiveItem.swift @@ -46,6 +46,7 @@ class ArchiveItem: CustomStringConvertible { var dsaSignature: String?; var edSignature: String?; + var downloadUrlPrefix: URL?; init(version: String, shortVersion: String?, feedURL: URL?, minimumSystemVersion: String?, publicEdKey: String?, supportsDSA: Bool, appPath: URL, archivePath: URL) throws { self.version = version; diff --git a/generate_appcast/main.swift b/generate_appcast/main.swift index 2fc7a3ce..3f88b4f1 100644 --- a/generate_appcast/main.swift +++ b/generate_appcast/main.swift @@ -120,7 +120,7 @@ func main() { else if args.count == 4 && args[1] == "-s" { privateEdString = args[2] } - else if args.count != 2 { + else if args.count != 2 && !args.contains("--download-url-prefix") { printUsage() exit(1) } @@ -131,6 +131,30 @@ func main() { do { let allUpdates = try makeAppcast(archivesSourceDir: archivesSourceDir, keys: keys, verbose:verbose); + // if the beginning of a static url for downloading the updates was provided set the download url + if args.contains("--download-url-prefix") { + // check that an url was provided + let optionIndex = args.firstIndex(of: "--download-url-prefix") + var downloadUrl: URL? = nil + if optionIndex != nil && optionIndex! + 1 < args.count { + // check that the next argument is a valid url + let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) + let nextArgument = args[optionIndex! + 1] + if detector.numberOfMatches(in: nextArgument, options: [], range: NSMakeRange(0, nextArgument.count)) != 1 { + print("Please provide a valid download prefix url") + } + downloadUrl = URL(string: nextArgument) + } + + // set the download prefix url for each archive item + for (_, archiveItems) in allUpdates { + for archiveItem in archiveItems { + archiveItem.downloadUrlPrefix = downloadUrl + } + } + } + + for (appcastFile, updates) in allUpdates { let appcastDestPath = URL(fileURLWithPath: appcastFile, relativeTo: archivesSourceDir); try writeAppcast(appcastDestPath:appcastDestPath, updates:updates);