Beispiel #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;

}
Beispiel #2
0
	void ReadFileAsset(const tstring & path, star::SerializedData & data)
	{
		auto app = star::StarEngine::GetInstance()->GetAndroidApp();
		auto manager = app->activity->assetManager;
		AAsset* asset = AAssetManager_open(
				manager,
				star::string_cast<sstring>(path.c_str()).c_str(),
				AASSET_MODE_UNKNOWN
				);
		star::Logger::GetInstance()->Log(asset != NULL,
			_T("Couldn't find '") + path + _T("'."));
		data.size = AAsset_getLength(asset);
		data.data = new schar[sizeof(schar) * data.size];
		AAsset_read(asset, data.data, data.size);
		AAsset_close(asset);
	}
Beispiel #3
0
bool FileReader::read(unsigned int count, void*buffer)
{
	writeLog("%d %x %x", count, buffer, asset);
	if(asset != nullptr)
	{
		writeLog("not null or sumthin");
		if(AAsset_read(asset, buffer,count) >=0)
		{
			writeLog("everything went better than expedition");
			return true;
		}
	}

	writeLog("Null asset");
	return false;
}
size_t FileInput::read(unsigned char *buffer, size_t size)
{
	if(!m_asset || !buffer)
	{
		Console::Print(Console::Error, "Could not read from file.");
		return 0;
	}

	DEBUGPRINT("Reading %i bytes from asset %x", size, m_asset);

	int returnval = AAsset_read(m_asset, buffer, size);

	DEBUGPRINT("AAsset_read returned %i", returnval);

	return returnval;
}
Beispiel #5
0
char* Renderer::LoadKernelFromAssets(const string * path)
{
#ifdef PLATFORM_WINDOWS
	string prefix = "kernelsPC/";
#else
	string prefix = "kernels/";
#endif
	string suffix = ".glsl";
	string fPath = prefix + *path + suffix;
#ifdef PLATFORM_WINDOWS

	fPath = Renderer::GetInstance()->ASSET_PATH + fPath;

	string sCode;
	ifstream vertexShaderStream(fPath.c_str(), ios::in);
	if (vertexShaderStream.is_open())
	{
		string Line = "";
		while (getline(vertexShaderStream, Line))
		{
			sCode += "\n" + Line;
		}
		vertexShaderStream.close();
	}

	int length = sCode.length();
	char* ret = new char[length + 1];
	strcpy(ret, sCode.c_str());
	ret[length] = '\0';

	return ret;

#else

	AAssetManager* mgr = System::GetInstance()->GetEngineData()->app->activity->assetManager;

	AAsset* shaderAsset = AAssetManager_open(mgr, fPath.c_str(), AASSET_MODE_UNKNOWN);
	unsigned int length = AAsset_getLength(shaderAsset);

	char * code = new char[length + 1];

	AAsset_read(shaderAsset, (void*)code, length);
	code[length] = '\0';
	return code;

#endif
}
WRes File_Read(CSzFile *p, void *data, size_t *size)
{
  size_t originalSize = *size;
  if (originalSize == 0)
    return 0;

  #ifdef USE_WINDOWS_FILE

  *size = 0;
  do
  {
    DWORD curSize = (originalSize > kChunkSizeMax) ? kChunkSizeMax : (DWORD)originalSize;
    DWORD processed = 0;
    BOOL res = ReadFile(p->handle, data, curSize, &processed, NULL);
    data = (void *)((Byte *)data + processed);
    originalSize -= processed;
    *size += processed;
    if (!res)
      return GetLastError();
    if (processed == 0)
      break;
  }
  while (originalSize > 0);
  return 0;

  #else
  if(p->mgr)
  {
	  msg_Dbg("file read");
#ifndef ANDROID22
	  if(p->asset)
		  *size = AAsset_read(p->asset,data,originalSize);
#endif
	  if (*size == originalSize)
		return 0;
	  return -1;
  }
  else
  {
	  *size = fread(data, 1, originalSize, p->file);
	  if (*size == originalSize)
		return 0;
	  return ferror(p->file);
  }

  #endif
}
bool JniJSModulesUnbundle::isUnbundle(
    AAssetManager *assetManager,
    const std::string& assetName) {
  if (!assetManager) {
    return false;
  }

  auto magicFileName = jsModulesDir(assetName) + MAGIC_FILE_NAME;
  auto asset = openAsset(assetManager, magicFileName.c_str());
  if (asset == nullptr) {
    return false;
  }

  magic_number_t fileHeader = 0;
  AAsset_read(asset.get(), &fileHeader, sizeof(fileHeader));
  return fileHeader == htole32(MAGIC_FILE_HEADER);
}
Beispiel #8
0
///
// esFileRead()
//
//    Wrapper for platform specific File read
//
static size_t esFileRead ( esFile *pFile, int bytesToRead, void *buffer )
{
   size_t bytesRead = 0;

   if ( pFile == NULL )
   {
      return bytesRead;
   }

#ifdef ANDROID
   bytesRead = AAsset_read ( pFile, buffer, bytesToRead );
#else
   bytesRead = fread ( buffer, bytesToRead, 1, pFile );
#endif

   return bytesRead;
}
Beispiel #9
0
bool Graphics::loadFont(const char *name, FT_Face &face, FT_Byte **buffer) {
  bool result = false;
  AAssetManager *assetManager = _app->activity->assetManager;
  AAsset *fontFile = AAssetManager_open(assetManager, name, AASSET_MODE_BUFFER);
  if (fontFile) {
    off_t len = AAsset_getLength(fontFile);
    *buffer = new FT_Byte[len + 1];
    if (AAsset_read(fontFile, *buffer, len) >= 0) {
      if (!FT_New_Memory_Face(_fontLibrary, *buffer, len, 0, &face)) {
        trace("loaded freetype face %s", name);
        result = true;
      }
    }
    AAsset_close(fontFile);
  }
  return result;
}
Beispiel #10
0
	/** 
	* Load a scene from a supported 3D file format
	*
	* @param filename Name of the file (or asset) to load
	* @param flags (Optional) Set of ASSIMP processing flags
	*
	* @return Returns true if the scene has been loaded
	*/
	bool LoadMesh(const std::string& filename, int flags = defaultFlags)
	{
#if defined(__ANDROID__)
		// Meshes are stored inside the apk on Android (compressed)
		// So they need to be loaded via the asset manager

		AAsset* asset = AAssetManager_open(assetManager, filename.c_str(), AASSET_MODE_STREAMING);
		assert(asset);
		size_t size = AAsset_getLength(asset);

		assert(size > 0);
		
		void *meshData = malloc(size);
		AAsset_read(asset, meshData, size);
		AAsset_close(asset);

		pScene = Importer.ReadFileFromMemory(meshData, size, flags);

		free(meshData);
#else
		pScene = Importer.ReadFile(filename.c_str(), flags);
#endif

		if (pScene)
		{
			m_Entries.clear();
			m_Entries.resize(pScene->mNumMeshes);
			// Read in all meshes in the scene
			for (auto i = 0; i < m_Entries.size(); i++)
			{
				m_Entries[i].vertexBase = numVertices;
				numVertices += pScene->mMeshes[i]->mNumVertices;
				const aiMesh* paiMesh = pScene->mMeshes[i];
				InitMesh(&m_Entries[i], paiMesh, pScene);
			}
			return true;
		}
		else 
		{
			printf("Error parsing '%s': '%s'\n", filename.c_str(), Importer.GetErrorString());
#if defined(__ANDROID__)
			LOGE("Error parsing '%s': '%s'", filename.c_str(), Importer.GetErrorString());
#endif
			return false;
		}
	}
