source: trunk/dll/extract.c@ 1694

Last change on this file since 1694 was 1694, checked in by Gregg Young, 12 years ago

Added comments for CS 1690 & 1692

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: extract.c 1694 2013-08-11 22:38:03Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2013 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 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
17 29 Nov 08 GKY Add the option of creating a subdirectory from the arcname
18 for the extract path.
19 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
20 17 Jan 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
21 23 Oct 10 GKY Changes to populate and utilize a HELPTABLE for context specific help
22 11 Aug 13 GKY Fix directory create failure on extract to directory based on archive name
23 if the name needed quoting.
24
25***********************************************************************/
26
27#include <string.h>
28#include <ctype.h>
29
30#define INCL_WIN
31#define INCL_DOS
32#define INCL_LONGLONG // dircnrs.h
33
34#include "fm3dll.h"
35#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
36#include "init.h" // Data declaration(s)
37#include "arccnrs.h" // Data declaration(s)
38#include "notebook.h" // Data declaration(s)
39#include "mainwnd.h" // Data declaration(s)
40#include "fm3dlg.h"
41#include "fm3str.h"
42#include "errutil.h" // Dos_Error...
43#include "strutil.h" // GetPString
44#include "cmdline.h" // CmdLineDlgProc
45#include "extract.h"
46#include "walkem.h" // WalkExtractDlgProc
47#include "droplist.h" // AcceptOneDrop, DropHelp, GetOneDrop
48#include "misc.h" // DrawTargetEmphasis
49#include "chklist.h" // PosOverOkay
50#include "mkdir.h" // SetDir
51#include "valid.h" // MakeValidDir
52#include "systemf.h" // runemf2
53#include "dirs.h" // save_dir2
54#include "strips.h" // bstrip
55
56#pragma data_seg(DATA1)
57
58static PSZ pszSrcFile = __FILE__;
59
60MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
61{
62 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
63 static BOOL emphasized = FALSE;
64
65 switch (msg) {
66 case DM_DRAGOVER:
67 if (!emphasized) {
68 emphasized = TRUE;
69 DrawTargetEmphasis(hwnd, emphasized);
70 }
71 if (AcceptOneDrop(hwnd, mp1, mp2))
72 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
73 return MRFROM2SHORT(DOR_NEVERDROP, 0);
74
75 case DM_DRAGLEAVE:
76 if (emphasized) {
77 emphasized = FALSE;
78 DrawTargetEmphasis(hwnd, emphasized);
79 }
80 break;
81
82 case DM_DROPHELP:
83 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
84 return 0;
85
86 case DM_DROP:
87 {
88 char szFrom[CCHMAXPATH + 2];
89
90 if (emphasized) {
91 emphasized = FALSE;
92 DrawTargetEmphasis(hwnd, emphasized);
93 }
94 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
95 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
96 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
97 }
98 return 0;
99 }
100 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
101 WinDefWindowProc(hwnd, msg, mp1, mp2);
102}
103
104MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
105{
106 EXTRDATA *arcdata = NULL;
107 ULONG size;
108 BOOL fFileNameExtPath;
109
110 switch (msg) {
111 case WM_INITDLG:
112 WinSetWindowPtr(hwnd, QWL_USER, mp2);
113 arcdata = (EXTRDATA *) mp2;
114 {
115 BOOL fDirectory = FALSE;
116 BOOL fRemember = FALSE;
117 PFNWP oldproc;
118
119 fFileNameExtPath = FALSE;
120 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
121 (PFNWP) ExtractTextProc);
122 if (oldproc)
123 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
124 QWL_USER, (PVOID) oldproc);
125 size = sizeof(BOOL);
126 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
127 (PVOID) & fRemember, &size);
128 size = sizeof(BOOL);
129 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
130 (PVOID) & fDirectory, &size);
131 size = sizeof(BOOL);
132 PrfQueryProfileData(fmprof, FM3Str, "FileNamePathExt",
133 (PVOID) & fFileNameExtPath, &size);
134 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
135 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
136 WinCheckButton(hwnd, EXT_FILENAMEEXT, fFileNameExtPath);
137 WinSendDlgItemMsg(hwnd, EXT_DIRECTORY, EM_SETTEXTLIMIT,
138 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
139 WinSendDlgItemMsg(hwnd, EXT_COMMAND, EM_SETTEXTLIMIT,
140 MPFROM2SHORT(256, 0), MPVOID);
141 WinSendDlgItemMsg(hwnd, EXT_MASK, EM_SETTEXTLIMIT,
142 MPFROM2SHORT(256, 0), MPVOID);
143 WinSendDlgItemMsg(hwnd, EXT_FILENAME, EM_SETTEXTLIMIT,
144 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
145 if (arcdata->arcname && *arcdata->arcname)
146 WinSetDlgItemText(hwnd, EXT_FILENAME, arcdata->arcname);
147 else
148 WinSetDlgItemText(hwnd, EXT_FILENAME, (CHAR *) GetPString(IDS_EXTVARIOUSTEXT));
149
150 if (fFileNameExtPath && arcdata->arcname) {
151
152 CHAR FileName[CCHMAXPATH];
153 PSZ p;
154
155 strcpy(FileName, arcdata->arcname);
156 p = strrchr(FileName, '.');
157 if (p) {
158 *p = 0;
159 if (strchr(FileName, '\"'))
160 memmove(FileName, FileName + 1, strlen(FileName) + 1);
161 }
162 else {
163 p = FileName + strlen(arcdata->arcname);
164 p--;
165 *p = 0;
166 if (strchr(FileName, '\"'))
167 memmove(FileName , FileName + 1, strlen(FileName) + 1);
168 }
169 strcpy(arcdata->extractdir, FileName);
170 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
171 }
172 if (fDirectory) {
173 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
174 MPFROM2SHORT(TRUE, 0), MPVOID);
175 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
176 }
177 else {
178 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
179 MPFROM2SHORT(TRUE, 0), MPVOID);
180 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
181
182 }
183 if (fRemember) {
184
185 CHAR textdir[CCHMAXPATH];
186
187 PrfQueryProfileString(fmprof, FM3Str, "Ext_ExtractDir", NULL, textdir, sizeof(textdir));
188 if (*textdir && !IsFile(textdir))
189 strcpy(arcdata->extractdir, textdir);
190 PrfQueryProfileString(fmprof, FM3Str, "Ext_Mask", NULL, textdir, sizeof(textdir));
191 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
192 }
193 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
194 if (arcdata->arcname && *arcdata->arcname &&
195 !strcmp(extractpath, "*")) {
196
197 CHAR *p;
198
199 strcpy(arcdata->extractdir, arcdata->arcname);
200 p = strrchr(arcdata->extractdir, '\\');
201 if (p) {
202 if (p < arcdata->extractdir + 3)
203 p++;
204 *p = 0;
205 }
206 }
207 else
208 strcpy(arcdata->extractdir, extractpath);
209 }
210 if (!*arcdata->extractdir) {
211 if (*lastextractpath)
212 strcpy(arcdata->extractdir, lastextractpath);
213 else if (arcdata->arcname && *arcdata->arcname) {
214
215 CHAR *p;
216
217 strcpy(arcdata->extractdir, arcdata->arcname);
218 p = strrchr(arcdata->extractdir, '\\');
219 if (p) {
220 if (p < arcdata->extractdir + 3)
221 p++;
222 *p = 0;
223 }
224 }
225 if (!*arcdata->extractdir)
226 strcpy(arcdata->extractdir, pFM2SaveDirectory);
227 }
228 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
229 if (!arcdata->info->exwdirs)
230 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
231 else if (fRemember) {
232 fRemember = FALSE;
233 size = sizeof(BOOL);
234 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
235 (PVOID) &fRemember, &size);
236 if (fRemember)
237 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
238 }
239 }
240 *arcdata->command = 0;
241 PosOverOkay(hwnd);
242 break;
243
244 case WM_ADJUSTWINDOWPOS:
245 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
246 break;
247
248 case UM_SETDIR:
249 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
250 TRUE);
251 return 0;
252
253 case WM_CONTROL:
254 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
255 switch (SHORT1FROMMP(mp1)) {
256 case EXT_REMEMBER:
257 {
258 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
259 size = sizeof(BOOL);
260 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
261 (PVOID) &fRemember, size);
262 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
263 MPFROM2SHORT(FALSE, 0), MPVOID);
264 }
265 break;
266
267 case EXT_AWDIRS:
268 {
269 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
270 size = sizeof(BOOL);
271 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
272 (PVOID) &fDirectory, size);
273
274 if (fDirectory) {
275 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
276 MPFROM2SHORT(TRUE, 0), MPVOID);
277 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
278 }
279 else {
280 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
281 MPFROM2SHORT(TRUE, 0), MPVOID);
282 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
283 }
284 }
285 break;
286
287 case EXT_FILENAMEEXT:
288 {
289 BOOL fFileNameExtPath = WinQueryButtonCheckstate(hwnd, EXT_FILENAMEEXT);
290 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
291 size = sizeof(BOOL);
292 PrfWriteProfileData(fmprof, FM3Str, "FileNamePathExt",
293 fRemember ? FALSE : (PVOID) &fFileNameExtPath, size);
294 if (fRemember) {
295 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
296 MPFROM2SHORT(FALSE, 0), MPVOID);
297 break;
298 }
299 if (fFileNameExtPath && arcdata->arcname) {
300 CHAR FileName[CCHMAXPATH];
301 PSZ p;
302
303 strcpy(FileName, arcdata->arcname);
304 p = strrchr(FileName, '.');
305 if (p) {
306 *p = 0;
307 if (strchr(FileName, '\"'))
308 memmove(FileName, FileName + 1, strlen(FileName) + 1);
309 }
310 else {
311 p = FileName + strlen(arcdata->arcname);
312 p--;
313 *p = 0;
314 if (strchr(FileName, '\"'))
315 memmove(FileName, FileName + 1, strlen(FileName) + 1);
316 }
317 strcpy(arcdata->extractdir, FileName);
318 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
319 }
320 else {
321 *arcdata->extractdir = 0;
322 if (*extractpath) {
323 if (arcdata->arcname && *arcdata->arcname &&
324 !strcmp(extractpath, "*")) {
325
326 CHAR *p;
327
328 strcpy(arcdata->extractdir, arcdata->arcname);
329 p = strrchr(arcdata->extractdir, '\\');
330 if (p) {
331 if (p < arcdata->extractdir + 3)
332 p++;
333 *p = 0;
334 }
335 }
336 else
337 strcpy(arcdata->extractdir, extractpath);
338 }
339 if (!*arcdata->extractdir) {
340 if (arcdata->arcname && *arcdata->arcname) {
341
342 CHAR *p;
343
344 strcpy(arcdata->extractdir, arcdata->arcname);
345 p = strrchr(arcdata->extractdir, '\\');
346 if (p) {
347 if (p < arcdata->extractdir + 3)
348 p++;
349 *p = 0;
350 }
351 }
352 if (!*arcdata->extractdir)
353 strcpy(arcdata->extractdir, pFM2SaveDirectory);
354 }
355 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
356 }
357 }
358 break;
359
360 case EXT_FILENAME:
361 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
362 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
363 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
364 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCARCNAMEHELPTEXT));
365 break;
366
367 case EXT_DIRECTORY:
368 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
369 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
370 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
371 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_EXTEXTRACTDIRHELPTEXT));
372 break;
373
374 case EXT_COMMAND:
375 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
376 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
377 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
378 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCCMDHELPTEXT));
379 break;
380
381 case EXT_MASK:
382 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
383 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
384 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
385 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCMASKHELPTEXT));
386 break;
387
388 case EXT_NORMAL:
389 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_QUERYCHECK,
390 MPVOID, MPVOID))
391 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
392 break;
393
394 case EXT_WDIRS:
395 if (arcdata->info->exwdirs) {
396 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_QUERYCHECK,
397 MPVOID, MPVOID))
398 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
399 }
400 break;
401 }
402 return 0;
403
404 case WM_COMMAND:
405 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
406 switch (SHORT1FROMMP(mp1)) {
407 case IDM_SWITCH:
408 if (mp2) {
409
410 CHAR tdir[CCHMAXPATH];
411
412 strcpy(tdir, (CHAR *) mp2);
413 MakeValidDir(tdir);
414 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
415 }
416 break;
417
418 case DID_CANCEL:
419 arcdata->ret = 0;
420 WinDismissDlg(hwnd, 0);
421 break;
422 case DID_OK:
423 {
424 CHAR s[CCHMAXPATH + 1];
425 BOOL fRemember;
426
427 fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
428 *s = 0;
429 WinQueryDlgItemText(hwnd, EXT_DIRECTORY, CCHMAXPATH, s);
430 bstrip(s);
431 if (*s) {
432 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
433 QW_OWNER), hwnd, s, fFileNameExtPath ? 1:0)) {
434 strcpy(arcdata->extractdir, s);
435 WinSetDlgItemText(hwnd, EXT_DIRECTORY, s);
436 if ((!isalpha(*s) || s[1] != ':') && *s != '.')
437 saymsg(MB_ENTER, hwnd,
438 GetPString(IDS_WARNINGTEXT),
439 GetPString(IDS_SPECIFYDRIVETEXT));
440 }
441 else
442 break;
443 strcpy(lastextractpath, s);
444 if (fRemember) {
445 PrfWriteProfileString(fmprof, FM3Str, "Ext_ExtractDir", s);
446 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
447 size = sizeof(BOOL);
448 PrfWriteProfileData(fmprof, FM3Str, "Ext_WDirs",
449 (PVOID) &fRemember, size);
450 fRemember = TRUE;
451 }
452 *s = 0;
453 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
454 if (*s) {
455 strcpy(arcdata->command, s);
456 *s = 0;
457 WinQueryDlgItemText(hwnd, EXT_MASK, 256, s);
458 *arcdata->masks = 0;
459 strcpy(arcdata->masks, s);
460 if (fRemember)
461 PrfWriteProfileString(fmprof, FM3Str, "Ext_Mask", s);
462 arcdata->ret = 1;
463 WinDismissDlg(hwnd, 1);
464 break;
465 }
466 }
467 }
468 if (!fErrorBeepOff)
469 DosBeep(50, 100); // Complain a refuse to quit
470 break;
471
472 case IDM_HELP:
473 case WM_HELP:
474 if (hwndHelp)
475 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
476 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
477 break;
478
479 case EXT_WALK:
480 {
481 CHAR temp[CCHMAXPATH + 1];
482
483 strcpy(temp, arcdata->extractdir);
484 if (WinDlgBox(HWND_DESKTOP, WinQueryWindow(WinQueryWindow(hwnd,
485 QW_PARENT),
486 QW_OWNER),
487 WalkExtractDlgProc, FM3ModHandle, WALK_FRAME,
488 (PVOID) temp)) {
489 if (*temp && stricmp(temp, arcdata->extractdir)) {
490 strcpy(arcdata->extractdir, temp);
491 }
492 }
493 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
494 }
495 break;
496
497 case EXT_SEE:
498 {
499 CHAR s[1001], *p;
500 EXECARGS ex;
501
502 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
503 lstrip(s);
504 if (!*s)
505 Runtime_Error(pszSrcFile, __LINE__, "no command");
506 else {
507 p = strchr(s, ' ');
508 if (p)
509 *p = 0; // Drop options
510 memset(&ex, 0, sizeof(EXECARGS));
511 ex.commandline = s;
512 ex.flags = WINDOWED | SEPARATEKEEP | MAXIMIZED;
513 *ex.path = 0;
514 *ex.environment = 0;
515 if (WinDlgBox(HWND_DESKTOP,
516 hwnd,
517 CmdLineDlgProc,
518 FM3ModHandle, EXEC_FRAME, MPFROMP(&ex)) && *s) {
519 runemf2(ex.flags,
520 hwnd, pszSrcFile, __LINE__,
521 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
522 }
523 }
524 }
525 break;
526 }
527 return 0;
528
529 case WM_CLOSE:
530 break;
531 }
532 return WinDefDlgProc(hwnd, msg, mp1, mp2);
533}
534
535#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.