2 // ScreenshotLoader.swift
5 // Created by Hori,Masaki on 2017/11/05.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 final class ScreenshotLoader {
20 func merge(screenshots: [ScreenshotInformation]) -> [ScreenshotInformation] {
22 let urls = screenshotURLs()
25 let itemWithoutDeleting = screenshots.filter { urls.contains($0.url) }
29 .filter { url in !itemWithoutDeleting.contains(where: { url == $0.url }) }
30 .map { ScreenshotInformation(url: $0) }
32 return itemWithoutDeleting + newItems
35 private func screenshotURLs() -> [URL] {
37 guard let files = try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil) else {
39 Logger.shared.log("can not read list of screenshot directory")
44 return files.filter(isPicture)
47 private func isPicture(_ url: URL) -> Bool {
49 guard let r = try? url.resourceValues(forKeys: [.typeIdentifierKey]) else {
53 guard let type = r.typeIdentifier else {
58 return NSImage.imageTypes.contains(type)