-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathOtaHelpers.swift
More file actions
59 lines (47 loc) · 1.88 KB
/
Copy pathOtaHelpers.swift
File metadata and controls
59 lines (47 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
import Foundation
class OtaHelpers: NSObject {
private static func version() -> String {
let info = Bundle.main.infoDictionary
return info?["CFBundleVersion"] as? String ?? ""
}
private static func shortVersion() -> String {
let info = Bundle.main.infoDictionary
return info?["CFBundleShortVersionString"] as? String ?? ""
}
private static func identifier() -> String {
let info = Bundle.main.infoDictionary
return info?["CFBundleIdentifier"] as? String ?? ""
}
static func resolveAppVersion() -> String {
return "\(shortVersion())-\(version())"
}
static func getOtaDir() -> String {
let supportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first ?? ""
return "\(supportDirectory)/\(identifier())/\(OTA_DIR_NAME)"
}
static func getOtaManifestFilepath() -> String {
return resolveAbsolutePathRelativeToOtaDir("/\(MANIFEST_FILE_NAME)")
}
static func resolveAbsolutePathRelativeToOtaDir(_ path: String) -> String {
return "\(getOtaDir())\(path)"
}
static func readManifestAsDictionary() -> [String: Any]? {
let manifestPath = getOtaManifestFilepath()
guard let contents = NSData(contentsOfFile: manifestPath) else {
return nil
}
do {
let jsonOutput = try JSONSerialization.jsonObject(with: contents as Data, options: [])
return jsonOutput as? [String: Any]
} catch {
return nil
}
}
static func getNativeDependencies() -> [String: Any] {
guard let path = Bundle.main.path(forResource: "native_dependencies", ofType: "json"),
let data = try? NativeFsModule.readJson(path) else {
return [:]
}
return data
}
}