示例#1
1
GLubyte* FileReader::loadTGA(const std::string &fileName, tgaHeader &header)
{
	AAsset* asset = AAssetManager_open(FileReader::manager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	if(asset == NULL)
	{
		writeLog("Asset = NULL");
	}
    AAsset_read(asset, &header.idLength, 1);
    AAsset_read(asset, &header.colorMapType, 1);
    AAsset_read(asset, &header.type, 1);
    AAsset_seek(asset, 9, SEEK_CUR);
    AAsset_read(asset, &header.width, 2);
    AAsset_read(asset, &header.height, 2);
    AAsset_read(asset, &header.depth, 1);
    AAsset_read(asset, &header.descriptor, 1);
    AAsset_seek(asset, header.idLength, SEEK_CUR);
    
	//writeLog("spritewidth: %d, height: %d, depth: %d", header.width, header.height, header.depth);

    //24bit / 8 = 3 (RGB), 32bit / 8 = 4 (RGBA)
    int componentCount = header.depth/8;
    
    int size = componentCount * header.width * header.height;
    GLubyte* data = new GLubyte[size];
    
    AAsset_read(asset, data, size);
    
    //data is now BGRA so we format it to RGBA
    for(int i = 0; i < size; i += componentCount)
    {
        GLubyte temp = data[i];
        
        //Switch red and blue
        data[i] = data[i+2];
        data[i+2] = temp;
    }
    
    AAsset_close(asset);

	return data;

}
示例#2
0
  void Sound_Buffer::init_SLES(const String &filename) {
    if(dynamic_cast<Sound_Renderer_SLES *>(&get_Sound().get_Renderer())) {
      // use asset manager to open asset by filename
      AAsset* asset = AAssetManager_open(File_Ops::get_AAssetManager(), (filename + ".wav").c_str(), AASSET_MODE_UNKNOWN);
      if(!asset)
        throw Sound_Buffer_Init_Failure();

      // open asset as file descriptor
      off_t start, length;
      int fd = AAsset_openFileDescriptor(asset, &start, &length);
      assert(0 <= fd);
      AAsset_close(asset);

      // configure audio source
      loc_fd = {SL_DATALOCATOR_ANDROIDFD, fd, start, length};
      format_mime = {SL_DATAFORMAT_MIME, NULL, SL_CONTAINERTYPE_UNSPECIFIED};
      audioSrc = {&loc_fd, &format_mime};
    }
  }
示例#3
0
文件: j_moc.c 项目: bigclean/moc
/*
 * For native implementation for java methods, if it's static method
 * belongs to class itself, then second parameter should be jclass(it
 * refers to MocClient here), otherwise, it should be jobject because
 * it's just instance of specified class.
 */
static jboolean
j_moc_init(JNIEnv *env, jobject obj,
        jobject assetManager, jstring fileStr)
{
    char *fileChars = NULL;
    if (fileStr) {
        fileChars = (char*) (*env)->GetStringUTFChars(env, fileStr, NULL);
        LOGI("moc client would to be initialized by file %s.", fileChars);
    } else {
        fileChars = "conf/mocclient.hdf";
        LOGI("moc client would to be initialized by default configurations.");
    }

    AAssetManager *manager = AAssetManager_fromJava(env, assetManager);
    assert(manager != NULL);

    AAsset *file = AAssetManager_open(manager, "conf/mocclient.hdf", AASSET_MODE_UNKNOWN);
    if (file == NULL) {
        LOGE("sepecified file does not exists in apk.");
    }

    /* read contents from config file */
    off_t bufferSize = AAsset_getLength(file);
    char *buffer     = (char*) malloc(bufferSize + 1);
    buffer[bufferSize] = 0;

    AAsset_read(file, buffer, bufferSize);

    /* close file */
    AAsset_close(file);

     moc_init_frombuf(buffer);

    /*
     * initial module calback hash table
     * but it only supports bang module currently
     */
    hash_init(&registed_callback_module_table, hash_str_hash, hash_str_comp, NULL);
    hash_insert(registed_callback_module_table, (void*) "bang", (void*) j_moc_regist_callback_bang);

    return true;
}
示例#4
0
JNIEXPORT jlong JNICALL Java_com_ly_widget_GifDrawable_loadGifAsset(JNIEnv * env, jobject  obj, jobject assetManager, jstring filepath, jarray size)
{
  int error;

  AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);
  const char *native_file_path = (*env)->GetStringUTFChars(env, filepath, 0);
  AAsset* asset = AAssetManager_open(mgr, native_file_path, AASSET_MODE_UNKNOWN);
  off_t start, length;
  fd = AAsset_openFileDescriptor(asset, &start, &length);
  bytesLeft = length;
  lseek(fd, start, SEEK_SET);
  if (fd < 0) {
    return 0;
  }
  GifFileType* gif = DGifOpen(NULL,&readFunc,&error);
  error = DGifSlurp(gif);
  (*env)->ReleaseStringUTFChars(env, filepath, native_file_path);
  AAsset_close(asset);
  return loadGif(env, gif, size);
}
示例#5
0
	bool _exists(const std::string &ipath) { // check for existance in platform-specific filesystem
		if (ipath.empty() || ipath.front() == '/' || ipath.compare(0, 2, "..") == 0 || ipath.find("/..") != String::npos) {
			return false;
		}

	    auto mngr = spjni::getAssetManager();
	    if (!mngr) {
	    	return false;
	    }

		auto path = _getAssetsPath(ipath);

	    AAsset* aa = AAssetManager_open(mngr, path.c_str(), AASSET_MODE_UNKNOWN);
	    if (aa) {
	    	AAsset_close(aa);
	    	return true;
	    }

	    return false;
	}
