Skip to content

Commit 5aa0ccc

Browse files
committed
Cleanup
1 parent 66d0704 commit 5aa0ccc

6 files changed

Lines changed: 645 additions & 349 deletions

File tree

AdversaryLabSwift/Base.lproj/Main.storyboard

Lines changed: 511 additions & 261 deletions
Large diffs are not rendered by default.

AdversaryLabSwift/Controllers/FileController.swift

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FileController
3838
guard let appDirectory = prepareDirectory(groupName: groupName)
3939
else
4040
{
41-
print("Failed to save the classifier, could not find the application document directory.")
41+
print("Failed to save the model, could not prepare the \(groupName) directory.")
4242
return
4343
}
4444

@@ -97,7 +97,7 @@ class FileController
9797
guard let appDirectory = prepareDirectory(groupName: groupName)
9898
else
9999
{
100-
print("Failed to save the classifier, could not find the application document directory.")
100+
print("Failed to save the classifier, could not prepare the \(groupName) directory.")
101101
return
102102
}
103103

@@ -206,6 +206,17 @@ class FileController
206206

207207
let directoryURL = appDirectory.appendingPathComponent(groupName)
208208
let bundleURL = directoryURL.appendingPathExtension("adversary")
209+
210+
if fileManager.fileExists(atPath: bundleURL.path)
211+
{
212+
do{
213+
try fileManager.removeItem(at: bundleURL)
214+
}
215+
catch let removeFileError
216+
{
217+
print("Error trying to remove file at \(bundleURL.path): \(removeFileError)")
218+
}
219+
}
209220

210221
do
211222
{
@@ -282,17 +293,21 @@ class FileController
282293
guard let appDirectory = getAdversarySupportDirectory()
283294
else
284295
{
285-
print("Failed to save the file, could not find the application document directory.")
296+
print("Failed to save the file, could not find the application support directory.")
286297
return nil
287298
}
288299

289300
let groupURL = appDirectory.appendingPathComponent(groupName)
290301

291-
guard fileManager.fileExists(atPath: groupURL.path)
292-
else
302+
if !fileManager.fileExists(atPath: groupURL.path)
293303
{
294-
print("Group directory does not exist.")
295-
return nil
304+
do {
305+
try fileManager.createDirectory(at: groupURL, withIntermediateDirectories: true, attributes: nil)
306+
} catch let createDirError {
307+
print("Failed to prepare the \(groupName) directory.")
308+
print("Received a directory creation error: \(createDirError)")
309+
return nil
310+
}
296311
}
297312

298313
do

AdversaryLabSwift/Controllers/RedisServerController.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ class RedisServerController: NSObject
258258
func runLaunchRedisScript(completion:@escaping (_ completion:Bool) -> Void)
259259
{
260260
let bundle = Bundle.main
261+
let workingDir = FileManager.default.currentDirectoryPath
261262

262263
guard let path = bundle.path(forResource: "LaunchRedisServerScript", ofType: "sh")
263264
else
@@ -270,15 +271,23 @@ class RedisServerController: NSObject
270271
guard let redisConfigPath = bundle.path(forResource: "redis", ofType: "conf")
271272
else
272273
{
273-
print("Unable to launch Redis server: could not find terraform executable.")
274+
print("Unable to launch Redis server: could not find redis executable.")
274275
completion(false)
275276
return
276277
}
277278

278279
guard let redisPath = bundle.path(forResource: "redis-server", ofType: nil)
279280
else
280281
{
281-
print("Unable to launch Redis server: could not find terraform executable.")
282+
print("Unable to launch Redis server: could not find redis-server.")
283+
completion(false)
284+
return
285+
}
286+
287+
guard let redisCliPath = bundle.path(forResource: "redis-cli", ofType: nil)
288+
else
289+
{
290+
print("Unable to launch Redis server: could not find redis-cli.")
282291
completion(false)
283292
return
284293
}
@@ -296,9 +305,10 @@ class RedisServerController: NSObject
296305
{
297306
print("🚀🚀🚀🚀🚀🚀🚀")
298307
print("Redis config path: \(redisConfigPath)")
308+
print("Working directory: \(workingDir)")
299309
self.redisProcess = Process()
300310
self.redisProcess.launchPath = path
301-
self.redisProcess.arguments = [redisPath, redisConfigPath, redisModulePath]
311+
self.redisProcess.arguments = [redisPath, redisConfigPath, redisModulePath, redisCliPath, workingDir]
302312
self.redisProcess.launch()
303313

304314
sleep(1)

AdversaryLabSwift/Controllers/SymphonyController.swift

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ class SymphonyController
3333
symphony = Symphony(root: songDirectory)
3434

3535
// Get the list of transports in the Symphony DB
36-
3736
do
3837
{
3938
let tables = try FileManager().contentsOfDirectory(at: songDirectory, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
@@ -103,18 +102,23 @@ class SymphonyController
103102
/// File management
104103
func unzipSong(sourceURL: URL) -> URL?
105104
{
106-
let fileManager = FileManager()
107-
let currentWorkingURL = URL(fileURLWithPath: fileManager.currentDirectoryPath)
108-
let destinationURL = currentWorkingURL.appendingPathComponent("adversary_data")
105+
guard let applicationSupportDir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first
106+
else {
107+
print("Unable to unzip the Song data because we could not find the application support directory.")
108+
return nil
109+
}
110+
111+
let destinationURL = applicationSupportDir.appendingPathComponent("adversary_data")
109112
do
110113
{
111114
// Overwrite any old data at this directory
112-
if fileManager.fileExists(atPath: destinationURL.path)
115+
if FileManager.default.fileExists(atPath: destinationURL.path)
113116
{
114-
try fileManager.removeItem(at: destinationURL)
117+
try FileManager.default.removeItem(at: destinationURL)
115118
}
116119

117-
try fileManager.unzipItem(at: sourceURL, to: currentWorkingURL)
120+
try FileManager.default.unzipItem(at: sourceURL, to: applicationSupportDir)
121+
118122
return destinationURL
119123
}
120124
catch

0 commit comments

Comments
 (0)