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?