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 "zipop.h"
4
#include "enter.h"
5
#include "dz_errs.h"
6
 
7
#undef _DZ_FILE_
8
#define _DZ_FILE_ DZ_ZIPMAIN_CPP
9
 
10
/* DLLmain.c * Copyright (C) 1997 Mike White and Eric W. Engler
11
* Permission is granted to any individual or institution to use, copy, or
12
* redistribute this software so long as all of the original files are included,
13
* that it is not sold for profit, and that this copyright notice is retained.
14
* This version modified by Chris Vleghert BCB/Delphi Zip.
15
** distributed under LGPL license
16
** see license.txt for details
17
 
18
  Copyright (c) 1990-2007 Info-ZIP.  All rights reserved.
19
 
20
  See the accompanying file LICENSE, version 2007-Mar-4 or later
21
  (the contents of which are also included in zip.h) for terms of use.
22
  If, for some reason, all these files are missing, the Info-ZIP license
23
  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html
24
 
25
  parts Copyright (C) 1997 Mike White, Eric W. Engler
26
************************************************************************
27
 Copyright (C) 2009, 2010  by Russell J. Peters, Roger Aelbrecht
28
 
29
   This file is part of TZipMaster Version 1.9.
30
 
31
    TZipMaster is free software: you can redistribute it and/or modify
32
    it under the terms of the GNU Lesser General Public License as published by
33
    the Free Software Foundation, either version 3 of the License, or
34
    (at your option) any later version.
35
 
36
    TZipMaster is distributed in the hope that it will be useful,
37
    but WITHOUT ANY WARRANTY; without even the implied warranty of
38
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
39
    GNU Lesser General Public License for more details.
40
 
41
    You should have received a copy of the GNU Lesser General Public License
42
    along with TZipMaster.  If not, see <http://www.gnu.org/licenses/>.
43
 
44
    contact: problems@delphizip.org (include ZipMaster in the subject).
45
    updates: http://www.delphizip.org
46
    DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip
47
************************************************************************/
48
 
49
#include <signal.h>
50
#include <stdarg.h>
51
#include <direct.h>
52
 
53
long ZipOp::Exec(const DllCommands *C)
54
{
55
    try
56
        {
57
        if (Verbose < 0)
58
            Notify(0,  _T("trace is on, ZipExec [%d %d %d]"), FCount,
59
                   ZCount, UCount);
60
 
61
                ZipSetParam(C);
62
 
63
        ftempath = CB->UserArg(zcbTempPath, 0, 0);
64
        if (!ftempath.IsEmpty())
65
        {
66
            // Temporary path -b
67
            ftempath = StrIncSep(ftempath);
68
//            ftempdir = 1;
69
        }
70
 
71
        //  fzipfile
72
        // in this state, we need the name of the zip file
73
        DZStrW tmp = CB->UserArg(zcbFilename, 0, 0);
74
        if (tmp.IsEmpty() && !fSS)
75
        {
76
            // Something screwed up, we don't have a filename
77
            Notify(DZ_ERM_BAD_OPTIONS, _T("No zip filename received"));
78
                        throw DZException(DZ_ERM_GENERAL);
79
        }
80
 
81
                fzipfile = ziptyp(tmp);
82
 
83
        if (Verbose)
84
        {
85
            DZStrW tmp(DZ_Banner());
86
            Notify(IVERBOSE, _T("Using %s"), tmp.c_str());
87
 
88
            if (Verbose < 0)
89
                Notify(ITRACE, _T("root = %s"), fRootDir.c_str());
90
        }
91
 
92
        if (Verbose < 0)
93
        {
94
            GiveTime();
95
            GiveGlobals();
96
                }
97
 
98
                if (fSS)
99
                {
100
                        ZipStreamStream();
101
                        ffiles_acted_on++;
102
                        CB->UserCB(zacEndOfBatch); // done with in-memory compression
103
                }
104
                else
105
                {
106
                        if (!ZipSelect(C))
107
                        {
108
                                if (Abort_Flag || ZipProcess() != 0)
109
                                        ffiles_acted_on = 0;
110
 
111
                                if (fBatchStarted)
112
                                        CB->UserCB(zacEndOfBatch); // done with a batch of files
113
 
114
                                diag(_T("*** BACK FROM CALL TO ZipProcess ***"));
115
                        }
116
                }
117
 
118
                if (Verbose)
119
                        Notify(0, _T("Files acted on = %d"), ffiles_acted_on);
120
 
121
                if (Abort_Flag)
122
                {
123
                        if (Abort_Flag & (GA_EXCEPT | GA_EXCEPT2))
124
              return -DZ_ERR_CALLBACK;
125
            if (Abort_Flag & GA_ABORT)
126
              return -DZ_ERR_ABORT;
127
            if (Abort_Flag & GA_CANCEL)
128
              return -DZ_ERR_CANCELLED;
129
        }
130
    }
131
    catch (DZException &E)
132
    {
133
                OutputDebugString(L"Exec - exception");
134
        DZError(E.ErrNo, E.Msg);
135
 
136
        if (fBatchStarted)
137
            CB->UserCB(zacEndOfBatch);
138
 
139
        return -DZ_ERR(E.ErrNo);
140
//        throw;
141
    }
142
 
143
    return ffiles_acted_on;
144
}
145
 
