diff options
| author | Ben Beltran <ben@nsovocal.com> | 2019-04-14 16:08:54 +0200 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2019-04-14 16:08:54 +0200 |
| commit | fdafe0d4012af00e0d9cb613a0146924b8fd8eaf (patch) | |
| tree | 6e1b145d57e5f3da54a3ddb57e40fbf6b9a2d752 /Sources/configuration.swift | |
| parent | 38d5d6de414ad69d6a7dc744e4aed39c488ba30f (diff) | |
Update swift files to use Bariloche
Diffstat (limited to 'Sources/configuration.swift')
| -rw-r--r-- | Sources/configuration.swift | 70 |
1 files changed, 0 insertions, 70 deletions
diff --git a/Sources/configuration.swift b/Sources/configuration.swift deleted file mode 100644 index 05e2802..0000000 --- a/Sources/configuration.swift +++ /dev/null @@ -1,70 +0,0 @@ -import Foundation - -// Reads and writes the configuration. Config keys are accessed as a dictionary. -class Configuration { - // Location of the global configuration file - private let configurationPath = NSString(string: "~/.lyricli.conf").expandingTildeInPath - - // Default options, will be automatically written to the global config if - // not found. - private var configuration: [String: Any] = [ - "enabled_sources": ["arguments", "itunes", "spotify"] - ] - - // The shared instance of the object - static let shared: Configuration = Configuration() - - private init() { - - // Read the config file and attempt to set any of the values. Otherwise - // don't do anything. - - if let data = try? NSData(contentsOfFile: configurationPath) as Data { - if let parsedConfig = try? JSONSerialization.jsonObject(with: data) { - if let parsedConfig = parsedConfig as? [String: Any] { - for (key, value) in parsedConfig { - - if key == "enabled_sources" { - if let value = value as? [String] { - configuration[key] = value - } - } else { - if let value = value as? String { - configuration[key] = value - } - } - } - } - } - } - - writeConfiguration() - } - - // Write the configuration back to the file - private func writeConfiguration() { - - var error: NSError? - - if let outputStream = OutputStream(toFileAtPath: configurationPath, append: false) { - outputStream.open() - JSONSerialization.writeJSONObject(configuration, - to: outputStream, - options: [JSONSerialization.WritingOptions.prettyPrinted], - error: &error) - outputStream.close() - } - } - - // Allow access to the config properties as a dictionary - subscript(index: String) -> Any? { - get { - return configuration[index] - } - - set(newValue) { - configuration[index] = newValue - writeConfiguration() - } - } -} |