-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathStorageManager.swift
More file actions
80 lines (66 loc) · 2 KB
/
StorageManager.swift
File metadata and controls
80 lines (66 loc) · 2 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//
// StorageManager.swift
// SwiftAndroid
//
// Created by Alsey Coleman Miller on 2/27/26.
//
#if os(Android)
import Android
import CAndroidNDK
#endif
/// Wrapper around Android `AStorageManager`.
public struct StorageManager: ~Copyable {
internal let pointer: OpaquePointer
internal init(pointer: OpaquePointer) {
self.pointer = pointer
}
deinit {
AStorageManager_delete(pointer)
}
}
// MARK: - Initialization
public extension StorageManager {
/// Creates an `AStorageManager` instance.
init() throws(AndroidFileManagerError) {
guard let pointer = AStorageManager_new() else {
throw .invalidStorageManager
}
self.init(pointer: pointer)
}
}
// MARK: - OBB Methods
public extension StorageManager {
/// Asks Android to mount an OBB container.
func mountObb(path: String, key: String? = nil) {
path.withCString { pathCString in
if let key {
key.withCString { keyCString in
AStorageManager_mountObb(pointer, pathCString, keyCString, nil, nil)
}
} else {
AStorageManager_mountObb(pointer, pathCString, nil, nil, nil)
}
}
}
/// Asks Android to unmount an OBB container.
func unmountObb(path: String, force: Bool = false) {
path.withCString {
AStorageManager_unmountObb(pointer, $0, force ? 1 : 0, nil, nil)
}
}
/// Returns whether the OBB at `path` is mounted.
func isObbMounted(path: String) -> Bool {
path.withCString { rawPath in
AStorageManager_isObbMounted(pointer, rawPath) != 0
}
}
/// Returns the mounted OBB path for a raw OBB path.
func mountedObbPath(for path: String) -> String? {
path.withCString { rawPath in
guard let cString = AStorageManager_getMountedObbPath(pointer, rawPath) else {
return nil
}
return String(cString: cString)
}
}
}