Game Development Reference
In-Depth Information
of TZipDirFileHeader structures. Note that there is a length of this array already
stored in the TZipDirHeader . This is important because there ' s actually a little
extra data stored in between each TZipDirFileHeader . It is variable length data
and contains the filename, comments, and other extras.
Enough memory is allocated to store the directory, and it is read in one chunk. The
data is then processed a bit. All the signatures are checked, the UNIX slashes are
converted to backslashes, and the pointers to each entry in the directory are set for
quick access. The filenames are also stored in an STL map for quick lookup. The
ReadFile method takes the index number of the file you want to read and a pointer
to the memory you
ll call GetFileLen
to find the size of the buffer and allocate enough memory to hold the file. It reads and
decompresses the entire file at once in a blocking call, which could be bad if you have a
large compressed file inside the Zip file. If you want to decompress something larger,
use the ReadLargeFile method. It has the same parameters as ReadFile has, and
it adds a function pointer to a callback method. This lets you show a progress bar as
the file is loaded, and it also allows a cancel button to stop the decompression
midstream.
One thing is a matter of taste for Windows programmers: Under UNIX operating
systems, filenames are case sensitive, which means that you could have two filenames
in the same directory that differ only in case. The same thing is true of Zip files, and
while it is not exactly perfect form to convert all filenames to lowercase before you
compare names, it sure makes it easier on you and the development team. An artist
might name a file Allbricks.bmp, and a programmer might expect it to be named
Allbricks.bmp. If you don ' t force the names to lowercase, the class will think the file
doesn
'
ve preallocated. Prior to calling this method, you
'
t exist.
With this class, you can iterate through all of the files packed in the Zip, find their
names, read and decompress the file data, and use the data in your game. Here
'
'
san
example:
char *buffer = NULL;
ZipFile zipFile;
if (zipFile.Init(resFileName))
{
optional<int> index = zipFile.Find(path);
if (index.valid())
{
int size = zipFile->GetFileLen(*index);
buffer = new char[size];
Search WWH ::




Custom Search