30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
private var path: OFString
private var storage: [String: [NSNumber: AnyObject]]
private var sites: [String]
override init() {
let fileManager = OFFileManager.default
let userDataPath = OFSystemInfo.userDataPath!
if !fileManager.directoryExists(atPath: userDataPath) {
fileManager.createDirectory(atPath: userDataPath)
}
let path = userDataPath.appendingPathComponent(
OFString(utf8String: "sites.msgpack"))
var storage: [String: [NSNumber: AnyObject]]? = nil
OFException.try({
let decoded = (OFData(contentsOfFile: path)
.objectByParsingMessagePack)
as? OFDictionary<OFString, OFDictionary<OFNumber, AnyObject>>
storage =
(decoded?.nsObject as? [String: [NSNumber: AnyObject]]) ?? [:]
}, catch: { (OFException) in
storage = [:]
})
self.path = path
self.storage = storage!
self.sites = self.storage.keys.sorted()
}
func sites(withFilter filter: String?) -> [String] {
return storage.keys.sorted().filter({ (name) in
if let filter = filter {
return name.localizedCaseInsensitiveContains(filter)
}
return true
})
}
func hasSite(_ name: String) -> Bool {
return (storage[name] != nil)
}
|
|
|
|
|
|
<
|
|
|
|
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
private var path: OFString
private var storage: [String: [NSNumber: AnyObject]]
private var sites: [String]
override init() {
let fileManager = OFFileManager.default
let userDataURL = OFSystemInfo.userDataURL!
if !fileManager.directoryExists(at: userDataURL) {
fileManager.createDirectory(at: userDataURL)
}
let URL = userDataURL.appendingPathComponent(
OFString(utf8String: "sites.msgpack"))
var storage: [String: [NSNumber: AnyObject]]? = nil
OFException.try({
let decoded = (OFData(contentsOf: URL).objectByParsingMessagePack)
as? OFDictionary<OFString, OFDictionary<OFNumber, AnyObject>>
storage =
(decoded?.nsObject as? [String: [NSNumber: AnyObject]]) ?? [:]
}, catch: { (OFException) in
storage = [:]
})
self.path = URL.fileSystemRepresentation!
self.storage = storage!
self.sites = self.storage.keys.sorted()
}
func sites(withFilter filter: String?) -> [String] {
return storage.keys.sorted().filter({ (name) in
if filter == nil || filter!.isEmpty {
return true
}
return name.localizedCaseInsensitiveContains(filter!)
})
}
func hasSite(_ name: String) -> Bool {
return (storage[name] != nil)
}
|