Beispiel #11
0
bool androidExtractAll() {
	AAssetDir* assetDir = AAssetManager_openDir(gActivity->assetManager, "");
	const char* filename = (const char*)NULL;
	std::string assetContent;
	while ((filename = AAssetDir_getNextFileName(assetDir)) != NULL) {
		std::string newPath = androidGetPath(filename);
		AAsset* asset = AAssetManager_open(gActivity->assetManager, filename,
		                                   AASSET_MODE_STREAMING);
		FLOG_DEBUG("File %s opened for extraction ...", filename );
		// Find size
		off_t assetSize = AAsset_getLength(asset);

		// Prepare input buffer
		assetContent.resize(assetSize);

		// Store input buffer
		AAsset_read(asset, &assetContent[0], assetSize);

		// Close
		AAsset_close(asset);

		// Check if file exists
		std::ifstream f(newPath.c_str());
		if (f.good()) {
			f.close();
			FLOG_DEBUG("Asset %s already extracted", filename);
		} else {
			// Prepare output buffer
			std::ofstream assetExtracted(newPath.c_str(),
			                             std::ios::out | std::ios::binary);
			if (!assetExtracted) {
				FLOG_ERROR("File %s not extracted", newPath.c_str());
				return false;
			}

			// Write output buffer into a file
			assetExtracted.write(assetContent.c_str(), assetSize);
			assetExtracted.close();

			FLOG_DEBUG("File %s extracted", filename);
		}
	}
	return true;
	AAssetDir_close(assetDir);
}
Beispiel #12
0
bool loadCompressedTexture(GLenum target, int level, GLenum internalFormat, int width,
                           int height, const std::string& fileName)
{
#if defined(SUPPORT_ANDROID)
    AAsset* asset = AAssetManager_open(ctx.assetManager, fileName.c_str(), O_RDONLY);
    if (!asset)
    {
        LOGW("Unable to open asset %s", fileName.c_str());
        return false;
    }
    off_t size = AAsset_getLength(asset);
    void* pixels = malloc(size);
    AAsset_read(asset, pixels, size);
    AAsset_close(asset);
#else // !SUPPORT_ANDROID
    int fd = open(fileName.c_str(), O_RDONLY); 

    if (fd == -1)
    {
        perror("open");
        return false;
    }

    struct stat sb;
    if (fstat(fd, &sb) == -1)
    {
        perror("stat");
        return false;
    }
    off_t size = sb.st_size;
    void* pixels = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
#endif // !SUPPORT_ANDROID

    glCompressedTexImage2D(target, level, internalFormat, width, height, 0, size, pixels);

#if defined(SUPPORT_ANDROID)
    free(pixels);
#else
    munmap(pixels, sb.st_size);
    close(fd);
#endif

    ASSERT_GL();
    return true;
}
Beispiel #13
0
bool androidExtract( const std::string& name ) {
	const char* pFile = name.c_str();
	std::string newPath = androidGetPath(pFile);
	AAssetDir* a;
	if ( androidExtracted(name.c_str()) ) {
		FLOG_DEBUG("File %s already extracted", name.c_str());
		return true;
	}

	AAsset* asset = AAssetManager_open(gActivity->assetManager, name.c_str(),
	                                   AASSET_MODE_STREAMING);
	std::string assetContent;

	if (asset != NULL) {
		// Find size
		off_t assetSize = AAsset_getLength(asset);

		// Prepare input buffer
		assetContent.resize(assetSize);

		// Store input buffer
		AAsset_read(asset, &assetContent[0], assetSize);

		// Close
		AAsset_close(asset);

		// Prepare output buffer
		std::ofstream assetExtracted(newPath.c_str(),
		                             std::ios::out | std::ios::binary);
		if (!assetExtracted) {
			FLOG_ERROR("File %s not extracted", newPath.c_str());
			return false;
		}

		// Write output buffer into a file
		assetExtracted.write(assetContent.c_str(), assetSize);
		assetExtracted.close();

		FLOG_DEBUG("File extracted");
		return true;
	} else {
		FLOG_ERROR("File %s not extracted. Returning empty string", name.c_str());
		return false;
	}
}
Beispiel #14
0
    bool CFileSystem::ReadFile(Handle file, void* pBuffer, uint32_t nNumberOfBytesToRead, uint32_t* pNumberOfBytesRead) {
        if (!file) {
            BEHAVIAC_LOGERROR("File not open");
            return 0;
        }

#if BEHAVIAC_CCDEFINE_ANDROID && (BEHAVIAC_CCDEFINE_ANDROID_VER > 8)
        size_t ret = AAsset_read((AAsset*)file, pBuffer, nNumberOfBytesToRead);
#else
        size_t ret = fread(pBuffer, 1, nNumberOfBytesToRead, (FILE*)file);
#endif

        if (pNumberOfBytesRead) {
            *pNumberOfBytesRead = ret;
        }

        return true;
    }
