source: trunk/dll/comp.c@ 762

Last change on this file since 762 was 762, checked in by Steven Levine, 18 years ago

Use two pass logic to free CNRITEMs and ARCITEMs
Rename pszLongname to pszLongName
More compare directories rework
Make directory sizes item draw placement deterministic - how did it ever work?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 72.6 KB
Line 
1
2/***********************************************************************
3
4 $Id: comp.c 762 2007-08-04 23:19:21Z stevenhl $
5
6 Compare directories
7
8 Copyright (c) 1993-02 M. Kimes
9 Copyright (c) 2003, 2007 Steven H. Levine
10
11 16 Oct 02 MK Baseline
12 04 Nov 03 SHL Force window refresh after subdir toggle
13 01 Aug 04 SHL Rework lstrip/rstrip usage
14 24 May 05 SHL Rework Win_Error usage
15 24 May 05 SHL Rework for CNRITEM.szSubject
16 25 May 05 SHL Rework with ULONGLONG
17 06 Jun 05 SHL Drop unused
18 12 Jul 06 SHL Renames and comments
19 13 Jul 06 SHL Use Runtime_Error
20 26 Jul 06 SHL Drop unreachable CN_... code
21 29 Jul 06 SHL Use xfgets_bstripcr
22 15 Aug 06 SHL Turn off hide not selected on dir change
23 19 Oct 06 SHL Correct . and .. detect
24 03 Nov 06 SHL Count thread usage
25 22 Mar 07 GKY Use QWL_USER
26 29 Jul 07 SHL Use Win_Error to report container errors
27 01 Aug 07 SHL Rework to sync with CNRITEM mods
28 01 Aug 07 SHL Rework to remove vast amount of duplicate code
29 03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
30
31***********************************************************************/
32
33#define INCL_DOS
34#define INCL_WIN
35#define INCL_GPI
36#define INCL_LONGLONG
37#include <os2.h>
38
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <ctype.h>
43#include <share.h>
44#include <io.h>
45#include <process.h> // _beginthread
46
47#include "fm3dll.h"
48#include "fm3dlg.h"
49#include "fm3str.h"
50
51#pragma alloc_text(COMPAREDIR,FillCnrsThread,FillDirList,CompNames)
52#pragma alloc_text(COMPAREDIR1,CompareDlgProc)
53#pragma alloc_text(COMPAREDIR2,SelectCnrsThread,ActionCnrThread)
54#pragma alloc_text(COMPAREFILE,CFileDlgProc,CompareFilesThread)
55#pragma alloc_text(SNAPSHOT,SnapShot,StartSnap)
56
57typedef struct
58{
59 CHAR filename[CCHMAXPATH];
60 CHAR dirname[CCHMAXPATH];
61 BOOL recurse;
62}
63SNAPSTUFF;
64
65static PSZ pszSrcFile = __FILE__;
66
67//=== SnapShot() Write directory tree to file and recurse if requested ===
68
69static VOID SnapShot(char *path, FILE * fp, BOOL recurse)
70{
71 FILEFINDBUF4 *fb;
72 char *mask, *enddir;
73 HDIR hdir = HDIR_CREATE;
74 ULONG nm = 1L;
75
76 fb = xmalloc(sizeof(FILEFINDBUF4), pszSrcFile, __LINE__);
77 if (fb) {
78 mask = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
79 if (mask) {
80 sprintf(mask,
81 "%s%s*",
82 path, (path[strlen(path) - 1] != '\\') ? "\\" : NullStr);
83 enddir = strrchr(mask, '\\');
84 enddir++;
85 if (!DosFindFirst(mask,
86 &hdir,
87 FILE_NORMAL | FILE_DIRECTORY |
88 FILE_ARCHIVED | FILE_READONLY | FILE_HIDDEN |
89 FILE_SYSTEM,
90 fb, sizeof(FILEFINDBUF4), &nm, FIL_QUERYEASIZE)) {
91 do {
92 strcpy(enddir, fb->achName);
93 if (!(fb->attrFile & FILE_DIRECTORY))
94 fprintf(fp,
95 "\"%s\",%u,%lu,%04u/%02u/%02u,%02u:%02u:%02u,%lu,%lu,N\n",
96 mask,
97 enddir - mask,
98 fb->cbFile,
99 (fb->fdateLastWrite.year + 1980),
100 fb->fdateLastWrite.month,
101 fb->fdateLastWrite.day,
102 fb->ftimeLastWrite.hours,
103 fb->ftimeLastWrite.minutes,
104 fb->ftimeLastWrite.twosecs,
105 fb->attrFile, (fb->cbList > 4L) ? (fb->cbList / 2L) : 0L);
106 // Skip . and ..
107 else if (recurse &&
108 (fb->achName[0] != '.' ||
109 (fb->achName[1] &&
110 (fb->achName[1] != '.' || fb->achName[2])))) {
111 SnapShot(mask, fp, recurse);
112 }
113 nm = 1L;
114 } while (!DosFindNext(hdir, fb, sizeof(FILEFINDBUF4), &nm));
115 DosFindClose(hdir);
116 }
117 free(mask);
118 }
119 free(fb);
120 }
121}
122
123//=== StartSnap() Write directory tree to snapshot file ===
124
125static VOID StartSnap(VOID * dummy)
126{
127 SNAPSTUFF *sf = (SNAPSTUFF *) dummy;
128 FILE *fp;
129 CHAR *p;
130
131 if (sf) {
132 if (*sf->dirname && *sf->filename) {
133 priority_normal();
134 p = sf->dirname;
135 while (*p) {
136 if (*p == '/')
137 *p = '\\';
138 p++;
139 }
140 if (*(p - 1) != '\\') {
141 *p = '\\';
142 p++;
143 }
144 fp = xfopen(sf->filename, "w", pszSrcFile, __LINE__);
145 if (fp) {
146 fprintf(fp, "\"%s\"\n", sf->dirname);
147 SnapShot(sf->dirname, fp, sf->recurse);
148 fclose(fp);
149 }
150 }
151 free(sf);
152 }
153}
154
155//=== CompareFilesThread() Compare files and update container select flags ===
156
157static VOID CompareFilesThread(VOID * args)
158{
159 FCOMPARE fc;
160 HAB hab2;
161 HMQ hmq2;
162 FILE *fp1, *fp2;
163 ULONG len1, len2, offset = 0L;
164 LONG numread1, numread2;
165 CHAR s[1024], ss[1024], *p1, *p2;
166
167 if (args) {
168 fc = *(FCOMPARE *) args;
169 hab2 = WinInitialize(0);
170 if (hab2) {
171 hmq2 = WinCreateMsgQueue(hab2, 0);
172 if (hmq2) {
173 WinCancelShutdown(hmq2, TRUE);
174 IncrThreadUsage();
175 if (!IsFile(fc.file1) || IsRoot(fc.file1)) {
176 p1 = strrchr(fc.file2, '\\');
177 if (p1) {
178 if (fc.file1[strlen(fc.file1) - 1] == '\\')
179 p1++;
180 strcat(fc.file1, p1);
181 }
182 }
183 else if (!IsFile(fc.file2) || IsRoot(fc.file2)) {
184 p1 = strrchr(fc.file1, '\\');
185 if (p1) {
186 if (fc.file2[strlen(fc.file2) - 1] == '\\')
187 p1++;
188 strcat(fc.file2, p1);
189 }
190 }
191 sprintf(s, GetPString(IDS_COMPCOMPARETEXT), fc.file1);
192 AddToListboxBottom(fc.hwndList, s);
193 sprintf(s, GetPString(IDS_COMPTOTEXT), fc.file2);
194 AddToListboxBottom(fc.hwndList, s);
195 fp1 = _fsopen(fc.file1, "rb", SH_DENYNO);
196 if (!fp1) {
197 sprintf(s, GetPString(IDS_COMPCANTOPENTEXT), fc.file1);
198 AddToListboxBottom(fc.hwndList, s);
199 WinSetWindowText(fc.hwndHelp, GetPString(IDS_ERRORTEXT));
200 }
201 else {
202 fp2 = _fsopen(fc.file2, "rb", SH_DENYNO);
203 if (!fp2) {
204 sprintf(s, GetPString(IDS_COMPCANTOPENTEXT), fc.file2);
205 AddToListboxBottom(fc.hwndList, s);
206 WinSetWindowText(fc.hwndHelp, GetPString(IDS_ERRORTEXT));
207 }
208 else {
209 len1 = filelength(fileno(fp1));
210 len2 = filelength(fileno(fp2));
211 if (len1 != len2) {
212 strcpy(s, GetPString(IDS_COMPDIFSIZESTEXT));
213 AddToListboxBottom(fc.hwndList, s);
214 sprintf(s, GetPString(IDS_COMPVSBYTESTEXT), len1, len2);
215 AddToListboxBottom(fc.hwndList, s);
216 WinSetWindowText(fc.hwndHelp,
217 GetPString(IDS_COMPDONTMATCHTEXT));
218 }
219 else {
220 WinSetWindowText(fc.hwndHelp,
221 GetPString(IDS_COMPCOMPARINGTEXT));
222 while (WinIsWindow(hab2, fc.hwndList)) {
223 numread1 = fread(s, 1, 1024, fp1);
224 numread2 = fread(ss, 1, 1024, fp2);
225 if (numread1 != numread2 || feof(fp1) != feof(fp2)) {
226 sprintf(s, GetPString(IDS_COMPREADERRORTEXT),
227 offset, offset);
228 AddToListboxBottom(fc.hwndList, s);
229 WinSetWindowText(fc.hwndHelp, GetPString(IDS_ERRORTEXT));
230 break;
231 }
232 else if (!numread1 && feof(fp1) && feof(fp2)) {
233 AddToListboxBottom(fc.hwndList,
234 GetPString(IDS_COMPFILESMATCHTEXT));
235 if (!stricmp(fc.file1, fc.file2))
236 AddToListboxBottom(fc.hwndList,
237 GetPString(IDS_COMPWONDERWHYTEXT));
238 WinSetWindowText(fc.hwndHelp,
239 GetPString(IDS_COMPCOMPLETETEXT));
240 break;
241 }
242 else if (numread1 <= 0 || numread2 <= 0) {
243 if (offset == len1)
244 break;
245 else {
246 sprintf(s, GetPString(IDS_COMPMATCHREADERRORTEXT),
247 offset, offset);
248 WinSetWindowText(fc.hwndHelp,
249 GetPString(IDS_COMPODDERRORTEXT));
250 AddToListboxBottom(fc.hwndList, s);
251 break;
252 }
253 }
254 else if (memcmp(s, ss, numread1)) {
255 p1 = s;
256 p2 = ss;
257 while (p1 < s + numread1) {
258 if (*p1 != *p2) {
259 sprintf(s, GetPString(IDS_COMPMISMATCHERRORTEXT),
260 offset + (p1 - s), offset + (p1 - s));
261 AddToListboxBottom(fc.hwndList, s);
262 WinSetWindowText(fc.hwndHelp,
263 GetPString(IDS_COMPDONTMATCHTEXT));
264 break;
265 }
266 p1++;
267 p2++;
268 }
269 break;
270 }
271 offset += numread1;
272 }
273 }
274 fclose(fp2);
275 }
276 fclose(fp1);
277 }
278 DecrThreadUsage();
279 WinDestroyMsgQueue(hmq2);
280 }
281 WinTerminate(hab2);
282 }
283 }
284}
285
286//=== CFileDlgProc() Select directories to compare dialog procedure ===
287
288MRESULT EXPENTRY CFileDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
289{
290 FCOMPARE *fc;
291
292 switch (msg) {
293 case WM_INITDLG:
294 if (!mp2)
295 WinDismissDlg(hwnd, 0);
296 else {
297 WinSetWindowPtr(hwnd, QWL_USER, mp2);
298 fc = (FCOMPARE *) mp2;
299 fc->hwndReport = hwnd;
300 fc->hwndList = WinWindowFromID(hwnd, FCMP_LISTBOX);
301 fc->hwndHelp = WinWindowFromID(hwnd, FCMP_HELP);
302 if (!*fc->file1 || !fc->file2) {
303 WinDismissDlg(hwnd, 0);
304 break;
305 }
306 MakeFullName(fc->file1);
307 MakeFullName(fc->file2);
308 if (!stricmp(fc->file1, fc->file2)) {
309 saymsg(MB_CANCEL, hwnd,
310 GetPString(IDS_COMPSILLYALERTTEXT),
311 GetPString(IDS_COMPTOITSELFTEXT));
312 WinDismissDlg(hwnd, 0);
313 break;
314 }
315 if (_beginthread(CompareFilesThread, NULL, 65536, (PVOID) fc) == -1) {
316 Runtime_Error(pszSrcFile, __LINE__,
317 GetPString(IDS_COULDNTSTARTTHREADTEXT));
318 WinDismissDlg(hwnd, 0);
319 }
320 }
321 break;
322
323 case WM_ADJUSTWINDOWPOS:
324 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
325 break;
326
327 case UM_SETDIR:
328 PaintRecessedWindow(WinWindowFromID(hwnd, FCMP_HELP),
329 (HPS) 0, FALSE, TRUE);
330 return 0;
331
332 case WM_COMMAND:
333 switch (SHORT1FROMMP(mp1)) {
334 case DID_OK:
335 WinDismissDlg(hwnd, 0);
336 break;
337 case DID_CANCEL:
338 WinDismissDlg(hwnd, 1);
339 break;
340 }
341 return 0;
342
343 case WM_DESTROY:
344 DosSleep(100);
345 break;
346 }
347 return WinDefDlgProc(hwnd, msg, mp1, mp2);
348}
349
350//=== ActionCnrThread() Do requested action on container contents ===
351
352static VOID ActionCnrThread(VOID *args)
353{
354 COMPARE *cmp = (COMPARE *)args;
355 HAB hab;
356 HMQ hmq;
357 HWND hwndCnrS, hwndCnrD;
358 PCNRITEM pci, pciD, pciNextS, pciNextD;
359 CHAR newname[CCHMAXPATH], dirname[CCHMAXPATH], *p;
360 APIRET rc;
361
362 if (!cmp) {
363 Runtime_Error(pszSrcFile, __LINE__, "no data");
364 return;
365 }
366
367 DosError(FERR_DISABLEHARDERR);
368
369 hab = WinInitialize(0);
370 if (hab) {
371 hmq = WinCreateMsgQueue(hab, 0);
372 if (hmq) {
373 WinCancelShutdown(hmq, TRUE);
374 IncrThreadUsage();
375 priority_normal();
376 switch (cmp->action) {
377 case COMP_DELETELEFT:
378 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
379 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
380 cmp->action = IDM_DELETE;
381 break;
382 case COMP_DELETERIGHT:
383 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
384 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
385 cmp->action = IDM_DELETE;
386 break;
387 case COMP_MOVELEFT:
388 cmp->action = IDM_MOVE;
389 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
390 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
391 break;
392 case COMP_MOVERIGHT:
393 cmp->action = IDM_MOVE;
394 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
395 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
396 break;
397 case COMP_COPYLEFT:
398 cmp->action = IDM_COPY;
399 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
400 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
401 break;
402 case COMP_COPYRIGHT:
403 cmp->action = IDM_COPY;
404 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
405 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
406 break;
407 default:
408 Runtime_Error(pszSrcFile, __LINE__, "bad case %u", cmp->action);
409 goto Abort;
410 }
411
412 pci = WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPVOID,
413 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
414 pciD = WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPVOID,
415 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
416
417 while (pci && (INT)pci != -1 && pciD && (INT)pciD != -1) {
418
419 pciNextS = WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPFROMP(pci),
420 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
421 pciNextD = WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPFROMP(pciD),
422 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
423
424 if (*pci->pszFileName && pci->rc.flRecordAttr & CRA_SELECTED) {
425
426 // Source name not blank
427 switch (cmp->action) {
428 case IDM_DELETE:
429 if (!unlinkf("%s", pci->pszFileName)) {
430 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pci),
431 MPFROM2SHORT(FALSE, CRA_SELECTED));
432
433 if (!*pciD->pszFileName) {
434 // Other side is blank - remove from both sides
435 RemoveCnrItems(hwndCnrS, pci, 1, CMA_FREE | CMA_INVALIDATE);
436 if (pciD->rc.flRecordAttr & CRA_SELECTED)
437 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciD),
438 MPFROM2SHORT(FALSE, CRA_SELECTED));
439 RemoveCnrItems(hwndCnrD, pciD, 1, CMA_FREE | CMA_INVALIDATE);
440 }
441 else {
442 // Other side is not blank - update just this side
443 FreeCnrItemData(pci);
444 pci->pszDisplayName = pci->pszFileName;
445 pci->rc.pszIcon = pci->pszFileName;
446 pci->flags = 0;
447 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD, MPFROMP(&pci),
448 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
449 }
450 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_LEFTDIR))
451 cmp->cmp->totalleft--;
452 else
453 cmp->cmp->totalright--;
454 DosSleep(1);
455 }
456 break;
457
458 case IDM_MOVE:
459 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR))
460 // 02 Aug 07 SHL fixme to replace this kind of stuff with _makepath or equivalent
461 sprintf(newname, "%s%s%s",
462 cmp->leftdir,
463 cmp->leftdir[strlen(cmp->leftdir) - 1] == '\\' ?
464 NullStr : "\\",
465 pci->pszDisplayName);
466 else
467 sprintf(newname, "%s%s%s",
468 cmp->rightdir,
469 cmp->rightdir[strlen(cmp->rightdir) - 1] == '\\' ?
470 NullStr : "\\",
471 pci->pszDisplayName);
472 // Make directory if required
473 strcpy(dirname, newname);
474 p = strrchr(dirname, '\\');
475 if (p) {
476 if (p > dirname + 2)
477 p++;
478 *p = 0;
479 if (IsFile(dirname) == -1)
480 MassMkdir(hwndMain, dirname);
481 }
482 rc = docopyf(MOVE, pci->pszFileName, "%s", newname);
483 if (!rc && stricmp(pci->pszFileName, newname)) {
484 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pci),
485 MPFROM2SHORT(FALSE, CRA_SELECTED));
486 if (pciD->rc.flRecordAttr & CRA_SELECTED)
487 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciD),
488 MPFROM2SHORT(FALSE, CRA_SELECTED));
489 FreeCnrItemData(pciD);
490 pciD->pszFileName = xstrdup(newname, pszSrcFile, __LINE__);
491 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR)) {
492 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->leftdir);
493 if (cmp->leftdir[strlen(cmp->leftdir) - 1] != '\\')
494 pciD->pszDisplayName++;
495 }
496 else {
497 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->rightdir);
498 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
499 pciD->pszDisplayName++;
500 }
501 // 02 Aug 07 SHL fixme to know Longname transfer is correct?
502 pciD->pszLongName = pci->pszLongName;
503 if (pciD->pszSubject != NullStr) {
504 xfree(pciD->pszSubject);
505 pciD->pszSubject = NullStr;
506 }
507 pciD->attrFile = pci->attrFile;
508 pciD->pszDispAttr = pci->pszDispAttr;
509 pciD->flags = CNRITEM_EXISTS; // 04 Aug 07 SHL
510 pciD->date = pci->date;
511 pciD->time = pci->time;
512 pciD->ladate = pci->ladate;
513 pciD->latime = pci->latime;
514 pciD->crdate = pci->crdate;
515 pciD->crtime = pci->crtime;
516 pciD->cbFile = pci->cbFile;
517 pciD->easize = pci->easize;
518
519 if (pci->pszFileName != NullStr) {
520 xfree(pci->pszFileName);
521 pci->pszFileName = NullStr;
522 pci->pszDisplayName = pci->pszFileName;
523 pci->rc.pszIcon = pci->pszFileName;
524 }
525 if (pci->pszSubject != NullStr) {
526 xfree(pci->pszSubject);
527 pci->pszSubject = NullStr;
528 }
529 pci->flags = 0;
530
531 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD, MPFROMP(&pci),
532 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
533 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD, MPFROMP(&pciD),
534 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
535 }
536 else if (rc) {
537 rc = Dos_Error(MB_ENTERCANCEL,
538 rc,
539 HWND_DESKTOP,
540 pszSrcFile,
541 __LINE__,
542 GetPString(IDS_COMPMOVEFAILEDTEXT),
543 pci->pszFileName, newname);
544 if (rc == MBID_CANCEL) // Cause loop to break
545 pciNextS = NULL;
546 }
547 break;
548
549 case IDM_COPY:
550 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR))
551 sprintf(newname, "%s%s%s",
552 cmp->leftdir,
553 cmp->leftdir[strlen(cmp->leftdir) - 1] == '\\' ?
554 NullStr : "\\",
555 pci->pszDisplayName);
556 else
557 sprintf(newname, "%s%s%s",
558 cmp->rightdir,
559 cmp->rightdir[strlen(cmp->rightdir) - 1] == '\\' ?
560 NullStr : "\\",
561 pci->pszDisplayName);
562 // Make directory if required
563 strcpy(dirname, newname);
564 p = strrchr(dirname, '\\');
565 if (p) {
566 if (p > dirname + 2)
567 p++;
568 *p = 0;
569 if (IsFile(dirname) == -1)
570 MassMkdir(hwndMain, dirname);
571 }
572 rc = docopyf(COPY, pci->pszFileName, "%s", newname);
573 if (rc) {
574 rc = Dos_Error(MB_ENTERCANCEL,
575 rc,
576 HWND_DESKTOP,
577 pszSrcFile,
578 __LINE__,
579 GetPString(IDS_COMPCOPYFAILEDTEXT),
580 pci->pszFileName, newname);
581 if (rc == MBID_CANCEL)
582 pciNextS = NULL; // Cause loop to break
583 }
584 else {
585 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pci),
586 MPFROM2SHORT(FALSE, CRA_SELECTED));
587 if (pciD->rc.flRecordAttr & CRA_SELECTED)
588 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciD),
589 MPFROM2SHORT(FALSE, CRA_SELECTED));
590 FreeCnrItemData(pciD);
591 pciD->pszFileName = xstrdup(newname, pszSrcFile, __LINE__);
592 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR)) {
593 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->leftdir);
594 if (cmp->leftdir[strlen(cmp->leftdir) - 1] != '\\')
595 pciD->pszDisplayName++;
596 }
597 else {
598 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->rightdir);
599 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
600 pciD->pszDisplayName++;
601 }
602 pciD->attrFile = pci->attrFile;
603 pciD->pszDispAttr = pci->pszDispAttr;
604 pciD->flags = CNRITEM_EXISTS;
605 pciD->date = pci->date;
606 pciD->time = pci->time;
607 pciD->ladate = pci->ladate;
608 pciD->latime = pci->latime;
609 pciD->crdate = pci->crdate;
610 pciD->crtime = pci->crtime;
611 pciD->cbFile = pci->cbFile;
612 pciD->easize = pci->easize;
613
614 // 02 Aug 07 SHL fixme to know why subject cleared?
615 if (pci->pszSubject != NullStr) {
616 xfree(pci->pszSubject);
617 pci->pszSubject = NullStr;
618 }
619 // 02 Aug 07 SHL fixme to know why - should already be set?
620 // pci->flags = CNRITEM_EXISTS;
621
622 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD, MPFROMP(&pci),
623 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
624 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD, MPFROMP(&pciD),
625 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
626 }
627 break;
628
629 default:
630 break;
631 } // switch
632
633 } // if have name
634
635 pci = pciNextS;
636 pciD = pciNextD;
637
638 } // while
639 Abort:
640 WinDestroyMsgQueue(hmq);
641 }
642 DecrThreadUsage();
643 WinTerminate(hab);
644 }
645 PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPFROMLONG(1L), MPVOID);
646 PostMsg(cmp->hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DESELECTALL, 0), MPVOID);
647 free(cmp);
648}
649
650//=== SelectCnrsThread() Update container selection flags thread ===
651
652static VOID SelectCnrsThread(VOID * args)
653{
654 COMPARE *cmp = (COMPARE *) args;
655 HAB hab;
656 HMQ hmq;
657
658 if (!cmp)
659 return;
660
661 DosError(FERR_DISABLEHARDERR);
662
663 hab = WinInitialize(0);
664 if (hab) {
665 hmq = WinCreateMsgQueue(hab, 0);
666 if (hmq) {
667 WinCancelShutdown(hmq, TRUE);
668 IncrThreadUsage();
669 priority_normal();
670 switch (cmp->action) {
671 case IDM_INVERT:
672 InvertAll(WinWindowFromID(cmp->hwnd, COMP_LEFTDIR));
673 InvertAll(WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR));
674 break;
675
676 case IDM_DESELECTALL:
677 Deselect(WinWindowFromID(cmp->hwnd, COMP_LEFTDIR));
678 Deselect(WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR));
679 break;
680
681 default:
682 SpecialSelect(WinWindowFromID(cmp->hwnd, COMP_LEFTDIR),
683 WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR),
684 cmp->action, cmp->reset);
685 break;
686 }
687 if (!PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPFROMLONG(1L), MPVOID))
688 WinSendMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPFROMLONG(1L), MPVOID);
689 WinDestroyMsgQueue(hmq);
690 }
691 DecrThreadUsage();
692 WinTerminate(hab);
693 }
694 free(cmp);
695}
696
697/**
698 * Build FILELIST given pathname
699 */
700
701static VOID FillDirList(CHAR *str, INT skiplen, BOOL recurse,
702 FILELIST ***list, INT *numfiles, INT *numalloc)
703{
704
705 BYTE *fb;
706 CHAR *enddir;
707 ULONG x;
708 CHAR *maskstr;
709 FILEFINDBUF4 *ffb4, *pffb;
710 HDIR hDir;
711 ULONG nm, fl = 0, ulM = 64;
712 APIRET rc;
713
714 if (!str || !*str) {
715 Runtime_Error(pszSrcFile, __LINE__, "no data");
716 return;
717 }
718
719 if (!recurse)
720 ulM = FilesToGet;
721 maskstr = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
722 if (!maskstr)
723 return;
724 ffb4 = xmalloc(sizeof(FILEFINDBUF4) * ulM, pszSrcFile, __LINE__);
725 if (!ffb4) {
726 free(maskstr);
727 return;
728 }
729 x = strlen(str);
730 memcpy(maskstr, str, x + 1);
731 enddir = maskstr + x;
732 if (*(enddir - 1) != '\\') {
733 *enddir = '\\';
734 enddir++;
735 *enddir = 0;
736 }
737 *enddir = '*';
738 *(enddir + 1) = 0;
739 hDir = HDIR_CREATE;
740 nm = ulM;
741 if (recurse)
742 fl = FILE_DIRECTORY;
743 DosError(FERR_DISABLEHARDERR);
744 rc = DosFindFirst(maskstr, &hDir,
745 (FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
746 FILE_SYSTEM | FILE_HIDDEN) | fl,
747 ffb4, sizeof(FILEFINDBUF4) * nm, &nm, FIL_QUERYEASIZE);
748 if (!rc) {
749 while (!rc) {
750 fb = (BYTE *) ffb4;
751 x = 0;
752 while (x < nm) {
753 pffb = (FILEFINDBUF4 *) fb;
754 if (pffb->attrFile & FILE_DIRECTORY) {
755 // Skip . and ..
756 if (recurse &&
757 (pffb->achName[0] != '.' ||
758 (pffb->achName[1] &&
759 (pffb->achName[1] != '.' || pffb->achName[2])))) {
760 if (fForceUpper)
761 strupr(pffb->achName);
762 else if (fForceLower)
763 strlwr(pffb->achName);
764 memcpy(enddir, pffb->achName, pffb->cchName + 1);
765 FillDirList(maskstr, skiplen, recurse, list, numfiles, numalloc);
766 }
767 }
768 else {
769 if (fForceUpper)
770 strupr(pffb->achName);
771 else if (fForceLower)
772 strlwr(pffb->achName);
773 memcpy(enddir, pffb->achName, pffb->cchName + 1);
774 if (AddToFileList
775 (maskstr + skiplen, pffb, list, numfiles, numalloc))
776 goto Abort;
777 }
778 fb += pffb->oNextEntryOffset;
779 x++;
780 }
781 nm = ulM;
782 DosError(FERR_DISABLEHARDERR);
783 rc = DosFindNext(hDir, ffb4, sizeof(FILEFINDBUF4) * nm, &nm);
784 }
785 Abort:
786 DosFindClose(hDir);
787 DosSleep(1);
788 }
789 free(maskstr);
790 free(ffb4);
791}
792
793//=== CompNames() Compare names for qsort ===
794
795static int CompNames(const void *n1, const void *n2)
796{
797 FILELIST *fl1 = *(FILELIST **) n1;
798 FILELIST *fl2 = *(FILELIST **) n2;
799
800 return stricmp(fl1->fname, fl2->fname);
801}
802
803//=== FillCnrsThread() Fill left and right containers ===
804
805static VOID FillCnrsThread(VOID *args)
806{
807 COMPARE *cmp = (COMPARE *) args;
808 HAB hab;
809 HMQ hmq;
810 BOOL notified = FALSE;
811
812 HWND hwndLeft, hwndRight;
813 CHAR szBuf[CCHMAXPATH];
814 CNRINFO cnri;
815
816 if (!cmp) {
817 Runtime_Error(pszSrcFile, __LINE__, "no data");
818 _endthread();
819 }
820
821 DosError(FERR_DISABLEHARDERR);
822
823 hab = WinInitialize(0);
824 if (!hab)
825 Win_Error(NULLHANDLE, NULLHANDLE, pszSrcFile, __LINE__, "WinInitialize");
826 else {
827 hmq = WinCreateMsgQueue(hab, 0);
828 if (!hmq)
829 Win_Error(NULLHANDLE, NULLHANDLE, pszSrcFile, __LINE__,
830 "WinCreateMsgQueue");
831 else {
832 INT x;
833 INT l;
834 INT r;
835 ULONG cntr;
836 FILELIST **filesl = NULL;
837 FILELIST **filesr = NULL;
838 INT numfilesl = 0;
839 INT numfilesr = 0;
840 INT numallocl = 0;
841 INT numallocr = 0;
842 INT lenl; // Directory prefix length
843 INT lenr;
844 UINT recsNeeded;
845 PCNRITEM pcilFirst;
846 PCNRITEM pcirFirst;
847 PCNRITEM pcil;
848 PCNRITEM pcir;
849 RECORDINSERT ri;
850 CHAR *pch;
851
852 WinCancelShutdown(hmq, TRUE);
853 IncrThreadUsage();
854 hwndLeft = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
855 hwndRight = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
856 lenl = strlen(cmp->leftdir);
857 if (cmp->leftdir[strlen(cmp->leftdir) - 1] != '\\')
858 lenl++;
859 lenr = strlen(cmp->rightdir);
860 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
861 lenr++;
862 priority_normal();
863 // Clear containers
864 RemoveCnrItems(hwndRight, NULL, 0, CMA_FREE | CMA_INVALIDATE);
865 RemoveCnrItems(hwndLeft, NULL, 0, CMA_FREE | CMA_INVALIDATE);
866 cmp->cmp->totalleft = cmp->cmp->totalright = 0;
867
868 // Build list of all files in left directory
869 if (fForceLower)
870 strlwr(cmp->leftdir);
871 else if (fForceUpper)
872 strupr(cmp->leftdir);
873 FillDirList(cmp->leftdir, lenl, cmp->includesubdirs,
874 &filesl, &numfilesl, &numallocl);
875
876 if (filesl)
877 qsort(filesl, numfilesl, sizeof(CHAR *), CompNames);
878
879 // Build list of all files in right directory
880 if (!*cmp->rightlist) {
881 if (fForceLower)
882 strlwr(cmp->rightdir);
883 else if (fForceUpper)
884 strupr(cmp->rightdir);
885 FillDirList(cmp->rightdir, lenr, cmp->includesubdirs,
886 &filesr, &numfilesr, &numallocr);
887 }
888 else {
889 // Use snapshot file
890 FILE *fp;
891 FILEFINDBUF4 fb4;
892 CHAR str[CCHMAXPATH * 2], *p;
893
894 memset(&fb4, 0, sizeof(fb4));
895 fp = fopen(cmp->rightlist, "r");
896 if (!fp)
897 Runtime_Error(pszSrcFile, __LINE__, "can not open %s (%d)",
898 cmp->rightlist, errno);
899 else {
900 while (!feof(fp)) {
901 // First get name of directory
902 if (!xfgets_bstripcr(str, sizeof(str), fp, pszSrcFile, __LINE__))
903 break; // EOF
904 p = str;
905 if (*p == '\"') {
906 // Quoted
907 p++;
908 if (*p && *p != '\"') {
909 p = strchr(p, '\"');
910 if (p) {
911 *p = 0;
912 if (*(str + 1)) {
913 strcpy(cmp->rightdir, str + 1);
914 if (fForceUpper)
915 strupr(cmp->rightdir);
916 else if (fForceLower)
917 strlwr(cmp->rightdir);
918 p = cmp->rightdir + (strlen(cmp->rightdir) - 1);
919 if (p - cmp->rightdir > 3 && *p == '\\')
920 *p = 0; // Chop trailing slash
921 break;
922 }
923 }
924 }
925 }
926 } // while !EOF
927
928 memset(&cnri, 0, sizeof(cnri));
929 cnri.cb = sizeof(cnri);
930 cnri.pszCnrTitle = cmp->rightdir;
931 if (!WinSendMsg(hwndRight, CM_SETCNRINFO,
932 MPFROMP(&cnri), MPFROMLONG(CMA_CNRTITLE))) {
933 Win_Error(hwndRight, cmp->hwnd, pszSrcFile, __LINE__, "CM_SETCNRINFO");
934 }
935
936 if (*cmp->rightdir) {
937 lenr = strlen(cmp->rightdir) +
938 (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\');
939 while (!feof(fp)) {
940 if (!xfgets_bstripcr
941 (str, sizeof(str), fp, pszSrcFile, __LINE__))
942 break;
943 p = str;
944 if (*p == '\"') {
945 p++;
946 if (*p && *p != '\"') {
947 p = strchr(p, '\"');
948 if (p) {
949 *p = 0;
950 p++;
951 if (*p == ',') {
952 p++;
953 if (!cmp->includesubdirs && atol(p) > lenr)
954 continue;
955 p = strchr(p, ',');
956 if (p) {
957 p++;
958 fb4.cbFile = atol(p);
959 p = strchr(p, ',');
960 if (p) {
961 p++;
962 fb4.fdateLastWrite.year = atol(p) - 1980;
963 p = strchr(p, '/');
964 if (p) {
965 p++;
966 fb4.fdateLastWrite.month = atol(p);
967 p = strchr(p, '/');
968 if (p) {
969 p++;
970 fb4.fdateLastWrite.day = atol(p);
971 p = strchr(p, ',');
972 if (p) {
973 p++;
974 fb4.ftimeLastWrite.hours = atol(p);
975 p = strchr(p, ':');
976 if (p) {
977 p++;
978 fb4.ftimeLastWrite.minutes = atol(p);
979 p = strchr(p, ':');
980 if (p) {
981 p++;
982 fb4.ftimeLastWrite.twosecs = atol(p);
983 p = strchr(p, ',');
984 if (p) {
985 p++;
986 fb4.attrFile = atol(p);
987 p = strchr(p, ',');
988 if (p) {
989 p++;
990 fb4.cbList = atol(p) * 2;
991 if (fForceUpper)
992 strupr(str + 1);
993 else if (fForceLower)
994 strlwr(str + 1);
995 if (AddToFileList((str + 1) + lenr,
996 &fb4,
997 &filesr,
998 &numfilesr,
999 &numallocr))
1000 break;
1001 }
1002 }
1003 }
1004 }
1005 }
1006 }
1007 }
1008 }
1009 }
1010 }
1011 }
1012 }
1013 }
1014 } // while
1015 } // if have rightdir
1016 fclose(fp);
1017 }
1018 } // if snapshot file
1019
1020 if (filesr)
1021 qsort(filesr, numfilesr, sizeof(CHAR *), CompNames);
1022
1023 // We now have two lists of files, both sorted.
1024 // Count total number of container entries required on each side
1025 l = r = 0;
1026 recsNeeded = 0;
1027 while ((filesl && filesl[l]) || (filesr && filesr[r])) {
1028
1029 if (filesl && filesl[l]) {
1030 if (filesr && filesr[r])
1031 x = stricmp(filesl[l]->fname, filesr[r]->fname);
1032 else
1033 x = -1; // Left side list longer
1034 }
1035 else
1036 x = +1; // Right side list longer
1037
1038 if (x <= 0)
1039 l++; // On left side
1040 if (x >= 0)
1041 r++; // On right side
1042
1043 recsNeeded++; // Keep count of how many entries req'd
1044
1045 } // while
1046
1047 WinSendMsg(cmp->hwnd, UM_CONTAINERHWND, MPVOID, MPVOID);
1048
1049 // Now insert records into the containers
1050 cntr = 0;
1051 l = r = 0;
1052 if (recsNeeded) {
1053 pcilFirst = WinSendMsg(hwndLeft,
1054 CM_ALLOCRECORD,
1055 MPFROMLONG(EXTRA_RECORD_BYTES),
1056 MPFROMLONG(recsNeeded));
1057 if (!pcilFirst) {
1058 Win_Error(hwndLeft, cmp->hwnd, pszSrcFile, __LINE__, "CM_ALLOCRECORD %u failed",
1059 recsNeeded);
1060 recsNeeded = 0;
1061 }
1062 }
1063 if (recsNeeded) {
1064 pcirFirst = WinSendMsg(hwndRight, CM_ALLOCRECORD,
1065 MPFROMLONG(EXTRA_RECORD_BYTES),
1066 MPFROMLONG(recsNeeded));
1067 if (!pcirFirst) {
1068 Win_Error(hwndRight, cmp->hwnd, pszSrcFile, __LINE__, "CM_ALLOCRECORD %u failed",
1069 recsNeeded);
1070 recsNeeded = 0;
1071 FreeCnrItemList(hwndLeft, pcilFirst);
1072 }
1073 }
1074
1075 if (recsNeeded) {
1076
1077 pcil = pcilFirst;
1078 pcir = pcirFirst;
1079 while ((filesl && filesl[l]) || (filesr && filesr[r])) {
1080 pcir->hwndCnr = hwndRight;
1081 pcir->rc.hptrIcon = (HPOINTER) 0;
1082 pcil->hwndCnr = hwndLeft;
1083 pcil->rc.hptrIcon = (HPOINTER) 0;
1084
1085 if (filesl && filesl[l]) {
1086 if (filesr && filesr[r])
1087 x = stricmp(filesl[l]->fname, filesr[r]->fname);
1088 else
1089 x = -1; // Left side list longer
1090 }
1091 else
1092 x = +1; // Right side list longer
1093
1094 if (x <= 0) {
1095 // File appears on left side
1096 sprintf(szBuf, "%s%s%s", cmp->leftdir,
1097 (cmp->leftdir[strlen(cmp->leftdir) - 1] == '\\') ?
1098 NullStr : "\\", filesl[l]->fname);
1099 pcil->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__);
1100 pcil->pszDisplayName = pcil->pszFileName + lenl;
1101 pcil->attrFile = filesl[l]->attrFile;
1102 pcil->pszDispAttr = FileAttrToString(pcil->attrFile);
1103 pcil->cbFile = filesl[l]->cbFile;
1104 pcil->easize = filesl[l]->easize;
1105 pcil->date.day = filesl[l]->date.day;
1106 pcil->date.month = filesl[l]->date.month;
1107 pcil->date.year = filesl[l]->date.year + 1980;
1108 pcil->time.seconds = filesl[l]->time.twosecs * 2;
1109 pcil->time.minutes = filesl[l]->time.minutes;
1110 pcil->time.hours = filesl[l]->time.hours;
1111 pcil->ladate.day = filesl[l]->ladate.day;
1112 pcil->ladate.month = filesl[l]->ladate.month;
1113 pcil->ladate.year = filesl[l]->ladate.year + 1980;
1114 pcil->latime.seconds = filesl[l]->latime.twosecs * 2;
1115 pcil->latime.minutes = filesl[l]->latime.minutes;
1116 pcil->latime.hours = filesl[l]->latime.hours;
1117 pcil->crdate.day = filesl[l]->crdate.day;
1118 pcil->crdate.month = filesl[l]->crdate.month;
1119 pcil->crdate.year = filesl[l]->crdate.year + 1980;
1120 pcil->crtime.seconds = filesl[l]->crtime.twosecs * 2;
1121 pcil->crtime.minutes = filesl[l]->crtime.minutes;
1122 pcil->crtime.hours = filesl[l]->crtime.hours;
1123 if (*cmp->dcd.mask.szMask) {
1124 if (!Filter((PMINIRECORDCORE) pcil, (PVOID)&cmp->dcd.mask)) {
1125 pcil->rc.flRecordAttr |= CRA_FILTERED;
1126 pcir->rc.flRecordAttr |= CRA_FILTERED;
1127 }
1128 }
1129 pcil->flags |= CNRITEM_EXISTS;
1130 } // if on left
1131
1132 if (x >= 0) {
1133 // File appears on right side
1134 sprintf(szBuf, "%s%s%s", cmp->rightdir,
1135 (cmp->rightdir[strlen(cmp->rightdir) - 1] == '\\') ?
1136 NullStr : "\\", filesr[r]->fname);
1137 pcir->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__); // 31 Jul 07 SHL
1138 pcir->pszDisplayName = pcir->pszFileName + lenr;
1139 pcir->attrFile = filesr[r]->attrFile;
1140 // pcir->rc.hptrIcon = hptrFile;
1141 pcir->pszDispAttr = FileAttrToString(pcir->attrFile);
1142 pcir->cbFile = filesr[r]->cbFile;
1143 pcir->easize = filesr[r]->easize;
1144 pcir->date.day = filesr[r]->date.day;
1145 pcir->date.month = filesr[r]->date.month;
1146 pcir->date.year = filesr[r]->date.year + 1980;
1147 pcir->time.seconds = filesr[r]->time.twosecs * 2;
1148 pcir->time.minutes = filesr[r]->time.minutes;
1149 pcir->time.hours = filesr[r]->time.hours;
1150 pcir->ladate.day = filesr[r]->ladate.day;
1151 pcir->ladate.month = filesr[r]->ladate.month;
1152 pcir->ladate.year = filesr[r]->ladate.year + 1980;
1153 pcir->latime.seconds = filesr[r]->latime.twosecs * 2;
1154 pcir->latime.minutes = filesr[r]->latime.minutes;
1155 pcir->latime.hours = filesr[r]->latime.hours;
1156 pcir->crdate.day = filesr[r]->crdate.day;
1157 pcir->crdate.month = filesr[r]->crdate.month;
1158 pcir->crdate.year = filesr[r]->crdate.year + 1980;
1159 pcir->crtime.seconds = filesr[r]->crtime.twosecs * 2;
1160 pcir->crtime.minutes = filesr[r]->crtime.minutes;
1161 pcir->crtime.hours = filesr[r]->crtime.hours;
1162 if (~pcil->rc.flRecordAttr & CRA_FILTERED &&
1163 *cmp->dcd.mask.szMask) {
1164 if (!Filter((PMINIRECORDCORE)pcir, (PVOID)&cmp->dcd.mask)) {
1165 pcil->rc.flRecordAttr |= CRA_FILTERED;
1166 pcir->rc.flRecordAttr |= CRA_FILTERED;
1167 }
1168 }
1169 pcir->flags |= CNRITEM_EXISTS;
1170 } // if on right
1171
1172 if (x == 0) {
1173 // File appears on both sides
1174 pch = szBuf;
1175 // Subject field holds status messages
1176 *pch = 0;
1177 if (pcil->cbFile + pcil->easize > pcir->cbFile + pcir->easize) {
1178 pcil->flags |= CNRITEM_LARGER;
1179 pcir->flags |= CNRITEM_SMALLER;
1180 strcpy(pch, GetPString(IDS_LARGERTEXT));
1181 pch += 6;
1182 }
1183 else if (pcil->cbFile + pcil->easize <
1184 pcir->cbFile + pcir->easize) {
1185 pcil->flags |= CNRITEM_SMALLER;
1186 pcir->flags |= CNRITEM_LARGER;
1187 strcpy(pch, GetPString(IDS_SMALLERTEXT));
1188 pch += 7;
1189 }
1190 if ((pcil->date.year > pcir->date.year) ? TRUE :
1191 (pcil->date.year < pcir->date.year) ? FALSE :
1192 (pcil->date.month > pcir->date.month) ? TRUE :
1193 (pcil->date.month < pcir->date.month) ? FALSE :
1194 (pcil->date.day > pcir->date.day) ? TRUE :
1195 (pcil->date.day < pcir->date.day) ? FALSE :
1196 (pcil->time.hours > pcir->time.hours) ? TRUE :
1197 (pcil->time.hours < pcir->time.hours) ? FALSE :
1198 (pcil->time.minutes > pcir->time.minutes) ? TRUE :
1199 (pcil->time.minutes < pcir->time.minutes) ? FALSE :
1200 (pcil->time.seconds > pcir->time.seconds) ? TRUE :
1201 (pcil->time.seconds < pcir->time.seconds) ? FALSE : FALSE) {
1202 pcil->flags |= CNRITEM_NEWER;
1203 pcir->flags |= CNRITEM_OLDER;
1204 if (pch != szBuf) {
1205 strcpy(pch, ", ");
1206 pch += 2;
1207 }
1208 strcpy(pch, GetPString(IDS_NEWERTEXT));
1209 pch += 5;
1210 }
1211 else if ((pcil->date.year < pcir->date.year) ? TRUE :
1212 (pcil->date.year > pcir->date.year) ? FALSE :
1213 (pcil->date.month < pcir->date.month) ? TRUE :
1214 (pcil->date.month > pcir->date.month) ? FALSE :
1215 (pcil->date.day < pcir->date.day) ? TRUE :
1216 (pcil->date.day > pcir->date.day) ? FALSE :
1217 (pcil->time.hours < pcir->time.hours) ? TRUE :
1218 (pcil->time.hours > pcir->time.hours) ? FALSE :
1219 (pcil->time.minutes < pcir->time.minutes) ? TRUE :
1220 (pcil->time.minutes > pcir->time.minutes) ? FALSE :
1221 (pcil->time.seconds < pcir->time.seconds) ? TRUE :
1222 (pcil->time.seconds > pcir->time.seconds) ? FALSE :
1223 FALSE) {
1224 pcil->flags |= CNRITEM_OLDER;
1225 pcir->flags |= CNRITEM_NEWER;
1226 if (pch != szBuf) {
1227 strcpy(pch, ", ");
1228 pch += 2;
1229 }
1230 strcpy(pch, GetPString(IDS_OLDERTEXT));
1231 pch += 5;
1232 }
1233 // fixme to know why not displayed - defect?
1234 pcil->pszSubject = *szBuf ?
1235 xstrdup(szBuf, pszSrcFile, __LINE__) :
1236 NullStr;
1237
1238 } // if on both sides
1239
1240 if (x <= 0) {
1241 free(filesl[l]);
1242 l++;
1243 }
1244
1245 if (x >= 0) {
1246 free(filesr[r]);
1247 r++;
1248 }
1249
1250 // Ensure empty buffers point somewhere
1251 if (!pcil->pszFileName) {
1252 pcil->pszFileName = NullStr;
1253 pcil->pszDisplayName = pcil->pszFileName;
1254 }
1255
1256 if (!pcir->pszFileName) {
1257 pcir->pszFileName = NullStr;
1258 pcir->pszDisplayName = pcir->pszFileName;
1259 }
1260
1261 pcil->rc.pszIcon = pcil->pszDisplayName;
1262 pcir->rc.pszIcon = pcir->pszDisplayName;
1263
1264 pcil->pszLongName = NullStr;
1265 pcir->pszLongName = NullStr;
1266
1267 if (!pcil->pszSubject)
1268 pcil->pszSubject = NullStr;
1269 if (!pcir->pszSubject)
1270 pcil->pszSubject = NullStr;
1271
1272 if (!pcil->pszDispAttr)
1273 pcil->pszDispAttr = NullStr;
1274 if (!pcir->pszDispAttr)
1275 pcil->pszDispAttr = NullStr;
1276
1277 // fixme to be time based - every 2 sec should be OK
1278 if (!(cntr % 500))
1279 DosSleep(1);
1280 else if (!(cntr % 50))
1281 DosSleep(1);
1282
1283 cntr++;
1284
1285 pcil = (PCNRITEM) pcil->rc.preccNextRecord;
1286 pcir = (PCNRITEM) pcir->rc.preccNextRecord;
1287
1288 } // while filling left or right
1289
1290 if (filesl)
1291 free(filesl); // Free header - have already freed elements
1292 filesl = NULL;
1293 if (filesr)
1294 free(filesr);
1295 filesr = NULL;
1296 // Insert 'em
1297 WinSendMsg(cmp->hwnd, UM_CONTAINERDIR, MPVOID, MPVOID);
1298
1299 memset(&ri, 0, sizeof(RECORDINSERT));
1300 ri.cb = sizeof(RECORDINSERT);
1301 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1302 ri.pRecordParent = (PRECORDCORE) NULL;
1303 ri.zOrder = (ULONG) CMA_TOP;
1304 ri.cRecordsInsert = recsNeeded;
1305 ri.fInvalidateRecord = FALSE;
1306 if (!WinSendMsg(hwndLeft, CM_INSERTRECORD,
1307 MPFROMP(pcilFirst), MPFROMP(&ri))) {
1308 Win_Error(hwndLeft, cmp->hwnd, pszSrcFile, __LINE__, "CM_INSERTRECORD");
1309 FreeCnrItemList(hwndLeft, pcilFirst);
1310 numfilesl = 0;
1311 }
1312
1313 memset(&ri, 0, sizeof(RECORDINSERT));
1314 ri.cb = sizeof(RECORDINSERT);
1315 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1316 ri.pRecordParent = (PRECORDCORE) NULL;
1317 ri.zOrder = (ULONG) CMA_TOP;
1318 ri.cRecordsInsert = recsNeeded;
1319 ri.fInvalidateRecord = FALSE;
1320
1321 if (!WinSendMsg(hwndRight, CM_INSERTRECORD,
1322 MPFROMP(pcirFirst), MPFROMP(&ri))) {
1323 Win_Error(hwndRight, cmp->hwnd, pszSrcFile, __LINE__, "CM_INSERTRECORD");
1324 RemoveCnrItems(hwndLeft, NULL, 0, CMA_FREE | CMA_INVALIDATE);
1325 FreeCnrItemList(hwndRight, pcirFirst);
1326 numfilesr = 0;
1327 }
1328
1329 cmp->cmp->totalleft = numfilesl;
1330 cmp->cmp->totalright = numfilesr;
1331
1332 } // if recsNeeded
1333
1334 Deselect(hwndLeft);
1335 Deselect(hwndRight);
1336
1337 if (!PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID))
1338 WinSendMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
1339 notified = TRUE;
1340
1341 if (filesl)
1342 FreeList((CHAR **)filesl); // Must have failed to create container
1343 if (filesr)
1344 FreeList((CHAR **)filesr);
1345
1346 WinDestroyMsgQueue(hmq);
1347 }
1348 DecrThreadUsage();
1349 WinTerminate(hab);
1350 }
1351 if (!notified)
1352 PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
1353 free(cmp);
1354 DosPostEventSem(CompactSem);
1355}
1356
1357#define hwndLeft (WinWindowFromID(hwnd,COMP_LEFTDIR))
1358#define hwndRight (WinWindowFromID(hwnd,COMP_RIGHTDIR))
1359
1360//=== CompareDlgProc() Compare directories dialog procedure ===
1361
1362MRESULT EXPENTRY CompareDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1363{
1364 COMPARE *cmp;
1365
1366 static HPOINTER hptr = (HPOINTER) 0;
1367
1368 switch (msg) {
1369 case WM_INITDLG:
1370 cmp = (COMPARE *) mp2;
1371 if (!cmp) {
1372 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
1373 WinDismissDlg(hwnd, 0);
1374 }
1375 else {
1376 if (!hptr)
1377 hptr = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, COMPARE_ICON);
1378 WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptr), MPVOID);
1379 cmp->hwnd = hwnd;
1380 WinSetWindowPtr(hwnd, QWL_USER, (PVOID) cmp);
1381 SetCnrCols(hwndLeft, TRUE);
1382 SetCnrCols(hwndRight, TRUE);
1383 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1384 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
1385 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
1386 {
1387 USHORT ids[] = { COMP_LEFTDIR, COMP_RIGHTDIR, COMP_TOTALLEFT,
1388 COMP_TOTALRIGHT, COMP_SELLEFT, COMP_SELRIGHT,
1389 0
1390 };
1391 INT x;
1392
1393 for (x = 0; ids[x]; x++)
1394 SetPresParams(WinWindowFromID(hwnd, ids[x]),
1395 &RGBGREY,
1396 &RGBBLACK, &RGBBLACK, GetPString(IDS_8HELVTEXT));
1397 }
1398 }
1399 break;
1400
1401 case UM_STRETCH:
1402 {
1403 SWP swp, swpC;
1404 LONG titl, szbx, szby, sz;
1405 HWND hwndActive;
1406
1407 WinQueryWindowPos(hwnd, &swp);
1408 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
1409 hwndActive = WinQueryFocus(HWND_DESKTOP);
1410 szbx = SysVal(SV_CXSIZEBORDER);
1411 szby = SysVal(SV_CYSIZEBORDER);
1412 titl = SysVal(SV_CYTITLEBAR);
1413 titl += 26;
1414 swp.cx -= (szbx * 2);
1415 sz = (swp.cx / 8);
1416 WinQueryWindowPos(WinWindowFromID(hwnd, COMP_LEFTDIR), &swpC);
1417 WinSetWindowPos(WinWindowFromID(hwnd, COMP_LEFTDIR), HWND_TOP,
1418 szbx + 6,
1419 swpC.y,
1420 (swp.cx / 2) - (szbx + 6),
1421 ((swp.cy - swpC.y) - titl) - szby,
1422 SWP_MOVE | SWP_SIZE);
1423 WinSetWindowPos(WinWindowFromID(hwnd, COMP_RIGHTDIR), HWND_TOP,
1424 (swp.cx / 2) + (szbx + 6),
1425 swpC.y,
1426 (swp.cx / 2) - (szbx + 6),
1427 ((swp.cy - swpC.y) - titl) - szby,
1428 SWP_MOVE | SWP_SIZE);
1429 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALLEFTHDR), HWND_TOP,
1430 szbx + 6,
1431 ((swp.cy - titl) - szby) + 4,
1432 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1433 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALLEFT), HWND_TOP,
1434 sz + (szbx + 6),
1435 ((swp.cy - titl) - szby) + 4,
1436 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1437 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELLEFTHDR), HWND_TOP,
1438 (sz * 2) + (szbx + 6),
1439 ((swp.cy - titl) - szby) + 4,
1440 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1441 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELLEFT), HWND_TOP,
1442 (sz * 3) + (szbx + 6),
1443 ((swp.cy - titl) - szby) + 4,
1444 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1445 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALRIGHTHDR), HWND_TOP,
1446 (sz * 4) + (szbx + 6),
1447 ((swp.cy - titl) - szby) + 4,
1448 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1449 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALRIGHT), HWND_TOP,
1450 (sz * 5) + (szbx + 6),
1451 ((swp.cy - titl) - szby) + 4,
1452 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1453 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELRIGHTHDR), HWND_TOP,
1454 (sz * 6) + (szbx + 6),
1455 ((swp.cy - titl) - szby) + 4,
1456 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1457 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELRIGHT), HWND_TOP,
1458 (sz * 7) + (szbx + 6),
1459 ((swp.cy - titl) - szby) + 4,
1460 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
1461 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_TOTALLEFT),
1462 (HPS) 0, FALSE, FALSE);
1463 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_SELLEFT),
1464 (HPS) 0, FALSE, FALSE);
1465 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_TOTALRIGHT),
1466 (HPS) 0, FALSE, FALSE);
1467 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_SELRIGHT),
1468 (HPS) 0, FALSE, FALSE);
1469 PaintRecessedWindow(hwndLeft, (HPS) 0,
1470 (hwndActive == hwndLeft), TRUE);
1471 PaintRecessedWindow(hwndRight, (HPS) 0,
1472 (hwndActive == hwndRight), TRUE);
1473 }
1474 }
1475 return 0;
1476
1477 case WM_ADJUSTWINDOWPOS:
1478 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
1479 break;
1480
1481 case UM_SETUP:
1482 {
1483 CNRINFO cnri;
1484 BOOL tempsubj;
1485
1486 cmp = INSTDATA(hwnd);
1487 if (cmp) {
1488 cmp->dcd.size = sizeof(DIRCNRDATA);
1489 cmp->dcd.type = DIR_FRAME;
1490 cmp->dcd.hwndFrame = hwnd;
1491 cmp->dcd.hwndClient = hwnd;
1492 cmp->dcd.mask.attrFile = (FILE_DIRECTORY | FILE_ARCHIVED |
1493 FILE_READONLY | FILE_SYSTEM | FILE_HIDDEN);
1494 LoadDetailsSwitches("DirCmp", &cmp->dcd);
1495 cmp->dcd.detailslongname = FALSE;
1496 cmp->dcd.detailsicon = FALSE; // TRUE;
1497 }
1498 memset(&cnri, 0, sizeof(CNRINFO));
1499 cnri.cb = sizeof(CNRINFO);
1500 WinSendDlgItemMsg(hwnd, COMP_LEFTDIR, CM_QUERYCNRINFO,
1501 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
1502 cnri.flWindowAttr |= (CA_OWNERDRAW | CV_MINI);
1503 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 68;
1504 WinSendDlgItemMsg(hwnd, COMP_LEFTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
1505 MPFROMLONG(CMA_FLWINDOWATTR | CMA_XVERTSPLITBAR));
1506 memset(&cnri, 0, sizeof(CNRINFO));
1507 cnri.cb = sizeof(CNRINFO);
1508 WinSendDlgItemMsg(hwnd, COMP_RIGHTDIR, CM_QUERYCNRINFO,
1509 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
1510 cnri.flWindowAttr |= (CA_OWNERDRAW | CV_MINI);
1511 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 54;
1512 WinSendDlgItemMsg(hwnd, COMP_RIGHTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
1513 MPFROMLONG(CMA_FLWINDOWATTR | CMA_XVERTSPLITBAR));
1514 AdjustCnrColRO(hwndLeft, GetPString(IDS_FILENAMECOLTEXT), TRUE, FALSE);
1515 AdjustCnrColRO(hwndLeft, GetPString(IDS_LONGNAMECOLTEXT), TRUE, FALSE);
1516 AdjustCnrColRO(hwndRight, GetPString(IDS_FILENAMECOLTEXT), TRUE, FALSE);
1517 AdjustCnrColRO(hwndRight, GetPString(IDS_LONGNAMECOLTEXT), TRUE, FALSE);
1518 AdjustCnrColsForPref(hwndLeft, cmp->leftdir, &cmp->dcd, TRUE);
1519 tempsubj = cmp->dcd.detailssubject;
1520 cmp->dcd.detailssubject = FALSE;
1521 AdjustCnrColsForPref(hwndRight, cmp->rightdir, &cmp->dcd, TRUE);
1522 if (*cmp->rightlist) {
1523 AdjustCnrColVis(hwndRight, GetPString(IDS_LADATECOLTEXT), FALSE,
1524 FALSE);
1525 AdjustCnrColVis(hwndRight, GetPString(IDS_LATIMECOLTEXT), FALSE,
1526 FALSE);
1527 AdjustCnrColVis(hwndRight, GetPString(IDS_CRDATECOLTEXT), FALSE,
1528 FALSE);
1529 AdjustCnrColVis(hwndRight, GetPString(IDS_CRTIMECOLTEXT), FALSE,
1530 FALSE);
1531 }
1532 cmp->dcd.detailssubject = tempsubj;
1533 }
1534 return 0;
1535
1536 case WM_DRAWITEM:
1537 if (mp2) {
1538 POWNERITEM pown = (POWNERITEM)mp2;
1539 PCNRDRAWITEMINFO pcown;
1540 PCNRITEM pci;
1541
1542 pcown = (PCNRDRAWITEMINFO)pown->hItem;
1543 if (pcown) {
1544 pci = (PCNRITEM) pcown->pRecord;
1545 // 01 Aug 07 SHL if field null or blank, we draw
1546 // fixme to know why - probably to optimize and bypass draw?
1547 if (pci && (INT)pci != -1 && !*pci->pszFileName)
1548 return MRFROMLONG(TRUE);
1549 }
1550 }
1551 return 0;
1552
1553 case UM_CONTAINERHWND:
1554 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPHOLDBLDLISTTEXT));
1555 return 0;
1556
1557 case UM_CONTAINERDIR:
1558 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPHOLDFILLCNRTEXT));
1559 return 0;
1560
1561 case UM_CONTAINER_FILLED:
1562 cmp = INSTDATA(hwnd);
1563 if (!cmp) {
1564 Runtime_Error(pszSrcFile, __LINE__, "pCompare NULL");
1565 WinDismissDlg(hwnd, 0);
1566 }
1567 else {
1568 CHAR s[81];
1569
1570 cmp->filling = FALSE;
1571 WinEnableWindow(hwndLeft, TRUE);
1572 WinEnableWindow(hwndRight, TRUE);
1573 WinEnableWindowUpdate(hwndLeft, TRUE);
1574 WinEnableWindowUpdate(hwndRight, TRUE);
1575 sprintf(s, " %d", cmp->totalleft);
1576 WinSetDlgItemText(hwnd, COMP_TOTALLEFT, s);
1577 sprintf(s, " %d", cmp->totalright);
1578 WinSetDlgItemText(hwnd, COMP_TOTALRIGHT, s);
1579 sprintf(s, " %d", cmp->selleft);
1580 WinSetDlgItemText(hwnd, COMP_SELLEFT, s);
1581 sprintf(s, " %d", cmp->selright);
1582 WinSetDlgItemText(hwnd, COMP_SELRIGHT, s);
1583 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), TRUE);
1584 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), TRUE);
1585 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), TRUE);
1586 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), TRUE);
1587 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), TRUE);
1588 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), TRUE);
1589 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), TRUE);
1590 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), TRUE);
1591 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), TRUE);
1592 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), TRUE);
1593 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), TRUE);
1594 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), TRUE);
1595 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), TRUE);
1596 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), TRUE);
1597 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER), TRUE);
1598 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), TRUE);
1599 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT), TRUE);
1600 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL), TRUE);
1601 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), TRUE);
1602 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), TRUE);
1603 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), TRUE);
1604 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), TRUE);
1605 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), TRUE);
1606 if (!*cmp->rightlist) {
1607 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), TRUE);
1608 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), TRUE);
1609 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), TRUE);
1610 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), TRUE);
1611 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), TRUE);
1612 }
1613 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS), TRUE);
1614 if (*cmp->dcd.mask.szMask)
1615 WinSetDlgItemText(hwnd, COMP_NOTE,
1616 GetPString(IDS_COMPREADYFILTEREDTEXT));
1617 else
1618 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
1619 }
1620 break;
1621
1622 case WM_INITMENU:
1623 cmp = INSTDATA(hwnd);
1624 if (cmp) {
1625 switch (SHORT1FROMMP(mp1)) {
1626 case IDM_COMMANDSMENU:
1627 SetupCommandMenu(cmp->dcd.hwndLastMenu, hwnd);
1628 break;
1629 }
1630 }
1631 break;
1632
1633 case WM_MENUEND:
1634 cmp = INSTDATA(hwnd);
1635 if (cmp) {
1636 if ((HWND) mp2 == cmp->dcd.hwndLastMenu) {
1637 MarkAll(hwndLeft, TRUE, FALSE, TRUE);
1638 MarkAll(hwndRight, TRUE, FALSE, TRUE);
1639 WinDestroyWindow(cmp->dcd.hwndLastMenu);
1640 cmp->dcd.hwndLastMenu = (HWND) 0;
1641 }
1642 }
1643 break;
1644
1645 case WM_CONTROL:
1646 switch (SHORT1FROMMP(mp1)) {
1647 case COMP_INCLUDESUBDIRS:
1648 switch (SHORT2FROMMP(mp1)) {
1649 case BN_CLICKED:
1650 cmp = INSTDATA(hwnd);
1651 if (cmp)
1652 *cmp->rightlist = 0;
1653 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
1654 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
1655 break;
1656 }
1657 break;
1658 case COMP_HIDENOTSELECTED:
1659 switch (SHORT2FROMMP(mp1)) {
1660 case BN_CLICKED:
1661 WinSendMsg(hwnd, UM_HIDENOTSELECTED, MPVOID, MPVOID);
1662 break;
1663 }
1664 break;
1665
1666 case COMP_LEFTDIR:
1667 case COMP_RIGHTDIR:
1668 switch (SHORT2FROMMP(mp1)) {
1669 case CN_KILLFOCUS:
1670 PaintRecessedWindow(WinWindowFromID(hwnd, SHORT1FROMMP(mp1)),
1671 (HPS) 0, FALSE, TRUE);
1672 break;
1673
1674 case CN_SETFOCUS:
1675 PaintRecessedWindow(WinWindowFromID(hwnd, SHORT1FROMMP(mp1)),
1676 (HPS) 0, TRUE, TRUE);
1677 break;
1678
1679 case CN_ENTER:
1680 if (mp2) {
1681
1682 PCNRITEM pci = (PCNRITEM) ((PNOTIFYRECORDENTER) mp2)->pRecord;
1683 HWND hwndCnr = WinWindowFromID(hwnd, SHORT1FROMMP(mp1));
1684
1685 SetShiftState();
1686 if (pci) {
1687 if (pci->rc.flRecordAttr & CRA_INUSE || !pci || !*pci->pszFileName)
1688 break;
1689 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
1690 MPFROM2SHORT(TRUE, CRA_INUSE));
1691 if (pci->attrFile & FILE_DIRECTORY) {
1692 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
1693 OpenObject(pci->pszFileName, Settings, hwnd);
1694 else
1695 OpenObject(pci->pszFileName, Default, hwnd);
1696 }
1697 else
1698 DefaultViewKeys(hwnd, hwnd, HWND_DESKTOP, NULL,
1699 pci->pszFileName);
1700 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS,
1701 MPFROMP(pci),
1702 MPFROM2SHORT(FALSE, CRA_INUSE |
1703 ((fUnHilite) ? CRA_SELECTED : 0)));
1704 }
1705 }
1706 break;
1707
1708 case CN_CONTEXTMENU:
1709 cmp = INSTDATA(hwnd);
1710 if (cmp) {
1711
1712 PCNRITEM pci = (PCNRITEM) mp2;
1713 USHORT id = COMP_CNRMENU;
1714
1715 if (cmp->dcd.hwndLastMenu)
1716 WinDestroyWindow(cmp->dcd.hwndLastMenu);
1717 cmp->dcd.hwndLastMenu = (HWND) 0;
1718 cmp->hwndCalling = WinWindowFromID(hwnd, SHORT1FROMMP(mp1));
1719 if (pci) {
1720 if (!pci || !*pci->pszFileName || *cmp->rightlist)
1721 break;
1722 id = COMP_MENU;
1723 WinSendMsg(cmp->hwndCalling, CM_SETRECORDEMPHASIS,
1724 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
1725 }
1726 cmp->dcd.hwndLastMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
1727 if (cmp->dcd.hwndLastMenu) {
1728 if (id == COMP_CNRMENU) {
1729 if (SHORT1FROMMP(mp1) == COMP_RIGHTDIR)
1730 WinSendMsg(cmp->dcd.hwndLastMenu, MM_DELETEITEM,
1731 MPFROM2SHORT(IDM_SHOWSUBJECT, FALSE), MPVOID);
1732 SetDetailsSwitches(cmp->dcd.hwndLastMenu, &cmp->dcd);
1733 if (SHORT1FROMMP(mp1) == COMP_LEFTDIR)
1734 WinSendMsg(cmp->dcd.hwndLastMenu, MM_DELETEITEM,
1735 MPFROM2SHORT(IDM_LOADLISTFILE, 0), MPVOID);
1736 else if (*cmp->rightlist)
1737 WinSendMsg(cmp->dcd.hwndLastMenu, MM_DELETEITEM,
1738 MPFROM2SHORT(IDM_SAVELISTFILE, 0), MPVOID);
1739 }
1740 PopupMenu(hwnd, hwnd, cmp->dcd.hwndLastMenu);
1741 }
1742 }
1743 break;
1744
1745 case CN_INITDRAG:
1746 cmp = INSTDATA(hwnd);
1747 if (*cmp->rightlist && SHORT1FROMMP(mp1) == COMP_RIGHTDIR)
1748 break;
1749 DoFileDrag(WinWindowFromID(hwnd, SHORT1FROMMP(mp1)),
1750 (HWND) 0, mp2, NULL, NULL, TRUE);
1751 break;
1752
1753 case CN_BEGINEDIT:
1754 case CN_REALLOCPSZ:
1755 // fixme to be gone - field edits not allowed
1756 Runtime_Error(pszSrcFile, __LINE__,
1757 "CN_BEGINEDIT/CN_REALLOCPSZ unexpected");
1758 break;
1759
1760 case CN_EMPHASIS:
1761 {
1762 PNOTIFYRECORDEMPHASIS pre = mp2;
1763 PCNRITEM pci;
1764
1765 if (pre->fEmphasisMask & CRA_SELECTED) {
1766 pci = (PCNRITEM) pre->pRecord;
1767 if (pci) {
1768 if (!pci || !*pci->pszFileName) {
1769 if (pci->rc.flRecordAttr & CRA_SELECTED)
1770 WinSendDlgItemMsg(hwnd, SHORT1FROMMP(mp1),
1771 CM_SETRECORDEMPHASIS,
1772 MPFROMP(pci),
1773 MPFROM2SHORT(FALSE, CRA_SELECTED));
1774 }
1775 else {
1776
1777 CHAR s[81];
1778
1779 cmp = INSTDATA(hwnd);
1780 if (pci->rc.flRecordAttr & CRA_SELECTED) {
1781 if (SHORT1FROMMP(mp1) == COMP_LEFTDIR)
1782 cmp->selleft++;
1783 else
1784 cmp->selright++;
1785 }
1786 else {
1787 if (SHORT1FROMMP(mp1) == COMP_LEFTDIR) {
1788 if (cmp->selleft)
1789 cmp->selleft--;
1790 }
1791 else {
1792 if (cmp->selright)
1793 cmp->selright--;
1794 }
1795 }
1796 if (SHORT1FROMMP(mp1) == COMP_LEFTDIR) {
1797 if (WinIsWindowEnabled(hwndLeft) || !(cmp->selleft % 50)) {
1798 sprintf(s, " %d", cmp->selleft);
1799 WinSetDlgItemText(hwnd, COMP_SELLEFT, s);
1800 }
1801 }
1802 else {
1803 if (WinIsWindowEnabled(hwndRight) || !(cmp->selright % 50)) {
1804 sprintf(s, " %d", cmp->selright);
1805 WinSetDlgItemText(hwnd, COMP_SELRIGHT, s);
1806 }
1807 }
1808 }
1809 }
1810 }
1811 }
1812 break;
1813
1814 case CN_SCROLL:
1815 cmp = INSTDATA(hwnd);
1816 if (!cmp->forcescroll) {
1817
1818 PNOTIFYSCROLL pns = mp2;
1819
1820 if (pns->fScroll & CMA_VERTICAL) {
1821 cmp->forcescroll = TRUE;
1822 WinSendDlgItemMsg(hwnd, (SHORT1FROMMP(mp1) == COMP_LEFTDIR) ?
1823 COMP_RIGHTDIR : COMP_LEFTDIR,
1824 CM_SCROLLWINDOW, MPFROMSHORT(CMA_VERTICAL),
1825 MPFROMLONG(pns->lScrollInc));
1826 cmp->forcescroll = FALSE;
1827 }
1828 }
1829 break;
1830 }
1831 break; // COMP_RIGHTDIR
1832 }
1833 return 0; // WM_CONTROL
1834
1835 case UM_SETDIR:
1836 cmp = INSTDATA(hwnd);
1837 if (cmp) {
1838
1839 COMPARE *forthread;
1840 CNRINFO cnri;
1841
1842 cmp->includesubdirs = WinQueryButtonCheckstate(hwnd,
1843 COMP_INCLUDESUBDIRS);
1844 memset(&cnri, 0, sizeof(CNRINFO));
1845 cnri.cb = sizeof(CNRINFO);
1846 cnri.pszCnrTitle = cmp->leftdir;
1847 cnri.flWindowAttr = CV_DETAIL | CV_MINI |
1848 CA_CONTAINERTITLE | CA_TITLESEPARATOR |
1849 CA_DETAILSVIEWTITLES | CA_OWNERDRAW;
1850 WinSendDlgItemMsg(hwnd, COMP_LEFTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
1851 MPFROMLONG(CMA_CNRTITLE | CMA_FLWINDOWATTR));
1852 cnri.pszCnrTitle = cmp->rightdir;
1853 WinSendDlgItemMsg(hwnd, COMP_RIGHTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
1854 MPFROMLONG(CMA_CNRTITLE | CMA_FLWINDOWATTR));
1855 WinCheckButton(hwnd, COMP_HIDENOTSELECTED, 0);
1856 cmp->filling = TRUE;
1857 forthread = xmalloc(sizeof(COMPARE), pszSrcFile, __LINE__);
1858 if (!forthread)
1859 WinDismissDlg(hwnd, 0);
1860 else {
1861 *forthread = *cmp;
1862 forthread->cmp = cmp;
1863 if (_beginthread(FillCnrsThread, NULL, 122880, (PVOID) forthread) ==
1864 -1) {
1865 Runtime_Error(pszSrcFile, __LINE__,
1866 GetPString(IDS_COULDNTSTARTTHREADTEXT));
1867 WinDismissDlg(hwnd, 0);
1868 free(forthread);
1869 }
1870 else {
1871 WinEnableWindowUpdate(hwndLeft, FALSE);
1872 WinEnableWindowUpdate(hwndRight, FALSE);
1873 cmp->selleft = cmp->selright = 0;
1874 WinSetDlgItemText(hwnd, COMP_SELLEFT, "0");
1875 WinSetDlgItemText(hwnd, COMP_SELRIGHT, "0");
1876 WinSetDlgItemText(hwnd, COMP_TOTALLEFT, "0");
1877 WinSetDlgItemText(hwnd, COMP_TOTALRIGHT, "0");
1878 WinSetDlgItemText(hwnd, COMP_NOTE,
1879 GetPString(IDS_COMPHOLDREADDISKTEXT));
1880 WinEnableWindow(hwndRight, FALSE);
1881 WinEnableWindow(hwndLeft, FALSE);
1882 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
1883 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
1884 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), FALSE);
1885 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), FALSE);
1886 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), FALSE);
1887 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), FALSE);
1888 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), FALSE);
1889 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), FALSE);
1890 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), FALSE);
1891 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), FALSE);
1892 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), FALSE);
1893 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), FALSE);
1894 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), FALSE);
1895 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), FALSE);
1896 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER), FALSE);
1897 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), FALSE);
1898 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS), FALSE);
1899 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), FALSE);
1900 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), FALSE);
1901 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), FALSE);
1902 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), FALSE);
1903 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), FALSE);
1904 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), FALSE);
1905 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), FALSE);
1906 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT),
1907 FALSE);
1908 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL), FALSE);
1909 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), FALSE);
1910 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), FALSE);
1911 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), FALSE);
1912 }
1913 }
1914 }
1915 return 0;
1916
1917 case UM_FILTER:
1918 cmp = INSTDATA(hwnd);
1919 if (cmp) {
1920 if (mp1) {
1921 DosEnterCritSec();
1922 SetMask((CHAR *) mp1, &cmp->dcd.mask);
1923 DosExitCritSec();
1924 }
1925 cmp->dcd.suspendview = 1;
1926 WinSendMsg(hwndLeft, CM_FILTER, MPFROMP(Filter),
1927 MPFROMP(&cmp->dcd.mask));
1928 WinSendMsg(hwndRight, CM_FILTER, MPFROMP(Filter),
1929 MPFROMP(&cmp->dcd.mask));
1930 cmp->dcd.suspendview = 0;
1931 if (*cmp->dcd.mask.szMask)
1932 WinSetDlgItemText(hwnd, COMP_NOTE,
1933 GetPString(IDS_COMPREADYFILTEREDTEXT));
1934 else
1935 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
1936 }
1937 return 0;
1938
1939 case UM_HIDENOTSELECTED:
1940 cmp = INSTDATA(hwnd);
1941 if (cmp) {
1942 USHORT wantHide = WinQueryButtonCheckstate(hwnd,
1943 COMP_HIDENOTSELECTED);
1944
1945 cmp->dcd.suspendview = 1;
1946 if (wantHide) {
1947 BOOL needRefresh = FALSE;
1948 HWND hwndl = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
1949 HWND hwndr = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
1950 PCNRITEM pcil = WinSendMsg(hwndl, CM_QUERYRECORD, MPVOID,
1951 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1952 PCNRITEM pcir = WinSendMsg(hwndr, CM_QUERYRECORD, MPVOID,
1953 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1954
1955 while (pcil && (INT) pcil != -1 && pcir && (INT) pcir != -1) {
1956 if (~pcil->rc.flRecordAttr & CRA_SELECTED &&
1957 ~pcir->rc.flRecordAttr & CRA_SELECTED) {
1958 pcil->rc.flRecordAttr |= CRA_FILTERED;
1959 pcir->rc.flRecordAttr |= CRA_FILTERED;
1960 needRefresh = TRUE;
1961 }
1962 pcil = WinSendMsg(hwndl, CM_QUERYRECORD, MPFROMP(pcil),
1963 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1964 pcir = WinSendMsg(hwndr, CM_QUERYRECORD, MPFROMP(pcir),
1965 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1966 } // while
1967 if (needRefresh) {
1968 WinSendMsg(hwndl, CM_INVALIDATERECORD,
1969 MPVOID, MPFROM2SHORT(0, CMA_REPOSITION));
1970 WinSendMsg(hwndr, CM_INVALIDATERECORD,
1971 MPVOID, MPFROM2SHORT(0, CMA_REPOSITION));
1972 }
1973 }
1974 else {
1975 WinSendMsg(hwndLeft, CM_FILTER, MPFROMP(Filter),
1976 MPFROMP(&cmp->dcd.mask));
1977 WinSendMsg(hwndRight, CM_FILTER, MPFROMP(Filter),
1978 MPFROMP(&cmp->dcd.mask));
1979 }
1980 cmp->dcd.suspendview = 0;
1981 if (*cmp->dcd.mask.szMask)
1982 WinSetDlgItemText(hwnd, COMP_NOTE,
1983 GetPString(IDS_COMPREADYFILTEREDTEXT));
1984 else
1985 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
1986 }
1987 return 0;
1988
1989 case WM_COMMAND:
1990 switch (SHORT1FROMMP(mp1)) {
1991 case IDM_COMPARE:
1992 cmp = INSTDATA(hwnd);
1993 if (cmp) {
1994
1995 PCNRITEM pci;
1996 CHAR ofile[CCHMAXPATH];
1997
1998 pci = (PCNRITEM) WinSendMsg(cmp->hwndCalling,
1999 CM_QUERYRECORDEMPHASIS,
2000 MPFROMLONG(CMA_FIRST),
2001 MPFROMSHORT(CRA_CURSORED));
2002 // 01 Aug 07 SHL
2003 if (pci && *pci->pszFileName) {
2004 if (cmp->hwndCalling == hwndLeft)
2005 strcpy(ofile, cmp->rightdir);
2006 else
2007 strcpy(ofile, cmp->leftdir);
2008 if (ofile[strlen(ofile) - 1] != '\\')
2009 strcat(ofile, "\\");
2010 strcat(ofile, pci->pszDisplayName);
2011 if (*compare) {
2012 CHAR *fakelist[3];
2013 fakelist[0] = pci->pszFileName;
2014 fakelist[1] = ofile;
2015 fakelist[2] = NULL;
2016 ExecOnList(hwnd, compare,
2017 WINDOWED | SEPARATEKEEP, NULL, fakelist, NULL);
2018 }
2019 else {
2020 FCOMPARE fc;
2021 memset(&fc, 0, sizeof(fc));
2022 fc.size = sizeof(fc);
2023 fc.hwndParent = hwnd;
2024 strcpy(fc.file1, pci->pszFileName);
2025 strcpy(fc.file2, ofile);
2026 WinDlgBox(HWND_DESKTOP, hwnd,
2027 CFileDlgProc, FM3ModHandle, FCMP_FRAME, (PVOID) & fc);
2028 }
2029 }
2030 }
2031 break;
2032
2033 case COMP_FILTER:
2034 case IDM_FILTER:
2035 cmp = INSTDATA(hwnd);
2036 if (cmp) {
2037
2038 BOOL empty = FALSE;
2039 PCNRITEM pci;
2040 CHAR *p;
2041 BOOL temp;
2042
2043 if (!*cmp->dcd.mask.szMask) {
2044 empty = TRUE;
2045 temp = fSelectedAlways;
2046 fSelectedAlways = TRUE;
2047 pci = (PCNRITEM)CurrentRecord(hwnd);
2048 fSelectedAlways = temp;
2049 // 01 Aug 07 SHL
2050 if (pci && ~pci->attrFile & FILE_DIRECTORY) {
2051 p = strrchr(pci->pszFileName, '\\');
2052 if (p) {
2053 p++;
2054 strcpy(cmp->dcd.mask.szMask, p);
2055 }
2056 }
2057 }
2058 cmp->dcd.mask.fNoAttribs = TRUE;
2059 cmp->dcd.mask.attrFile = ALLATTRS;
2060 cmp->dcd.mask.antiattr = 0;
2061 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
2062 FM3ModHandle, MSK_FRAME, MPFROMP(&cmp->dcd.mask))) {
2063 cmp->dcd.mask.attrFile = ALLATTRS;
2064 cmp->dcd.mask.antiattr = 0;
2065 WinSendMsg(hwnd, UM_FILTER, MPVOID, MPVOID);
2066 }
2067 else if (empty) {
2068 *cmp->dcd.mask.szMask = 0;
2069 cmp->dcd.mask.attrFile = ALLATTRS;
2070 cmp->dcd.mask.antiattr = 0;
2071 }
2072 }
2073 break;
2074
2075 case IDM_SHOWSUBJECT:
2076 case IDM_SHOWEAS:
2077 case IDM_SHOWSIZE:
2078 case IDM_SHOWLWDATE:
2079 case IDM_SHOWLWTIME:
2080 case IDM_SHOWLADATE:
2081 case IDM_SHOWLATIME:
2082 case IDM_SHOWCRDATE:
2083 case IDM_SHOWCRTIME:
2084 case IDM_SHOWATTR:
2085 cmp = INSTDATA(hwnd);
2086 if (cmp) {
2087
2088 DIRCNRDATA dcd1;
2089 BOOL tempsubj;
2090
2091 dcd1 = cmp->dcd;
2092 AdjustDetailsSwitches(hwndLeft,
2093 (HWND) 0, SHORT1FROMMP(mp1),
2094 cmp->leftdir, "DirCmp", &cmp->dcd, TRUE);
2095 tempsubj = cmp->dcd.detailssubject;
2096 cmp->dcd = dcd1;
2097 cmp->dcd.detailssubject = FALSE;
2098 AdjustDetailsSwitches(hwndRight,
2099 cmp->dcd.hwndLastMenu, SHORT1FROMMP(mp1),
2100 cmp->rightdir, "DirCmp", &cmp->dcd, TRUE);
2101 cmp->dcd.detailssubject = tempsubj;
2102 }
2103 break;
2104
2105 case IDM_LOADLISTFILE:
2106 cmp = INSTDATA(hwnd);
2107 if (cmp) {
2108
2109 CHAR fullname[CCHMAXPATH];
2110
2111 strcpy(fullname, "*.PMD");
2112 if (insert_filename(HWND_DESKTOP, fullname, TRUE, FALSE) &&
2113 *fullname && !strchr(fullname, '*') && !strchr(fullname, '?')) {
2114 strcpy(cmp->rightlist, fullname);
2115 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2116 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2117 }
2118 }
2119 break;
2120
2121 case IDM_SAVELISTFILE:
2122 cmp = INSTDATA(hwnd);
2123 if (cmp) {
2124
2125 SNAPSTUFF *sf;
2126 CHAR fullname[CCHMAXPATH];
2127
2128 strcpy(fullname, "*.PMD");
2129 if (export_filename(HWND_DESKTOP, fullname, 1) && *fullname &&
2130 !strchr(fullname, '*') && !strchr(fullname, '?')) {
2131 sf = xmallocz(sizeof(SNAPSTUFF), pszSrcFile, __LINE__);
2132 if (sf) {
2133 strcpy(sf->filename, fullname);
2134 if (hwndLeft == cmp->hwndCalling)
2135 strcpy(sf->dirname, cmp->leftdir);
2136 else
2137 strcpy(sf->dirname, cmp->rightdir);
2138 sf->recurse = cmp->includesubdirs;
2139 if (_beginthread(StartSnap, NULL, 65536, (PVOID) sf) == -1) {
2140 Runtime_Error(pszSrcFile, __LINE__,
2141 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2142 free(sf);
2143 }
2144 }
2145 }
2146 }
2147 break;
2148
2149 case COMP_SETDIRS:
2150 cmp = INSTDATA(hwnd);
2151 if (cmp) {
2152
2153 WALK2 wa;
2154
2155 memset(&wa, 0, sizeof(wa));
2156 wa.size = sizeof(wa);
2157 strcpy(wa.szCurrentPath1, cmp->leftdir);
2158 strcpy(wa.szCurrentPath2, cmp->rightdir);
2159 if (WinDlgBox(HWND_DESKTOP, hwnd, WalkTwoCmpDlgProc,
2160 FM3ModHandle, WALK2_FRAME,
2161 MPFROMP(&wa)) &&
2162 !IsFile(wa.szCurrentPath1) && !IsFile(wa.szCurrentPath2)) {
2163 strcpy(cmp->leftdir, wa.szCurrentPath1);
2164 strcpy(cmp->rightdir, wa.szCurrentPath2);
2165 *cmp->rightlist = 0;
2166 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2167 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2168 }
2169 }
2170 break;
2171
2172 case COMP_COPYLEFT:
2173 case COMP_MOVELEFT:
2174 case COMP_COPYRIGHT:
2175 case COMP_MOVERIGHT:
2176 case COMP_DELETELEFT:
2177 case COMP_DELETERIGHT:
2178 cmp = INSTDATA(hwnd);
2179 if (cmp) {
2180
2181 COMPARE *forthread;
2182
2183 cmp->filling = TRUE;
2184 forthread = xmalloc(sizeof(COMPARE), pszSrcFile, __LINE__);
2185 if (forthread) {
2186 *forthread = *cmp;
2187 forthread->cmp = cmp;
2188 forthread->action = SHORT1FROMMP(mp1);
2189 if (_beginthread(ActionCnrThread, NULL, 122880, (PVOID) forthread)
2190 == -1) {
2191 Runtime_Error(pszSrcFile, __LINE__,
2192 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2193 free(forthread);
2194 }
2195 else {
2196 WinEnableWindowUpdate(hwndLeft, FALSE);
2197 WinEnableWindowUpdate(hwndRight, FALSE);
2198 switch (SHORT1FROMMP(mp1)) {
2199 case COMP_DELETELEFT:
2200 case COMP_DELETERIGHT:
2201 WinSetDlgItemText(hwnd, COMP_NOTE,
2202 GetPString(IDS_COMPHOLDDELETINGTEXT));
2203 break;
2204 case COMP_MOVELEFT:
2205 case COMP_MOVERIGHT:
2206 WinSetDlgItemText(hwnd, COMP_NOTE,
2207 GetPString(IDS_COMPHOLDMOVINGTEXT));
2208 break;
2209 case COMP_COPYLEFT:
2210 case COMP_COPYRIGHT:
2211 WinSetDlgItemText(hwnd, COMP_NOTE,
2212 GetPString(IDS_COMPHOLDCOPYINGTEXT));
2213 break;
2214 default:
2215 WinSetDlgItemText(hwnd, COMP_NOTE,
2216 GetPString(IDS_COMPHOLDDUNNOTEXT));
2217 break;
2218 }
2219 WinEnableWindow(hwndRight, FALSE);
2220 WinEnableWindow(hwndLeft, FALSE);
2221 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
2222 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
2223 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), FALSE);
2224 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), FALSE);
2225 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), FALSE);
2226 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), FALSE);
2227 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), FALSE);
2228 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), FALSE);
2229 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), FALSE);
2230 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), FALSE);
2231 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), FALSE);
2232 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), FALSE);
2233 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), FALSE);
2234 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), FALSE);
2235 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER),
2236 FALSE);
2237 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), FALSE);
2238 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS),
2239 FALSE);
2240 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), FALSE);
2241 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), FALSE);
2242 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), FALSE);
2243 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), FALSE);
2244 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), FALSE);
2245 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), FALSE);
2246 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), FALSE);
2247 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT),
2248 FALSE);
2249 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL),
2250 FALSE);
2251 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), FALSE);
2252 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), FALSE);
2253 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), FALSE);
2254 }
2255 }
2256 }
2257 break;
2258
2259 case DID_OK:
2260 WinDismissDlg(hwnd, 0);
2261 break;
2262 case DID_CANCEL:
2263 WinDismissDlg(hwnd, 1);
2264 break;
2265
2266 case IDM_HELP:
2267 if (hwndHelp)
2268 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
2269 MPFROM2SHORT(HELP_COMPARE, 0), MPFROMSHORT(HM_RESOURCEID));
2270 break;
2271
2272 case IDM_DESELECTALL:
2273 case IDM_SELECTNEWER:
2274 case IDM_SELECTOLDER:
2275 case IDM_SELECTBIGGER:
2276 case IDM_SELECTSMALLER:
2277 case IDM_DESELECTNEWER:
2278 case IDM_DESELECTOLDER:
2279 case IDM_DESELECTBIGGER:
2280 case IDM_DESELECTSMALLER:
2281 case IDM_DESELECTONE:
2282 case IDM_DESELECTBOTH:
2283 case IDM_SELECTBOTH:
2284 case IDM_SELECTONE:
2285 case IDM_SELECTSAMECONTENT:
2286 case IDM_SELECTIDENTICAL: // Name, size and time
2287 case IDM_SELECTSAME: // Name and size
2288 case IDM_INVERT:
2289 cmp = INSTDATA(hwnd);
2290 if (!cmp)
2291 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2292 else {
2293 COMPARE *forthread;
2294
2295 cmp->filling = TRUE;
2296 forthread = xmalloc(sizeof(COMPARE), pszSrcFile, __LINE__);
2297 if (forthread) {
2298 *forthread = *cmp;
2299 forthread->cmp = cmp;
2300 forthread->action = SHORT1FROMMP(mp1);
2301 if (_beginthread(SelectCnrsThread, NULL, 65536, (PVOID) forthread)
2302 == -1) {
2303 Runtime_Error(pszSrcFile, __LINE__,
2304 GetPString(IDS_COULDNTSTARTTHREADTEXT));
2305 free(forthread);
2306 }
2307 else {
2308 WinEnableWindowUpdate(hwndLeft, FALSE);
2309 WinEnableWindowUpdate(hwndRight, FALSE);
2310 switch (SHORT1FROMMP(mp1)) {
2311 case IDM_DESELECTALL:
2312 case IDM_DESELECTNEWER:
2313 case IDM_DESELECTOLDER:
2314 case IDM_DESELECTBIGGER:
2315 case IDM_DESELECTSMALLER:
2316 case IDM_DESELECTONE:
2317 case IDM_DESELECTBOTH:
2318 WinSetDlgItemText(hwnd, COMP_NOTE,
2319 GetPString(IDS_COMPHOLDDESELTEXT));
2320 break;
2321 case IDM_INVERT:
2322 WinSetDlgItemText(hwnd, COMP_NOTE,
2323 GetPString(IDS_COMPHOLDINVERTTEXT));
2324 break;
2325 default:
2326 WinSetDlgItemText(hwnd, COMP_NOTE,
2327 GetPString(IDS_COMPHOLDSELTEXT));
2328 break;
2329 }
2330 WinEnableWindow(hwndRight, FALSE);
2331 WinEnableWindow(hwndLeft, FALSE);
2332 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
2333 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
2334 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), FALSE);
2335 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), FALSE);
2336 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), FALSE);
2337 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), FALSE);
2338 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), FALSE);
2339 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), FALSE);
2340 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), FALSE);
2341 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), FALSE);
2342 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), FALSE);
2343 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), FALSE);
2344 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), FALSE);
2345 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), FALSE);
2346 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER),
2347 FALSE);
2348 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), FALSE);
2349 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS),
2350 FALSE);
2351 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), FALSE);
2352 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), FALSE);
2353 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), FALSE);
2354 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), FALSE);
2355 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), FALSE);
2356 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), FALSE);
2357 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), FALSE);
2358 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT),
2359 FALSE);
2360 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL),
2361 FALSE);
2362 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), FALSE);
2363 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), FALSE);
2364 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), FALSE);
2365 }
2366 }
2367 }
2368 break;
2369
2370 case COMP_COLLECT:
2371 cmp = INSTDATA(hwnd);
2372 if (cmp) {
2373
2374 CHAR **listl, **listr = NULL;
2375
2376 if (!Collector) {
2377
2378 SWP swp;
2379 HWND hwndC;
2380
2381 if (!fAutoTile && !ParentIsDesktop(hwnd, cmp->hwndParent) &&
2382 (!fExternalCollector && !strcmp(realappname, FM3Str)))
2383 GetNextWindowPos(cmp->hwndParent, &swp, NULL, NULL);
2384 hwndC = StartCollector((fExternalCollector ||
2385 strcmp(realappname, FM3Str)) ?
2386 HWND_DESKTOP : cmp->hwndParent, 4);
2387 if (hwndC) {
2388 if (!fAutoTile && !ParentIsDesktop(hwnd, cmp->hwndParent) &&
2389 (!fExternalCollector && !strcmp(realappname, FM3Str)))
2390 WinSetWindowPos(hwndC, HWND_TOP, swp.x, swp.y,
2391 swp.cx, swp.cy, SWP_MOVE | SWP_SIZE |
2392 SWP_SHOW | SWP_ZORDER);
2393 else if (!ParentIsDesktop(hwnd, cmp->hwndParent) && fAutoTile &&
2394 !strcmp(realappname, FM3Str))
2395 TileChildren(cmp->hwndParent, TRUE);
2396 DosSleep(64);
2397 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(COMP_COLLECT, 0), MPVOID);
2398 break;
2399 }
2400 }
2401 else
2402 StartCollector(cmp->hwndParent, 4);
2403 {
2404 BOOL temp;
2405
2406 temp = fSelectedAlways;
2407 fSelectedAlways = TRUE;
2408 listl = BuildList(hwndLeft);
2409 if (!*cmp->rightlist)
2410 listr = BuildList(hwndRight);
2411 fSelectedAlways = temp;
2412 }
2413 if (listl || listr) {
2414 if (Collector) {
2415 if (listl) {
2416 if (!PostMsg(Collector, WM_COMMAND,
2417 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(listl)))
2418 FreeList(listl);
2419 }
2420 if (listr) {
2421 if (!PostMsg(Collector, WM_COMMAND,
2422 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(listr)))
2423 FreeList(listr);
2424 }
2425 WinSetWindowPos(WinQueryWindow(WinQueryWindow(Collector,
2426 QW_PARENT),
2427 QW_PARENT), HWND_TOP, 0, 0, 0, 0,
2428 SWP_ACTIVATE);
2429 }
2430 else {
2431 FreeList(listl);
2432 FreeList(listr);
2433 }
2434 }
2435 }
2436 break;
2437 }
2438 return 0;
2439
2440 case WM_CLOSE:
2441 WinDismissDlg(hwnd, 0);
2442 return 0;
2443
2444 case WM_DESTROY:
2445 cmp = INSTDATA(hwnd);
2446 if (cmp) {
2447 if (cmp->dcd.hwndLastMenu)
2448 WinDestroyWindow(cmp->dcd.hwndLastMenu);
2449 if (cmp->dcd.hwndObject) {
2450 WinSetWindowPtr(cmp->dcd.hwndObject, QWL_USER, (PVOID) NULL);
2451 if (!PostMsg(cmp->dcd.hwndObject, WM_CLOSE, MPVOID, MPVOID))
2452 WinSendMsg(cmp->dcd.hwndObject, WM_CLOSE, MPVOID, MPVOID);
2453 }
2454 free(cmp);
2455 }
2456 EmptyCnr(hwndLeft);
2457 EmptyCnr(hwndRight);
2458 DosPostEventSem(CompactSem);
2459 break;
2460 }
2461 return WinDefDlgProc(hwnd, msg, mp1, mp2);
2462}
Note: See TracBrowser for help on using the repository browser.