//int AAsset_openFileDescriptor(AAsset* asset, off_t* outStart, off_t* outLength); //int AAsset_isAllocated(AAsset* asset); //const void* AAsset_getBuffer(AAsset* asset); CX_METHOD_DEF(cxMMapStream,Open,cxBool) { CX_ASSERT(this->cxStream.isOpen == false,"stream repeat open"); cxConstChars path = cxStringBody(this->cxStream.path); this->asset = AAssetManager_open(cxEngineGetAssetManager(), path, AASSET_MODE_UNKNOWN); if(this->asset == NULL){ CX_ERROR("open asset file %s failed",path); return false; } this->map = (cxAny)AAsset_getBuffer(this->asset); if(this->map == NULL){ CX_ERROR("asset get buffer error"); return false; } this->off = 0; this->cxStream.Length = (cxInt)AAsset_getLength(this->asset); this->cxStream.canRead = true; this->cxStream.canSeek = true; this->cxStream.canWrite = false; this->cxStream.isOpen = true; return true; }
// #include <android/asset_manager.h> #include <unistd.h> #include <sys/stat.h> #include <core/cxUtil.h> #include <streams/cxAssetsStream.h> #include <streams/cxAssetsLuaImp.c> #include "cxAndroid.h" static cxBool cxAssetsStreamOpen(cxAny this) { cxAssetsStream asserts = this; CX_ASSERT(asserts->super.isOpen == false,"stream repeat open"); cxConstChars path = cxStringBody(asserts->super.path); asserts->asset = AAssetManager_open(cxEngineGetAssetManager(), path, AASSET_MODE_UNKNOWN); if(asserts->asset == NULL){ CX_ERROR("open asset file %s failed",path); return false; } asserts->super.length = (cxInt)AAsset_getLength(asserts->asset); asserts->super.canRead = true; asserts->super.canSeek = true; asserts->super.canWrite = false; asserts->super.isOpen = true; return true; } static cxInt cxAssetsStreamRead(cxAny this,cxPointer buffer,cxInt size) { cxAssetsStream asserts = this;