Beispiel #15
0
char *
VSShaderLib::textFileRead(std::string fileName) {

	char *content = NULL;

#ifndef __ANDROID_API__
	FILE *fp;

	size_t count=0;

	if (fileName != "") {
		fp = fopen(fileName.c_str(),"rt");

		if (fp != NULL) {
      
			fseek(fp, 0, SEEK_END);
			count = ftell(fp);
			rewind(fp);

			if (count > 0) {
				content = (char *)malloc(sizeof(char) * (count+1));
				count = fread(content, sizeof(char), count, fp);
				content[count] = '\0';
			}
			fclose(fp);
		}
	}
	return content;
#else
	AAsset* asset = AAssetManager_open(s_AssetManager, fileName.c_str(), AASSET_MODE_UNKNOWN);
	const char *loc = "VSShaderLib::readText";
	if (NULL == asset) {
		__android_log_print(ANDROID_LOG_ERROR, loc, "%s", "_ASSET_NOT_FOUND_");
		return content;
	}
	size_t size = (size_t)AAsset_getLength(asset);
	content = (char*)malloc(sizeof(char)*size + 1);
	AAsset_read(asset, content, size);
	content[size] = '\0';
	__android_log_print(ANDROID_LOG_DEBUG, loc, "%s", content);
	AAsset_close(asset);
	return content;
#endif
}
FileUtils::FileData FileUtils::getFileData(const char* fileName)
{
	DebugLog::print( "FileUtils::getFileData(%s)", fileName );

	AAsset* asset = AAssetManager_open(g_aassetManager, (const char *) fileName, AASSET_MODE_UNKNOWN);
    if (NULL == asset) {
        DebugLog::print("Failed !");
        return FileData();
    }

    long size = AAsset_getLength(asset);
    FileData res = findFreeFileDataSlot(size);	
    res.size = size;
    
    AAsset_read (asset, res.bytes, size);
    AAsset_close(asset);	

    return res;
}
Beispiel #17
0
void androidReadToString(const char* pFileName, std::string& fileContent) {
	assert( gActivity->assetManager );

	AAsset* pFile = AAssetManager_open(gActivity->assetManager, pFileName,
	                                   AASSET_MODE_UNKNOWN);

	if (pFile != NULL) {
		off_t fileSize = AAsset_getLength(pFile);

		fileContent.resize(fileSize);
		char* pData = new char[fileSize];
		AAsset_read(pFile, &fileContent[0], fileSize);

		AAsset_close(pFile);
		FLOG_DEBUG("File %s found", pFileName);
	} else {
		FLOG_ERROR("File %s not found", pFileName);
	}
}
Beispiel #18
0
/*
 * 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;
}
int FileAccessAndroid::get_buffer(uint8_t *p_dst, int p_length) const {


	off_t r = AAsset_read(a,p_dst,p_length);

	if (pos+p_length >len ) {
		eof=true;
	}

	if (r>=0) {

		pos+=r;
		if (pos>len) {
			pos=len;
		}

	}
	return r;

}
Beispiel #20
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;
}
static void* LoadFileFunc(const char* pFilename, char** pData, size_t &size)
{
	size = 0;
	AAsset* pAsset = AAssetManager_open(g_AssetManager, pFilename, AASSET_MODE_BUFFER);

	if(pAsset)
	{
		off_t length = AAsset_getLength(pAsset);

		if(length)
		{
			SHandle *pHandle = new SHandle();

			if(pHandle)
			{
				pHandle->size = length;
				pHandle->pData = new char[length];

				if(pHandle->pData)
				{
					if(length == AAsset_read(pAsset, pHandle->pData, length))
					{
						AAsset_close(pAsset);

						size = length;
						*pData = pHandle->pData;
						return pHandle;
					}

					delete[] pHandle->pData;
				}

				delete pHandle;
			}
		}

		AAsset_close(pAsset);
	}

	return 0;
}
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));
}
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;
}
int ReadStringAM(AAsset* asset, char * buffer, int count, int offset) {


	AAsset_seek(asset, offset, SEEK_SET);
	int r_count = AAsset_read(asset, buffer, count);

	if (r_count <= 0)
		return r_count;

	for (int i = 0; i < r_count; ++i) {
		if (buffer[i] == '\n') {
			buffer[i] = '\0';
			AAsset_seek(asset, offset + i + 1, SEEK_SET);
			return offset + i + 1;
		}
	}

	if (count == r_count && buffer[r_count - 1] != '\n')
		return 0;
	return offset + r_count + 1;
}
std::string ResourceEngineAndroid::loadLevel(std::string const& levelName) {
	//logging::Fatal() << " not implemented";
	if (!assertAssetManager())
		return "";

	const std::string fileName(getLevelPrefix() + levelName + ".xml");
	AAsset * asset = AAssetManager_open(m_assetManager, fileName.c_str(),
			AASSET_MODE_STREAMING);

	if (asset == nullptr) {
		logging::Fatal() << "Asset with name " << fileName
				<< " could not be loaded.";
		return "";
	}

	constexpr size_t buffer_size = 1024;
	int bytes_read;
	char buffer[buffer_size];
	std::string textFileString;

	while (true) {
		bytes_read = AAsset_read(asset, &buffer, buffer_size);
		if (bytes_read < 0) {
			logging::Fatal() << "Error while reading from file " << fileName;
			return "";
		} else {
			std::string bufString(buffer);
			bufString.resize(bytes_read);
			textFileString.append(bufString);

			// at the end !
			if (bytes_read < buffer_size)
				break;
		}
	}

	logging::Info() << "Completed reading of file " << fileName;

	return textFileString;
}
///
// esFileRead()
//
//    Wrapper for platform specific File read
//
static int esFileRead ( void * ioContext, void *pFile, int bytesToRead, void *buffer )
{
    int bytesRead = 0;

    if ( pFile == NULL )
    {
        return bytesRead;
    }

    LOGE("bytesToRead is %d", bytesToRead);

    if (ioContext != NULL)
    {
        bytesRead = AAsset_read ( pFile, buffer, bytesToRead );
    }
    else
    {
        bytesRead = fread ( buffer, bytesToRead, 1, pFile );
    }

    return bytesRead;
}
Beispiel #27
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);
}
s32 FileAsset::readBuffer(void* Buffer, u32 Size, u32 Count) const
{
    /* Check for valid data */
    if (!Buffer || !Size || !Count || !opened())
        return 0;
    
    /* Read buffer out of file */
    s32 Result = AAsset_read(Asset_, Buffer, Size * Count);
    
    /* Check for errors */
    if (Result < 0)
    {
        Log::error("Could not read buffer out of asset");
        return -1;
    }
    
    /* Boost seek position */
    Pos_ += Result;
    
    /* Return count of read bytes */
    return Result;
}
/********************************************************************
 * 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);
}
Beispiel #30
0
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;
}