source: trunk/dll/extract.c@ 1505

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

Remove unnecessary type casts; minor formating cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.2 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: extract.c 1505 2010-04-11 22:29:56Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
[1498]7 Copyright (c) 2004, 2010 Steven H. Levine
[123]8
[186]9 01 Aug 04 SHL Rework lstrip/rstrip usage
10 05 Jun 05 SHL Use QWL_USER
[350]11 17 Jul 06 SHL Use Runtime_Error
[549]12 20 Dec 06 GKY Added checkbox to make default extract with directories
[574]13 22 Mar 07 GKY Use QWL_USER
[618]14 19 Apr 07 SHL Sync with AcceptOneDrop GetOneDrop mods
[793]15 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[1104]16 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
[1300]17 29 Nov 08 GKY Add the option of creating a subdirectory from the arcname
18 for the extract path.
[1395]19 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
[1498]20 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
[123]21
22***********************************************************************/
23
[907]24#include <string.h>
25#include <ctype.h>
26
[2]27#define INCL_WIN
28#define INCL_DOS
[907]29#define INCL_LONGLONG // dircnrs.h
[2]30
[1179]31#include "fm3dll.h"
[1223]32#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1207]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)
[2]37#include "fm3dlg.h"
38#include "fm3str.h"
[907]39#include "errutil.h" // Dos_Error...
40#include "strutil.h" // GetPString
[1157]41#include "cmdline.h" // CmdLineDlgProc
42#include "extract.h"
43#include "walkem.h" // WalkExtractDlgProc
[1179]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
[2]52
53#pragma data_seg(DATA1)
[350]54
55static PSZ pszSrcFile = __FILE__;
[2]56
[551]57MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[350]58{
[574]59 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
[551]60 static BOOL emphasized = FALSE;
[2]61
[551]62 switch (msg) {
63 case DM_DRAGOVER:
64 if (!emphasized) {
65 emphasized = TRUE;
66 DrawTargetEmphasis(hwnd, emphasized);
67 }
[618]68 if (AcceptOneDrop(hwnd, mp1, mp2))
[551]69 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
70 return MRFROM2SHORT(DOR_NEVERDROP, 0);
[2]71
[551]72 case DM_DRAGLEAVE:
73 if (emphasized) {
74 emphasized = FALSE;
75 DrawTargetEmphasis(hwnd, emphasized);
76 }
77 break;
[2]78
[551]79 case DM_DROPHELP:
80 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
81 return 0;
[2]82
[551]83 case DM_DROP:
84 {
85 char szFrom[CCHMAXPATH + 2];
[2]86
[551]87 if (emphasized) {
88 emphasized = FALSE;
89 DrawTargetEmphasis(hwnd, emphasized);
[2]90 }
[618]91 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
[551]92 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
93 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
94 }
95 return 0;
[2]96 }
[551]97 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
98 WinDefWindowProc(hwnd, msg, mp1, mp2);
[2]99}
100
[551]101MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[350]102{
[551]103 EXTRDATA *arcdata = NULL;
[1344]104 ULONG size;
[1300]105 BOOL fFileNameExtPath;
[2]106
[551]107 switch (msg) {
108 case WM_INITDLG:
[574]109 WinSetWindowPtr(hwnd, QWL_USER, mp2);
[551]110 arcdata = (EXTRDATA *) mp2;
111 {
[1344]112 BOOL fDirectory = FALSE;
[551]113 BOOL fRemember = FALSE;
114 PFNWP oldproc;
[2]115
[1300]116 fFileNameExtPath = FALSE;
[551]117 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
118 (PFNWP) ExtractTextProc);
119 if (oldproc)
120 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
[1344]121 QWL_USER, (PVOID) oldproc);
122 size = sizeof(BOOL);
[1505]123 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
[1344]124 (PVOID) & fRemember, &size);
125 size = sizeof(BOOL);
[1505]126 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
[1300]127 (PVOID) & fDirectory, &size);
[1344]128 size = sizeof(BOOL);
[1505]129 PrfQueryProfileData(fmprof, FM3Str, "FileNamePathExt",
[1300]130 (PVOID) & fFileNameExtPath, &size);
[551]131 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
132 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
[1300]133 WinCheckButton(hwnd, EXT_FILENAMEEXT, fFileNameExtPath);
[551]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
[1498]145 WinSetDlgItemText(hwnd, EXT_FILENAME, (CHAR *) GetPString(IDS_EXTVARIOUSTEXT));
[1300]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 }
[551]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);
[549]173
[551]174 }
175 if (fRemember) {
[2]176
[1344]177 CHAR textdir[CCHMAXPATH];
[2]178
[1505]179 PrfQueryProfileString(fmprof, FM3Str, "Ext_ExtractDir", NULL, textdir, sizeof(textdir));
[551]180 if (*textdir && !IsFile(textdir))
181 strcpy(arcdata->extractdir, textdir);
[1505]182 PrfQueryProfileString(fmprof, FM3Str, "Ext_Mask", NULL, textdir, sizeof(textdir));
[551]183 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
184 }
185 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
186 if (arcdata->arcname && *arcdata->arcname &&
187 !strcmp(extractpath, "*")) {
[2]188
[551]189 CHAR *p;
[2]190
[551]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) {
[2]206
[551]207 CHAR *p;
[2]208
[551]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)
[1104]218 strcpy(arcdata->extractdir, pFM2SaveDirectory);
[2]219 }
[551]220 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
221 if (!arcdata->info->exwdirs)
222 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
223 else if (fRemember) {
[1344]224 fRemember = FALSE;
225 size = sizeof(BOOL);
[1505]226 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
[1300]227 (PVOID) &fRemember, &size);
[551]228 if (fRemember)
229 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
230 }
231 }
232 *arcdata->command = 0;
233 PosOverOkay(hwnd);
234 break;
[2]235
[551]236 case WM_ADJUSTWINDOWPOS:
237 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
238 break;
[2]239
[551]240 case UM_SETDIR:
241 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
242 TRUE);
243 return 0;
[2]244
[551]245 case WM_CONTROL:
[574]246 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
[551]247 switch (SHORT1FROMMP(mp1)) {
248 case EXT_REMEMBER:
249 {
250 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
[1344]251 size = sizeof(BOOL);
[1505]252 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
[1344]253 (PVOID) &fRemember, size);
254 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
255 MPFROM2SHORT(FALSE, 0), MPVOID);
[551]256 }
257 break;
[2]258
[551]259 case EXT_AWDIRS:
260 {
261 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
[1344]262 size = sizeof(BOOL);
[1505]263 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
[1300]264 (PVOID) &fDirectory, size);
[549]265
[551]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;
[549]278
[1300]279 case EXT_FILENAMEEXT:
280 {
[1344]281 BOOL fFileNameExtPath = WinQueryButtonCheckstate(hwnd, EXT_FILENAMEEXT);
282 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
283 size = sizeof(BOOL);
[1505]284 PrfWriteProfileData(fmprof, FM3Str, "FileNamePathExt",
[1344]285 fRemember ? FALSE : (PVOID) &fFileNameExtPath, size);
[1349]286 if (fRemember) {
287 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
288 MPFROM2SHORT(FALSE, 0), MPVOID);
[1344]289 break;
[1349]290 }
[1300]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) {
[1306]327 if (arcdata->arcname && *arcdata->arcname) {
[1300]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
[551]347 case EXT_FILENAME:
348 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
[1498]349 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
[551]350 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[1498]351 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCARCNAMEHELPTEXT));
[551]352 break;
[2]353
[551]354 case EXT_DIRECTORY:
355 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
[1498]356 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
[551]357 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[1498]358 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_EXTEXTRACTDIRHELPTEXT));
[551]359 break;
[2]360
[551]361 case EXT_COMMAND:
362 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
[1498]363 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
[551]364 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[1498]365 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCCMDHELPTEXT));
[551]366 break;
[2]367
[551]368 case EXT_MASK:
369 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
[1498]370 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCDEFAULTHELPTEXT));
[551]371 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
[1498]372 WinSetDlgItemText(hwnd, EXT_HELP, (CHAR *) GetPString(IDS_ARCMASKHELPTEXT));
[551]373 break;
[2]374
[551]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;
[2]380
[551]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);
[2]386 }
[551]387 break;
388 }
389 return 0;
[2]390
[551]391 case WM_COMMAND:
[574]392 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
[551]393 switch (SHORT1FROMMP(mp1)) {
394 case IDM_SWITCH:
395 if (mp2) {
[2]396
[551]397 CHAR tdir[CCHMAXPATH];
[2]398
[551]399 strcpy(tdir, (CHAR *) mp2);
400 MakeValidDir(tdir);
401 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
402 }
403 break;
[2]404
[551]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;
[2]413
[551]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),
[1300]420 QW_OWNER), hwnd, s, fFileNameExtPath ? 1:0)) {
[551]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) {
[1505]432 PrfWriteProfileString(fmprof, FM3Str, "Ext_ExtractDir", s);
[1344]433 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
434 size = sizeof(BOOL);
[1505]435 PrfWriteProfileData(fmprof, FM3Str, "Ext_WDirs",
[1300]436 (PVOID) &fRemember, size);
[551]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)
[1505]448 PrfWriteProfileString(fmprof, FM3Str, "Ext_Mask", s);
[551]449 arcdata->ret = 1;
450 WinDismissDlg(hwnd, 1);
451 break;
452 }
453 }
454 }
[1395]455 if (!fErrorBeepOff)
456 DosBeep(50, 100); // Complain a refuse to quit
[551]457 break;
[2]458
[551]459 case IDM_HELP:
460 if (hwndHelp)
461 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
462 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
463 break;
[2]464
[551]465 case EXT_WALK:
466 {
467 CHAR temp[CCHMAXPATH + 1];
[2]468
[551]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;
[2]482
[551]483 case EXT_SEE:
484 {
485 CHAR s[1001], *p;
486 EXECARGS ex;
[2]487
[551]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,
[888]506 hwnd, pszSrcFile, __LINE__,
[551]507 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
508 }
509 }
[2]510 }
[551]511 break;
512 }
513 return 0;
[2]514
[551]515 case WM_CLOSE:
516 break;
[2]517 }
[551]518 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]519}
[793]520
521#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.