Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | //--------------------------------------------------------------------------- |
2 | |||
3 | #ifndef DZOperH |
||
4 | #define DZOperH |
||
5 | /************************************************************************ |
||
6 | Copyright (C) 2009, 2010 by Russell J. Peters, Roger Aelbrecht, |
||
7 | Eric W. Engler and Chris Vleghert. |
||
8 | |||
9 | This file is part of TZipMaster Version 1.9. |
||
10 | |||
11 | TZipMaster is free software: you can redistribute it and/or modify |
||
12 | it under the terms of the GNU Lesser General Public License as published by |
||
13 | the Free Software Foundation, either version 3 of the License, or |
||
14 | (at your option) any later version. |
||
15 | |||
16 | TZipMaster is distributed in the hope that it will be useful, |
||
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
19 | GNU Lesser General Public License for more details. |
||
20 | |||
21 | You should have received a copy of the GNU Lesser General Public License |
||
22 | along with TZipMaster. If not, see <http://www.gnu.org/licenses/>. |
||
23 | |||
24 | contact: problems@delphizip.org (include ZipMaster in the subject). |
||
25 | updates: http://www.delphizip.org |
||
26 | DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip |
||
27 | ************************************************************************/ |
||
28 | #include <sys\stat.h> |
||
29 | #ifndef __BORLANDC__ |
||
30 | #define stati64 _stati64 |
||
31 | #endif |
||
32 | |||
33 | #include "common.h" |
||
34 | #include "enter.h" |
||
35 | #include "DZFrame.h" |
||
36 | #include <stdarg.h> |
||
37 | |||
38 | /* Message code format |
||
39 | 0FFF FFFF LLLL LLLL LLLL MTTT EEEE EEEE {31 .. 0} |
||
40 | F = file number (7 bits = 128 files) |
||
41 | L = line number (12 bits=4096 lines) |
||
42 | M = message instead of error string |
||
43 | T = type (3 bits=8) |
||
44 | E = error/string code (8 bits = 256 errors) |
||
45 | * / |
||
46 | |||
47 | const DZM_MessageBit = 0x800; // mask for buffer bit |
||
48 | // t = type, e = error |
||
49 | #define DZ_MESSAGE(t, e) ((t&0xF00) | e) |
||
50 | #define DZ_MSG(x) (x & 0xff) |
||
51 | #define DZ_MSGTYP(x) (x & 0x700) |
||
52 | const DZM_General = 0x000; |
||
53 | const DZM_Error = 0x600; // 1 1 x (E... is identifier) |
||
54 | const DZM_Warning = 0x400; // 1 0 x |
||
55 | const DZM_Trace = 0x300; // 0 1 1 |
||
56 | const DZM_Verbose = 0x100; // 0 0 1 |
||
57 | const DZM_Message = 0x200; // 0 1 0 (E... is identifier) |
||
58 | */ |
||
59 | class ZFilter |
||
60 | { |
||
61 | ZFilter(); |
||
62 | ZFilter(const ZFilter&); |
||
63 | ZFilter operator=(const ZFilter&); |
||
64 | ZFilter* fnext; |
||
65 | int flevel; // only for suffixes |
||
66 | DZStrW fspec; |
||
67 | public: |
||
68 | ZFilter(DZStrW &spec); |
||
69 | ~ZFilter(); |
||
70 | bool __fastcall ISEmpty(void) const; |
||
71 | ZFilter * __fastcall Find(const DZStrW &spec); |
||
72 | |||
73 | __property int Level = {read = flevel, write = flevel}; |
||
74 | __property ZFilter* Next = {read = fnext, write = fnext}; |
||
75 | }; |
||
76 | |||
77 | class PWRec |
||
78 | { |
||
79 | const char* fpw; |
||
80 | PWRec *fnext; |
||
81 | PWRec(); |
||
82 | PWRec(const PWRec &); |
||
83 | PWRec& operator=(const PWRec&); |
||
84 | public: |
||
85 | PWRec(const DZStrA &pw); |
||
86 | ~PWRec(); |
||
87 | __property const char* Passw = {read=fpw}; |
||
88 | __property PWRec* Next = {read=fnext, write=fnext}; |
||
89 | }; |
||
90 | |||
91 | class BaseRec |
||
92 | { |
||
93 | const TCHAR* fbase; |
||
94 | BaseRec *fnext; |
||
95 | BaseRec(); |
||
96 | BaseRec(const BaseRec &); |
||
97 | BaseRec& operator=(const BaseRec&); |
||
98 | inline DZStrW __fastcall GetBaseDir(void) const {return DZStrW(fbase);} |
||
99 | public: |
||
100 | BaseRec(const DZStrW &base); |
||
101 | ~BaseRec(); |
||
102 | DZStrW __fastcall FullPath(const DZStrW& filename) const; |
||
103 | __property const TCHAR* Base = {read=fbase}; |
||
104 | __property BaseRec* Next = {read=fnext, write=fnext}; |
||
105 | __property DZStrW BaseDir = {read=GetBaseDir}; |
||
106 | }; |
||
107 | |||
108 | class UserCallback; |
||
109 | class DZOp: public DZFrame |
||
110 | { |
||
111 | protected: |
||
112 | friend class UserCallback; |
||
113 | HWND global_handle; |
||
114 | void *global_caller; |
||
115 | const DllCommands *Command; |
||
116 | int CallerVersion; |
||
117 | ZFunctionPtrType callb; // Function address for callback purposes. |
||
118 | ZStreamFuncPtrType ZStreamFunc; |
||
119 | ZInt64 fBytesWritten; |
||
120 | ZSSArgs *fSS; // used stream-stream |
||
121 | unsigned fEncodedAs; |
||
122 | bool fQuiet; |
||
123 | int fdll_handles_errors; |
||
124 | int fuser_notified_of_abort; |
||
125 | int fglobal_error_code; |
||
126 | DZStrW DZErrMsg; |
||
127 | int fpathput; |
||
128 | public: |
||
129 | int Verbose; |
||
130 | bool fNTFSStamps; |
||
131 | unsigned long fFromPage; // country to use |
||
132 | PWRec *CurPW; |
||
133 | BaseRec *CurBase; |
||
134 | // bool NoSkipping; //<< |
||
135 | |||
136 | UserCallback *CB; |
||
137 | ZS_Rec ZSData; // stream op data |
||
138 | DZOp(const DllCommands *C); |
||
139 | ~DZOp(void); |
||
140 | virtual long Exec(const DllCommands *C) = 0; |
||
141 | virtual int Init(void); // after construction |
||
142 | void ShowSysMsg(DWORD Error); |
||
143 | void SendInfo(unsigned err, const DZStrW& info); |
||
144 | void __cdecl Notify(unsigned err, const TCHAR* szFmt, ...); |
||
145 | void GiveTime(void); |
||
146 | int EraseFile(const DZStrW &Fname, bool safe); |
||
147 | int __fastcall StreamCB(void); |
||
148 | const char* AddPW(const DZStrA& pw, bool toFront); |
||
149 | const BaseRec* AddBase(const DZStrW& base, bool toFront); |
||
150 | DZStrW __fastcall GetFullPath(const DZStrW &Filename) const; |
||
151 | DZStrW __fastcall FullPath(const DZStrW &Filename, const BaseRec* base) const; |
||
152 | void MsgBox(const DZStrW& msg, bool CanCancel); |
||
153 | int __fastcall Fatal(int err, unsigned flag = 0, bool raise = true); |
||
154 | int __fastcall DZError(int err, const TCHAR* msg = NULL); |
||
155 | unsigned __fastcall IsEncoded(ush made,unsigned utf) const;//, unsigned unix); |
||
156 | bool Skipping(const DZStrW& fn, int err, int typ); |
||
157 | DZStrW MakeExclFilters(void); |
||
158 | DZStrW ConvExclFilters(const DZStrW & filters); |
||
159 | DZStrW ex2IntForm(const DZStrW &exname, bool ignore); |
||
160 | protected: |
||
161 | bool ZStat(const DZStrW& fn, struct stati64 *res); |
||
162 | private: |
||
163 | DZOp(void); |
||
164 | DZOp(const DZOp&); // copy not allowed |
||
165 | DZOp& operator=(const DZOp&); |
||
166 | DZStrW lastStatName; |
||
167 | |||
168 | struct stati64 lastStat; |
||
169 | }; |
||
170 | |||
171 | class UserCallback |
||
172 | { |
||
173 | friend class DZOp; |
||
174 | private: |
||
175 | DZOp *Owner; |
||
176 | ZFunctionPtrType callb; |
||
177 | DZStrW hold, hold2; |
||
178 | struct ZCallBackStruct CBData; |
||
179 | UserCallback(void); |
||
180 | UserCallback(const UserCallback&); |
||
181 | UserCallback& operator=(const UserCallback&); |
||
182 | inline const char *GetData(void) const {return (const char*)CBData.MsgP;} |
||
183 | inline void SetData(const char *value) {CBData.MsgP = (const void*)value;} |
||
184 | inline const char *GetData2(void) const {return (const char*)CBData.MsgP2;} |
||
185 | inline void SetData2(const char *value) {CBData.MsgP2 = (const void*)value;} |
||
186 | inline __int64 GetFileSize(void) const {return CBData.FileSize;} |
||
187 | inline void SetFileSize(const __int64 value) {CBData.FileSize = value;} |
||
188 | inline __int64 GetWritten(void) const {return CBData.Written;} |
||
189 | inline void SetWritten(const __int64 value) {CBData.Written = value;} |
||
190 | inline long GetArg1(void) const {return CBData.Arg1;} |
||
191 | inline void SetArg1(const long value) {CBData.Arg1 = value;} |
||
192 | inline unsigned GetArg2(void) const {return CBData.Arg2;} |
||
193 | inline void SetArg2(const unsigned value) {CBData.Arg2 = value;} |
||
194 | inline int GetArg3(void) const {return CBData.Arg3;} |
||
195 | inline void SetArg3(const int value) {CBData.Arg3 = value;} |
||
196 | DZStrW __fastcall RetMsg(const void *_msg) const; |
||
197 | DZStrW __fastcall GetMsg(void) const; |
||
198 | void __fastcall SetMsg(const DZStrW& value); |
||
199 | DZStrW __fastcall GetMsg2(void) const; |
||
200 | void __fastcall SetMsg2(const DZStrW& value); |
||
201 | inline int GetAbort(void) const {return Owner->Abort_Flag;} |
||
202 | inline void SetAbort(const int value) {Owner->Abort_Flag = value;} |
||
203 | protected: |
||
204 | DZStrA __fastcall GetZCmnt(void) const; |
||
205 | __property int Abort_Flag = {read=GetAbort, write=SetAbort}; |
||
206 | public: |
||
207 | UserCallback(DZOp *theOwner, bool OpIsZip); |
||
208 | ~UserCallback(void); |
||
209 | int __fastcall UserCB(unsigned Action); |
||
210 | int __fastcall UserCB(unsigned Action, const DZStrW& msg); |
||
211 | int UserCB(unsigned Action, const DZStrW& msg, const DZStrW& msg2); |
||
212 | int __fastcall UserMsg(int err, const DZStrW& msg); |
||
213 | int UserItem(__int64 cnt, const DZStrW& msg); |
||
214 | int __fastcall UserProgress(__int64 adv); |
||
215 | int UserXProgress(__int64 adv, int typ); |
||
216 | int UserXItem(__int64 cnt, int typ, const DZStrW& msg); |
||
217 | DZStrW UserArg(int arg, int idx, int *cnt); |
||
218 | DZStrA UserZCmnt(void); |
||
219 | __property DZStrW Msg = {read=GetMsg, write=SetMsg}; |
||
220 | __property DZStrW Msg2 = {read=GetMsg2, write=SetMsg2}; |
||
221 | __property const char *Data = {read=GetData, write=SetData}; |
||
222 | __property const char *Data2 = {read=GetData2, write=SetData2}; |
||
223 | __property __int64 FileSize = {read=GetFileSize, write=SetFileSize}; |
||
224 | __property __int64 Written = {read=GetWritten, write=SetWritten}; |
||
225 | __property long Arg1 = {read=GetArg1, write=SetArg1}; |
||
226 | __property unsigned Arg2 = {read=GetArg2, write=SetArg2}; |
||
227 | __property int Arg3 = {read=GetArg3, write=SetArg3}; |
||
228 | }; |
||
229 | |||
230 | |||
231 | DZStrW LastSystemMsg(void); |
||
232 | DZStrW SystemMsg(DWORD Error, const TCHAR* arg1 = NULL); |
||
233 | |||
234 | class SysMsg : public DZStrW |
||
235 | { |
||
236 | public: |
||
237 | SysMsg() : DZStrW(LastSystemMsg()){} |
||
238 | SysMsg(DWORD error): DZStrW(SystemMsg(error, NULL)){} |
||
239 | SysMsg(DWORD error, const TCHAR* arg1): DZStrW(SystemMsg(error, arg1)){} |
||
240 | private: |
||
241 | SysMsg& operator=(const SysMsg&) { return *this; } |
||
242 | }; |
||
243 | |||
244 | |||
245 | DZOp *MakeZipper(const DllCommands *C); |
||
246 | DZOp *MakeUnzipper(const DllCommands *C); |
||
247 | |||
248 | #endif |
||
249 | |||
250 | |||
251 | |||
252 | |||
253 | |||
254 |