Merge pull request #3299 from stuartbreckenridge/nnwtheme-downloader

Performs search of directory for theme file.
This commit is contained in:
Maurice Parker 2021-09-21 20:22:52 -05:00 committed by GitHub
commit b022854397
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 1 deletions

View File

@ -58,7 +58,7 @@ public class ArticleThemeDownloader {
let unzipDirectory = URL(fileURLWithPath: location.path.replacingOccurrences(of: ".zip", with: ""))
try Zip.unzipFile(location, destination: unzipDirectory, overwrite: true, password: nil, progress: nil, fileOutputHandler: nil) // Unzips to folder in Application Support/NetNewsWire/Downloads
try FileManager.default.removeItem(at: location) // Delete zip in Cache
let themeFilePath = FileManager.default.filenames(inFolder: unzipDirectory.path)?.first(where: { $0.contains(".nnwtheme") })
let themeFilePath = findThemeFile(in: unzipDirectory.path)
if themeFilePath == nil {
throw ArticleThemeDownloaderError.noThemeFile
}
@ -69,6 +69,22 @@ public class ArticleThemeDownloader {
}
}
/// Performs a deep search of the unzipped direcotry to find the theme file.
/// - Parameter searchPath: directory to search
/// - Returns: optional `String`
private func findThemeFile(in searchPath: String) -> String? {
if let directoryContents = FileManager.default.enumerator(atPath: searchPath) {
while let file = directoryContents.nextObject() as? String {
if file.hasSuffix(".nnwtheme") {
return file
}
}
}
return nil
}
/// The download directory used by the theme downloader: `Application Suppport/NetNewsWire/Downloads`
/// - Returns: `URL`
private func downloadDirectory() -> URL {