source: trunk/dll/collect.c@ 1803

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

Changes to allow a JAVA executable object to be created using "Real object" menu item on a jar file. (Ticket [37]) Eliminate redundant prompts and error messages when telling FM/2 not to delete a R/O file. (Ticket [548]) Limit attempts to unlock files to exes and dlls. (Ticket [549])

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