Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | daniel-mar | 1 | #include "stdafx.h" |
2 | #pragma hdrstop |
||
3 | |||
4 | #include "common.h" |
||
5 | #include "DZOper.h" |
||
6 | #include "dz_errs.h" |
||
7 | #include "version.h" |
||
8 | #include <alloc.h> |
||
9 | #include <new> |
||
10 | #include <except.h> |
||
11 | |||
12 | #undef _DZ_FILE_ |
||
13 | #define _DZ_FILE_ DZ_ENTER_CPP |
||
14 | |||
15 | /* enter.cpp |
||
16 | |||
17 | ************************************************************************ |
||
18 | Copyright (C) 2009, 2010 by Russell J. Peters, Roger Aelbrecht |
||
19 | |||
20 | This file is part of TZipMaster Version 1.9. |
||
21 | |||
22 | TZipMaster is free software: you can redistribute it and/or modify |
||
23 | it under the terms of the GNU Lesser General Public License as published by |
||
24 | the Free Software Foundation, either version 3 of the License, or |
||
25 | (at your option) any later version. |
||
26 | |||
27 | TZipMaster is distributed in the hope that it will be useful, |
||
28 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
29 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
30 | GNU Lesser General Public License for more details. |
||
31 | |||
32 | You should have received a copy of the GNU Lesser General Public License |
||
33 | along with TZipMaster. If not, see <http://www.gnu.org/licenses/>. |
||
34 | |||
35 | contact: problems@delphizip.org (include ZipMaster in the subject). |
||
36 | updates: http://www.delphizip.org |
||
37 | DelphiZip maillist subscribe at http://www.freelists.org/list/delphizip |
||
38 | ************************************************************************/ |
||
39 | |||
40 | #include <alloc.H> |
||
41 | #ifndef MULTITHREAD |
||
42 | #error Multithread required |
||
43 | #endif |
||
44 | |||
45 | CRITICAL_SECTION csSync; |
||
46 | HINSTANCE ModuleInst = 0; |
||
47 | int UCount = 0; |
||
48 | int ZCount = 0; |
||
49 | unsigned int FCount = 0; |
||
50 | bool IsNTorAbove = false; |
||
51 | //--------------------------------------------------------------------------- |
||
52 | |||
53 | /* ===================================================== |
||
54 | * Entry point to abort operation started with C |
||
55 | */ |
||
56 | long WINAPI DZ_Abort(void * C) |
||
57 | { |
||
58 | return Set_Oper_Abort((OperKeys)C); |
||
59 | } |
||
60 | |||
61 | static int IsOpFrame(DZFrame * p) |
||
62 | { |
||
63 | #if defined(__BORLANDC__) && (__BORLANDC__ < 0x0550) |
||
64 | if (!p) |
||
65 | return 0; |
||
66 | #else |
||
67 | if (!p || std::heapchecknode(p) != _USEDENTRY) |
||
68 | return 0; |
||
69 | #endif |
||
70 | return p->IsME(p); |
||
71 | } |
||
72 | |||
73 | #if defined(ALLOW_WIN98) && defined(UNICODE) |
||
74 | extern int Init_Imports(void); |
||
75 | extern void FreeDLLs(void); |
||
76 | #endif |
||
77 | |||
78 | typedef void (*pvf)(); |
||
79 | pvf OldTerm = 0; |
||
80 | pvf OldUnex = 0; |
||
81 | |||
82 | #pragma argsused |
||
83 | //int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void * lpReserved) |
||
84 | int WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved) |
||
85 | { |
||
86 | // OutputDebugString("Entering DllEntryPoint "); |
||
87 | switch (fwdreason) |
||
88 | { |
||
89 | |||
90 | case DLL_PROCESS_ATTACH: |
||
91 | ModuleInst = hinstDLL; |
||
92 | InitializeCriticalSection(&csSync); |
||
93 | UCount = 0; |
||
94 | ZCount = 0; |
||
95 | FCount = 0; |
||
96 | #ifndef _ONLY_A |
||
97 | IsNTorAbove = GetVersion() < 0x80000000; |
||
98 | #endif |
||
99 | #if defined(ALLOW_WIN98) && defined(UNICODE) |
||
100 | if (IsNTorAbove) |
||
101 | Init_Imports(); |
||
102 | #endif |
||
103 | // fall through |
||
104 | |||
105 | case DLL_THREAD_ATTACH: |
||
106 | break; |
||
107 | |||
108 | case DLL_THREAD_DETACH: |
||
109 | break; |
||
110 | |||
111 | case DLL_PROCESS_DETACH: |
||
112 | Cleanup_Process(); |
||
113 | #if defined(ALLOW_WIN98) && defined(UNICODE) |
||
114 | FreeDLLs(); |
||
115 | #endif |
||
116 | DeleteCriticalSection(&csSync); |
||
117 | } |
||
118 | |||
119 | return 1; |
||
120 | } |
||
121 | |||
122 | //--------------------------------------------------------------------------- |
||
123 | void Set_Oper(DZFrame *Op, int typ) |
||
124 | { |
||
125 | if (Op) |
||
126 | { |
||
127 | EnterCriticalSection(&csSync); |
||
128 | |||
129 | if (Op->SetME(Op, typ)) |
||
130 | { |
||
131 | if (typ == ZIPOPER) |
||
132 | ZCount++; |
||
133 | else |
||
134 | UCount++; |
||
135 | |||
136 | FCount++; |
||
137 | } |
||
138 | else |
||
139 | { |
||
140 | if (typ == ZIPOPER) |
||
141 | ZCount--; |
||
142 | else |
||
143 | UCount--; |
||
144 | } |
||
145 | |||
146 | LeaveCriticalSection(&csSync); |
||
147 | } |
||
148 | } |
||
149 | |||
150 | |||
151 | int Set_Oper_Abort(OperKeys key) |
||
152 | { |
||
153 | int ret = 1; |
||
154 | DZFrame *p = (DZFrame *)(key << 2); |
||
155 | |||
156 | #if defined(__BORLANDC__) && (__BORLANDC__ < 0x0550) |
||
157 | if (!p) |
||
158 | return -1; |
||
159 | #else |
||
160 | if (!p || std::heapchecknode(p) != _USEDENTRY) |
||
161 | return -1; |
||
162 | #endif |
||
163 | |||
164 | EnterCriticalSection(&csSync); |
||
165 | |||
166 | if (p->IsME(p)) |
||
167 | { |
||
168 | if (p->Abort_Flag > GA_CANCEL) |
||
169 | ret--; // could not set it |
||
170 | else |
||
171 | p->Abort_Flag |= GA_ABORT; |
||
172 | } |
||
173 | |||
174 | LeaveCriticalSection(&csSync); |
||
175 | |||
176 | return ret; |
||
177 | } |
||
178 | |||
179 | long WINAPI DZ_Version(void) |
||
180 | { |
||
181 | return DZ_VER_VERSION; // see version.h |
||
182 | } |
||
183 | |||
184 | long WINAPI DZ_PrivVersion(void) |
||
185 | { |
||
186 | return DZ_VER_PRIVATE; |
||
187 | } |
||
188 | |||
189 | char gbuf[MAX_PATH + 2]; |
||
190 | const char* WINAPI DZ_Path(void) |
||
191 | { |
||
192 | if (!GetModuleFileNameA(ModuleInst, gbuf, MAX_PATH)) |
||
193 | { |
||
194 | gbuf[0] = 0; |
||
195 | } |
||
196 | |||
197 | return gbuf; |
||
198 | } |
||
199 | |||
200 | long WINAPI DZ_Name(void* buf, int bufsiz, int wide) |
||
201 | { |
||
202 | if (wide) |
||
203 | return GetModuleFileNameW(ModuleInst, (wchar_t*)buf, bufsiz); |
||
204 | else |
||
205 | return GetModuleFileNameA(ModuleInst, (char*)buf, bufsiz); |
||
206 | } |
||
207 | |||
208 | const char* WINAPI DZ_Banner(void) |
||
209 | { |
||
210 | sprintf(gbuf, "%s.dll version %s, %s", DLLNAME, DZ_VER, __DATE__); |
||
211 | return gbuf; |
||
212 | } |
||
213 | |||
214 | void KillpG(DZOp** ppG) |
||
215 | { |
||
216 | if (ppG) |
||
217 | { |
||
218 | DZOp * tmp = *ppG; |
||
219 | *ppG = NULL; |
||
220 | delete tmp; |
||
221 | OutputDebugString(L"killed pG"); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | int xxfilter(EXCEPTION_POINTERS *); |
||
226 | |||
227 | // Add, update, freshen, move, or delete zip entries in a zip file. |
||
228 | long WINAPI DZ_Exec(const DllCommands * C) |
||
229 | { |
||
230 | DZOp *pG = 0; |
||
231 | long RetVal; |
||
232 | |||
233 | // EXCEPTION_POINTERS *xp = 0; // Marx Fix |
||
234 | |||
235 | OutputDebugString(L"DZ_Exec enter"); |
||
236 | if (!C || C->fCheck != DLLCOMMANDCHECK) |
||
237 | { |
||
238 | // This Seven is at another place as in ZCL! |
||
239 | return -DZ_ERR_STRUCT; |
||
240 | } |
||
241 | |||
242 | int cmd = C->fOptions.opts & 0xF; |
||
243 | |||
244 | if (cmd != DLL_OPT_OpIsZip && cmd != DLL_OPT_OpIsDelete && cmd != |
||
245 | DLL_OPT_OpIsUnz && cmd != DLL_OPT_OpIsTest) |
||
246 | { |
||
247 | return -DZ_ERR_STRUCT; |
||
248 | } |
||
249 | |||
250 | try |
||
251 | { |
||
252 | if (cmd == DLL_OPT_OpIsZip || cmd == DLL_OPT_OpIsDelete) |
||
253 | pG = MakeZipper(C); |
||
254 | else |
||
255 | pG = MakeUnzipper(C); |
||
256 | |||
257 | if (!pG) |
||
258 | throw DZFatalException(DZ_ERR_MEMORY); |
||
259 | try |
||
260 | { |
||
261 | try |
||
262 | { |
||
263 | RetVal = pG->Init(); |
||
264 | if (!RetVal) |
||
265 | { |
||
266 | RetVal = pG->Exec(C); |
||
267 | if (pG->Verbose < 0) |
||
268 | pG->Notify(ITRACE, _T("RetVal = %d "), RetVal); |
||
269 | } |
||
270 | } |
||
271 | catch(DZFatalException & E) |
||
272 | { |
||
273 | RetVal = -DZ_ERR(E.ErrNo); |
||
274 | } |
||
275 | catch(std::bad_alloc) |
||
276 | { |
||
277 | RetVal = -DZ_ERR_MEMORY; |
||
278 | } |
||
279 | catch(int X) |
||
280 | { |
||
281 | X = DZ_ERR(X); |
||
282 | RetVal = -X; |
||
283 | } |
||
284 | catch(...) |
||
285 | { |
||
286 | RetVal = -DZ_ERR_ERROR; |
||
287 | } |
||
288 | } |
||
289 | __finally |
||
290 | { |
||
291 | KillpG(&pG); |
||
292 | } |
||
293 | } |
||
294 | __except (xxfilter(/* xp = */ GetExceptionInformation())) // Marx Fix |
||
295 | { |
||
296 | RetVal = -DZ_ERR_ERROR; |
||
297 | } |
||
298 | |||
299 | OutputDebugString(L"DZ_Exec done"); |
||
300 | return RetVal; |
||
301 | } |
||
302 | |||
303 | int xxfilter(EXCEPTION_POINTERS * xp) |
||
304 | { |
||
305 | int rc = EXCEPTION_CONTINUE_SEARCH; // default - give up |
||
306 | |||
307 | EXCEPTION_RECORD *xr = xp->ExceptionRecord; |
||
308 | // CONTEXT *xc = xp->ContextRecord; |
||
309 | switch (xr->ExceptionCode) { |
||
310 | case STATUS_INTEGER_DIVIDE_BY_ZERO: |
||
311 | case EXCEPTION_ACCESS_VIOLATION: |
||
312 | rc = EXCEPTION_EXECUTE_HANDLER; |
||
313 | // break; |
||
314 | }; |
||
315 | return rc; |
||
316 | } |