From fa6a0a0b51735ab1f9a4caef2dc9bad3ec09bd9e Mon Sep 17 00:00:00 2001 From: masakih Date: Tue, 14 Aug 2018 20:52:52 +0900 Subject: [PATCH] =?utf8?q?static=E3=83=97=E3=83=AD=E3=83=91=E3=83=86?= =?utf8?q?=E3=82=A3=E3=82=92=E3=82=A4=E3=83=B3=E3=82=B9=E3=82=BF=E3=83=B3?= =?utf8?q?=E3=82=B9=E3=83=97=E3=83=AD=E3=83=91=E3=83=86=E3=82=A3=E3=81=AB?= =?utf8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- KCD/ApplicationDirecrories.swift | 70 ++++++++++++++++--------------- KCD/ApplicationDirecroriesExtension.swift | 2 +- KCD/CustomHTTPProtocol.swift | 2 +- KCD/LoggerExtension.swift | 2 +- KCD/UpgradableShipsWindowController.swift | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/KCD/ApplicationDirecrories.swift b/KCD/ApplicationDirecrories.swift index bbab898b..ce1f60a4 100644 --- a/KCD/ApplicationDirecrories.swift +++ b/KCD/ApplicationDirecrories.swift @@ -33,14 +33,14 @@ struct ApplicationDirecrories { static let shared = ApplicationDirecrories() - static let support = searchedURL(for: .applicationSupportDirectory) + let support = searchedURL(for: .applicationSupportDirectory) .appendingPathComponent(supportDirName()) - static let documents = searchedURL(for: .documentDirectory) + let documents = searchedURL(for: .documentDirectory) - static let pictures = searchedURL(for: .picturesDirectory) + let pictures = searchedURL(for: .picturesDirectory) - private static func searchedURL(for directory: FileManager.SearchPathDirectory) -> URL { + static func searchedURL(for directory: FileManager.SearchPathDirectory) -> URL { return FileManager.default.urls(for: directory, in: .userDomainMask) .last @@ -48,44 +48,46 @@ struct ApplicationDirecrories { } } - -func createDirectory(_ url: URL) -> Bool { +extension ApplicationDirecrories { - do { - - try FileManager.default.createDirectory(at: url, - withIntermediateDirectories: false, - attributes: nil) - - return true + func createDirectory(_ url: URL) -> Bool { - } catch { - - return false - } -} - -func checkDirectory(_ url: URL, create: Bool) -> Bool { - - do { - - let resourceValue = try url.resourceValues(forKeys: [.isDirectoryKey]) - if !resourceValue.isDirectory! { + do { + + try FileManager.default.createDirectory(at: url, + withIntermediateDirectories: false, + attributes: nil) + + return true - print("Expected a folder to store application data, found a file \(url.path).") + } catch { return false } + } + + func checkDirectory(_ url: URL, create: Bool) -> Bool { - return true - - } catch let error as NSError { - - if create, error.code == NSFileReadNoSuchFileError { + do { + + let resourceValue = try url.resourceValues(forKeys: [.isDirectoryKey]) + if !resourceValue.isDirectory! { + + print("Expected a folder to store application data, found a file \(url.path).") + + return false + } - return createDirectory(url) + return true + + } catch let error as NSError { + + if create, error.code == NSFileReadNoSuchFileError { + + return createDirectory(url) + } + + return false } - - return false } } diff --git a/KCD/ApplicationDirecroriesExtension.swift b/KCD/ApplicationDirecroriesExtension.swift index 27b0e5a7..9420ce41 100644 --- a/KCD/ApplicationDirecroriesExtension.swift +++ b/KCD/ApplicationDirecroriesExtension.swift @@ -20,7 +20,7 @@ extension ApplicationDirecrories { var screenShotSaveDirectory: String { - return UserDefaults.standard[.screenShotSaveDirectory] ?? ApplicationDirecrories.pictures.path + return UserDefaults.standard[.screenShotSaveDirectory] ?? ApplicationDirecrories.shared.pictures.path } func setScreenshotDirectory(_ newValue: String) { diff --git a/KCD/CustomHTTPProtocol.swift b/KCD/CustomHTTPProtocol.swift index 9bb625f8..53d129d2 100644 --- a/KCD/CustomHTTPProtocol.swift +++ b/KCD/CustomHTTPProtocol.swift @@ -94,7 +94,7 @@ extension URLCache { static let kcd = URLCache(memoryCapacity: 32 * 1024 * 1024, diskCapacity: 1024 * 1024 * 1024, - diskPath: ApplicationDirecrories.support.appendingPathComponent("Caches").path) + diskPath: ApplicationDirecrories.shared.support.appendingPathComponent("Caches").path) static let cachedExtensions = ["swf", "flv", "png", "jpg", "jpeg", "mp3"] func storeIfNeeded(for task: URLSessionTask, data: Data) { diff --git a/KCD/LoggerExtension.swift b/KCD/LoggerExtension.swift index 1055d403..eadc2774 100644 --- a/KCD/LoggerExtension.swift +++ b/KCD/LoggerExtension.swift @@ -10,5 +10,5 @@ import Foundation extension Logger { - static let shared = Logger(destination: ApplicationDirecrories.support.appendingPathComponent("KCD.log")) + static let shared = Logger(destination: ApplicationDirecrories.shared.support.appendingPathComponent("KCD.log")) } diff --git a/KCD/UpgradableShipsWindowController.swift b/KCD/UpgradableShipsWindowController.swift index e5972067..e721e6cc 100644 --- a/KCD/UpgradableShipsWindowController.swift +++ b/KCD/UpgradableShipsWindowController.swift @@ -105,7 +105,7 @@ final class UpgradableShipsWindowController: NSWindowController { private var excludeShipIDsSaveURL: URL { - return ApplicationDirecrories.support.appendingPathComponent("ExcludeShipIDs") + return ApplicationDirecrories.shared.support.appendingPathComponent("ExcludeShipIDs") } override func windowWillLoad() { -- 2.11.0