Subversion Repositories autosfx

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 daniel-mar 1
#include "stdafx.h"
2
#pragma hdrstop
3
#include "dz_errs.h"
4
 
5
#undef _DZ_FILE_
6
#define _DZ_FILE_ DZ_UNZSS_CPP
7
/*
8
UnzSS.cpp -
9
 
10
  Copyright (c) 1990-2007 Info-ZIP.  All rights reserved.
11
 
12
  See the accompanying file LICENSE, version 2007-Mar-4 or later
13
  (the contents of which are also included in zip.h) for terms of use.
14
  If, for some reason, all these files are missing, the Info-ZIP license
15
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
16
 
17
  parts Copyright (C) 1997 Mike White, Eric W. Engler
18
************************************************************************
19
 Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
20
 
21
   This file is part of TZipMaster Version 1.9.
22
 
23
    TZipMaster is free software: you can redistribute it and/or modify
24
    it under the terms of the GNU Lesser General Public License as published by
25
    the Free Software Foundation, either version 3 of the License, or
26
    (at your option) any later version.
27
 
28
    TZipMaster is distributed in the hope that it will be useful,
29
    but WITHOUT ANY WARRANTY; without even the implied warranty of
30
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
31
    GNU Lesser General Public License for more details.
32
 
33
    You should have received a copy of the GNU Lesser General Public License
34
    along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
35
 
36
    contact: problems@delphizip.org (include ZipMaster in the subject).
37
    updates: http://www.delphizip.org
38
    DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
39
************************************************************************/
40
 
41
#include "UnzOp.h"     
42
#include <stdio.h>
43
 
