Game Development Reference
In-Depth Information
}
if ( NewPos >= 0 && ( NewPos < Sz ) )
{ S->Seek( ( uint64 )NewPos ); }
else
{ return -1; }
return 0;
}
5.
We do not close or handle errors, so the
fclose()
and
ferror()
callbacks are
empty:
static int ZCALLBACK zip_fclose(voidpf op, voidpf s)
{ return 0; }
static int ZCALLBACK zip_ferror(voidpf op, voidpf s)
{ return 0; }
6.
Finally, the pointers to all functions are stored in the
zlib_filefunc64_def
structure that is passed instead of the usual
FILE*
to all functions of
MiniZIP
.
We write a simple routine to ill this structure, as shown in the following code:
void fill_functions( iIStream* Stream, zlib_filefunc64_def* f )
{
f->zopen64_file = zip_fopen;
f->zread_file = zip_fread;
f->zwrite_file = NULL;
f->ztell64_file = zip_ftell;
f->zseek64_file = zip_fseek;
f->zclose_file = zip_fclose;
f->zerror_file = zip_ferror;
f->opaque = Stream;
}
7.
Once we have implemented the
fopen()
interface, we can provide the code snippet
to enumerate the iles in the archive represented by the
iIStream
object. This is one
of the two essential functions in the
ArchiveReader
class:
bool ArchiveReader::Enumerate_ZIP()
{
iIStream* TheSource = FSourceFile;
zlib_filefunc64_def ffunc;
fill_functions( TheSource, &ffunc );
unzFile uf = unzOpen2_64( "", &ffunc );
unz_global_info64 gi;
int err = unzGetGlobalInfo64( uf, &gi );