艦娘をちゅーちゅーします
Révision | 970f28aac73ca42538dfea33f734c20f7d34e79d (tree) |
---|---|
l'heure | 2017-08-06 17:24:48 |
Auteur | masakih <masakih@user...> |
Commiter | masakih |
一時フォルダを削除するようにした
@@ -28,6 +28,8 @@ struct ApplicationDirecrories { | ||
28 | 28 | |
29 | 29 | class ViewController: NSViewController { |
30 | 30 | |
31 | + static let chuchu = "ちゅーちゅー" | |
32 | + static let tempDirName = "___temp_chu-chu-_ship___" | |
31 | 33 | |
32 | 34 | @IBOutlet var cachePathField: NSPathControl! |
33 | 35 | @IBOutlet var outputFolderField: NSPathControl! |
@@ -109,12 +111,22 @@ extension ViewController { | ||
109 | 111 | throw ExtractKanMusu.urlMissing("Cache dir is nil") |
110 | 112 | } |
111 | 113 | |
112 | - let tempURL = tempParentURL.appendingPathComponent("___temp_chu-chu-_ship___") | |
114 | + let tempURL = tempParentURL.appendingPathComponent(ViewController.tempDirName) | |
113 | 115 | |
114 | 116 | try FileManager.default |
115 | 117 | .createDirectory(at: tempURL, withIntermediateDirectories: true, attributes: nil) |
116 | 118 | |
119 | + } | |
120 | + func deleteTempDir() throws { | |
121 | + | |
122 | + guard let tempParentURL = cachePathField.url else { | |
123 | + | |
124 | + throw ExtractKanMusu.urlMissing("Cache dir is nil") | |
125 | + } | |
117 | 126 | |
127 | + let tempURL = tempParentURL.appendingPathComponent(ViewController.tempDirName) | |
128 | + | |
129 | + try FileManager.default.removeItem(at: tempURL) | |
118 | 130 | } |
119 | 131 | func createDestDir() throws { |
120 | 132 |
@@ -123,12 +135,11 @@ extension ViewController { | ||
123 | 135 | throw ExtractKanMusu.urlMissing("Output dir is nil") |
124 | 136 | } |
125 | 137 | |
126 | - let destURL = destParentURL.appendingPathComponent("ちゅーちゅー") | |
138 | + let destURL = destParentURL.appendingPathComponent(ViewController.chuchu) | |
127 | 139 | |
128 | 140 | try FileManager.default |
129 | 141 | .createDirectory(at: destURL, withIntermediateDirectories: true, attributes: nil) |
130 | 142 | |
131 | - | |
132 | 143 | } |
133 | 144 | |
134 | 145 |
@@ -144,6 +155,18 @@ extension ViewController { | ||
144 | 155 | existDestinationDir |
145 | 156 | else { return } |
146 | 157 | |
158 | + | |
159 | + defer { | |
160 | + | |
161 | + do { | |
162 | + | |
163 | + try deleteTempDir() | |
164 | + | |
165 | + } catch { | |
166 | + print(error) | |
167 | + } | |
168 | + } | |
169 | + | |
147 | 170 | do { |
148 | 171 | |
149 | 172 | try createTempDir() |
@@ -175,8 +198,8 @@ extension ViewController { | ||
175 | 198 | |
176 | 199 | do { |
177 | 200 | |
178 | - let tempURL = originalDir.appendingPathComponent("___temp_chu-chu-_ship___") | |
179 | - let destURL = destinationDir.appendingPathComponent("ちゅーちゅー") | |
201 | + let tempURL = originalDir.appendingPathComponent(ViewController.tempDirName) | |
202 | + let destURL = destinationDir.appendingPathComponent(ViewController.chuchu) | |
180 | 203 | |
181 | 204 | let swfs = try FileManager.default |
182 | 205 | .contentsOfDirectory(at: tempURL, includingPropertiesForKeys: nil) |