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 "enter.h"
4
#include "dz_errs.h"
5
 
6
#undef _DZ_FILE_
7
#define _DZ_FILE_ DZ_UNZEXEC_CPP
8
/*
9
unzmain.c -
10
 
11
  Copyright (c) 1990-2007 Info-ZIP.  All rights reserved.
12
 
13
  See the accompanying file LICENSE, version 2007-Mar-4 or later
14
  (the contents of which are also included in zip.h) for terms of use.
15
  If, for some reason, all these files are missing, the Info-ZIP license
16
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
17
 
18
  parts Copyright (C) 1997 Mike White, Eric W. Engler
19
************************************************************************
20
 Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
21
 
22
   This file is part of TZipMaster Version 1.9.
23
 
24
    TZipMaster is free software: you can redistribute it and/or modify
25
    it under the terms of the GNU Lesser General Public License as published by
26
    the Free Software Foundation, either version 3 of the License, or
27
    (at your option) any later version.
28
 
29
    TZipMaster is distributed in the hope that it will be useful,
30
    but WITHOUT ANY WARRANTY; without even the implied warranty of
31
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
    GNU Lesser General Public License for more details.
33
 
34
    You should have received a copy of the GNU Lesser General Public License
35
    along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
36
 
37
    contact: problems@delphizip.org (include ZipMaster in the subject).
38
    updates: http://www.delphizip.org
39
    DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
40
************************************************************************/
41
 
42
 
43
/* Main UnZip DLL module
44
* This version modified by Chris Vleghert and Eric W. Engler
45
* for BCB/Delphi Zip.
46
* Based on Mike White's DLL, but is dissimilar in many ways.
47
* This module has the entry point for the two calls from BCB and Delphi.
48
*/
49
 
50
#include "UnzOp.h"
51
#include <excpt.h>
52
 
53
#define PWLEN 80
54
/* ===================================================== */
55
 
56
long UnzOpr::Exec(const DllCommands *C)
57
{
58
  int FilesActedOn;
59
 
60
  if (Verbose < 0)
61
        Notify(0,  _T("trace is on, UnzDllExec [%d %d %d]"), FCount,
62
      ZCount, UCount);
63
 
64
  fzipfn = CB->UserArg(zcbFilename, 0, 0);
65
  if (!fzipfn)
66
  {
67
    /* Something screwed up, we don't have a filename */
68
        throw DZException(DZ_ERM_BAD_OPTIONS, _T("No zip filename received"));
69
  }
70
 
71
  /* ---------------------------------------------------------------- */
72
  if (Verbose < 0)
73
    Notify(ITRACE, _T("ready to setup"));
74
  if (FSetUpToProcessZipFile(C))
75
  {
76
    if (Verbose)
77
    {
78
        DZStrW tmp(DZ_Banner());
79
        Notify(IVERBOSE, _T("Using %s"), tmp.c_str());
80
        if (Verbose < 0)
81
            Notify(ITRACE, _T("root = %s"), CurBase->Base);
82
    }
83
 
84
//#ifdef USE_STRM_INPUT
85
//    if (fUseInStream)
86
//        MemExtract();
87
//    else
88
//    {
89
//      if (fSS)
90
//      {
91
//        UnzStreamStream();
92
//        if (Verbose < 0)
93
//          Notify(ITRACE, _T("*** BACK FROM CALL TO unzip stream ***"));
94
//      }
95
//      else
96
//      {
97
//        process_zipfiles();   // Pass ptr to global bufs.
98
//        if (Verbose < 0)
99
//          Notify(ITRACE, _T("*** BACK FROM CALL TO process_zipfiles ***"));
100
//      }
101
//    }
102
//#else
103
    if (fSS)
104
    {
105
      UnzStreamStream();
106
      if (Verbose < 0)
107
        Notify(ITRACE, _T("*** BACK FROM CALL TO unzip stream ***"));
108
    }
109
    else
110
    {
111
          process_zipfiles();   // Pass ptr to global bufs.
112
      if (Verbose < 0)
113
        Notify(ITRACE, _T("*** BACK FROM CALL TO process_zipfiles ***"));
114
    }
115
//#endif
116
 
117
    if (Verbose)
118
      Notify(IVERBOSE, _T("Files acted on = %d"), ffiles_acted_on);
119
  }
120
  FilesActedOn = ffiles_acted_on;
121
  inflate_free();
122
  TakeDownFromProcessZipFile();
123
 
124
  if (Verbose < 0)
125
        GiveTime();
126
 
127
  if (Abort_Flag)
128
  {
129
    if (Abort_Flag & (GA_EXCEPT | GA_EXCEPT2))
130
          return -DZ_ERR_CALLBACK;
131
        if (Abort_Flag & GA_ABORT)
132
          return -DZ_ERR_ABORT;
133
    if (Abort_Flag & GA_CANCEL)
134
          return -DZ_ERR_CANCELLED;
135
  }
136
  return FilesActedOn;
137
}
138
 
