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
Line 
1
2/***********************************************************************
3
4 $Id: extract.c 1349 2008-12-20 04:27:50Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2008 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
20***********************************************************************/
21
22#include <string.h>
23#include <ctype.h>
24
25#define INCL_WIN
26#define INCL_DOS
27#define INCL_LONGLONG // dircnrs.h
28
29#include "fm3dll.h"
30#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
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)
35#include "fm3dlg.h"
36#include "fm3str.h"
37#include "errutil.h" // Dos_Error...
38#include "strutil.h" // GetPString
39#include "cmdline.h" // CmdLineDlgProc
40#include "extract.h"
41#include "walkem.h" // WalkExtractDlgProc
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
50
51#pragma data_seg(DATA1)
52
53static PSZ pszSrcFile = __FILE__;
54
55MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
56{
57 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
58 static BOOL emphasized = FALSE;
59
60 switch (msg) {
61 case DM_DRAGOVER:
62 if (!emphasized) {
63 emphasized = TRUE;
64 DrawTargetEmphasis(hwnd, emphasized);
65 }
66 if (AcceptOneDrop(hwnd, mp1, mp2))
67 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
68 return MRFROM2SHORT(DOR_NEVERDROP, 0);
69
70 case DM_DRAGLEAVE:
71 if (emphasized) {
72 emphasized = FALSE;
73 DrawTargetEmphasis(hwnd, emphasized);
74 }
75 break;
76
77 case DM_DROPHELP:
78 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
79 return 0;
80
81 case DM_DROP:
82 {
83 char szFrom[CCHMAXPATH + 2];
84
85 if (emphasized) {
86 emphasized = FALSE;
87 DrawTargetEmphasis(hwnd, emphasized);
88 }
89 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
90 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
91 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
92 }
93 return 0;
94 }
95 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
96 WinDefWindowProc(hwnd, msg, mp1, mp2);
97}
98
99MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
100{
101 EXTRDATA *arcdata = NULL;
102 ULONG size;
103 BOOL fFileNameExtPath;
104
105 switch (msg) {
106 case WM_INITDLG:
107 WinSetWindowPtr(hwnd, QWL_USER, mp2);
108 arcdata = (EXTRDATA *) mp2;
109 {
110 BOOL fDirectory = FALSE;
111 BOOL fRemember = FALSE;
112 PFNWP oldproc;
113
114 fFileNameExtPath = FALSE;
115 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
116 (PFNWP) ExtractTextProc);
117 if (oldproc)
118 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
119 QWL_USER, (PVOID) oldproc);
120 size = sizeof(BOOL);
121 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
122 (PVOID) & fRemember, &size);
123 size = sizeof(BOOL);
124 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
125 (PVOID) & fDirectory, &size);
126 size = sizeof(BOOL);
127 PrfQueryProfileData(fmprof, FM3Str, "FileNamePathExt",
128 (PVOID) & fFileNameExtPath, &size);
129 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
130 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
131 WinCheckButton(hwnd, EXT_FILENAMEEXT, fFileNameExtPath);
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
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 }
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);
171
172 }
173 if (fRemember) {
174
175 CHAR textdir[CCHMAXPATH];
176
177 PrfQueryProfileString(fmprof, FM3Str, "Ext_ExtractDir", NULL, textdir, sizeof(textdir));
178 if (*textdir && !IsFile(textdir))
179 strcpy(arcdata->extractdir, textdir);
180 PrfQueryProfileString(fmprof, FM3Str, "Ext_Mask", NULL, textdir, sizeof(textdir));
181 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
182 }
183 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
184 if (arcdata->arcname && *arcdata->arcname &&
185 !strcmp(extractpath, "*")) {
186
187 CHAR *p;
188
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) {
204
205 CHAR *p;
206
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)
216 strcpy(arcdata->extractdir, pFM2SaveDirectory);
217 }
218 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
219 if (!arcdata->info->exwdirs)
220 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
221 else if (fRemember) {
222 fRemember = FALSE;
223 size = sizeof(BOOL);
224 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
225 (PVOID) &fRemember, &size);
226 if (fRemember)
227 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
228 }
229 }
230 *arcdata->command = 0;
231 PosOverOkay(hwnd);
232 break;
233
234 case WM_ADJUSTWINDOWPOS:
235 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
236 break;
237
238 case UM_SETDIR:
239 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
240 TRUE);
241 return 0;
242
243 case WM_CONTROL:
244 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
245 switch (SHORT1FROMMP(mp1)) {
246 case EXT_REMEMBER:
247 {
248 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
249 size = sizeof(BOOL);
250 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
251 (PVOID) &fRemember, size);
252 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
253 MPFROM2SHORT(FALSE, 0), MPVOID);
254 }
255 break;
256
257 case EXT_AWDIRS:
258 {
259 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
260 size = sizeof(BOOL);
261 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
262 (PVOID) &fDirectory, size);
263
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;
276
277 case EXT_FILENAMEEXT:
278 {
279 BOOL fFileNameExtPath = WinQueryButtonCheckstate(hwnd, EXT_FILENAMEEXT);
280 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
281 size = sizeof(BOOL);
282 PrfWriteProfileData(fmprof, FM3Str, "FileNamePathExt",
283 fRemember ? FALSE : (PVOID) &fFileNameExtPath, size);
284 if (fRemember) {
285 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
286 MPFROM2SHORT(FALSE, 0), MPVOID);
287 break;
288 }
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) {
325 if (arcdata->arcname && *arcdata->arcname) {
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
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;
351
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;
359
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;
366
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;
373
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;
379
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);
385 }
386 break;
387 }
388 return 0;
389
390 case WM_COMMAND:
391 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
392 switch (SHORT1FROMMP(mp1)) {
393 case IDM_SWITCH:
394 if (mp2) {
395
396 CHAR tdir[CCHMAXPATH];
397
398 strcpy(tdir, (CHAR *) mp2);
399 MakeValidDir(tdir);
400 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
401 }
402 break;
403
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;
412
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),
419 QW_OWNER), hwnd, s, fFileNameExtPath ? 1:0)) {
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);
432 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
433 size = sizeof(BOOL);
434 PrfWriteProfileData(fmprof, FM3Str, "Ext_WDirs",
435 (PVOID) &fRemember, size);
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;
456
457 case IDM_HELP:
458 if (hwndHelp)
459 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
460 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
461 break;
462
463 case EXT_WALK:
464 {
465 CHAR temp[CCHMAXPATH + 1];
466
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;
480
481 case EXT_SEE:
482 {
483 CHAR s[1001], *p;
484 EXECARGS ex;
485
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,
504 hwnd, pszSrcFile, __LINE__,
505 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
506 }
507 }
508 }
509 break;
510 }
511 return 0;
512
513 case WM_CLOSE:
514 break;
515 }
516 return WinDefDlgProc(hwnd, msg, mp1, mp2);
517}
518
519#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.