OSDN Git Service

shared instanceを持つようにした
[kcd/KCD.git] / KCD / ApplicationDirecrories.swift
index a752054..bbab898 100644 (file)
@@ -18,8 +18,21 @@ private func supportDirName() -> String {
         ?? "UnknownAppliation"
 }
 
+func localizedAppName() -> String {
+    
+    guard let name = Bundle.main.localizedInfoDictionary?["CFBundleName"] as? String,
+        !name.isEmpty else {
+            
+            return supportDirName()
+    }
+    
+    return name
+}
+
 struct ApplicationDirecrories {
     
+    static let shared = ApplicationDirecrories()
+    
     static let support = searchedURL(for: .applicationSupportDirectory)
         .appendingPathComponent(supportDirName())
     
@@ -35,6 +48,7 @@ struct ApplicationDirecrories {
     }
 }
 
+
 func createDirectory(_ url: URL) -> Bool {
     
     do {
@@ -48,11 +62,10 @@ func createDirectory(_ url: URL) -> Bool {
     } catch {
         
         return false
-        
     }
 }
 
-func checkDirectory(_ url: URL) -> Bool {
+func checkDirectory(_ url: URL, create: Bool) -> Bool {
     
     do {
         
@@ -66,10 +79,9 @@ func checkDirectory(_ url: URL) -> Bool {
         
         return true
         
-    } catch {
+    } catch let error as NSError {
         
-        let nserror = error as NSError
-        if nserror.code == NSFileReadNoSuchFileError {
+        if create, error.code == NSFileReadNoSuchFileError {
             
             return createDirectory(url)
         }