OpendTect-6_4  6.4
ziphandler.h
Go to the documentation of this file.
1 #ifndef ziphandler_h
2 #define ziphandler_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Salil Agarwal
9  Date: 30 August 2012
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "bufstringset.h"
17 #include "typeset.h"
18 #include "od_iosfwd.h"
19 
20 
21 class ZipArchiveInfo;
22 
28 {
29 
30 public:
31 
32  ZipFileInfo(const char* fnm,
33  od_int64 compsize,
34  od_int64 uncompsize,
35  od_int64 offset)
36  : fnm_(fnm)
37  , compsize_(compsize)
38  , uncompsize_(uncompsize)
39  , localheaderoffset_(offset) {}
40 
45 
46 };
47 
48 
54 {
55 public:
56 
57  friend class ZipUtils;
58  friend class Zipper;
59  friend class UnZipper;
60 
61  enum CompLevel { NoComp=0, SuperFast=1, Fast=3, Normal=6,
62  Maximum=9 };
63 
65  : initialfilecount_(0)
66  , uncompfilesize_(0)
67  , compfilesize_(0)
68  , offsetofcentraldir_(0)
69  , istrm_(0)
70  , ostrm_(0)
71  , curinputidx_(0)
72  , curfileidx_(0)
73  , totalsize_(0)
74  , nrdonesize_(0) {}
75 
76  ~ZipHandler();
77 
78  const char* errorMsg()const;
79 
80  bool getArchiveInfo(const char*,
82 
83  bool getFileList(const char*,BufferStringSet&);
84 
85  od_uint16 dateInDosFormat(const char*) const;
86  od_uint16 timeInDosFormat(const char*) const;
87  bool setTimeDateModified(const char*,od_uint16,
88  od_uint16)const;
89 
90  bool getBitValue(const unsigned char byte,
91  int bitposition) const;
92  void setBitValue(unsigned char& byte, int
93  bitposition, bool value) const;
94 
95 
96 protected:
97 
98  bool initUnZipArchive(const char*,const char*);
99  bool unZipFile(const char* srcfnm,const char* fnm,
100  const char* path);
101 
102  bool extractNextFile();
103  int readLocalFileHeader();
104  bool openStreamToWrite();
105 
106  bool doZUnCompress();
107  bool readEndOfCentralDirHeader();
108  bool readCentralDirHeader(ObjectSet<ZipFileInfo>*
109  zfileinfo=0);
110  bool readZIP64EndOfCentralDirLocator();
111  bool readZIP64EndOfCentralDirRecord();
112  bool readXtraFldForZIP64(const char*,int);
113  bool readAndSetFileAttr();
114 
115  bool initMakeZip(const char*,const BufferStringSet&);
116  bool initAppend(const char*,const char*);
117 
118  bool compressNextFile();
119  bool doZCompress();
120  int openStrmToRead(const char* src);
121  bool setLocalFileHeader();
122  bool setLocalFileHeaderForDir();
123  bool setLocalFileHeaderForLink();
124  bool setZIP64Header();
125  bool setEndOfArchiveHeaders();
126  bool setCentralDirHeader();
127  bool setEndOfCentralDirHeader(od_int64,od_uint32);
128  bool setZIP64EndOfDirRecord(od_int64);
129  bool setZIP64EndOfDirLocator(od_int64);
130  od_uint32 setExtFileAttr(od_uint32);
131 
132  const BufferStringSet& getAllFileNames() { return allfilenames_; }
134  { return cumulativefilecounts_.last(); }
135  int getCumulativeFileCount(int) const;
136  void setCompLevel(CompLevel);
137 
138  od_int64 getTotalSize()const { return totalsize_; }
139  od_int64 getNrDoneSize()const { return nrdonesize_; }
140 
141  bool reportReadError(const char* filenm=0) const;
142  bool reportWriteError(const char* filenm=0) const;
143  bool reportStrmReadError(od_istream*,
144  const char*) const;
145  void closeInputStream();
146  void closeOutputStream();
147 
150 
153 
156 
159 
162 
164 
169 
172 
174 
177 
180 
183 
184 };
185 
186 
187 #endif
#define mExpClass(module)
Definition: commondefs.h:160
int curfileidx_
Definition: ziphandler.h:166
Handles zipping and unzipping of files.
Definition: ziphandler.h:53
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:26
od_uint16 compmethod_
Definition: ziphandler.h:160
od_uint16 lastmodtime_
Definition: ziphandler.h:170
od_int64 getNrDoneSize() const
Definition: ziphandler.h:139
#define od_int64
Definition: plftypes.h:36
BufferString srcfile_
Definition: ziphandler.h:151
od_int64 od_stream_Pos
Definition: od_iosfwd.h:21
od_int64 localheaderoffset_
Definition: ziphandler.h:44
TypeSet< od_int64 > cumulativefilecounts_
Definition: ziphandler.h:168
od_int64 uncompfilesize_
Definition: ziphandler.h:158
ZipHandler()
Definition: ziphandler.h:64
od_uint32 crc_
Definition: ziphandler.h:173
ZipFileInfo(const char *fnm, od_int64 compsize, od_int64 uncompsize, od_int64 offset)
Definition: ziphandler.h:32
Set of BufferString objects.
Definition: bufstringset.h:28
od_int64 compsize_
Definition: ziphandler.h:42
OD class for stream read.
Definition: od_istream.h:24
od_int64 totalsize_
Definition: ziphandler.h:178
od_int64 nrdonesize_
Definition: ziphandler.h:179
BufferString destfile_
Definition: ziphandler.h:155
Gives information of zip archives.
Definition: ziparchiveinfo.h:27
CompLevel complevel_
Definition: ziphandler.h:161
Zip Utilities.
Definition: ziputils.h:25
od_int64 uncompsize_
Definition: ziphandler.h:43
od_int64 getTotalSize() const
Definition: ziphandler.h:138
It is an Executor class which uncompresses files of zip format but user should instead use ZipUtils::...
Definition: ziputils.h:115
od_stream_Pos offsetoflocalheader_
Definition: ziphandler.h:176
#define od_uint32
Definition: plftypes.h:32
od_uint16 lastmoddate_
Definition: ziphandler.h:171
od_int64 initialfilecount_
Definition: ziphandler.h:167
CompLevel
Definition: ziphandler.h:61
od_uint16 srcfnmsize_
Definition: ziphandler.h:152
od_int64 compfilesize_
Definition: ziphandler.h:157
It is an Executor class which compresses files into zip format but user should not use it directly in...
Definition: ziputils.h:85
od_ostream * ostrm_
Definition: ziphandler.h:181
od_stream_Pos offsetofcentraldir_
Definition: ziphandler.h:175
BufferString fnm_
Definition: ziphandler.h:41
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
Zip file information.
Definition: ziphandler.h:27
BufferString destbasepath_
Definition: ziphandler.h:154
#define od_uint16
Definition: plftypes.h:28
int curinputidx_
Definition: ziphandler.h:165
FixedString Maximum()
Definition: keystrs.h:165
od_int64 getCumulativeFileCount() const
Definition: ziphandler.h:133
const BufferStringSet & getAllFileNames()
Definition: ziphandler.h:132
BufferStringSet allfilenames_
Definition: ziphandler.h:149
od_istream * istrm_
Definition: ziphandler.h:182
int curnrlevels_
Definition: ziphandler.h:163
BufferString errormsg_
Definition: ziphandler.h:148

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019