Game Development Reference
In-Depth Information
the file before and after compression. Each file in the Zip file has a local header
stored just before the compressed file data. It stores much of the same data as the
TZipDirFileHeader structure.
One fine example of reading a Zip file comes from Javier Arevalo. I
ve modified it
only slightly to work well with the rest of the source code in this topic. The basic
premise of the solution is to open a Zip file, read the directory into memory, and
use it to index the rest of the file. Here is the definition for the ZipFile class:
'
// This maps a path to a zip content id
typedef std::map<std::string, int> ZipContentsMap;
class ZipFile
{
public:
ZipFile() { m_nEntries=0; m_pFile=NULL; m_pDirData=NULL; }
Virtual ~ZipFile() { End(); fclose(m_pFile); }
bool Init(const std::wstring &resFileName);
void End();
int GetNumFiles()const { return m_nEntries; }
std::string GetFilename(int i) const;
int GetFileLen(int i) const;
bool ReadFile(int i, void *pBuf);
// Added to show multi-threaded decompression
bool ReadLargeFile(int i, void *pBuf, void (*progressCallback)(int, bool &));
optional<int> Find(const std::string &path) const;
ZipContentsMap m_ZipContentsMap;
private:
struct TZipDirHeader;
struct TZipDirFileHeader;
struct TZipLocalHeader;
FILE *m_pFile; // Zip file
char *m_pDirData; // Raw data buffer.
int m_nEntries;
// Number of entries.
// Pointers to the dir entries in pDirData.
const TZipDirFileHeader **m_papDir;
};
Search WWH ::




Custom Search