source: trunk/dll/collect.c@ 1844

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

Fix trap in collector if a pci-pszFileName = NullStr and fix heap corruption problem and its related traps. This code reverts John double free fix. Ticket [551][555]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 88.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: collect.c 1836 2015-07-15 00:48:14Z gyoung $
5
6 Collector
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2003, 2012 Steven H. Levine
10
11 15 Oct 02 MK Baseline
12 10 Jan 04 SHL Avoid -1L byte counts
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 23 May 05 SHL Use QWL_USER
15 24 May 05 SHL Rework Win_Error usage
16 25 May 05 SHL Use ULONGLONG and CommaFmtULL
17 25 May 05 SHL Rework for FillInRecordFromFFB
18 05 Jun 05 SHL Use QWL_USER
19 06 Jun 05 SHL Indent -i2
20 06 Jun 05 SHL Make savedSortFlags static to avoid referencing garbage
21 24 Oct 05 SHL Sanitize handle references
22 24 Oct 05 SHL CollectorCnrWndProc: avoid excess writes to Status2 window
23 10 Nov 05 SHL CollectorCnrWndProc: correct missing button window updates
24 14 Jul 06 SHL Use Runtime_Error
25 27 Jul 06 SHL Avoid shutdown hang - pre3 typo
26 29 Jul 06 SHL Use xfgets_bstripcr
27 15 Aug 06 SHL Don't write garbage to CollectorFilter INI entry
28 15 Aug 06 SHL Rework SetMask args
29 18 Aug 06 SHL CollectorCnrWndProc: avoid freeing NULL pointer
30 31 Aug 06 SHL Disable Utilities->Seek and scan menu while busy
31 31 Aug 06 SHL Correct stop scan context menu enable/disable
32 30 Mar 07 GKY Remove GetPString for window class names
33 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
34 06 Apr 07 GKY Add some error checking in drag/drop
35 19 Apr 07 SHL Use FreeDragInfoData. Add more drag/drop error checks.
36 12 May 07 SHL Use dcd->ulItemsToUnHilite
37 10 Jun 07 GKY Add CheckPmDrgLimit including IsFm2Window as part of work around PM drag limit
38 05 Jul 07 SHL CollectorCnrWndProc: just warn if busy
39 02 Aug 07 SHL Sync with CNRITEM mods
40 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
41 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
42 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
43 22 Nov 07 GKY Use CopyPresParams to fix presparam inconsistencies in menus
44 10 Jan 08 SHL Sync with CfgDlgProc mods
45 10 Feb 08 GKY Implement bubble help for bitmap menu items
46 15 Feb 08 SHL Sync with settings menu rework
47 15 Feb 08 GKY Fix attempt to free container items that were never inserted
48 15 Feb 08 GKY Fix "collect" so it updates recollected files and unhides them if needed
49 29 Feb 08 GKY Use xfree where appropriate
50 06 Jul 08 GKY Update delete/undelete to include move to and open XWP trashcan
51 11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating
52 all the details view settings (both the global variables and those in the
53 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
54 20 Jul 08 GKY Add save/append filename to clipboard.
55 Change menu wording to make these easier to find
56 25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
57 less than 10 KiB (It hangs and can't be closed)
58 10 Dec 08 SHL Integrate exception handler support
59 26 Dec 08 GKY Fixed DROPHELP to check for copy as default is action is DO_DEFAULT
60 01 Jan 09 GKY Add Seek and Scan to drives & directory context menus pass drive/dir as search root
61 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
62 07 Feb 09 GKY Allow user to turn off alert and/or error beeps in settings notebook.
63 07 Feb 09 GKY Add *DateFormat functions to format dates based on locale
64 07 Feb 09 GKY Move repeated strings to PCSZs.
65 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
66 08 Mar 09 GKY Additional strings move to PCSZs in init.c
67 06 Jun 09 GKY Add option to show file system type or drive label in tree
68 12 Jul 09 GKY Add szFSType to FillInRecordFromFSA use to bypass EA scan and size formatting
69 for tree container
70 13 Jul 09 GKY Fixed double free of memory buffer in UM_COLLECTFROMFILE
71 15 Sep 09 SHL Use UM_GREP when passing pathname
72 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
73 23 Oct 10 GKY Add menu items for opening directory cnrs based on path of selected item
74 including the option to use walk directories to select path
75 28 May 11 GKY Fixed trap caused by passing a nonexistant pci to FillInRecordFromFFB in
76 UM_COLLECT because pci is limited to 65535 files. (nRecord is a USHORT)
77 29 May 11 SHL Rework UM_COLLECT >65K records logic to not require double loop
78 29 May 11 SHL Tweak UM_COLLECT to bypass FindCnrRecord when container initially empty
79 08 Aug 11 SHL Rework UM_COLLECT to avoid spurious container items free
80 13 Aug 11 GKY Have file count and KIBs update at the same time
81 04 Aug 12 GKY Changes to use Unlock to unlock files if Unlock.exe is in path both from menu and as part of copy, move and
82 delete operations
83 05 Sep 12 SHL Correct UM_COLLECTFROMFILE bad list file reporting
84 13 Dec 13 SHL CollectorCnrWndProc IDM_FILTER: avoid exception on missing fileName
85 22 Feb 14 GKY Fix warn readonly yes don't ask to work when recursing directories.
86 16 Mar 15 GKY Add semaphore hmtxFiltering to prevent freeing dcd while filtering. Prevents
87 a trap when FM2 is shutdown or the container is closed while collector
88 container is still populating
89 02 May 15 GKY Changes to allow a JAVA executable object to be created using "Real object"
90 menu item on a jar file.
91 14 Jun 15 GKY Changes to prevent trap in Filter
92
93***********************************************************************/
94
95#include <stdlib.h>
96#include <string.h>
97#include <ctype.h>
98#include <share.h>
99#include <limits.h> // USHRT_MAX
100// #include <process.h> // _beginthread
101
102#define INCL_DOS // QSV_MS_COUNT
103#define INCL_WIN
104#define INCL_DOSERRORS
105#define INCL_LONGLONG
106
107#include "fm3dll.h"
108#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
109#include "dircnrs.h" // Data declaration(s)
110#include "info.h" // Data declaration(s)
111#include "init.h" // Data declaration(s)
112#include "fm3dlg.h"
113#include "fm3str.h"
114#include "mle.h"
115#include "grep.h"
116#include "comp.h"
117#include "arccnrs.h" // StartArcCnr
118#include "filldir.h" // EmptyCnr...
119#include "strutil.h" // GetPString
120#include "errutil.h" // Runtime_Error
121#include "tmrsvcs.h" // ITIMER_DESC
122#include "notebook.h" // CfgDlgProc
123#include "command.h" // RunCommand
124#include "worker.h" // Action, MassAction
125#include "notify.h" // AddNote
126#include "misc.h" // AdjustCnrColsForPref, AdjustDetailsSwitches, CnrDirectEdit,
127 // LoadDetailsSwitches, OpenEdit, QuickPopup, SayFilter
128 // SaySort, SayView, SetCnrCols, SetDetailsSwitches
129 // SetSortChecks, SetViewMenu, disable_menuitem, CheckMenu
130 // CurrentRecord, DrawTargetEmphasis, IsFm2Window
131#include "chklist.h" // CenterOverWindow, DropListProc
132#include "collect.h"
133#include "common.h" // CommonCnrProc, CommonCreateTextChildren, CommonFrameWndProc
134 // CommonTextPaint
135#include "select.h" // DeselectAll, HideAll, RemoveAll, SelectAll, SelectList
136#include "dirsize.h" // DirSizeProc
137#include "grep2.h" // GrepDlgProc
138#include "mainwnd.h" // MakeBubble
139#include "objwin.h" // MakeObjWin
140#include "saveclip.h" // SaveListDlgProc
141#include "findrec.h" // ShowCnrRecord
142#include "sortcnr.h" // SortCollectorCnr
143#include "seeall.h" // StartSeeAll
144#include "update.h" // UpdateCnrList, UpdateCnrRecord
145#include "droplist.h" // CheckPmDrgLimit
146#include "common.h" // CommonTextButton, CommonTextProc
147#include "presparm.h" // CopyPresParams
148#include "defview.h" // DefaultViewKeys
149#include "draglist.h" // DoFileDrag, FreeDragInfoData
150#include "systemf.h" // ExecOnList
151#include "filter.h" // Filter
152#include "findrec.h" // FindCnrRecord
153#include "shadow.h" // OpenObject
154#include "mkdir.h" // PMMkDir
155#include "valid.h" // ParentIsDesktop
156#include "viewer.h" // StartMLEEditor
157#include "newview.h" // StartViewer
158#include "undel.h" // UndeleteDlgProc
159#include "i18nutil.h" // commafmt
160#include "getnames.h" // insert_filename
161#include "select.h" // InvertAll
162#include "strips.h" // bstrip
163#include "wrappers.h" // xDosFindFirst
164#include "fortify.h"
165#include "excputil.h" // xbeginthread
166#include "walkem.h" // WalkAllDlgProc
167#include "copyf.h" // ignorereadonly
168
169// Data definitions
170#pragma data_seg(GLOBAL1)
171HWND CollectorCnrMenu;
172HWND hwndStatus2;
173
174#pragma data_seg(GLOBAL2)
175INT CollectorsortFlags;
176
177#pragma data_seg(DATA1)
178static PSZ pszSrcFile = __FILE__;
179
180MRESULT EXPENTRY CollectorFrameWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
181 MPARAM mp2)
182{
183 return CommonFrameWndProc(COLLECTOR_CNR, hwnd, msg, mp1, mp2);
184}
185
186MRESULT EXPENTRY CollectorTextProc(HWND hwnd, ULONG msg, MPARAM mp1,
187 MPARAM mp2)
188{
189 DIRCNRDATA *dcd;
190
191 static BOOL emphasized = FALSE;
192 static HWND hwndButtonPopup = (HWND) 0;
193 static ULONG timestamp = ULONG_MAX;
194 static USHORT lastid = 0;
195
196 switch (msg) {
197 case WM_CREATE:
198 return CommonTextProc(hwnd, msg, mp1, mp2);
199
200 case UM_CONTEXTMENU:
201 case WM_CONTEXTMENU:
202 {
203 USHORT id;
204
205 id = WinQueryWindowUShort(hwnd, QWS_ID);
206 switch (id) {
207 case DIR_SELECTED:
208 case DIR_VIEW:
209 case DIR_SORT:
210 {
211 POINTL ptl = { 0, 0 };
212 SWP swp;
213
214 if (hwndButtonPopup)
215 WinDestroyWindow(hwndButtonPopup);
216 if (id == lastid) {
217 ULONG check;
218
219 DosQuerySysInfo(QSV_MS_COUNT,
220 QSV_MS_COUNT, &check, sizeof(check));
221 if (check < timestamp + 500) {
222 lastid = 0;
223 goto MenuAbort;
224 }
225 }
226 hwndButtonPopup = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
227 if (hwndButtonPopup) {
228 WinSetWindowUShort(hwndButtonPopup, QWS_ID, id);
229 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
230 QW_PARENT),
231 COLLECTOR_CNR), QWL_USER);
232 if (id == DIR_VIEW) {
233 if (dcd) {
234 SetViewMenu(hwndButtonPopup, dcd->flWindowAttr);
235 SetDetailsSwitches(hwndButtonPopup, &dcd->ds);
236 CopyPresParams(hwndButtonPopup, hwnd);
237 }
238
239 // don't have tree view in collector
240 WinSendMsg(hwndButtonPopup,
241 MM_DELETEITEM,
242 MPFROM2SHORT(IDM_TREEVIEW, FALSE), MPVOID);
243
244 }
245 else if (id == DIR_SORT) {
246 if (dcd)
247 SetSortChecks(hwndButtonPopup, dcd->sortFlags);
248 }
249 ptl.x = 0;
250 if (WinPopupMenu(HWND_OBJECT,
251 HWND_OBJECT,
252 hwndButtonPopup, -32767, -32767, 0, 0)) {
253 WinQueryWindowPos(hwndButtonPopup, &swp);
254 ptl.y = -(swp.cy + 2);
255 }
256 else {
257 WinQueryWindowPos(hwnd, &swp);
258 ptl.y = swp.cy + 2;
259 }
260 if (WinPopupMenu(hwnd,
261 hwnd,
262 hwndButtonPopup,
263 ptl.x,
264 ptl.y,
265 0,
266 PU_HCONSTRAIN | PU_VCONSTRAIN |
267 PU_KEYBOARD | PU_MOUSEBUTTON1)) {
268 CenterOverWindow(hwndButtonPopup);
269 PaintRecessedWindow(hwnd, NULLHANDLE, FALSE, FALSE);
270 }
271 }
272 }
273 break;
274 default:
275 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
276 COLLECTOR_CNR),
277 WM_CONTROL,
278 MPFROM2SHORT(COLLECTOR_CNR, CN_CONTEXTMENU), MPVOID);
279 break;
280 }
281 }
282 MenuAbort:
283 if (msg == UM_CONTEXTMENU)
284 return 0;
285 break;
286
287 case WM_MENUEND:
288 if (hwndButtonPopup == (HWND) mp2) {
289 lastid = WinQueryWindowUShort((HWND) mp2, QWS_ID);
290 WinDestroyWindow(hwndButtonPopup);
291 hwndButtonPopup = (HWND) 0;
292 DosQuerySysInfo(QSV_MS_COUNT, QSV_MS_COUNT, &timestamp,
293 sizeof(timestamp));
294 switch (lastid) {
295 case DIR_SELECTED:
296 case DIR_VIEW:
297 case DIR_SORT:
298 PaintRecessedWindow(hwnd, NULLHANDLE, TRUE, FALSE);
299 break;
300 }
301 }
302 break;
303
304 case WM_COMMAND:
305 {
306 DIRCNRDATA *dcd;
307 MRESULT mr;
308
309 mr = WinSendMsg(WinWindowFromID(WinQueryWindow(hwnd,
310 QW_PARENT),
311 COLLECTOR_CNR), msg, mp1, mp2);
312 if (hwndButtonPopup &&
313 SHORT1FROMMP(mp1) > IDM_DETAILSTITLES &&
314 SHORT1FROMMP(mp1) < IDM_DETAILSSETUP) {
315 dcd = WinQueryWindowPtr(WinWindowFromID(WinQueryWindow(hwnd,
316 QW_PARENT),
317 COLLECTOR_CNR), QWL_USER);
318 if (dcd)
319 SetDetailsSwitches(hwndButtonPopup, &dcd->ds);
320 }
321 return mr;
322 }
323
324 case WM_MOUSEMOVE:
325 {
326 USHORT id = WinQueryWindowUShort(hwnd, QWS_ID);
327 PCSZ s = NULL;
328
329 if (fOtherHelp) {
330 if ((!hwndBubble ||
331 WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
332 !WinQueryCapture(HWND_DESKTOP)) {
333 switch (id) {
334 case DIR_SELECTED:
335 s = GetPString(IDS_COLSELECTEDHELP);
336 break;
337 case DIR_TOTALS:
338 s = GetPString(IDS_COLTOTALSHELP);
339 break;
340 case DIR_VIEW:
341 s = GetPString(IDS_DIRCNRVIEWHELP);
342 break;
343 case DIR_SORT:
344 s = GetPString(IDS_DIRCNRSORTHELP);
345 break;
346 case DIR_FILTER:
347 s = GetPString(IDS_DIRCNRFILTERHELP);
348 break;
349 default:
350 break;
351 }
352 if (s)
353 MakeBubble(hwnd, TRUE, s);
354 else if (hwndBubble)
355 WinDestroyWindow(hwndBubble);
356 }
357 }
358 switch (id) {
359 case DIR_FILTER:
360 case DIR_SORT:
361 case DIR_VIEW:
362 case DIR_SELECTED:
363 return CommonTextButton(hwnd, msg, mp1, mp2);
364 }
365 }
366 break;
367
368 case WM_BUTTON3UP:
369 case WM_BUTTON1UP:
370 case WM_BUTTON3DOWN:
371 case WM_BUTTON1DOWN:
372 {
373 USHORT id;
374
375 id = WinQueryWindowUShort(hwnd, QWS_ID);
376 switch (id) {
377 case DIR_FILTER:
378 case DIR_SORT:
379 case DIR_VIEW:
380 case DIR_SELECTED:
381 return CommonTextButton(hwnd, msg, mp1, mp2);
382 }
383 }
384 break;
385
386 case UM_CLICKED:
387 case UM_CLICKED3:
388 {
389 USHORT id, cmd = 0;
390
391 id = WinQueryWindowUShort(hwnd, QWS_ID);
392 switch (id) {
393 case DIR_VIEW:
394 case DIR_SORT:
395 case DIR_SELECTED:
396 PostMsg(hwnd, UM_CONTEXTMENU, MPVOID, MPVOID);
397 break;
398 case DIR_FILTER:
399 cmd = IDM_FILTER;
400 break;
401 default:
402 break;
403 }
404 if (cmd)
405 PostMsg(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
406 COLLECTOR_CNR),
407 WM_COMMAND, MPFROM2SHORT(cmd, 0), MPVOID);
408 }
409 return 0;
410
411 case DM_DROP:
412 case DM_DRAGOVER:
413 case DM_DRAGLEAVE:
414 case DM_DROPHELP:
415 if (msg == DM_DRAGOVER) {
416 if (!emphasized) {
417 emphasized = TRUE;
418 DrawTargetEmphasis(hwnd, emphasized);
419 }
420 }
421 else {
422 if (emphasized) {
423 emphasized = FALSE;
424 DrawTargetEmphasis(hwnd, emphasized);
425 }
426 }
427 {
428 CNRDRAGINFO cnd;
429 USHORT dcmd;
430
431 switch (msg) {
432 case DM_DROP:
433 dcmd = CN_DROP;
434 break;
435 case DM_DRAGOVER:
436 dcmd = CN_DRAGOVER;
437 break;
438 case DM_DRAGLEAVE:
439 dcmd = CN_DRAGLEAVE;
440 break;
441 case DM_DROPHELP:
442 dcmd = CN_DROPHELP;
443 break;
444 }
445 memset(&cnd, 0, sizeof(cnd));
446 cnd.pDragInfo = (PDRAGINFO) mp1;
447 cnd.pRecord = NULL;
448 return WinSendMsg(WinQueryWindow(hwnd, QW_PARENT), WM_CONTROL,
449 MPFROM2SHORT(COLLECTOR_CNR, dcmd), MPFROMP(&cnd));
450 }
451 }
452 return PFNWPStatic(hwnd, msg, mp1, mp2);
453}
454
455MRESULT EXPENTRY CollectorClientWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
456 MPARAM mp2)
457{
458 switch (msg) {
459 case UM_CONTAINERHWND:
460 return MRFROMLONG(WinWindowFromID(hwnd, COLLECTOR_CNR));
461
462 case UM_VIEWSMENU:
463 return MRFROMLONG(CheckMenu(hwnd, &CollectorCnrMenu, COLLECTORCNR_POPUP));
464
465 case MM_PORTHOLEINIT:
466 case WM_INITMENU:
467 case UM_INITMENU:
468 case UM_CONTAINER_FILLED:
469 case UM_FILESMENU:
470 case UM_UPDATERECORD:
471 case UM_UPDATERECORDLIST:
472 return WinSendMsg(WinWindowFromID(hwnd, COLLECTOR_CNR), msg, mp1, mp2);
473
474 case WM_PSETFOCUS:
475 case WM_SETFOCUS:
476 if (mp2)
477 PostMsg(hwnd, UM_FOCUSME, MPVOID, MPVOID);
478 break;
479
480 case UM_FOCUSME:
481 WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, COLLECTOR_CNR));
482 break;
483
484 case WM_PAINT:
485 {
486 HPS hps;
487 RECTL rcl;
488
489 hps = WinBeginPaint(hwnd, NULLHANDLE, NULL);
490 if (hps) {
491 WinQueryWindowRect(hwnd, &rcl);
492 WinFillRect(hps, &rcl, CLR_PALEGRAY);
493 CommonTextPaint(hwnd, hps);
494 WinEndPaint(hps);
495 }
496 }
497 break;
498
499 case UM_SIZE:
500 case WM_SIZE:
501 if (msg == UM_SIZE) {
502 SWP swp;
503
504 WinQueryWindowPos(hwnd, &swp);
505 mp1 = MPFROM2SHORT(swp.cx, swp.cy);
506 mp2 = MPFROM2SHORT(swp.cx, swp.cy);
507 }
508 {
509 USHORT cx, cy, bx;
510
511 cx = SHORT1FROMMP(mp2);
512 cy = SHORT2FROMMP(mp2);
513 WinSetWindowPos(WinWindowFromID(hwnd, COLLECTOR_CNR), HWND_TOP,
514 0, 0, cx, cy - 24, SWP_SHOW | SWP_MOVE | SWP_SIZE);
515 WinSetWindowPos(WinWindowFromID(hwnd, DIR_TOTALS), HWND_TOP,
516 2,
517 cy - 22,
518 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
519 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SELECTED), HWND_TOP,
520 2 + (cx / 3) + 2,
521 cy - 22,
522 (cx / 3) - 2, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
523 bx = (cx - (2 + (((cx / 3) + 2) * 2))) / 3;
524 WinSetWindowPos(WinWindowFromID(hwnd, DIR_VIEW), HWND_TOP,
525 2 + (((cx / 3) + 2) * 2),
526 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
527 WinSetWindowPos(WinWindowFromID(hwnd, DIR_SORT), HWND_TOP,
528 2 + (((cx / 3) + 2) * 2) + bx,
529 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
530 WinSetWindowPos(WinWindowFromID(hwnd, DIR_FILTER), HWND_TOP,
531 2 + (((cx / 3) + 2) * 2) + (bx * 2),
532 cy - 22, bx - 4, 20, SWP_SHOW | SWP_MOVE | SWP_SIZE);
533 }
534 CommonTextPaint(hwnd, NULLHANDLE);
535 if (msg == UM_SIZE) {
536 WinSetWindowPos(WinQueryWindow(hwnd, QW_PARENT), HWND_TOP, 0, 0, 0, 0,
537 SWP_SHOW | SWP_ZORDER | SWP_ACTIVATE);
538 return 0;
539 }
540 break;
541
542 case UM_COMMAND:
543 case WM_COMMAND:
544 case WM_CONTROL:
545 case WM_CLOSE:
546 return WinSendMsg(WinWindowFromID(hwnd, COLLECTOR_CNR), msg, mp1, mp2);
547 }
548 return WinDefWindowProc(hwnd, msg, mp1, mp2);
549}
550
551MRESULT EXPENTRY CollectorObjWndProc(HWND hwnd, ULONG msg,
552 MPARAM mp1, MPARAM mp2)
553{
554 ULONG size;
555 DIRCNRDATA *dcd;
556
557 switch (msg) {
558 case WM_CREATE:
559 // 18 Jul 08 SHL fixme to doc why messsage gets lost
560 DbgMsg(pszSrcFile, __LINE__, "WM_CREATE mp1 %p mp2 %p", mp1, mp2); // 18 Jul 08 SHL fixme
561 break;
562
563 case DM_PRINTOBJECT:
564 return MRFROMLONG(DRR_TARGET);
565
566 case DM_DISCARDOBJECT:
567 dcd = INSTDATA(hwnd);
568 if (fFM2Deletes && dcd) {
569 LISTINFO *li;
570 CNRDRAGINFO cni;
571
572 cni.pRecord = NULL;
573 cni.pDragInfo = (PDRAGINFO) mp1;
574 li = DoFileDrop(dcd->hwndCnr, NULL, FALSE, MPVOID, MPFROMP(&cni));
575 CheckPmDrgLimit(cni.pDragInfo);
576 if (li) {
577 li->type = fDefaultDeletePerm ? IDM_PERMDELETE : IDM_DELETE;
578 if (!PostMsg(hwnd, UM_MASSACTION, MPFROMP(li), MPVOID))
579 FreeListInfo(li);
580 else
581 return MRFROMLONG(DRR_SOURCE);
582 }
583 }
584 return MRFROMLONG(DRR_TARGET);
585
586 case UM_UPDATERECORDLIST:
587 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
588 if (dcd && mp1) {
589 INT numentries = 0;
590 CHAR **list = (CHAR **) mp1;
591
592 while (list[numentries])
593 numentries++;
594 if (numentries)
595 UpdateCnrList(dcd->hwndCnr, list, numentries, FALSE, dcd);
596 }
597 return 0;
598
599 case UM_SETUP:
600# ifdef FORTIFY
601 Fortify_EnterScope();
602# endif
603 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
604 if (dcd) {
605# ifdef FORTIFY
606 Fortify_BecomeOwner(dcd);
607# endif
608 // set unique id
609 WinSetWindowUShort(hwnd,
610 QWS_ID,
611 COLLECTOROBJ_FRAME + (COLLECTOR_FRAME - dcd->id));
612 dcd->hwndObject = hwnd;
613 // 09 Feb 08 SHL fixme to be sure applet does not really need this
614 // if (ParentIsDesktop(hwnd, dcd->hwndParent))
615 // DosSleep(100); //05 Aug 07 GKY 250
616 }
617 else
618 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
619 return 0;
620
621 case UM_COMMAND:
622 if (mp1) {
623 LISTINFO *li = (LISTINFO *) mp1;
624
625 switch (li->type) {
626 case IDM_DOITYOURSELF:
627 case IDM_APPENDTOCLIP:
628 case IDM_APPENDTOCLIPFILENAME:
629 case IDM_SAVETOCLIP:
630 case IDM_ARCHIVE:
631 case IDM_ARCHIVEM:
632 case IDM_VIEW:
633 case IDM_VIEWTEXT:
634 case IDM_VIEWBINARY:
635 case IDM_VIEWARCHIVE:
636 case IDM_EDIT:
637 case IDM_EDITTEXT:
638 case IDM_EDITBINARY:
639 case IDM_OBJECT:
640 case IDM_SHADOW:
641 case IDM_SHADOW2:
642 case IDM_JAVAEXE:
643 case IDM_PRINT:
644 case IDM_ATTRS:
645 case IDM_DELETE:
646 case IDM_PERMDELETE:
647 case IDM_FAKEEXTRACT:
648 case IDM_FAKEEXTRACTM:
649 case IDM_MCIPLAY:
650 case IDM_UPDATE:
651 if (li->type == IDM_DELETE)
652 ignorereadonly = FALSE;
653 if (PostMsg(hwnd, UM_MASSACTION, mp1, mp2))
654 return (MRESULT) TRUE;
655 break;
656 default:
657 if (PostMsg(hwnd, UM_ACTION, mp1, mp2))
658 return (MRESULT) TRUE;
659 }
660 }
661 return 0;
662
663 case UM_COLLECT:
664 DosError(FERR_DISABLEHARDERR);
665 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
666 if (dcd) {
667 LISTINFO *li = (LISTINFO *) mp1;
668 INT x;
669 FILEFINDBUF4L fb4;
670 HDIR hdir;
671 ULONG ulMaxFiles;
672 CHAR fullname[CCHMAXPATH];
673
674 if (!hwndStatus) {
675 WinSetWindowText(WinWindowFromID(dcd->hwndClient, DIR_SELECTED),
676 (CHAR *) GetPString(IDS_COLLECTINGTEXT));
677 }
678 else {
679 if (WinQueryFocus(HWND_DESKTOP) == dcd->hwndCnr)
680 WinSetWindowText(hwndStatus, (CHAR *) GetPString(IDS_COLLECTINGTEXT));
681 }
682
683 for (ulMaxFiles = 0; li->list[ulMaxFiles]; ulMaxFiles++) ; // Count
684
685 if (ulMaxFiles) {
686 PCNRITEM pci = NULL;
687 PCNRITEM pciFirst = NULL;
688 PCNRITEM pciPrev;
689 ULONG nm;
690 ULONG ulRecsAtStart;
691 ULONG ulRecsToInsert;
692 ULONG ulRecsInserted = 0;
693 ULONGLONG ullTotalBytes = 0;
694 BOOL checkToInsert = FALSE;
695 CNRINFO cnri;
696 RECORDINSERT ri;
697 ITIMER_DESC itdSleep = { 0 }; // 06 Feb 08 SHL
698
699 InitITimer(&itdSleep, 500); // Sleep every 500 mSec
700
701 // Query initial count
702 // 2011-05-29 SHL fixme to be utility
703 memset(&cnri, 0, sizeof(CNRINFO));
704 cnri.cb = sizeof(CNRINFO);
705 if (WinSendMsg(dcd->hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
706 MPFROMLONG(sizeof(CNRINFO)))) {
707 ulRecsAtStart = cnri.cRecords;
708 }
709 else {
710 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__, PCSZ_QUERYCNRINFO);
711 ulRecsAtStart = 0;
712 }
713
714 for (x = 0; li->list[x]; x++) {
715
716 // Allocate more container items if needed
717 if (!pci) {
718 ulRecsToInsert = ulMaxFiles - ulRecsInserted; // Left to do
719 if (ulRecsToInsert > USHRT_MAX)
720 ulRecsToInsert = USHRT_MAX; // Avoid USHORT overflows
721 pci = WinSendMsg(dcd->hwndCnr, CM_ALLOCRECORD,
722 MPFROMLONG(EXTRA_RECORD_BYTES),
723 MPFROMLONG(ulRecsToInsert));
724 pciFirst = pci;
725 pciPrev = NULL;
726 if (!pci) {
727 Runtime_Error(pszSrcFile, __LINE__, PCSZ_CM_ALLOCRECORD);
728 break;
729 }
730 } // if need allocate
731
732 nm = 1;
733 hdir = HDIR_CREATE;
734 DosError(FERR_DISABLEHARDERR);
735 // If started with records in container, check if updating existing record
736 if (ulRecsAtStart &&
737 FindCnrRecord(dcd->hwndCnr,
738 li->list[x],
739 NULL,
740 FALSE,
741 FALSE,
742 TRUE))
743 {
744 // Updating existing record
745 PCNRITEM pciUpd = UpdateCnrRecord(dcd->hwndCnr, li->list[x], FALSE, dcd);
746 if (!pciUpd) {
747 // file has disappeared
748 Runtime_Error(pszSrcFile, __LINE__, "pci NULL for list[%u]", x);
749 }
750 else {
751 // Update OK
752 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
753 if (dcd && Filter((PMINIRECORDCORE) pciUpd, (PVOID) & dcd->mask)) {
754 pciUpd->rc.flRecordAttr &= ~CRA_FILTERED; // Ensure visible
755 // 2011-05-29 SHL fixme to check fail
756 WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID,
757 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
758 }
759 DosReleaseMutexSem(hmtxFiltering);
760 }
761 ulMaxFiles--; // No insert needed
762 checkToInsert = TRUE;
763 }
764 // Add new entry maybe
765 else if (*li->list[x] &&
766 !DosQueryPathInfo(li->list[x], FIL_QUERYFULLNAME,
767 fullname, sizeof(fullname)) &&
768 !IsRoot(fullname) &&
769 !xDosFindFirst(fullname,
770 &hdir,
771 FILE_NORMAL | FILE_DIRECTORY |
772 FILE_ARCHIVED | FILE_SYSTEM |
773 FILE_HIDDEN | FILE_READONLY,
774 &fb4, sizeof(fb4), &nm, FIL_QUERYEASIZEL))
775 {
776 // OK to add
777 DosFindClose(hdir);
778 priority_normal();
779 *fb4.achName = 0;
780 ullTotalBytes += FillInRecordFromFFB(dcd->hwndCnr,
781 pci,
782 fullname, &fb4, FALSE, dcd);
783 pciPrev = pci;
784 pci = (PCNRITEM) pci->rc.preccNextRecord;
785 }
786 else {
787 // DosQueryPathInfo etc. failed - try to recover
788 Runtime_Error(pszSrcFile, __LINE__, "DosQueryPathInfo failed for %s", fullname);
789 ulMaxFiles--; // Nothing to insert
790 checkToInsert = TRUE;
791 }
792
793 if (checkToInsert) {
794 checkToInsert = FALSE;
795 // Remove extra records from chain
796 while (ulRecsInserted + ulRecsToInsert > ulMaxFiles) {
797 PCNRITEM pciNext = (PCNRITEM)pci->rc.preccNextRecord;
798 if (pciPrev)
799 pciPrev->rc.preccNextRecord = (PMINIRECORDCORE)pciNext;
800 else
801 pciFirst = pciNext;
802 pci->pszFileName = NullStr; // Avoid spurious complaints
803 FreeCnrItem(dcd->hwndCnr, pci);
804 pci = pciNext;
805 ulRecsToInsert--; // Remember gone
806 }
807 }
808
809 // Check if time to insert
810 if (!pci) {
811 // All allocated CNRITEMs filled
812 if (ulRecsToInsert) {
813 // Have CNRITEMs to insert
814 memset(&ri, 0, sizeof(RECORDINSERT));
815 ri.cb = sizeof(RECORDINSERT);
816 ri.pRecordOrder = (PRECORDCORE) CMA_END;
817 ri.pRecordParent = (PRECORDCORE) 0;
818 ri.zOrder = (ULONG) CMA_TOP;
819 ri.cRecordsInsert = ulRecsToInsert;
820 ri.fInvalidateRecord = TRUE;
821 WinSendMsg(dcd->hwndCnr,
822 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri));
823 // 2011-05-29 SHL fixme to complain on failure
824 PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
825 ulRecsInserted += ulRecsToInsert;
826 dcd->ullTotalBytes = ullTotalBytes;
827 pciFirst = NULL;
828 ulRecsToInsert = 0;
829 }
830 } // if need CM_INSERTRECORD
831 SleepIfNeeded(&itdSleep, 1); // 09 Feb 08 SHL
832 } // for
833
834 // Clean up in case stopped early by error
835 if (pci)
836 Runtime_Error(pszSrcFile, __LINE__, "pci not NULL");
837
838 if (pciFirst) {
839 Runtime_Error(pszSrcFile, __LINE__, "pciFirst not NULL");
840 // 2011-08-08 SHL fixme to initialze pszFileName to prevent spurious complaints
841 FreeCnrItemList(dcd->hwndCnr, pciFirst);
842 }
843
844 } // if have files
845
846 if (dcd->flWindowAttr & CV_DETAIL)
847 WinSendDlgItemMsg(hwnd,
848 COLLECTOR_CNR,
849 CM_INVALIDATERECORD,
850 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
851 } // if dcd
852 return 0;
853
854 case UM_COLLECTFROMFILE:
855 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
856# ifdef FORTIFY
857 Fortify_EnterScope();
858# endif
859
860 if (dcd && mp1) {
861 // mp1 is pszFileName, mp2 is unused
862 FILESTATUS4L fs4;
863 PCNRITEM pci;
864 RECORDINSERT ri;
865 CHAR fullname[1024], *p;
866 FILE *fp;
867 ULONG errs = 0;
868 BOOL first = TRUE; // 2012-09-05 SHL
869 size_t c;
870 CHAR *moder = "r";
871
872# ifdef FORTIFY
873 Fortify_BecomeOwner(mp1);
874# endif
875
876 fp = xfsopen((CHAR *)mp1, moder, SH_DENYNO, pszSrcFile, __LINE__, TRUE);
877 if (fp) {
878 while (!feof(fp)) {
879 // Avoid too much noise if collecting from binary file - oops
880 if (!fgets(fullname, sizeof(fullname), fp)) {
881 if (ferror(fp))
882 Runtime_Error(pszSrcFile, __LINE__, "fgets");
883 break;
884 }
885
886 c = strlen(fullname);
887 if (c + 1 >= sizeof(fullname))
888 errs++; // Name too long
889 else if (!c || (fullname[c - 1] != '\n' && fullname[c - 1] != '\r'))
890 errs++; // Probably reading a binary file
891 else {
892 bstripcr(fullname);
893
894 if (*fullname == '\"') {
895 // Strip quotes
896 memmove(fullname, fullname + 1, strlen(fullname) + 1);
897 lstrip(fullname);
898 p = strchr(fullname, '\"');
899 if (p)
900 *p = 0;
901 rstrip(fullname);
902 }
903 else {
904 // Strip trailing spaces
905 p = strchr(fullname, ' ');
906 if (p)
907 *p = 0;
908 }
909 // fullname now contains name of file to collect
910 DosError(FERR_DISABLEHARDERR);
911 if (FindCnrRecord(dcd->hwndCnr,
912 fullname,
913 NULL,
914 FALSE,
915 FALSE,
916 TRUE)) {
917 // Already in container
918 pci = UpdateCnrRecord(dcd->hwndCnr, fullname, FALSE, dcd);
919 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
920 if (dcd && Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask)) {
921 pci->rc.flRecordAttr &= ~CRA_FILTERED;
922 WinSendMsg(dcd->hwndCnr, CM_INVALIDATERECORD, MPVOID,
923 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
924 }
925 DosReleaseMutexSem(hmtxFiltering);
926 }
927 else if (IsFullName(fullname) &&
928 !IsRoot(fullname) &&
929 !DosQueryPathInfo(fullname,
930 FIL_QUERYEASIZEL,
931 &fs4,
932 sizeof(fs4))) {
933 // Add to collector containter
934 pci = WinSendMsg(dcd->hwndCnr,
935 CM_ALLOCRECORD,
936 MPFROMLONG(EXTRA_RECORD_BYTES),
937 MPFROMLONG(1));
938 if (pci) {
939 dcd->ullTotalBytes += FillInRecordFromFSA(dcd->hwndCnr, pci,
940 fullname,
941 &fs4, FALSE, NULL, dcd);
942 memset(&ri, 0, sizeof(RECORDINSERT));
943 ri.cb = sizeof(RECORDINSERT);
944 ri.pRecordOrder = (PRECORDCORE) CMA_END;
945 ri.pRecordParent = (PRECORDCORE) 0;
946 ri.zOrder = (ULONG) CMA_TOP;
947 ri.cRecordsInsert = 1;
948 ri.fInvalidateRecord = TRUE;
949 WinSendMsg(dcd->hwndCnr, CM_INSERTRECORD,
950 MPFROMP(pci), MPFROMP(&ri));
951 }
952 }
953 else
954 errs++; // Something wrong with filename or file
955 }
956 if (errs > (first ? 0 : 50)) {
957 // prevent runaway on bad file
958 APIRET ret = saymsg(MB_YESNO, dcd->hwndCnr,
959 GetPString(IDS_COLLECTNOLISTHDRTEXT),
960 GetPString(IDS_COLLECTNOLISTTEXT),
961 (CHAR *)mp1);
962
963 if (ret == MBID_NO)
964 break; // Give up
965 if (!first)
966 errs = 0;
967 else
968 first = FALSE;
969 }
970 } // while not eof
971 fclose(fp);
972 } // if file opened
973 free(mp1);
974 }
975# ifdef FORTIFY
976 Fortify_LeaveScope();
977# endif
978 return 0;
979
980 case UM_SELECT:
981 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
982 if (dcd) {
983 switch (SHORT1FROMMP(mp1)) {
984 case IDM_SELECTLIST:
985 {
986 CHAR filename[CCHMAXPATH], *p, *pp;
987
988 strcpy(filename, PCSZ_STARDOTLST);
989 size = CCHMAXPATH;
990 PrfQueryProfileData(fmprof, appname, "SaveToListName", filename,
991 &size);
992 pp = strrchr(filename, '\\');
993 if (!pp)
994 pp = filename;
995 p = strrchr(pp, '.');
996 if (p && *(p + 1) && p > pp + 1) {
997 if (pp > filename)
998 pp++;
999 *pp = '*';
1000 pp++;
1001 if (p > pp)
1002 memmove(pp, p, strlen(p) + 1);
1003 }
1004 if (insert_filename(hwnd, filename, FALSE, FALSE))
1005 SelectList(dcd->hwndCnr, TRUE, FALSE, FALSE, NULL, filename,
1006 NULL);
1007 }
1008 break;
1009 case IDM_SELECTALL:
1010 SelectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, FALSE);
1011 break;
1012 case IDM_DESELECTALL:
1013 DeselectAll(dcd->hwndCnr, TRUE, TRUE, NULL, NULL, FALSE);
1014 break;
1015 case IDM_SELECTALLFILES:
1016 SelectAll(dcd->hwndCnr, TRUE, FALSE, NULL, NULL, FALSE);
1017 break;
1018 case IDM_DESELECTALLFILES:
1019 DeselectAll(dcd->hwndCnr, TRUE, FALSE, NULL, NULL, FALSE);
1020 break;
1021 case IDM_SELECTALLDIRS:
1022 SelectAll(dcd->hwndCnr, FALSE, TRUE, NULL, NULL, FALSE);
1023 break;
1024 case IDM_DESELECTALLDIRS:
1025 DeselectAll(dcd->hwndCnr, FALSE, TRUE, NULL, NULL, FALSE);
1026 break;
1027 case IDM_DESELECTMASK:
1028 case IDM_SELECTMASK:
1029 {
1030 MASK mask;
1031 PCNRITEM pci = (PCNRITEM) mp2;
1032
1033 memset(&mask, 0, sizeof(MASK));
1034 mask.fNoAttribs = TRUE;
1035 mask.fNoDirs = TRUE;
1036 mask.fText = TRUE;
1037 strcpy(mask.prompt,
1038 GetPString((SHORT1FROMMP(mp1) == IDM_SELECTMASK) ?
1039 IDS_SELECTFILTERTEXT : IDS_DESELECTFILTERTEXT));
1040 if (pci && (INT) pci != -1)
1041 strcpy(mask.szMask, pci->pszFileName);
1042 if (WinDlgBox(HWND_DESKTOP, dcd->hwndCnr, PickMaskDlgProc,
1043 FM3ModHandle, MSK_FRAME, MPFROMP(&mask))) {
1044 if (SHORT1FROMMP(mp1) == IDM_SELECTMASK)
1045 SelectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, mask.szText,
1046 FALSE);
1047 else
1048 DeselectAll(dcd->hwndCnr, TRUE, TRUE, mask.szMask, mask.szText,
1049 FALSE);
1050 }
1051 }
1052
1053 case IDM_DESELECTCLIP:
1054 case IDM_SELECTCLIP:
1055 {
1056 CHAR **list;
1057
1058 list = ListFromClipboard(hwnd);
1059 if (list) {
1060 SelectList(dcd->hwndCnr, TRUE, FALSE,
1061 (SHORT1FROMMP(mp1) == IDM_DESELECTCLIP),
1062 NULL, NULL, list);
1063 FreeList(list);
1064 }
1065 }
1066 break;
1067
1068 case IDM_INVERT:
1069 InvertAll(dcd->hwndCnr);
1070 break;
1071 }
1072 }
1073 return 0;
1074
1075 case UM_MASSACTION:
1076# ifdef FORTIFY
1077 Fortify_EnterScope();
1078# endif
1079 if (mp1) {
1080# ifdef FORTIFY
1081 Fortify_BecomeOwner(mp1);
1082# endif
1083 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1084 if (dcd) {
1085 WORKER *wk;
1086 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
1087 if (!wk)
1088 FreeListInfo((LISTINFO *) mp1);
1089 else {
1090 wk->size = sizeof(WORKER);
1091 wk->hwndCnr = dcd->hwndCnr;
1092 wk->hwndParent = dcd->hwndParent;
1093 wk->hwndFrame = dcd->hwndFrame;
1094 wk->hwndClient = dcd->hwndClient;
1095 wk->li = (LISTINFO *) mp1;
1096 strcpy(wk->directory, dcd->directory);
1097 if (xbeginthread(MassAction,
1098 122880,
1099 wk,
1100 pszSrcFile,
1101 __LINE__) == -1)
1102 {
1103 free(wk);
1104 FreeListInfo((LISTINFO *) mp1);
1105 }
1106 }
1107 }
1108 }
1109# ifdef FORTIFY
1110 DosSleep(1); // Let receiver take ownership
1111 Fortify_LeaveScope();
1112# endif
1113 return 0;
1114
1115 case UM_ACTION:
1116# ifdef FORTIFY
1117 Fortify_EnterScope();
1118# endif
1119 if (mp1) {
1120# ifdef FORTIFY
1121 Fortify_BecomeOwner(mp1);
1122# endif
1123 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1124 if (dcd) {
1125 WORKER *wk;
1126 wk = xmallocz(sizeof(WORKER), pszSrcFile, __LINE__);
1127 if (!wk)
1128 FreeListInfo((LISTINFO *) mp1);
1129 else {
1130 wk->size = sizeof(WORKER);
1131 wk->hwndCnr = dcd->hwndCnr;
1132 wk->hwndParent = dcd->hwndParent;
1133 wk->hwndFrame = dcd->hwndFrame;
1134 wk->hwndClient = dcd->hwndClient;
1135 wk->li = (LISTINFO *) mp1;
1136 strcpy(wk->directory, dcd->directory);
1137 if (xbeginthread(Action,
1138 122880,
1139 wk,
1140 pszSrcFile,
1141 __LINE__) == -1)
1142 {
1143 free(wk);
1144 FreeListInfo((LISTINFO *) mp1);
1145 }
1146 }
1147 }
1148 }
1149# ifdef FORTIFY
1150 DosSleep(1); // Let receiver take ownership
1151 Fortify_LeaveScope();
1152# endif
1153 return 0;
1154
1155 case WM_CLOSE:
1156 WinDestroyWindow(hwnd);
1157 break;
1158
1159 case WM_DESTROY:
1160 dcd = WinQueryWindowPtr(hwnd, QWL_USER);
1161 if (dcd) {
1162 INT x;
1163
1164 dcd->stopflag = 1;
1165 // Allow other threads to honor stop request
1166 for (x = 0; x < 100 && dcd->amextracted; x++)
1167 DosSleep(10);
1168 if (dcd->amextracted)
1169 Runtime_Error(pszSrcFile, __LINE__, "still busy");
1170 WinSendMsg(dcd->hwndCnr, UM_CLOSE, MPVOID, MPVOID);
1171 FreeList(dcd->lastselection);
1172 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, NULL); // 13 Apr 10 SHL Set NULL before freeing dcd
1173 DosRequestMutexSem(hmtxFiltering, SEM_INDEFINITE_WAIT);
1174 free(dcd);
1175 dcd = NULL;
1176 DosReleaseMutexSem(hmtxFiltering);
1177# ifdef FORTIFY
1178 Fortify_LeaveScope();
1179# endif
1180 }
1181 DosPostEventSem(CompactSem);
1182 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
1183 WinSendMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID);
1184 break;
1185 }
1186 return WinDefWindowProc(hwnd, msg, mp1, mp2);
1187}
1188
1189MRESULT EXPENTRY CollectorCnrWndProc(HWND hwnd, ULONG msg, MPARAM mp1,
1190 MPARAM mp2)
1191{
1192 DIRCNRDATA *dcd = INSTDATA(hwnd);
1193 ULONG size;
1194
1195 static INT savedSortFlags;
1196
1197 switch (msg) {
1198 case DM_PRINTOBJECT:
1199 return MRFROMLONG(DRR_TARGET);
1200
1201 case DM_DISCARDOBJECT:
1202 if (dcd)
1203 return WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
1204 else
1205 return MRFROMLONG(DRR_TARGET);
1206
1207 case WM_CHAR:
1208 shiftstate = (SHORT1FROMMP(mp1) & (KC_SHIFT | KC_ALT | KC_CTRL));
1209 if (SHORT1FROMMP(mp1) & KC_KEYUP)
1210 return (MRESULT) TRUE;
1211 if (SHORT1FROMMP(mp1) & KC_VIRTUALKEY) {
1212 switch (SHORT2FROMMP(mp2)) {
1213 case VK_DELETE:
1214 if ((shiftstate & KC_CTRL) == KC_CTRL)
1215 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_PERMDELETE, 0), MPVOID);
1216 else if ((shiftstate & KC_SHIFT) == KC_SHIFT)
1217 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_SAVETOCLIP, 0), MPVOID);
1218 else
1219 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DELETE, 0), MPVOID);
1220 break;
1221 }
1222 }
1223 if (shiftstate || fNoSearch)
1224 break;
1225 if (SHORT1FROMMP(mp1) & KC_CHAR) {
1226 ULONG thistime, len;
1227 SEARCHSTRING srch;
1228 PCNRITEM pci;
1229
1230 if (!dcd)
1231 break;
1232 switch (SHORT1FROMMP(mp2)) {
1233 case '\x1b':
1234 case '\r':
1235 case '\n':
1236 dcd->lasttime = 0;
1237 *dcd->szCommonName = 0;
1238 break;
1239 default:
1240 thistime = WinQueryMsgTime(WinQueryAnchorBlock(hwnd));
1241 if (thistime > dcd->lasttime + 1250)
1242 *dcd->szCommonName = 0;
1243 dcd->lasttime = thistime;
1244 if (SHORT1FROMMP(mp2) == ' ' && !dcd->szCommonName)
1245 break;
1246 KbdRetry:
1247 len = strlen(dcd->szCommonName);
1248 if (len >= CCHMAXPATH - 1) {
1249 *dcd->szCommonName = 0;
1250 len = 0;
1251 }
1252 dcd->szCommonName[len] = toupper(SHORT1FROMMP(mp2));
1253 dcd->szCommonName[len + 1] = 0;
1254 memset(&srch, 0, sizeof(SEARCHSTRING));
1255 srch.cb = sizeof(SEARCHSTRING);
1256 srch.pszSearch = dcd->szCommonName;
1257 srch.fsPrefix = TRUE;
1258 srch.fsCaseSensitive = FALSE;
1259 srch.usView = CV_ICON;
1260 pci = WinSendMsg(hwnd, CM_SEARCHSTRING, MPFROMP(&srch),
1261 MPFROMLONG(CMA_FIRST));
1262 if (pci && (INT) pci != -1) {
1263 USHORT attrib = CRA_CURSORED;
1264
1265 // make found item current item
1266 if (!stricmp(pci->pszFileName, dcd->szCommonName))
1267 attrib |= CRA_SELECTED;
1268 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
1269 MPFROM2SHORT(TRUE, attrib));
1270 // make sure that record shows in viewport
1271 ShowCnrRecord(hwnd, (PMINIRECORDCORE) pci);
1272 return (MRESULT) TRUE;
1273 }
1274 else {
1275 if (SHORT1FROMMP(mp2) == ' ') {
1276 dcd->szCommonName[len] = 0;
1277 break;
1278 }
1279 *dcd->szCommonName = 0;
1280 dcd->lasttime = 0;
1281 if (len) // retry as first letter if no match
1282
1283 goto KbdRetry;
1284 }
1285 break;
1286 }
1287 }
1288 break;
1289
1290 case WM_MOUSEMOVE:
1291 case WM_BUTTON1UP:
1292 case WM_BUTTON2UP:
1293 case WM_BUTTON3UP:
1294 case WM_CHORD:
1295 shiftstate = (SHORT2FROMMP(mp2) & (KC_SHIFT | KC_ALT | KC_CTRL));
1296 break;
1297
1298 case WM_BUTTON1MOTIONEND:
1299 {
1300 CNRINFO cnri;
1301
1302 memset(&cnri, 0, sizeof(CNRINFO));
1303 cnri.cb = sizeof(CNRINFO);
1304 if (WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
1305 MPFROMLONG(sizeof(CNRINFO)))) {
1306 if (cnri.flWindowAttr & CV_DETAIL)
1307 PrfWriteProfileData(fmprof, appname, "CollectorCnrSplitBar",
1308 (PVOID) & cnri.xVertSplitbar, sizeof(LONG));
1309 }
1310 }
1311 break;
1312
1313 case WM_PRESPARAMCHANGED:
1314 PresParamChanged(hwnd, PCSZ_COLLECTOR, mp1, mp2);
1315 break;
1316
1317 case UM_COMPARE:
1318 if (dcd && mp1 && mp2) {
1319 COMPARE *cmp;
1320 CHAR *leftdir = (CHAR *)mp1, *rightdir = (CHAR *)mp2;
1321
1322 if (!IsFile(leftdir) && !IsFile(rightdir)) {
1323 cmp = xmallocz(sizeof(COMPARE), pszSrcFile, __LINE__);
1324 if (cmp) {
1325 cmp->size = sizeof(COMPARE);
1326 strcpy(cmp->leftdir, leftdir);
1327 strcpy(cmp->rightdir, rightdir);
1328 cmp->hwndParent = dcd->hwndParent;
1329 cmp->dcd.hwndParent = dcd->hwndParent;
1330 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, CompareDlgProc,
1331 FM3ModHandle, COMP_FRAME, MPFROMP(cmp));
1332 }
1333 }
1334 }
1335 return 0;
1336
1337 case UM_UPDATERECORDLIST:
1338 if (dcd && mp1)
1339 WinSendMsg(dcd->hwndObject, msg, mp1, mp2);
1340 return 0;
1341
1342 case UM_UPDATERECORD:
1343 if (dcd && mp1) {
1344 CHAR *filename;
1345
1346 filename = mp1;
1347 if (filename)
1348 UpdateCnrRecord(hwnd, filename, TRUE, dcd);
1349 }
1350 return 0;
1351
1352 case WM_SETFOCUS:
1353 // put name of our window on status line
1354 if (dcd && hwndStatus && mp2) {
1355 PCNRITEM pci = NULL;
1356
1357 if (fAutoView && hwndMain) {
1358 pci = WinSendMsg(hwnd,
1359 CM_QUERYRECORDEMPHASIS,
1360 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1361 if (pci && (INT) pci != -1 &&
1362 (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_SLOW)))
1363 WinSendMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName), MPVOID);
1364 else
1365 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1366 }
1367 if (dcd->amextracted)
1368 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_INSEEKSCANTEXT)); // Say working
1369 WinSendMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1370 }
1371 break;
1372
1373 case UM_RESCAN:
1374 if (dcd) {
1375 CNRINFO cnri;
1376 CHAR s[CCHMAXPATH + 69], tb[81], tf[81], szDate[DATE_BUF_BYTES] *p;
1377 PCNRITEM pci = NULL;
1378
1379 memset(&cnri, 0, sizeof(CNRINFO));
1380 cnri.cb = sizeof(CNRINFO);
1381 WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
1382 MPFROMLONG(sizeof(CNRINFO)));
1383 dcd->totalfiles = cnri.cRecords;
1384 commafmt(tf, sizeof(tf), dcd->totalfiles);
1385 CommaFmtULL(tb, sizeof(tb), dcd->ullTotalBytes, ' ');
1386 sprintf(s, "%s / %s", tf, tb);
1387 WinSetDlgItemText(dcd->hwndClient, DIR_TOTALS, s);
1388
1389 commafmt(tf, sizeof(tf), dcd->selectedfiles);
1390 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
1391 sprintf(s, "%s / %s", tf, tb);
1392 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
1393
1394 if (hwndStatus &&
1395 dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
1396 if (hwndMain) {
1397 pci = WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
1398 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1399 if (pci && (INT) pci != -1)
1400 PostMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName), MPVOID);
1401 else
1402 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
1403 }
1404 if (!dcd->amextracted) {
1405 if (!fMoreButtons) {
1406 sprintf(s, " %s%s%s%s",
1407 GetPString(IDS_COLLECTORTEXT),
1408 *dcd->mask.szMask || dcd->mask.antiattr ||
1409 dcd->mask.attrFile != ALLATTRS ? " (" : NullStr,
1410 *dcd->mask.szMask ?
1411 dcd->mask.szMask :
1412 dcd->mask.antiattr ||
1413 dcd->mask.attrFile != ALLATTRS ?
1414 GetPString(IDS_ATTRTEXT) : NullStr,
1415 *dcd->mask.szMask || dcd->mask.antiattr ||
1416 dcd->mask.attrFile != ALLATTRS ?
1417 ")" : NullStr);
1418 }
1419 else
1420 strcpy(s, GetPString(IDS_COLLECTORTEXT));
1421 WinSetWindowText(hwndStatus, s);
1422 }
1423 if (!pci)
1424 pci = WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
1425 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1426 if (pci && (INT) pci != -1) {
1427 BOOL fStatus2Used = FALSE;
1428
1429 if (fSplitStatus && hwndStatus2) {
1430 if (pci->attrFile & FILE_DIRECTORY)
1431 p = pci->pszFileName;
1432 else {
1433 if (!pci->pszFileName) {
1434 Runtime_Error(pszSrcFile, __LINE__, "pci->pszFileName NULL for %p", pci);
1435 return 0;
1436 }
1437 p = strrchr(pci->pszFileName, '\\');
1438 if (p) {
1439 if (*(p + 1))
1440 p++;
1441 else
1442 p = pci->pszFileName;
1443 }
1444 else
1445 p = pci->pszFileName;
1446 }
1447 CommaFmtULL(tb, sizeof(tb), pci->cbFile + pci->easize, ' ');
1448 if (!fMoreButtons) {
1449 DateFormat(szDate, pci->date);
1450 sprintf(s, " %s %s %02u%s%02u%s%02u [%s] %s",
1451 tb, szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
1452 TimeSeparator, pci->time.seconds, pci->pszDispAttr, p);
1453 }
1454 else {
1455 if (pci->cbFile + pci->easize > 1024)
1456 CommaFmtULL(tf, sizeof(tf), pci->cbFile + pci->easize, 'K');
1457 else
1458 *tf = 0;
1459 sprintf(s, GetPString(IDS_STATUSSIZETEXT),
1460 tb, *tf ? " (" : NullStr, tf, *tf ? ")" : NullStr);
1461 }
1462 WinSetWindowText(hwndStatus2, s);
1463 fStatus2Used = TRUE;
1464 }
1465 if (fMoreButtons) {
1466 WinSetWindowText(hwndName, pci->pszFileName);
1467 DateFormat(szDate, pci->date);
1468 sprintf(s, "%s %02u%s%02u%s%02u",
1469 szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
1470 TimeSeparator, pci->time.seconds);
1471 WinSetWindowText(hwndDate, s);
1472 WinSetWindowText(hwndAttr, pci->pszDispAttr);
1473 }
1474 if (dcd->amextracted && hwndStatus2 && !fStatus2Used)
1475 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_INSEEKSCANTEXT)); // Say working
1476 }
1477 else {
1478 if (hwndStatus2) {
1479 if (dcd->amextracted)
1480 WinSetWindowText(hwndStatus2, (CHAR *) GetPString(IDS_INSEEKSCANTEXT)); // Say working
1481 else
1482 WinSetWindowText(hwndStatus2, NullStr);
1483 }
1484 if (fMoreButtons) {
1485 WinSetWindowText(hwndName, NullStr);
1486 WinSetWindowText(hwndDate, NullStr);
1487 WinSetWindowText(hwndAttr, NullStr);
1488 }
1489 }
1490 }
1491 }
1492 return 0;
1493
1494 case UM_CONTAINER_FILLED:
1495 if (!fAlertBeepOff)
1496 DosBeep(1000, 50); // Wake up user?
1497 WinSendMsg(hwnd,
1498 CM_INVALIDATERECORD,
1499 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
1500 disable_menuitem(WinWindowFromID(WinQueryWindow(hwndMain, QW_PARENT),
1501 FID_MENU), IDM_GREP, FALSE);
1502 disable_menuitem(TreeMenu, IDM_GREP, FALSE);
1503 disable_menuitem(DirMenu, IDM_GREP, FALSE);
1504 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
1505 if (dcd) {
1506 dcd->stopflag = 0;
1507 dcd->amextracted = FALSE; // Say not busy
1508 if (dcd->namecanchange) {
1509 if (!PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID))
1510 WinSendMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1511 }
1512 else
1513 WinSetWindowPos(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
1514 QW_PARENT),
1515 HWND_TOP,
1516 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE | SWP_ZORDER);
1517 }
1518 return 0;
1519
1520 case UM_SETUP:
1521 if (dcd) {
1522 if (!dcd->hwndObject) {
1523 // first time through -- set things up
1524
1525 CNRINFO cnri;
1526
1527 RestorePresParams(hwnd, PCSZ_COLLECTOR);
1528 LoadDetailsSwitches(PCSZ_COLLECTOR, &dcd->ds, FALSE);
1529
1530 dcd->amextracted = FALSE; // Say not busy
1531 dcd->stopflag = 0;
1532 memset(&cnri, 0, sizeof(CNRINFO));
1533 cnri.cb = sizeof(CNRINFO);
1534 WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
1535 MPFROMLONG(sizeof(CNRINFO)));
1536 cnri.cyLineSpacing = 0;
1537 cnri.cxTreeIndent = 12;
1538
1539 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT | CV_DETAIL));
1540 cnri.flWindowAttr |= (CV_NAME | CA_DETAILSVIEWTITLES |
1541 CV_MINI | CV_FLOW);
1542 cnri.pSortRecord = (PVOID) SortCollectorCnr;
1543
1544 size = sizeof(ULONG);
1545 PrfQueryProfileData(fmprof, appname, "CollectorflWindowAttr",
1546 (PVOID) & cnri.flWindowAttr, &size);
1547 size = sizeof(MASK);
1548 if (PrfQueryProfileSize(fmprof, appname, "CollectorFilter", &size) &&
1549 size) {
1550 PrfQueryProfileData(fmprof, appname, "CollectorFilter", &dcd->mask,
1551 &size);
1552 SetMask(NULL, &dcd->mask);
1553 }
1554 else {
1555 dcd->mask.attrFile = (FILE_NORMAL | FILE_READONLY |
1556 FILE_DIRECTORY | FILE_HIDDEN |
1557 FILE_SYSTEM | FILE_ARCHIVED);
1558 dcd->mask.antiattr = 0;
1559 }
1560
1561 *(dcd->mask.prompt) = 0;
1562
1563 cnri.flWindowAttr |= CV_FLOW;
1564 cnri.flWindowAttr &= (~(CA_MIXEDTARGETEMPH | CA_ORDEREDTARGETEMPH));
1565 dcd->flWindowAttr = cnri.flWindowAttr;
1566 WinSendMsg(hwnd, CM_SETCNRINFO, MPFROMP(&cnri),
1567 MPFROMLONG(CMA_FLWINDOWATTR | CMA_LINESPACING |
1568 CMA_CXTREEINDENT | CMA_PSORTRECORD));
1569 SetCnrCols(hwnd, FALSE);
1570 AdjustCnrColsForPref(hwnd, NULL, &dcd->ds, FALSE);
1571
1572 // fix splitbar for collector container
1573 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
1574 size = sizeof(LONG);
1575 PrfQueryProfileData(fmprof, appname, "CollectorCnrSplitBar",
1576 &cnri.xVertSplitbar, &size);
1577 if (cnri.xVertSplitbar <= 0)
1578 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 32;
1579 WinSendMsg(hwnd, CM_SETCNRINFO, MPFROMP(&cnri),
1580 MPFROMLONG(CMA_XVERTSPLITBAR));
1581
1582 if (xbeginthread(MakeObjWin,
1583 245760,
1584 dcd,
1585 pszSrcFile,
1586 __LINE__) == -1)
1587 {
1588 Runtime_Error(pszSrcFile, __LINE__,
1589 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1590 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1591 return 0;
1592 }
1593 else
1594 DosSleep(32); // Let object window get started
1595 }
1596 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1597 DIR_FILTER), &dcd->mask, FALSE);
1598 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1599 DIR_SORT), CollectorsortFlags, FALSE);
1600 SayView(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1601 DIR_VIEW), dcd->flWindowAttr);
1602 }
1603 else {
1604 PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
1605 return 0;
1606 }
1607 return 0;
1608
1609 case WM_MENUEND:
1610 if (dcd) {
1611 HWND hwndMenu = (HWND) mp2;
1612
1613 if (hwndMenu == CollectorCnrMenu || hwndMenu == CollectorFileMenu ||
1614 hwndMenu == CollectorDirMenu) {
1615 MarkAll(hwnd, TRUE, FALSE, TRUE);
1616 if (dcd->cnremphasized) {
1617 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
1618 MPFROM2SHORT(FALSE, CRA_SOURCE));
1619 dcd->cnremphasized = FALSE;
1620 }
1621 }
1622 }
1623 break;
1624
1625 case UM_OPENWINDOWFORME:
1626 if (dcd) {
1627 if (mp1 && !IsFile((CHAR *)mp1))
1628 OpenDirCnr(HWND_DESKTOP, hwndMain, dcd->hwndFrame, FALSE, (PSZ) mp1);
1629 else if (mp1 && IsFile(mp1) == 1 &&
1630 CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2)
1631 StartArcCnr(HWND_DESKTOP,
1632 dcd->hwndFrame, (CHAR *)mp1, 4, (ARC_TYPE *) mp2);
1633 }
1634 return 0;
1635
1636 case MM_PORTHOLEINIT:
1637 if (dcd) {
1638 switch (SHORT1FROMMP(mp1)) {
1639 case 0:
1640 case 1:
1641 {
1642 ULONG wmsg;
1643
1644 wmsg = (SHORT1FROMMP(mp1) == 0) ? UM_FILESMENU : UM_VIEWSMENU;
1645 PortholeInit((HWND) WinSendMsg(dcd->hwndClient, wmsg, MPVOID,
1646 MPVOID), mp1, mp2);
1647 }
1648 break;
1649 }
1650 }
1651 break;
1652
1653 case UM_INITMENU:
1654 case WM_INITMENU:
1655 if (dcd) {
1656 switch (SHORT1FROMMP(mp1)) {
1657 case IDM_VIEWSMENU:
1658 SetViewMenu((HWND) mp2, dcd->flWindowAttr);
1659 WinEnableMenuItem((HWND) mp2, IDM_RESELECT,
1660 (dcd->lastselection != NULL));
1661 CopyPresParams((HWND) mp2, hwnd);
1662 break;
1663
1664 case IDM_DETAILSSETUP:
1665 SetDetailsSwitches((HWND) mp2, &dcd->ds);
1666 break;
1667
1668 case IDM_COMMANDSMENU:
1669 SetupCommandMenu((HWND) mp2, hwnd);
1670 break;
1671
1672 case IDM_SORTSUBMENU:
1673 SetSortChecks((HWND) mp2, CollectorsortFlags);
1674 break;
1675 }
1676 dcd->hwndLastMenu = (HWND) mp2;
1677 }
1678 if (msg == WM_INITMENU)
1679 break;
1680 return 0;
1681
1682 case UM_COLLECTFROMFILE:
1683 if (mp1) {
1684# ifdef FORTIFY
1685 Fortify_EnterScope();
1686 Fortify_BecomeOwner(mp1);
1687# endif
1688 if (!dcd) {
1689 Runtime_Error(pszSrcFile, __LINE__, NULL);
1690 free(mp1);
1691 }
1692 else {
1693 if (!PostMsg(dcd->hwndObject, UM_COLLECTFROMFILE, mp1, mp2)) {
1694 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
1695 free(mp1);
1696 }
1697 }
1698# ifdef FORTIFY
1699 DosSleep(1); // Let receiver take ownership
1700 Fortify_LeaveScope();
1701# endif
1702 }
1703 return 0;
1704
1705 case UM_COMMAND:
1706 if (mp1) {
1707 if (dcd) {
1708 if (!PostMsg(dcd->hwndObject, UM_COMMAND, mp1, mp2)) {
1709 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
1710 FreeListInfo((LISTINFO *) mp1);
1711 }
1712 else
1713 return (MRESULT) TRUE;
1714 }
1715 else
1716 FreeListInfo((LISTINFO *) mp1);
1717 }
1718 return 0;
1719
1720 case UM_NOTIFY:
1721 if (mp2)
1722 AddNote((CHAR *)mp2);
1723 return 0;
1724
1725 case WM_COMMAND:
1726 DosError(FERR_DISABLEHARDERR);
1727 if (dcd) {
1728 switch (SHORT1FROMMP(mp1)) {
1729 case IDM_SETTARGET:
1730 SetTargetDir(hwnd, FALSE, NULL);
1731 break;
1732
1733 case IDM_CONTEXTMENU:
1734 {
1735 PCNRITEM pci;
1736
1737 pci = (PCNRITEM) CurrentRecord(hwnd);
1738 PostMsg(hwnd, WM_CONTROL, MPFROM2SHORT(COLLECTOR_CNR,
1739 CN_CONTEXTMENU),
1740 MPFROMP(pci));
1741 }
1742 break;
1743
1744 case IDM_SHOWALLFILES:
1745 {
1746 PCNRITEM pci;
1747
1748 pci = WinSendMsg(hwnd,
1749 CM_QUERYRECORDEMPHASIS,
1750 MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
1751 if (pci && (INT) pci != -1) {
1752 static CHAR dirname[CCHMAXPATH];
1753
1754 strcpy(dirname, pci->pszFileName);
1755 MakeValidDir(dirname);
1756 StartSeeAll(HWND_DESKTOP, FALSE, dirname);
1757 }
1758 }
1759 break;
1760
1761 case IDM_BEGINEDIT:
1762 OpenEdit(hwnd);
1763 break;
1764
1765 case IDM_ENDEDIT:
1766 WinSendMsg(hwnd, CM_CLOSEEDIT, MPVOID, MPVOID);
1767 break;
1768
1769 case IDM_SHOWSELECT:
1770 QuickPopup(hwnd, dcd,
1771 CheckMenu(hwnd, &CollectorCnrMenu, COLLECTORCNR_POPUP),
1772 IDM_SELECTSUBMENU);
1773 break;
1774
1775 case IDM_SHOWSORT:
1776 QuickPopup(hwnd, dcd,
1777 CheckMenu(hwnd, &CollectorCnrMenu, COLLECTORCNR_POPUP),
1778 IDM_SORTSUBMENU);
1779 break;
1780
1781 case IDM_VIEWORARC:
1782 {
1783 SWP swp;
1784 PCNRITEM pci;
1785
1786 pci = (PCNRITEM) WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
1787 MPFROMLONG(CMA_FIRST),
1788 MPFROMSHORT(CRA_CURSORED));
1789 if (pci && (INT) pci != -1) {
1790 WinQueryWindowPos(dcd->hwndFrame, &swp);
1791 DefaultViewKeys(hwnd, dcd->hwndFrame, dcd->hwndParent, &swp,
1792 pci->pszFileName);
1793 }
1794 }
1795 break;
1796
1797 case IDM_SEEALL:
1798 StartSeeAll(HWND_DESKTOP, FALSE, NULL);
1799 break;
1800
1801 case IDM_COLLECTSELECT:
1802 {
1803 CHAR filename[CCHMAXPATH], *p, *pp;
1804
1805 strcpy(filename, PCSZ_STARDOTLST);
1806 size = CCHMAXPATH;
1807 PrfQueryProfileData(fmprof, appname, "SaveToListName",
1808 filename, &size);
1809 pp = strrchr(filename, '\\');
1810 if (!pp)
1811 pp = filename;
1812 p = strrchr(pp, '.');
1813 if (p && *(p + 1) && p > pp + 1) {
1814 if (pp > filename)
1815 pp++;
1816 *pp = '*';
1817 pp++;
1818 if (p > pp)
1819 memmove(pp, p, strlen(p) + 1);
1820 }
1821 if (insert_filename(hwnd, filename, FALSE, FALSE)) {
1822# ifdef FORTIFY
1823 Fortify_EnterScope();
1824# endif
1825 p = xstrdup(filename, pszSrcFile, __LINE__);
1826 if (p) {
1827 if (!PostMsg(hwnd, UM_COLLECTFROMFILE, MPFROMP(p), MPVOID))
1828 free(p);
1829 }
1830# ifdef FORTIFY
1831 DosSleep(1); // Let receiver take ownership
1832 Fortify_LeaveScope();
1833# endif
1834 }
1835 }
1836 break;
1837
1838 case IDM_COLLECTORVIEWSETTINGS:
1839 if (!ParentIsDesktop(dcd->hwndParent, dcd->hwndParent))
1840 PostMsg(dcd->hwndParent, msg, MPFROMLONG(IDM_COLLECTORVIEWSETTINGS), mp2);
1841 else {
1842 WinDlgBox(HWND_DESKTOP,
1843 hwnd,
1844 CfgDlgProc,
1845 FM3ModHandle,
1846 CFG_FRAME,
1847 MPFROMLONG(IDM_COLLECTORVIEWSETTINGS));
1848 }
1849 break;
1850
1851 case IDM_RESELECT:
1852 SelectList(hwnd, FALSE, FALSE, FALSE, NULL, NULL, dcd->lastselection);
1853 break;
1854
1855 case IDM_WALKDIR:
1856 case IDM_OPENDIRWINDOW:
1857 case IDM_OPENDIRICON:
1858 case IDM_OPENDIRDETAILS:
1859 case IDM_OPENDIRTREE:
1860 {
1861 CHAR newpath[CCHMAXPATH];
1862 PCNRITEM pci;
1863
1864 pci = (PCNRITEM) CurrentRecord(hwnd);
1865 if (pci && (INT) pci != -1) {
1866 strcpy(newpath, pci->pszFileName);
1867 MakeValidDir(newpath);
1868 }
1869 else
1870 strcpy(newpath, pFM2SaveDirectory);
1871 if (*newpath) {
1872 switch (SHORT1FROMMP(mp1)) {
1873 case IDM_WALKDIR:
1874 WinDlgBox(HWND_DESKTOP, dcd->hwndParent, WalkAllDlgProc,
1875 FM3ModHandle, WALK_FRAME, MPFROMP(newpath));
1876 break;
1877 case IDM_OPENDIRWINDOW:
1878 WinSendMsg(hwnd, UM_OPENWINDOWFORME, MPFROMP(newpath), MPVOID);
1879 break;
1880 case IDM_OPENDIRICON:
1881 OpenObject(newpath, PCSZ_ICON, hwnd);
1882 break;
1883 case IDM_OPENDIRDETAILS:
1884 OpenObject(newpath, Details, hwnd);
1885 break;
1886 case IDM_OPENDIRTREE:
1887 OpenObject(newpath, PCSZ_TREE, hwnd);
1888 break;
1889 default:
1890 break;
1891 }
1892 }
1893 }
1894 break;
1895
1896 case IDM_HELP:
1897 if (hwndHelp)
1898 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
1899 MPFROM2SHORT(HELP_COLLECT, 0),
1900 MPFROMSHORT(HM_RESOURCEID));
1901 break;
1902
1903 case IDM_SORTNONE:
1904 case IDM_SORTSMARTNAME:
1905 case IDM_SORTNAME:
1906 case IDM_SORTFILENAME:
1907 case IDM_SORTSIZE:
1908 case IDM_SORTEASIZE:
1909 case IDM_SORTFIRST:
1910 case IDM_SORTLAST:
1911 case IDM_SORTLWDATE:
1912 case IDM_SORTLADATE:
1913 case IDM_SORTCRDATE:
1914 case IDM_SORTSUBJECT:
1915 savedSortFlags = CollectorsortFlags;
1916 CollectorsortFlags &= (SORT_REVERSE | SORT_DIRSFIRST | SORT_DIRSLAST);
1917 case IDM_SORTDIRSFIRST:
1918 case IDM_SORTDIRSLAST:
1919 case IDM_SORTREVERSE:
1920 switch (SHORT1FROMMP(mp1)) {
1921 case IDM_SORTSUBJECT:
1922 CollectorsortFlags |= SORT_SUBJECT;
1923 break;
1924 case IDM_SORTNONE:
1925 CollectorsortFlags |= SORT_NOSORT;
1926 break;
1927 case IDM_SORTSMARTNAME:
1928 if (~savedSortFlags & SORT_FILENAME)
1929 CollectorsortFlags |= SORT_FILENAME;
1930 break;
1931 case IDM_SORTFILENAME:
1932 CollectorsortFlags |= SORT_FILENAME;
1933 break;
1934 case IDM_SORTSIZE:
1935 CollectorsortFlags |= SORT_SIZE;
1936 break;
1937 case IDM_SORTEASIZE:
1938 CollectorsortFlags |= SORT_EASIZE;
1939 break;
1940 case IDM_SORTFIRST:
1941 CollectorsortFlags |= SORT_FIRSTEXTENSION;
1942 break;
1943 case IDM_SORTLAST:
1944 CollectorsortFlags |= SORT_LASTEXTENSION;
1945 break;
1946 case IDM_SORTLWDATE:
1947 CollectorsortFlags |= SORT_LWDATE;
1948 break;
1949 case IDM_SORTLADATE:
1950 CollectorsortFlags |= SORT_LADATE;
1951 break;
1952 case IDM_SORTCRDATE:
1953 CollectorsortFlags |= SORT_CRDATE;
1954 break;
1955 case IDM_SORTDIRSFIRST:
1956 if (CollectorsortFlags & SORT_DIRSFIRST)
1957 CollectorsortFlags &= (~SORT_DIRSFIRST);
1958 else {
1959 CollectorsortFlags |= SORT_DIRSFIRST;
1960 CollectorsortFlags &= (~SORT_DIRSLAST);
1961 }
1962 break;
1963 case IDM_SORTDIRSLAST:
1964 if (CollectorsortFlags & SORT_DIRSLAST)
1965 CollectorsortFlags &= (~SORT_DIRSLAST);
1966 else {
1967 CollectorsortFlags |= SORT_DIRSLAST;
1968 CollectorsortFlags &= (~SORT_DIRSFIRST);
1969 }
1970 break;
1971 case IDM_SORTREVERSE:
1972 if (CollectorsortFlags & SORT_REVERSE)
1973 CollectorsortFlags &= (~SORT_REVERSE);
1974 else
1975 CollectorsortFlags |= SORT_REVERSE;
1976 break;
1977 }
1978 PrfWriteProfileData(fmprof, appname, "CollectorSort",
1979 &CollectorsortFlags, sizeof(INT));
1980 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortCollectorCnr), MPVOID);
1981 SaySort(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
1982 DIR_SORT), CollectorsortFlags, FALSE);
1983 break;
1984
1985 case IDM_COLLECTFROMCLIP:
1986 {
1987 LISTINFO *li;
1988# ifdef FORTIFY
1989 Fortify_EnterScope();
1990# endif
1991 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
1992 if (li) {
1993 li->list = ListFromClipboard(hwnd);
1994 if (!li->list || !li->list[0])
1995 FreeListInfo(li);
1996 else {
1997 li->type = IDM_COLLECT;
1998 if (!PostMsg(dcd->hwndObject, UM_COLLECT, MPFROMP(li), MPVOID))
1999 FreeListInfo(li);
2000 }
2001 }
2002# ifdef FORTIFY
2003 DosSleep(1); // Let receiver take ownership
2004 Fortify_LeaveScope();
2005# endif
2006 }
2007 break;
2008
2009 case IDM_REMOVE:
2010 if (fAutoView && hwndMain)
2011 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2012 dcd->suspendview = 1;
2013 RemoveAll(hwnd, &dcd->ullTotalBytes, &dcd->totalfiles);
2014 dcd->suspendview = 0;
2015 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2016 break;
2017
2018 case IDM_CLEARCNR:
2019 {
2020 PCNRITEM pci;
2021
2022 pci = (PCNRITEM) WinSendMsg(hwnd,
2023 CM_QUERYRECORD,
2024 MPVOID,
2025 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
2026 if (pci && (INT) pci != -1) {
2027 RemoveCnrItems(hwnd, NULL, 0, CMA_FREE | CMA_INVALIDATE);
2028 dcd->ullTotalBytes = dcd->selectedbytes = dcd->selectedfiles =
2029 dcd->totalfiles = 0;
2030 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2031 }
2032 }
2033 break;
2034
2035 case DID_CANCEL:
2036 if (dcd->amextracted)
2037 dcd->stopflag = 1; // Request cancel
2038 break;
2039
2040 case IDM_COLLECTOR:
2041 if (mp2) {
2042 LISTINFO *li;
2043# ifdef FORTIFY
2044 Fortify_EnterScope();
2045# endif
2046 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
2047 if (li) {
2048 li->list = mp2;
2049 if (!li->list || !li->list[0])
2050 FreeListInfo(li);
2051 else {
2052 li->type = IDM_COLLECT;
2053 if (!PostMsg(dcd->hwndObject, UM_COLLECT, MPFROMP(li), MPVOID))
2054 FreeListInfo(li);
2055 }
2056 }
2057 else
2058 FreeList(mp2);
2059# ifdef FORTIFY
2060 DosSleep(1); // Let receiver take ownership
2061 Fortify_LeaveScope();
2062# endif
2063 }
2064 break;
2065
2066 case IDM_UNDELETE:
2067 {
2068 PCNRITEM pci;
2069 CHAR path[CCHMAXPATH];
2070 HOBJECT hObject;
2071 HWND hwndDesktop;
2072
2073 hObject = WinQueryObject("<XWP_TRASHCAN>");
2074 if (hObject != NULLHANDLE && fTrashCan) {
2075 hwndDesktop = WinQueryDesktopWindow((HAB) 0, NULLHANDLE);
2076 WinSetFocus(HWND_DESKTOP, hwndDesktop);
2077 WinOpenObject(hObject, 0, TRUE);
2078 }
2079 else {
2080 pci = (PCNRITEM) CurrentRecord(hwnd);
2081 if (pci && (INT) pci != -1) {
2082 strcpy(path, pci->pszFileName);
2083 MakeValidDir(path);
2084 WinDlgBox(HWND_DESKTOP, hwnd, UndeleteDlgProc, FM3ModHandle,
2085 UNDEL_FRAME, MPFROMP(path));
2086 }
2087 }
2088 }
2089 break;
2090
2091 case IDM_GREP:
2092 case UM_GREP:
2093 if (dcd->amextracted) {
2094 saymsg(MB_OK | MB_ICONASTERISK,
2095 hwnd,
2096 GetPString(IDS_WARNINGTEXT),
2097 "Collector busy - please try again later");
2098 }
2099 else {
2100 GREPINFO *GrepInfo;
2101
2102 GrepInfo = xmallocz(sizeof(GREPINFO), pszSrcFile, __LINE__);
2103 if (GrepInfo) {
2104 GrepInfo->hwnd = &hwnd;
2105 if (msg == UM_GREP && mp2)
2106 GrepInfo->szGrepPath = mp2;
2107 if (WinDlgBox(HWND_DESKTOP, hwnd, GrepDlgProc,
2108 FM3ModHandle, GREP_FRAME, (PVOID) GrepInfo)) {
2109 free(GrepInfo);
2110 dcd->amextracted = TRUE; // Say busy scanning
2111 disable_menuitem(WinWindowFromID
2112 (WinQueryWindow(hwndMain, QW_PARENT), FID_MENU),
2113 IDM_GREP, TRUE);
2114 disable_menuitem(TreeMenu, IDM_GREP, TRUE);
2115 disable_menuitem(DirMenu, IDM_GREP, TRUE);
2116 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2117 }
2118 else
2119 free(GrepInfo);
2120 }
2121 }
2122 break;
2123
2124 case IDM_RESORT:
2125 WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(SortCollectorCnr), MPVOID);
2126 break;
2127
2128 case IDM_FILTER:
2129 {
2130 BOOL empty = FALSE;
2131 PCNRITEM pci;
2132 CHAR *p;
2133
2134 if (!*dcd->mask.szMask) {
2135 empty = TRUE;
2136 // 2013-12-13 SHL Allow nul pszFileName
2137 pci = (PCNRITEM) CurrentRecord(hwnd);
2138 if (pci && pci->pszFileName != NullStr && ~pci->attrFile & FILE_DIRECTORY) {
2139 p = strrchr(pci->pszFileName, '\\');
2140 if (p) {
2141 p++;
2142 strcpy(dcd->mask.szMask, p);
2143 }
2144 }
2145 }
2146 *(dcd->mask.prompt) = 0;
2147
2148 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
2149 FM3ModHandle, MSK_FRAME, MPFROMP(&dcd->mask))) {
2150 size = sizeof(MASK);
2151 PrfWriteProfileData(fmprof, appname, "CollectorFilter",
2152 &dcd->mask, size);
2153 dcd->suspendview = 1;
2154 WinSendMsg(hwnd, CM_FILTER, MPFROMP(Filter), MPFROMP(&dcd->mask));
2155 dcd->suspendview = 0;
2156 if (fAutoView && hwndMain) {
2157 pci = WinSendMsg(hwnd, CM_QUERYRECORDEMPHASIS,
2158 MPFROMLONG(CMA_FIRST),
2159 MPFROMSHORT(CRA_CURSORED));
2160 if (pci && (INT) pci != -1 &&
2161 (!(driveflags[toupper(*pci->pszFileName) - 'A'] &
2162 DRIVE_SLOW)))
2163 WinSendMsg(hwndMain, UM_LOADFILE, MPFROMP(pci->pszFileName),
2164 MPVOID);
2165 else
2166 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2167 }
2168 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2169 }
2170 else if (empty)
2171 *dcd->mask.szMask = 0;
2172 SayFilter(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2173 DIR_FILTER), &dcd->mask, FALSE);
2174 }
2175 break;
2176
2177 case IDM_UNHIDEALL:
2178 WinSendMsg(hwnd, CM_FILTER, MPFROMP(Filter), MPFROMP(&dcd->mask));
2179 break;
2180
2181 case IDM_HIDEALL:
2182 if (fAutoView && hwndMain)
2183 PostMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2184 dcd->suspendview = 1;
2185 HideAll(hwnd);
2186 dcd->suspendview = 0;
2187 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2188 break;
2189
2190 case IDM_SELECTLIST:
2191 case IDM_SELECTALL:
2192 case IDM_DESELECTALL:
2193 case IDM_SELECTALLFILES:
2194 case IDM_DESELECTALLFILES:
2195 case IDM_SELECTALLDIRS:
2196 case IDM_DESELECTALLDIRS:
2197 case IDM_SELECTMASK:
2198 case IDM_DESELECTMASK:
2199 case IDM_INVERT:
2200 case IDM_SELECTCLIP:
2201 case IDM_DESELECTCLIP:
2202 {
2203 PCNRITEM pci;
2204
2205 pci = (PCNRITEM) CurrentRecord(hwnd);
2206 if ((INT) pci == -1)
2207 pci = NULL;
2208 if (SHORT1FROMMP(mp1) == IDM_HIDEALL) {
2209 if (pci) {
2210 if (!(pci->rc.flRecordAttr & CRA_SELECTED))
2211 pci->rc.flRecordAttr |= CRA_FILTERED;
2212 WinSendMsg(hwnd, CM_INVALIDATERECORD, MPFROMP(&pci),
2213 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
2214 break;
2215 }
2216 }
2217 PostMsg(dcd->hwndObject, UM_SELECT, mp1, MPFROMP(pci));
2218 }
2219 break;
2220
2221 case IDM_RESCAN:
2222 PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID);
2223 break;
2224
2225 case IDM_SHOWLNAMES:
2226 case IDM_SHOWSUBJECT:
2227 case IDM_SHOWEAS:
2228 case IDM_SHOWSIZE:
2229 case IDM_SHOWICON:
2230 case IDM_SHOWLWDATE:
2231 case IDM_SHOWLWTIME:
2232 case IDM_SHOWLADATE:
2233 case IDM_SHOWLATIME:
2234 case IDM_SHOWCRDATE:
2235 case IDM_SHOWCRTIME:
2236 case IDM_SHOWATTR:
2237 AdjustDetailsSwitches(hwnd, dcd->hwndLastMenu,
2238 SHORT1FROMMP(mp1), NULL,
2239 PCSZ_COLLECTOR, &dcd->ds, FALSE);
2240 break;
2241
2242 case IDM_ICON:
2243 case IDM_TEXT:
2244 case IDM_DETAILS:
2245 case IDM_NAME:
2246 case IDM_MINIICONS:
2247 case IDM_DETAILSTITLES:
2248 {
2249 CNRINFO cnri;
2250
2251 memset(&cnri, 0, sizeof(CNRINFO));
2252 cnri.cb = sizeof(CNRINFO);
2253 WinSendMsg(hwnd, CM_QUERYCNRINFO, MPFROMP(&cnri),
2254 MPFROMLONG(sizeof(CNRINFO)));
2255 switch (SHORT1FROMMP(mp1)) {
2256 case IDM_ICON:
2257 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2258 CV_DETAIL | CV_NAME));
2259 cnri.flWindowAttr |= CV_ICON;
2260 break;
2261 case IDM_NAME:
2262 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2263 CV_DETAIL | CV_NAME));
2264 cnri.flWindowAttr |= CV_NAME;
2265 break;
2266 case IDM_TEXT:
2267 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2268 CV_DETAIL | CV_NAME));
2269 cnri.flWindowAttr |= CV_TEXT;
2270 break;
2271 case IDM_DETAILS:
2272 cnri.flWindowAttr &= (~(CV_ICON | CV_TREE | CV_TEXT |
2273 CV_DETAIL | CV_NAME));
2274 cnri.flWindowAttr |= CV_DETAIL;
2275 break;
2276 case IDM_MINIICONS:
2277 if (cnri.flWindowAttr & CV_MINI)
2278 cnri.flWindowAttr &= (~CV_MINI);
2279 else
2280 cnri.flWindowAttr |= CV_MINI;
2281 break;
2282 case IDM_DETAILSTITLES:
2283 if (cnri.flWindowAttr & CA_DETAILSVIEWTITLES)
2284 cnri.flWindowAttr &= (~CA_DETAILSVIEWTITLES);
2285 else
2286 cnri.flWindowAttr |= CA_DETAILSVIEWTITLES;
2287 break;
2288 }
2289 cnri.flWindowAttr &= (~(CA_ORDEREDTARGETEMPH | CA_MIXEDTARGETEMPH));
2290 cnri.flWindowAttr |= CV_FLOW;
2291 dcd->flWindowAttr = cnri.flWindowAttr;
2292 PrfWriteProfileData(fmprof, appname, "CollectorflWindowAttr",
2293 &cnri.flWindowAttr, sizeof(ULONG));
2294 WinSendMsg(hwnd, CM_SETCNRINFO, MPFROMP(&cnri),
2295 MPFROMLONG(CMA_FLWINDOWATTR));
2296 WinSendMsg(hwnd, CM_INVALIDATERECORD, MPVOID,
2297 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
2298 SayView(WinWindowFromID(WinQueryWindow(hwnd, QW_PARENT),
2299 DIR_VIEW), dcd->flWindowAttr);
2300 }
2301 break;
2302
2303 case IDM_SAVETOLIST:
2304 WinDlgBox(HWND_DESKTOP, hwnd, SaveListDlgProc, FM3ModHandle,
2305 SAV_FRAME, MPFROMP(&hwnd));
2306 break;
2307
2308 case IDM_SIZES:
2309 {
2310 PCNRITEM pci;
2311
2312 pci = (PCNRITEM) CurrentRecord(hwnd);
2313 if (pci && (INT) pci != -1)
2314 WinDlgBox(HWND_DESKTOP, HWND_DESKTOP, DirSizeProc, FM3ModHandle,
2315 DSZ_FRAME, pci->pszFileName);
2316 }
2317 break;
2318
2319 case IDM_MKDIR:
2320 {
2321 PCNRITEM pci;
2322
2323 pci = (PCNRITEM) CurrentRecord(hwnd);
2324 PMMkDir(dcd->hwndParent, (pci && (INT) pci != -1) ?
2325 pci->pszFileName : NULL, FALSE);
2326 }
2327 break;
2328
2329 case IDM_DOITYOURSELF:
2330 case IDM_UPDATE:
2331 case IDM_COLLECTFROMFILE:
2332 case IDM_OPENWINDOW:
2333 case IDM_OPENSETTINGS:
2334 case IDM_OPENDEFAULT:
2335 case IDM_OPENICON:
2336 case IDM_OPENDETAILS:
2337 case IDM_OPENTREE:
2338 case IDM_OBJECT:
2339 case IDM_SHADOW:
2340 case IDM_SHADOW2:
2341 case IDM_JAVAEXE:
2342 case IDM_DELETE:
2343 case IDM_PERMDELETE:
2344 case IDM_PRINT:
2345 case IDM_ATTRS:
2346 case IDM_INFO:
2347 case IDM_COPY:
2348 case IDM_MOVE:
2349 case IDM_WPSCOPY:
2350 case IDM_WPSMOVE:
2351 case IDM_COPYPRESERVE:
2352 case IDM_MOVEPRESERVE:
2353 case IDM_WILDCOPY:
2354 case IDM_WILDMOVE:
2355 case IDM_RENAME:
2356 case IDM_COMPARE:
2357 case IDM_EAS:
2358 case IDM_SUBJECT:
2359 case IDM_VIEW:
2360 case IDM_VIEWTEXT:
2361 case IDM_VIEWBINARY:
2362 case IDM_VIEWARCHIVE:
2363 case IDM_EDIT:
2364 case IDM_EDITTEXT:
2365 case IDM_EDITBINARY:
2366 case IDM_SAVETOCLIP:
2367 case IDM_SAVETOCLIPFILENAME:
2368 case IDM_APPENDTOCLIP:
2369 case IDM_APPENDTOCLIPFILENAME:
2370 case IDM_ARCHIVE:
2371 case IDM_ARCHIVEM:
2372 case IDM_EXTRACT:
2373 case IDM_MCIPLAY:
2374 case IDM_UUDECODE:
2375 case IDM_UNLOCKFILE:
2376 case IDM_MERGE:
2377 {
2378 LISTINFO *li;
2379 ULONG action = UM_ACTION;
2380# ifdef FORTIFY
2381 Fortify_EnterScope();
2382# endif
2383 li = xmallocz(sizeof(LISTINFO), pszSrcFile, __LINE__);
2384 if (li) {
2385 li->type = SHORT1FROMMP(mp1);
2386 li->hwnd = hwnd;
2387 li->list = BuildList(hwnd);
2388 if (li->list) {
2389 switch (SHORT1FROMMP(mp1)) {
2390 case IDM_DOITYOURSELF:
2391 case IDM_APPENDTOCLIP:
2392 case IDM_APPENDTOCLIPFILENAME:
2393 case IDM_SAVETOCLIP:
2394 case IDM_SAVETOCLIPFILENAME:
2395 case IDM_ARCHIVE:
2396 case IDM_ARCHIVEM:
2397 case IDM_DELETE:
2398 case IDM_PERMDELETE:
2399 case IDM_ATTRS:
2400 case IDM_PRINT:
2401 case IDM_SHADOW:
2402 case IDM_SHADOW2:
2403 case IDM_JAVAEXE:
2404 case IDM_OBJECT:
2405 case IDM_VIEW:
2406 case IDM_VIEWTEXT:
2407 case IDM_VIEWBINARY:
2408 case IDM_EDIT:
2409 case IDM_EDITTEXT:
2410 case IDM_EDITBINARY:
2411 case IDM_MCIPLAY:
2412 case IDM_UPDATE:
2413 case IDM_INFO:
2414 case IDM_EAS:
2415 action = UM_MASSACTION;
2416 break;
2417 }
2418 if (li->type == IDM_DELETE)
2419 ignorereadonly = FALSE;
2420 if (li->type == IDM_SHADOW || li->type == IDM_OBJECT ||
2421 li->type == IDM_SHADOW2)
2422 *li->targetpath = 0;
2423 if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID)) {
2424 Runtime_Error(pszSrcFile, __LINE__, PCSZ_POSTMSG);
2425 FreeListInfo(li);
2426 }
2427 else if (fUnHilite)
2428 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
2429 }
2430 else
2431 free(li);
2432 }
2433# ifdef FORTIFY
2434 Fortify_LeaveScope();
2435# endif
2436 }
2437 break;
2438
2439 default:
2440 if (!cmdloaded)
2441 load_commands();
2442 if (SHORT1FROMMP(mp1) >= IDM_COMMANDSTART &&
2443 SHORT1FROMMP(mp1) < IDM_QUICKTOOLSTART) {
2444 INT x;
2445
2446 x = SHORT1FROMMP(mp1); // - IDM_COMMANDSTART;
2447 if (x >= 0) {
2448 //x++;
2449 RunCommand(hwnd, x);
2450 if (fUnHilite)
2451 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
2452 }
2453 }
2454 break;
2455 }
2456 }
2457 return 0;
2458
2459 case UM_FIXCNRMLE:
2460 case UM_FIXEDITNAME:
2461 return CommonCnrProc(hwnd, msg, mp1, mp2);
2462
2463 case UM_FILESMENU:
2464 {
2465 PCNRITEM pci;
2466 HWND menuHwnd = (HWND) 0;
2467
2468 pci = (PCNRITEM) CurrentRecord(hwnd);
2469 if (pci && (INT) pci != -1) {
2470 if (pci->attrFile & FILE_DIRECTORY)
2471 menuHwnd = CheckMenu(hwnd, &CollectorDirMenu, COLLECTORDIR_POPUP);
2472 else
2473 menuHwnd = CheckMenu(hwnd, &CollectorFileMenu, COLLECTORFILE_POPUP);
2474 }
2475 return MRFROMLONG(menuHwnd);
2476 }
2477
2478 case WM_CONTROL:
2479 DosError(FERR_DISABLEHARDERR);
2480 if (dcd) {
2481 switch (SHORT2FROMMP(mp1)) {
2482 case CN_CONTEXTMENU:
2483 {
2484 PCNRITEM pci = (PCNRITEM) mp2;
2485
2486 if (pci) {
2487 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPFROMP(pci),
2488 MPFROM2SHORT(TRUE, CRA_CURSORED));
2489 MarkAll(hwnd, FALSE, FALSE, TRUE);
2490 if (pci->attrFile & FILE_DIRECTORY)
2491 dcd->hwndLastMenu = CheckMenu(hwnd, &CollectorDirMenu,
2492 COLLECTORDIR_POPUP);
2493 else
2494 dcd->hwndLastMenu = CheckMenu(hwnd, &CollectorFileMenu,
2495 COLLECTORFILE_POPUP);
2496 }
2497 else {
2498 dcd->hwndLastMenu = CheckMenu(hwnd, &CollectorCnrMenu,
2499 COLLECTORCNR_POPUP);
2500 if (dcd->hwndLastMenu && !dcd->cnremphasized) {
2501 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
2502 MPFROM2SHORT(TRUE, CRA_SOURCE));
2503 dcd->cnremphasized = TRUE;
2504 }
2505 }
2506 if (dcd->hwndLastMenu) {
2507 if (dcd->hwndLastMenu == CollectorCnrMenu) {
2508 SetViewMenu(dcd->hwndLastMenu, dcd->flWindowAttr);
2509 SetDetailsSwitches(dcd->hwndLastMenu, &dcd->ds);
2510 CopyPresParams(dcd->hwndLastMenu, hwnd);
2511 if (dcd->flWindowAttr & CV_MINI)
2512 WinCheckMenuItem(dcd->hwndLastMenu, IDM_MINIICONS, TRUE);
2513 disable_menuitem(dcd->hwndLastMenu, DID_CANCEL,
2514 !dcd->amextracted);
2515 disable_menuitem(dcd->hwndLastMenu, IDM_GREP, dcd->amextracted);
2516 }
2517 if (!PopupMenu(hwnd, hwnd, dcd->hwndLastMenu)) {
2518 if (dcd->cnremphasized) {
2519 WinSendMsg(hwnd, CM_SETRECORDEMPHASIS, MPVOID,
2520 MPFROM2SHORT(FALSE, CRA_SOURCE));
2521 dcd->cnremphasized = TRUE;
2522 }
2523 MarkAll(hwnd, TRUE, FALSE, TRUE);
2524 }
2525 }
2526 }
2527 break;
2528
2529 case CN_DROPHELP:
2530 if (mp2) {
2531 PDRAGINFO pDInfo;
2532 PCNRITEM pci;
2533 ULONG numitems;
2534 USHORT usOperation;
2535
2536 pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
2537 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
2538 if (!DrgAccessDraginfo(pDInfo)) {
2539 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
2540 PCSZ_DRGACCESSDRAGINFO);
2541 return 0;
2542 }
2543 numitems = DrgQueryDragitemCount(pDInfo);
2544 usOperation = pDInfo->usOperation;
2545 if (usOperation == DO_DEFAULT)
2546 usOperation = fCopyDefault ? DO_COPY : DO_MOVE;
2547 FreeDragInfoData(hwnd, pDInfo);
2548 saymsg(MB_ENTER | MB_ICONASTERISK,
2549 hwnd,
2550 GetPString(IDS_DROPHELPHDRTEXT),
2551 GetPString(IDS_DROPHELPTEXT),
2552 numitems,
2553 &"s"[numitems == 1],
2554 (pci) ? NullStr : GetPString(IDS_NOTEXT),
2555 (pci) ? NullStr : " ",
2556 (pci) ? pci->pszFileName : NullStr,
2557 (pci) ? " " : NullStr,
2558 GetPString((usOperation == DO_COPY) ?
2559 IDS_COPYTEXT :
2560 (usOperation == DO_LINK) ?
2561 IDS_LINKTEXT : IDS_MOVETEXT));
2562 }
2563 return 0;
2564
2565 case CN_DRAGLEAVE:
2566 if (mp2) {
2567 PDRAGINFO pDInfo;
2568
2569 // fixme to know why needed
2570 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
2571 DrgAccessDraginfo(pDInfo); // Access DRAGINFO
2572 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
2573 }
2574 return 0;
2575
2576 case CN_DRAGAFTER:
2577 case CN_DRAGOVER:
2578 if (mp2) {
2579 PDRAGITEM pDItem; // Pointer to DRAGITEM
2580 PDRAGINFO pDInfo; // Pointer to DRAGINFO
2581 PCNRITEM pci;
2582 USHORT uso;
2583
2584 pci = (PCNRITEM) ((PCNRDRAGINFO) mp2)->pRecord;
2585 // if(SHORT1FROMMP(mp1) == CN_DRAGAFTER)
2586 // pci = NULL;
2587 pDInfo = ((PCNRDRAGINFO) mp2)->pDragInfo;
2588 if (!DrgAccessDraginfo(pDInfo)) {
2589 Win_Error(hwnd, hwnd, pszSrcFile, __LINE__,
2590 PCSZ_DRGACCESSDRAGINFO);
2591 return (MRFROM2SHORT(DOR_NODROP, 0)); // Drop not valid
2592 }
2593 if (pci) {
2594 if (pci->rc.flRecordAttr & CRA_SOURCE) {
2595 DrgFreeDraginfo(pDInfo);
2596 return (MRFROM2SHORT(DOR_NODROP, 0));
2597 }
2598 uso = pDInfo->usOperation;
2599 if (uso == DO_DEFAULT)
2600 uso = (fCopyDefault) ? DO_COPY : DO_MOVE;
2601 if (!(pci->attrFile & FILE_DIRECTORY)) {
2602 if (uso != DO_LINK && uso != DO_MOVE && uso != DO_COPY) {
2603 DrgFreeDraginfo(pDInfo);
2604 return MRFROM2SHORT(DOR_NODROP, 0);
2605 }
2606 if (uso != DO_LINK &&
2607 !(driveflags[toupper(*pci->pszFileName) - 'A'] &
2608 DRIVE_NOTWRITEABLE)) {
2609 ARC_TYPE *info = NULL;
2610
2611 if (!fQuickArcFind &&
2612 !(driveflags[toupper(*pci->pszFileName) - 'A'] &
2613 DRIVE_SLOW))
2614 info = find_type(pci->pszFileName, NULL);
2615 else
2616 info = quick_find_type(pci->pszFileName, NULL);
2617 if (!info || ((uso == DO_MOVE && !info->move) ||
2618 (uso == DO_COPY && !info->create))) {
2619 DrgFreeDraginfo(pDInfo);
2620 return MRFROM2SHORT(DOR_NODROP, 0);
2621 }
2622 }
2623 }
2624 }
2625 pDItem = DrgQueryDragitemPtr(pDInfo, // Access DRAGITEM
2626 0); // Index to DRAGITEM
2627 if (DrgVerifyRMF(pDItem, // Check valid rendering
2628 (CHAR *) DRM_OS2FILE, // mechanisms and data
2629 NULL)) {
2630 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
2631 if (pci) {
2632 if (driveflags[toupper(*pci->pszFileName) - 'A'] &
2633 DRIVE_NOTWRITEABLE)
2634 return MRFROM2SHORT(DOR_DROP, DO_LINK);
2635 if (toupper(*pci->pszFileName) < 'C')
2636 return MRFROM2SHORT(DOR_DROP, DO_COPY);
2637 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
2638 ((fCopyDefault) ? DO_COPY : DO_MOVE));
2639 }
2640 else
2641 return MRFROM2SHORT(DOR_DROP, // Return okay to drop
2642 DO_COPY);
2643 }
2644 DrgFreeDraginfo(pDInfo); // Free DRAGINFO
2645 }
2646 return (MRFROM2SHORT(DOR_NODROP, 0)); // Drop not valid
2647
2648 case CN_INITDRAG:
2649 if (mp2) {
2650 BOOL wasemphasized = FALSE;
2651 PCNRDRAGINIT pcd = (PCNRDRAGINIT) mp2;
2652 PCNRITEM pci;
2653
2654 if (pcd) {
2655 pci = (PCNRITEM) pcd->pRecord;
2656 if (pci) {
2657 if (pci->rc.flRecordAttr & CRA_SELECTED)
2658 wasemphasized = TRUE;
2659 if (IsRoot(pci->pszFileName))
2660 break;
2661 if (hwndStatus2)
2662 WinSetWindowText(hwndStatus2,
2663 (CHAR *) GetPString(IDS_DRAGFILEOBJTEXT));
2664 if (DoFileDrag(hwnd, dcd->hwndObject, mp2, NULL, NULL, TRUE)) {
2665 if ((fUnHilite && wasemphasized) || dcd->ulItemsToUnHilite)
2666 UnHilite(hwnd, TRUE, &dcd->lastselection, dcd->ulItemsToUnHilite);
2667 }
2668 if (hwndStatus2)
2669 PostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
2670 }
2671 }
2672 }
2673 return 0;
2674
2675 case CN_DROP:
2676 if (mp2) {
2677 LISTINFO *li;
2678 ULONG action = UM_ACTION;
2679
2680 li = DoFileDrop(hwnd, NULL, TRUE, mp1, mp2);
2681 CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
2682 if (li) {
2683 if (!*li->targetpath) {
2684 li->type = IDM_COLLECT;
2685 action = UM_COLLECT;
2686 }
2687 else {
2688 if (li->list && li->list[0] && IsRoot(li->list[0]))
2689 li->type = DO_LINK;
2690 else if (fDragndropDlg && (!*li->arcname || !li->info)) {
2691 CHECKLIST cl;
2692
2693 memset(&cl, 0, sizeof(cl));
2694 cl.size = sizeof(cl);
2695 cl.flags = li->type;
2696 cl.list = li->list;
2697 cl.cmd = li->type;
2698 cl.prompt = li->targetpath;
2699 li->type = WinDlgBox(HWND_DESKTOP, dcd->hwndParent,
2700 DropListProc, FM3ModHandle,
2701 DND_FRAME, MPFROMP(&cl));
2702 if (li->type == DID_ERROR)
2703 Win_Error(DND_FRAME, HWND_DESKTOP, pszSrcFile, __LINE__,
2704 GetPString(IDS_DRAGDROPDIALOGTEXT));
2705 if (!li->type) {
2706 FreeListInfo(li);
2707 return 0;
2708 }
2709 li->list = cl.list;
2710 if (!li->list || !li->list[0]) {
2711 FreeListInfo(li);
2712 return 0;
2713 }
2714 }
2715 switch (li->type) {
2716 case DND_LAUNCH:
2717 strcat(li->targetpath, " %a");
2718 ExecOnList(dcd->hwndParent, li->targetpath,
2719 PROMPT | WINDOWED, NULL, NULL, li->list, NULL,
2720 pszSrcFile, __LINE__);
2721 FreeList(li->list);
2722 li->list = NULL;
2723 break;
2724 case DO_LINK:
2725 if (fLinkSetsIcon) {
2726 li->type = IDM_SETICON;
2727 action = UM_MASSACTION;
2728 }
2729 else
2730 li->type = IDM_COMPARE;
2731 break;
2732 case DND_EXTRACT:
2733 if (*li->targetpath && !IsFile(li->targetpath))
2734 li->type = IDM_EXTRACT;
2735 break;
2736 case DND_MOVE:
2737 li->type = IDM_MOVE;
2738 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2739 action = UM_MASSACTION;
2740 li->type = IDM_ARCHIVEM;
2741 }
2742 break;
2743 case DND_WILDMOVE:
2744 li->type = IDM_WILDMOVE;
2745 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2746 action = UM_MASSACTION;
2747 li->type = IDM_ARCHIVEM;
2748 }
2749 break;
2750 case DND_OBJECT:
2751 li->type = IDM_OBJECT;
2752 action = UM_MASSACTION;
2753 break;
2754 case DND_SHADOW:
2755 li->type = IDM_SHADOW;
2756 action = UM_MASSACTION;
2757 break;
2758 case DND_COMPARE:
2759 li->type = IDM_COMPARE;
2760 break;
2761 case DND_SETICON:
2762 action = UM_MASSACTION;
2763 li->type = IDM_SETICON;
2764 break;
2765 case DND_WILDCOPY:
2766 li->type = IDM_WILDCOPY;
2767 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2768 action = UM_MASSACTION;
2769 li->type = IDM_ARCHIVE;
2770 }
2771 break;
2772 case DND_COPY:
2773 li->type = IDM_COPY;
2774 if (*li->targetpath && IsFile(li->targetpath) == 1) {
2775 action = UM_MASSACTION;
2776 li->type = IDM_ARCHIVE;
2777 }
2778 break;
2779 default:
2780 if (*li->arcname && li->info) {
2781 action = UM_MASSACTION;
2782 li->type =
2783 (li->type ==
2784 DO_MOVE) ? IDM_FAKEEXTRACTM : IDM_FAKEEXTRACT;
2785 }
2786 else if (*li->targetpath && IsFile(li->targetpath) == 1) {
2787 action = UM_MASSACTION;
2788 li->type =
2789 (li->type == DO_MOVE) ? IDM_ARCHIVEM : IDM_ARCHIVE;
2790 }
2791 else
2792 li->type = (li->type == DO_MOVE) ? IDM_MOVE : IDM_COPY;
2793 break;
2794 } // switch
2795 } // if !collect
2796 if (!li->list || !li->list[0])
2797 FreeListInfo(li);
2798 else if (!PostMsg(dcd->hwndObject, action, MPFROMP(li), MPVOID))
2799 FreeListInfo(li);
2800 else {
2801 USHORT usop = 0;
2802
2803 switch (li->type) {
2804 case IDM_COPY:
2805 case IDM_WILDCOPY:
2806 usop = DO_COPY;
2807 break;
2808 case IDM_MOVE:
2809 case IDM_WILDMOVE:
2810 case IDM_ARCHIVEM:
2811 usop = DO_MOVE;
2812 break;
2813 }
2814 if (usop)
2815 return MRFROM2SHORT(DOR_DROP, usop);
2816 }
2817 }
2818 }
2819 return 0;
2820
2821 case CN_BEGINEDIT:
2822 case CN_REALLOCPSZ:
2823 case CN_ENDEDIT:
2824 {
2825 MRESULT mre;
2826
2827 mre = CnrDirectEdit(hwnd, msg, mp1, mp2);
2828 if (mre != (MRESULT) - 1)
2829 return mre;
2830 }
2831 break;
2832
2833 case CN_EMPHASIS:
2834 if (mp2) {
2835 PNOTIFYRECORDEMPHASIS pre = mp2;
2836 PCNRITEM pci;
2837 CHAR s[CCHMAXPATH + 91], tb[81], tf[81], szDate[DATE_BUF_BYTES], *p;
2838
2839 pci = (PCNRITEM) ((pre) ? pre->pRecord : NULL);
2840 if (!pci) {
2841 if (hwndStatus2)
2842 WinSetWindowText(hwndStatus2, NullStr);
2843 if (fMoreButtons) {
2844 WinSetWindowText(hwndName, NullStr);
2845 WinSetWindowText(hwndDate, NullStr);
2846 WinSetWindowText(hwndAttr, NullStr);
2847 }
2848 if (hwndMain)
2849 WinSendMsg(hwndMain, UM_LOADFILE, MPVOID, MPVOID);
2850 break;
2851 }
2852 if (pre->fEmphasisMask & CRA_SELECTED) {
2853 if (pci->rc.flRecordAttr & CRA_SELECTED) {
2854 dcd->selectedbytes += (pci->cbFile + pci->easize);
2855 dcd->selectedfiles++;
2856 }
2857 else if (dcd->selectedfiles) {
2858 dcd->selectedbytes -= (pci->cbFile + pci->easize);
2859 dcd->selectedfiles--;
2860 }
2861 if (!dcd->suspendview) {
2862 commafmt(tf, sizeof(tf), dcd->selectedfiles);
2863 CommaFmtULL(tb, sizeof(tb), dcd->selectedbytes, ' ');
2864 sprintf(s, "%s / %s", tf, tb);
2865 WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
2866 }
2867 }
2868 if (!dcd->suspendview &&
2869 WinQueryActiveWindow(dcd->hwndParent) == dcd->hwndFrame) {
2870 if (pre->fEmphasisMask & CRA_CURSORED) {
2871 if (pci->rc.flRecordAttr & CRA_CURSORED) {
2872 if (fSplitStatus && hwndStatus2) {
2873 if (pci->attrFile & FILE_DIRECTORY)
2874 p = pci->pszFileName;
2875 else {
2876 p = strrchr(pci->pszFileName, '\\');
2877 if (p) {
2878 if (*(p + 1))
2879 p++;
2880 else
2881 p = pci->pszFileName;
2882 }
2883 else
2884 p = pci->pszFileName;
2885 }
2886 CommaFmtULL(tb, sizeof(tb), pci->cbFile + pci->easize, ' ');
2887 if (!fMoreButtons) {
2888 DateFormat(szDate, pci->date);
2889 sprintf(s, " %s %s %02u%s%02u%s%02u [%s] %s",
2890 tb, szDate, pci->time.hours, TimeSeparator,
2891 pci->time.minutes, TimeSeparator, pci->time.seconds,
2892 pci->pszDispAttr, p);
2893 }
2894 else {
2895 if (pci->cbFile + pci->easize > 1024)
2896 CommaFmtULL(tf, sizeof(tf), pci->cbFile + pci->easize,
2897 ' ');
2898 else
2899 *tf = 0;
2900 sprintf(s, GetPString(IDS_STATUSSIZETEXT),
2901 tb,
2902 *tf ? " (" : NullStr, tf, *tf ? ")" : NullStr);
2903 }
2904 WinSetWindowText(hwndStatus2, s);
2905 }
2906 if (fMoreButtons) {
2907 WinSetWindowText(hwndName, pci->pszFileName);
2908 DateFormat(szDate, pci->date);
2909 sprintf(s, "%s %02u%s%02u%s%02u",
2910 szDate, pci->time.hours, TimeSeparator, pci->time.minutes,
2911 TimeSeparator, pci->time.seconds);
2912 WinSetWindowText(hwndDate, s);
2913 WinSetWindowText(hwndAttr, pci->pszDispAttr);
2914 }
2915 }
2916 }
2917 }
2918 if (!dcd->suspendview && hwndMain &&
2919 (pre->fEmphasisMask & CRA_CURSORED) &&
2920 (pci->rc.flRecordAttr & CRA_CURSORED) &&
2921 WinQueryActiveWindow(dcd->hwndParent) == dcd->hwndFrame)
2922 WinSendMsg(hwndMain, UM_LOADFILE,
2923 MPFROMP(((fComments
2924 || (pci->attrFile & FILE_DIRECTORY) ==
2925 0) ? pci->pszFileName : NULL)), MPVOID);
2926 }
2927 break;
2928
2929 case CN_ENTER:
2930 if (mp2) {
2931 PCNRITEM pci = (PCNRITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
2932 FILEFINDBUF3 ffb;
2933 HDIR hDir = HDIR_CREATE;
2934 ULONG nm = 1;
2935 APIRET status = 0;
2936
2937 SetShiftState();
2938 if (pci) {
2939 if (pci->rc.flRecordAttr & CRA_INUSE)
2940 break;
2941 DosError(FERR_DISABLEHARDERR);
2942 status = DosFindFirst(pci->pszFileName, &hDir,
2943 FILE_NORMAL | FILE_DIRECTORY |
2944 FILE_ARCHIVED | FILE_READONLY |
2945 FILE_HIDDEN | FILE_SYSTEM,
2946 &ffb, sizeof(ffb), &nm, FIL_STANDARD);
2947 priority_bumped();
2948 if (!status) {
2949 DosFindClose(hDir);
2950 if (ffb.attrFile & FILE_DIRECTORY) {
2951 if ((shiftstate & (KC_CTRL | KC_ALT)) == (KC_CTRL | KC_ALT))
2952 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(IDM_SHOWALLFILES, 0),
2953 MPVOID);
2954 else if ((shiftstate & (KC_CTRL | KC_SHIFT)) ==
2955 (KC_CTRL | KC_SHIFT))
2956 OpenObject(pci->pszFileName, Settings, dcd->hwndFrame);
2957 else if (shiftstate & KC_CTRL)
2958 OpenObject(pci->pszFileName, Default, dcd->hwndFrame);
2959 else
2960 OpenDirCnr(HWND_DESKTOP,
2961 hwndMain,
2962 dcd->hwndFrame, FALSE, pci->pszFileName);
2963 }
2964 else {
2965 SWP swp;
2966
2967 WinSendMsg(hwnd,
2968 CM_SETRECORDEMPHASIS,
2969 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_INUSE));
2970 WinQueryWindowPos(dcd->hwndFrame, &swp);
2971 DefaultViewKeys(hwnd,
2972 dcd->hwndFrame,
2973 dcd->hwndParent, &swp, pci->pszFileName);
2974 WinSendMsg(hwnd,
2975 CM_SETRECORDEMPHASIS,
2976 MPFROMP(pci),
2977 MPFROM2SHORT(FALSE, CRA_INUSE |
2978 ((fUnHilite) ? CRA_SELECTED : 0)));
2979 }
2980 }
2981 else
2982 RemoveCnrItems(hwnd, pci, 1, CMA_FREE | CMA_INVALIDATE | CMA_ERASE);
2983 }
2984 }
2985 break;
2986 }
2987 }
2988 return 0;
2989
2990 case UM_LOADFILE:
2991 if (dcd && mp2) {
2992
2993 HWND hwnd;
2994
2995 if ((INT)mp1 == 5 || (INT)mp1 == 13 || (INT)mp1 == 21)
2996 hwnd = StartViewer(HWND_DESKTOP, (INT)mp1,
2997 (CHAR *)mp2, dcd->hwndFrame);
2998 else
2999 hwnd = StartMLEEditor(dcd->hwndParent,
3000 (INT)mp1, (CHAR *)mp2, dcd->hwndFrame);
3001 free((CHAR *)mp2);
3002 return MRFROMLONG(hwnd);
3003 }
3004 return 0;
3005
3006 case UM_CLOSE:
3007 WinDestroyWindow(WinQueryWindow(WinQueryWindow(hwnd, QW_PARENT),
3008 QW_PARENT));
3009 return 0;
3010
3011 case UM_FOLDUP:
3012 if (!PostMsg((HWND) 0, WM_QUIT, MPVOID, MPVOID))
3013 DosExit(EXIT_PROCESS, 1);
3014 return 0;
3015
3016 case WM_CLOSE:
3017 if (dcd) {
3018 dcd->namecanchange = TRUE;
3019 dcd->stopflag = 1;
3020 if (dcd->amextracted)
3021 return 0; // Can not close yet
3022 }
3023 WinSendMsg(hwnd, WM_SAVEAPPLICATION, MPVOID, MPVOID);
3024 if (dcd) {
3025 if (!dcd->dontclose && ParentIsDesktop(hwnd, dcd->hwndParent))
3026 PostMsg(hwnd, UM_FOLDUP, MPVOID, MPVOID);
3027 if (dcd->hwndObject) {
3028 DosSleep(32); // Allow UM_FOLDUP to process
3029 if (!PostMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID))
3030 WinSendMsg(dcd->hwndObject, WM_CLOSE, MPVOID, MPVOID);
3031 }
3032 }
3033 else
3034 WinSendMsg(hwnd, UM_CLOSE, MPVOID, MPVOID);
3035 return 0;
3036
3037 case WM_DESTROY:
3038 if (CollectorDirMenu)
3039 WinDestroyWindow(CollectorDirMenu);
3040 if (CollectorFileMenu)
3041 WinDestroyWindow(CollectorFileMenu);
3042 if (CollectorCnrMenu)
3043 WinDestroyWindow(CollectorCnrMenu);
3044 CollectorCnrMenu = CollectorFileMenu = CollectorDirMenu = (HWND) 0;
3045 Collector = (HWND) 0;
3046 EmptyCnr(hwnd);
3047 break;
3048 }
3049 if (dcd && dcd->oldproc){
3050 return dcd->oldproc(hwnd, msg, mp1, mp2);
3051 }
3052 else
3053 return PFNWPCnr(hwnd, msg, mp1, mp2);
3054}
3055
3056MRESULT EXPENTRY CollectorMenuProc(HWND hwnd, ULONG msg, MPARAM mp1,
3057 MPARAM mp2)
3058{
3059 PFNWP oldMenuProc = WinQueryWindowPtr(hwnd, QWL_USER);
3060 static short sLastMenuitem;
3061
3062 switch (msg) {
3063 case WM_MOUSEMOVE: {
3064 if (fOtherHelp) {
3065 RECTL rectl;
3066 SHORT i, sCurrentMenuitem;
3067 SHORT MenuItems = 5;
3068 SHORT asMenuIDs[5] = {IDM_GREP,
3069 IDM_SEEALL,
3070 IDM_CLEARCNR,
3071 IDM_REMOVE,
3072 0};
3073 PCSZ szHelpString = NULL;
3074
3075 for (i=0; i<MenuItems; i++) {
3076 sCurrentMenuitem = asMenuIDs[i];
3077 oldMenuProc(hwnd,MM_QUERYITEMRECT,
3078 MPFROM2SHORT(asMenuIDs[i], FALSE),
3079 &rectl);
3080
3081 if (MOUSEMSG(&msg)->x > rectl.xLeft &&
3082 MOUSEMSG(&msg)->x < rectl.xRight &&
3083 MOUSEMSG(&msg)->y > rectl.yBottom &&
3084 MOUSEMSG(&msg)->y < rectl.yTop)
3085 break;
3086 } // for
3087
3088 switch (sCurrentMenuitem) {
3089 case 0:
3090 break;
3091 case IDM_GREP:
3092 szHelpString = GetPString(IDS_COLMENUSEEKSCANHELP);
3093 break;
3094 case IDM_SEEALL:
3095 szHelpString = GetPString(IDS_COLMENUSEEALLHELP);
3096 break;
3097 case IDM_CLEARCNR:
3098 szHelpString = GetPString(IDS_COLMENUCLEARCNRHELP);
3099 break;
3100 case IDM_REMOVE:
3101 szHelpString = GetPString(IDS_COLMENUREMOVECNRHELP);
3102 break;
3103 default:
3104 break;
3105 }
3106
3107 if (sLastMenuitem != sCurrentMenuitem && szHelpString) {
3108 sLastMenuitem = sCurrentMenuitem;
3109 MakeBubble(hwnd, TRUE, szHelpString);
3110 }
3111 else if (hwndBubble && !sCurrentMenuitem){
3112 sLastMenuitem = sCurrentMenuitem;
3113 WinDestroyWindow(hwndBubble);
3114 }
3115 }
3116 }
3117 }
3118 return oldMenuProc(hwnd, msg, mp1, mp2);
3119}
3120
3121HWND StartCollector(HWND hwndParent, INT flags)
3122{
3123 HWND hwndFrame = (HWND) 0;
3124 HWND hwndClient;
3125 ULONG FrameFlags = FCF_TITLEBAR | FCF_SYSMENU |
3126 FCF_SIZEBORDER | FCF_MINMAX | FCF_ICON | FCF_NOBYTEALIGN | FCF_ACCELTABLE;
3127 USHORT id;
3128 DIRCNRDATA *dcd;
3129
3130 static USHORT idinc = 0;
3131
3132 if (ParentIsDesktop(hwndParent, hwndParent))
3133 FrameFlags |= (FCF_TASKLIST | FCF_SHELLPOSITION | FCF_MENU);
3134 if (Collector) {
3135 WinSetWindowPos(WinQueryWindow(WinQueryWindow(Collector,
3136 QW_PARENT),
3137 QW_PARENT),
3138 HWND_TOP, 0, 0, 0, 0, SWP_SHOW | SWP_RESTORE);
3139 return WinQueryWindow(WinQueryWindow(Collector, QW_PARENT), QW_PARENT);
3140 }
3141 hwndFrame = WinCreateStdWindow(hwndParent,
3142 WS_VISIBLE,
3143 &FrameFlags,
3144 (CHAR *) WC_COLLECTOR,
3145 NULL,
3146 WS_VISIBLE | fwsAnimate,
3147 FM3ModHandle, COLLECTOR_FRAME, &hwndClient);
3148 if (hwndFrame && hwndClient) {
3149 id = COLLECTOR_FRAME + idinc++;
3150 WinSetWindowUShort(hwndFrame, QWS_ID, id);
3151# ifdef FORTIFY
3152 Fortify_EnterScope();
3153# endif
3154 dcd = xmallocz(sizeof(DIRCNRDATA), pszSrcFile, __LINE__);
3155 if (!dcd) {
3156 Runtime_Error(pszSrcFile, __LINE__, NULL);
3157 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3158 hwndFrame = (HWND) 0;
3159 }
3160 else {
3161 dcd->size = sizeof(DIRCNRDATA);
3162 dcd->id = id;
3163 dcd->type = COLLECTOR_FRAME;
3164 dcd->hwndParent = (hwndParent) ? hwndParent : HWND_DESKTOP;
3165 dcd->hwndFrame = hwndFrame;
3166 dcd->hwndClient = hwndClient;
3167 if (flags & 4)
3168 dcd->dontclose = TRUE;
3169 {
3170 PFNWP oldproc;
3171
3172 oldproc = WinSubclassWindow(hwndFrame, (PFNWP) CollectorFrameWndProc);
3173 WinSetWindowPtr(hwndFrame, QWL_USER, (PVOID) oldproc);
3174 }
3175 dcd->hwndCnr = WinCreateWindow(hwndClient,
3176 WC_CONTAINER,
3177 NULL,
3178 CCS_AUTOPOSITION | CCS_MINIICONS |
3179 CCS_MINIRECORDCORE | ulCnrType |
3180 WS_VISIBLE,
3181 0,
3182 0,
3183 0,
3184 0,
3185 hwndClient,
3186 HWND_TOP,
3187 (ULONG) COLLECTOR_CNR, NULL, NULL);
3188 if (!dcd->hwndCnr) {
3189 Win_Error(hwndClient, hwndClient, pszSrcFile, __LINE__,
3190 PCSZ_WINCREATEWINDOW);
3191 PostMsg(hwndClient, WM_CLOSE, MPVOID, MPVOID);
3192 free(dcd);
3193 hwndFrame = (HWND) 0;
3194 }
3195 else {
3196 Collector = dcd->hwndCnr;
3197 WinSetWindowPtr(dcd->hwndCnr, QWL_USER, (PVOID) dcd);
3198 WinSetWindowText(hwndFrame, (CHAR *) GetPString(IDS_COLLECTORTITLETEXT));
3199 if (FrameFlags & FCF_MENU) {
3200 PFNWP oldmenuproc;
3201 HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
3202
3203 oldmenuproc = WinSubclassWindow(hwndMenu, (PFNWP) CollectorMenuProc);
3204 WinSetWindowPtr(hwndMenu, QWL_USER, (PVOID) oldmenuproc);
3205 if (!fToolbar) {
3206 if (hwndMenu) {
3207
3208 WinSendMsg(hwndMenu,
3209 MM_DELETEITEM,
3210 MPFROM2SHORT(IDM_SEEALL, FALSE), MPVOID);
3211 WinSendMsg(hwndMenu,
3212 MM_DELETEITEM,
3213 MPFROM2SHORT(IDM_GREP, FALSE), MPVOID);
3214 WinSendMsg(hwndMenu,
3215 MM_DELETEITEM,
3216 MPFROM2SHORT(IDM_CLEARCNR, FALSE), MPVOID);
3217 WinSendMsg(hwndMenu,
3218 MM_DELETEITEM,
3219 MPFROM2SHORT(IDM_REMOVE, FALSE), MPVOID);
3220 }
3221 }
3222 }
3223 dcd->oldproc = WinSubclassWindow(dcd->hwndCnr,
3224 (PFNWP) CollectorCnrWndProc);
3225 {
3226 USHORT ids[] = { DIR_TOTALS,
3227 DIR_SELECTED,
3228 DIR_VIEW,
3229 DIR_SORT,
3230 DIR_FILTER,
3231 0
3232 };
3233
3234 CommonCreateTextChildren(dcd->hwndClient,
3235 WC_COLSTATUS, ids);
3236 }
3237 if (FrameFlags & FCF_SHELLPOSITION)
3238 PostMsg(hwndClient, UM_SIZE, MPVOID, MPVOID);
3239 if (!PostMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID))
3240 WinSendMsg(dcd->hwndCnr, UM_SETUP, MPVOID, MPVOID);
3241 }
3242 }
3243# ifdef FORTIFY
3244 DosSleep(1); // Let receiver take ownership
3245 Fortify_LeaveScope();
3246# endif
3247 }
3248 return hwndFrame;
3249}
3250
3251#pragma alloc_text(COLLECTOR,CollectorCnrWndProc,CollectorObjWndProc)
3252#pragma alloc_text(COLLECTOR,CollectorClientWndProc,CollectorTextProc)
3253#pragma alloc_text(COLLECTOR,CollectorFrameWndProc)
3254#pragma alloc_text(STARTUP,StartCollector)
Note: See TracBrowser for help on using the repository browser.