blob: 30825ea89eedae745ebd96ce5911389da2398b3c (
plain)
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
|
module os
struct C.AAsset {
}
struct C.AAssetManager {
}
struct C.ANativeActivity {
assetManager voidptr
}
fn C.AAssetManager_open(&C.AAssetManager, &char, int) &C.AAsset
fn C.AAsset_getLength(&C.AAsset) int
fn C.AAsset_read(&C.AAsset, voidptr, int) int
fn C.AAsset_close(&C.AAsset)
pub fn read_apk_asset(file string) ?[]byte {
act := &C.ANativeActivity(C.sapp_android_get_native_activity())
if isnil(act) {
return error('Could not get reference to Android activity')
}
asset := C.AAssetManager_open(&C.AAssetManager(act.assetManager), file.str, C.AASSET_MODE_STREAMING)
if isnil(asset) {
return error('File `$file` not found')
}
len := C.AAsset_getLength(asset)
buf := []byte{len: len}
for {
if C.AAsset_read(asset, buf.data, len) > 0 {
break
}
}
C.AAsset_close(asset)
return buf
}
|