Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


#Actualpolyfrag

Posted 28 March 2013 - 12:09 AM

Here's how I load files into memory from the APK:

CFile::CFile(const char* filepath)
{
	data = NULL;
	fsize = 0;
	position = 0;

	//zip_file* file = zip_fopen(APKArchive, filepath, 0);
	AAsset* asset_file = AAssetManager_open(g_amgr, filepath, AASSET_MODE_UNKNOWN); 

	//if(!file)
	if(!asset_file)
		return;

	unsigned char buff[256];
	unsigned char* oldbuf = NULL;
	unsigned char* newbuf = NULL;

	int r=0;
	//while((r=zip_fread(file, buff, 256)) > 0)
	while((r = AAsset_read(asset_file, buff, 256)) > 0)
	{
		newbuf = new unsigned char[fsize+r];

		if(oldbuf)
		{
			memcpy(newbuf, oldbuf, fsize);
		}

		memcpy(&newbuf[fsize], buff, r);

		delete [] oldbuf;
		oldbuf = newbuf;

		fsize += r;
	}

	data = newbuf;

	//zip_fclose(file);
	AAsset_close(asset_file);
}

void CFile::seek(int off)
{
	position = off;
}

int CFile::read(void* to, int amt)
{
	int read = amt;

	if(read > fsize-position)
		read = fsize-position;

	memcpy(to, &data[position], read);
	position += read;

	return read;
}
class CFile
{
public:
	unsigned char* data;
	int fsize;
	int position;

	CFile();
	CFile(const char* filepath);
	~CFile();
	void seek(int off);
	void seekend();
	int read(void* to, int amt);
	int tell();
	void close();
};

 

 

Is there anything wrong with this?


#1polyfrag

Posted 28 March 2013 - 12:07 AM

Here's how I load files into memory from the APK:

CFile::CFile(const char* filepath)
{
	data = NULL;
	fsize = 0;
	position = 0;

	//zip_file* file = zip_fopen(APKArchive, filepath, 0);
	AAsset* asset_file = AAssetManager_open(g_amgr, filepath, AASSET_MODE_UNKNOWN); 

	//if(!file)
	if(!asset_file)
		return;

	unsigned char buff[256];
	unsigned char* oldbuf = NULL;
	unsigned char* newbuf = NULL;

	int r=0;
	//while((r=zip_fread(file, buff, 256)) > 0)
	while((r = AAsset_read(asset_file, buff, 256)) > 0)
	{
		newbuf = new unsigned char[fsize+r];

		if(oldbuf)
		{
			memcpy(newbuf, oldbuf, fsize);
		}

		memcpy(&newbuf[fsize], buff, r);

		delete [] oldbuf;
		oldbuf = newbuf;

		fsize += r;
	}

	data = newbuf;

	//zip_fclose(file);
	AAsset_close(asset_file);
}

CFile::~CFile()
{
	if(data)
	{
		delete [] data;
		data = NULL;
	}
}

void CFile::seek(int off)
{
	position = off;
}

void CFile::seekend()
{
	position = fsize;
}

int CFile::read(void* to, int amt)
{
	int read = amt;

	if(read > fsize-position)
		read = fsize-position;

	memcpy(to, &data[position], read);
	position += read;

	return read;
}
class CFile
{
public:
	unsigned char* data;
	int fsize;
	int position;

	CFile();
	CFile(const char* filepath);
	~CFile();
	void seek(int off);
	void seekend();
	int read(void* to, int amt);
	int tell();
	void close();
};

 

 

Is there anything wrong with this?


PARTNERS