|
Public Types | |
Read = Torque::FS::File::Read | |
Open a zip or file in a zip for reading. | |
Write = Torque::FS::File::Write | |
Open a zip or file in a zip for writing. | |
ReadWrite = Torque::FS::File::ReadWrite | |
Open a zip file for reading and writing. Note: Not valid for files in zips. | |
enum | AccessMode { Read = Torque::FS::File::Read, Write = Torque::FS::File::Write, ReadWrite = Torque::FS::File::ReadWrite } |
Access modes for zip files and files within the zip. More... | |
Public Member Functions | |
ZipArchive () | |
virtual | ~ZipArchive () |
Miscellaneous Methods | |
void | setFilename (const char *filename) |
Set the filename of the zip file. | |
const char * | getFilename () |
Get the filename of the zip file. | |
bool | isVerbose () |
Determine if the Zip code is in verbose mode. | |
void | setVerbose (bool verbose) |
Turn verbose mode on or off. | |
Archive Access Methods | |
virtual bool | openArchive (const char *filename, AccessMode mode=Read) |
Open a zip archive from a file. | |
virtual bool | openArchive (Stream *stream, AccessMode mode=Read) |
Open a zip archive from a stream. | |
virtual void | closeArchive () |
Close the zip archive and free any resources. | |
Stream Based File Access Methods | |
virtual Stream * | openFile (const char *filename, AccessMode mode=Read) |
Open a file within the zip file. | |
virtual void | closeFile (Stream *stream) |
Close a file opened through openFile(). | |
Stream * | openFileForRead (const CentralDir *fileCD) |
Open a file within the zip file for read. | |
Archiver Style File Access Methods | |
bool | addFile (const char *filename, const char *pathInZip, bool replace=true) |
Add a file to the zip. | |
bool | extractFile (const char *pathInZip, const char *filename, bool *crcFail=NULL) |
Extract a file from the zip. | |
bool | deleteFile (const char *filename) |
Delete a file from the zip. | |
Enumeration Methods | |
U32 | numEntries () const |
Get number of entries in the central directory. | |
const CentralDir & | operator[] (const U32 idx) const |
Get a central directory entry. | |
CentralDir * | findFileInfo (const char *filename) |
Find a file in the zip. | |
Protected Member Functions | |
bool | readCentralDirectory () |
void | insertEntry (ZipEntry *ze) |
void | removeEntry (ZipEntry *ze) |
ZipEntry * | findZipEntry (const char *filename) |
Stream * | createNewFile (const char *filename, Compressor *method) |
Stream * | createNewFile (const char *filename, const char *method) |
Stream * | createNewFile (const char *filename, S32 method) |
void | updateFile (ZipTempStream *stream) |
bool | rebuildZip () |
bool | copyFileToNewZip (CentralDir *cdir, Stream *newZipStream) |
bool | writeDirtyFileToNewZip (ZipTempStream *fileStream, Stream *zipStream) |
U32 | localTimeToDOSTime (const Platform::LocalTime &t) |
U32 | currentTimeToDOSTime () |
Protected Attributes | |
Stream * | mStream |
FileStream * | mDiskStream |
AccessMode | mMode |
EndOfCentralDir | mEOCD |
ZipEntry * | mRoot |
VectorPtr< ZipEntry * > | mEntries |
const char * | mFilename |
VectorPtr< ZipTempStream * > | mTempFiles |
Friends | |
class | ::ZipTestWrite |
class | ::ZipTestRead |
class | ::ZipTestMisc |
Classes | |
struct | ZipEntry |
Zip::ZipArchive::ZipArchive | ( | ) |
virtual Zip::ZipArchive::~ZipArchive | ( | ) | [virtual] |
bool Zip::ZipArchive::readCentralDirectory | ( | ) | [protected] |
ZipEntry* Zip::ZipArchive::findZipEntry | ( | const char * | filename | ) | [protected] |
Stream* Zip::ZipArchive::createNewFile | ( | const char * | filename, | |
Compressor * | method | |||
) | [protected] |
Stream* Zip::ZipArchive::createNewFile | ( | const char * | filename, | |
const char * | method | |||
) | [inline, protected] |
void Zip::ZipArchive::updateFile | ( | ZipTempStream * | stream | ) | [protected] |
bool Zip::ZipArchive::rebuildZip | ( | ) | [protected] |
bool Zip::ZipArchive::copyFileToNewZip | ( | CentralDir * | cdir, | |
Stream * | newZipStream | |||
) | [protected] |
bool Zip::ZipArchive::writeDirtyFileToNewZip | ( | ZipTempStream * | fileStream, | |
Stream * | zipStream | |||
) | [protected] |
U32 Zip::ZipArchive::localTimeToDOSTime | ( | const Platform::LocalTime & | t | ) | [protected] |
U32 Zip::ZipArchive::currentTimeToDOSTime | ( | ) | [protected] |
void Zip::ZipArchive::setFilename | ( | const char * | filename | ) |
Set the filename of the zip file.
The zip filename is used by the resource manager and for error reporting.
Note: The filename is set automatically when you open the file.
filename | Filename of the zip file |
const char* Zip::ZipArchive::getFilename | ( | ) | [inline] |
Get the filename of the zip file.
bool Zip::ZipArchive::isVerbose | ( | ) |
Determine if the Zip code is in verbose mode.
Verbose mode causes the Zip code to provide diagnostic error messages when things go wrong. It can be enabled or disabled through script by setting the $Pref::Zip::Verbose variable to true to enable it or false to disable it.
Verbose mode is mostly useful when tracking down issues with opening a zip file without having to resort to using a debugger.
Turn verbose mode on or off.
This sets the $Pref::Zip::Verbose variable.
See isVerbose() for a discussion on verbose mode.
verbose | True to enable verbose mode, false to disable |
virtual bool Zip::ZipArchive::openArchive | ( | const char * | filename, | |
AccessMode | mode = Read | |||
) | [virtual] |
Open a zip archive from a file.
The archive must be closed with closeArchive() when you are done with it.
filename | Filename of zip file to open | |
mode | Access mode. May be Read, Write or ReadWrite |
virtual bool Zip::ZipArchive::openArchive | ( | Stream * | stream, | |
AccessMode | mode = Read | |||
) | [virtual] |
Open a zip archive from a stream.
The stream must support seeking and must support the specified access mode. For example, if the stream is opened for Read you cannot specify Write to openArchive(). However, if the stream is open for ReadWrite then you can specify any one of Read, Write or ReadWrite as the mode argument to openArchive().
The archive must be closed with closeArchive() when you are done with it.
stream | Pointer to stream to open the zip archive from | |
mode | Access mode. May be Read, Write or ReadWrite |
virtual void Zip::ZipArchive::closeArchive | ( | ) | [virtual] |
Close the zip archive and free any resources.
virtual Stream* Zip::ZipArchive::openFile | ( | const char * | filename, | |
AccessMode | mode = Read | |||
) | [virtual] |
Open a file within the zip file.
The access mode can only be Read or Write. It is not possible to open a file within the zip as ReadWrite.
The returned stream must be freed with closeFile(). Do not delete it directly.
In verbose mode, openFile() will display additional error information in the console when it fails.
filename | Filename of the file in the zip | |
mode | Access mode. May be Read or Write |
Stream* Zip::ZipArchive::openFileForRead | ( | const CentralDir * | fileCD | ) |
Open a file within the zip file for read.
This method exists mainly for the integration with the resource manager. Unless there is good reason to use this method, it is better to use the openFile() method instead.
fileCD | Pointer to central directory of the file to open |
bool Zip::ZipArchive::addFile | ( | const char * | filename, | |
const char * | pathInZip, | |||
bool | replace = true | |||
) |
Add a file to the zip.
If replace is false and the file already exists in the zip, this function will fail and return false. If replace is true, the existing file will be overwritten.
filename | Filename on the local file system to add | |
pathInZip | The path and filename in the zip file to give this file | |
replace | true to replace existing files, false otherwise |
bool Zip::ZipArchive::extractFile | ( | const char * | pathInZip, | |
const char * | filename, | |||
bool * | crcFail = NULL | |||
) |
Extract a file from the zip.
The file will be created through the resource manager and so must be in a location that is writable.
The file will be CRC checked during extraction and extractFile() will return false if the CRC check failed. The CRC check is just an advisory, the output file will still exist if the CRC check failed. It is up to the caller to decide what to do in the event of a CRC failure.
You can optionally pass a pointer to a bool to determine if a CRC check failed. If extractFile() returns false and crcFail is false then the failure was not CRC related. If crcFail is true and extractFile() returns false, then the CRC check failed but the file otherwise extracted OK. You can take your chances as to whether the data is valid or not, if you wish.
In verbose mode, extractFile() will display an error in the console when a file fails the CRC check.
pathInZip | The path and filename in the zip file to extract | |
filename | Filename on the local file system to extract to | |
crcFail | Pointer to a boolean that receives the result of the CRC check |
bool Zip::ZipArchive::deleteFile | ( | const char * | filename | ) |
Delete a file from the zip.
Flags a file as deleted so it is removed when the zip file is rebuilt.
filename | Filename in the zip to delete |
U32 Zip::ZipArchive::numEntries | ( | ) | const [inline] |
const CentralDir& Zip::ZipArchive::operator[] | ( | const U32 | idx | ) | const [inline] |
Get a central directory entry.
CentralDir* Zip::ZipArchive::findFileInfo | ( | const char * | filename | ) |
Find a file in the zip.
filename | Path and filename to find |
friend class ::ZipTestWrite [friend] |
friend class ::ZipTestRead [friend] |
friend class ::ZipTestMisc [friend] |
Stream* Zip::ZipArchive::mStream [protected] |
FileStream* Zip::ZipArchive::mDiskStream [protected] |
AccessMode Zip::ZipArchive::mMode [protected] |
EndOfCentralDir Zip::ZipArchive::mEOCD [protected] |
ZipEntry* Zip::ZipArchive::mRoot [protected] |
VectorPtr<ZipEntry *> Zip::ZipArchive::mEntries [protected] |
const char* Zip::ZipArchive::mFilename [protected] |
VectorPtr<ZipTempStream *> Zip::ZipArchive::mTempFiles [protected] |