139
/* =========================================================================== */
140
bool UnzOpr::FSetUpToProcessZipFile(const DllCommands *C)
141
{
142
//  char * ExtDir, *tp;
143
//  int len;
144
 
145
  fqflag = C->fOptions.Quiet; // quiet flag
146
  if (Verbose < 0)
147
    Notify(ITRACE, _T("FSetUpToProcessZipFile"));
148
 
149
  /* These flags all have a fixed value in this version. */
150
  fextract_flag = 1;
151
  ftflag = C->fOptions.OpIsTest;     /* if true, test zipfile */
152
  fT_flag = 1;     /* -T: timestamps (unzip) or dec. time fmt (zipinfo) */
153
 
154
  // set options from caller
155
  fcreate_dirs = C->fOptions.Directories; // used by main(), mapname(), checkdir()
156
  fdflag = C->fOptions.Directories; // "recreate dir structure"
157
  fjflag = !(fdflag);   // "junk pathnames"
158
 
159
  if (C->fHandle == 0)   // if we don't have a window handle, then
160
    fqflag = true; // we need to be quiet (no dialog boxes)
161
 
162
  fuflag = C->fOptions.Update; // "Update" - extract only newer files & brand new files
163
  ffflag = C->fOptions.Freshen; // "freshen" (extract only newer files)
164
 
165
  if (C->fOptions.Overwrite)
166
    foverwrite_all = true; // Don't ask, always overwrite else Don't overwrite; skip that file.
167
 
168
  ffilespecs = 0; // number of fspecs
169
 
170
//#ifdef CRYPT
171
  /* IMPORTANT! For ZIPDLL, the password is malloc'd, and then pointed-to
172
  * by the global "key",  However, in UNZDLL, this is done:
173
  * - "key" and "fkey" must remain NULL
174
  * - fpwdarg must point to the password passed-in, or else must be NULL
175
  * - fP_flag must be set to true if a password was passed-in */
176
 
177
  /* if no password, we will prompt user later (only if encrypted file found) */
178
  fpwdarg = CB->UserArg(zcbPassword, 0, 0).c_str();
179
  fP_flag = fpwdarg ? 1 : 0;
180
  fPwdReqCount = C->fPwdReqCount & 0x0F;
181
//#endif
182
 
183
  if (!C->fSS)
184
  {
185
//#ifdef USE_STRM_INPUT
186
//  if (!C->fUseInStream)
187
//  {
188
//      if (_stati64(fzipfn, & fstatbuf) || (fstatbuf.st_mode & S_IFMT) == S_IFDIR)
189
//        STRCAT(fzipfn, ZSUFX);
190
//      if (_stati64(fzipfn, & fstatbuf))
191
//      {
192
//        Notify(IERROR, _T(" can't find zipfile [%s]"), fzipfn);
193
//        return false;
194
//      }
195
//      else
196
//        fziplen = fstatbuf.st_size;
197
//  }
198
//#else
199
  if (_tstati64(fzipfn, & fstatbuf))
200
  {
201
    Notify(IERROR, _T(" can't find zipfile [%s]"), fzipfn.c_str());
202
    return false;
203
  }
204
  else
205
    fziplen = fstatbuf.st_size;
206
//#endif
207
  }
208
 
209
  if (Verbose < 0)
210
        GiveTime();
211
 
212
  /*---------------------------------------------------------------------------
213
  *     Ok, we have everything we need to get started.
214
  *---------------------------------------------------------------------------*/
215
  foutbuf = new uch[OUTBUFSIZ + 1];
216
  finbuf = new uch[INBUFSIZ + 4];
217
  frootlen = 0;
218
  fhold = & finbuf[INBUFSIZ];
219
  /* to check for boundary-spanning signatures */
220
 
221
  if (fSS)
222
  {                                        
223
      fredirect_pointer = 0;
224
      fredirect_size = 0;
225
    return true;
226
  }
227
//#ifdef USE_STRM_INPUT
228
//  if (C->fUseInStream)
229
//  {
230
//    fUseInStream = C->fUseInStream;
231
//    fInStream = C->fInStream;
232
//    fInStreamSize = C->fInStreamSize;
233
//  }
234
//#endif
235
//#ifdef USE_STRM_OUTPUT
236
//  if (C->fUseOutStream)
237
//  {
238
//      fredirect_data = true;
239
//      fbuffer_size = C->fOutStreamSize;
240
//      fredirect_buffer = (unsigned char *) C->fOutStream;
241
//#ifdef USE_STRM_INPUT
242
//      if (fUseInStream)
243
//      {
244
//        fredirect_pointer = foutbuf; // Circular buffer inside DLL
245
//        fredirect_size = OUTBUFSIZ;
246
//    }
247
//      else
248
//    {
249
//#endif
250
//      fredirect_pointer = fredirect_buffer;
251
//        fredirect_size = C->fOutStreamSize;
252
//#ifdef USE_STRM_INPUT
253
//      }
254
//#endif
255
//      if (!fredirect_buffer)
256
//        return false;
257
//  }
258
//#endif
259
  return true;
260
  /* set up was OK */
261
}
262
 
263
 
264
/* ============================================================ */
265
void UnzOpr::TakeDownFromProcessZipFile(void)
266
{
267
  if (finbuf)
268
  {
269
        delete[] finbuf;
270
    finbuf = NULL;
271
  }
272
  if (foutbuf)
273
  {
274
        delete[] foutbuf;
275
    foutbuf = NULL;
276
  }
277
}
278
 
279
 
280