source: trunk/dll/extract.c@ 1498

Last change on this file since 1498 was 1498, checked in by Gregg Young, 16 years ago

Changes to get FM2 to compile with the latest watcom 1.9 beta (mostly type casts of CHAR CONSTANT * to CHAR *). Changes to get the environment settings working everywhere again (broken by the change that moved commands to the INI); Added an environment size variable (set to 2048 which was the largest I found hard coded). Still need to find everywhere the environment size is set and use this variable.

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