source: trunk/dll/extract.c@ 1570

Last change on this file since 1570 was 1546, checked in by Gregg Young, 15 years ago

Add menu item to allow opening of directory container from the collector based on the path of the selected item. (Ticket 362) Add open file button to EAs dialog to allow opening of a new file's eas (Ticket 439). Initial work on populating the help table (It provides F1 help a few more places) (Ticket 95). Some minor code cleanup and help file updates.

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