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 "DZOper.h" |
||
36 | #include "ZipDflt.h" |
||
37 | #include "dz_errs.h" |
||
38 | |||
39 | #undef _DZ_FILE_ |
||
40 | #define _DZ_FILE_ DZ_ZIPDFLT_CPP |
||
41 | |||
42 | //--------------------------------------------------------------------------- |
||
43 | int extra_lbits[LENGTH_CODES] // extra bits for each length code |
||
44 | = |
||
45 | { |
||
46 | 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, |
||
47 | 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0 |
||
48 | }; |
||
49 | |||
50 | int extra_dbits[D_CODES] // extra bits for each distance code |
||
51 | = |
||
52 | { |
||
53 | 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, |
||
54 | 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13 |
||
55 | }; |
||
56 | |||
57 | int extra_blbits[BL_CODES] // extra bits for each bit length code |
||
58 | = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; |
||
59 | |||
60 | ZipDflt::ZipDflt(const DllCommands *C): DZOp(C) |
||
61 | { |
||
62 | flevel = 9; |
||
63 | fhInz = INVALID_HANDLE_VALUE; |
||
64 | fZipInfile = NULL; |
||
65 | fZipOutfile = NULL; |
||
66 | fcalls = 0; // crypt static: ensure diff. random header each time |
||
67 | fkey = NULL; // crypt static: decryption password or NULL |
||
68 | #ifdef DEBUG |
||
69 | fbits_sent = 0; |
||
70 | #endif |
||
71 | fin_buf = NULL; |
||
72 | fwindow_size = 0; |
||
73 | fimax = 0; |
||
74 | fzipfile = ""; |
||
75 | fdispose = 0; |
||
76 | |||
77 | memset(fdyn_ltree, 0, sizeof(fdyn_ltree)); |
||
78 | memset(fdyn_dtree, 0, sizeof(fdyn_dtree)); |
||
79 | memset(fstatic_ltree, 0, sizeof(fstatic_ltree)); |
||
80 | memset(fstatic_dtree, 0, sizeof(fstatic_dtree)); |
||
81 | |||
82 | memset(&fl_desc, 0, sizeof(fl_desc)); |
||
83 | memset(&fd_desc, 0, sizeof(fd_desc)); |
||
84 | memset(&fbl_desc, 0, sizeof(fbl_desc)); |
||
85 | memset(fbl_tree, 0, sizeof(fbl_tree)); |
||
86 | memset(fbase_length, 0, sizeof(fbase_length)); |
||
87 | memset(flength_code, 0, sizeof(flength_code)); |
||
88 | memset(fbase_dist, 0, sizeof(fbase_dist)); |
||
89 | memset(fdist_code, 0, sizeof(fdist_code)); |
||
90 | memset(fbl_count, 0, sizeof(fbl_count)); |
||
91 | fopt_len = 0; |
||
92 | fstatic_len = 0; |
||
93 | flast_lit = 0; |
||
94 | flast_dist = 0; |
||
95 | flast_flags = 0; |
||
96 | fflags = 0; |
||
97 | fflag_bit = 0; |
||
98 | memset(fheap, 0, sizeof(fheap)); |
||
99 | fheap_len = 0; |
||
100 | fheap_max = 0; |
||
101 | memset(fdepth, 0, sizeof(fdepth)); |
||
102 | memset(fflag_buf, 0, sizeof(fflag_buf)); |
||
103 | memset(fl_buf, 0, sizeof(fl_buf)); |
||
104 | memset(fd_buf, 0, sizeof(fd_buf)); |
||
105 | |||
106 | fl_desc.dyn_tree = fdyn_ltree; |
||
107 | fl_desc.static_tree = fstatic_ltree; |
||
108 | fl_desc.extra_bits = extra_lbits; |
||
109 | fl_desc.extra_base = LITERALS + 1; |
||
110 | fl_desc.elems = L_CODES; |
||
111 | fl_desc.max_length = MAX_BITS; |
||
112 | |||
113 | fd_desc.dyn_tree = fdyn_dtree; |
||
114 | fd_desc.static_tree = fstatic_dtree; |
||
115 | fd_desc.extra_bits = extra_dbits; |
||
116 | fd_desc.elems = D_CODES; |
||
117 | fd_desc.max_length = MAX_BITS; |
||
118 | |||
119 | fbl_desc.dyn_tree = fbl_tree; |
||
120 | fbl_desc.extra_bits = extra_blbits; |
||
121 | fbl_desc.elems = BL_CODES; |
||
122 | fbl_desc.max_length = MAX_BL_BITS; |
||
123 | } |
||
124 | |||
125 | ZipDflt::~ZipDflt(void) |
||
126 | { |
||
127 | if (fZipInfile) |
||
128 | delete fZipInfile; |
||
129 | |||
130 | fZipInfile = NULL; |
||
131 | |||
132 | if (fZipOutfile) |
||
133 | delete fZipOutfile; |
||
134 | |||
135 | fZipOutfile = NULL; |
||
136 | } |
||
137 | |||
138 | // Read a new buffer from the current input file, perform end-of-line |
||
139 | // translation, and update the crc and input file size. IN assertion: size >= |
||
140 | // 2 (for end-of-line translation) |
||
141 | int ZipDflt::read_buf(unsigned char *buf, unsigned size) |
||
142 | { |
||
143 | DWORD len, olen; |
||
144 | |||
145 | if (fimax > 0 && (fisize + size) > fimax) |
||
146 | { |
||
147 | if (fisize < fimax) |
||
148 | size = (unsigned)(fimax - fisize); |
||
149 | else |
||
150 | return 0; |
||
151 | } |
||
152 | |||
153 | if (!fZipInfile->Read(buf, size, &len)) |
||
154 | { |
||
155 | fFileError = GetLastError(); |
||
156 | return EOF; |
||
157 | } |
||
158 | |||
159 | olen = len; |
||
160 | |||
161 | if (!len) |
||
162 | return 0; |
||
163 | |||
164 | fcrc = crc32(fcrc, (uch*)buf, len); |
||
165 | |||
166 | fisize += (ulg)len; |
||
167 | |||
168 | CB->UserProgress(olen); |
||
169 | |||
170 | return (int)len; |
||
171 | } |
||
172 |