source: trunk/dll/extract.c@ 1306

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

Added option to use subdirectory based on the archive name for extraction from the arc container; it is set in the notebook and separate from the extract dialog setting; includes help file update, comments and cleanup (Ticket 22)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: extract.c 1306 2008-11-30 19:23:56Z gyoung $
5
6 Copyright (c) 1993-98 M. Kimes
7 Copyright (c) 2004, 2007 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 = sizeof(BOOL);
103 BOOL fFileNameExtPath;
104
105 switch (msg) {
106 case WM_INITDLG:
107 WinSetWindowPtr(hwnd, QWL_USER, mp2);
108 arcdata = (EXTRDATA *) mp2;
109 {
110 ULONG sizet;
111 BOOL fRemember = FALSE;
112 BOOL fDirectory = FALSE;
113 PFNWP oldproc;
114
115 fFileNameExtPath = FALSE;
116 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
117 (PFNWP) ExtractTextProc);
118 if (oldproc)
119 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
120 QWL_USER, (PVOID) oldproc);
121 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
122 (PVOID) & fRemember, &size);
123 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
124 (PVOID) & fDirectory, &size);
125 PrfQueryProfileData(fmprof, FM3Str, "FileNamePathExt",
126 (PVOID) & fFileNameExtPath, &size);
127 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
128 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
129 WinCheckButton(hwnd, EXT_FILENAMEEXT, fFileNameExtPath);
130 WinSendDlgItemMsg(hwnd, EXT_DIRECTORY, EM_SETTEXTLIMIT,
131 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
132 WinSendDlgItemMsg(hwnd, EXT_COMMAND, EM_SETTEXTLIMIT,
133 MPFROM2SHORT(256, 0), MPVOID);
134 WinSendDlgItemMsg(hwnd, EXT_MASK, EM_SETTEXTLIMIT,
135 MPFROM2SHORT(256, 0), MPVOID);
136 WinSendDlgItemMsg(hwnd, EXT_FILENAME, EM_SETTEXTLIMIT,
137 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
138 if (arcdata->arcname && *arcdata->arcname)
139 WinSetDlgItemText(hwnd, EXT_FILENAME, arcdata->arcname);
140 else
141 WinSetDlgItemText(hwnd, EXT_FILENAME, GetPString(IDS_EXTVARIOUSTEXT));
142
143 if (fFileNameExtPath && arcdata->arcname) {
144
145 CHAR FileName[CCHMAXPATH];
146 PSZ p;
147
148 strcpy(FileName, arcdata->arcname);
149 p = strrchr(FileName, '.');
150 if (p)
151 *p = 0;
152 else {
153 p = FileName + strlen(arcdata->arcname);
154 p--;
155 *p = 0;
156 }
157 strcpy(arcdata->extractdir, FileName);
158 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
159 }
160 if (fDirectory) {
161 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
162 MPFROM2SHORT(TRUE, 0), MPVOID);
163 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
164 }
165 else {
166 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
167 MPFROM2SHORT(TRUE, 0), MPVOID);
168 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
169
170 }
171 if (fRemember) {
172
173 CHAR textdir[CCHMAXPATH];
174
175 sizet = sizeof(textdir);
176 *textdir = 0;
177 PrfQueryProfileData(fmprof, FM3Str, "Ext_ExtractDir",
178 (PVOID) textdir, &size);
179 if (*textdir && !IsFile(textdir))
180 strcpy(arcdata->extractdir, textdir);
181 sizet = sizeof(textdir);
182 *textdir = 0;
183 PrfQueryProfileData(fmprof, FM3Str, "Ext_Mask", (PVOID) textdir,
184 &size);
185 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
186 }
187 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
188 if (arcdata->arcname && *arcdata->arcname &&
189 !strcmp(extractpath, "*")) {
190
191 CHAR *p;
192
193 strcpy(arcdata->extractdir, arcdata->arcname);
194 p = strrchr(arcdata->extractdir, '\\');
195 if (p) {
196 if (p < arcdata->extractdir + 3)
197 p++;
198 *p = 0;
199 }
200 }
201 else
202 strcpy(arcdata->extractdir, extractpath);
203 }
204 if (!*arcdata->extractdir) {
205 if (*lastextractpath)
206 strcpy(arcdata->extractdir, lastextractpath);
207 else if (arcdata->arcname && *arcdata->arcname) {
208
209 CHAR *p;
210
211 strcpy(arcdata->extractdir, arcdata->arcname);
212 p = strrchr(arcdata->extractdir, '\\');
213 if (p) {
214 if (p < arcdata->extractdir + 3)
215 p++;
216 *p = 0;
217 }
218 }
219 if (!*arcdata->extractdir)
220 strcpy(arcdata->extractdir, pFM2SaveDirectory);
221 }
222 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
223 if (!arcdata->info->exwdirs)
224 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
225 else if (fRemember) {
226 //size = sizeof(BOOL);
227 fRemember = FALSE;
228 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
229 (PVOID) &fRemember, &size);
230 if (fRemember)
231 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
232 }
233 }
234 *arcdata->command = 0;
235 PosOverOkay(hwnd);
236 break;
237
238 case WM_ADJUSTWINDOWPOS:
239 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
240 break;
241
242 case UM_SETDIR:
243 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
244 TRUE);
245 return 0;
246
247 case WM_CONTROL:
248 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
249 switch (SHORT1FROMMP(mp1)) {
250 case EXT_REMEMBER:
251 {
252 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
253
254 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
255 (PVOID) &fRemember, size);
256 }
257 break;
258
259 case EXT_AWDIRS:
260 {
261 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
262
263 PrfWriteProfileData(fmprof, 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
283 PrfWriteProfileData(fmprof, FM3Str, "FileNamePathExt",
284 (PVOID) &fFileNameExtPath, size);
285 if (fFileNameExtPath && arcdata->arcname) {
286 CHAR FileName[CCHMAXPATH];
287 PSZ p;
288
289 strcpy(FileName, arcdata->arcname);
290 p = strrchr(FileName, '.');
291 if (p)
292 *p = 0;
293 else {
294 p = FileName + strlen(arcdata->arcname);
295 p--;
296 *p = 0;
297 }
298 strcpy(arcdata->extractdir, FileName);
299 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
300 }
301 else {
302 *arcdata->extractdir = 0;
303 if (*extractpath) {
304 if (arcdata->arcname && *arcdata->arcname &&
305 !strcmp(extractpath, "*")) {
306
307 CHAR *p;
308
309 strcpy(arcdata->extractdir, arcdata->arcname);
310 p = strrchr(arcdata->extractdir, '\\');
311 if (p) {
312 if (p < arcdata->extractdir + 3)
313 p++;
314 *p = 0;
315 }
316 }
317 else
318 strcpy(arcdata->extractdir, extractpath);
319 }
320 if (!*arcdata->extractdir) {
321 if (arcdata->arcname && *arcdata->arcname) {
322
323 CHAR *p;
324
325 strcpy(arcdata->extractdir, arcdata->arcname);
326 p = strrchr(arcdata->extractdir, '\\');
327 if (p) {
328 if (p < arcdata->extractdir + 3)
329 p++;
330 *p = 0;
331 }
332 }
333 if (!*arcdata->extractdir)
334 strcpy(arcdata->extractdir, pFM2SaveDirectory);
335 }
336 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
337 }
338 }
339 break;
340
341 case EXT_FILENAME:
342 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
343 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
344 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
345 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCARCNAMEHELPTEXT));
346 break;
347
348 case EXT_DIRECTORY:
349 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
350 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
351 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
352 WinSetDlgItemText(hwnd, EXT_HELP,
353 GetPString(IDS_EXTEXTRACTDIRHELPTEXT));
354 break;
355
356 case EXT_COMMAND:
357 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
358 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
359 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
360 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCCMDHELPTEXT));
361 break;
362
363 case EXT_MASK:
364 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
365 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
366 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
367 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCMASKHELPTEXT));
368 break;
369
370 case EXT_NORMAL:
371 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_QUERYCHECK,
372 MPVOID, MPVOID))
373 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
374 break;
375
376 case EXT_WDIRS:
377 if (arcdata->info->exwdirs) {
378 if ((BOOL) WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_QUERYCHECK,
379 MPVOID, MPVOID))
380 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
381 }
382 break;
383 }
384 return 0;
385
386 case WM_COMMAND:
387 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
388 switch (SHORT1FROMMP(mp1)) {
389 case IDM_SWITCH:
390 if (mp2) {
391
392 CHAR tdir[CCHMAXPATH];
393
394 strcpy(tdir, (CHAR *) mp2);
395 MakeValidDir(tdir);
396 WinSetDlgItemText(hwnd, EXT_DIRECTORY, tdir);
397 }
398 break;
399
400 case DID_CANCEL:
401 arcdata->ret = 0;
402 WinDismissDlg(hwnd, 0);
403 break;
404 case DID_OK:
405 {
406 CHAR s[CCHMAXPATH + 1];
407 BOOL fRemember;
408
409 fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
410 *s = 0;
411 WinQueryDlgItemText(hwnd, EXT_DIRECTORY, CCHMAXPATH, s);
412 bstrip(s);
413 if (*s) {
414 if (!SetDir(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
415 QW_OWNER), hwnd, s, fFileNameExtPath ? 1:0)) {
416 strcpy(arcdata->extractdir, s);
417 WinSetDlgItemText(hwnd, EXT_DIRECTORY, s);
418 if ((!isalpha(*s) || s[1] != ':') && *s != '.')
419 saymsg(MB_ENTER, hwnd,
420 GetPString(IDS_WARNINGTEXT),
421 GetPString(IDS_SPECIFYDRIVETEXT));
422 }
423 else
424 break;
425 strcpy(lastextractpath, s);
426 if (fRemember) {
427 PrfWriteProfileString(fmprof, FM3Str, "Ext_ExtractDir", s);
428 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
429 PrfWriteProfileData(fmprof, FM3Str, "Ext_WDirs",
430 (PVOID) &fRemember, size);
431 fRemember = TRUE;
432 }
433 *s = 0;
434 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
435 if (*s) {
436 strcpy(arcdata->command, s);
437 *s = 0;
438 WinQueryDlgItemText(hwnd, EXT_MASK, 256, s);
439 *arcdata->masks = 0;
440 strcpy(arcdata->masks, s);
441 if (fRemember)
442 PrfWriteProfileString(fmprof, FM3Str, "Ext_Mask", s);
443 arcdata->ret = 1;
444 WinDismissDlg(hwnd, 1);
445 break;
446 }
447 }
448 }
449 DosBeep(50, 100); // Complain a refuse to quit
450 break;
451
452 case IDM_HELP:
453 if (hwndHelp)
454 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
455 MPFROM2SHORT(HELP_EXTRACT, 0), MPFROMSHORT(HM_RESOURCEID));
456 break;
457
458 case EXT_WALK:
459 {
460 CHAR temp[CCHMAXPATH + 1];
461
462 strcpy(temp, arcdata->extractdir);
463 if (WinDlgBox(HWND_DESKTOP, WinQueryWindow(WinQueryWindow(hwnd,
464 QW_PARENT),
465 QW_OWNER),
466 WalkExtractDlgProc, FM3ModHandle, WALK_FRAME,
467 (PVOID) temp)) {
468 if (*temp && stricmp(temp, arcdata->extractdir)) {
469 strcpy(arcdata->extractdir, temp);
470 }
471 }
472 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
473 }
474 break;
475
476 case EXT_SEE:
477 {
478 CHAR s[1001], *p;
479 EXECARGS ex;
480
481 WinQueryDlgItemText(hwnd, EXT_COMMAND, 256, s);
482 lstrip(s);
483 if (!*s)
484 Runtime_Error(pszSrcFile, __LINE__, "no command");
485 else {
486 p = strchr(s, ' ');
487 if (p)
488 *p = 0; // Drop options
489 memset(&ex, 0, sizeof(EXECARGS));
490 ex.commandline = s;
491 ex.flags = WINDOWED | SEPARATEKEEP | MAXIMIZED;
492 *ex.path = 0;
493 *ex.environment = 0;
494 if (WinDlgBox(HWND_DESKTOP,
495 hwnd,
496 CmdLineDlgProc,
497 FM3ModHandle, EXEC_FRAME, MPFROMP(&ex)) && *s) {
498 runemf2(ex.flags,
499 hwnd, pszSrcFile, __LINE__,
500 NULL, (*ex.environment) ? ex.environment : NULL, "%s", s);
501 }
502 }
503 }
504 break;
505 }
506 return 0;
507
508 case WM_CLOSE:
509 break;
510 }
511 return WinDefDlgProc(hwnd, msg, mp1, mp2);
512}
513
514#pragma alloc_text(FMEXTRACT,ExtractTextProc,ExtractDlgProc)
Note: See TracBrowser for help on using the repository browser.