source: trunk/dll/extract.c@ 1395

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

Allow user to turn off alert and/or error beeps in settings notebook. Ticket 341 Move repeated strings to PCSZs. Ticket 6 Add *DateFormat functions to format dates based on locale Ticket 28 Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error Ticket 6

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.0 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: extract.c 1395 2009-02-08 01:48:16Z 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.
[1395]19 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
[123]20
21***********************************************************************/
22
[907]23#include <string.h>
24#include <ctype.h>
25
[2]26#define INCL_WIN
27#define INCL_DOS
[907]28#define INCL_LONGLONG // dircnrs.h
[2]29
[1179]30#include "fm3dll.h"
[1223]31#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1207]32#include "init.h" // Data declaration(s)
33#include "arccnrs.h" // Data declaration(s)
34#include "notebook.h" // Data declaration(s)
35#include "mainwnd.h" // Data declaration(s)
[2]36#include "fm3dlg.h"
37#include "fm3str.h"
[907]38#include "errutil.h" // Dos_Error...
39#include "strutil.h" // GetPString
[1157]40#include "cmdline.h" // CmdLineDlgProc
41#include "extract.h"
42#include "walkem.h" // WalkExtractDlgProc
[1179]43#include "droplist.h" // AcceptOneDrop, DropHelp, GetOneDrop
44#include "misc.h" // DrawTargetEmphasis
45#include "chklist.h" // PosOverOkay
46#include "mkdir.h" // SetDir
47#include "valid.h" // MakeValidDir
48#include "systemf.h" // runemf2
49#include "dirs.h" // save_dir2
50#include "strips.h" // bstrip
[2]51
52#pragma data_seg(DATA1)
[350]53
54static PSZ pszSrcFile = __FILE__;
[2]55
[551]56MRESULT EXPENTRY ExtractTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[350]57{
[574]58 PFNWP oldproc = (PFNWP) WinQueryWindowPtr(hwnd, QWL_USER);
[551]59 static BOOL emphasized = FALSE;
[2]60
[551]61 switch (msg) {
62 case DM_DRAGOVER:
63 if (!emphasized) {
64 emphasized = TRUE;
65 DrawTargetEmphasis(hwnd, emphasized);
66 }
[618]67 if (AcceptOneDrop(hwnd, mp1, mp2))
[551]68 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
69 return MRFROM2SHORT(DOR_NEVERDROP, 0);
[2]70
[551]71 case DM_DRAGLEAVE:
72 if (emphasized) {
73 emphasized = FALSE;
74 DrawTargetEmphasis(hwnd, emphasized);
75 }
76 break;
[2]77
[551]78 case DM_DROPHELP:
79 DropHelp(mp1, mp2, hwnd, GetPString(IDS_EXTDROPHELPTEXT));
80 return 0;
[2]81
[551]82 case DM_DROP:
83 {
84 char szFrom[CCHMAXPATH + 2];
[2]85
[551]86 if (emphasized) {
87 emphasized = FALSE;
88 DrawTargetEmphasis(hwnd, emphasized);
[2]89 }
[618]90 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
[551]91 WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_COMMAND,
92 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
93 }
94 return 0;
[2]95 }
[551]96 return (oldproc) ? oldproc(hwnd, msg, mp1, mp2) :
97 WinDefWindowProc(hwnd, msg, mp1, mp2);
[2]98}
99
[551]100MRESULT EXPENTRY ExtractDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[350]101{
[551]102 EXTRDATA *arcdata = NULL;
[1344]103 ULONG size;
[1300]104 BOOL fFileNameExtPath;
[2]105
[551]106 switch (msg) {
107 case WM_INITDLG:
[574]108 WinSetWindowPtr(hwnd, QWL_USER, mp2);
[551]109 arcdata = (EXTRDATA *) mp2;
110 {
[1344]111 BOOL fDirectory = FALSE;
[551]112 BOOL fRemember = FALSE;
113 PFNWP oldproc;
[2]114
[1300]115 fFileNameExtPath = FALSE;
[551]116 oldproc = WinSubclassWindow(WinWindowFromID(hwnd, EXT_DIRECTORY),
117 (PFNWP) ExtractTextProc);
118 if (oldproc)
119 WinSetWindowPtr(WinWindowFromID(hwnd, EXT_DIRECTORY),
[1344]120 QWL_USER, (PVOID) oldproc);
121 size = sizeof(BOOL);
[551]122 PrfQueryProfileData(fmprof, FM3Str, "RememberExt",
[1344]123 (PVOID) & fRemember, &size);
124 size = sizeof(BOOL);
[551]125 PrfQueryProfileData(fmprof, FM3Str, "DirectoryExt",
[1300]126 (PVOID) & fDirectory, &size);
[1344]127 size = sizeof(BOOL);
[1300]128 PrfQueryProfileData(fmprof, FM3Str, "FileNamePathExt",
129 (PVOID) & fFileNameExtPath, &size);
[551]130 WinCheckButton(hwnd, EXT_REMEMBER, fRemember);
131 WinCheckButton(hwnd, EXT_AWDIRS, fDirectory);
[1300]132 WinCheckButton(hwnd, EXT_FILENAMEEXT, fFileNameExtPath);
[551]133 WinSendDlgItemMsg(hwnd, EXT_DIRECTORY, EM_SETTEXTLIMIT,
134 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
135 WinSendDlgItemMsg(hwnd, EXT_COMMAND, EM_SETTEXTLIMIT,
136 MPFROM2SHORT(256, 0), MPVOID);
137 WinSendDlgItemMsg(hwnd, EXT_MASK, EM_SETTEXTLIMIT,
138 MPFROM2SHORT(256, 0), MPVOID);
139 WinSendDlgItemMsg(hwnd, EXT_FILENAME, EM_SETTEXTLIMIT,
140 MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
141 if (arcdata->arcname && *arcdata->arcname)
142 WinSetDlgItemText(hwnd, EXT_FILENAME, arcdata->arcname);
143 else
[1300]144 WinSetDlgItemText(hwnd, EXT_FILENAME, GetPString(IDS_EXTVARIOUSTEXT));
145
146 if (fFileNameExtPath && arcdata->arcname) {
147
148 CHAR FileName[CCHMAXPATH];
149 PSZ p;
150
151 strcpy(FileName, arcdata->arcname);
152 p = strrchr(FileName, '.');
153 if (p)
154 *p = 0;
155 else {
156 p = FileName + strlen(arcdata->arcname);
157 p--;
158 *p = 0;
159 }
160 strcpy(arcdata->extractdir, FileName);
161 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
162 }
[551]163 if (fDirectory) {
164 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
165 MPFROM2SHORT(TRUE, 0), MPVOID);
166 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
167 }
168 else {
169 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
170 MPFROM2SHORT(TRUE, 0), MPVOID);
171 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
[549]172
[551]173 }
174 if (fRemember) {
[2]175
[1344]176 CHAR textdir[CCHMAXPATH];
[2]177
[1344]178 PrfQueryProfileString(fmprof, FM3Str, "Ext_ExtractDir", NULL, textdir, sizeof(textdir));
[551]179 if (*textdir && !IsFile(textdir))
180 strcpy(arcdata->extractdir, textdir);
[1344]181 PrfQueryProfileString(fmprof, FM3Str, "Ext_Mask", NULL, textdir, sizeof(textdir));
[551]182 WinSetDlgItemText(hwnd, EXT_MASK, textdir);
183 }
184 if (*extractpath && (!fRemember || !*arcdata->extractdir)) {
185 if (arcdata->arcname && *arcdata->arcname &&
186 !strcmp(extractpath, "*")) {
[2]187
[551]188 CHAR *p;
[2]189
[551]190 strcpy(arcdata->extractdir, arcdata->arcname);
191 p = strrchr(arcdata->extractdir, '\\');
192 if (p) {
193 if (p < arcdata->extractdir + 3)
194 p++;
195 *p = 0;
196 }
197 }
198 else
199 strcpy(arcdata->extractdir, extractpath);
200 }
201 if (!*arcdata->extractdir) {
202 if (*lastextractpath)
203 strcpy(arcdata->extractdir, lastextractpath);
204 else if (arcdata->arcname && *arcdata->arcname) {
[2]205
[551]206 CHAR *p;
[2]207
[551]208 strcpy(arcdata->extractdir, arcdata->arcname);
209 p = strrchr(arcdata->extractdir, '\\');
210 if (p) {
211 if (p < arcdata->extractdir + 3)
212 p++;
213 *p = 0;
214 }
215 }
216 if (!*arcdata->extractdir)
[1104]217 strcpy(arcdata->extractdir, pFM2SaveDirectory);
[2]218 }
[551]219 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
220 if (!arcdata->info->exwdirs)
221 WinEnableWindow(WinWindowFromID(hwnd, EXT_WDIRS), FALSE);
222 else if (fRemember) {
[1344]223 fRemember = FALSE;
224 size = sizeof(BOOL);
[551]225 PrfQueryProfileData(fmprof, FM3Str, "Ext_WDirs",
[1300]226 (PVOID) &fRemember, &size);
[551]227 if (fRemember)
228 PostMsg(WinWindowFromID(hwnd, EXT_WDIRS), BM_CLICK, MPVOID, MPVOID);
229 }
230 }
231 *arcdata->command = 0;
232 PosOverOkay(hwnd);
233 break;
[2]234
[551]235 case WM_ADJUSTWINDOWPOS:
236 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
237 break;
[2]238
[551]239 case UM_SETDIR:
240 PaintRecessedWindow(WinWindowFromID(hwnd, EXT_HELP), (HPS) 0, FALSE,
241 TRUE);
242 return 0;
[2]243
[551]244 case WM_CONTROL:
[574]245 arcdata = (EXTRDATA *) WinQueryWindowPtr(hwnd, QWL_USER);
[551]246 switch (SHORT1FROMMP(mp1)) {
247 case EXT_REMEMBER:
248 {
249 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
[1344]250 size = sizeof(BOOL);
[551]251 PrfWriteProfileData(fmprof, FM3Str, "RememberExt",
[1344]252 (PVOID) &fRemember, size);
253 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
254 MPFROM2SHORT(FALSE, 0), MPVOID);
[551]255 }
256 break;
[2]257
[551]258 case EXT_AWDIRS:
259 {
260 BOOL fDirectory = WinQueryButtonCheckstate(hwnd, EXT_AWDIRS);
[1344]261 size = sizeof(BOOL);
[551]262 PrfWriteProfileData(fmprof, FM3Str, "DirectoryExt",
[1300]263 (PVOID) &fDirectory, size);
[549]264
[551]265 if (fDirectory) {
266 WinSendDlgItemMsg(hwnd, EXT_WDIRS, BM_SETCHECK,
267 MPFROM2SHORT(TRUE, 0), MPVOID);
268 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->exwdirs);
269 }
270 else {
271 WinSendDlgItemMsg(hwnd, EXT_NORMAL, BM_SETCHECK,
272 MPFROM2SHORT(TRUE, 0), MPVOID);
273 WinSetDlgItemText(hwnd, EXT_COMMAND, arcdata->info->extract);
274 }
275 }
276 break;
[549]277
[1300]278 case EXT_FILENAMEEXT:
279 {
[1344]280 BOOL fFileNameExtPath = WinQueryButtonCheckstate(hwnd, EXT_FILENAMEEXT);
281 BOOL fRemember = WinQueryButtonCheckstate(hwnd, EXT_REMEMBER);
282 size = sizeof(BOOL);
[1300]283 PrfWriteProfileData(fmprof, FM3Str, "FileNamePathExt",
[1344]284 fRemember ? FALSE : (PVOID) &fFileNameExtPath, size);
[1349]285 if (fRemember) {
286 WinSendDlgItemMsg(hwnd, EXT_FILENAMEEXT, BM_SETCHECK,
287 MPFROM2SHORT(FALSE, 0), MPVOID);
[1344]288 break;
[1349]289 }
[1300]290 if (fFileNameExtPath && arcdata->arcname) {
291 CHAR FileName[CCHMAXPATH];
292 PSZ p;
293
294 strcpy(FileName, arcdata->arcname);
295 p = strrchr(FileName, '.');
296 if (p)
297 *p = 0;
298 else {
299 p = FileName + strlen(arcdata->arcname);
300 p--;
301 *p = 0;
302 }
303 strcpy(arcdata->extractdir, FileName);
304 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
305 }
306 else {
307 *arcdata->extractdir = 0;
308 if (*extractpath) {
309 if (arcdata->arcname && *arcdata->arcname &&
310 !strcmp(extractpath, "*")) {
311
312 CHAR *p;
313
314 strcpy(arcdata->extractdir, arcdata->arcname);
315 p = strrchr(arcdata->extractdir, '\\');
316 if (p) {
317 if (p < arcdata->extractdir + 3)
318 p++;
319 *p = 0;
320 }
321 }
322 else
323 strcpy(arcdata->extractdir, extractpath);
324 }
325 if (!*arcdata->extractdir) {
[1306]326 if (arcdata->arcname && *arcdata->arcname) {
[1300]327
328 CHAR *p;
329
330 strcpy(arcdata->extractdir, arcdata->arcname);
331 p = strrchr(arcdata->extractdir, '\\');
332 if (p) {
333 if (p < arcdata->extractdir + 3)
334 p++;
335 *p = 0;
336 }
337 }
338 if (!*arcdata->extractdir)
339 strcpy(arcdata->extractdir, pFM2SaveDirectory);
340 }
341 WinSetDlgItemText(hwnd, EXT_DIRECTORY, arcdata->extractdir);
342 }
343 }
344 break;
345
[551]346 case EXT_FILENAME:
347 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
348 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
349 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
350 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCARCNAMEHELPTEXT));
351 break;
[2]352
[551]353 case EXT_DIRECTORY:
354 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
355 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
356 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
357 WinSetDlgItemText(hwnd, EXT_HELP,
358 GetPString(IDS_EXTEXTRACTDIRHELPTEXT));
359 break;
[2]360
[551]361 case EXT_COMMAND:
362 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
363 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
364 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
365 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCCMDHELPTEXT));
366 break;
[2]367
[551]368 case EXT_MASK:
369 if (SHORT2FROMMP(mp1) == EN_KILLFOCUS)
370 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCDEFAULTHELPTEXT));
371 if (SHORT2FROMMP(mp1) == EN_SETFOCUS)
372 WinSetDlgItemText(hwnd, EXT_HELP, GetPString(IDS_ARCMASKHELPTEXT));
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) {
432 PrfWriteProfileString(fmprof, FM3Str, "Ext_ExtractDir", s);
[1344]433 fRemember = WinQueryButtonCheckstate(hwnd, EXT_WDIRS);
434 size = sizeof(BOOL);
[551]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)
448 PrfWriteProfileString(fmprof, FM3Str, "Ext_Mask", s);
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.