source: trunk/dll/comp.c@ 763

Last change on this file since 763 was 763, checked in by Gregg Young, 18 years ago

Replaced sprintf path building with BldFullPathName at functions for quoting path and file names

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