OSDN Git Service

staticプロパティをインスタンスプロパティに変更 master
authormasakih <masakih@users.sourceforge.jp>
Tue, 14 Aug 2018 11:52:52 +0000 (20:52 +0900)
committermasakih <masakih@users.sourceforge.jp>
Tue, 14 Aug 2018 11:52:52 +0000 (20:52 +0900)
KCD/ApplicationDirecrories.swift
KCD/ApplicationDirecroriesExtension.swift
KCD/CustomHTTPProtocol.swift
KCD/LoggerExtension.swift
KCD/UpgradableShipsWindowController.swift

index bbab898..ce1f60a 100644 (file)
@@ -33,14 +33,14 @@ struct ApplicationDirecrories {
     
     static let shared = ApplicationDirecrories()
     
     
     static let shared = ApplicationDirecrories()
     
-    static let support = searchedURL(for: .applicationSupportDirectory)
+    let support = searchedURL(for: .applicationSupportDirectory)
         .appendingPathComponent(supportDirName())
     
         .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
         
         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
         }
             
             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
     }
 }
     }
 }
index 27b0e5a..9420ce4 100644 (file)
@@ -20,7 +20,7 @@ extension ApplicationDirecrories {
     
     var screenShotSaveDirectory: String {
         
     
     var screenShotSaveDirectory: String {
         
-        return UserDefaults.standard[.screenShotSaveDirectory] ?? ApplicationDirecrories.pictures.path
+        return UserDefaults.standard[.screenShotSaveDirectory] ?? ApplicationDirecrories.shared.pictures.path
     }
     
     func setScreenshotDirectory(_ newValue: String) {
     }
     
     func setScreenshotDirectory(_ newValue: String) {
index 9bb625f..53d129d 100644 (file)
@@ -94,7 +94,7 @@ extension URLCache {
     
     static let kcd = URLCache(memoryCapacity: 32 * 1024 * 1024,
                               diskCapacity: 1024 * 1024 * 1024,
     
     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) {
     static let cachedExtensions = ["swf", "flv", "png", "jpg", "jpeg", "mp3"]
     
     func storeIfNeeded(for task: URLSessionTask, data: Data) {
index 1055d40..eadc277 100644 (file)
@@ -10,5 +10,5 @@ import Foundation
 
 extension Logger {
     
 
 extension Logger {
     
-    static let shared = Logger(destination: ApplicationDirecrories.support.appendingPathComponent("KCD.log"))
+    static let shared = Logger(destination: ApplicationDirecrories.shared.support.appendingPathComponent("KCD.log"))
 }
 }
index e597206..e721e6c 100644 (file)
@@ -105,7 +105,7 @@ final class UpgradableShipsWindowController: NSWindowController {
     
     private var excludeShipIDsSaveURL: URL {
         
     
     private var excludeShipIDsSaveURL: URL {
         
-        return ApplicationDirecrories.support.appendingPathComponent("ExcludeShipIDs")
+        return ApplicationDirecrories.shared.support.appendingPathComponent("ExcludeShipIDs")
     }
     
     override func windowWillLoad() {
     }
     
     override func windowWillLoad() {