146
int ZipOp::ZipSetParam(const DllCommands *C)
147
{
148
    int ii;                              
149
 
150
    ii = C->fLevel;
151
 
152
    if (ii < 0)
153
        ii = 0;
154
    else
155
        if (ii > 9)
156
            ii = 9;
157
 
158
    flevel = ii;
159
 
160
    if (Verbose < 0)
161
        Notify(ITRACE, _T("setting compression level to %d"), flevel);
162
 
163
    faction = C->fOptions.OpIsDelete ? PURGE : ADD;
164
 
165
    if (C->fOptions.Freshen) // Freshen zip file--overwrite only -f
166
    {
167
        if (faction != ADD)
168
        {
169
            Notify(DZ_ERM_BAD_OPTIONS, _T("invalid options"));
170
                        throw DZException(DZ_ERM_BAD_OPTIONS);
171
        }
172
 
173
        faction = FRESHEN;
174
    }
175
 
176
    if (C->fOptions.Update) // Update zip file--overwrite only if newer -u
177
    {
178
        if (faction != ADD)
179
        {
180
            Notify(DZ_ERM_BAD_OPTIONS, _T("invalid options"));
181
                        throw DZException(DZ_ERM_BAD_OPTIONS);
182
        }
183
 
184
        faction = UPDATE;
185
    }
186
 
187
//    fzcomment = CB->UserArg(zcbComment, 0, 0);
188
//    if (fzcomment)
189
//        fzcomlen = strlen(fzcomment);
190
/* **** */
191
    fzcomment = CB->UserZCmnt();
192
    if (fzcomment)
193
        fzcomlen = fzcomment.Length();
194
/* **** */
195
 
196
    fGPassword = CB->UserArg(zcbPassword, 0, 0);
197
 
198
    return 0;
199
}
200
 
201
 
202
//#ifdef DZ_LOGGING
203
char w(bool v)
204
{
205
    if (v)
206
        return '+';
207
 
208
    return '-';
209
}
210
 
211
void ZipOp::GiveGlobals(void)
212
{
213
//    if (!Verbose)
214
//        return;
215
 
216
    DZStrW tmp;
217
 
218
    tmp.Format(_T("g%c j%c J%c" /* k%c"*/), w(fAllowGrow), w(fpathput),
219
               w(fjunk_sfx));//, w(fdosify));
220
 
221
    Notify(IVERBOSE, _T("%s m%c o%c S%c t%c"), tmp.c_str() , w(fdispose), w(flatest),
222
           w(fhidden_files), w(fbefore));
223
}
224
//#endif
225
 
226
 
227
 
228
 
229
 
230
 
231