source: trunk/dll/arccnrs.c@ 1851

Last change on this file since 1851 was 1851, checked in by Gregg Young, 10 years ago

Improved pci checks

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 109.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: arccnrs.c 1851 2015-08-14 21:29:17Z gyoung $
5
6 Archive containers
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2001, 2013 Steven H. Levine
10
11 11 Jun 02 SHL Ensure archive name not garbage
12 22 May 03 SHL ArcObjWndProc: fix UM_RESCAN now that we understand it
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 23 May 05 SHL Use QWL_USER
15 25 May 05 SHL Rename comnam to szCommonName and fix typo
16 25 May 05 SHL Use ULONGLONG and CommaFmtULL
17 05 Jun 05 SHL Drop obsolete, localize
18 05 Jun 05 SHL Correct last sort logic
19 05 Jun 05 SHL Use QWL_USER
20 22 Jun 05 SHL ArcSort: correct typo in last sort fix
21 13 Aug 05 SHL FillArcCnr: optimize
22 08 Dec 05 SHL FillArcCnr: allow list start and end markers to be empty (i.e. tar)
23 08 Dec 05 SHL ArcCnrWndProc: suppress IDM_EXTRACT if no simple extract (i.e. tar)
24 30 Dec 05 SHL ArcCnrWndProc: correct date/time column display setup
25 29 May 06 SHL Comments
26 14 Jul 06 SHL Use Runtime_Error
27 26 Jul 06 SHL Correct SelectAll usage
28 29 Jul 06 SHL Use xfgets_bstripcr
29 31 Jul 06 SHL Lower priority for archives with more than 1000 entries
30 02 Aug 06 SHL Add logic to stop processing large archives
31 23 Aug 06 SHL Integrate John Small's switch list title logic
32 03 Nov 06 SHL Renames
33 14 Mar 07 SHL ArcObjWndProc/UM_ENTER: delay before starting viewer
34 30 Mar 07 GKY Remove GetPString for window class names
35 06 Apr 07 GKY Work around PM DragInfo and DrgFreeISH limit
36 06 Apr 07 GKY Add some error checking in drag/drop
37 20 Apr 07 SHL Sync with NumItemsToUnhilite mods
38 21 Apr 07 GKY Find FM2Utils by path or utils directory
39 12 May 07 SHL Use dcd->ulItemsToUnHilite; sync with UnHilite arg mods
40 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
41 16 Jun 07 SHL Use DosQueryAppType not DosQAppType
42 02 Aug 07 SHL Sync with ARCITEM mods
43 06 Aug 07 SHL Use BldFullPathName and BldQuotedFileName
44 06 Aug 07 SHL Move BldQuotedFileName and BldQuotedFullPathNamehere
45 to be near primary caller
46 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
47 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
48 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
49 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
50 30 Dec 07 GKY Use TestCDates for sort by date
51 10 Jan 08 SHL Sync with CfgDlgProc mods
52 10 Feb 08 GKY Implement bubble help for bitmap menu items
53 15 Feb 08 SHL Sync with settings menu rework
54 29 Feb 08 GKY Use xfree where appropriate
55 14 Jul 08 JBS Ticket 126: Add support for WPS open default & open settings in arccnrs
56 16 Jul 08 GKY Fix trap on viewing multiple files from an archive (misplaced free)
57 16 Jul 08 GKY Use TMP directory for temp files if present. Use MakeTempName
58 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
59 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
60 less than 10 KiB (It hangs and can't be closed)
61 08 Nov 08 GKY Add WaitChildThread to fix hang caused by viewer trying to open a file before
62 the archiver process closes. (Ticket 58)
63 23 Nov 08 JBS Ticket 284: Support archivers with no Start or End of list strings
64 29 Nov 08 GKY Add flag to tell CheckListProc file is in an archive so it won't try to open it.
65 29 Nov 08 GKY Remove or replace with a mutex semaphore DosEnterCriSec where appropriate.
66 30 Nov 08 GKY Add the option of creating a subdirectory from the arcname
67 for the extract path to arc container.
68 02 Dec 08 JBS Ticket 284: Changed string indicating no Start/End of list strings.
69 03 Dec 08 GKY Subdirectory from the arcname for the extract path only created if an "extract"
70 menu option is selected.
71 10 Dec 08 SHL Integrate exception handler support
72 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
73 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
74 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
75 08 Mar 09 GKY Additional strings move to PCSZs in init.c
76 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
77 12 Mar 09 SHL Use common SearchContainer
78 13 Dec 09 GKY Fixed separate paramenters. Please note that appname should be used in
79 profile calls for user settings that work and are setable in more than one
80 miniapp; FM3Str should be used for setting only relavent to FM/2 or that
81 aren't user settable; realappname should be used for setting applicable to
82 one or more miniapp but not to FM/2
83 17 Jan 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
84 15 Apr 10 JBS Ticket 422: Stop hang when open archive gets deleted or moved
85 23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
86 20 Nov 10 GKY Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused
87 by temp file creation failures.
88 13 Aug 11 GKY Change to Doxygen comment format
89 30 Jul 13 GKY Changes to allow 7z archiver to work with AV.
90 05 Aug 13 GKY Changes to allow Lzip to work with AV
91 11 Aug 13 GKY Removed code that attempted to use the archive name as the extract directory
92 It was never fully implemented and doesn't make sense for the container.
93 09 Feb 14 GKY Fix trap on opening a file without an extention
94 22 Feb 14 GKY Fix warn readonly yes don't ask to work when recursing directories.
95 28 Apr 14 JBS Ticket #522: Ensure use of wrapper functions where needed
96 01 Mar 14 GKY Fixed error checking in FillArcCnr only to report missing archivers after
97 all entries have been tried. Added a check b/gzip exes for TAR.B/GZ archives.
98 Use the test archive string from the first working archive description.
99 Enhance the error message. Ticket 502
100 01 Mar 14 GKY Fix a trap caused by selecting "print" from the arccontainer menu. Ticket 525
101 01 Mar 14 GKY Fix the problem with copying text from the test archive window by launching
102 it in a command shell (i.e. comspec /k archiver -t archive) Ticket 503
103 02 Mar 14 GKY Fixed typo that reversed the function of the saymsg dialog g/bzip check.
104 Added option to suppress message regarding missing bzip2.exe
105 or gzip.exe on TAR.B/GZ archives.
106 06 Apr 14 GKY Removed all BZ/GZ checks
107 28 Jun 14 GKY Fix errors identified with CPPCheck; Fix retry to create workdir code
108 12 Aug 15 JBS Ticket #522: Ensure no "highmem-unsafe" functions are called directly.
109 Calls to unsafe Dos... functions have been changed to call the wrapped xDos... functions.
110
111***********************************************************************/
112
113#include <stdlib.h> // free..
114#include <string.h>
115#include <ctype.h>
116#include <direct.h> // rmdir
117#include <share.h> // SH_DENYWR
118#include <limits.h> // ULONG_MAX
119
120#if 0
121#include <malloc.h> // _heapchk
122#endif
123
124#define INCL_DOS
125#define INCL_DOSERRORS
126#define INCL_WIN
127#define INCL_LONGLONG
128
129#include "fm3dll.h"
130#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
131#include "arccnrs.h"
132#include "makelist.h" // Typedef
133#include "colors.h" // Typedef
134#include "mainwnd2.h" // Data declaration(s)
135#include "grep.h" // Data declaration(s)
136#include "dircnrs.h" // Data declaration(s)
137#include "info.h" // Data declaration(s)
138#include "init.h" // Data declaration(s)
139#include "fm3dlg.h"
140#include "fm3str.h"
141#include "mle.h"
142#include "pathutil.h" // BldFullPathName
143#include "filldir.h" // EmptyCnr...
144#include "errutil.h" // Dos_Error...
145#include "strutil.h" // GetPString
146#include "notebook.h" // CfgDlgProc
147#include "worker.h" // Action, MassAction
148#include "avv.h" // ArcReviewDlgProc, rewrite_archiverbb2
149#include "chklist.h" // CenterOverWindow, CheckListProc
150#include "common.h" // CommonCreateTextChildren, CommonFrameWndProc, CommonTextPaint
151 // CommonTextButton
152#include "draglist.h" // DoFileDrag, DragOne
153#include "valid.h" // GetDesktopName, TestCDates
154#include "mainwnd.h" // GetNextWindowPos, MakeBubble, TopWindowName
155#include "objwin.h" // MakeObjWin
156#include "shadow.h" // MakeShadows
157#include "objcnr.h" // ObjCnrDlgProc
158#include "printer.h" // PrintListThread
159#include "srchpath.h" // RunFM2Util
160#include "misc.h" // Broadcast, CheckMenu, CurrentRecord, SayFilter, SaySort
161 // DrawTargetEmphasis, IsFm2Window
162#include "select.h" // SelectAll, SelectList
163#include "findrec.h" // ShowCnrRecord
164#include "walkem.h" // WalkExtractDlgProc
165#include "droplist.h" // AcceptOneDrop, CheckPmDrgLimit, DropHelp, GetOneDrop
166#include "archive.h" // ArchiveDlgProc
167#include "common.h" // CommonTextProc
168#include "presparm.h" // CopyPresParams
169#include "defview.h" // DefaultViewKeys
170#include "systemf.h" // ExecOnList
171#include "filter.h" // PickMaskDlgProc
172#include "avl.h" // SBoxDlgProc
173#include "mkdir.h" // SetDir
174#include "collect.h" // StartCollector
175#include "viewer.h" // StartMLEEditor
176#include "newview.h" // StartViewer
177#include "i18nutil.h" // commafmt
178#include "copyf.h" // unlinkf
179#include "literal.h" // wildcard
180#include "wrappers.h" // xrealloc
181#include "misc.h" // AdjustCnrColVis, QuickPopup, SetSortChecks, SwitchCommand
182#include "select.h" // DeselectAll, InvertAll
183#include "strips.h" // bstrip
184#include "dirs.h" // save_dir2
185#include "fortify.h"
186#include "excputil.h" // 06 May 08 SHL added
187
188#define ARCFLAGS_REALDIR 0x00000001
189#define ARCFLAGS_PSEUDODIR 0x00000002
190#define CON_COLS 6
191#define EXTRA_ARCRECORD_BYTES (sizeof(ARCITEM) - sizeof(MINIRECORDCORE))
192#define NO_START_OF_ARCHIVER_LIST_STRING "None"
193#define NO_END_OF_ARCHIVER_LIST_STRING NO_START_OF_ARCHIVER_LIST_STRING
194
195#pragma data_seg(DATA1)
196static INT DefArcSortFlags;
197
198// Data definitions
199static PSZ pszSrcFile = __FILE__;
200#pragma data_seg(GLOBAL1)
201HWND ArcCnrMenu;
202HWND ArcMenu;
203CHAR ArcTempRoot[CCHMAXPATH];
204BOOL fArcStuffVisible;
205BOOL fFileNameCnrPath;
206
207#pragma data_seg(GLOBAL2)
208CHAR lastextractpath[CCHMAXPATH];
209ULONGLONG ullDATFileSpaceNeeded = 10000;
210
211typedef struct {
212
213 HWND hwndCnr; //hwnd you want the message posted to
214 HWND hwndClient; //hwnd calling this thread; NULL will work
215 ULONG RunFlags; //runemf2 flags see systemf.h
216 ULONG msg; //Message to post
217 UINT uiLineNumber;
218 PCSZ pszSrcFile;
219 CHAR filename[CCHMAXPATH]; //file passed as MP1 message parameter (file selected)
220 CHAR *pszDirectory; //Execution directory
221 CHAR *pszEnvironment; //Enviroment -- NULL passes current
222 CHAR *pszCmdLine; //Use sprintf to format multipart command line into single string
223 CHAR formatstring[40]; //Usally "%s"
224}
225WAITCHILD;
226
227/** Creates a thread to wait for a child process to complete then posts a message and closes
228 * This function should only be used for runemf2 calls that include the WAIT flag
229 */
230VOID WaitChildThread(VOID * arg)
231{
232 WAITCHILD *WaitChild;
233 HAB thab;
234 CHAR *filename;
235 INT ret;
236
237 DosError(FERR_DISABLEHARDERR);
238
239# ifdef FORTIFY
240 Fortify_EnterScope();
241# endif
242
243 WaitChild = (WAITCHILD *) arg;
244 if (WaitChild) {
245 filename = xstrdup(WaitChild->filename, pszSrcFile, __LINE__);
246 thab = WinInitialize(0);
247 if (thab) {
248 IncrThreadUsage();
249 priority_normal();
250 ret = runemf2(WaitChild->RunFlags, WaitChild->hwndClient,
251 WaitChild->pszSrcFile, WaitChild->uiLineNumber,
252 WaitChild->pszDirectory, WaitChild->pszEnvironment,
253 WaitChild->formatstring, WaitChild->pszCmdLine);
254 if (ret != -1) {
255 if (IsFile(WaitChild->filename) == 1)
256 PostMsg(WaitChild->hwndCnr, WaitChild->msg, MPFROMP(filename), MPVOID);
257 }
258 DecrThreadUsage();
259 WinTerminate(thab);
260 }
261 xfree(WaitChild->pszDirectory, pszSrcFile, __LINE__);
262 xfree(WaitChild->pszEnvironment, pszSrcFile, __LINE__);
263 xfree(WaitChild->pszCmdLine, pszSrcFile, __LINE__);
264 free(WaitChild);
265 } // if WaitChild
266# ifdef FORTIFY
267 Fortify_LeaveScope();
268# endif
269}
270
271static MRESULT EXPENTRY ArcErrProc(HWND hwnd, ULONG msg, MPARAM mp1,
272 MPARAM mp2)
273{
274 ARCDUMP *ad;
275 CHAR szQuotedArcName[CCHMAXPATH];
276
277 switch (msg) {
278 case WM_INITDLG:
279 if (!mp2)
280 WinDismissDlg(hwnd, 0);
281 else {
282 ad = (ARCDUMP *) mp2;
283 WinSetWindowPtr(hwnd, QWL_USER, ad);
284 if (ad->errmsg)
285 WinSetDlgItemText(hwnd, ARCERR_TEXT, ad->errmsg);
286 if (!ad->info->test)
287 WinEnableWindow(WinWindowFromID(hwnd, ARCERR_TEST), FALSE);
288 if (ad->listname) {
289 MLEsetlimit(WinWindowFromID(hwnd, ARCERR_MLE), -1L);
290 MLEsetformat(WinWindowFromID(hwnd, ARCERR_MLE), MLFIE_NOTRANS);
291 MLEsetcurpos(WinWindowFromID(hwnd, ARCERR_MLE),
292 MLEgetlen(WinWindowFromID(hwnd, ARCERR_MLE)));
293 MLEinsert(WinWindowFromID(hwnd, ARCERR_MLE),
294 GetPString(IDS_ARCHIVERREPORTTEXT));
295 MLEinsertfile(WinWindowFromID(hwnd, ARCERR_MLE), ad->listname);
296 }
297 }
298 break;
299
300 case WM_COMMAND:
301 switch (SHORT1FROMMP(mp1)) {
302 case DID_CANCEL:
303 WinDismissDlg(hwnd, 0);
304 break;
305
306 case IDM_HELP:
307 if (hwndHelp) {
308 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
309 MPFROM2SHORT(HELP_ARCERR, 0), MPFROMSHORT(HM_RESOURCEID));
310 }
311 break;
312
313 case DID_OK:
314 ad = WinQueryWindowPtr(hwnd, QWL_USER);
315 WinDlgBox(HWND_DESKTOP, hwnd, ArcReviewDlgProc, FM3ModHandle,
316 AD_FRAME, MPFROMP(ad));
317 WinDismissDlg(hwnd, 0);
318 break;
319
320 case ARCERR_VIEW:
321 ad = WinQueryWindowPtr(hwnd, QWL_USER);
322 {
323 CHAR *list[2];
324
325 list[0] = ad->arcname;
326 list[1] = NULL;
327 if (TestBinary(ad->arcname)) {
328 if (*binview)
329 ExecOnList((HWND) 0, binview, WINDOWED | SEPARATE, NULL, NULL, list,
330 NULL, pszSrcFile, __LINE__);
331 else
332 StartMLEEditor(HWND_DESKTOP, 16 + 4 + 1, ad->arcname, hwnd);
333 }
334 else {
335 if (*viewer) {
336 ExecOnList((HWND) 0, viewer, WINDOWED | SEPARATE |
337 (fViewChild ? CHILD : 0), NULL,
338 NULL, list, NULL, pszSrcFile, __LINE__);
339 }
340 else
341 StartMLEEditor(HWND_DESKTOP, 8 + 4 + 1, ad->arcname, hwnd);
342 }
343 }
344 break;
345
346 case ARCERR_TEST: {
347 CHAR *comspec;
348
349 ad = WinQueryWindowPtr(hwnd, QWL_USER);
350 comspec = getenv( "COMSPEC" );
351 runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
352 hwnd, pszSrcFile, __LINE__, NULL, NULL,
353 "%s /k %s %s",
354 comspec, ad->info->test,
355 BldQuotedFileName(szQuotedArcName, ad->arcname));
356 break;
357 }
358 }
359 return 0;
360 }
361 return WinDefDlgProc(hwnd, msg, mp1, mp2);
362}
363
364static SHORT APIENTRY ArcSort(PMINIRECORDCORE pmrc1, PMINIRECORDCORE pmrc2,
365 PVOID pStorage)
366{
367 PARCITEM pai1 = (PARCITEM) pmrc1;
368 PARCITEM pai2 = (PARCITEM) pmrc2;
369 DIRCNRDATA *pdcd = (DIRCNRDATA *) pStorage;
370 SHORT ret = 0;
371 CHAR *pext, *ppext;
372 INT sortFlags;
373
374 if (!pdcd) {
375 HWND hwndCnr = pai1->hwndCnr;
376
377 pdcd = WinQueryWindowPtr(hwndCnr, QWL_USER);
378 if (!pdcd) {
379 Runtime_Error(pszSrcFile, __LINE__, NULL);
380 return ret;
381 }
382 }
383
384 sortFlags = pdcd->sortFlags; // Optimize
385
386 if (sortFlags) {
387 switch (sortFlags & (~SORT_REVERSE)) {
388 case SORT_FIRSTEXTENSION:
389 pext = strchr(pai1->pszFileName, '.');
390 ppext = strchr(pai2->pszFileName, '.');
391 if (!pext)
392 pext = NullStr;
393 if (!ppext)
394 ppext = NullStr;
395 ret = stricmp(pext, ppext);
396 break;
397
398 case SORT_LASTEXTENSION:
399 pext = strrchr(pai1->pszFileName, '.');
400 ppext = strrchr(pai2->pszFileName, '.');
401 if (!pext)
402 pext = NullStr;
403 if (!ppext)
404 ppext = NullStr;
405 ret = stricmp(pext, ppext);
406 break;
407
408 case SORT_LWDATE:
409 ret = TestCDates(&pai1->date, &pai1->time,
410 &pai2->date, &pai2->time);
411 break;
412
413 case SORT_SIZE:
414 ret =
415 (pai1->cbFile < pai2->cbFile) ? 1 : (pai1->cbFile ==
416 pai2->cbFile) ? 0 : -1;
417 if (!ret)
418 ret =
419 (pai1->cbComp < pai2->cbComp) ? 1 : (pai1->cbComp ==
420 pai2->cbComp) ? 0 : -1;
421 break;
422
423 case SORT_EASIZE:
424 ret =
425 (pai1->cbComp < pai2->cbComp) ? 1 : (pai1->cbComp ==
426 pai2->cbComp) ? 0 : -1;
427 if (!ret)
428 ret =
429 (pai1->cbFile < pai2->cbFile) ? 1 : (pai1->cbFile ==
430 pai2->cbFile) ? 0 : -1;
431 break;
432 }
433 if (!ret)
434 ret = (SHORT) stricmp(pai1->pszFileName, pai2->pszFileName);
435 if (ret && (sortFlags & SORT_REVERSE))
436 ret = ret > 0 ? -1 : 1;
437 return ret;
438 }
439 return (SHORT) stricmp(pai1->pszFileName, pai2->pszFileName);
440}
441
442static INT APIENTRY ArcFilter(PMINIRECORDCORE rmini, PVOID arg)
443{
444 DIRCNRDATA *dcd = (DIRCNRDATA *) arg;
445 PARCITEM r;
446 register INT x;
447 INT ret = FALSE;
448
449 if (dcd && *dcd->mask.szMask) {
450 r = (PARCITEM) rmini;
451 if (dcd->mask.pszMasks[1]) {
452 for (x = 0; dcd->mask.pszMasks[x]; x++) {
453 if (*dcd->mask.pszMasks[x]) {
454 if (*dcd->mask.pszMasks[x] != '/') {
455 if (wildcard(r->pszFileName, dcd->mask.pszMasks[x], TRUE))
456 ret = TRUE;
457 }
458 else {
459 if (wildcard(r->pszFileName, dcd->mask.pszMasks[x] + 1, TRUE)) {
460 ret = FALSE;
461 break;
462 }
463 }
464 }
465 }
466 }
467 else {
468 if (wildcard(r->pszFileName, dcd->mask.szMask, TRUE))
469 ret = TRUE;
470 }
471 }
472 else
473 ret = TRUE;
474 return ret;
475}
476
477static MRESULT EXPENTRY ArcFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
478 MPARAM mp2)
479{
480 return CommonFrameWndProc(ARC_CNR, hwnd, msg, mp1, mp2);
481}
482
483static BOOL IsArcThere(HWND hwnd, CHAR * arcname)
484{
485 if (arcname) {
486 if (IsFile(arcname) != 1) {
487 saymsg(MB_CANCEL, hwnd,
488 GetPString(IDS_SAYWHATTEXT),
489 GetPString(IDS_ARCNOTTHERETEXT), arcname);
490 return FALSE;
491 }
492 return TRUE;
493 }
494 return FALSE;
495}
496
497/**
498 * Free storage associated with archive container item
499 * Caller is responsible for correcting pointers
500 */
501
502static VOID FreeArcItemData(PARCITEM pai)
503{
504 // DbgMsg(pszSrcFile, __LINE__, "FreeArcItemData %p", pai);
505 PSZ psz;
506
507 if (pai->pszFileName && pai->pszFileName != NullStr) {
508 psz = pai->pszFileName;
509 pai->pszFileName = NULL; // 08 Jul 08 SHL was NulStr
510 free(psz);
511 }
512}
513
514/**
515 * Remove item(s) from archive container and free associated storage if requested
516 * @param paiFirst points to first item to remove or NULL to remove all
517 * @param usCnt is remove count or 0 to remove all
518 */
519
520static VOID RemoveArcItems(HWND hwnd, PARCITEM paiFirst, USHORT usCnt, USHORT usFlags)
521{
522 INT remaining = usCnt;
523 PARCITEM pai;
524
525 if ((usCnt && !paiFirst) || (!usCnt && paiFirst))
526 Runtime_Error(pszSrcFile, __LINE__, "paiFirst %p usCnt %u mismatch", paiFirst, usCnt);
527 else {
528 // Free our buffers if free requested
529 if (usFlags & CMA_FREE) {
530 if (paiFirst)
531 pai = paiFirst;
532 else {
533 pai = (PARCITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
534 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
535 if ((INT)pai == -1) {
536 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
537 remaining = -1;
538 pai = NULL;
539 }
540 }
541 while (pai) {
542 FreeArcItemData(pai);
543 pai = (PARCITEM)pai->rc.preccNextRecord;
544 if (remaining && --remaining == 0)
545 break;
546 }
547 }
548 }
549
550 // DbgMsg(pszSrcFile, __LINE__, "RemoveArcItems %p %u %s", pai, usCnt, pai->pszFileName);
551
552 if (remaining != - 1) {
553 remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&paiFirst), MPFROM2SHORT(usCnt, usFlags));
554 if (remaining == -1) {
555 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pai %p cnt %u",
556 hwnd, paiFirst, usCnt);
557 }
558 }
559}
560
561/**
562 * Empty all records from an archive container and
563 * free associated storage and free up field infos
564 */
565
566static VOID EmptyArcCnr(HWND hwnd)
567{
568#if 0 // fixme to be gone or to be configurable
569 {
570 int state = _heapchk();
571 if (state != _HEAPOK)
572 Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
573 else
574 DbgMsg(pszSrcFile, __LINE__, "_memavl %u", _memavl());
575 }
576#endif
577
578 // Remove all ARCITEM records
579 RemoveArcItems(hwnd, NULL, 0, CMA_FREE);
580
581 // Use common code to remove rest
582 EmptyCnr(hwnd);
583}
584
585//== FillArcCnr() generate archive content list and fill container window ==
586
587static INT FillArcCnr(HWND hwndCnr, CHAR * arcname, ARC_TYPE ** arcinfo,
588 ULONGLONG * pullTotalBytes, volatile PCHAR pStopFlag)
589{
590 FILE *fp;
591 HFILE oldstdout;
592 HFILE newstdout;
593 CHAR lonename[CCHMAXPATH + 2],
594 *nsize, *osize, *fdate, *fname, *p, *pp, *arctemp;
595 CHAR s[CCHMAXPATH * 2];
596 CHAR TestStr[CCHMAXPATH * 2];
597 BOOL gotstart;
598 BOOL gotend;
599 BOOL wasquote;
600 BOOL nomove = FALSE; // fixme to be gone?
601 BOOL notest;
602 INT highest = 0, fieldnum, counter = 0, numarcfiles = 0;
603 PARCITEM lastpai;
604 ARC_TYPE *info;
605 ARC_TYPE *tinfo;
606 ULONG apptype;
607 APIRET rc;
608 CHAR *mode;
609 ULONG cnter = 0;
610
611 if (!arcname || !arcinfo)
612 return 0;
613
614 info = *arcinfo;
615 if (!info)
616 info = find_type(arcname, NULL);
617 arctemp = xmallocz(CCHMAXPATH, pszSrcFile, __LINE__);
618 if (CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) == 1)
619 saymsg(MB_OK,
620 HWND_DESKTOP,
621 NullStr,
622 GetPString(IDS_ARCTMPDRIVESPACELIMITED),
623 ArcTempRoot);
624 MakeTempName(arctemp, ArcTempRoot, 2);
625
626
627ReTry:
628
629 tinfo = NULL;
630 numarcfiles = counter = highest = 0;
631 gotstart = gotend = FALSE;
632 lastpai = NULL;
633 *pullTotalBytes = 0;
634 if (!info || !info->list)
635 Runtime_Error(pszSrcFile, __LINE__, NULL);
636 else {
637 RemoveArcItems(hwndCnr, NULL, 0, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
638 *arcinfo = info;
639 highest = info->osizepos;
640 if (info->nsizepos > highest)
641 highest = info->nsizepos;
642 if (info->fdpos > highest)
643 highest = info->fdpos;
644 if (info->fnpos > highest)
645 highest = info->fnpos;
646 if (highest > 50) {
647 saymsg(MB_ENTER | MB_ICONEXCLAMATION, HWND_DESKTOP,
648 GetPString(IDS_SHAMETEXT), GetPString(IDS_BUNGEDUPTEXT));
649 }
650 if (info->fnpos == -1)
651 highest = 32767;
652
653 DosError(FERR_DISABLEHARDERR);
654 xDosForceDelete(arctemp);
655 DosError(FERR_DISABLEHARDERR);
656
657 strcpy(s, info->list);
658 p = strchr(s, ' ');
659 if (p)
660 *p = 0;
661 DosError(FERR_DISABLEHARDERR);
662 if (!xDosQueryAppType(s, &apptype) &&
663 (apptype & FAPPTYP_DOS ||
664 apptype & FAPPTYP_WINDOWSREAL ||
665 apptype & FAPPTYP_WINDOWSPROT ||
666 apptype & FAPPTYP_WINDOWSPROT31)) {
667 p = GetCmdSpec(TRUE);
668 runemf2(SEPARATE | INVISIBLE | MINIMIZED | BACKGROUND | WAIT,
669 hwndCnr, pszSrcFile, __LINE__, NULL, "DOS_BACKGROUND_EXECUTION=1",
670 "%s /C %s %s >%s",
671 p, // shell
672 info->list, // list command
673 BldQuotedFileName(s, arcname),
674 arctemp);
675 }
676 else {
677 mode = "w";
678 fp = xfopen(arctemp, mode, pszSrcFile, __LINE__, FALSE);
679 if (!fp) {
680 xfree(arctemp, pszSrcFile, __LINE__);
681 return 0;
682 }
683 else {
684 newstdout = -1;
685 DosError(FERR_DISABLEHARDERR);
686 rc = xDosDupHandle(fileno(stdout), &newstdout);
687 if (rc) {
688 Dos_Error(MB_CANCEL, rc, hwndCnr, pszSrcFile, __LINE__,
689 PCSZ_DOSDUPHANDLE);
690 xfree(arctemp, pszSrcFile, __LINE__);
691 return 0;
692 }
693 else {
694 oldstdout = fileno(stdout);
695 DosError(FERR_DISABLEHARDERR);
696 rc = xDosDupHandle(fileno(fp), &oldstdout);
697 if (rc) {
698 Dos_Error(MB_CANCEL, rc, hwndCnr, pszSrcFile, __LINE__,
699 PCSZ_DOSDUPHANDLE);
700 xfree(arctemp, pszSrcFile, __LINE__);
701 return 0;
702 }
703 else {
704 rc = 0;
705 //DbgMsg(pszSrcFile, __LINE__, "Number of tries %i", cnter);
706 rc = SearchPathForFile(PCSZ_PATH, s, NULL);
707 if (!rc) {
708 cnter ++;
709 runemf2(SEPARATE | INVISIBLE | MINIMIZED | BACKGROUND | WAIT,
710 hwndCnr, pszSrcFile, __LINE__, NULL, NULL,
711 "%s %s",
712 info->list,
713 BldQuotedFileName(s, arcname));
714 if (cnter == 1) {
715 if (info->test)
716 strcpy(TestStr, info->test);
717 else {
718 strcpy(TestStr, "");
719 notest = TRUE;
720 }
721 }
722 else if (notest && info->test) {
723 strcpy(TestStr, info->test);
724 notest = FALSE;
725 }
726 }
727 oldstdout = fileno(stdout);
728 DosError(FERR_DISABLEHARDERR);
729 xDosDupHandle(newstdout, &oldstdout);
730 DosClose(newstdout);
731 fclose(fp);
732 }
733 }
734 }
735 }
736
737 DosError(FERR_DISABLEHARDERR);
738 mode = "r";
739 fp = xfsopen(arctemp, mode, SH_DENYWR, pszSrcFile, __LINE__, TRUE);
740
741 if (fp) {
742 gotstart = !info->startlist || // If list has no start marker
743 !*info->startlist ||
744 (stricmp(info->startlist, NO_START_OF_ARCHIVER_LIST_STRING) == 0);
745
746 while (!feof(fp) && !gotend && !*pStopFlag) {
747 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
748 break;
749 if (!gotstart) {
750 if (!strcmp(s, info->startlist))
751 gotstart = TRUE;
752 }
753 else if (info->endlist && !strcmp(s, info->endlist))
754 gotend = TRUE;
755 else {
756 // add to container
757 fname = NULL;
758 bstrip(s);
759 if (info->nameisfirst) {
760 strncpy(lonename, s, CCHMAXPATH + 2);
761 lonename[CCHMAXPATH + 1] = 0;
762 fname = lonename;
763 if (!xfgets_bstripcr(s, sizeof(s), fp, pszSrcFile, __LINE__))
764 break;
765 if (*fname == '\"') {
766 memmove(fname, fname + 1, strlen(fname) + 1);
767 p = strchr(fname, '\"');
768 if (p)
769 *p = 0;
770 }
771 }
772 nsize = NULL;
773 osize = fdate = NullStr;
774 p = s;
775 for (fieldnum = 0; fieldnum <= highest; fieldnum++) {
776 pp = p;
777 while (*pp && (*pp == ' ' || *pp == '\t')) // skip leading
778 pp++;
779 if (!*pp) {
780 if (fieldnum == info->fnpos && (!strcmp(strupr(info->ext), "7Z") ||
781 !strcmp(strupr(info->signature), "7Z")))
782 fname = nsize;// GKY 7-30-13 Work around for missing nsize field for some members of archive
783 break;
784 }
785 wasquote = FALSE;
786 p = pp;
787 while (*p && (wasquote ||
788 ((fieldnum != info->fnpos || !info->nameislast) ?
789 (*p != ' ' && *p != '\t') : TRUE))) {
790 if (*p == '\"') {
791 if (!wasquote) {
792 wasquote = TRUE;
793 memmove(p, p + 1, strlen(p));
794 while (*p == ' ' || *p == '\t')
795 p++;
796 }
797 else {
798 memmove(p, p + 1, strlen(p));
799 break;
800 }
801 }
802 else if (*p)
803 p++;
804 }
805 if (*p) {
806 *p = 0;
807 p++;
808 }
809 if (fieldnum == info->nsizepos)
810 nsize = pp;
811 else if (fieldnum == info->osizepos)
812 osize = pp;
813 else if (fieldnum == info->fdpos) {
814 fdate = pp;
815 if (info->fdflds > 1 && info->fdflds < 24) {
816 INT y;
817
818 if (*p) {
819 p--;
820 *p = ' ';
821 for (y = 0; y < info->fdflds - 1; y++) {
822 while (*p && (*p == ' ' || *p == '\t'))
823 p++;
824 while (*p && (*p != ' ' && *p != '\t'))
825 p++;
826 fieldnum++;
827 }
828 if (*p) {
829 *p = 0;
830 p++;
831 }
832 }
833 }
834 }
835 else if (fieldnum == info->fnpos) {
836 fname = pp;
837 if (pp && *pp == '*' && !*(pp + 1)) // workaround for LH.EXE
838 fname = NULL;
839 if (info->nameislast)
840 break;
841 }
842 else if ((!p || !*p) && info->fnpos == -1) {
843 fname = pp;
844 break;
845 }
846 } // for fldnum
847 if (info->nameisnext) {
848 if (!xfgets_bstripcr
849 (lonename, sizeof(lonename), fp, pszSrcFile, __LINE__))
850 break;
851 fname = lonename;
852 }
853 // fixme to complain?
854 if (fname && *fname) {
855
856 RECORDINSERT ri;
857 PARCITEM pai;
858
859 pai = WinSendMsg(hwndCnr,
860 CM_ALLOCRECORD,
861 MPFROMLONG(EXTRA_ARCRECORD_BYTES),
862 MPFROMLONG(1L));
863 if (!pai) {
864 Runtime_Error(pszSrcFile, __LINE__, PCSZ_CM_ALLOCRECORD);
865 break;
866 }
867 else {
868 memset(pai, 0, sizeof(ARCITEM));
869 pai->hwndCnr = hwndCnr;
870 if (*fname == '*') {
871 fname++;
872 pai->flags = ARCFLAGS_REALDIR;
873 }
874 if (fname[strlen(fname) - 1] == '\\' ||
875 fname[strlen(fname) - 1] == '/')
876 pai->flags = ARCFLAGS_REALDIR;
877 pai->pszFileName = xstrdup(fname,pszSrcFile, __LINE__);
878# ifdef FORTIFY
879 // Will be freed by WM_DESTROY
880 Fortify_SetOwner(pai->pszFileName, 1);
881 // Fortify_ChangeScope(pai->pszFileName, -1);
882# endif
883
884 pai->pszDisplayName = pai->pszFileName;
885 pai->rc.pszIcon = pai->pszDisplayName;
886 if (fdate)
887 strcpy(pai->szDate, fdate);
888 // pai->pszFileName = pai->pszFileName;
889 pai->rc.pszIcon = pai->pszFileName;
890 pai->rc.hptrIcon = (pai->flags & ARCFLAGS_REALDIR) != 0 ?
891 hptrDir : hptrFile;
892 pai->pszDate = pai->szDate;
893 if (osize)
894 pai->cbFile = atol(osize);
895 if (nsize)
896 pai->cbComp = atol(nsize);
897 if (info->datetype && fdate && *fdate)
898 ArcDateTime(fdate, info->datetype, &pai->date, &pai->time);
899 memset(&ri, 0, sizeof(RECORDINSERT));
900 ri.cb = sizeof(RECORDINSERT);
901 ri.pRecordOrder = (PRECORDCORE) CMA_END;
902 ri.pRecordParent = (PRECORDCORE) NULL;
903 ri.zOrder = (USHORT) CMA_TOP;
904 ri.cRecordsInsert = 1L;
905 ri.fInvalidateRecord = FALSE;
906 if (WinSendMsg(hwndCnr,
907 CM_INSERTRECORD, MPFROMP(pai), MPFROMP(&ri))) {
908 *pullTotalBytes += pai->cbFile;
909 }
910 numarcfiles++;
911 if (!(++counter % 50)) {
912 if (!lastpai)
913 lastpai = pai;
914 WinSendMsg(hwndCnr,
915 CM_INVALIDATERECORD,
916 lastpai,
917 MPFROM2SHORT(10, CMA_ERASE | CMA_REPOSITION));
918 lastpai = pai;
919 }
920 // Avoid hogging system for large archive
921 if (numarcfiles == 100)
922 priority_idle();
923 }
924 }
925 }
926 } // while !eof
927
928 fclose(fp);
929
930 if (*pStopFlag)
931 numarcfiles = 0; // Request close
932 else if (!numarcfiles || !gotstart
933 || (!gotend && info->endlist && *info->endlist &&
934 (stricmp(info->endlist, NO_END_OF_ARCHIVER_LIST_STRING)))) {
935 // Oops
936 ARCDUMP ad;
937 CHAR errstr[CCHMAXPATH + 256];
938
939 // Try for alternate archiver
940 tinfo = info;
941 do {
942 tinfo = tinfo->next;
943 if (tinfo)
944 tinfo = find_type(arcname, tinfo);
945 if (tinfo) {
946 DosError(FERR_DISABLEHARDERR);
947 xDosForceDelete(arctemp);
948 info = tinfo;
949 goto ReTry;
950 }
951 } while (tinfo);
952 if (!fAlertBeepOff)
953 DosBeep(750, 50); // wake up user
954
955 if (cnter > 0) {
956 CHAR Temp[CCHMAXPATH + 2];
957
958 sprintf(errstr, GetPString(IDS_ARCERRORINFOTEXT),
959 arcname,
960 !gotstart ? GetPString(IDS_NOGOTSTARTTEXT) : NullStr,
961 !numarcfiles ? GetPString(IDS_NOARCFILESFOUNDTEXT) : NullStr,
962 !gotend ? GetPString(IDS_NOENDOFLISTTEXT) : NullStr,
963 !notest ? NullStr : GetPString(IDS_ARCNOTEST));
964 memset(&ad, 0, sizeof(ARCDUMP));
965 ad.info = info;
966 strcpy(ad.listname, arctemp);
967 strcpy(ad.arcname, arcname);
968 if (!notest) {
969 strcpy(Temp, info->test);
970 info->test = xstrdup(TestStr, pszSrcFile, __LINE__);
971 }
972 else if (rc) {
973 strcpy(Temp, info->test);
974 info->test = NULL;
975 }
976 ad.errmsg = errstr;
977 WinDlgBox(HWND_DESKTOP,
978 hwndCnr,
979 ArcErrProc, FM3ModHandle, ARCERR_FRAME, MPFROMP(&ad));
980 if (!notest || rc)
981 info->test = xstrdup(Temp, pszSrcFile, __LINE__);
982 }
983 else
984 saymsg(MB_OK, HWND_DESKTOP, GetPString(IDS_ARCMISSINGEXE),
985 GetPString(IDS_ARCMISSINGEXEVERBOSE));
986 }
987 else if (!nomove && tinfo) {
988 // if we got a false hit, move working hit to top
989 tinfo = info->next;
990 info->next = arcsighead;
991 arcsighead->prev = info;
992 if (tinfo)
993 tinfo->next->prev = info->prev;
994 info->prev->next = tinfo;
995 info->prev = NULL;
996 arcsighead = info;
997 rewrite_archiverbb2(NULL); // Rewrite with warning
998 }
999 } // if opened
1000
1001 DosError(FERR_DISABLEHARDERR);
1002 xDosForceDelete(arctemp);
1003 xfree(arctemp, pszSrcFile, __LINE__);
1004 }
1005
1006 if (numarcfiles)
1007 priority_normal();
1008
1009 return numarcfiles;
1010} // FillArcCnr
1011
1012MRESULT EXPENTRY ArcTextProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1013{
1014 static BOOL emphasized = FALSE;
1015 static HWND hwndButtonPopup = (HWND) 0;
1016 static ULONG timestamp = ULONG_MAX;
1017 static USHORT lastid = 0;
1018
1019 switch (msg) {
1020 case WM_CREATE:
1021 return CommonTextProc(hwnd, msg, mp1, mp2);
1022
1023 case WM_COMMAND:
1024 return WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1025 ARC_CNR), msg, mp1, mp2);
1026
1027 case UM_CONTEXTMENU:
1028 case WM_CONTEXTMENU:
1029 {
1030 USHORT id;
1031
1032 id = WinQueryWindowUShort(hwnd, QWS_ID);
1033 switch (id) {
1034 case DIR_SELECTED:
1035 case DIR_VIEW:
1036 case DIR_SORT:
1037 {
1038 POINTL ptl = { 0, 0 };
1039 SWP swp;
1040 DIRCNRDATA *dcd;
1041
1042 if (hwndButtonPopup)
1043 WinDestroyWindow(hwndButtonPopup);
1044 if (id == DIR_SELECTED)
1045 id = DIR_RESTORE;
1046 if (id == lastid) {
1047
1048 ULONG check;
1049
1050 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &check,
1051 sizeof(check));
1052 if (check < timestamp + 500) {
1053 lastid = 0;
1054 goto MenuAbort;
1055 }
1056 }
1057 hwndButtonPopup = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
1058 if (hwndButtonPopup) {
1059 WinSetWindowUShort(hwndButtonPopup, QWS_ID, id);
1060 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
1061 QW_PARENT),
1062 ARC_CNR), QWL_USER);
1063 if (id == DIR_SORT) {
1064 if (dcd)
1065 SetSortChecks(hwndButtonPopup, dcd->sortFlags);
1066 WinSendMsg(hwndButtonPopup,
1067 MM_DELETEITEM,
1068 MPFROM2SHORT(IDM_SORTNONE, FALSE), MPVOID);
1069 WinSendMsg(hwndButtonPopup,
1070 MM_DELETEITEM,
1071 MPFROM2SHORT(IDM_SORTNAME, FALSE), MPVOID);
1072 WinSendMsg(hwndButtonPopup,
1073 MM_DELETEITEM,
1074 MPFROM2SHORT(IDM_SORTLADATE, FALSE), MPVOID);
1075 WinSendMsg(hwndButtonPopup,
1076 MM_DELETEITEM,
1077 MPFROM2SHORT(IDM_SORTCRDATE, FALSE), MPVOID);
1078 WinSendMsg(hwndButtonPopup,
1079 MM_DELETEITEM,
1080 MPFROM2SHORT(IDM_SORTDIRSFIRST, FALSE), MPVOID);
1081 WinSendMsg(hwndButtonPopup,
1082 MM_DELETEITEM,
1083 MPFROM2SHORT(IDM_SORTDIRSLAST, FALSE), MPVOID);
1084 WinSendMsg(hwndButtonPopup,
1085 MM_DELETEITEM,
1086 MPFROM2SHORT(IDM_SORTSUBJECT, FALSE), MPVOID);
1087 WinSendMsg(hwndButtonPopup,
1088 MM_SETITEMTEXT,
1089 MPFROM2SHORT(IDM_SORTEASIZE, 0),
1090 MPFROMP(GetPString(IDS_COMPRESSEDSIZEMENUTEXT)));
1091 WinSendMsg(hwndButtonPopup,
1092 MM_SETITEMTEXT,
1093 MPFROM2SHORT(IDM_SORTLWDATE, 0),
1094 MPFROMP(GetPString(IDS_DATEMENUTEXT)));
1095 }
1096 ptl.x = 0;
1097 if (WinPopupMenu(HWND_OBJECT,
1098 HWND_OBJECT,
1099 hwndButtonPopup, -32767, -32767, 0, 0)) {
1100 WinQueryWindowPos(hwndButtonPopup, &swp);
1101 ptl.y = -(swp.cy + 2);
1102 }
1103 else {
1104 WinQueryWindowPos(hwnd, &swp);
1105 ptl.y = swp.cy + 2;
1106 }
1107 if (WinPopupMenu(hwnd,
1108 hwnd,
1109 hwndButtonPopup,
1110 ptl.x,
1111 ptl.y,
1112 0,
1113 PU_HCONSTRAIN | PU_VCONSTRAIN |
1114 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
1115 CenterOverWindow(hwndButtonPopup);
1116 PaintRecessedWindow(hwnd, (HPS) 0, FALSE, FALSE);
1117 }
1118 }
1119 }
1120 break;
1121 default:
1122 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1123 ARC_CNR),
1124 WM_CONTROL, MPFROM2SHORT(ARC_CNR, CN_CONTEXTMENU), MPVOID);
1125 break;
1126 }
1127 }
1128 MenuAbort:
1129 if (msg == UM_CONTEXTMENU)
1130 return 0;
1131 break;
1132
1133 case WM_MENUEND:
1134 if (hwndButtonPopup == (HWND) mp2) {
1135 lastid = WinQueryWindowUShort((HWND) mp2, QWS_ID);
1136 WinDestroyWindow(hwndButtonPopup);
1137 hwndButtonPopup = (HWND) 0;
1138 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &timestamp,
1139 sizeof(timestamp));
1140 switch (lastid) {
1141 case DIR_VIEW:
1142 case DIR_SORT:
1143 case DIR_RESTORE:
1144 case DIR_SELECTED:
1145 PaintRecessedWindow(hwnd, (HPS) 0, TRUE, FALSE);
1146 break;
1147 }
1148 }
1149 break;
1150
1151 case WM_MOUSEMOVE:
1152 {
1153 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
1154 PCSZ s = NULL;
1155
1156 if (fOtherHelp) {
1157 if ((!hwndBubble ||
1158 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
1159 !WinQueryCapture(HWND_DESKTOP)) {
1160 switch (id) {
1161 case DIR_TOTALS:
1162 s = GetPString(IDS_ARCCNRTOTALSHELPTEXT);
1163 break;
1164 case DIR_SELECTED:
1165 s = GetPString(IDS_ARCCNRSELECTEDHELPTEXT);
1166 break;
1167 case DIR_VIEW:
1168 s = GetPString(IDS_ARCCNRVIEWHELPTEXT);
1169 break;
1170 case DIR_SORT:
1171 s = GetPString(IDS_DIRCNRSORTHELP);
1172 break;
1173 case DIR_FILTER:
1174 s = GetPString(IDS_DIRCNRFILTERHELP);
1175 break;
1176 case DIR_FOLDERICON:
1177 s = GetPString(IDS_ARCCNRFOLDERHELPTEXT);
1178 break;
1179 default:
1180 break;
1181 }
1182 if (s)
1183 MakeBubble(hwnd, TRUE, s);
1184 else if (hwndBubble)
1185 WinDestroyWindow(hwndBubble);
1186 }
1187 }
1188 switch (id) {
1189 case DIR_FILTER:
1190 case DIR_SORT:
1191 case DIR_VIEW:
1192 case DIR_SELECTED:
1193 case DIR_FOLDERICON:
1194 return CommonTextButton(hwnd, msg, mp1, mp2);
1195 }
1196 }
1197 break;
1198
1199 case WM_BUTTON3UP:
1200 case WM_BUTTON1UP:
1201 case WM_BUTTON1DOWN:
1202 case WM_BUTTON3DOWN:
1203 {
1204 USHORT id;
1205
1206 id = WinQueryWindowUShort(hwnd, QWS_ID);
1207 switch (id) {
1208 case DIR_FILTER:
1209 case DIR_SORT:
1210 case DIR_VIEW:
1211 case DIR_SELECTED:
1212 case DIR_FOLDERICON:
1213 return CommonTextButton(hwnd, msg, mp1, mp2);
1214 }
1215 }
1216 break;
1217
1218 case UM_CLICKED:
1219 case UM_CLICKED3:
1220 {
1221 USHORT id, cmd = 0;
1222
1223 id = WinQueryWindowUShort(hwnd, QWS_ID);
1224 switch (id) {
1225 case DIR_FOLDERICON:
1226 switch (msg) {
1227 case WM_BUTTON3CLICK:
1228 case WM_CHORD:
1229 cmd = IDM_RESCAN;
1230 break;
1231 default:
1232 if ((SHORT2FROMMP(mp2) & KC_ALT) != 0)
1233 cmd = IDM_WINDOWDLG;
1234 else
1235 cmd = IDM_WALKDIR;
1236 break;
1237 }
1238 break;
1239 case DIR_VIEW:
1240 case DIR_SORT:
1241 case DIR_SELECTED:
1242 PostMsg(hwnd, UM_CONTEXTMENU, MPVOID, MPVOID);
1243 break;
1244 case DIR_FILTER:
1245 cmd = IDM_FILTER;
1246 break;
1247 default:
1248 break;
1249 }
1250 if (cmd)
1251 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1252 ARC_CNR),
1253 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
1254 }
1255 return 0;
1256
1257 case WM_BEGINDRAG:
1258 case DM_DROP:
1259 case DM_DRAGOVER:
1260 case DM_DRAGLEAVE:
1261 case DM_DROPHELP:
1262 if (msg == DM_DRAGOVER) {
1263 if (!emphasized) {
1264 emphasized = TRUE;
1265 DrawTargetEmphasis(hwnd, emphasized);
1266 }
1267 }
1268 else if (msg != WM_BEGINDRAG) {
1269 if (emphasized) {
1270 emphasized = FALSE;
1271 DrawTargetEmphasis(hwnd, emphasized);
1272 }
1273 }
1274 switch (WinQueryWindowUShort(hwnd, QWS_ID)) {
1275 case DIR_FOLDERICON:
1276 switch (msg) {
1277 case DM_DRAGOVER:
1278 if (AcceptOneDrop(hwnd, mp1, mp2))
1279 return MRFROM2SHORT(DOR_DROP, DO_MOVE);
1280 return MRFROM2SHORT(DOR_NODROP, 0); // Drop not valid
1281 case DM_DROPHELP:
1282 DropHelp(mp1, mp2, hwnd, GetPString(IDS_ARCCNRFOLDERDROPHELPTEXT));
1283 return 0;
1284 case DM_DROP:
1285 {
1286 char szFrom[CCHMAXPATH + 2];
1287
1288 if (emphasized) {
1289 emphasized = FALSE;
1290 DrawTargetEmphasis(hwnd, emphasized);
1291 }
1292 if (GetOneDrop(hwnd, mp1, mp2, szFrom, sizeof(szFrom)))
1293 WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1294 ARC_CNR),
1295 WM_COMMAND,
1296 MPFROM2SHORT(IDM_SWITCH, 0), MPFROMP(szFrom));
1297 }
1298 return 0;
1299 default:
1300 return PFNWPStatic(hwnd, msg, mp1, mp2);
1301 }
1302 default:
1303 {
1304 CNRDRAGINFO cnd;
1305 USHORT dcmd;
1306
1307 switch (msg) {
1308 case DM_DROP:
1309 dcmd = CN_DROP;
1310 break;
1311 case DM_DRAGOVER:
1312 dcmd = CN_DRAGOVER;
1313 break;
1314 case DM_DRAGLEAVE:
1315 dcmd = CN_DRAGLEAVE;
1316 break;
1317 case DM_DROPHELP:
1318 dcmd = CN_DROPHELP;
1319 break;
1320 case WM_BEGINDRAG:
1321 dcmd = CN_INITDRAG;
1322 break;
1323 }
1324 cnd.pDragInfo = (PDRAGINFO) mp1;
1325 cnd.pRecord = NULL;
1326 return WinSendMsg(WinQueryWindow(hwnd, QW_PARENT),
1327 WM_CONTROL,
1328 MPFROM2SHORT(ARC_CNR, dcmd), MPFROMP(&cnd));
1329 }
1330 }
1331 }
1332 return PFNWPStatic(hwnd, msg, mp1, mp2);
1333}
1334
1335MRESULT EXPENTRY ArcClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1336 MPARAM mp2)
1337{
1338
1339 switch (msg) {
1340 case UM_CONTAINERHWND:
1341 return MRFROMLONG(WinWindowFromID(hwnd, ARC_CNR));
1342
1343 case UM_VIEWSMENU:
1344 // fixme to disble menu items as needed
1345 return MRFROMLONG(CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP));
1346
1347 case UM_FILESMENU:
1348 // fixme to disble menu items as needed
1349 return MRFROMLONG(CheckMenu(hwnd, &ArcMenu, ARC_POPUP));
1350
1351 case MM_PORTHOLEINIT:
1352 case WM_INITMENU:
1353 case UM_INITMENU:
1354 case UM_COMMAND:
1355 case UM_LOADFILE:
1356 case UM_UPDATERECORD:
1357 case UM_UPDATERECORDLIST:
1358 case WM_COMMAND:
1359 case WM_CONTROL:
1360 case WM_CLOSE:
1361 return WinSendMsg(WinWindowFromID(hwnd, ARC_CNR), msg, mp1, mp2);
1362
1363 case WM_PSETFOCUS:
1364 case WM_SETFOCUS:
1365 if (mp2)
1366 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
1367 break;
1368
1369 case UM_FOCUSME:
1370 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, ARC_CNR));
1371 break;
1372
1373 case WM_PAINT:
1374 {
1375 HPS hps;
1376 RECTL rcl;
1377
1378 hps = WinBeginPaint(hwnd, (HPS) 0, NULL);
1379 if (hps) {
1380 WinQueryWindowRect(hwnd, &rcl);
1381 WinFillRect(hps, &rcl, CLR_PALEGRAY);
1382 CommonTextPaint(hwnd, hps);
1383 WinEndPaint(hps);
1384 }
1385 }
1386 break;
1387
1388 case UM_SIZE:
1389 case WM_SIZE:
1390 if (msg == UM_SIZE) {
1391
1392 SWP swp;
1393
1394 WinQueryWindowPos(hwnd, &swp);
1395 mp1 = MPFROM2SHORT(swp.cx, swp.cy);
1396 mp2 = MPFROM2SHORT(swp.cx, swp.cy);
1397 }
1398 {
1399 USHORT cx, cy, bx;
1400
1401 cx = SHORT1FROMMP(mp2);
1402 cy = SHORT2FROMMP(mp2);
1403 WinSetWindowPos(WinWindowFromID(hwnd, ARC_CNR), HWND_TOP,
1404 0,
1405 22, cx, cy - (24 + 22), SWP_SHOW | SWP_MOVE | SWP_SIZE);
1406 WinSetWindowPos(WinWindowFromID(hwnd, ARC_EXTRACTDIR), HWND_TOP,
1407 0, 0, cx, 22, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1408 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FOLDERICON), HWND_TOP,
1409 2, cy - 22, 24, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1410 WinSetWindowPos(WinWindowFromID(hwnd, DIR_TOTALS), HWND_TOP,
1411 29,
1412 cy - 22,
1413 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1414 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SELECTED), HWND_TOP,
1415 29 + (cx / 3) + 2,
1416 cy - 22,
1417 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1418 bx = (cx - (29 + (((cx / 3) + 2) * 2))) / 3;
1419 WinSetWindowPos(WinWindowFromID(hwnd, DIR_VIEW), HWND_TOP,
1420 29 + (((cx / 3) + 2) * 2),
1421 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1422 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SORT), HWND_TOP,
1423 29 + (((cx / 3) + 2) * 2) + bx,
1424 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1425 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FILTER), HWND_TOP,
1426 29 + (((cx / 3) + 2) * 2) + (bx * 2),
1427 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
1428 }
1429 CommonTextPaint(hwnd, (HPS) 0);
1430 if (msg == UM_SIZE) {
1431 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
1432 SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE);
1433 return 0;
1434 }
1435 break;
1436 }
1437 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1438}
1439
1440MRESULT EXPENTRY ArcObjWndProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1441{
1442 DIRCNRDATA *dcd;
1443 PSZ psz;
1444 CHAR szQuotedArcName[CCHMAXPATH];
1445 CHAR szQuotedMemberName[CCHMAXPATH];
1446
1447 switch (msg) {
1448 case WM_CREATE:
1449 DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2); // 18 Jul 08 SHL fixme
1450 break;
1451
1452 case DM_PRINTOBJECT:
1453 case DM_DISCARDOBJECT:
1454 dcd = INSTDATA(hwnd);
1455 if (dcd) {
1456
1457 LISTINFO *li;
1458 CNRDRAGINFO cni;
1459
1460 cni.pRecord = NULL;
1461 cni.pDragInfo = (PDRAGINFO) mp1;
1462 li = DoFileDrop(dcd->hwndCnr,
1463 dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
1464 CheckPmDrgLimit(cni.pDragInfo);
1465 if (li) {
1466 li->type = (msg == DM_DISCARDOBJECT) ? IDM_DELETE : IDM_PRINT;
1467 if (!li->list ||
1468 !li->list[0] || !PostMsg(hwnd, UM_ACTION, MPFROMP(li), MPVOID))
1469 FreeListInfo(li);
1470 else
1471 return MRFROMLONG(DRR_SOURCE);
1472 }
1473 }
1474 return MRFROMLONG(DRR_TARGET);
1475
1476 case DM_RENDERPREPARE:
1477 return (MRESULT) TRUE;
1478
1479 case DM_RENDER:
1480 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1481 if (dcd && dcd->info && dcd->info->extract && dcd->arcname) {
1482
1483 PDRAGTRANSFER pdt = (PDRAGTRANSFER) mp1;
1484 CHAR filename[CCHMAXPATH];
1485 ULONG len;
1486
1487 if (pdt->hwndClient && pdt->pditem && pdt->hstrSelectedRMF &&
1488 pdt->hstrRenderToName) {
1489 if (pdt->usOperation == DO_COPY || pdt->usOperation == DO_MOVE) {
1490 *filename = 0;
1491 len = DrgQueryStrName(pdt->hstrSelectedRMF, CCHMAXPATH, filename);
1492 filename[len] = 0;
1493 if (strnicmp(filename, "OS2FILE,", 8)) {
1494 *filename = 0;
1495 len = DrgQueryStrName(pdt->hstrRenderToName, CCHMAXPATH, filename);
1496 filename[len] = 0;
1497 if (len && *filename) {
1498 psz = xstrdup(filename, pszSrcFile, __LINE__);
1499 if (psz) {
1500 PostMsg(hwnd, UM_RENDER, MPFROMP(pdt), MPFROMP(psz));
1501 return (MRESULT) TRUE;
1502 }
1503 }
1504 }
1505 }
1506 pdt->fsReply = DMFL_RENDERRETRY;
1507 }
1508 }
1509 return (MRESULT) FALSE;
1510
1511 case UM_RENDER:
1512 {
1513 PDRAGTRANSFER pdt = (PDRAGTRANSFER) mp1;
1514 USHORT usRes = DMFL_RENDERFAIL;
1515
1516 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1517 if (dcd && dcd->info && dcd->info->extract && dcd->arcname) {
1518
1519 CHAR *filename = (CHAR *) mp2, *p;
1520 ULONG len;
1521 CHAR membername[CCHMAXPATH], construct[CCHMAXPATH * 2];
1522
1523 *membername = 0;
1524 len = DrgQueryStrName(pdt->pditem->hstrSourceName,
1525 CCHMAXPATH, membername);
1526 membername[len] = 0;
1527 if (*membername && len && filename) {
1528 unlinkf(filename);
1529 strcpy(construct, filename);
1530 p = strrchr(filename, '\\');
1531 if (!p)
1532 *construct = 0;
1533 else {
1534 if (p == filename || *(p - 1) == ':')
1535 p++;
1536 *p = 0;
1537 }
1538 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS | WAIT |
1539 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1540 dcd->hwndClient, pszSrcFile, __LINE__, construct, NULL,
1541 "%s %s %s",
1542 dcd->info->extract,
1543 BldQuotedFileName(szQuotedArcName, dcd->arcname),
1544 BldQuotedFileName(szQuotedMemberName, membername));
1545 BldFullPathName(construct, construct, membername);
1546 if (IsFile(construct) != -1) {
1547 rename(construct, filename);
1548 unlinkf(construct);
1549 if (IsFile(filename) != -1)
1550 usRes = DMFL_RENDEROK;
1551 }
1552 }
1553 }
1554 xfree((CHAR *)mp2, pszSrcFile, __LINE__);
1555 PostMsg(pdt->hwndClient, DM_RENDERCOMPLETE, MPFROMP(pdt),
1556 MPFROM2SHORT(usRes, 0));
1557 }
1558 return 0;
1559
1560 case UM_SETUP:
1561# ifdef FORTIFY
1562 Fortify_EnterScope();
1563# endif
1564 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1565 if (!dcd) {
1566 Runtime_Error(pszSrcFile, __LINE__, NULL);
1567 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1568 }
1569 else {
1570# ifdef FORTIFY
1571 Fortify_BecomeOwner(dcd);
1572# endif
1573 // set unique id
1574 WinSetWindowUShort(hwnd, QWS_ID, ARCOBJ_FRAME + (ARC_FRAME - dcd->id));
1575 dcd->hwndObject = hwnd; // pass back hwnd
1576 if (ParentIsDesktop(hwnd, dcd->hwndParent))
1577 DosSleep(100); //05 Aug 07 GKY 250 // Avoid race?
1578 }
1579 return 0;
1580
1581 case UM_RESCAN:
1582 /**
1583 * populate container
1584 */
1585 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1586 if (dcd) {
1587 if (mp1)
1588 strcpy(dcd->arcname, (CHAR *) mp1); // Update name on request
1589 dcd->ullTotalBytes = dcd->totalfiles =
1590 dcd->selectedfiles = dcd->selectedbytes = 0;
1591 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, "0");
1592 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, "0 / 0k");
1593 dcd->totalfiles = FillArcCnr(dcd->hwndCnr,
1594 dcd->arcname,
1595 &dcd->info,
1596 &dcd->ullTotalBytes, &dcd->stopflag);
1597 if (!dcd->totalfiles)
1598 PostMsg(dcd->hwndCnr, WM_CLOSE, MPVOID, MPVOID);
1599 else {
1600 dcd->arcfilled = TRUE;
1601 if (!PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID))
1602 WinSendMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
1603 PostMsg(dcd->hwndCnr, UM_SETUP2, MPVOID, MPVOID);
1604 WinSendMsg(dcd->hwndCnr,
1605 CM_INVALIDATERECORD,
1606 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
1607 }
1608 }
1609 return 0;
1610
1611 case UM_SELECT:
1612 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1613 if (dcd) {
1614 switch (SHORT1FROMMP(mp1)) {
1615 case IDM_SELECTALL:
1616 case IDM_SELECTALLFILES:
1617 SelectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, TRUE);
1618 break;
1619 case IDM_DESELECTALL:
1620 case IDM_DESELECTALLFILES:
1621 DeselectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, TRUE);
1622 break;
1623 case IDM_DESELECTMASK:
1624 case IDM_SELECTMASK:
1625 {
1626 MASK mask;
1627 PARCITEM pci = (PARCITEM) mp2;
1628
1629 memset(&mask, 0, sizeof(MASK));
1630 mask.fNoAttribs = TRUE;
1631 mask.fNoDirs = TRUE;
1632 mask.fText = TRUE;
1633 strcpy(mask.prompt,
1634 GetPString((SHORT1FROMMP(mp1) == IDM_SELECTMASK) ?
1635 IDS_SELECTFILTERTEXT : IDS_DESELECTFILTERTEXT));
1636 if (pci && (INT) pci != -1)
1637 strcpy(mask.szMask, pci->pszFileName);
1638 if (WinDlgBox(HWND_DESKTOP, dcd->hwndCnr, PickMaskDlgProc,
1639 FM3ModHandle, MSK_FRAME, MPFROMP(&mask))) {
1640 if (SHORT1FROMMP(mp1) == IDM_SELECTMASK)
1641 SelectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, NULL, FALSE);
1642 else
1643 DeselectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, NULL, FALSE);
1644 }
1645 }
1646 break;
1647
1648 case IDM_INVERT:
1649 InvertAll(dcd->hwndCnr);
1650 break;
1651 }
1652 }
1653 return 0;
1654
1655 case UM_ENTER:
1656 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1657 if (dcd) {
1658
1659 CHAR *s = (CHAR *) mp1, *p, *pp; // filename[CCHMAXPATH];
1660 WAITCHILD *WaitChild;
1661
1662 WaitChild = xmallocz(sizeof(WAITCHILD), pszSrcFile, __LINE__);
1663 if (!WaitChild)
1664 return 0;
1665 WaitChild->pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1666 if (s) {
1667 if (!dcd->info->extract) {
1668 Runtime_Error(pszSrcFile, __LINE__, "no extract");
1669 free(s);
1670 return 0;
1671 }
1672 sprintf(WaitChild->pszCmdLine, "%s %s %s",
1673 dcd->info->exwdirs ? dcd->info->exwdirs :
1674 dcd->info->extract,
1675 BldQuotedFileName(szQuotedArcName, dcd->arcname),
1676 BldQuotedFileName(szQuotedMemberName, s));
1677 if (!dcd->info->exwdirs) {
1678 p = s;
1679 p = strrchr(s, '\\');
1680 pp = strrchr(s, '/');
1681 if (p && pp)
1682 p = max(p, pp);
1683 else if (!p)
1684 p = pp;
1685 if (p)
1686 memmove(s, p + 1, strlen(p + 1));
1687 }
1688 sprintf(WaitChild->filename, "%s\\%s", dcd->workdir, s);
1689 ForwardslashToBackslash(WaitChild->filename);
1690 free(s);
1691 WaitChild->RunFlags = SEPARATE | ASYNCHRONOUS | WAIT |
1692 (fArcStuffVisible ? 0 : BACKGROUND);
1693 WaitChild->hwndClient = dcd->hwndClient;
1694 WaitChild->msg = UM_ENTER;
1695 WaitChild->uiLineNumber = __LINE__;
1696 WaitChild->pszSrcFile = pszSrcFile;
1697 WaitChild->pszDirectory = xstrdup(dcd->workdir, pszSrcFile, __LINE__);
1698 WaitChild->pszEnvironment = NULL;
1699 strcpy(WaitChild->formatstring, "%s");
1700 WaitChild->hwndCnr = dcd->hwndCnr;
1701 xbeginthread(WaitChildThread,
1702 65536,
1703 WaitChild,
1704 pszSrcFile,
1705 __LINE__);
1706 }
1707 }
1708 return 0;
1709
1710 case UM_COMMAND:
1711 if (mp1) {
1712 if (PostMsg(hwnd, UM_ACTION, mp1, mp2))
1713 return (MRESULT) TRUE;
1714 }
1715 return 0;
1716
1717 case UM_ACTION:
1718 DosError(FERR_DISABLEHARDERR);
1719 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1720 if (dcd) {
1721
1722 LISTINFO *li = (LISTINFO *) mp1;
1723 register INT x;
1724
1725 if (li && li->list && li->list[0]) {
1726 // printf("%x/r", li->type); fflush(stdout); // 24 Sep 08 SHL
1727 switch (li->type) {
1728 case IDM_ARCHIVE:
1729 case IDM_ARCHIVEM:
1730 {
1731 DIRCNRDATA ad;
1732 CHAR szBuffer[1025], *p;
1733
1734 if (!li->list[1] && !stricmp(li->list[0], dcd->arcname)) {
1735 Runtime_Error(pszSrcFile, __LINE__, "arc to self");
1736 break;
1737 }
1738 ad = *dcd;
1739 ad.namecanchange = 0;
1740 ad.fmoving = (li->type == IDM_ARCHIVEM);
1741 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndClient, ArchiveDlgProc,
1742 FM3ModHandle, ARCH_FRAME, (PVOID) & ad) || !*ad.arcname ||
1743 !*ad.command) // we blew it
1744 break;
1745 // build the sucker
1746 strcpy(szBuffer, ad.command);
1747 strcat(szBuffer, " ");
1748
1749 BldQuotedFileName(szBuffer + strlen(szBuffer), ad.arcname);
1750
1751 p = &szBuffer[strlen(szBuffer)]; // Remeber where archiver name ends
1752
1753 if (ad.mask.szMask) {
1754 strcat(szBuffer, " ");
1755
1756 BldQuotedFileName(szBuffer + strlen(szBuffer), ad.mask.szMask);
1757 }
1758 strcat(szBuffer, " ");
1759 x = 0;
1760
1761 // Run commands avoiding command line overflow
1762 while (li->list[x]) {
1763
1764 if (IsFile(li->list[x]))
1765 BldQuotedFileName(szBuffer + strlen(szBuffer), li->list[x]);
1766 else
1767 BldQuotedFullPathName(szBuffer + strlen(szBuffer), li->list[x], "*");
1768
1769 x++;
1770 if (!li->list[x] || strlen(szBuffer) +
1771 strlen(li->list[x]) + 5 > MaxComLineStrg) {
1772 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
1773 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1774 hwnd, pszSrcFile, __LINE__,
1775 NULL, NULL, "%s", szBuffer);
1776 *p = 0;
1777 }
1778 strcat(szBuffer, " ");
1779 } // while
1780
1781 PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID);
1782 Broadcast(WinQueryAnchorBlock(hwnd),
1783 hwndMain, UM_UPDATERECORD, MPFROMP(ad.arcname), MPVOID);
1784 Broadcast(WinQueryAnchorBlock(hwnd),
1785 hwndMain,
1786 UM_UPDATERECORDLIST, MPFROMP(li->list), MPVOID);
1787 }
1788 break;
1789
1790 case IDM_REFRESH:
1791 case IDM_DELETE:
1792 {
1793 CHAR *endofit;
1794 PSZ pszCmdLine;
1795 INT z;
1796 CHECKLIST ck;
1797 CHAR prompt[CCHMAXPATH + 257];
1798
1799 if (!dcd->info->delete)
1800 break;
1801 memset(&ck, 0, sizeof(ck));
1802 ck.size = sizeof(ck);
1803 ck.list = li->list;
1804 ck.cmd = li->type;
1805 ck.prompt = prompt;
1806 ck.flags = CHECK_ARCHIVE;
1807 sprintf(prompt, GetPString(IDS_ARCCNRDELREFTEXT),
1808 (li->type == IDM_DELETE) ?
1809 GetPString(IDS_DELETELOWERTEXT) :
1810 GetPString(IDS_REFRESHLOWERTEXT),
1811 &"s"[li->list[1] == NULL],
1812 dcd->arcname,
1813 (li->type == IDM_DELETE) ?
1814 GetPString(IDS_DELETELOWERTEXT) :
1815 GetPString(IDS_REFRESHLOWERTEXT));
1816 if (!WinDlgBox(HWND_DESKTOP, hwnd, CheckListProc,
1817 FM3ModHandle, CHECK_FRAME, MPFROMP(&ck)))
1818 break;
1819 li->list = ck.list;
1820 if (!li->list || !li->list[0])
1821 break;
1822 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1823 if (!pszCmdLine)
1824 break;
1825 strcpy(pszCmdLine, li->type == IDM_DELETE ?
1826 dcd->info->delete :
1827 dcd->info->create);
1828 strcat(pszCmdLine, " ");
1829 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), dcd->arcname);
1830 endofit = &pszCmdLine[strlen(pszCmdLine)];
1831 z = 0;
1832 do {
1833 for (x = z; li->list[x] &&
1834 strlen(pszCmdLine) + strlen(li->list[x]) < 999; x++) {
1835 strcat(pszCmdLine, " ");
1836 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->list[x]);
1837 }
1838 z = x;
1839 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS | WAIT |
1840 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1841 hwnd, pszSrcFile, __LINE__, NullStr, NULL, "%s", pszCmdLine);
1842 *endofit = 0;
1843 free(pszCmdLine);
1844 } while (li->list[x]);
1845 PostMsg(dcd->hwndCnr, UM_RESCAN, MPFROMSHORT(1), MPVOID);
1846 Broadcast(WinQueryAnchorBlock(hwnd),
1847 hwndMain,
1848 UM_UPDATERECORD, MPFROMP(dcd->arcname), MPVOID);
1849 }
1850 break;
1851
1852 case IDM_PRINT:
1853 case IDM_VIRUSSCAN:
1854 case IDM_VIEW:
1855 case IDM_MCIPLAY:
1856 case IDM_VIEWARCHIVE:
1857 case IDM_VIEWTEXT:
1858 case IDM_VIEWBINARY:
1859 case IDM_EDIT:
1860 case IDM_EDITTEXT:
1861 case IDM_EDITBINARY:
1862 case IDM_EXEC:
1863 case IDM_EXTRACTWDIRS:
1864 case IDM_EXTRACT:
1865 case IDM_OPENDEFAULT:
1866 case IDM_OPENSETTINGS:
1867 {
1868 CHAR *endofit, *ptr;
1869 PSZ pszCmdLine;
1870 INT z;
1871 if ((li->type == IDM_EXTRACT && !li->info->extract) ||
1872 ((li->type == IDM_VIEW || li->type == IDM_VIEWTEXT ||
1873 li->type == IDM_VIEWBINARY || li->type == IDM_EDIT ||
1874 li->type == IDM_VIEWARCHIVE || li->type == IDM_EDITTEXT ||
1875 li->type == IDM_EDITBINARY || li->type == IDM_MCIPLAY) &&
1876 (!li->info->extract && !li->info->exwdirs)) ||
1877 (li->type != IDM_EXTRACT && li->type != IDM_EDIT &&
1878 li->type != IDM_VIEW && li->type != IDM_VIEWTEXT &&
1879 li->type != IDM_VIEWBINARY &&
1880 li->type != IDM_VIEWARCHIVE &&
1881 li->type != IDM_EDITTEXT &&
1882 li->type != IDM_EDITBINARY &&
1883 li->type != IDM_MCIPLAY && !li->info->exwdirs)) {
1884 Runtime_Error(pszSrcFile, __LINE__, "no cmd for request");
1885 break;
1886 }
1887 if (li->type == IDM_EXTRACT || li->type == IDM_EXTRACTWDIRS) {
1888
1889 CHAR fullname[CCHMAXPATH * 2];
1890 CHAR **exfiles = NULL;
1891 UINT numfiles = 0, numalloc = 0;
1892
1893 if (li->targetpath && fFileNameCnrPath &&
1894 stricmp(lastextractpath, li->targetpath)) {
1895 strcpy(lastextractpath, li->targetpath);
1896 SetDir(dcd->hwndParent, hwnd, li->targetpath, 1);
1897 }
1898 for (x = 0; li->list[x]; x++) {
1899 BldFullPathName(fullname, li->targetpath, li->list[x]);
1900 //Check if file already exists on disk warn if it does.
1901 if (IsFile(fullname) != -1) {
1902 AddToList(li->list[x], &exfiles, &numfiles, &numalloc);
1903 li->list = RemoveFromList(li->list, li->list[x]);
1904 if (!li->list)
1905 break;
1906 x--;
1907 }
1908 }
1909 if (exfiles && numfiles) {
1910
1911 CHECKLIST ckl;
1912 CHAR prompt[(CCHMAXPATH * 2) + 256];
1913
1914 memset(&ckl, 0, sizeof(ckl));
1915 ckl.size = sizeof(ckl);
1916 ckl.list = exfiles;
1917 ckl.prompt = prompt;
1918 ckl.cmd = li->type;
1919 ckl.flags = CHECK_ARCHIVE;
1920 sprintf(prompt,
1921 GetPString(IDS_REPLACEWARNTEXT),
1922 &"s"[numfiles == 1],
1923 li->arcname, &"s"[numfiles != 1], li->targetpath);
1924 if (!WinDlgBox(HWND_DESKTOP, hwnd, CheckListProc,
1925 FM3ModHandle, CHECK_FRAME, MPFROMP(&ckl))) {
1926 if (ckl.list)
1927 FreeList(ckl.list);
1928 break;
1929 }
1930 else if (ckl.list)
1931 li->list = CombineLists(li->list, ckl.list);
1932 } // end check and warn
1933 }
1934 if (!li->list || !li->list[0])
1935 break;
1936 pszCmdLine = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
1937 if (!pszCmdLine)
1938 break;
1939 strcpy(pszCmdLine,
1940 (li->type == IDM_EXTRACT ||
1941 ((li->type == IDM_VIEW ||
1942 li->type == IDM_VIEWTEXT ||
1943 li->type == IDM_VIEWBINARY ||
1944 li->type == IDM_VIEWARCHIVE ||
1945 li->type == IDM_PRINT ||
1946 li->type == IDM_EDIT ||
1947 li->type == IDM_EDITTEXT ||
1948 li->type == IDM_OPENDEFAULT ||
1949 li->type == IDM_OPENSETTINGS ||
1950 (li->type == IDM_EDITBINARY || // JBS No way for this () to be true??
1951 li->type == IDM_MCIPLAY)) ||
1952 !li->info->exwdirs)) ?
1953 li->info->extract :
1954 li->info->exwdirs);
1955 strcat(pszCmdLine, " ");
1956 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->arcname);
1957 endofit = &pszCmdLine[strlen(pszCmdLine)];
1958 z = 0;
1959 do {
1960 for (x = z; li->list[x] &&
1961 strlen(pszCmdLine) + strlen(li->list[x]) < MaxComLineStrg - 1 ; x++) {
1962 strcat(pszCmdLine, " ");
1963 BldQuotedFileName(pszCmdLine + strlen(pszCmdLine), li->list[x]);
1964 ptr = li->list[x];
1965 while (*ptr) {
1966 if (*ptr == '/')
1967 *ptr = '\\';
1968 ptr++;
1969 }
1970 }
1971 z = x;
1972 runemf2(SEPARATE | WINDOWED | WAIT |
1973 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
1974 hwnd, pszSrcFile, __LINE__,
1975 li->targetpath, NULL, "%s", pszCmdLine);
1976 *endofit = 0;
1977 } while (li->list[x]);
1978 if (li->type == IDM_EXTRACT || li->type == IDM_EXTRACTWDIRS) {
1979 // update windows
1980 for (x = 0; li->list[x]; x++) {
1981
1982 CHAR *temp, *p;
1983
1984 temp = li->list[x];
1985 ForwardslashToBackslash(temp);
1986 p = xmalloc(strlen(temp) + strlen(li->targetpath) + 2,
1987 pszSrcFile, __LINE__);
1988 if (p) {
1989 BldFullPathName(p, li->targetpath, temp);
1990 li->list[x] = p;
1991 free(temp);
1992 }
1993 }
1994 if (fFolderAfterExtract) {
1995
1996 CHAR objectpath[CCHMAXPATH], *p;
1997 APIRET rc;
1998
1999 GetDesktopName(objectpath, sizeof(objectpath));
2000 rc = WinDlgBox(HWND_DESKTOP, dcd->hwndParent, ObjCnrDlgProc,
2001 FM3ModHandle, OBJCNR_FRAME,
2002 MPFROMP(objectpath));
2003 if (rc) {
2004 if (rc > 1)
2005 strcpy(objectpath, "<WP_DESKTOP>");
2006 p = NULL;
2007 if (li->arcname) {
2008 p = strrchr(li->arcname, '\\');
2009 if (p)
2010 p++;
2011 }
2012 MakeShadows(dcd->hwndParent, li->list, 2, objectpath, p);
2013 }
2014 }
2015 Broadcast(WinQueryAnchorBlock(hwnd),
2016 hwndMain,
2017 UM_UPDATERECORDLIST, MPFROMP(li->list), MPVOID);
2018 }
2019 else if (li->type == IDM_EXEC)
2020 ExecOnList(hwnd,
2021 li->runfile,
2022 WINDOWED | SEPARATEKEEP | PROMPT,
2023 li->targetpath, NULL, NULL, GetPString(IDS_EXECARCFILETITLETEXT),
2024 pszSrcFile, __LINE__);
2025 else if (li->type == IDM_VIRUSSCAN)
2026 ExecOnList(hwnd, virus, PROMPT | WINDOWED | SEPARATEKEEP,
2027 li->targetpath, NULL, NULL,
2028 GetPString(IDS_VIRUSSCANARCHIVETITLETEXT),
2029 pszSrcFile, __LINE__);
2030 else if (li->type == IDM_VIEW || li->type == IDM_VIEWTEXT ||
2031 li->type == IDM_VIEWBINARY || li->type == IDM_EDIT ||
2032 li->type == IDM_EDITTEXT ||
2033 li->type == IDM_VIEWARCHIVE ||
2034 li->type == IDM_EDITBINARY ||
2035 li->type == IDM_OPENDEFAULT ||
2036 li->type == IDM_OPENSETTINGS ||
2037 li->type == IDM_MCIPLAY || li->type == IDM_PRINT) {
2038
2039 CHAR *temp, *p;
2040 for (x = 0; li->list[x]; x++) {
2041 if (!li->info->exwdirs) {
2042 temp = li->list[x];
2043 p = strrchr(li->list[x], '\\');
2044 if (p) {
2045 p++;
2046 li->list[x] = xstrdup(p, pszSrcFile, __LINE__);
2047 if (!li->list[x])
2048 li->list[x] = temp;
2049 else {
2050 xfree(temp, pszSrcFile, __LINE__);
2051 }
2052 }
2053 }
2054 BldFullPathName(pszCmdLine, li->targetpath, li->list[x]);
2055 temp = li->list[x];
2056 li->list[x] = xstrdup(pszCmdLine, pszSrcFile, __LINE__);
2057 if (!li->list[x])
2058 li->list[x] = temp;
2059 else
2060 xfree(temp, pszSrcFile, __LINE__);
2061 }
2062 free(pszCmdLine);
2063 if (li->type == IDM_VIEW || li->type == IDM_EDIT) {
2064
2065 BOOL isit = TestBinary(li->list[0]);
2066
2067 if (isit) {
2068 if (li->type == IDM_VIEW)
2069 li->type = IDM_VIEWBINARY;
2070 else
2071 li->type = IDM_EDITBINARY;
2072 }
2073 else {
2074 if (li->type == IDM_VIEW)
2075 li->type = IDM_VIEWTEXT;
2076 else
2077 li->type = IDM_EDITTEXT;
2078 }
2079 }
2080 if (li->type == IDM_MCIPLAY) {
2081
2082 FILE *fp;
2083 CHAR szTempFile[CCHMAXPATH];
2084 CHAR *modew = "w";
2085
2086 if (pTmpDir && !IsValidDir(pTmpDir))
2087 DosCreateDir(pTmpDir, 0);
2088 BldFullPathName(szTempFile, pTmpDir, PCSZ_FM2PLAYTEMP);
2089 fp = xfopen(szTempFile, modew, pszSrcFile, __LINE__, FALSE);
2090 if (fp) {
2091 fprintf(fp, "%s", ";AV/2-built FM2Play listfile\n");
2092 for (x = 0; li->list[x]; x++)
2093 fprintf(fp, "%s\n", li->list[x]);
2094 fprintf(fp, ";end\n");
2095 fclose(fp);
2096 strrev(szTempFile);
2097 strcat(szTempFile, "@/");
2098 strrev(szTempFile);
2099 RunFM2Util(PCSZ_FM2PLAYEXE, szTempFile);
2100 }
2101 }
2102 else if (li->type == IDM_PRINT) {
2103 strcpy(li->targetpath, printer);
2104 // 10 Dec 08 SHL correct error handling - looked backward
2105 if (xbeginthread(PrintListThread,
2106 65536,
2107 li,
2108 pszSrcFile,
2109 __LINE__) != -1)
2110 {
2111 li = NULL; // Ensure not freed here
2112 }
2113
2114 }
2115 else if (li->type == IDM_VIEWARCHIVE) {
2116
2117 ARC_TYPE *info;
2118
2119 for (x = 0; li->list[x]; x++) {
2120 if (IsFile(li->list[x]) == 1) {
2121 info = NULL; // Do not hide dups - fixme to know why?
2122 if (WinDlgBox(HWND_DESKTOP, HWND_DESKTOP,
2123 SBoxDlgProc, FM3ModHandle, ASEL_FRAME,
2124 (PVOID) & info) && info) {
2125 StartArcCnr(HWND_DESKTOP,
2126 HWND_DESKTOP, li->list[x], 4, info);
2127 }
2128 }
2129 }
2130 }
2131 else if ((li->type == IDM_VIEWTEXT && *viewer) ||
2132 (li->type == IDM_VIEWBINARY && *binview) ||
2133 (li->type == IDM_EDITTEXT && *editor) ||
2134 (li->type == IDM_EDITBINARY && *bined)) {
2135 //DosSleep(32); // Added WAIT to runemf2 12-12-08 GKY
2136 ExecOnList(hwnd, ((li->type == IDM_VIEWTEXT) ? viewer :
2137 (li->type == IDM_VIEWBINARY) ? binview :
2138 (li->type == IDM_EDITTEXT) ? editor :
2139 bined),
2140 WINDOWED | SEPARATE, NULL, NULL, // li->targetpath,
2141 li->list,
2142 NULL, pszSrcFile, __LINE__);
2143 }
2144 else if (li->type == IDM_OPENDEFAULT ||
2145 li->type == IDM_OPENSETTINGS) {
2146 WORKER *wk;
2147# ifdef FORTIFY
2148 Fortify_EnterScope();
2149# endif
2150 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
2151 if (!wk)
2152 FreeListInfo(li);
2153 else {
2154 wk->size = sizeof(WORKER);
2155 wk->hwndCnr = dcd->hwndCnr;
2156 wk->hwndParent = dcd->hwndParent;
2157 wk->hwndFrame = dcd->hwndFrame;
2158 wk->hwndClient = dcd->hwndClient;
2159 wk->li = li;
2160 strcpy(wk->directory, dcd->directory);
2161 if (xbeginthread(Action,
2162 122880,
2163 wk,
2164 pszSrcFile,
2165 __LINE__) == -1)
2166 {
2167 free(wk);
2168 FreeListInfo((LISTINFO *) mp1);
2169 }
2170 }
2171# ifdef FORTIFY
2172 Fortify_LeaveScope();
2173# endif
2174 }
2175 else {
2176 if (li->hwnd) {
2177
2178 ULONG viewtype;
2179
2180 for (x = 0; li->list[x]; x++) {
2181 if (x == 0) {
2182 if (li->type == IDM_VIEWBINARY ||
2183 li->type == IDM_EDITBINARY)
2184 viewtype = 16;
2185 else
2186 viewtype = 8;
2187 }
2188 else
2189 viewtype = 0;
2190# ifdef FORTIFY
2191 Fortify_EnterScope();
2192# endif
2193 temp = xstrdup(li->list[x], pszSrcFile, __LINE__);
2194 if (temp) {
2195 if (!PostMsg(WinQueryWindow(li->hwnd, QW_PARENT),
2196 UM_LOADFILE,
2197 MPFROMLONG(4L +
2198 (li->type == IDM_VIEWTEXT ||
2199 li->type == IDM_VIEWBINARY) +
2200 viewtype), MPFROMP(temp)))
2201 free(temp);
2202 }
2203# ifdef FORTIFY
2204 DosSleep(1); // Allow MassAction to take ownership
2205 Fortify_LeaveScope();
2206# endif
2207 }
2208 }
2209 }
2210 }
2211 }
2212 break;
2213
2214 case IDM_FIND:
2215 {
2216 UINT numfiles = 0, numalloced = 0;
2217 CHAR **list2 = NULL, fullname[CCHMAXPATH * 2], *p;
2218
2219 for (x = 0; li->list[x]; x++) {
2220 ForwardslashToBackslash(li->list[x]);
2221 BldFullPathName(fullname, dcd->directory, li->list[x]);
2222 if (IsFile(fullname) != -1)
2223 if (AddToList(fullname, &list2, &numfiles, &numalloced))
2224 break;
2225 if (strchr(li->list[x], '\\')) {
2226 p = strrchr(li->list[x], '\\');
2227 if (p) {
2228 p++;
2229 if (*p) {
2230 BldFullPathName(fullname, dcd->directory, p);
2231 if (IsFile(fullname) != -1)
2232 if (AddToList(fullname, &list2, &numfiles, &numalloced))
2233 break;
2234 }
2235 }
2236 }
2237 }
2238 if (!numfiles || !list2)
2239 Runtime_Error(pszSrcFile, __LINE__, "no files or list");
2240 else {
2241 WinSendMsg(dcd->hwndCnr, WM_COMMAND,
2242 MPFROM2SHORT(IDM_COLLECTOR, 0), MPVOID);
2243 DosSleep(10); //05 Aug 07 GKY 128
2244 if (Collector) {
2245 if (!PostMsg(Collector, WM_COMMAND,
2246 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(list2)))
2247 FreeList(list2);
2248 }
2249 else
2250 FreeList(list2);
2251 }
2252 }
2253 break;
2254 } // switch
2255 }
2256 if (li && li->type != IDM_OPENDEFAULT && li->type != IDM_OPENSETTINGS)
2257 {
2258 FreeListInfo(li);
2259 }
2260 }
2261 return 0;
2262
2263 case WM_CLOSE:
2264 WinDestroyWindow(hwnd);
2265 break;
2266
2267 case WM_DESTROY:
2268 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
2269 if (dcd) {
2270 if (*dcd->workdir) {
2271 DosSleep(16); //05 Aug 07 GKY 33
2272 wipeallf(TRUE, "%s\\*", dcd->workdir);
2273 if (rmdir(dcd->workdir)) {
2274 DosSleep(100); //05 Aug 07 GKY 256
2275 wipeallf(TRUE, "%s\\*", dcd->workdir);
2276 rmdir(dcd->workdir);
2277 }
2278 }
2279 FreeList(dcd->lastselection);
2280 WinSendMsg(dcd->hwndCnr, UM_CLOSE, MPVOID, MPVOID);
2281 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); // 13 Apr 10 SHL Set NULL before freeing dcd
2282 free(dcd);
2283# ifdef FORTIFY
2284 Fortify_LeaveScope();
2285# endif
2286 }
2287 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
2288 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
2289 break;
2290 } // switch
2291 return WinDefWindowProc(hwnd, msg, mp1, mp2);
2292}
2293
2294static MRESULT EXPENTRY ArcCnrWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
2295 MPARAM mp2)
2296{
2297 DIRCNRDATA *dcd = INSTDATA(hwnd);
2298 CHAR szQuotedArcName[CCHMAXPATH];
2299
2300 switch (msg) {
2301 case DM_PRINTOBJECT:
2302 case DM_DISCARDOBJECT:
2303 if (dcd)
2304 return WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
2305 else
2306 return MRFROMLONG(DRR_TARGET);
2307
2308 case WM_CHAR:
2309 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
2310 if (SHORT1FROMMP(mp1) & KC_KEYUP)
2311 return (MRESULT)TRUE;
2312 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
2313 switch (SHORT2FROMMP(mp2)) {
2314 case VK_DELETE:
2315 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DELETE, 0), MPVOID);
2316 break;
2317 }
2318 }
2319
2320 if (SearchContainer(hwnd, msg, mp1, mp2))
2321 return (MRESULT)TRUE; // Avoid default handler
2322 break; // Let default handler see key too
2323
2324 case WM_MOUSEMOVE:
2325 case WM_BUTTON1UP:
2326 case WM_BUTTON2UP:
2327 case WM_BUTTON3UP:
2328 case WM_CHORD:
2329 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
2330 break;
2331
2332 case WM_BUTTON1MOTIONEND:
2333 {
2334 CNRINFO cnri;
2335
2336 memset(&cnri, 0, sizeof(CNRINFO));
2337 cnri.cb = sizeof(CNRINFO);
2338 if (WinSendMsg(hwnd,
2339 CM_QUERYCNRINFO,
2340 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)))) {
2341 if (cnri.flWindowAttr & CV_DETAIL)
2342 PrfWriteProfileData(fmprof,
2343 appname,
2344 "ArcCnrSplitBar",
2345 (PVOID) & cnri.xVertSplitbar, sizeof(LONG));
2346 }
2347 }
2348 break;
2349
2350 case WM_PRESPARAMCHANGED:
2351 PresParamChanged(hwnd, PCSZ_ARCCNR, mp1, mp2);
2352 break;
2353
2354 case UM_UPDATERECORD:
2355 case UM_UPDATERECORDLIST:
2356 if (dcd && !IsArcThere(hwnd, dcd->arcname))
2357 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2358 return 0;
2359
2360 case WM_SETFOCUS:
2361 /**
2362 * put name of our window (archive name) on status line
2363 */
2364 if (dcd && hwndStatus && mp2)
2365 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2366 break;
2367
2368 case UM_SETUP2:
2369 if (dcd && dcd->info) {
2370 if (dcd->info->fdpos == -1 || !dcd->info->datetype)
2371 dcd->sortFlags &= (~SORT_LWDATE);
2372 if (dcd->info->nsizepos == -1)
2373 dcd->sortFlags &= (~SORT_EASIZE);
2374 if (dcd->info->osizepos == -1)
2375 dcd->sortFlags &= (~SORT_SIZE);
2376 AdjustCnrColVis(hwnd,
2377 GetPString(IDS_OLDSIZECOLTEXT),
2378 dcd->info->osizepos != -1, FALSE);
2379 AdjustCnrColVis(hwnd,
2380 GetPString(IDS_NEWSIZECOLTEXT),
2381 dcd->info->nsizepos != -1, FALSE);
2382 // Display unsullied date/time string if type 0
2383 AdjustCnrColVis(hwnd,
2384 GetPString(IDS_DATETIMECOLTEXT),
2385 dcd->info->fdpos != -1 && !dcd->info->datetype, FALSE);
2386 // Display parsed date/time columns if type specified
2387 AdjustCnrColVis(hwnd,
2388 GetPString(IDS_TIMECOLTEXT),
2389 dcd->info->fdpos != -1 && dcd->info->datetype, FALSE);
2390 AdjustCnrColVis(hwnd,
2391 GetPString(IDS_DATECOLTEXT),
2392 dcd->info->fdpos != -1 && dcd->info->datetype, FALSE);
2393 WinSendMsg(hwnd, CM_INVALIDATEDETAILFIELDINFO, MPVOID, MPVOID);
2394 }
2395 return 0;
2396
2397 case UM_RESCAN:
2398 if (dcd) {
2399 CNRINFO cnri;
2400 CHAR s[CCHMAXPATH * 2], tb[81], tf[81];
2401 PARCITEM pci;
2402
2403 if (mp1) {
2404 PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID);
2405 return 0;
2406 }
2407 memset(&cnri, 0, sizeof(CNRINFO));
2408 cnri.cb = sizeof(CNRINFO);
2409 WinSendMsg(hwnd,
2410 CM_QUERYCNRINFO,
2411 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
2412 dcd->totalfiles = cnri.cRecords;
2413 commafmt(tf, sizeof(tf), dcd->selectedfiles);
2414 if (dcd->ullTotalBytes)
2415 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, 'K');
2416 else
2417 *tb = 0;
2418 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
2419 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
2420 commafmt(tf, sizeof(tf), dcd->totalfiles);
2421 if (dcd->ullTotalBytes)
2422 CommaFmtULL(tb, sizeof(tb), dcd->ullTotalBytes, 'K');
2423 else
2424 *tb = 0;
2425 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
2426 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, s);
2427 if (hwndStatus &&
2428 dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
2429 sprintf(s, " [%s%s%s]%s%s%s %s",
2430 tf,
2431 *tb ? " / " : NullStr,
2432 tb,
2433 *dcd->mask.szMask ? " (" : NullStr,
2434 *dcd->mask.szMask ? dcd->mask.szMask : NullStr,
2435 *dcd->mask.szMask ? ")" : NullStr, dcd->arcname);
2436 WinSetWindowText(hwndStatus, s);
2437 if (!ParentIsDesktop(hwnd, dcd->hwndParent)) {
2438 pci = WinSendMsg(hwnd,
2439 CM_QUERYRECORDEMPHASIS,
2440 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
2441 if (pci && (INT) pci != -1) {
2442 if (fSplitStatus && hwndStatus2) {
2443 if (dcd->ullTotalBytes)
2444 CommaFmtULL(tb, sizeof(tb), pci->cbFile, ' ');
2445 else
2446 *tb = 0;
2447 sprintf(s, "%s%s%s%s",
2448 *tb ? " " : NullStr,
2449 tb, *tb ? " " : NullStr, pci->pszFileName);
2450 WinSetWindowText(hwndStatus2, s);
2451 }
2452 if (fMoreButtons)
2453 WinSetWindowText(hwndName, pci->pszFileName);
2454 }
2455 else {
2456 WinSetWindowText(hwndStatus2, NullStr);
2457 WinSetWindowText(hwndName, NullStr);
2458 }
2459 WinSetWindowText(hwndDate, NullStr);
2460 WinSetWindowText(hwndAttr, NullStr);
2461 }
2462 }
2463 if ((dcd->arcfilled && !dcd->totalfiles) ||
2464 !IsArcThere(hwnd, dcd->arcname))
2465 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2466 }
2467 return 0;
2468
2469 case UM_SETUP:
2470 if (!dcd) {
2471 Runtime_Error(pszSrcFile, __LINE__, NULL);
2472 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2473 return 0;
2474 }
2475 else {
2476 if (!dcd->hwndObject) {
2477 /**
2478 * first time through -- set things up
2479 */
2480 {
2481 CHAR *p;
2482 ULONG z, was;
2483 APIRET rc;
2484
2485 rc = DosCreateDir(dcd->workdir, 0);
2486 if (rc) {
2487 if (rc == ERROR_ACCESS_DENIED) {
2488 p = strrchr(dcd->workdir, '.');
2489 if (p) { /* jbs: What if there is no "."? Give up? */
2490 p++;
2491 was = strtoul(p, NULL, 16);
2492 for (z = 0; z < 99; z++) {
2493 was++;
2494 sprintf(p, "%03x", was);
2495 rc = DosCreateDir(dcd->workdir, 0);
2496 if (!rc || rc != ERROR_ACCESS_DENIED)
2497 break;
2498 }
2499 }
2500 }
2501 if (rc) {
2502 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2503 return 0;
2504 }
2505 }
2506 }
2507 RestorePresParams(hwnd, PCSZ_ARCCNR);
2508 dcd->mask.fNoAttribs = TRUE;
2509 dcd->mask.fNoDirs = TRUE;
2510 *dcd->mask.prompt = 0;
2511 {
2512 PFIELDINFO pfi, pfiLastLeftCol;
2513 ULONG numcols = CON_COLS;
2514 CNRINFO cnri;
2515 ULONG size;
2516
2517 pfi = WinSendMsg(hwnd,
2518 CM_ALLOCDETAILFIELDINFO,
2519 MPFROMLONG(numcols), NULL);
2520 if (pfi) {
2521
2522 PFIELDINFO pfiFirst;
2523 FIELDINFOINSERT fii;
2524
2525 pfiFirst = pfi;
2526 pfi->flData = CFA_STRING | CFA_LEFT | CFA_FIREADONLY;
2527 pfi->flTitle = CFA_CENTER;
2528 pfi->pTitleData = (PSZ)GetPString(IDS_FILENAMECOLTEXT);
2529 pfi->offStruct = FIELDOFFSET(ARCITEM, pszDisplayName);
2530 pfiLastLeftCol = pfi;
2531 pfi = pfi->pNextFieldInfo;
2532 pfi->flData =
2533 CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
2534 pfi->flTitle = CFA_CENTER;
2535 pfi->pTitleData = (PSZ)GetPString(IDS_OLDSIZECOLTEXT);
2536 pfi->offStruct = FIELDOFFSET(ARCITEM, cbFile);
2537 pfi = pfi->pNextFieldInfo;
2538 pfi->flData =
2539 CFA_ULONG | CFA_RIGHT | CFA_SEPARATOR | CFA_FIREADONLY;
2540 pfi->flTitle = CFA_CENTER;
2541 pfi->pTitleData = (PSZ)GetPString(IDS_NEWSIZECOLTEXT);
2542 pfi->offStruct = FIELDOFFSET(ARCITEM, cbComp);
2543 pfi = pfi->pNextFieldInfo;
2544 pfi->flData =
2545 CFA_STRING | CFA_CENTER | CFA_SEPARATOR | CFA_FIREADONLY;
2546 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
2547 pfi->pTitleData = (PSZ)GetPString(IDS_DATETIMECOLTEXT);
2548 pfi->offStruct = FIELDOFFSET(ARCITEM, pszDate);
2549 pfi = pfi->pNextFieldInfo;
2550 pfi->flData = CFA_DATE | CFA_RIGHT | CFA_FIREADONLY;
2551 pfi->flTitle = CFA_CENTER;
2552 pfi->pTitleData = (PSZ)GetPString(IDS_DATECOLTEXT);
2553 pfi->offStruct = FIELDOFFSET(ARCITEM, date);
2554 pfi = pfi->pNextFieldInfo;
2555 pfi->flData = CFA_TIME | CFA_RIGHT | CFA_FIREADONLY;
2556 pfi->flTitle = CFA_CENTER | CFA_FITITLEREADONLY;
2557 pfi->pTitleData = (PSZ)GetPString(IDS_TIMECOLTEXT);
2558 pfi->offStruct = FIELDOFFSET(ARCITEM, time);
2559 memset(&fii, 0, sizeof(FIELDINFOINSERT));
2560 fii.cb = sizeof(FIELDINFOINSERT);
2561 fii.pFieldInfoOrder = (PFIELDINFO) CMA_FIRST;
2562 fii.cFieldInfoInsert = (SHORT) numcols;
2563 fii.fInvalidateFieldInfo = TRUE;
2564 WinSendMsg(hwnd,
2565 CM_INSERTDETAILFIELDINFO,
2566 MPFROMP(pfiFirst), MPFROMP(&fii));
2567 PostMsg(hwnd, UM_SETUP2, MPVOID, MPVOID);
2568
2569 memset(&cnri, 0, sizeof(cnri));
2570 cnri.cb = sizeof(CNRINFO);
2571 cnri.pFieldInfoLast = pfiLastLeftCol;
2572 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET + 32;
2573
2574 size = sizeof(LONG);
2575 PrfQueryProfileData(fmprof, appname, "ArcCnrSplitBar",
2576 &cnri.xVertSplitbar, &size);
2577 if (cnri.xVertSplitbar <= 0)
2578 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET + 32;
2579
2580 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT | CV_NAME));
2581 cnri.flWindowAttr |= (CV_DETAIL | CA_DETAILSVIEWTITLES | CV_FLOW);
2582 cnri.flWindowAttr &= (~(CA_ORDEREDTARGETEMPH |
2583 CA_MIXEDTARGETEMPH));
2584 cnri.pSortRecord = (PVOID) ArcSort;
2585 WinSendMsg(hwnd,
2586 CM_SETCNRINFO,
2587 MPFROMP(&cnri),
2588 MPFROMLONG(CMA_PFIELDINFOLAST |
2589 CMA_XVERTSPLITBAR |
2590 CMA_PSORTRECORD | CMA_FLWINDOWATTR));
2591 }
2592 }
2593 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
2594 if (xbeginthread(MakeObjWin,
2595 245760,
2596 dcd,
2597 pszSrcFile,
2598 __LINE__) == -1)
2599 {
2600 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2601 return 0;
2602 }
2603 else
2604 DosSleep(1);
2605 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2606 DIR_FILTER), &dcd->mask, TRUE);
2607 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2608 DIR_SORT), dcd->sortFlags, TRUE);
2609 DefArcSortFlags = dcd->sortFlags; // Remember for new windows
2610 }
2611 }
2612 return 0;
2613
2614 case UM_SETDIR:
2615 if (dcd) {
2616
2617 CHAR s[CCHMAXPATH], *p;
2618 ULONG ret = 0;
2619
2620 WinQueryDlgItemText(dcd->hwndClient, ARC_EXTRACTDIR, CCHMAXPATH, s);
2621 bstrip(s);
2622 MakeFullName(s);
2623 if (*s) {
2624 while ((p = strchr(s, '/')) != NULL)
2625 *p = '\\';
2626 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
2627 s[strlen(s) - 1] = 0;
2628 if (stricmp(s, dcd->directory)) {
2629 if (IsFullName(s)) {
2630 if (driveflags[toupper(*s) - 'A'] &
2631 (DRIVE_NOTWRITEABLE | DRIVE_IGNORE | DRIVE_INVALID)) {
2632 Runtime_Error(pszSrcFile, __LINE__, "drive %s bad", s);
2633 WinSetDlgItemText(dcd->hwndClient,
2634 ARC_EXTRACTDIR, dcd->directory);
2635 return 0;
2636 }
2637 }
2638 if (!SetDir(dcd->hwndParent, hwnd, s, 0)) {
2639 if (stricmp(dcd->directory, s)) {
2640 //DosEnterCritSec(); //GKY 11-29-08
2641 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
2642 strcpy(lastextractpath, s);
2643 DosReleaseMutexSem(hmtxFM2Globals);
2644 //DosExitCritSec();
2645 }
2646 strcpy(dcd->directory, s);
2647 if ((!isalpha(*s) || s[1] != ':') && *s != '.')
2648 saymsg(MB_ENTER | MB_ICONASTERISK,
2649 hwnd,
2650 GetPString(IDS_WARNINGTEXT),
2651 GetPString(IDS_SPECIFYDRIVETEXT));
2652 }
2653 else
2654 ret = 1;
2655 }
2656 }
2657 WinSetDlgItemText(dcd->hwndClient, ARC_EXTRACTDIR, dcd->directory);
2658 return (MRESULT) ret;
2659 }
2660 return 0;
2661
2662 case UM_ENTER:
2663 if (WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID)) {
2664 free(mp1);
2665 return 0;
2666 }
2667 SetShiftState();
2668 if (dcd && (CHAR *) mp1) {
2669
2670 SWP swp;
2671 CHAR *filename = mp1;
2672 //printf("%s %d UM_ENTER %s\n",__FILE__, __LINE__, filename); fflush(stdout);
2673 if (IsFile(filename) != 1) {
2674 free(mp1);
2675 return 0;
2676 }
2677 WinQueryWindowPos(dcd->hwndFrame, &swp);
2678 DefaultViewKeys(hwnd, dcd->hwndFrame, dcd->hwndParent, &swp, filename);
2679 if (fUnHilite)
2680 UnHilite(hwnd, FALSE, &dcd->lastselection, 0);
2681 }
2682 free(mp1);
2683 return 0;
2684
2685 case WM_MENUEND:
2686 if (dcd) {
2687
2688 HWND hwndMenu = (HWND) mp2;
2689
2690 if (hwndMenu == ArcCnrMenu || hwndMenu == ArcMenu) {
2691 MarkAll(hwnd, TRUE, FALSE, TRUE);
2692 if (dcd->cnremphasized) {
2693 WinSendMsg(hwnd,
2694 CM_SETRECORDEMPHASIS,
2695 MPVOID, MPFROM2SHORT(FALSE, CRA_SOURCE));
2696 dcd->cnremphasized = FALSE;
2697 }
2698 }
2699 }
2700 break;
2701
2702 case MM_PORTHOLEINIT:
2703 if (dcd) {
2704 switch (SHORT1FROMMP(mp1)) {
2705 case 0:
2706 case 1:
2707 {
2708 ULONG wmsg;
2709
2710 wmsg = SHORT1FROMMP(mp1) == 0 ? UM_FILESMENU : UM_VIEWSMENU;
2711 PortholeInit((HWND) WinSendMsg(dcd->hwndClient,
2712 wmsg, MPVOID, MPVOID), mp1, mp2);
2713 }
2714 break;
2715 }
2716 }
2717 break;
2718
2719 case UM_INITMENU:
2720 case WM_INITMENU:
2721 if (dcd) {
2722 switch (SHORT1FROMMP(mp1)) {
2723 case IDM_FILESMENU:
2724 if (dcd->info) {
2725 WinEnableMenuItem((HWND) mp2,
2726 IDM_DELETE, dcd->info->delete != NULL);
2727 WinEnableMenuItem((HWND) mp2, IDM_TEST, dcd->info->test != NULL);
2728 WinEnableMenuItem((HWND) mp2, IDM_EXTRACT,
2729 dcd->info->extract != NULL && !strstr(dcd->info->ext, "TAR"));
2730 WinEnableMenuItem((HWND) mp2, IDM_ARCEXTRACT,
2731 dcd->info->extract != NULL && !strstr(dcd->info->ext, "TAR"));
2732 WinEnableMenuItem((HWND) mp2,
2733 IDM_EXTRACTWDIRS, dcd->info->exwdirs != NULL);
2734 WinEnableMenuItem((HWND) mp2,
2735 IDM_ARCEXTRACTWDIRS, dcd->info->exwdirs != NULL);
2736 WinEnableMenuItem((HWND) mp2,
2737 IDM_ARCEXTRACTWDIRSEXIT,
2738 dcd->info->exwdirs != NULL);
2739 }
2740 break;
2741
2742 case IDM_VIEWSMENU:
2743 WinEnableMenuItem((HWND) mp2, IDM_TEST, dcd->info->test != NULL);
2744 WinEnableMenuItem((HWND) mp2, IDM_ARCEXTRACT,
2745 dcd->info->extract != NULL && !strstr(dcd->info->ext, "TAR"));
2746 WinCheckMenuItem((HWND) mp2,
2747 IDM_MINIICONS, (dcd->flWindowAttr & CV_MINI) != 0);
2748 WinEnableMenuItem((HWND) mp2,
2749 IDM_RESELECT, (dcd->lastselection != NULL));
2750 break;
2751
2752 case IDM_COMMANDSMENU:
2753 SetupCommandMenu((HWND) mp2, hwnd);
2754 break;
2755
2756 case IDM_SORTSUBMENU:
2757 SetSortChecks((HWND) mp2, dcd->sortFlags);
2758 break;
2759
2760 case IDM_WINDOWSMENU:
2761 /**
2762 * add switchlist entries to end of pulldown menu
2763 */
2764 SetupWinList((HWND)mp2,
2765 hwndMain ? hwndMain : (HWND)0, dcd->hwndFrame);
2766 break;
2767 }
2768 dcd->hwndLastMenu = (HWND) mp2;
2769 }
2770 if (msg == WM_INITMENU)
2771 break;
2772 return 0;
2773
2774 case UM_LOADFILE:
2775 if (dcd && mp2) {
2776
2777 HWND hwnd;
2778
2779 if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21)
2780 hwnd = StartViewer(HWND_DESKTOP, (INT)mp1,
2781 (CHAR *)mp2, dcd->hwndFrame);
2782 else
2783 hwnd = StartMLEEditor(dcd->hwndParent,
2784 (INT)mp1, (CHAR *)mp2, dcd->hwndFrame);
2785 free((CHAR *)mp2);
2786 return MRFROMLONG(hwnd);
2787 }
2788 return 0;
2789
2790 case UM_COMMAND:
2791 if (mp1) {
2792 if (dcd) {
2793 if (!PostMsg(dcd->hwndObject, UM_COMMAND, mp1, mp2)) {
2794 Runtime_Error(pszSrcFile, __LINE__, "post");
2795 FreeListInfo((LISTINFO *) mp1);
2796 }
2797 else
2798 return (MRESULT) TRUE;
2799 }
2800 else
2801 FreeListInfo((LISTINFO *) mp1);
2802 }
2803 return 0;
2804
2805 case UM_OPENWINDOWFORME:
2806 if (dcd) {
2807 if (mp1 && !IsFile((CHAR *) mp1)) {
2808 OpenDirCnr((HWND) 0, hwndMain, dcd->hwndFrame, FALSE, (char *)mp1);
2809 }
2810 else if (mp1 && IsFile(mp1) == 1 &&
2811 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
2812 StartArcCnr(HWND_DESKTOP,
2813 dcd->hwndFrame, (CHAR *) mp1, 4, (ARC_TYPE *) mp2);
2814 }
2815 }
2816 return 0;
2817
2818 case WM_COMMAND:
2819 DosError(FERR_DISABLEHARDERR);
2820 if (dcd) {
2821 if (SwitchCommand(dcd->hwndLastMenu, SHORT1FROMMP(mp1)))
2822 return 0;
2823 if (WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID))
2824 return 0;
2825 if (!IsArcThere(hwnd, dcd->arcname)) {
2826 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
2827 return 0;
2828 }
2829 switch (SHORT1FROMMP(mp1)) {
2830 case IDM_TREEVIEW:
2831
2832 break;
2833
2834 case IDM_CONTEXTMENU:
2835 {
2836 PCNRITEM pci;
2837
2838 pci = (PCNRITEM) CurrentRecord(hwnd);
2839 PostMsg(hwnd,
2840 WM_CONTROL,
2841 MPFROM2SHORT(ARC_CNR, CN_CONTEXTMENU), MPFROMP(pci));
2842 }
2843 break;
2844
2845 case IDM_NEXTWINDOW:
2846 case IDM_PREVWINDOW:
2847 {
2848 HWND hwndActive;
2849
2850 hwndActive = WinQueryFocus(HWND_DESKTOP);
2851 WinSetFocus(HWND_DESKTOP,
2852 hwndActive == hwnd ?
2853 WinWindowFromID(dcd->hwndClient, ARC_EXTRACTDIR) :
2854 hwnd);
2855 }
2856 break;
2857
2858 case IDM_FOLDERAFTEREXTRACT:
2859 fFolderAfterExtract = fFolderAfterExtract ? FALSE : TRUE;
2860 PrfWriteProfileData(fmprof, appname, "FolderAfterExtract",
2861 &fFolderAfterExtract, sizeof(BOOL));
2862 break;
2863
2864 case IDM_SHOWSELECT:
2865 QuickPopup(hwnd, dcd, CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP),
2866 IDM_SELECTSUBMENU);
2867 break;
2868
2869 case IDM_SHOWSORT:
2870 QuickPopup(hwnd, dcd, CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP),
2871 IDM_SORTSUBMENU);
2872 break;
2873
2874 case IDM_ARCHIVERSETTINGS:
2875 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndParent))
2876 PostMsg(dcd->hwndParent, msg, MPFROMLONG(IDM_ARCHIVERSETTINGS), mp2);
2877 else {
2878 WinDlgBox(HWND_DESKTOP,
2879 hwnd,
2880 CfgDlgProc,
2881 FM3ModHandle,
2882 CFG_FRAME,
2883 MPFROMLONG(IDM_ARCHIVERSETTINGS));
2884 }
2885 break;
2886
2887 case IDM_RESCAN:
2888 dcd->ullTotalBytes = dcd->totalfiles =
2889 dcd->selectedfiles = dcd->selectedbytes = 0;
2890 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, "0");
2891 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, "0 / 0k");
2892 dcd->totalfiles = FillArcCnr(dcd->hwndCnr,
2893 dcd->arcname,
2894 &dcd->info,
2895 &dcd->ullTotalBytes, &dcd->stopflag);
2896 PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
2897 PostMsg(dcd->hwndCnr, UM_SETUP2, MPVOID, MPVOID);
2898 WinSendMsg(dcd->hwndCnr,
2899 CM_INVALIDATERECORD,
2900 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
2901 break;
2902
2903 case IDM_RESELECT:
2904 SelectList(hwnd, TRUE, FALSE, FALSE, NULL, NULL, dcd->lastselection);
2905 break;
2906
2907 case IDM_HELP:
2908 if (hwndHelp)
2909 WinSendMsg(hwndHelp,
2910 HM_DISPLAY_HELP,
2911 MPFROM2SHORT(HELP_ARCLIST, 0),
2912 MPFROMSHORT(HM_RESOURCEID));
2913 break;
2914
2915 case IDM_WINDOWDLG:
2916 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndFrame))
2917 PostMsg(dcd->hwndParent,
2918 UM_COMMAND, MPFROM2SHORT(IDM_WINDOWDLG, 0), MPVOID);
2919 break;
2920
2921 case IDM_SELECTALL:
2922 case IDM_SELECTALLFILES:
2923 case IDM_DESELECTALL:
2924 case IDM_DESELECTALLFILES:
2925 case IDM_SELECTMASK:
2926 case IDM_DESELECTMASK:
2927 case IDM_INVERT:
2928 {
2929 PARCITEM pci;
2930
2931 pci = (PARCITEM) WinSendMsg(hwnd,
2932 CM_QUERYRECORDEMPHASIS,
2933 MPFROMLONG(CMA_FIRST),
2934 MPFROMSHORT(CRA_CURSORED));
2935 if ((INT) pci == -1)
2936 pci = NULL;
2937 if (SHORT1FROMMP(mp1) == IDM_HIDEALL) {
2938 if (pci) {
2939 if (!(pci->rc.flRecordAttr & CRA_SELECTED))
2940 pci->rc.flRecordAttr |= CRA_FILTERED;
2941 WinSendMsg(hwnd,
2942 CM_INVALIDATERECORD,
2943 MPFROMP(&pci),
2944 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2945 break;
2946 }
2947 }
2948 PostMsg(dcd->hwndObject, UM_SELECT, mp1, MPFROMP(pci));
2949 }
2950 break;
2951
2952 case IDM_SORTSMARTNAME:
2953 case IDM_SORTNAME:
2954 case IDM_SORTFILENAME:
2955 case IDM_SORTSIZE:
2956 case IDM_SORTEASIZE:
2957 case IDM_SORTFIRST:
2958 case IDM_SORTLAST:
2959 case IDM_SORTLWDATE:
2960 dcd->sortFlags &= SORT_REVERSE;
2961 // intentional fallthru
2962 case IDM_SORTREVERSE:
2963 switch (SHORT1FROMMP(mp1)) {
2964 case IDM_SORTSMARTNAME:
2965 case IDM_SORTFILENAME:
2966 dcd->sortFlags |= SORT_FILENAME;
2967 break;
2968 case IDM_SORTSIZE:
2969 dcd->sortFlags |= SORT_SIZE;
2970 break;
2971 case IDM_SORTEASIZE:
2972 dcd->sortFlags |= SORT_EASIZE;
2973 break;
2974 case IDM_SORTFIRST:
2975 dcd->sortFlags |= SORT_FIRSTEXTENSION;
2976 break;
2977 case IDM_SORTLAST:
2978 dcd->sortFlags |= SORT_LASTEXTENSION;
2979 break;
2980 case IDM_SORTLWDATE:
2981 dcd->sortFlags |= SORT_LWDATE;
2982 break;
2983 case IDM_SORTREVERSE:
2984 if (dcd->sortFlags & SORT_REVERSE)
2985 dcd->sortFlags &= (~SORT_REVERSE);
2986 else
2987 dcd->sortFlags |= SORT_REVERSE;
2988 break;
2989 }
2990 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
2991 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2992 DIR_SORT), dcd->sortFlags, TRUE);
2993 DefArcSortFlags = dcd->sortFlags; // Remember for new windows
2994 break;
2995
2996 case IDM_COLLECTOR:
2997 if (!Collector) {
2998 HWND hwndC;
2999 SWP swp;
3000
3001 if (ParentIsDesktop(hwnd, dcd->hwndParent) && !fAutoTile &&
3002 (!fExternalCollector && !strcmp(realappname, FM3Str)))
3003 GetNextWindowPos(dcd->hwndParent, &swp, NULL, NULL);
3004 hwndC = StartCollector(fExternalCollector ||
3005 strcmp(realappname, FM3Str) ?
3006 HWND_DESKTOP : dcd->hwndParent, 4);
3007 if (hwndC) {
3008 if (!ParentIsDesktop(hwnd, dcd->hwndParent) && !fAutoTile &&
3009 (!fExternalCollector && !strcmp(realappname, FM3Str)))
3010 WinSetWindowPos(hwndC,
3011 HWND_TOP,
3012 swp.x,
3013 swp.y,
3014 swp.cx,
3015 swp.cy,
3016 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
3017 else if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3018 fAutoTile && !strcmp(realappname, FM3Str)) {
3019 TileChildren(dcd->hwndParent, TRUE);
3020 }
3021 WinSetWindowPos(hwndC, HWND_TOP, 0, 0, 0, 0, SWP_ACTIVATE);
3022 DosSleep(100); //05 Aug 07 GKY 128
3023 }
3024 }
3025 else
3026 StartCollector(dcd->hwndParent, 4);
3027 break;
3028
3029 case IDM_ARCEXTRACTEXIT:
3030 case IDM_ARCEXTRACT:
3031 if (dcd->directory && fFileNameCnrPath &&
3032 stricmp(lastextractpath, dcd->directory)) {
3033 strcpy(lastextractpath, dcd->directory);
3034 //DbgMsg(pszSrcFile, __LINE__, "Extract dir %s", dcd->directory);
3035 SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
3036 }
3037 if (dcd->info->extract)
3038 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
3039 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
3040 hwnd, pszSrcFile, __LINE__,
3041 dcd->directory, NULL, "%s %s", dcd->info->extract,
3042 BldQuotedFileName(szQuotedArcName, dcd->arcname));
3043 if (SHORT1FROMMP(mp1) == IDM_ARCEXTRACTEXIT)
3044 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
3045 break;
3046
3047 case IDM_ARCEXTRACTWDIRSEXIT:
3048 case IDM_ARCEXTRACTWDIRS:
3049 if (dcd->directory && fFileNameCnrPath &&
3050 stricmp(lastextractpath, dcd->directory)) {
3051 strcpy(lastextractpath, dcd->directory);
3052 SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
3053 }
3054 if (dcd->info->exwdirs)
3055 runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
3056 (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
3057 hwnd, pszSrcFile, __LINE__,
3058 dcd->directory, NULL, "%s %s",
3059 dcd->info->exwdirs,
3060 BldQuotedFileName(szQuotedArcName, dcd->arcname));
3061 if (SHORT1FROMMP(mp1) == IDM_ARCEXTRACTWDIRSEXIT)
3062 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
3063 break;
3064
3065 case IDM_RESORT:
3066 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
3067 break;
3068
3069 case IDM_FILTER:
3070 {
3071 BOOL empty = FALSE;
3072 PARCITEM pci;
3073
3074 if (!*dcd->mask.szMask) {
3075 empty = TRUE;
3076 pci = (PARCITEM) CurrentRecord(hwnd);
3077 if (pci && (INT) pci != -1 && strchr(pci->pszFileName, '.'))
3078 strcpy(dcd->mask.szMask, pci->pszFileName);
3079 }
3080
3081 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
3082 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask))) {
3083 WinSendMsg(hwnd, CM_FILTER, MPFROMP(ArcFilter), MPFROMP(dcd));
3084 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3085 }
3086 else if (empty)
3087 *dcd->mask.szMask = 0;
3088 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
3089 DIR_FILTER), &dcd->mask, TRUE);
3090 }
3091 break;
3092
3093 case IDM_SWITCH:
3094 if (mp2) {
3095 if (stricmp(dcd->directory, (CHAR *) mp2)) {
3096 //DosEnterCritSec(); //GKY 11-29-08
3097 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
3098 strcpy(lastextractpath, (CHAR *) mp2);
3099 MakeValidDir(lastextractpath);
3100 DosReleaseMutexSem(hmtxFM2Globals);
3101 //DosExitCritSec();
3102 }
3103 strcpy(dcd->directory, (CHAR *) mp2);
3104 MakeValidDir(dcd->directory);
3105 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3106 }
3107 break;
3108
3109 case IDM_WALKDIR:
3110 {
3111 CHAR newdir[CCHMAXPATH];
3112
3113 strcpy(newdir, dcd->directory);
3114 if (!WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkExtractDlgProc,
3115 FM3ModHandle, WALK_FRAME,
3116 MPFROMP(newdir)) || !*newdir)
3117 break;
3118 if (stricmp(newdir, dcd->directory)) {
3119 strcpy(dcd->directory, newdir);
3120 if (stricmp(lastextractpath, newdir))
3121 strcpy(lastextractpath, newdir);
3122 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3123 }
3124 }
3125 break;
3126
3127 case IDM_TEST:
3128 if (dcd->info->test)
3129 runemf2(SEPARATEKEEP | WINDOWED | MAXIMIZED,
3130 hwnd, pszSrcFile, __LINE__, NULL, NULL,
3131 "%s %s",dcd->info->test,
3132 BldQuotedFileName(szQuotedArcName, dcd->arcname));
3133 break;
3134
3135 case IDM_REFRESH:
3136 case IDM_DELETE:
3137 case IDM_PRINT:
3138 case IDM_VIEW:
3139 case IDM_VIEWTEXT:
3140 case IDM_VIEWBINARY:
3141 case IDM_VIEWARCHIVE:
3142 case IDM_EDIT:
3143 case IDM_EDITTEXT:
3144 case IDM_EDITBINARY:
3145 case IDM_EXTRACT:
3146 case IDM_EXTRACTWDIRS:
3147 case IDM_FIND:
3148 case IDM_EXEC:
3149 case IDM_VIRUSSCAN:
3150 case IDM_OPENDEFAULT:
3151 case IDM_OPENSETTINGS:
3152 case IDM_MCIPLAY:
3153 {
3154 LISTINFO *li;
3155# ifdef FORTIFY
3156 Fortify_EnterScope();
3157# endif
3158 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
3159 if (li) {
3160 li->type = SHORT1FROMMP(mp1);
3161 li->hwnd = hwnd;
3162 li->list = BuildArcList(hwnd);
3163 if (li->type == IDM_DELETE)
3164 ignorereadonly = FALSE;
3165 if (li->type == IDM_REFRESH) {
3166
3167 CHAR s[CCHMAXPATH], *p;
3168 INT x, y;
3169
3170 for (x = 0; li->list && li->list[x]; x++) {
3171 BldFullPathName(s, dcd->workdir, li->list[x]);
3172 if (IsFile(s) != 1) {
3173 free(li->list[x]);
3174 li->list[x] = NULL;
3175 for (y = x; li->list[y]; y++)
3176 li->list[y] = li->list[y + 1];
3177 li->list =
3178 xrealloc(li->list, y * sizeof(CHAR *), pszSrcFile,
3179 __LINE__);
3180 x--;
3181 }
3182 else {
3183 p = xstrdup(s, pszSrcFile, __LINE__);
3184 if (p) {
3185 free(li->list[x]);
3186 li->list[x] = p;
3187 }
3188 }
3189 } // for
3190 }
3191 strcpy(li->arcname, dcd->arcname);
3192 li->info = dcd->info;
3193 {
3194 PARCITEM pai;
3195
3196 if (SHORT1FROMMP(mp1) != IDM_EXEC)
3197 pai = (PARCITEM) CurrentRecord(hwnd);
3198 else
3199 pai = (PARCITEM) WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
3200 MPFROMLONG(CMA_FIRST),
3201 MPFROMSHORT(CRA_CURSORED));
3202 if (pai && (INT) pai != -1)
3203 strcpy(li->runfile, pai->pszFileName);
3204 else
3205 strcpy(li->runfile, li->list[0]);
3206 }
3207 switch (SHORT1FROMMP(mp1)) {
3208 case IDM_VIEW:
3209 case IDM_VIEWTEXT:
3210 case IDM_VIEWBINARY:
3211 case IDM_VIEWARCHIVE:
3212 case IDM_EDIT:
3213 case IDM_EDITTEXT:
3214 case IDM_EDITBINARY:
3215 case IDM_EXEC:
3216 case IDM_PRINT:
3217 case IDM_VIRUSSCAN:
3218 case IDM_OPENDEFAULT:
3219 case IDM_OPENSETTINGS:
3220 case IDM_MCIPLAY:
3221 strcpy(li->targetpath, dcd->workdir);
3222 break;
3223 default:
3224 strcpy(li->targetpath, dcd->directory);
3225 break;
3226 }
3227 if (li->list) {
3228 if (!PostMsg(dcd->hwndObject, UM_ACTION, MPFROMP(li), MPVOID)) {
3229 Runtime_Error(pszSrcFile, __LINE__, "post");
3230 FreeListInfo(li);
3231 }
3232 else if (fUnHilite && SHORT1FROMMP(mp1) != IDM_EDIT)
3233 UnHilite(hwnd, TRUE, &dcd->lastselection, 0);
3234 }
3235 else {
3236 free(li);
3237 }
3238 }
3239# ifdef FORTIFY
3240 Fortify_LeaveScope();
3241# endif
3242 }
3243 break;
3244 }
3245 }
3246 return 0;
3247
3248 case WM_CONTROL:
3249 DosError(FERR_DISABLEHARDERR);
3250 if (dcd) {
3251 switch (SHORT2FROMMP(mp1)) {
3252 case CN_BEGINEDIT:
3253 PostMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
3254 break;
3255
3256 case CN_ENDEDIT:
3257 if (!((PCNREDITDATA) mp2)->pRecord) {
3258
3259 PFIELDINFO pfi = ((PCNREDITDATA) mp2)->pFieldInfo;
3260 USHORT cmd = 0;
3261
3262 if (!pfi || pfi->offStruct == FIELDOFFSET(ARCITEM, pszDisplayName))
3263 cmd = IDM_SORTSMARTNAME;
3264 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, cbFile))
3265 cmd = IDM_SORTSIZE;
3266 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, cbComp))
3267 cmd = IDM_SORTEASIZE;
3268 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, date))
3269 cmd = IDM_SORTLWDATE;
3270 else if (pfi->offStruct == FIELDOFFSET(ARCITEM, time))
3271 cmd = IDM_SORTLWDATE;
3272 if (cmd)
3273 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
3274 }
3275 break;
3276
3277 case CN_DROPHELP:
3278 saymsg(MB_ENTER, hwnd,
3279 GetPString(IDS_DROPHELPHDRTEXT),
3280 GetPString(IDS_ARCCNRDROPHELPTEXT), dcd->arcname);
3281 return 0;
3282
3283 case CN_DRAGLEAVE:
3284 if (mp2) {
3285
3286 PDRAGINFO pDInfo;
3287
3288 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
3289 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
3290 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
3291 }
3292 return 0;
3293
3294 case CN_DRAGAFTER:
3295 case CN_DRAGOVER:
3296 if (mp2) {
3297
3298 PDRAGITEM pDItem; // Pointer to DRAGITEM
3299 PDRAGINFO pDInfo; // Pointer to DRAGINFO
3300 PARCITEM pci;
3301
3302 pci = (PARCITEM) ((PCNRDRAGINFO) mp2)->pRecord;
3303 if (SHORT1FROMMP(mp1) == CN_DRAGAFTER)
3304 pci = NULL;
3305 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
3306 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
3307 if (*dcd->arcname) {
3308 if ((driveflags[toupper(*dcd->arcname) - 'A'] &
3309 DRIVE_NOTWRITEABLE) || !dcd->info || !dcd->info->create) {
3310 DrgFreeDraginfo(pDInfo);
3311 return MRFROM2SHORT(DOR_NEVERDROP, 0);
3312 }
3313 }
3314 if (pci && (INT) pci != -1) {
3315 DrgFreeDraginfo(pDInfo);
3316 return MRFROM2SHORT(DOR_NODROP, 0);
3317 }
3318 pDItem = DrgQueryDragitemPtr(pDInfo, // Access DRAGITEM
3319 0); // Index to DRAGITEM
3320 if (DrgVerifyRMF(pDItem, // Check valid rendering
3321 (CHAR *) DRM_OS2FILE, // mechanisms and data
3322 NULL) && !(pDItem->fsControl & DC_PREPARE)) {
3323 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
3324 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
3325 fCopyDefault ? DO_COPY : DO_MOVE);
3326 }
3327 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
3328 }
3329 return (MRFROM2SHORT(DOR_NEVERDROP, 0)); // Drop not valid
3330
3331 case CN_INITDRAG:
3332 if (mp2) {
3333
3334 BOOL wasemphasized = FALSE;
3335 PCNRDRAGINIT pcd = (PCNRDRAGINIT) mp2;
3336 PARCITEM pci;
3337
3338 if (pcd) {
3339 pci = (PARCITEM) pcd->pRecord;
3340 if (pci && (INT) pci != -1) {
3341 if (pci->rc.flRecordAttr & CRA_SELECTED)
3342 wasemphasized = TRUE;
3343 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3344 fSplitStatus && hwndStatus2)
3345 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_DRAGARCMEMTEXT));
3346 if (DoFileDrag(hwnd,
3347 dcd->hwndObject,
3348 mp2, dcd->arcname, NULL, TRUE)) {
3349 if ((fUnHilite && wasemphasized) || dcd->ulItemsToUnHilite)
3350 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
3351 }
3352 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3353 fSplitStatus && hwndStatus2) {
3354 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3355 }
3356 }
3357 else {
3358 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3359 fSplitStatus && hwndStatus2)
3360 WinSetWindowText(hwndStatus2,
3361 (CHAR *) GetPString(IDS_DRAGARCFILETEXT));
3362 DragOne(hwnd, dcd->hwndObject, dcd->arcname, FALSE);
3363 if (!ParentIsDesktop(hwnd, dcd->hwndParent) &&
3364 fSplitStatus && hwndStatus2)
3365 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
3366 }
3367 }
3368 }
3369 return 0;
3370
3371 case CN_DROP:
3372 if (mp2) {
3373
3374 LISTINFO *li;
3375
3376 //DosBeep(500, 100); // fixme to know why beep?
3377 li = DoFileDrop(hwnd, dcd->arcname, FALSE, mp1, mp2);
3378 //DosBeep(50, 100); // fixme to know why beep?
3379 CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
3380 if (li) {
3381 li->type = li->type == DO_MOVE ? IDM_ARCHIVEM : IDM_ARCHIVE;
3382 strcpy(li->targetpath, dcd->arcname);
3383 if (!li->list ||
3384 !li->list[0] ||
3385 !PostMsg(dcd->hwndObject, UM_ACTION, MPFROMP(li), MPVOID))
3386 FreeListInfo(li);
3387 }
3388 }
3389 return 0;
3390
3391 case CN_CONTEXTMENU:
3392 {
3393 PARCITEM pci = (PARCITEM) mp2;
3394
3395 if (pci && (INT) pci != -1) {
3396 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
3397 MPFROM2SHORT(TRUE, CRA_CURSORED));
3398 MarkAll(hwnd, FALSE, FALSE, TRUE);
3399 dcd->hwndLastMenu = CheckMenu(hwnd, &ArcMenu, ARC_POPUP);
3400 }
3401 else {
3402 dcd->hwndLastMenu = CheckMenu(hwnd, &ArcCnrMenu, ARCCNR_POPUP);
3403 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
3404 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
3405 MPFROM2SHORT(TRUE, CRA_SOURCE));
3406 dcd->cnremphasized = TRUE;
3407 }
3408 }
3409 if (dcd->hwndLastMenu) {
3410 if (dcd->hwndLastMenu == ArcCnrMenu) {
3411 if (dcd->flWindowAttr & CV_MINI)
3412 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
3413 }
3414 WinCheckMenuItem(dcd->hwndLastMenu, IDM_FOLDERAFTEREXTRACT,
3415 fFolderAfterExtract);
3416 if (!PopupMenu(hwnd, hwnd, dcd->hwndLastMenu)) {
3417 if (dcd->cnremphasized) {
3418 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
3419 MPFROM2SHORT(FALSE, CRA_SOURCE));
3420 dcd->cnremphasized = TRUE;
3421 }
3422 MarkAll(hwnd, TRUE, FALSE, TRUE);
3423 }
3424 }
3425 }
3426 break;
3427
3428 case CN_EMPHASIS:
3429 if (mp2) {
3430
3431 PNOTIFYRECORDEMPHASIS pre = mp2;
3432 PARCITEM pci;
3433 CHAR s[CCHMAXPATHCOMP + 91], tf[81], tb[81];
3434
3435 pci = (PARCITEM)(pre ? pre->pRecord : NULL);
3436 if (!pci) {
3437 if (!ParentIsDesktop(hwnd, dcd->hwndParent)) {
3438 if (hwndStatus2)
3439 WinSetWindowText(hwndStatus2, NullStr);
3440 if (fMoreButtons)
3441 WinSetWindowText(hwndName, NullStr);
3442 }
3443 break;
3444 }
3445 if (pre->fEmphasisMask & CRA_SELECTED) {
3446 if (pci->rc.flRecordAttr & CRA_SELECTED) {
3447 dcd->selectedbytes += pci->cbFile;
3448 dcd->selectedfiles++;
3449 }
3450 else if (dcd->selectedfiles) {
3451 dcd->selectedbytes -= pci->cbFile;
3452 dcd->selectedfiles--;
3453 }
3454 commafmt(tf, sizeof(tf), dcd->selectedfiles);
3455 if (dcd->ullTotalBytes)
3456 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
3457 else
3458 *tb = 0;
3459 sprintf(s, "%s%s%s", tf, *tb ? " / " : NullStr, tb);
3460 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
3461 }
3462 else if (WinQueryActiveWindow(dcd->hwndParent) ==
3463 dcd->hwndFrame &&
3464 !ParentIsDesktop(hwnd, dcd->hwndParent)) {
3465 if (pre->fEmphasisMask & CRA_CURSORED) {
3466 if (pci->rc.flRecordAttr & CRA_CURSORED) {
3467 if (fSplitStatus && hwndStatus2) {
3468 if (dcd->ullTotalBytes)
3469 CommaFmtULL(tb, sizeof(tb), pci->cbFile, ' ');
3470 else
3471 *tb = 0;
3472 sprintf(s, "%s%s%s%s",
3473 *tb ? " " : NullStr,
3474 tb, *tb ? " " : NullStr, pci->pszFileName);
3475 WinSetWindowText(hwndStatus2, s);
3476 }
3477 if (fMoreButtons)
3478 WinSetWindowText(hwndName, pci->pszFileName);
3479 }
3480 }
3481 }
3482 }
3483 break;
3484
3485 case CN_ENTER:
3486 if (mp2) {
3487
3488 PARCITEM pci = (PARCITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
3489
3490 if (pci && (INT) pci != -1) {
3491
3492 CHAR *s;
3493
3494 if ((pci->rc.flRecordAttr & CRA_INUSE) ||
3495 (pci->flags & (ARCFLAGS_REALDIR | ARCFLAGS_PSEUDODIR)))
3496 break;
3497 s = xstrdup(pci->pszFileName, pszSrcFile, __LINE__);
3498 if (s) {
3499 if (!PostMsg(dcd->hwndObject, UM_ENTER, MPFROMP(s), MPVOID)) {
3500 Runtime_Error(pszSrcFile, __LINE__, "post");
3501 free(s);
3502 }
3503 }
3504 }
3505 }
3506 break;
3507 }
3508 }
3509 return 0;
3510
3511 case UM_FOLDUP:
3512 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
3513 DosExit(EXIT_PROCESS, 1);
3514 return 0;
3515
3516 case UM_CLOSE:
3517 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
3518 QW_PARENT));
3519 return 0;
3520
3521 case WM_SAVEAPPLICATION:
3522 if (dcd && ParentIsDesktop(hwnd, dcd->hwndParent)) {
3523 SWP swp;
3524
3525 WinQueryWindowPos(dcd->hwndFrame, &swp);
3526 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE | SWP_MAXIMIZE)))
3527 PrfWriteProfileData(fmprof, appname, "AV2SizePos", &swp, sizeof(swp));
3528 }
3529 break;
3530
3531 case WM_CLOSE:
3532 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
3533 if (dcd)
3534 dcd->stopflag++;
3535 if (dcd && dcd->hwndObject) {
3536 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
3537 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
3538 }
3539 // In case object window frees dcd
3540 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
3541 if (!dcd ||
3542 (!dcd->dontclose &&
3543 !dcd->amextracted && ParentIsDesktop(hwnd, dcd->hwndParent))) {
3544 if (!PostMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID))
3545 WinSendMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID);
3546 }
3547 return 0;
3548
3549 case WM_DESTROY:
3550 if (ArcMenu)
3551 WinDestroyWindow(ArcMenu);
3552 if (ArcCnrMenu)
3553 WinDestroyWindow(ArcCnrMenu);
3554 ArcMenu = ArcCnrMenu = (HWND) 0;
3555 EmptyArcCnr(hwnd);
3556# ifdef FORTIFY
3557 Fortify_LeaveScope();
3558# endif
3559 break;
3560 }
3561 if (dcd && dcd->oldproc){
3562 return dcd->oldproc(hwnd, msg, mp1, mp2);
3563 }
3564 else
3565 return PFNWPCnr(hwnd, msg, mp1, mp2);
3566}
3567
3568MRESULT EXPENTRY ArcCnrMenuProc(HWND hwnd, ULONG msg, MPARAM mp1,
3569 MPARAM mp2)
3570{
3571 PFNWP oldMenuProc = WinQueryWindowPtr(hwnd, QWL_USER);
3572 static short sLastMenuitem;
3573
3574 switch (msg) {
3575 case WM_MOUSEMOVE: {
3576 if (fOtherHelp) {
3577 RECTL rectl;
3578 SHORT i, sCurrentMenuitem;
3579 SHORT MenuItems = 10;
3580 SHORT asMenuIDs[10] = {IDM_VIEW,
3581 IDM_DELETE,
3582 IDM_EXEC,
3583 IDM_EXTRACT,
3584 IDM_TEST,
3585 IDM_VIRUSSCAN,
3586 IDM_RESCAN,
3587 IDM_WALKDIR,
3588 IDM_FILTER,
3589 0};
3590 PCSZ szHelpString = NULL;
3591
3592
3593 for (i=0; i<MenuItems; i++) {
3594 sCurrentMenuitem = asMenuIDs[i];
3595 oldMenuProc(hwnd,MM_QUERYITEMRECT,
3596 MPFROM2SHORT(asMenuIDs[i], FALSE),
3597 &rectl);
3598
3599 if (MOUSEMSG(&msg)->x > rectl.xLeft &&
3600 MOUSEMSG(&msg)->x < rectl.xRight &&
3601 MOUSEMSG(&msg)->y > rectl.yBottom &&
3602 MOUSEMSG(&msg)->y < rectl.yTop)
3603 break;
3604 } // for
3605
3606
3607 switch (sCurrentMenuitem) {
3608 case 0:
3609 break;
3610 case IDM_VIEW:
3611 szHelpString = GetPString(IDS_ARCCNRVIEWMENUHELP);
3612 break;
3613 case IDM_DELETE:
3614 szHelpString = GetPString(IDS_ARCCNRDELETEMENUHELP);
3615 break;
3616 case IDM_EXEC:
3617 szHelpString = GetPString(IDS_ARCCNREXECMENUHELP);
3618 break;
3619 case IDM_EXTRACT:
3620 szHelpString = GetPString(IDS_ARCCNREXTRACTMENUHELP);
3621 break;
3622 case IDM_TEST:
3623 szHelpString = GetPString(IDS_ARCCNRTESTMENUHELP);
3624 break;
3625 case IDM_VIRUSSCAN:
3626 szHelpString = GetPString(IDS_ARCCNRVIRUSMENUHELP);
3627 break;
3628 case IDM_RESCAN:
3629 szHelpString = GetPString(IDS_ARCCNRRESCANMENUHELP);
3630 break;
3631 case IDM_WALKDIR:
3632 szHelpString = GetPString(IDS_ARCCNRWALKDIRMENUHELP);
3633 break;
3634 case IDM_FILTER:
3635 szHelpString = GetPString(IDS_ARCCNRFILTERMENUHELP);
3636 break;
3637 default:
3638 break;
3639 }
3640
3641 if (sLastMenuitem != sCurrentMenuitem && szHelpString) {
3642 sLastMenuitem = sCurrentMenuitem;
3643 MakeBubble(hwnd, TRUE, szHelpString);
3644 }
3645 else if (hwndBubble && !sCurrentMenuitem){
3646 sLastMenuitem = sCurrentMenuitem;
3647 WinDestroyWindow(hwndBubble);
3648 }
3649 }
3650 }
3651 }
3652 return oldMenuProc(hwnd, msg, mp1, mp2);
3653}
3654
3655HWND StartArcCnr(HWND hwndParent, HWND hwndCaller, CHAR * arcname, INT flags,
3656 ARC_TYPE * sinfo)
3657{
3658 /**
3659 * bitmapped flags:
3660 * 1 = am extracted from another archive
3661 * 4 = don't kill proc on close
3662 */
3663
3664 HWND hwndFrame = (HWND) 0, hwndClient;
3665 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
3666 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
3667 USHORT id;
3668 DIRCNRDATA *dcd;
3669 ARC_TYPE *info = sinfo;
3670 CHAR title[MAXNAMEL + 1] = "AV/2 - ";
3671 CHAR fullname[CCHMAXPATH + 8], *p, temp;
3672 static USHORT idinc = 0;
3673
3674 if (!idinc)
3675 idinc = (rand() % 256);
3676 if (ParentIsDesktop(hwndParent, hwndParent))
3677 FrameFlags |= (FCF_TASKLIST | FCF_MENU);
3678 if (arcname) {
3679 DosError(FERR_DISABLEHARDERR);
3680 if (DosQueryPathInfo(arcname,
3681 FIL_QUERYFULLNAME, fullname, sizeof(fullname)))
3682 strcpy(fullname, arcname);
3683 ForwardslashToBackslash(fullname);
3684 if (!info)
3685 info = find_type(fullname, arcsighead);
3686 if (!info)
3687 return hwndFrame;
3688 if (strlen(title) + strlen(fullname) > MAXNAMEL) {
3689 p = title + strlen(title);
3690 strncpy(p, fullname, MAXNAMEL / 2 - 5);
3691 strcpy(p + MAXNAMEL / 2 - 5, "...");
3692 strcat(title, fullname + strlen(fullname) - (MAXNAMEL / 2 - 5));
3693 }
3694 else {
3695 strcat(title, fullname);
3696 }
3697 hwndFrame = WinCreateStdWindow(hwndParent,
3698 WS_VISIBLE,
3699 &FrameFlags,
3700 (CHAR *) WC_ARCCONTAINER,
3701 title,
3702 WS_VISIBLE | fwsAnimate,
3703 FM3ModHandle, ARC_FRAME, &hwndClient);
3704 if (hwndFrame && hwndClient) {
3705 id = ARC_FRAME + idinc++;
3706 if (idinc > 512)
3707 idinc = 0;
3708 WinSetWindowUShort(hwndFrame, QWS_ID, id);
3709# ifdef FORTIFY
3710 Fortify_EnterScope();
3711# endif
3712 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3713 if (!dcd) {
3714 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3715 hwndFrame = (HWND) 0;
3716 }
3717 else {
3718# ifdef FORTIFY
3719 // Will be freed by WM_DESTROY
3720 Fortify_ChangeScope(dcd, -1);
3721# endif
3722 dcd->size = sizeof(DIRCNRDATA);
3723 dcd->id = id;
3724 dcd->type = ARC_FRAME;
3725 if (pTmpDir && !IsValidDir(pTmpDir))
3726 DosCreateDir(pTmpDir, 0);
3727 MakeTempName(dcd->workdir, ArcTempRoot, 2);
3728 strcpy(dcd->arcname, fullname);
3729 if (*extractpath) {
3730 if (!strcmp(extractpath, "*")) {
3731 p = strrchr(fullname, '\\');
3732 if (p) {
3733 if (p < fullname + 3)
3734 p++;
3735 temp = *p;
3736 *p = 0;
3737 strcpy(dcd->directory, fullname);
3738 *p = temp;
3739 }
3740 }
3741 else
3742 strcpy(dcd->directory, extractpath);
3743 }
3744 if (!*dcd->directory && *lastextractpath) {
3745 //DosEnterCritSec(); //GKY 11-29-08
3746 DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
3747 strcpy(dcd->directory, lastextractpath);
3748 DosReleaseMutexSem(hmtxFM2Globals);
3749 //DosExitCritSec();
3750 }
3751 if (!*dcd->directory) {
3752 if (!ParentIsDesktop(hwndParent, hwndParent))
3753 TopWindowName(hwndParent, hwndCaller, dcd->directory);
3754 if (!*dcd->directory) {
3755 p = strrchr(fullname, '\\');
3756 if (p) {
3757 if (p < fullname + 3)
3758 p++;
3759 *p = 0;
3760 strcpy(dcd->directory, fullname);
3761 }
3762 }
3763 }
3764 if (!*dcd->directory ||
3765 (IsFile(dcd->directory) == 1) ||
3766 (isalpha(*dcd->directory) &&
3767 (driveflags[toupper(*dcd->directory) - 'A'] &
3768 DRIVE_NOTWRITEABLE)))
3769 strcpy(dcd->directory, pFM2SaveDirectory);
3770 dcd->hwndParent = hwndParent ? hwndParent : HWND_DESKTOP;
3771 dcd->hwndFrame = hwndFrame;
3772 dcd->hwndClient = hwndClient;
3773 dcd->amextracted = (flags & 1) != 0;
3774 dcd->dontclose = (flags & 4) != 0;
3775 dcd->info = info;
3776 dcd->sortFlags = DefArcSortFlags;
3777 {
3778 PFNWP oldproc;
3779
3780 oldproc = WinSubclassWindow(hwndFrame, (PFNWP) ArcFrameWndProc);
3781 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3782 }
3783 dcd->hwndCnr = WinCreateWindow(hwndClient,
3784 WC_CONTAINER,
3785 NULL,
3786 CCS_AUTOPOSITION | CCS_MINIICONS |
3787 CCS_MINIRECORDCORE | ulCnrType |
3788 WS_VISIBLE,
3789 0,
3790 0,
3791 0,
3792 0,
3793 hwndClient,
3794 HWND_TOP, (ULONG) ARC_CNR, NULL, NULL);
3795 if (!dcd->hwndCnr) {
3796 Win_Error(hwndClient, hwndClient, pszSrcFile, __LINE__,
3797 PCSZ_WINCREATEWINDOW);
3798 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3799 free(dcd);
3800 hwndFrame = (HWND) 0;
3801 }
3802 else {
3803 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3804 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr,
3805 (PFNWP) ArcCnrWndProc);
3806 {
3807 USHORT ids[] = { DIR_TOTALS, DIR_SELECTED, DIR_VIEW, DIR_SORT,
3808 DIR_FILTER, DIR_FOLDERICON, 0
3809 };
3810
3811 CommonCreateTextChildren(dcd->hwndClient,
3812 WC_ARCSTATUS, ids);
3813 }
3814 WinEnableWindow(WinWindowFromID(dcd->hwndClient, DIR_VIEW), FALSE);
3815 dcd->hwndExtract = WinCreateWindow(dcd->hwndClient,
3816 WC_ENTRYFIELD,
3817 NULL,
3818 ES_AUTOSCROLL,
3819 0,
3820 0,
3821 0,
3822 0,
3823 dcd->hwndClient,
3824 HWND_TOP,
3825 ARC_EXTRACTDIR, NULL, NULL);
3826 WinSendMsg(dcd->hwndExtract,
3827 EM_SETTEXTLIMIT, MPFROM2SHORT(CCHMAXPATH, 0), MPVOID);
3828 WinSetWindowText(dcd->hwndExtract, dcd->directory);
3829 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3830 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3831 if (FrameFlags & FCF_MENU) {
3832 PFNWP oldmenuproc;
3833 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
3834
3835 oldmenuproc = WinSubclassWindow(hwndMenu, (PFNWP) ArcCnrMenuProc);
3836 WinSetWindowPtr(hwndMenu, QWL_USER, (PVOID) oldmenuproc);
3837 if (!fToolbar) {
3838
3839 if (hwndMenu) {
3840 WinSendMsg(hwndMenu, MM_DELETEITEM,
3841 MPFROM2SHORT(IDM_VIEW, FALSE), MPVOID);
3842 WinSendMsg(hwndMenu, MM_DELETEITEM,
3843 MPFROM2SHORT(IDM_EXEC, FALSE), MPVOID);
3844 WinSendMsg(hwndMenu, MM_DELETEITEM,
3845 MPFROM2SHORT(IDM_RESCAN, FALSE), MPVOID);
3846 WinSendMsg(hwndMenu, MM_DELETEITEM,
3847 MPFROM2SHORT(IDM_DELETE, FALSE), MPVOID);
3848 WinSendMsg(hwndMenu, MM_DELETEITEM,
3849 MPFROM2SHORT(IDM_EXTRACT, FALSE), MPVOID);
3850 WinSendMsg(hwndMenu, MM_DELETEITEM,
3851 MPFROM2SHORT(IDM_TEST, FALSE), MPVOID);
3852 WinSendMsg(hwndMenu, MM_DELETEITEM,
3853 MPFROM2SHORT(IDM_VIRUSSCAN, FALSE), MPVOID);
3854 WinSendMsg(hwndMenu, MM_DELETEITEM,
3855 MPFROM2SHORT(IDM_WALKDIR, FALSE), MPVOID);
3856 WinSendMsg(hwndMenu, MM_DELETEITEM,
3857 MPFROM2SHORT(IDM_FILTER, FALSE), MPVOID);
3858 }
3859 }
3860 }
3861 if (FrameFlags & FCF_TASKLIST) {
3862
3863 SWP swp, swpD;
3864 ULONG size = sizeof(swp);
3865 LONG cxScreen, cyScreen;
3866
3867 WinQueryTaskSizePos(WinQueryAnchorBlock(hwndFrame), 0, &swp);
3868 if (PrfQueryProfileData(fmprof, appname, "AV2SizePos", &swpD, &size)) {
3869 cxScreen = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
3870 cyScreen = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
3871 if (swp.x + swpD.cx > cxScreen)
3872 swp.x = cxScreen - swpD.cx;
3873 if (swp.y + swpD.cy > cyScreen)
3874 swp.y = cyScreen - swpD.cy;
3875 swp.cx = swpD.cx;
3876 swp.cy = swpD.cy;
3877 }
3878 WinSetWindowPos(hwndFrame,
3879 HWND_TOP,
3880 swp.x,
3881 swp.y,
3882 swp.cx,
3883 swp.cy,
3884 SWP_SIZE | SWP_MOVE | SWP_SHOW | SWP_ZORDER |
3885 SWP_ACTIVATE);
3886 }
3887 }
3888 }
3889# ifdef FORTIFY
3890 Fortify_LeaveScope();
3891# endif
3892 }
3893 }
3894 return hwndFrame;
3895}
3896
3897#pragma alloc_text(ARCCNRS,ArcCnrWndProc,ArcObjWndProc,ArcClientWndProc,BldQuotedFullPathName)
3898#pragma alloc_text(ARCCNRS,ArcTextProc,FillArcCnr,ArcFilter,BldQuotedFileName)
3899#pragma alloc_text(ARCCNRS,ArcSort,ArcFrameWndProc,IsArcThere,ArcErrProc)
3900#pragma alloc_text(STARTUP,StartArcCnr)
Note: See TracBrowser for help on using the repository browser.