2017-07-19 23:20:32 +02:00
|
|
|
#pragma once
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2013-08-16 01:43:18 +02:00
|
|
|
#include "lc_array.h"
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
#ifdef DeleteFile
|
|
|
|
#undef DeleteFile
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class lcFile;
|
|
|
|
|
|
|
|
// Date/time info.
|
|
|
|
struct tm_unz
|
|
|
|
{
|
2017-12-02 21:22:04 +01:00
|
|
|
quint32 tm_sec; // seconds after the minute - [0,59]
|
|
|
|
quint32 tm_min; // minutes after the hour - [0,59]
|
|
|
|
quint32 tm_hour; // hours since midnight - [0,23]
|
|
|
|
quint32 tm_mday; // day of the month - [1,31]
|
|
|
|
quint32 tm_mon; // months since January - [0,11]
|
|
|
|
quint32 tm_year; // years - [1980..2044]
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Information about a file in the zipfile.
|
|
|
|
struct lcZipFileInfo
|
|
|
|
{
|
2017-12-02 21:22:04 +01:00
|
|
|
quint16 version; // version made by 2 bytes
|
|
|
|
quint16 version_needed; // version needed to extract 2 bytes
|
|
|
|
quint16 flag; // general purpose bit flag 2 bytes
|
|
|
|
quint16 compression_method; // compression method 2 bytes
|
|
|
|
quint32 dosDate; // last mod file date in Dos fmt 4 bytes
|
|
|
|
quint32 crc; // crc-32 4 bytes
|
|
|
|
quint64 compressed_size; // compressed size 8 bytes
|
|
|
|
quint64 uncompressed_size; // uncompressed size 8 bytes
|
|
|
|
quint16 size_filename; // filename length 2 bytes
|
|
|
|
quint16 size_file_extra; // extra field length 2 bytes
|
|
|
|
quint16 size_file_comment; // file comment length 2 bytes
|
|
|
|
|
|
|
|
quint16 disk_num_start; // disk number start 2 bytes
|
|
|
|
quint16 internal_fa; // internal file attributes 2 bytes
|
|
|
|
quint32 external_fa; // external file attributes 4 bytes
|
|
|
|
|
|
|
|
quint64 offset_curfile; // relative offset of local header 8 bytes
|
2013-08-09 06:57:18 +02:00
|
|
|
char file_name[256];
|
|
|
|
tm_unz tmu_date;
|
|
|
|
|
|
|
|
lcMemFile* write_buffer;
|
|
|
|
bool deleted;
|
|
|
|
};
|
|
|
|
|
|
|
|
class lcZipFile
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
lcZipFile();
|
|
|
|
~lcZipFile();
|
|
|
|
|
2020-05-04 00:39:39 +02:00
|
|
|
lcZipFile(const lcZipFile&) = delete;
|
|
|
|
lcZipFile(lcZipFile&&) = delete;
|
|
|
|
lcZipFile& operator=(const lcZipFile&) = delete;
|
|
|
|
lcZipFile& operator=(lcZipFile&&) = delete;
|
|
|
|
|
2017-05-29 22:31:24 +02:00
|
|
|
bool OpenRead(const QString& FileName);
|
2020-12-13 16:40:29 +01:00
|
|
|
bool OpenRead(std::unique_ptr<lcFile> File);
|
2017-05-29 22:31:24 +02:00
|
|
|
bool OpenWrite(const QString& FileName);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-12-02 21:22:04 +01:00
|
|
|
bool ExtractFile(int FileIndex, lcMemFile& File, quint32 MaxLength = 0xffffffff);
|
|
|
|
bool ExtractFile(const char* FileName, lcMemFile& File, quint32 MaxLength = 0xffffffff);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2013-08-16 01:43:18 +02:00
|
|
|
lcArray<lcZipFileInfo> mFiles;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool Open();
|
|
|
|
bool ReadCentralDir();
|
2017-12-02 21:22:04 +01:00
|
|
|
quint64 SearchCentralDir();
|
|
|
|
quint64 SearchCentralDir64();
|
|
|
|
bool CheckFileCoherencyHeader(int FileIndex, quint32* SizeVar, quint64* OffsetLocalExtraField, quint32* SizeLocalExtraField);
|
2013-08-09 06:57:18 +02:00
|
|
|
|
2017-01-23 04:28:05 +01:00
|
|
|
QMutex mMutex;
|
2020-12-13 16:40:29 +01:00
|
|
|
std::unique_ptr<lcFile> mFile;
|
2013-08-09 06:57:18 +02:00
|
|
|
|
|
|
|
bool mModified;
|
|
|
|
bool mZip64;
|
2017-12-02 21:22:04 +01:00
|
|
|
quint64 mNumEntries;
|
|
|
|
quint64 mCentralDirSize;
|
|
|
|
quint64 mCentralDirOffset;
|
|
|
|
quint64 mBytesBeforeZipFile;
|
|
|
|
quint64 mCentralPos;
|
2013-08-09 06:57:18 +02:00
|
|
|
};
|
|
|
|
|