forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzipfile.hh
78 lines (61 loc) · 2.12 KB
/
zipfile.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* This file is (c) 2008-2012 Konstantin Isakov <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#ifndef __ZIPFILE_HH_INCLUDED__
#define __ZIPFILE_HH_INCLUDED__
#include <QFile>
#include <QDateTime>
#include "splitfile.hh"
/// Support for zip files in GoldenDict. Note that the implementation is
/// strictly tailored to GoldenDict needs only.
namespace ZipFile {
// Support for split zip files
class SplitZipFile : public SplitFile::SplitFile
{
public:
SplitZipFile()
{}
SplitZipFile( const QString & name );
virtual void setFileName( const QString & name );
// Latest modified time for all parts
QDateTime lastModified() const;
// Calc absolute offset by relative offset in part and part nom
qint64 calcAbsoluteOffset( qint64 offset, quint16 partNo );
};
enum CompressionMethod
{
Uncompressed,
Deflated,
Unsupported
};
/// Entry from central dir
struct CentralDirEntry
{
QByteArray fileName;
quint32 localHeaderOffset, compressedSize, uncompressedSize;
CompressionMethod compressionMethod;
bool fileNameInUTF8;
};
/// Represents contents of the local file header -- that what CentralDirEntry::
/// localHeaderOffset points at.
struct LocalFileHeader
{
QByteArray fileName;
quint32 compressedSize, uncompressedSize;
CompressionMethod compressionMethod;
};
/// Finds the central directory in the given file and positions it at its
/// beginning. Returns true if the file is positioned, false otherwise (not a
/// zip file or other error).
/// Once the file is positioned, entries may be read by constructing Entry
/// objects.
bool positionAtCentralDir( SplitZipFile & );
/// Reads entry from the zip at its current offset. The file gets advanced
/// by the size of entry, so it points to the next entry.
/// Returns true on success, false otherwise.
bool readNextEntry( SplitZipFile &, CentralDirEntry & );
/// Reads loca file header from the zip at its current offset. The file gets
/// advanced by the size of entry and starts pointing to file data.
/// Returns true on success, false otherwise.
bool readLocalHeader( SplitZipFile &, LocalFileHeader & );
}
#endif