bool FileUtilsAndroid::isFileExist(const std::string &fileName) {
	if (fileName.empty()) {
		return false;
	}
	bool result = false;
	if (fileName[0] != '/') {
		AAsset* asset = AAssetManager_open(assetmanager, fileName.c_str(), AASSET_MODE_UNKNOWN);
		if (asset) {
			result = true;
			AAsset_close(asset);
		}
	} else {
		FILE *fp = fopen(fileName.c_str(), "r");
		if (fp) {
			fclose(fp);
			result = true;
		}
	}
	return result;
}
示例#7
0
std::string gg::Util::loadFile(const std::string &fileName)
{
	//TODO: check for invalid filenames
	AAsset* asset = AAssetManager_open(gg::AssetManager::manager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	off_t length = AAsset_getLength(asset);

	char* text = new char[length+1];
	if(AAsset_read(asset, text, length) < 1)
	{
		writeLog("File not loaded! Error! Error!");
	}

	text[length] = 0;

	AAsset_close(asset);
	text[length] = 0;
	std::string r(text);

	return r;
}
示例#8
0
bool do_file_exists(const std::string& fname)
{
	std::ifstream file(fname.c_str(), std::ios_base::binary);
	if(file.rdstate() == 0) {
        file.close();
        return true;
	}
	AAssetManager* assetManager = GetJavaAssetManager();
	AAsset* asset;
	if(fname[0] == '.' && fname[1] == '/') {
		asset = AAssetManager_open(assetManager, fname.substr(2).c_str(), AASSET_MODE_UNKNOWN);
	} else {
		asset = AAssetManager_open(assetManager, fname.c_str(), AASSET_MODE_UNKNOWN);
	}
    if(asset) {
        AAsset_close(asset);
        return true;
    }
    return false;
}
示例#9
0
int getFileDescriptor(const char * filename, off_t & start, off_t & length)
{
	JniMethodInfo methodInfo;
	if (! getStaticMethodInfo(methodInfo, ASSET_MANAGER_GETTER, "()Landroid/content/res/AssetManager;"))
	{
		methodInfo.env->DeleteLocalRef(methodInfo.classID);
		return FILE_NOT_FOUND;
	}
	jobject assetManager = methodInfo.env->CallStaticObjectMethod(methodInfo.classID, methodInfo.methodID);
	methodInfo.env->DeleteLocalRef(methodInfo.classID);

	AAssetManager* (*AAssetManager_fromJava)(JNIEnv* env, jobject assetManager);
	AAssetManager_fromJava = (AAssetManager* (*)(JNIEnv* env, jobject assetManager))
		dlsym(s_pAndroidHandle, "AAssetManager_fromJava");
	AAssetManager* mgr = AAssetManager_fromJava(methodInfo.env, assetManager);
	assert(NULL != mgr);

	AAsset* (*AAssetManager_open)(AAssetManager* mgr, const char* filename, int mode);
	AAssetManager_open = (AAsset* (*)(AAssetManager* mgr, const char* filename, int mode))
		dlsym(s_pAndroidHandle, "AAssetManager_open");
	AAsset* Asset = AAssetManager_open(mgr, filename, AASSET_MODE_UNKNOWN);
	if (NULL == Asset)
	{
		LOGD("file not found! Stop preload file: %s", filename);
		return FILE_NOT_FOUND;
	}

	// open asset as file descriptor
	int (*AAsset_openFileDescriptor)(AAsset* asset, off_t* outStart, off_t* outLength);
	AAsset_openFileDescriptor = (int (*)(AAsset* asset, off_t* outStart, off_t* outLength))
		dlsym(s_pAndroidHandle, "AAsset_openFileDescriptor");
	int fd = AAsset_openFileDescriptor(Asset, &start, &length);
	assert(0 <= fd);

	void (*AAsset_close)(AAsset* asset);
	AAsset_close = (void (*)(AAsset* asset))
		dlsym(s_pAndroidHandle, "AAsset_close");
	AAsset_close(Asset);

	return fd;
}
char* _spUtil_readFile (const char* path, int* length) {

	AAssetManager* assetManager = (AAssetManager*) get_asset_manager();

	AAsset* asset = AAssetManager_open(assetManager, (const char *) path, AASSET_MODE_UNKNOWN);

	if (NULL == asset) {
		__android_log_print(ANDROID_LOG_ERROR, "SpineAndroid", "Asset (%s) not found", path);
		return NULL;
	}

	long size = AAsset_getLength(asset);

	*length = size;

	char* buffer = (char*) malloc (sizeof(char)*size);
	AAsset_read (asset,buffer,size);
	AAsset_close(asset);

	return buffer;
}
static void assetReadSync(JXValue *results, int argc) {
  char *filename = JX_GetString(&results[0]);

  AAsset *asset =
      AAssetManager_open(assetManager, filename, AASSET_MODE_UNKNOWN);

  free(filename);
  if (asset) {
    off_t fileSize = AAsset_getLength(asset);
    void *data = malloc(fileSize);
    int read_len = AAsset_read(asset, data, fileSize);

    JX_SetBuffer(&results[argc], (char *)data, read_len);
    free(data);
    AAsset_close(asset);
    return;
  }

  const char *err = "File doesn't exist";
  JX_SetError(&results[argc], err, strlen(err));
}
示例#12
0
GAE_File_t* GAE_File_close(GAE_File_t* file, const GAE_FILE_CLOSE_MODE mode, GAE_FILE_STATUS* status) {
	GAE_PlatformFile_t* platform = (GAE_PlatformFile_t*)file->platformFile;

	if (file->fileStatus != GAE_FILE_OPEN) {
		if (0 != status)
			*status = GAE_FILE_ERROR;
		return file;
	}
	
	if (0 == platform->file) {
		if (0 != status)
			*status = GAE_FILE_ERROR;
		return file;
	}
	
	if (0 != platform->file) {
		fclose(platform->file);
		platform->file = 0;
	}

	if (0 != platform->asset) {
		AAsset_close(platform->asset);
		platform->asset = 0;
	}
	
	file->fileStatus = GAE_FILE_CLOSED;
	if (0 != status)
		*status = file->fileStatus;
	
	if (mode == GAE_FILE_CLOSE_DELETE_DATA) {
		if (GAE_TRUE == file->owned) {
			free(file->buffer);
			file->buffer = 0;
			file->owned = GAE_FALSE;
			file->bufferSize = 0U;
		}
	}
	
	return file;
}
示例#13
0
bool IsFile(const tstring& sPath)
{
	InitializeAssetManager();

	AAsset* pAsset = AAssetManager_open(g_pAssetManager, sPath.c_str(), AASSET_MODE_STREAMING);
	if (pAsset)
	{
		AAsset_close(pAsset);
		return true;
	}

	struct stat stFileInfo;
	bool blnReturn;
	int intStat;

	// Attempt to get the file attributes
	intStat = stat(sPath.c_str(), &stFileInfo);
	if(intStat == 0 && S_ISREG(stFileInfo.st_mode))
		return true;
	else
		return false;
}
bool FileUtilsAndroid::isFileExistInternal(const std::string& strFilePath) const
{
    if (strFilePath.empty())
    {
        return false;
    }

    bool bFound = false;
    
    // Check whether file exists in apk.
    if (strFilePath[0] != '/')
    {
        const char* s = strFilePath.c_str();

        // Found "assets/" at the beginning of the path and we don't want it
        if (strFilePath.find(_defaultResRootPath) == 0) s += strlen("assets/");

        if (FileUtilsAndroid::assetmanager) {
            AAsset* aa = AAssetManager_open(FileUtilsAndroid::assetmanager, s, AASSET_MODE_UNKNOWN);
            if (aa)
            {
                bFound = true;
                AAsset_close(aa);
            } else {
                // CCLOG("[AssetManager] ... in APK %s, found = false!", strFilePath.c_str());
            }
        }
    }
    else
    {
        FILE *fp = fopen(strFilePath.c_str(), "r");
        if(fp)
        {
            bFound = true;
            fclose(fp);
        }
    }
    return bFound;
}
示例#15
0
文件: main.c 项目: seishuku/gauges
int LoadShader(GLuint Shader, char *Filename)
{
	AAsset *stream;
	char *buffer;
	int length;

	if((stream=AAssetManager_open(assetManager, Filename, AASSET_MODE_BUFFER))==NULL)
		return 0;

	length=AAsset_getLength(stream);

	buffer=(char *)malloc(length+1);
	AAsset_read(stream, buffer, length);
	buffer[length]='\0';

	glShaderSource(Shader, 1, (const char **)&buffer, &length);

	AAsset_close(stream);
	free(buffer);

	return 1;
}
/********************************************************************
 * Test for asset
 *******************************************************************/
void test_apk(struct android_app* state)
{
    AAssetManager* mgr = state->activity->assetManager;
    AAsset* asset = AAssetManager_open(mgr,
                                       "f**k.txt", AASSET_MODE_UNKNOWN);

    if(asset == NULL)
    {
        LOGI("assets == NULL");
    }

    off_t size = AAsset_getLength(asset);
    LOGI("size=%d",size);

    char* buffer = new char[size+1];
    buffer[size] = 0;

    int num_read = AAsset_read(asset, buffer, size);
    //LOGI(buffer);

    AAsset_close(asset);
}
示例#17
0
//--------------------------------------------------------------------------
VeAssetPath::ReadTask::ReadTask(const VeChar8* pcFullPath,
	VeRefNode<ReadCallback>& kCallback) noexcept
	: m_kFullPath(pcFullPath)
{
	IncRefCount();
	m_kNode.m_Content = this;
	ve_sys.Collect(m_kNode);
	m_kCallback.attach_back(kCallback);
	m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
	{
		AAsset* pkAsset = AAssetManager_open(s_pkAssetManager,
			m_kFullPath, AASSET_MODE_UNKNOWN);
		if (pkAsset)
		{
			VeInt32 i32Len = AAsset_getLength(pkAsset);
			if (i32Len)
			{
				VeBlobPtr spBlob = VE_NEW VeBlob(i32Len);
				VeInt32 i32Read = AAsset_read(pkAsset,
					spBlob->GetBuffer(), i32Len);
				if (i32Read == i32Len)
				{
					m_spData = VE_NEW VeMemoryIStream(spBlob);
				}
			}
			AAsset_close(pkAsset);
		}
		m_kTask.m_Content = [this](VeTaskQueue& kMgr) noexcept
		{
			for (auto call : m_kCallback)
			{
				call(m_spData);
			}
			DecRefCount();
		};
		kMgr.AddFGTask(m_kTask);
	};
	ve_res_mgr.GetTaskQueue(VeResourceManager::TASK_FILE).AddBGTask(m_kTask);
}
示例#18
0
  void MemoryBuffer::unlock()
  {
    #if defined(CHR_FS_APK)
      if (asset)
      {
        AAsset_close(asset);
        asset = nullptr;
      }
    #elif defined(FS_JS_EMBED) || defined(FS_JS_PRELOAD)
      if (_data && _size)
      {
        munmap(_data, _size);
      }
    #endif

    #if defined(CHR_FS_APK) || defined(FS_JS_EMBED) || defined(FS_JS_PRELOAD)
      _size = 0;
      _data = nullptr;

      locked = false;
    #endif
  }
示例#19
0
Ogre::DataStreamPtr CFileManager::openDataStream(const std::string& fileName) {
  Ogre::DataStreamPtr stream;
#if OGRE_PLATFORM == OGRE_PLATFORM_ANDROID
  AAsset* asset = AAssetManager_open(mNativeActivity->assetManager, fileName.c_str(), AASSET_MODE_BUFFER);
  if(asset) {
    off_t length = AAsset_getLength(asset);
    void* membuf = OGRE_MALLOC(length, Ogre::MEMCATEGORY_GENERAL);
    memcpy(membuf, AAsset_getBuffer(asset), length);
    AAsset_close(asset);
      
    stream = Ogre::DataStreamPtr(new Ogre::MemoryDataStream(membuf, length, true, true));
  }
#else
  // first one gives a memory leak
  //stream = Ogre::DataStreamPtr(new Ogre::FileStreamDataStream(new std::fstream(fileName)));
  // second one results in strange crash (segmentation fault on closing)
  //stream = Ogre::DataStreamPtr(new Ogre::FileStreamDataStream(OGRE_NEW_T( std::fstream, Ogre::MEMCATEGORY_GENERAL )( fileName.c_str(), std::fstream::in ) ));
  // this one works
  stream = Ogre::DataStreamPtr(new Ogre::FileHandleDataStream(fopen(fileName.c_str(), "r")));
#endif
  return stream;
}
/*
 * load text content from asset
 */
std::string loadContentFromAsset(std::string fname) {
    std::string content;
    /*
     * read squirrel script from asset
     */
    AAssetManager* mgr = engine->app->activity->assetManager;
    if (mgr == NULL) {
        engine->setLastError(ERR_SCRIPT_LOAD);
        LOGE("loadScriptFromAsset: failed to load AAssetManager");
        return content;
    }

    AAsset* asset = AAssetManager_open(mgr, fname.c_str(), AASSET_MODE_UNKNOWN);
    if (asset == NULL) {
        engine->setLastError(ERR_SCRIPT_OPEN);
        LOGW("loadScriptFromAsset: failed to open main script file");
        LOGW(fname.c_str());
        return content;
    }

    off_t length = AAsset_getLength(asset);
    char* buffer = new char[length + 1];

    for (int i = 0; i < length; i++) {
        SQChar c;
        if (AAsset_read((AAsset*) asset, &c, 1) > 0) {
            buffer[i] = c;
        }
    }
    buffer[length] = NULL;

    content = buffer;
    delete buffer;

    AAsset_close(asset);

    return content;
}
示例#21
0
SDL_RWops * AAsset_RWFromAsset(AAssetManager *mgr, const char *filename)
{
	AAsset *asset = AAssetManager_open(mgr, filename, AASSET_MODE_RANDOM);

	if (!asset)
		return NULL;
	
	SDL_RWops *ops = SDL_AllocRW();
	
	if (!ops)
	{
		AAsset_close(asset);
		return NULL;
	}
	
	ops->hidden.unknown.data1 = asset;
	ops->read = aa_rw_read;
	ops->write = NULL;
	ops->seek = aa_rw_seek;
	ops->close = aa_rw_close;
	
	return ops;
}
	FileInfoListPtr APKFileSystemArchive::listFileInfo(bool recursive, bool dirs)
	{
		FileInfoListPtr files(new FileInfoList);
		std::map<String, std::vector< String > >::iterator iter = mFiles.find( mName );
		std::vector< String > fileList = iter->second;
		for( size_t i = 0; i < fileList.size(); i++ )
		{
			AAsset* asset = AAssetManager_open(mAssetMgr, (mPathPreFix + fileList[i]).c_str(), AASSET_MODE_UNKNOWN);
			if(asset)
			{
				FileInfo info;
				info.archive = this;
				info.filename = fileList[i];
				info.path = mName;
				info.basename = fileList[i];
				info.compressedSize = AAsset_getLength(asset);
				info.uncompressedSize = info.compressedSize;
				files->push_back(info);
				AAsset_close(asset);
			}
		}
		return files;
	}
示例#23
0
std::string ResourceLoader::loadLuaScript(const std::string &scriptname) {
	const std::string &filename = scriptname + ".lua";
	AssetLoader *loader = AssetLoader::instance();
    AAsset *asset = loader->open(filename);

    // the asset might not be found
    if (NULL == asset) {
		DEBUGLOG("Asset not found: %s", filename.c_str());
		return NULL;
    }

	size_t length = AAsset_getLength(asset);
	const char *buffer = (char *)AAsset_getBuffer(asset);

	std::string script(buffer, length);

	if (buffer = NULL) {
		DEBUGLOG("Buffer is empty");
	}

	AAsset_close(asset);
	return script;
}
示例#24
0
/*
 * sqlite3_vfs.xAccess - tests if file exists and/or can be read.
 * Implemented using AAssetManager_open
 */
static int ndkAccess(sqlite3_vfs *pVfs, const char *zPath, int flags,
		int *pResOut)
{
	const ndk_vfs* ndk = (ndk_vfs*) pVfs;

	*pResOut = 0;

	switch (flags)
	{
	case SQLITE_ACCESS_EXISTS:
	case SQLITE_ACCESS_READ:
		AAsset* asset = AAssetManager_open(ndk->mgr, zPath, AASSET_MODE_RANDOM);
		if (asset)
		{
			AAsset_close(asset);
			*pResOut = 1;
		}

		break;
	}

	return SQLITE_OK;
}
示例#25
0
JNIEXPORT jlong JNICALL
Java_org_gearvrf_NativeBaseTexture_fileConstructor(JNIEnv * env,
        jobject obj, jobject asset_manager, jstring filename, jintArray jtexture_parameters) {

    jint* texture_parameters = env->GetIntArrayElements(jtexture_parameters,0);

    const char* native_string = env->GetStringUTFChars(filename, 0);
    AAssetManager* mgr = AAssetManager_fromJava(env, asset_manager);
    AAsset* asset = AAssetManager_open(mgr, native_string, AASSET_MODE_UNKNOWN);
    if (NULL == asset) {
        LOGE("_ASSET_NOT_FOUND_");
        return JNI_FALSE;
    }

    PngLoader loader;
    loader.loadFromAsset(asset);

    AAsset_close(asset);
    env->ReleaseStringUTFChars(filename, native_string);

    if (loader.pOutImage.bits == NULL) {
        LOGE("PNG decoder failed");
        return JNI_FALSE;
    }

    if (loader.pOutImage.format != PngLoader::RGBAFormat) {
        LOGE("Only RGBA format supported");
        return JNI_FALSE;
    }

    int imgW = loader.pOutImage.width;
    int imgH = loader.pOutImage.height;
    unsigned char *pixels = loader.pOutImage.bits;
    jlong result = reinterpret_cast<jlong>(new BaseTexture(imgW, imgH, pixels, texture_parameters));
    env->ReleaseIntArrayElements(jtexture_parameters, texture_parameters, 0);
    return result;
}
示例#26
0
std::string FileReader::loadFile(const std::string &fileName)
{	
	//TODO: check for invalid filenames
	asset = AAssetManager_open(FileReader::manager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	writeLog("%s", fileName.c_str());
	if(asset == NULL)
	{
		writeLog("Asset = NULL");
	}

	_length = AAsset_getLength(asset);
	writeLog("FILE SIZE: %u", _length);
	char* text = new char[_length];
	if(AAsset_read(asset, text, _length) < 0)
	{
		writeLog("File not loaded! Error! Error!");
	}

	AAsset_close(asset);
	std::string r(text, _length);
	delete[] text;

	return r;
}
JNIEXPORT jboolean JNICALL Java_com_adobe_plugins_FastCanvasJNI_addPngTexture
  (JNIEnv *je, jclass jc, jobject assetManager, jstring path, jint id, jobject dim)
{
	bool success = false;
    Canvas *theCanvas = Canvas::GetCanvas();
    if (theCanvas) {
		AAssetManager* mgr = AAssetManager_fromJava(je, assetManager);
		if (mgr == NULL) return false;

        const char *p = je->GetStringUTFChars(path, 0);
		AAsset* asset = AAssetManager_open(mgr, p, AASSET_MODE_UNKNOWN);
        je->ReleaseStringUTFChars(path, p);
		if (asset == NULL) return false;

		long size = AAsset_getLength(asset);
		unsigned char* buffer = (unsigned char*) malloc (size);
		if (buffer == NULL) return false;

		AAsset_read (asset, buffer, size);
		AAsset_close(asset);

		unsigned int width;
		unsigned int height;
        success = theCanvas->AddPngTexture(buffer, size, id, &width, &height);
		free (buffer);

		if (success) {
			jclass cls = je->GetObjectClass(dim);  
			jfieldID wID = je->GetFieldID(cls, "width", "I");
			je->SetIntField(dim, wID, (int)width);
			jfieldID hID = je->GetFieldID(cls, "height", "I");
			je->SetIntField(dim, hID, (int)height);
		}
    }
	return success;
}
示例#28
0
char *NvAssetLoaderRead(const char *filePath, int32_t &length)
{
    char *buff = NULL;

    if (!s_assetManager)
        return NULL;

    AAsset *fileAsset = AAssetManager_open(s_assetManager, filePath, AASSET_MODE_BUFFER);

    if(fileAsset != NULL)
    {
        length = AAsset_getLength(fileAsset);
        buff = new char[length+1];
        int32_t numBytes = AAsset_read(fileAsset, buff, length);
        buff[length] = '\0';

        LOGI("Read asset '%s', %d bytes", filePath, numBytes);
        //LOGI(" %s\n", buff);

        AAsset_close(fileAsset);
    }

    return buff;
}
示例#29
0
void ExportAssets( void )
{
	AAssetManager* mgr;
	mgr = engine.app->activity->assetManager;
	AAssetDir* assetDir = AAssetManager_openDir(engine.app->activity->assetManager, "");
	const char* filename = (const char*)NULL;
	while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
		AAsset* asset = AAssetManager_open(mgr, filename, AASSET_MODE_STREAMING);
		char buf[BUFSIZ];
		int nb_read = 0;
		//LOGI( "Asset:[%s]", filename );
		FILE* out = OpenFile(filename);
		if( out )
		{
			while ((nb_read = AAsset_read(asset, buf, BUFSIZ)) > 0)
				fwrite(buf, nb_read, 1, out);
			fclose(out);
		}
		else
			LOGI( "Failed to open asset copy: %s", filename );
		AAsset_close(asset);
	}
	AAssetDir_close(assetDir);
}
示例#30
0
SDL_RWops* read_sdl_rw_from_asset(const std::string& name)
{
	AAssetManager* assetManager = GetJavaAssetManager();
	AAsset* asset;
	if(name[0] == '.' && name[1] == '/') {
		asset = AAssetManager_open(assetManager, name.substr(2).c_str(), AASSET_MODE_RANDOM);
	} else {
		asset = AAssetManager_open(assetManager, name.c_str(), AASSET_MODE_RANDOM);
	}
    if(!asset) {
        return 0;
    }
    SDL_RWops* ops = SDL_AllocRW();
    if(!ops) {
        AAsset_close(asset);
        return 0;
    }
	ops->hidden.unknown.data1 = asset;
	ops->read = aa_rw_read;
	ops->write = NULL;
	ops->seek = aa_rw_seek;
	ops->close = aa_rw_close;
	return ops;
}