| Linderdaum Engine: clArchiveReader Class Reference | ![]() |
Encapsulation of .tar,.rar,.zip archive management. More...
#include <Archive.h>
Classes | |
| struct | sFileInfo |
| Internal file information. More... | |
Public Member Functions | |
| clArchiveReader () | |
| virtual | ~clArchiveReader () |
| scriptmethod bool | OpenArchive (iIStream *Source, bool OwnStream) |
| Assign the source stream and set the internal ownership flag. | |
| scriptmethod bool | OpenArchiveFile (const LString &FName) |
| Create a stream reader and read archive contents. | |
| scriptmethod bool | ExtractSingleFile (const LString &FName, const LString &Password, int *AbortFlag, float *Progress, iOStream *FOut) |
| Extract a file from archive. | |
| scriptmethod bool | CloseArchive () |
| Free everything and optionally close the source stream. | |
| iIStream * | GetSourceFile () const |
| LArchiveType | GetArchiveType () const |
| Get opened archive type. | |
| scriptmethod bool | FileExists (const LString &FileName) const |
| Check if such a file exists in the archive. | |
| scriptmethod Luint64 | GetFileSize (const LString &FileName) const |
| Get the size of file. | |
| const void * | GetFileData (const LString &FileName) |
| Get the data for this file. | |
| scriptmethod Luint64 | GetFileTime (const LString &FileName) const |
| Get the extracted timestamp for this file. | |
| scriptmethod int | GetFileIdx (const LString &FileName) const |
| Convert file name to an internal linear index. | |
| scriptmethod size_t | GetNumFiles () const |
| Get the number of files in archive. | |
| scriptmethod LString | GetFileName (Luint idx) |
| Get i-th file name in archive. | |
Public Attributes | |
| int | FAbortScanningFlag |
| If 1, then the current Open() operation terminates. | |
| int | FScanProgress |
| Updated inside the Enumerate() | |
| int | FTotalFiles |
| The number of files in archive, available soon after the Enumerate() is called. | |
| volatile bool * | FCompletionFlag |
| If not NULL, EnumerateFiles() sets this to true at the end. | |
Private Member Functions | |
| bool | EnumerateFiles () |
| Internal function to enumerate the files in archive. | |
| bool | Enumerate_TAR () |
| bool | Enumerate_RAR () |
| bool | Enumerate_ZIP () |
| const void * | GetFileData_TAR_or_RAR (size_t idx) |
| const void * | GetFileData_ZIP (size_t idx) |
| void | ClearExtracted () |
| Remove each extracted file from tmp container. | |
| void * | AllocData (size_t Sz) |
| void | FreeData (void *DataPtr) |
Private Attributes | |
| std::vector< sFileInfo > | FFileInfos |
| File information. | |
| std::vector< LString > | FFileNames |
| File names (adapted for our VFS - upper case, slash-separated path) | |
| std::vector< LString > | FRealFileNames |
| Real (in-archive) file names. | |
| std::map< LString, int > | FFileInfoIdx |
| File information indices (name to index map) | |
| iIStream * | FSourceFile |
| Source file. | |
| bool | FOwnsSourceFile |
| Do we manage the source file. | |
| LArchiveType | FArchiveType |
| Cached archive type. | |
| std::map< int, const void * > | FExtractedFromArchive |
| Temporary cache for the extracted files. Removed on CloseArchive() call. | |
Encapsulation of .tar,.rar,.zip archive management.
Provides file enumeration facilities and access to individual files
Contains an extracted list of files (and corresponding time stamps).
clArchive supports:
Access to the file content is done using iIStream interface, so it is completely compatible with the engine's IO.
There are no delegation and subclasses to avoid having a lot of generated metainformations for them. The .rar/.tar/.zip parsing is performed in dedicated methods (Enumerate_*) File type is determined from the header or from the file extension.
The user creates an archive reader instance and supplies the Source (file)stream to read the data from. If the ownership flag is true, the stream is automatically closed at the end.
Utility method OpenArchiveFile() reads the data from the specified file. Source file ownership is set to True in this case.
Since Open() can be a lenghty operation, we provide the information in FScanProgress variable and FAbortFlag can terminate the scanning before it is finished.
| clArchiveReader::clArchiveReader | ( | ) | [inline] |
| virtual clArchiveReader::~clArchiveReader | ( | ) | [inline, virtual] |
| void* clArchiveReader::AllocData | ( | size_t | Sz | ) | [inline, private] |
| void clArchiveReader::ClearExtracted | ( | ) | [inline, private] |
Remove each extracted file from tmp container.
Other archive types do not decompress and allocate additional buffers
| bool clArchiveReader::CloseArchive | ( | ) |
Free everything and optionally close the source stream.
Clear info containers
Clear data cache
Close the source stream
Clear the pointers
| bool clArchiveReader::Enumerate_RAR | ( | ) | [private] |
| bool clArchiveReader::Enumerate_TAR | ( | ) | [private] |
Round to 512
Skip unknown blocks (0 and 72 are supported)
Normal file, skip bytes
| bool clArchiveReader::Enumerate_ZIP | ( | ) | [private] |
| bool clArchiveReader::EnumerateFiles | ( | ) | [private] |
Internal function to enumerate the files in archive.
Determine archive type using the file extension.
When all else fails
Inform our mount point that we are done
| scriptmethod bool clArchiveReader::FileExists | ( | const LString & | FileName | ) | const [inline] |
Check if such a file exists in the archive.
| void clArchiveReader::FreeData | ( | void * | DataPtr | ) | [inline, private] |
| LArchiveType clArchiveReader::GetArchiveType | ( | ) | const [inline] |
Get opened archive type.
| const void* clArchiveReader::GetFileData | ( | const LString & | FileName | ) | [inline] |
Get the data for this file.
Check if we already have this data in cache
Decompress/extract the data
| void * clArchiveReader::GetFileData_TAR_or_RAR | ( | size_t | idx | ) | [private] |
| void * clArchiveReader::GetFileData_ZIP | ( | size_t | idx | ) | [private] |
sanity check
| scriptmethod int clArchiveReader::GetFileIdx | ( | const LString & | FileName | ) | const [inline] |
Convert file name to an internal linear index.
| scriptmethod LString clArchiveReader::GetFileName | ( | Luint | idx | ) | [inline] |
Get i-th file name in archive.
| scriptmethod Luint64 clArchiveReader::GetFileSize | ( | const LString & | FileName | ) | const [inline] |
Get the size of file.
| scriptmethod Luint64 clArchiveReader::GetFileTime | ( | const LString & | FileName | ) | const [inline] |
Get the extracted timestamp for this file.
| scriptmethod size_t clArchiveReader::GetNumFiles | ( | ) | const [inline] |
Get the number of files in archive.
| iIStream* clArchiveReader::GetSourceFile | ( | ) | const [inline] |
| scriptmethod bool clArchiveReader::OpenArchive | ( | iIStream * | Source, |
| bool | OwnStream | ||
| ) | [inline] |
Assign the source stream and set the internal ownership flag.
| bool clArchiveReader::OpenArchiveFile | ( | const LString & | FName | ) |
Create a stream reader and read archive contents.
If 1, then the current Open() operation terminates.
When OpenArchive is called, the caller can track progress
LArchiveType clArchiveReader::FArchiveType [private] |
Cached archive type.
| volatile bool* clArchiveReader::FCompletionFlag |
If not NULL, EnumerateFiles() sets this to true at the end.
std::map<int, const void*> clArchiveReader::FExtractedFromArchive [private] |
Temporary cache for the extracted files. Removed on CloseArchive() call.
std::map<LString, int> clArchiveReader::FFileInfoIdx [mutable, private] |
File information indices (name to index map)
std::vector<sFileInfo> clArchiveReader::FFileInfos [private] |
File information.
std::vector<LString> clArchiveReader::FFileNames [private] |
File names (adapted for our VFS - upper case, slash-separated path)
bool clArchiveReader::FOwnsSourceFile [private] |
Do we manage the source file.
std::vector<LString> clArchiveReader::FRealFileNames [private] |
Real (in-archive) file names.
Updated inside the Enumerate()
iIStream* clArchiveReader::FSourceFile [private] |
Source file.
The number of files in archive, available soon after the Enumerate() is called.