leocad/common/lc_zipfile.h

82 lines
2.7 KiB
C
Raw Normal View History

2012-09-20 02:53:12 +02:00
#ifndef _LC_ZIPFILE_H_
#define _LC_ZIPFILE_H_
#include "array.h"
class lcFile;
// Date/time info.
struct tm_unz
{
lcuint32 tm_sec; // seconds after the minute - [0,59]
lcuint32 tm_min; // minutes after the hour - [0,59]
lcuint32 tm_hour; // hours since midnight - [0,23]
lcuint32 tm_mday; // day of the month - [1,31]
lcuint32 tm_mon; // months since January - [0,11]
lcuint32 tm_year; // years - [1980..2044]
};
// Information about a file in the zipfile.
struct lcZipFileInfo
{
lcuint16 version; // version made by 2 bytes
lcuint16 version_needed; // version needed to extract 2 bytes
lcuint16 flag; // general purpose bit flag 2 bytes
lcuint16 compression_method; // compression method 2 bytes
lcuint32 dosDate; // last mod file date in Dos fmt 4 bytes
lcuint32 crc; // crc-32 4 bytes
lcuint64 compressed_size; // compressed size 8 bytes
lcuint64 uncompressed_size; // uncompressed size 8 bytes
lcuint16 size_filename; // filename length 2 bytes
lcuint16 size_file_extra; // extra field length 2 bytes
lcuint16 size_file_comment; // file comment length 2 bytes
lcuint16 disk_num_start; // disk number start 2 bytes
lcuint16 internal_fa; // internal file attributes 2 bytes
lcuint32 external_fa; // external file attributes 4 bytes
lcuint64 offset_curfile; // relative offset of local header 8 bytes
char file_name[256];
tm_unz tmu_date;
2012-10-05 21:11:37 +02:00
lcMemFile* write_buffer;
bool deleted;
2012-09-20 02:53:12 +02:00
};
class lcZipFile
{
public:
lcZipFile();
~lcZipFile();
2012-10-05 21:11:37 +02:00
bool OpenRead(const char* FilePath);
2012-10-06 01:09:38 +02:00
bool OpenWrite(const char* FilePath, bool Append);
2012-10-05 21:11:37 +02:00
2012-09-29 02:16:43 +02:00
bool ExtractFile(int FileIndex, lcMemFile& File, lcuint32 MaxLength = 0xffffffff);
2012-10-04 00:38:33 +02:00
bool ExtractFile(const char* FileName, lcMemFile& File, lcuint32 MaxLength = 0xffffffff);
2012-10-05 21:11:37 +02:00
bool AddFile(const char* FileName, lcMemFile& File);
bool DeleteFile(const char* FileName);
2012-09-20 02:53:12 +02:00
ObjArray<lcZipFileInfo> mFiles;
protected:
bool Open();
void Flush();
2012-09-20 02:53:12 +02:00
bool ReadCentralDir();
lcuint64 SearchCentralDir();
lcuint64 SearchCentralDir64();
2012-09-29 02:16:43 +02:00
bool CheckFileCoherencyHeader(int FileIndex, lcuint32* SizeVar, lcuint64* OffsetLocalExtraField, lcuint32* SizeLocalExtraField);
2012-09-20 02:53:12 +02:00
lcDiskFile* mFile;
2012-09-20 02:53:12 +02:00
bool mModified;
2012-09-20 02:53:12 +02:00
bool mZip64;
lcuint64 mNumEntries;
lcuint64 mCentralDirSize;
lcuint64 mCentralDirOffset;
lcuint64 mBytesBeforeZipFile;
lcuint64 mCentralPos;
};
#endif // _LC_ZIPFILE_H_