source: trunk/dll/extract.c@ 1349

Last change on this file since 1349 was 1349, checked in by Gregg Young, 17 years ago

Filename as ext dir can't be selected while Remember is selected

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