44
int UnzOpr::UnzStreamStream(void)
45
{
46
    CHdrInfo sinfo;
47
    fpInfo = &sinfo;
48
    int b, r;
49
    int error = 0;
50
    memset(&sinfo, 0, sizeof(CHdrInfo));
51
    fnewzip = true;
52
    InProgress = true;
53
    fBytesWritten = 0;
54
    ffilename = _T("0:<INSTREAM>");
55
//    STRCPY(ffilename, "<INSTREAM>");
56
    fUnzInfile = new ZStream(this, ffilename, fSS->fSSInput);
57
    AutoStream inz(&fUnzInfile);
58
    /*---------------------------------------------------------------------------
59
    *    Initialize variables, buffers, etc.
60
    *---------------------------------------------------------------------------*/
61
//  fcsize = 50028;
62
//  fcsize = 0x40000000000i64;
63
    fcsize = fSS->Size;
64
    fbits_left = 0;
65
    fbitbuf = 0L;
66
    /* unreduce and unshrink only */
67
    fzipeof = 0;
68
    fnewfile = true;
69
    fdisk_full = 0;
70
    fcrc32val = CRCVAL_INITIAL;
71
    defer_leftover_input();
72
    // so NEXTBYTE bounds check will work
73
    int method = fSS->Method & 0xff;
74
 
75
    if ((unsigned)fSS->Method > 0xFF)
76
    {
77
        if (Verbose < 0)
78
            Notify(ITRACE, _T("about to call decrypt"));
79
 
80
        Encrypted = true;
81
 
82
        if ((error = decrypt(fSS->CRC >> 24)) != PK_COOL)
83
                {
84
//                      int cbe;
85
//            CB->Arg1 = 0;
86
//            CB->Arg2 = SKIPPED_BAD_PASSWORD;
87
//                      cbe = CB->UserCB(zacSkipped, ffilename);
88
 
89
            if (Verbose < 0)
90
                                Notify(ITRACE, _T("Skipping encrypted Stream, bad password"));
91
 
92
                        if (Skipping(ffilename, error, SKIPPED_BAD_PASSWORD))
93
                                Fatal(DZ_ERM_SKIPPED, 2);
94
 
95
                        if (Abort_Flag)// || cbe == CALLBACK_TRUE)
96
                                Fatal(DZ_ERM_ABORT, 0);
97
 
98
            return error;
99
        }
100
    }
101
 
102
    fBytesWritten = 0;
103
 
104
    CB->Arg1 = 1;
105
    CB->UserCB(zacCount);
106
 
107
    // Pass total filesize.
108
    CB->FileSize = fcsize;
109
    CB->UserCB(zacSize);
110
//    CBData.MsgP = "<UNDEFLATE>";
111
    CB->FileSize = fcsize;
112
    CB->UserCB(zacItem, _T("<undeflate>"));
113
 
114
    fUnzOutfile = new ZStream(this, _T("0:<OUTSTREAM>"), fSS->fSSOutput);
115
    AutoStream outz(&fUnzOutfile);
116
 
117
        switch (method)
118
    {
119
 
120
        case STORED:
121
            foutptr = Slide;
122
            foutcnt = 0L;
123
 
124
            while ((b = NEXTBYTE) != EOF && !fdisk_full)
125
            {
126
                * foutptr++ = (uch)b;
127
 
128
                if (++foutcnt == wsize)
129
                {
130
                    // EWE: wsize = 32K
131
                    flush(Slide, foutcnt, 0);
132
                    foutptr = Slide;
133
                    foutcnt = 0L;
134
 
135
                    if (Abort_Flag)
136
                    {
137
                        /* v1.6026 */
138
                        CloseOut();
139
                        undefer_input();
140
                                                Fatal(DZ_ERM_ABORT, 0);
141
                    }
142
                }
143
            }
144
 
145
            if (foutcnt) // flush final (partial) buffer
146
                flush(Slide, foutcnt, 0);
147
 
148
            break;
149
 
150
        case DEFLATED:
151
 
152
        case ENHDEFLATED:
153
        {
154
            if (Verbose < 0)
155
                Notify(ITRACE,  _T("about to call Inflate"));
156
 
157
            if ((r = inflate(method == ENHDEFLATED)) != 0)
158
            {
159
                int zerr = DZ_ERR(r);
160
            if (zerr != DZ_ERR(PK_WARN) &&
161
                (zerr == DZ_ERR(PK_BADERR) || zerr == DZ_ERR(PK_NOZIP) ||
162
                                zerr == DZ_ERR(PK_FIND) || zerr == DZ_ERR(PK_EOF)))
163
                {
164
                    return r;
165
                }
166
 
167
                Notify(0, _T("Error unzipping files"));
168
 
169
                error = PK_ERR;
170
            }
171
            else
172
            {
173
                ffiles_acted_on++;
174
                fSS->CRC = fcrc32val;
175
            }
176
        }
177
 
178
        break;
179
 
180
        default:
181
            /* should never get to this point */
182
 
183
            if (Verbose)// < 0)
184
                Notify(ITRACE, _T("should NEVER get here"));
185
 
186
            Notify(0, _T("Error stream - unknown method"));
187
 
188
                        /* close and delete file before return? */
189
            return PK_ERR;
190
    }
191
 
192
    /* end switch (compression method) */
193
    CB->UserCB(zacEndOfBatch); // done with stream extraction
194
 
195
    if (fdisk_full)
196
    {
197
        /* set by flush() */
198
        if (fdisk_full > 1)
199
        {
200
            return PK_DISKFULL;
201
        }
202
 
203
        error = PK_WARN;
204
    }
205
 
206
    if (PK_Rank(error) > PK_Rank(PK_WARN))
207
    {
208
        return error;
209
    }
210
 
211
    if (Verbose)
212
        Notify(IVERBOSE,  _T("stream of size %Lu %s"), fBytesWritten,
213
            ftflag ? _T("Tested  ") : _T("Unzipped"));
214
 
215
    if (error != PK_COOL && Verbose < 0)
216
        Notify(ITRACE, _T("UnzStreamStream returning error: %d"), error);
217
 
218
    return error;
219
}
220