Linderdaum Engine: clArchiveReader Class Reference
Updated: Sun Feb 5 2012 22:59:48
clArchiveReader Class Reference

Encapsulation of .tar,.rar,.zip archive management. More...

#include <Archive.h>

List of all members.

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.
iIStreamGetSourceFile () 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< sFileInfoFFileInfos
 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, intFFileInfoIdx
 File information indices (name to index map)
iIStreamFSourceFile
 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.

Detailed Description

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:

  • compressed data using zlib/libbzip2 (pkware's .zip files)
  • uncompressed .tar and .rar files

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.


Constructor & Destructor Documentation

clArchiveReader::clArchiveReader ( ) [inline]
virtual clArchiveReader::~clArchiveReader ( ) [inline, virtual]

Member Function Documentation

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

bool clArchiveReader::ExtractSingleFile ( const LString &  FName,
const LString &  Password,
int AbortFlag,
float Progress,
iOStream FOut 
)

Extract a file from archive.

end of .ZIP stuff

Decompress the data

Dump the data to OutStream

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.


Member Data Documentation

If 1, then the current Open() operation terminates.

When OpenArchive is called, the caller can track progress

Cached archive type.

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)

Do we manage the source file.

std::vector<LString> clArchiveReader::FRealFileNames [private]

Real (in-archive) file names.

Updated inside the Enumerate()

Source file.

The number of files in archive, available soon after the Enumerate() is called.


The documentation for this class was generated from the following files: