source: trunk/dll/extract.c@ 1036

Last change on this file since 1036 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.0 KB
Line 
1
2/***********************************************************************
3
4 $Id: extract.c 907 2008-01-06 07:26:17Z stevenhl $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2007 Steven H. Levine
8
9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 05 Jun 05 SHL Use QWL_USER
11 17 Jul 06 SHL Use Runtime_Error
12 20 Dec 06 GKY Added checkbox to make default extract with directories
13 22 Mar 07 GKY Use QWL_USER
14 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
15 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
16
17***********************************************************************/
18
19#include <string.h>
20#include <ctype.h>
21
22#define INCL_WIN
23#define INCL_DOS
24#define INCL_LONGLONG // dircnrs.h
25
26#include "fm3dlg.h"
27#include "fm3str.h"
28#include "errutil.h" // Dos_Error...
29#include "strutil.h" // GetPString
30#include "fm3dll.h"
31
32#pragma data_seg(DATA1)
33
34static PSZ pszSrcFile = __FILE__;
35
36MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
37{
38 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
39 static BOOL emphasized = FALSE;
40
41 switch (msg) {
42 case DM_DRAGOVER:
43 if (!emphasized) {
44 emphasized = TRUE;
45 DrawTargetEmphasis(hwnd, emphasized);
46 }
47 if (AcceptOneDrop(hwnd, mp1, mp2))
48 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
49 return MRFROM2SHORT(DOR_NEVERDROP, 0);
50
51 case DM_DRAGLEAVE:
52 if (emphasized) {
53 emphasized = FALSE;
54 DrawTargetEmphasis(hwnd, emphasized);
55 }
56 break;
57
58 case DM_DROPHELP:
59 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
60 return 0;
61
62 case DM_DROP:
63 {
64 char szFrom[CCHMAXPATH + 2];
65
66 if (emphasized) {
67 emphasized = FALSE;
68 DrawTargetEmphasis(hwnd, emphasized);
69 }
70 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
71 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
72 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
73 }
74 return 0;
75 }
76 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
77 WinDefWindowProc(hwnd, msg, mp1, mp2);
78}
79
80MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
81{
82 EXTRDATA *arcdata = NULL;
83
84 switch (msg) {
85 case WM_INITDLG:
86 WinSetWindowPtr(hwnd, QWL_USER, mp2);
87 arcdata = (EXTRDATA *) mp2;
88 {
89 ULONG size = sizeof(BOOL);
90 BOOL fRemember = FALSE;
91 BOOL fDirectory = FALSE;
92 PFNWP oldproc;
93
94 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
95 (PFNWP) ExtractTextProc);
96 if (oldproc)
97 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
98 QWL_USER, (PVOID) oldproc);
99 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
100 (PVOID) & fRemember, &size);
101 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
102 (PVOID) & fDirectory, &size);
103 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
104 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
105 WinSendDlgItemMsg(hwnd, EXT_DIRECTORY, EM_SETTEXTLIMIT,
106 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
107 WinSendDlgItemMsg(hwnd, EXT_COMMAND, EM_SETTEXTLIMIT,
108 MPFROM2SHORT(256, 0), MPVOID);
109 WinSendDlgItemMsg(hwnd, EXT_MASK, EM_SETTEXTLIMIT,
110 MPFROM2SHORT(256, 0), MPVOID);
111 WinSendDlgItemMsg(hwnd, EXT_FILENAME, EM_SETTEXTLIMIT,
112 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
113 if (arcdata->arcname && *arcdata->arcname)
114 WinSetDlgItemText(hwnd, EXT_FILENAME, arcdata->arcname);
115 else
116 WinSetDlgItemText(hwnd, EXT_FILENAME, GetPString(IDS_EXTVARIOUSTEXT));
117 if (fDirectory) {
118 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
119 MPFROM2SHORT(TRUE, 0), MPVOID);
120 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
121 }
122 else {
123 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
124 MPFROM2SHORT(TRUE, 0), MPVOID);
125 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
126
127 }
128 if (fRemember) {
129
130 CHAR textdir[CCHMAXPATH];
131
132 size = sizeof(textdir);
133 *textdir = 0;
134 PrfQueryProfileData(fmprof, FM3Str, "Ext_ExtractDir",
135 (PVOID) textdir, &size);
136 if (*textdir && !IsFile(textdir))
137 strcpy(arcdata->extractdir, textdir);
138 size = sizeof(textdir);
139 *textdir = 0;
140 PrfQueryProfileData(fmprof, FM3Str, "Ext_Mask", (PVOID) textdir,
141 &size);
142 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
143 }
144 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
145 if (arcdata->arcname && *arcdata->arcname &&
146 !strcmp(extractpath, "*")) {
147
148 CHAR *p;
149
150 strcpy(arcdata->extractdir, arcdata->arcname);
151 p = strrchr(arcdata->extractdir, '\\');
152 if (p) {
153 if (p < arcdata->extractdir + 3)
154 p++;
155 *p = 0;
156 }
157 }
158 else
159 strcpy(arcdata->extractdir, extractpath);
160 }
161 if (!*arcdata->extractdir) {
162 if (*lastextractpath)
163 strcpy(arcdata->extractdir, lastextractpath);
164 else if (arcdata->arcname && *arcdata->arcname) {
165
166 CHAR *p;
167
168 strcpy(arcdata->extractdir, arcdata->arcname);
169 p = strrchr(arcdata->extractdir, '\\');
170 if (p) {
171 if (p < arcdata->extractdir + 3)
172 p++;
173 *p = 0;
174 }
175 }
176 if (!*arcdata->extractdir)
177 save_dir2(arcdata->extractdir);
178 }
179 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
180 if (!arcdata->info->exwdirs)
181 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
182 else if (fRemember) {
183 size = sizeof(BOOL);
184 fRemember = FALSE;
185 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
186 (PVOID) & fRemember, &size);
187 if (fRemember)
188 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
189 }
190 }
191 *arcdata->command = 0;
192 PosOverOkay(hwnd);
193 break;
194
195 case WM_ADJUSTWINDOWPOS:
196 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
197 break;
198
199 case UM_SETDIR:
200 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
201 TRUE);
202 return 0;
203
204 case WM_CONTROL:
205 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
206 switch (SHORT1FROMMP(mp1)) {
207 case EXT_REMEMBER:
208 {
209 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
210
211 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
212 (PVOID) & fRemember, sizeof(BOOL));
213 }
214 break;
215
216 case EXT_AWDIRS:
217 {
218 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
219
220 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
221 (PVOID) & fDirectory, sizeof(BOOL));
222
223 if (fDirectory) {
224 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
225 MPFROM2SHORT(TRUE, 0), MPVOID);
226 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
227 }
228 else {
229 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
230 MPFROM2SHORT(TRUE, 0), MPVOID);
231 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
232 }
233 }
234 break;
235
236 case EXT_FILENAME:
237 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
238 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
239 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
240 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCARCNAMEHELPTEXT));
241 break;
242
243 case EXT_DIRECTORY:
244 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
245 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
246 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
247 WinSetDlgItemText(hwnd, EXT_HELP,
248 GetPString(IDS_EXTEXTRACTDIRHELPTEXT));
249 break;
250
251 case EXT_COMMAND:
252 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
253 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
254 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
255 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCCMDHELPTEXT));
256 break;
257
258 case EXT_MASK:
259 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
260 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
261 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
262 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCMASKHELPTEXT));
263 break;
264
265 case EXT_NORMAL:
266 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_QUERYCHECK,
267 MPVOID, MPVOID))
268 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
269 break;
270
271 case EXT_WDIRS:
272 if (arcdata->info->exwdirs) {
273 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_QUERYCHECK,
274 MPVOID, MPVOID))
275 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
276 }
277 break;
278 }
279 return 0;
280
281 case WM_COMMAND:
282 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
283 switch (SHORT1FROMMP(mp1)) {
284 case IDM_SWITCH:
285 if (mp2) {
286
287 CHAR tdir[CCHMAXPATH];
288
289 strcpy(tdir, (CHAR *) mp2);
290 MakeValidDir(tdir);
291 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
292 }
293 break;
294
295 case DID_CANCEL:
296 arcdata->ret = 0;
297 WinDismissDlg(hwnd, 0);
298 break;
299 case DID_OK:
300 {
301 CHAR s[CCHMAXPATH + 1];
302 BOOL fRemember;
303
304 fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
305 *s = 0;
306 WinQueryDlgItemText(hwnd, EXT_DIRECTORY, CCHMAXPATH, s);
307 bstrip(s);
308 if (*s) {
309 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
310 QW_OWNER), hwnd, s, 0)) {
311 strcpy(arcdata->extractdir, s);
312 WinSetDlgItemText(hwnd, EXT_DIRECTORY, s);
313 if ((!isalpha(*s) || s[1] != ':') && *s != '.')
314 saymsg(MB_ENTER, hwnd,
315 GetPString(IDS_WARNINGTEXT),
316 GetPString(IDS_SPECIFYDRIVETEXT));
317 }
318 else
319 break;
320 strcpy(lastextractpath, s);
321 if (fRemember) {
322 PrfWriteProfileString(fmprof, FM3Str, "Ext_ExtractDir", s);
323 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
324 PrfWriteProfileData(fmprof, FM3Str, "Ext_WDirs",
325 (PVOID) & fRemember, sizeof(BOOL));
326 fRemember = TRUE;
327 }
328 *s = 0;
329 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
330 if (*s) {
331 strcpy(arcdata->command, s);
332 *s = 0;
333 WinQueryDlgItemText(hwnd, EXT_MASK, 256, s);
334 *arcdata->masks = 0;
335 strcpy(arcdata->masks, s);
336 if (fRemember)
337 PrfWriteProfileString(fmprof, FM3Str, "Ext_Mask", s);
338 arcdata->ret = 1;
339 WinDismissDlg(hwnd, 1);
340 break;
341 }
342 }
343 }
344 DosBeep(50, 100); // Complain a refuse to quit
345 break;
346
347 case IDM_HELP:
348 if (hwndHelp)
349 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
350 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
351 break;
352
353 case EXT_WALK:
354 {
355 CHAR temp[CCHMAXPATH + 1];
356
357 strcpy(temp, arcdata->extractdir);
358 if (WinDlgBox(HWND_DESKTOP, WinQueryWindow(WinQueryWindow(hwnd,
359 QW_PARENT),
360 QW_OWNER),
361 WalkExtractDlgProc, FM3ModHandle, WALK_FRAME,
362 (PVOID) temp)) {
363 if (*temp && stricmp(temp, arcdata->extractdir)) {
364 strcpy(arcdata->extractdir, temp);
365 }
366 }
367 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
368 }
369 break;
370
371 case EXT_SEE:
372 {
373 CHAR s[1001], *p;
374 EXECARGS ex;
375
376 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
377 lstrip(s);
378 if (!*s)
379 Runtime_Error(pszSrcFile, __LINE__, "no command");
380 else {
381 p = strchr(s, ' ');
382 if (p)
383 *p = 0; // Drop options
384 memset(&ex, 0, sizeof(EXECARGS));
385 ex.commandline = s;
386 ex.flags = WINDOWED | SEPARATEKEEP | MAXIMIZED;
387 *ex.path = 0;
388 *ex.environment = 0;
389 if (WinDlgBox(HWND_DESKTOP,
390 hwnd,
391 CmdLineDlgProc,
392 FM3ModHandle, EXEC_FRAME, MPFROMP(&ex)) && *s) {
393 runemf2(ex.flags,
394 hwnd, pszSrcFile, __LINE__,
395 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
396 }
397 }
398 }
399 break;
400 }
401 return 0;
402
403 case WM_CLOSE:
404 break;
405 }
406 return WinDefDlgProc(hwnd, msg, mp1, mp2);
407}
408
409#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.