diff options
author | Indrajith K L | 2022-12-03 17:00:20 +0530 |
---|---|---|
committer | Indrajith K L | 2022-12-03 17:00:20 +0530 |
commit | f5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch) | |
tree | 2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/old/vlib/os/os_android.c.v | |
download | cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2 cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip |
Diffstat (limited to 'v_windows/v/old/vlib/os/os_android.c.v')
-rw-r--r-- | v_windows/v/old/vlib/os/os_android.c.v | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/v_windows/v/old/vlib/os/os_android.c.v b/v_windows/v/old/vlib/os/os_android.c.v new file mode 100644 index 0000000..30825ea --- /dev/null +++ b/v_windows/v/old/vlib/os/os_android.c.v @@ -0,0 +1,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 +} |