Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | #include "stdafx.h" |
2 | #pragma hdrstop |
||
3 | /* |
||
4 | |||
5 | Copyright (c) 1990-2007 Info-ZIP. All rights reserved. |
||
6 | |||
7 | See the accompanying file LICENSE, version 2007-Mar-4 or later |
||
8 | (the contents of which are also included in zip.h) for terms of use. |
||
9 | If, for some reason, all these files are missing, the Info-ZIP license |
||
10 | also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html |
||
11 | |||
12 | parts Copyright (C) 1997 Mike White, Eric W. Engler |
||
13 | ************************************************************************ |
||
14 | Copyright (C) 2009, 2010 by Russell J. Peters, Roger Aelbrecht |
||
15 | |||
16 | This file is part of TZipMaster Version 1.9. |
||
17 | |||
18 | TZipMaster is free software: you can redistribute it and/or modify |
||
19 | it under the terms of the GNU Lesser General Public License as published by |
||
20 | the Free Software Foundation, either version 3 of the License, or |
||
21 | (at your option) any later version. |
||
22 | |||
23 | TZipMaster is distributed in the hope that it will be useful, |
||
24 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
25 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
26 | GNU Lesser General Public License for more details. |
||
27 | |||
28 | You should have received a copy of the GNU Lesser General Public License |
||
29 | along with TZipMaster. If not, see <http://www.gnu.org/licenses/>. |
||
30 | |||
31 | contact: problems@delphizip.org (include ZipMaster in the subject). |
||
32 | updates: http://www.delphizip.org |
||
33 | DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip |
||
34 | ************************************************************************/ |
||
35 | #include "UnzSup.h" |
||
36 | #include "dz_errs.h" |
||
37 | |||
38 | #undef _DZ_FILE_ |
||
39 | #define _DZ_FILE_ DZ_UNZSUP_CPP |
||
40 | //--------------------------------------------------------------------------- |
||
41 | //#pragma package(smart_init) |
||
42 | |||
43 | |||
44 | UnzSup::UnzSup(const DllCommands *C): DZOp(C) |
||
45 | { |
||
46 | fqflag = 0; |
||
47 | ftflag = 0; |
||
48 | |||
49 | fredirect_data = 0; |
||
50 | fredirect_pointer = 0; |
||
51 | fredirect_buffer = 0; |
||
52 | fredirect_size = 0; |
||
53 | fbuffer_size = 0; |
||
54 | chdrList = NULL; |
||
55 | chdrCount = 0; |
||
56 | Encrypted = false; |
||
57 | InProgress = false; |
||
58 | |||
59 | fpInfo = NULL; |
||
60 | |||
61 | fcsize = 0; /* used by list_files(), NEXTBYTE: must be signed */ |
||
62 | fucsize = 0; /* used by list_files(), unReduce(), explode() */ |
||
63 | fused_csize = 0; /* used by extract_or_test_member(), explode() */ |
||
64 | fcur_zipfile_bufstart = 0; /* extract_or_test, readbuf, ReadByte */ |
||
65 | |||
66 | fincnt_leftover = 0; /* so improved NEXTBYTE does not waste input */ |
||
67 | finptr_leftover = 0; |
||
68 | foutbufptr = 0; /* extract.c static */ |
||
69 | foutsize = 0; /* extract.c static */ |
||
70 | freported_backslash = 0; /* extract.c static */ |
||
71 | |||
72 | fcrc32val = 0; /* CRC shift reg. (was static in funzip) */ |
||
73 | |||
74 | finbuf = 0; /* input buffer (any size is OK) */ |
||
75 | finptr = 0; /* pointer into input buffer */ |
||
76 | fincnt = 0; |
||
77 | fbitbuf = 0; |
||
78 | fbits_left = 0; /* unreduce and unshrink only */ |
||
79 | fzipeof = 0; |
||
80 | fUnzInfile = NULL; |
||
81 | fUnzOutfile = NULL; |
||
82 | fextra_bytes = 0; |
||
83 | |||
84 | fmem_mode = 0; |
||
85 | foutbuf = 0; |
||
86 | frealbuf = 0; |
||
87 | |||
88 | foutbuf2 = 0; /* main() (never changes); else malloc'd */ |
||
89 | foutptr = 0; |
||
90 | foutcnt = 0; /* number of chars stored in outbuf */ |
||
91 | fnewfile = 0; |
||
92 | |||
93 | fTextLast = 0; // last text convert buffer character |
||
94 | fsol = 0; /* fileio static: at start of line */ |
||
95 | fdisk_full = 0; |
||
96 | } |
||
97 | |||
98 | UnzSup::~UnzSup(void) |
||
99 | { |
||
100 | CHdrInfo *t, *p = chdrList; |
||
101 | |||
102 | while (p) |
||
103 | { |
||
104 | t = p; |
||
105 | p = p->next; |
||
106 | |||
107 | delete t; |
||
108 | } |
||
109 | |||
110 | if (fUnzInfile) |
||
111 | delete fUnzInfile; |
||
112 | |||
113 | if (fUnzOutfile) |
||
114 | delete fUnzOutfile; |
||
115 | } |
||
116 | |||
117 | // used by extract for searches |
||
118 | UnzFileSpec::UnzFileSpec() |
||
119 | { |
||
120 | fFileSpec = NULL; |
||
121 | fPassword = NULL; |
||
122 | fBase = NULL; |
||
123 | Match = 0; |
||
124 | } |
||
125 | |||
126 | UnzFileSpec::~UnzFileSpec() |
||
127 | { |
||
128 | if (fFileSpec) |
||
129 | delete [] fFileSpec; |
||
130 | } |
||
131 | |||
132 | void __fastcall UnzFileSpec::SetSpec(const DZStrW& value) |
||
133 | { |
||
134 | if (fFileSpec) |
||
135 | delete [] fFileSpec; |
||
136 | fFileSpec = (TCHAR*)DupStr(value); |
||
137 | fHash = 0; |
||
138 | // if (!IsWild(value)) |
||
139 | fHash = HashFunc(value); |
||
140 | } |
||
141 | |||
142 | void __fastcall UnzFileSpec::SetPassw(const DZStrA& value) |
||
143 | { |
||
144 | if (fPassword) |
||
145 | delete [] fPassword; |
||
146 | fPassword = (char*)DupStr(value); |
||
147 | } |
||
148 | |||
149 | |||
150 | CHdrInfo::CHdrInfo() |
||
151 | { |
||
152 | offset = 0; |
||
153 | compr_size = 0; |
||
154 | uncomp_size = 0; |
||
155 | crc = 0; |
||
156 | _flags = 0; |
||
157 | file_attr = 0; |
||
158 | chdrseq = 0; |
||
159 | spec = NULL; |
||
160 | next = NULL; |
||
161 | fxname = NULL; |
||
162 | fhname = NULL; |
||
163 | ntfs_data = NULL; |
||
164 | } |
||
165 | |||
166 | CHdrInfo::~CHdrInfo() |
||
167 | { |
||
168 | if (fxname) |
||
169 | delete[] fxname; |
||
170 | if (fhname) |
||
171 | delete[] fhname; |
||
172 | if (ntfs_data) |
||
173 | delete ntfs_data; |
||
174 | } |
||
175 | |||
176 | void CHdrInfo::Clear(void) |
||
177 | { |
||
178 | if (fxname) |
||
179 | delete[] fxname; |
||
180 | fxname = NULL; |
||
181 | if (fhname) |
||
182 | delete[] fhname; |
||
183 | fhname = NULL; |
||
184 | if (ntfs_data) |
||
185 | delete ntfs_data; |
||
186 | ntfs_data = NULL; |
||
187 | _flags = 0; |
||
188 | offset = 0; |
||
189 | compr_size = 0; |
||
190 | uncomp_size = 0; |
||
191 | crc = 0; |
||
192 | file_attr = 0; |
||
193 | chdrseq = 0; |
||
194 | spec = NULL; |
||
195 | next = NULL; |
||
196 | } |
||
197 | |||
198 | DZStrW __fastcall CHdrInfo::FullPath(void) const |
||
199 | { |
||
200 | return spec->Base->FullPath(XName); |
||
201 | } |
||
202 | |||
203 | |||
204 | void __fastcall CHdrInfo::Setxname(const TCHAR *value) |
||
205 | { |
||
206 | if (fxname) |
||
207 | delete[] fxname; |
||
208 | fxname = NULL; |
||
209 | if (value) |
||
210 | fxname = zstrdup(value); |
||
211 | } |
||
212 | |||
213 | |||
214 | |||
215 | void __fastcall CHdrInfo::Sethname(const char* value) |
||
216 | { |
||
217 | if (fhname) |
||
218 | delete[] fhname; |
||
219 | fhname = NULL; |
||
220 | if (value) |
||
221 | fhname = zstrdupB(value); |
||
222 | } |
||
223 | |||
224 | bool __fastcall CHdrInfo::GetIsFolder(void) const |
||
225 | { |
||
226 | return fhname[strlen(fhname)- 1] == '/'; |
||
227 | } |
||
228 | |||
229 | const int ErrOrder[] = {DZ_ERR_WARNING, DZ_ERR_GENERAL, DZ_ERR_INVAL_NAME, DZ_ERR_INVAL_ZIP, |
||
230 | DZ_ERR_NO_FILE_OPEN, DZ_ERR_BAD_OPTIONS, DZ_ERR_MISS, DZ_ERR_ERROR_WRITE, |
||
231 | DZ_ERR_ZIP_EOF, DZ_ERR_ERROR_CREATE, DZ_ERR_ERROR_DELETE, 0}; |
||
232 | int PK_Rank(int err) |
||
233 | { |
||
234 | int e = DZ_ERR(err); |
||
235 | int r = 2;//0; |
||
236 | if (!e) |
||
237 | return r; |
||
238 | for (const int *p = ErrOrder; *p && *p != e; r++, p++) ; |
||
239 | return r; |
||
240 | } |
||
241 | |||
242 | unsigned HashFunc(const DZStrW& strng) |
||
243 | { |
||
244 | if (strng.FindOneOf(_T("*?|"), 0) >= 0) |
||
245 | return 0; |
||
246 | DZStrW upr(StrExtSep(strng)); |
||
247 | upr.ToUpper().Trim(); |
||
248 | const wchar_t *str = upr.c_str(); |
||
249 | int len = upr.length(); |
||
250 | if (Is_Drv(upr) < 0) |
||
251 | { |
||
252 | int dlen = DriveLen(upr); |
||
253 | str += dlen; // get filename for stream |
||
254 | len -= dlen; |
||
255 | } |
||
256 | return crc32(0, (uch*)str, len * sizeof(TCHAR)); |
||
257 | } |
||
258 |