• R/O
  • HTTP
  • SSH
  • HTTPS

KCD: Commit

main code repository.


Commit MetaInfo

Revision0c3ec4c478b5b8a835e01bfa1287d2996ff8a4e3 (tree)
Time2018-08-14 19:17:50
Authormasakih <masakih@user...>
Commitermasakih

Log Message

分散していたスクリーンショットディレクトリを表すプロパティを集約した

Change Summary

Incremental Difference

--- a/KCD/AppDelegate.swift
+++ b/KCD/AppDelegate.swift
@@ -37,23 +37,6 @@ final class AppDelegate: NSObject {
3737 private var updaters: [() -> Void] = []
3838 private var didLoadedMainMenu = false
3939
40- var screenShotSaveDirectory: String {
41-
42- get {
43-
44- return UserDefaults.standard[.screenShotSaveDirectory] ?? ApplicationDirecrories.pictures.path
45- }
46- set {
47-
48- UserDefaults.standard[.screenShotSaveDirectory] = newValue
49- }
50- }
51-
52- var screenShotSaveDirectoryURL: URL {
53-
54- return URL(fileURLWithPath: screenShotSaveDirectory)
55- }
56-
5740 @objc dynamic var monospaceSystemFont11: NSFont {
5841
5942 return NSFont.monospacedDigitSystemFont(ofSize: 11, weight: .regular)
--- a/KCD/ApplicationDirecroriesExtension.swift
+++ b/KCD/ApplicationDirecroriesExtension.swift
@@ -8,33 +8,23 @@
88
99 extension ApplicationDirecrories {
1010
11- static let screenshotSaveDirectoryURL: URL = {
11+ var screenshotSaveDirectoryURL: URL {
1212
13- let parentURL = URL(fileURLWithPath: AppDelegate.shared.screenShotSaveDirectory)
13+ let parentURL = URL(fileURLWithPath: screenShotSaveDirectory)
1414 let url = parentURL.appendingPathComponent(localizedAppName())
15- let fm = FileManager.default
16- var isDir: ObjCBool = false
1715
18- do {
19-
20- if !fm.fileExists(atPath: url.path, isDirectory: &isDir) {
21-
22- try fm.createDirectory(at: url, withIntermediateDirectories: false)
23-
24- } else if !isDir.boolValue {
25-
26- print("\(url) is regular file, not direcory.")
27-
28- return parentURL
29- }
30-
31- } catch {
32-
33- print("Can not create screenshot save directory.")
34-
35- return parentURL
36- }
16+ guard checkDirectory(url, create: true) else { return parentURL }
3717
3818 return url
39- }()
19+ }
20+
21+ var screenShotSaveDirectory: String {
22+
23+ return UserDefaults.standard[.screenShotSaveDirectory] ?? ApplicationDirecrories.pictures.path
24+ }
25+
26+ func setScreenshotDirectory(_ newValue: String) {
27+
28+ UserDefaults.standard[.screenShotSaveDirectory] = newValue
29+ }
4030 }
--- a/KCD/GameViewController.swift
+++ b/KCD/GameViewController.swift
@@ -128,7 +128,7 @@ final class GameViewController: NSViewController {
128128
129129 webView.cacheDisplay(in: frame, to: rep)
130130
131- ScreenshotRegister(ApplicationDirecrories.screenshotSaveDirectoryURL)
131+ ScreenshotRegister(ApplicationDirecrories.shared.screenshotSaveDirectoryURL)
132132 .registerScreenshot(rep, name: localizedAppName())
133133 }
134134
@@ -191,7 +191,7 @@ final class GameViewController: NSViewController {
191191 rep.size = NSSize(width: 800, height: 480)
192192 }
193193
194- ScreenshotRegister(ApplicationDirecrories.screenshotSaveDirectoryURL)
194+ ScreenshotRegister(ApplicationDirecrories.shared.screenshotSaveDirectoryURL)
195195 .registerScreenshot(rep, name: localizedAppName())
196196 }
197197
--- a/KCD/PreferencePanelController.swift
+++ b/KCD/PreferencePanelController.swift
@@ -40,10 +40,10 @@ final class PreferencePanelController: NSWindowController {
4040
4141 private(set) var screenShotSaveDirectory: String {
4242
43- get { return AppDelegate.shared.screenShotSaveDirectory }
43+ get { return ApplicationDirecrories.shared.screenShotSaveDirectory }
4444 set {
4545
46- AppDelegate.shared.screenShotSaveDirectory = newValue
46+ ApplicationDirecrories.shared.setScreenshotDirectory(newValue)
4747
4848 let index = screenShotSaveDirectoryPopUp
4949 .indexOfItem(withTag: ScreenshotSaveDirectoryPopupMenuItemTag.saveDirectory.rawValue)
@@ -67,7 +67,7 @@ final class PreferencePanelController: NSWindowController {
6767
6868 super.windowDidLoad()
6969
70- screenShotSaveDirectory = AppDelegate.shared.screenShotSaveDirectory
70+ screenShotSaveDirectory = ApplicationDirecrories.shared.screenShotSaveDirectory
7171
7272 guard let window = window else {
7373
--- a/KCD/ScreenshotListViewController.swift
+++ b/KCD/ScreenshotListViewController.swift
@@ -62,36 +62,6 @@ final class ScreenshotListViewController: NSViewController {
6262 return name
6363 }
6464
65- private var screenshotSaveDirectoryURL: URL {
66-
67- let parentURL = URL(fileURLWithPath: AppDelegate.shared.screenShotSaveDirectory)
68- let url = parentURL.appendingPathComponent(dirName)
69- let fm = FileManager.default
70- var isDir: ObjCBool = false
71-
72- do {
73-
74- if !fm.fileExists(atPath: url.path, isDirectory: &isDir) {
75-
76- try fm.createDirectory(at: url, withIntermediateDirectories: false)
77-
78- } else if !isDir.boolValue {
79-
80- Logger.shared.log("\(url) is regular file, not direcory.")
81-
82- return parentURL
83- }
84-
85- } catch {
86-
87- Logger.shared.log("Can not create screenshot save directory.")
88-
89- return parentURL
90- }
91-
92- return url
93- }
94-
9565 var indexPathsOfItemsBeingDragged: Set<IndexPath>?
9666
9767 // MARK: - Function
@@ -212,7 +182,8 @@ final class ScreenshotListViewController: NSViewController {
212182
213183 Future<[ScreenshotInformation]> {
214184
215- ScreenshotLoader(self.screenshotSaveDirectoryURL).merge(screenshots: [])
185+ ScreenshotLoader(ApplicationDirecrories.shared.screenshotSaveDirectoryURL)
186+ .merge(screenshots: [])
216187
217188 }
218189 .onSuccess { screenshots in
--- a/KCD/ScreenshotListWindowController.swift
+++ b/KCD/ScreenshotListWindowController.swift
@@ -74,7 +74,7 @@ final class ScreenshotListWindowController: NSWindowController {
7474
7575 func registerScreenshot(_ image: NSBitmapImageRep) {
7676
77- ScreenshotRegister(ApplicationDirecrories.screenshotSaveDirectoryURL)
77+ ScreenshotRegister(ApplicationDirecrories.shared.screenshotSaveDirectoryURL)
7878 .registerScreenshot(image, name: localizedAppName())
7979 }
8080
@@ -89,7 +89,7 @@ final class ScreenshotListWindowController: NSWindowController {
8989 .flatMap { NSBitmapImageRep(data: $0) }
9090 .map {
9191
92- ScreenshotRegister(ApplicationDirecrories.screenshotSaveDirectoryURL)
92+ ScreenshotRegister(ApplicationDirecrories.shared.screenshotSaveDirectoryURL)
9393 .registerScreenshot($0, name: localizedAppName())
9494 }
9595 }
Show on old repository browser