source: trunk/dll/comp.c@ 1394

Last change on this file since 1394 was 1394, checked in by Steven Levine, 17 years ago

Ticket 340: Convert GetPString to use STRINGTABLE.

Drop fm3dll.str and mkstr.exe from makefiles and wpi builders

Convert many functions to expect PCSZ arguments.
Correct walk, compare and dirsizes dialog setups to ignore saved dialog size
Drop copyright.c logic from makefile

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 101.5 KB
RevLine 
[1335]1
[76]2/***********************************************************************
3
4 $Id: comp.c 1394 2009-02-05 04:17:25Z stevenhl $
5
6 Compare directories
7
8 Copyright (c) 1993-02 M. Kimes
[1394]9 Copyright (c) 2003, 2009 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)
[773]30 06 Aug 07 SHL Move BldFullPathName here to be near primary caller
31 07 Aug 07 SHL COMP_COLLECT: Avoid collecting empty entries when nothing selected
[775]32 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
[783]33 13 Aug 07 SHL Sync code with other FilesToGet usage
34 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
[790]35 20 Aug 07 SHL Correct remaining pcil/pcir typos (we hope)
36 20 Aug 07 SHL Revert to DosSleep(0)
37 20 Aug 07 SHL Use GetMSecTimer for timing
[846]38 20 Aug 07 SHL A few more speed up tweaks. Some experimental timing code
[814]39 26 Aug 07 GKY DosSleep(1) in loops changed to (0)
[846]40 27 Sep 07 SHL Correct ULONGLONG size formatting
[897]41 30 Dec 07 GKY Use TestCDates for compare by file date/time
[907]42 04 Jan 08 SHL Avoid traps if CM_ALLOCRECORD returns less that requested
43 05 Jan 08 SHL Use WM_TIMER for progress messaging
44 05 Jan 08 SHL Use ITIMER_DESC for hogging control
[919]45 12 Jan 08 SHL Correct select count display regression
[924]46 12 Jan 08 SHL Localize SpecialSelect here and rename
47 12 Jan 08 SHL Use SleepIfNeeded
48 12 Jan 08 SHL Reduce/eliminate more DosSleep calls
[929]49 16 Jan 08 SHL Update total/select counts with WM_TIMER only
50 17 Jan 08 SHL Change hide not selected button to 3 state
51 18 Jan 08 SHL Honor filters in actions
[938]52 20 Jan 08 GKY Compare dialog now saves and restores size and position
[985]53 29 Feb 08 GKY Use xfree where appropriate
54 29 Feb 08 GKY Refactor global command line variables to notebook.h
[1000]55 16 Mar 08 GKY Prevent trap caused by files that exceed maxpath length
[1065]56 11 Jul 08 JBS Ticket 230: Simplified code and eliminated some local variables by incorporating
[1175]57 all the details view settings (both the global variables and those in the
58 DIRCNRDATA struct) into a new struct: DETAILS_SETTINGS.
59 08 Sep 08 SHL Avoid aliased pszLongName pointer in ActionCnrThread IDM_MOVE
[1335]60 10 Dec 08 SHL Integrate exception handler support
[1358]61 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis.
[1391]62 11 Jan 09 GKY Replace font names in the string file with global set at compile in init.c
[76]63
64***********************************************************************/
65
[907]66#include <stdlib.h>
67#include <string.h>
68#include <share.h>
69#include <io.h>
[1354]70#include <ctype.h>
[1335]71// #include <process.h> // _endthread
[907]72
[2]73#define INCL_DOS
74#define INCL_WIN
[783]75#define INCL_DOSERRORS
[2]76#define INCL_GPI
[157]77#define INCL_LONGLONG
[2]78
[1179]79#include "fm3dll.h"
[1221]80#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
[1205]81#include "mainwnd2.h" // Data declaration(s)
82#include "inis.h" // Data declaration(s)
83#include "init.h" // Data declaration(s)
84#include "newview.h" // Data declarations
[2]85#include "fm3dlg.h"
86#include "fm3str.h"
[907]87#include "pathutil.h" // BldFullPathName
88#include "filldir.h" // EmptyCnr...
89#include "makelist.h" // AddToFileList...
90#include "errutil.h" // Dos_Error...
91#include "strutil.h" // GetPString
92#include "tmrsvcs.h" // IsITimerExpired
93#include "comp.h"
[1179]94#include "misc.h" // AddToListboxBottom, AdjustCnrColRO, AdjustCnrColVis,
95 // AdjustCnrColsForPref, CurrentRecord,
[1175]96 // AdjustDetailsSwitches, LoadDetailsSwitches, SetCnrCols
97 // SetDetailsSwitches
[1179]98#include "select.h" // Deselect, Deselect, InvertAll
[1157]99#include "mkdir.h" // MassMkdir
100#include "valid.h" // TestCDates
101#include "walkem.h" // WalkTwoCmpDlgProc
[1179]102#include "common.h" // DecrThreadUsage, IncrThreadUsage
103#include "defview.h" // DefaultViewKeys
104#include "draglist.h" // DoFileDrag
105#include "systemf.h" // ExecOnList
106#include "filter.h" // Filter
107#include "mainwnd.h" // GetNextWindowPos
108#include "shadow.h" // OpenObject
109#include "chklist.h" // PopupMenu
110#include "presparm.h" // SetPresParams
111#include "collect.h" // StartCollector
112#include "subj.h" // Subject
113#include "copyf.h" // docopyf
114#include "getnames.h" // export_filename
115#include "wrappers.h" // xDosFindNext
[1175]116#include "notebook.h" // External compare/dircompare
[1179]117#include "commafmt.h" // CommaFmtULL
[1335]118#include "fortify.h" // 06 May 08 SHL added
119#include "excputil.h" // xbeginthread
[1354]120#include "info.h" // driveflags
[1009]121
[551]122typedef struct
123{
124 CHAR filename[CCHMAXPATH];
125 CHAR dirname[CCHMAXPATH];
126 BOOL recurse;
127}
128SNAPSTUFF;
[2]129
[1205]130// Data definitions
[362]131static PSZ pszSrcFile = __FILE__;
132
[1205]133#pragma data_seg(GLOBAL1)
134BOOL fSelectedAlways;
135
[316]136//=== SnapShot() Write directory tree to file and recurse if requested ===
[2]137
[783]138static VOID SnapShot(char *path, FILE *fp, BOOL recurse)
[157]139{
[841]140 PFILEFINDBUF4L pffb;
[551]141 char *mask, *enddir;
142 HDIR hdir = HDIR_CREATE;
[783]143 ULONG ulFindCnt;
[2]144
[783]145 // 13 Aug 07 SHL fimxe to use FileToGet
[841]146 pffb = xmalloc(sizeof(FILEFINDBUF4L), pszSrcFile, __LINE__);
[783]147 if (pffb) {
[551]148 mask = xmalloc(CCHMAXPATH, pszSrcFile, __LINE__);
149 if (mask) {
[783]150 BldFullPathName(mask, path, "*");
[551]151 enddir = strrchr(mask, '\\');
[2]152 enddir++;
[783]153 ulFindCnt = 1;
154 // 13 Aug 07 SHL fixme to report errors
[838]155 if (!xDosFindFirst(mask,
[907]156 &hdir,
[838]157 FILE_NORMAL | FILE_DIRECTORY |
158 FILE_ARCHIVED | FILE_READONLY | FILE_HIDDEN |
159 FILE_SYSTEM,
[841]160 pffb, sizeof(FILEFINDBUF4L), &ulFindCnt, FIL_QUERYEASIZEL)) {
[551]161 do {
[783]162 strcpy(enddir, pffb->achName);
163 if (!(pffb->attrFile & FILE_DIRECTORY))
[846]164 // 27 Sep 07 SHL fixme to use CommaFmtULL
[551]165 fprintf(fp,
[846]166 "\"%s\",%u,%llu,%04u/%02u/%02u,%02u:%02u:%02u,%lu,%lu,N\n",
[551]167 mask,
168 enddir - mask,
[783]169 pffb->cbFile,
170 (pffb->fdateLastWrite.year + 1980),
171 pffb->fdateLastWrite.month,
172 pffb->fdateLastWrite.day,
173 pffb->ftimeLastWrite.hours,
174 pffb->ftimeLastWrite.minutes,
175 pffb->ftimeLastWrite.twosecs,
[846]176 pffb->attrFile,
177 pffb->cbList > 4 ? pffb->cbList / 2 : 0);
[517]178 // Skip . and ..
[551]179 else if (recurse &&
[783]180 (pffb->achName[0] != '.' ||
181 (pffb->achName[1] &&
182 (pffb->achName[1] != '.' || pffb->achName[2])))) {
[551]183 SnapShot(mask, fp, recurse);
184 }
[783]185 ulFindCnt = 1;
[850]186 } while (!xDosFindNext(hdir, pffb, sizeof(FILEFINDBUF4L), &ulFindCnt, FIL_QUERYEASIZEL));
[551]187 DosFindClose(hdir);
[2]188 }
[1039]189 free(mask);
[2]190 }
[1039]191 free(pffb);
[2]192 }
193}
194
[316]195//=== StartSnap() Write directory tree to snapshot file ===
[2]196
[919]197static VOID StartSnap(VOID *pargs)
[316]198{
[919]199 SNAPSTUFF *sf = (SNAPSTUFF *)pargs;
[551]200 FILE *fp;
201 CHAR *p;
[2]202
[551]203 if (sf) {
204 if (*sf->dirname && *sf->filename) {
[2]205 priority_normal();
206 p = sf->dirname;
[551]207 while (*p) {
208 if (*p == '/')
209 *p = '\\';
210 p++;
[2]211 }
[551]212 if (*(p - 1) != '\\') {
213 *p = '\\';
214 p++;
[2]215 }
[551]216 fp = xfopen(sf->filename, "w", pszSrcFile, __LINE__);
[362]217 if (fp) {
[551]218 fprintf(fp, "\"%s\"\n", sf->dirname);
219 SnapShot(sf->dirname, fp, sf->recurse);
220 fclose(fp);
[2]221 }
222 }
[1039]223 free(sf);
[2]224 }
225}
226
[316]227//=== CompareFilesThread() Compare files and update container select flags ===
[2]228
[919]229static VOID CompareFilesThread(VOID *args)
[316]230{
[2]231 FCOMPARE fc;
[551]232 HAB hab2;
233 HMQ hmq2;
234 FILE *fp1, *fp2;
[847]235 ULONG len1, len2;
[841]236 ULONG offset = 0;
[551]237 LONG numread1, numread2;
238 CHAR s[1024], ss[1024], *p1, *p2;
[2]239
[551]240 if (args) {
[919]241 fc = *(FCOMPARE *)args;
[2]242 hab2 = WinInitialize(0);
[551]243 if (hab2) {
[1063]244# ifdef FORTIFY
245 Fortify_EnterScope();
246# endif
[1038]247 hmq2 = WinCreateMsgQueue(hab2, 0);
248 if (hmq2) {
[551]249 WinCancelShutdown(hmq2, TRUE);
[535]250 IncrThreadUsage();
[551]251 if (!IsFile(fc.file1) || IsRoot(fc.file1)) {
252 p1 = strrchr(fc.file2, '\\');
253 if (p1) {
254 if (fc.file1[strlen(fc.file1) - 1] == '\\')
255 p1++;
256 strcat(fc.file1, p1);
257 }
[362]258 }
[551]259 else if (!IsFile(fc.file2) || IsRoot(fc.file2)) {
260 p1 = strrchr(fc.file1, '\\');
261 if (p1) {
262 if (fc.file2[strlen(fc.file2) - 1] == '\\')
263 p1++;
264 strcat(fc.file2, p1);
265 }
266 }
267 sprintf(s, GetPString(IDS_COMPCOMPARETEXT), fc.file1);
268 AddToListboxBottom(fc.hwndList, s);
269 sprintf(s, GetPString(IDS_COMPTOTEXT), fc.file2);
270 AddToListboxBottom(fc.hwndList, s);
271 fp1 = _fsopen(fc.file1, "rb", SH_DENYNO);
272 if (!fp1) {
273 sprintf(s, GetPString(IDS_COMPCANTOPENTEXT), fc.file1);
274 AddToListboxBottom(fc.hwndList, s);
275 WinSetWindowText(fc.hwndHelp, GetPString(IDS_ERRORTEXT));
276 }
[362]277 else {
[551]278 fp2 = _fsopen(fc.file2, "rb", SH_DENYNO);
279 if (!fp2) {
280 sprintf(s, GetPString(IDS_COMPCANTOPENTEXT), fc.file2);
281 AddToListboxBottom(fc.hwndList, s);
282 WinSetWindowText(fc.hwndHelp, GetPString(IDS_ERRORTEXT));
[362]283 }
284 else {
[847]285 len1 = filelength(fileno(fp1));
286 len2 = filelength(fileno(fp2));
[551]287 if (len1 != len2) {
288 strcpy(s, GetPString(IDS_COMPDIFSIZESTEXT));
289 AddToListboxBottom(fc.hwndList, s);
290 sprintf(s, GetPString(IDS_COMPVSBYTESTEXT), len1, len2);
291 AddToListboxBottom(fc.hwndList, s);
292 WinSetWindowText(fc.hwndHelp,
293 GetPString(IDS_COMPDONTMATCHTEXT));
294 }
295 else {
296 WinSetWindowText(fc.hwndHelp,
297 GetPString(IDS_COMPCOMPARINGTEXT));
298 while (WinIsWindow(hab2, fc.hwndList)) {
299 numread1 = fread(s, 1, 1024, fp1);
300 numread2 = fread(ss, 1, 1024, fp2);
301 if (numread1 != numread2 || feof(fp1) != feof(fp2)) {
302 sprintf(s, GetPString(IDS_COMPREADERRORTEXT),
303 offset, offset);
304 AddToListboxBottom(fc.hwndList, s);
305 WinSetWindowText(fc.hwndHelp, GetPString(IDS_ERRORTEXT));
306 break;
307 }
308 else if (!numread1 && feof(fp1) && feof(fp2)) {
309 AddToListboxBottom(fc.hwndList,
310 GetPString(IDS_COMPFILESMATCHTEXT));
311 if (!stricmp(fc.file1, fc.file2))
312 AddToListboxBottom(fc.hwndList,
313 GetPString(IDS_COMPWONDERWHYTEXT));
314 WinSetWindowText(fc.hwndHelp,
315 GetPString(IDS_COMPCOMPLETETEXT));
316 break;
317 }
318 else if (numread1 <= 0 || numread2 <= 0) {
319 if (offset == len1)
320 break;
321 else {
322 sprintf(s, GetPString(IDS_COMPMATCHREADERRORTEXT),
323 offset, offset);
324 WinSetWindowText(fc.hwndHelp,
325 GetPString(IDS_COMPODDERRORTEXT));
326 AddToListboxBottom(fc.hwndList, s);
327 break;
328 }
329 }
330 else if (memcmp(s, ss, numread1)) {
331 p1 = s;
332 p2 = ss;
333 while (p1 < s + numread1) {
334 if (*p1 != *p2) {
335 sprintf(s, GetPString(IDS_COMPMISMATCHERRORTEXT),
336 offset + (p1 - s), offset + (p1 - s));
337 AddToListboxBottom(fc.hwndList, s);
338 WinSetWindowText(fc.hwndHelp,
339 GetPString(IDS_COMPDONTMATCHTEXT));
340 break;
341 }
342 p1++;
343 p2++;
344 }
345 break;
346 }
347 offset += numread1;
348 }
349 }
350 fclose(fp2);
351 }
352 fclose(fp1);
353 }
[535]354 DecrThreadUsage();
[551]355 WinDestroyMsgQueue(hmq2);
[2]356 }
357 WinTerminate(hab2);
[1063]358# ifdef FORTIFY
[1038]359 Fortify_LeaveScope();
[1063]360# endif
[2]361 }
362 }
363}
364
[316]365//=== CFileDlgProc() Select directories to compare dialog procedure ===
[2]366
[551]367MRESULT EXPENTRY CFileDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[316]368{
[2]369 FCOMPARE *fc;
370
[551]371 switch (msg) {
372 case WM_INITDLG:
373 if (!mp2)
374 WinDismissDlg(hwnd, 0);
375 else {
[574]376 WinSetWindowPtr(hwnd, QWL_USER, mp2);
[919]377 fc = (FCOMPARE *)mp2;
[551]378 fc->hwndReport = hwnd;
379 fc->hwndList = WinWindowFromID(hwnd, FCMP_LISTBOX);
380 fc->hwndHelp = WinWindowFromID(hwnd, FCMP_HELP);
381 if (!*fc->file1 || !fc->file2) {
382 WinDismissDlg(hwnd, 0);
383 break;
[2]384 }
[551]385 MakeFullName(fc->file1);
386 MakeFullName(fc->file2);
387 if (!stricmp(fc->file1, fc->file2)) {
388 saymsg(MB_CANCEL, hwnd,
389 GetPString(IDS_COMPSILLYALERTTEXT),
390 GetPString(IDS_COMPTOITSELFTEXT));
391 WinDismissDlg(hwnd, 0);
392 break;
393 }
[1335]394 if (xbeginthread(CompareFilesThread,
395 65536,
396 fc,
397 pszSrcFile,
398 __LINE__) == -1)
399 {
[551]400 WinDismissDlg(hwnd, 0);
401 }
402 }
403 break;
[2]404
[551]405 case WM_ADJUSTWINDOWPOS:
406 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
407 break;
[2]408
[551]409 case UM_SETDIR:
410 PaintRecessedWindow(WinWindowFromID(hwnd, FCMP_HELP),
[919]411 (HPS)0, FALSE, TRUE);
[551]412 return 0;
[2]413
[551]414 case WM_COMMAND:
415 switch (SHORT1FROMMP(mp1)) {
416 case DID_OK:
417 WinDismissDlg(hwnd, 0);
418 break;
419 case DID_CANCEL:
420 WinDismissDlg(hwnd, 1);
421 break;
422 }
423 return 0;
[2]424
[551]425 case WM_DESTROY:
[924]426 DosSleep(50); // Let others die first
[551]427 break;
[2]428 }
[551]429 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]430}
431
[316]432//=== ActionCnrThread() Do requested action on container contents ===
[2]433
[731]434static VOID ActionCnrThread(VOID *args)
[316]435{
[731]436 COMPARE *cmp = (COMPARE *)args;
[551]437 HAB hab;
438 HMQ hmq;
439 HWND hwndCnrS, hwndCnrD;
[924]440 PCNRITEM pciS, pciD, pciNextS, pciNextD;
[769]441 CHAR szNewName[CCHMAXPATH], szDirName[CCHMAXPATH], *p;
[551]442 APIRET rc;
[924]443 ITIMER_DESC itdSleep = { 0 };
[2]444
[748]445 if (!cmp) {
[773]446 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
[2]447 return;
[748]448 }
[2]449
450 DosError(FERR_DISABLEHARDERR);
451
452 hab = WinInitialize(0);
[551]453 if (hab) {
[1063]454# ifdef FORTIFY
455 Fortify_EnterScope();
456# endif
[1038]457 hmq = WinCreateMsgQueue(hab, 0);
458 if (hmq) {
[551]459 WinCancelShutdown(hmq, TRUE);
[535]460 IncrThreadUsage();
[2]461 priority_normal();
[551]462 switch (cmp->action) {
463 case COMP_DELETELEFT:
464 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
465 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
466 cmp->action = IDM_DELETE;
467 break;
468 case COMP_DELETERIGHT:
469 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
470 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
471 cmp->action = IDM_DELETE;
472 break;
473 case COMP_MOVELEFT:
474 cmp->action = IDM_MOVE;
475 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
476 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
477 break;
478 case COMP_MOVERIGHT:
479 cmp->action = IDM_MOVE;
480 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
481 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
482 break;
483 case COMP_COPYLEFT:
484 cmp->action = IDM_COPY;
485 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
486 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
487 break;
488 case COMP_COPYRIGHT:
489 cmp->action = IDM_COPY;
490 hwndCnrS = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
491 hwndCnrD = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
492 break;
493 default:
494 Runtime_Error(pszSrcFile, __LINE__, "bad case %u", cmp->action);
495 goto Abort;
[2]496 }
497
[924]498 pciS = WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPVOID,
[551]499 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]500 pciD = WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPVOID,
[551]501 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[316]502
[1175]503 InitITimer(&itdSleep, 500); // Sleep every 500 mSec
[907]504
[924]505 while (pciS && (INT)pciS != -1 && pciD && (INT)pciD != -1) {
[748]506
[924]507 pciNextS = WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPFROMP(pciS),
[551]508 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[748]509 pciNextD = WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPFROMP(pciD),
[551]510 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[748]511
[929]512 // Process file if selected and not filtered
513 if (*pciS->pszFileName &&
514 pciS->rc.flRecordAttr & CRA_SELECTED &&
515 ~pciS->rc.flRecordAttr & CRA_FILTERED)
516 {
[748]517 // Source name not blank
[551]518 switch (cmp->action) {
519 case IDM_DELETE:
[924]520 if (!unlinkf("%s", pciS->pszFileName)) {
521 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciS),
[551]522 MPFROM2SHORT(FALSE, CRA_SELECTED));
[748]523
524 if (!*pciD->pszFileName) {
[751]525 // Other side is blank - remove from both sides
[924]526 RemoveCnrItems(hwndCnrS, pciS, 1, CMA_FREE | CMA_INVALIDATE);
[748]527 if (pciD->rc.flRecordAttr & CRA_SELECTED)
528 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciD),
[551]529 MPFROM2SHORT(FALSE, CRA_SELECTED));
[751]530 RemoveCnrItems(hwndCnrD, pciD, 1, CMA_FREE | CMA_INVALIDATE);
[551]531 }
[742]532 else {
[1132]533 // Other side is not blank - blank just this side
[924]534 FreeCnrItemData(pciS);
[1132]535 // 29 Aug 08 SHL Point pci fields at NullStr to sync with FreeCnrItemData mods
536 pciS->pszFileName = NullStr;
[924]537 pciS->pszDisplayName = pciS->pszFileName;
538 pciS->rc.pszIcon = pciS->pszFileName;
539 pciS->flags = 0; // Just on one side
540 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD, MPFROMP(&pciS),
[551]541 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
[924]542 pciD->flags = 0; // Just on one side
[929]543 if (pciD->pszSubject != NullStr) {
[1009]544 xfree(pciD->pszSubject, pszSrcFile, __LINE__);
[924]545 pciD->pszSubject = NullStr;
[929]546 }
[551]547 }
548 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_LEFTDIR))
549 cmp->cmp->totalleft--;
550 else
551 cmp->cmp->totalright--;
552 }
553 break;
[2]554
[1394]555 case IDM_MOVE:
556 {
557 BOOL fResetVerify = FALSE;
[751]558
[1394]559 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR))
560 BldFullPathName(szNewName, cmp->leftdir, pciS->pszDisplayName);
561 else
562 BldFullPathName(szNewName, cmp->rightdir, pciS->pszDisplayName);
563 // Make directory if required
564 strcpy(szDirName, szNewName);
565 p = strrchr(szDirName, '\\');
566 if (fVerify && (driveflags[toupper(*szNewName) - 'A'] & DRIVE_WRITEVERIFYOFF ||
567 driveflags[toupper(*pciS->pszFileName) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
568 DosSetVerify(FALSE);
569 fResetVerify = TRUE;
570 }
571 if (p) {
572 if (p > szDirName + 2)
573 p++;
574 *p = 0;
575 if (IsFile(szDirName) == -1)
576 MassMkdir(hwndMain, szDirName);
577 }
578 rc = docopyf(MOVE, pciS->pszFileName, "%s", szNewName);
579 if (fResetVerify) {
580 DosSetVerify(fVerify);
581 fResetVerify = FALSE;
582 }
583 if (!rc && stricmp(pciS->pszFileName, szNewName)) {
584 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciS),
585 MPFROM2SHORT(FALSE, CRA_SELECTED));
586 if (pciD->rc.flRecordAttr & CRA_SELECTED)
587 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciD),
588 MPFROM2SHORT(FALSE, CRA_SELECTED));
589 FreeCnrItemData(pciD);
590 pciD->pszFileName = xstrdup(szNewName, pszSrcFile, __LINE__);
591 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR)) {
592 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->leftdir);
593 if (cmp->leftdir[strlen(cmp->leftdir) - 1] != '\\')
594 pciD->pszDisplayName++;
595 }
596 else {
597 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->rightdir);
598 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
599 pciD->pszDisplayName++;
600 }
601 pciD->pszLongName = pciS->pszLongName;
602 pciS->pszLongName = NullStr; // 07 Sep 08 SHL avoid aliased pointer
603 if (pciD->pszSubject != NullStr) {
604 xfree(pciD->pszSubject, pszSrcFile, __LINE__);
605 pciD->pszSubject = NullStr;
606 }
607 pciD->attrFile = pciS->attrFile;
608 pciD->pszDispAttr = pciS->pszDispAttr;
609 pciD->flags = 0; // Just on one side
610 pciD->date = pciS->date;
611 pciD->time = pciS->time;
612 pciD->ladate = pciS->ladate;
613 pciD->latime = pciS->latime;
614 pciD->crdate = pciS->crdate;
615 pciD->crtime = pciS->crtime;
616 pciD->cbFile = pciS->cbFile;
617 pciD->easize = pciS->easize;
[751]618
[1394]619 if (pciS->pszFileName != NullStr) {
620 xfree(pciS->pszFileName, pszSrcFile, __LINE__);
621 pciS->pszFileName = NullStr;
622 pciS->pszDisplayName = pciS->pszFileName;
623 pciS->rc.pszIcon = pciS->pszFileName;
624 }
625 if (pciS->pszSubject != NullStr) {
626 xfree(pciS->pszSubject, pszSrcFile, __LINE__);
627 pciS->pszSubject = NullStr;
628 }
629 pciS->flags = 0; // Just on one side
[924]630
[1394]631 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD, MPFROMP(&pciS),
632 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
[924]633
[1394]634 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD, MPFROMP(&pciD),
635 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
[2]636
[1394]637 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_LEFTDIR))
638 cmp->cmp->totalleft--;
639 else
640 cmp->cmp->totalright--;
641 }
642 else if (rc) {
643 rc = Dos_Error(MB_ENTERCANCEL,
644 rc,
645 HWND_DESKTOP,
646 pszSrcFile,
647 __LINE__,
648 GetPString(IDS_COMPMOVEFAILEDTEXT),
649 pciS->pszFileName, szNewName);
650 if (rc == MBID_CANCEL) // Cause loop to break
651 pciNextS = NULL;
652 }
653 break;
654 }
[751]655
[1394]656 case IDM_COPY:
657 {
658 BOOL fResetVerify = FALSE;
[751]659
[1394]660 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR))
661 BldFullPathName(szNewName, cmp->leftdir, pciS->pszDisplayName);
662 else
663 BldFullPathName(szNewName, cmp->rightdir, pciS->pszDisplayName);
664 // Make directory if required
665 strcpy(szDirName, szNewName);
666 p = strrchr(szDirName, '\\');
667 if (fVerify && (driveflags[toupper(*szNewName) - 'A'] & DRIVE_WRITEVERIFYOFF ||
668 driveflags[toupper(*pciS->pszFileName) - 'A'] & DRIVE_WRITEVERIFYOFF)) {
669 DosSetVerify(FALSE);
670 fResetVerify = TRUE;
671 }
672 if (p) {
673 if (p > szDirName + 2)
674 p++;
675 *p = 0;
676 if (IsFile(szDirName) == -1)
677 MassMkdir(hwndMain, szDirName);
678 }
679 rc = docopyf(COPY, pciS->pszFileName, "%s", szNewName);
680 if (fResetVerify) {
681 DosSetVerify(fVerify);
682 fResetVerify = FALSE;
683 }
684 if (rc) {
685 rc = Dos_Error(MB_ENTERCANCEL,
686 rc,
687 HWND_DESKTOP,
688 pszSrcFile,
689 __LINE__,
690 GetPString(IDS_COMPCOPYFAILEDTEXT),
691 pciS->pszFileName, szNewName);
692 if (rc == MBID_CANCEL)
693 pciNextS = NULL; // Cause loop to break
694 }
695 else {
696 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciS),
697 MPFROM2SHORT(FALSE, CRA_SELECTED));
698 if (pciD->rc.flRecordAttr & CRA_SELECTED)
699 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciD),
700 MPFROM2SHORT(FALSE, CRA_SELECTED));
701 // 12 Jan 08 SHL
702 if (pciD->pszFileName == NullStr) {
703 if (hwndCnrD == WinWindowFromID(cmp->hwnd, COMP_LEFTDIR))
704 cmp->totalleft++;
705 else
706 cmp->totalright++;
707 }
708 FreeCnrItemData(pciD);
709 pciD->pszFileName = xstrdup(szNewName, pszSrcFile, __LINE__);
710 if (hwndCnrS == WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR)) {
711 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->leftdir);
712 if (cmp->leftdir[strlen(cmp->leftdir) - 1] != '\\')
713 pciD->pszDisplayName++;
714 }
715 else {
716 pciD->pszDisplayName = pciD->pszFileName + strlen(cmp->rightdir);
717 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
718 pciD->pszDisplayName++;
719 }
720 pciD->attrFile = pciS->attrFile;
721 pciD->pszDispAttr = pciS->pszDispAttr;
722 pciD->flags = CNRITEM_EXISTS; // Now on both sides
723 pciD->date = pciS->date;
724 pciD->time = pciS->time;
725 pciD->ladate = pciS->ladate;
726 pciD->latime = pciS->latime;
727 pciD->crdate = pciS->crdate;
728 pciD->crtime = pciS->crtime;
729 pciD->cbFile = pciS->cbFile;
730 pciD->easize = pciS->easize;
[2]731
[1394]732 // Forget status until we regenerate it
733 if (pciS->pszSubject != NullStr) {
734 xfree(pciS->pszSubject, pszSrcFile, __LINE__);
735 pciS->pszSubject = NullStr;
736 }
737 pciS->flags = CNRITEM_EXISTS; // Now on both sides
[1354]738
[1394]739 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD, MPFROMP(&pciS),
740 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
741 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD, MPFROMP(&pciD),
742 MPFROM2SHORT(1, CMA_ERASE | CMA_TEXTCHANGED));
743 }
744 break;
745 }
[1354]746
[551]747 default:
748 break;
[748]749 } // switch
750
751 } // if have name
752
[924]753 pciS = pciNextS;
[748]754 pciD = pciNextD;
755
[924]756 SleepIfNeeded(&itdSleep, 0);
[748]757 } // while
[929]758 WinPostMsg(cmp->hwnd, WM_TIMER, MPFROMLONG(ID_TIMER), 0); // Force update
[551]759 Abort:
[2]760 WinDestroyMsgQueue(hmq);
761 }
[929]762 PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPFROMLONG(1), MPVOID);
763 // PostMsg(cmp->hwnd, WM_COMMAND, MPFROM2SHORT(IDM_DESELECTALL, 0), MPVOID); // 18 Jan 08 SHL we can count now
[535]764 DecrThreadUsage();
[1039]765 free(cmp);
[2]766 WinTerminate(hab);
[1063]767# ifdef FORTIFY
[1038]768 Fortify_LeaveScope();
[1063]769# endif
[2]770 }
[1032]771 else
772 xfree(cmp, pszSrcFile, __LINE__);
[2]773}
774
[929]775VOID CompSelect(HWND hwndCnrS, HWND hwndCnrD, HWND hwnd, INT action, BOOL reset);
[924]776
[316]777//=== SelectCnrsThread() Update container selection flags thread ===
[2]778
[919]779static VOID SelectCnrsThread(VOID *args)
[316]780{
[919]781 COMPARE *cmp = (COMPARE *)args;
[551]782 HAB hab;
783 HMQ hmq;
[2]784
[783]785 if (!cmp) {
786 Runtime_Error(pszSrcFile, __LINE__, "no data");
[2]787 return;
[783]788 }
[2]789
790 DosError(FERR_DISABLEHARDERR);
791
792 hab = WinInitialize(0);
[551]793 if (hab) {
[1063]794# ifdef FORTIFY
795 Fortify_EnterScope();
796# endif
[1038]797 hmq = WinCreateMsgQueue(hab, 0);
798 if (hmq) {
[551]799 WinCancelShutdown(hmq, TRUE);
[535]800 IncrThreadUsage();
[2]801 priority_normal();
[551]802 switch (cmp->action) {
803 case IDM_INVERT:
804 InvertAll(WinWindowFromID(cmp->hwnd, COMP_LEFTDIR));
805 InvertAll(WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR));
806 break;
[2]807
[551]808 case IDM_DESELECTALL:
809 Deselect(WinWindowFromID(cmp->hwnd, COMP_LEFTDIR));
810 Deselect(WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR));
811 break;
[2]812
[551]813 default:
[924]814 // 13 Jan 08 SHL fixme to decide if cmp->reset can ever get set
815 // if not lots of code can disappear
816 if (cmp->reset)
817 DbgMsg(pszSrcFile, __LINE__, "cmp->reset is TRUE");
818 CompSelect(WinWindowFromID(cmp->hwnd, COMP_LEFTDIR),
819 WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR),
[929]820 cmp->hwnd,
821 cmp->action,
822 cmp->reset);
[551]823 break;
[2]824 }
[551]825 if (!PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPFROMLONG(1L), MPVOID))
826 WinSendMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPFROMLONG(1L), MPVOID);
[2]827 WinDestroyMsgQueue(hmq);
828 }
[535]829 DecrThreadUsage();
[1039]830 free(cmp);
[2]831 WinTerminate(hab);
[1063]832# ifdef FORTIFY
[1038]833 Fortify_LeaveScope();
[1063]834# endif
[2]835 }
[1032]836 else
[1039]837 free(cmp);
[2]838}
839
[748]840/**
[924]841 * Do select actions for compare directories containers
842 * @param action is select mode
843 * @param reset requests flags by regenerated
844 */
845
[929]846VOID CompSelect(HWND hwndCnrS, HWND hwndCnrD, HWND hwnd, INT action, BOOL reset)
[924]847{
848 PCNRITEM pciS, pciD, *pciSa = NULL, *pciDa = NULL;
849 CNRINFO cnri;
850 BOOL slow = FALSE;
851 UINT x, numD, numS;
852 INT ret = 0;
853 ITIMER_DESC itdSleep = { 0 };
[929]854 BOOL fUpdateHideButton = FALSE;
[924]855
856 if (!hwndCnrS || !hwndCnrD) {
857 Runtime_Error(pszSrcFile, __LINE__, "hwndCnrS %p hwndCnrD %p", hwndCnrS, hwndCnrD);
858 return;
859 }
860
861 memset(&cnri, 0, sizeof(CNRINFO));
862 cnri.cb = sizeof(CNRINFO);
863 WinSendMsg(hwndCnrD, CM_QUERYCNRINFO, MPFROMP(&cnri),
864 MPFROMLONG(sizeof(CNRINFO)));
865 numD = cnri.cRecords;
866 memset(&cnri, 0, sizeof(CNRINFO));
867 cnri.cb = sizeof(CNRINFO);
868 WinSendMsg(hwndCnrS, CM_QUERYCNRINFO, MPFROMP(&cnri),
869 MPFROMLONG(sizeof(CNRINFO)));
870 numS = cnri.cRecords;
871 if (!numD || numS != numD) {
872 Runtime_Error(pszSrcFile, __LINE__, "numD %u != numS %u", numD, numS);
873 return;
874 }
875
876 pciDa = xmalloc(sizeof(PCNRITEM) * numD, pszSrcFile, __LINE__);
877 if (!pciDa)
878 return;
879
880 pciSa = xmalloc(sizeof(PCNRITEM) * numS, pszSrcFile, __LINE__);
881 if (!pciSa) {
[1039]882 free(pciDa);
[924]883 return;
884 }
885
886 InitITimer(&itdSleep, 500); // Sleep every 500 mSec
887
888Restart:
889
890 memset(pciDa, 0, sizeof(PCNRITEM) * numD);
891 memset(pciSa, 0, sizeof(PCNRITEM) * numS);
892
893 pciD = (PCNRITEM)WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPVOID,
894 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
895 x = 0;
896 while (pciD && (INT)pciD != -1 && x < numD) {
897 if (reset)
898 pciD->flags = 0;
899 pciDa[x] = pciD;
900 x++;
901 if (!slow)
902 pciD = (PCNRITEM) pciD->rc.preccNextRecord;
903 else
904 pciD = (PCNRITEM) WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPFROMP(pciD),
905 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
906 SleepIfNeeded(&itdSleep, 0);
907 } // while
908
909 if (numD != x) {
910 // Something out of sync - fixme to document why
911 if (!slow) {
912 slow = TRUE;
913 goto Restart;
914 }
[1039]915 free(pciDa);
916 free(pciSa);
[924]917 Runtime_Error(pszSrcFile, __LINE__, "numD %u != x %lu", numD, x);
918 return;
919 }
920
921 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPVOID,
922 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
923 x = 0;
924 while (pciS && (INT)pciS != -1 && x < numS) {
925 if (reset)
926 pciS->flags = 0;
927 pciSa[x] = pciS;
928 x++;
929 if (!slow)
930 pciS = (PCNRITEM) pciS->rc.preccNextRecord;
931 else
932 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPFROMP(pciS),
933 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
934 SleepIfNeeded(&itdSleep, 0);
935 } // while
936
937 if (numS != x) {
938 if (!slow) {
939 slow = TRUE;
940 goto Restart;
941 }
[1039]942 free(pciSa);
943 free(pciDa);
[924]944 Runtime_Error(pszSrcFile, __LINE__, "numS (%lu) != x (%lu)", numS, x);
945 return;
946 }
947
948 if (reset) {
949 // Update flags for files that exist on both sides
950 for (x = 0; x < numS; x++) {
951
952 if (!*pciSa[x]->pszFileName || !*pciDa[x]->pszFileName) {
953 // 12 Jan 08 SHL clear flags
[1175]954 pciSa[x]->flags = 0; // File exists on one side only
[924]955 pciDa[x]->flags = 0;
956 continue;
957 }
958
959 pciSa[x]->flags |= CNRITEM_EXISTS; // File exists on both sides
960 pciDa[x]->flags |= CNRITEM_EXISTS;
961 if (pciSa[x]->cbFile + pciSa[x]->easize >
962 pciDa[x]->cbFile + pciDa[x]->easize) {
963 pciSa[x]->flags |= CNRITEM_LARGER;
964 pciDa[x]->flags |= CNRITEM_SMALLER;
965 }
966 else if (pciSa[x]->cbFile + pciSa[x]->easize <
967 pciDa[x]->cbFile + pciDa[x]->easize) {
968 pciSa[x]->flags |= CNRITEM_SMALLER;
969 pciDa[x]->flags |= CNRITEM_LARGER;
970 }
971 ret = TestCDates(&pciDa[x]->date, &pciDa[x]->time,
972 &pciSa[x]->date, &pciSa[x]->time);
973 if (ret == 1)
974 /* 13 Jan 08 SHL fixme to be gone?
975 ((pciSa[x]->date.year > pciDa[x]->date.year) ? TRUE :
976 (pciSa[x]->date.year < pciDa[x]->date.year) ? FALSE :
977 (pciSa[x]->date.month > pciDa[x]->date.month) ? TRUE :
978 (pciSa[x]->date.month < pciDa[x]->date.month) ? FALSE :
979 (pciSa[x]->date.day > pciDa[x]->date.day) ? TRUE :
980 (pciSa[x]->date.day < pciDa[x]->date.day) ? FALSE :
981 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? TRUE :
982 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? FALSE :
983 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? TRUE :
984 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? FALSE :
985 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? TRUE :
986 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? FALSE : FALSE)
987 */
988 {
989 pciSa[x]->flags |= CNRITEM_NEWER;
990 pciDa[x]->flags |= CNRITEM_OLDER;
991 }
992 else if (ret == -1)
993 /* 13 Jan 08 SHL fixme to be gone?
994 ((pciSa[x]->date.year < pciDa[x]->date.year) ? TRUE :
995 (pciSa[x]->date.year > pciDa[x]->date.year) ? FALSE :
996 (pciSa[x]->date.month < pciDa[x]->date.month) ? TRUE :
997 (pciSa[x]->date.month > pciDa[x]->date.month) ? FALSE :
998 (pciSa[x]->date.day < pciDa[x]->date.day) ? TRUE :
999 (pciSa[x]->date.day > pciDa[x]->date.day) ? FALSE :
1000 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? TRUE :
1001 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? FALSE :
1002 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? TRUE :
1003 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? FALSE :
1004 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? TRUE :
1005 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? FALSE :
1006 FALSE)
1007 */
1008 {
1009 pciSa[x]->flags |= CNRITEM_OLDER;
1010 pciDa[x]->flags |= CNRITEM_NEWER;
1011 }
1012 SleepIfNeeded(&itdSleep, 0);
1013 } // for
1014 } // if reset
1015
1016 switch (action) {
1017 case IDM_SELECTIDENTICAL:
1018 for (x = 0; x < numS; x++) {
1019 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1020 pciSa[x]->flags & CNRITEM_EXISTS &&
1021 ~pciSa[x]->flags & CNRITEM_SMALLER &&
1022 ~pciSa[x]->flags & CNRITEM_LARGER &&
1023 ~pciSa[x]->flags & CNRITEM_NEWER &&
1024 ~pciSa[x]->flags & CNRITEM_OLDER) {
1025 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1026 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1027 MPFROM2SHORT(TRUE, CRA_SELECTED));
1028 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1029 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1030 MPFROM2SHORT(TRUE, CRA_SELECTED));
1031 }
1032 SleepIfNeeded(&itdSleep, 0);
1033 } // for
1034 break;
1035
1036 case IDM_SELECTSAME:
1037 for (x = 0; x < numS; x++) {
1038 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1039 pciSa[x]->flags & CNRITEM_EXISTS &&
1040 ~pciSa[x]->flags & CNRITEM_SMALLER &&
1041 ~pciSa[x]->flags & CNRITEM_LARGER) {
1042 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1043 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1044 MPFROM2SHORT(TRUE, CRA_SELECTED));
1045 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1046 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1047 MPFROM2SHORT(TRUE, CRA_SELECTED));
1048 }
1049 SleepIfNeeded(&itdSleep, 0);
1050 } // for
1051 break;
1052
1053 case IDM_SELECTSAMECONTENT:
1054 for (x = 0; x < numS; x++) {
1055 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1056 pciSa[x]->flags & CNRITEM_EXISTS)
1057 {
1058 FILE *fp1 = NULL;
1059 FILE *fp2 = NULL;
1060 BOOL gotMatch = FALSE;
1061 UINT errLineNo = 0;
1062 UINT compErrno = 0;
1063 CHAR buf1[1024];
1064 CHAR buf2[1024];
1065 HAB hab = WinQueryAnchorBlock(hwndCnrS);
1066
1067 if (!*pciSa[x]->pszFileName ||
1068 !*pciDa[x]->pszFileName) {
1069 Runtime_Error(pszSrcFile, __LINE__,
1070 "CNRITEM_EXISTS set with null file name for index %u", x);
1071 break;
1072 }
1073
1074 fp1 = _fsopen(pciSa[x]->pszFileName, "rb", SH_DENYNO);
1075 if (!fp1) {
1076 errLineNo = __LINE__;
1077 compErrno = errno;
1078 }
1079 else {
1080 fp2 = _fsopen(pciDa[x]->pszFileName, "rb", SH_DENYNO);
1081 if (!fp2) {
1082 errLineNo = __LINE__;
1083 compErrno = errno;
1084 }
1085 else {
1086 size_t len1 = filelength(fileno(fp1));
1087 size_t len2 = filelength(fileno(fp2));
1088
1089 if (len1 == len2) {
1090 setbuf(fp1, NULL);
1091 setbuf(fp2, NULL);
1092 while (WinIsWindow(hab, hwndCnrS)) {
1093 size_t numread1 = fread(buf1, 1, 1024, fp1);
1094 size_t numread2 = fread(buf2, 1, 1024, fp2);
1095
1096 if (!numread1 || !numread2 || numread1 != numread2) {
1097 if (ferror(fp1) || ferror(fp2)) {
1098 errLineNo = __LINE__;
1099 compErrno = errno;
1100 }
1101 else if (feof(fp1) && feof(fp2))
1102 gotMatch = TRUE;
1103 break;
1104 }
1105 else if (memcmp(buf1, buf2, numread1))
1106 break;
1107 } // while
1108 } // same len
1109 }
1110 }
1111
1112 if (fp1)
1113 fclose(fp1);
1114
1115 if (fp2)
1116 fclose(fp2);
1117
1118 if (errLineNo) {
1119 Runtime_Error(pszSrcFile, errLineNo,
1120 "error %d while comparing", compErrno);
1121 }
1122
1123 if (gotMatch) {
1124 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1125 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1126 MPFROM2SHORT(TRUE, CRA_SELECTED));
1127 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1128 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1129 MPFROM2SHORT(TRUE, CRA_SELECTED));
1130 }
1131 }
1132 SleepIfNeeded(&itdSleep, 0);
1133 } // for
1134 break;
1135
1136 case IDM_SELECTBOTH:
1137 for (x = 0; x < numS; x++) {
1138 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1139 pciSa[x]->flags & CNRITEM_EXISTS) {
1140 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1141 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1142 MPFROM2SHORT(TRUE, CRA_SELECTED));
1143 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1144 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1145 MPFROM2SHORT(TRUE, CRA_SELECTED));
1146 }
1147 SleepIfNeeded(&itdSleep, 0);
1148 } // for
1149 break;
1150
1151 case IDM_SELECTONE:
1152 for (x = 0; x < numS; x++) {
1153 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1154 ~pciSa[x]->flags & CNRITEM_EXISTS) {
1155 if (*pciSa[x]->pszFileName) {
1156 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
1157 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1158 MPFROM2SHORT(TRUE, CRA_SELECTED));
1159 }
1160 }
1161 else if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
1162 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1163 MPFROM2SHORT(TRUE, CRA_SELECTED));
1164 }
1165 }
1166 SleepIfNeeded(&itdSleep, 0);
1167 } // for
1168 break;
1169
1170 case IDM_SELECTBIGGER:
1171 for (x = 0; x < numS; x++) {
1172 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1173 if (pciSa[x]->flags & CNRITEM_LARGER) {
1174 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1175 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1176 MPFROM2SHORT(TRUE, CRA_SELECTED));
1177 }
1178 else if (pciDa[x]->flags & CNRITEM_LARGER) {
1179 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1180 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1181 MPFROM2SHORT(TRUE, CRA_SELECTED));
1182 }
1183 }
1184 SleepIfNeeded(&itdSleep, 0);
1185 } // for
1186 break;
1187
1188 case IDM_SELECTSMALLER:
1189 for (x = 0; x < numS; x++) {
1190 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1191 if (pciSa[x]->flags & CNRITEM_SMALLER) {
1192 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1193 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1194 MPFROM2SHORT(TRUE, CRA_SELECTED));
1195 }
1196 else if (pciDa[x]->flags & CNRITEM_SMALLER) {
1197 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1198 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1199 MPFROM2SHORT(TRUE, CRA_SELECTED));
1200 }
1201 }
1202 SleepIfNeeded(&itdSleep, 0);
1203 } // for
1204 break;
1205
1206 case IDM_SELECTNEWER:
1207 for (x = 0; x < numS; x++) {
1208 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1209 if (pciSa[x]->flags & CNRITEM_NEWER) {
1210 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1211 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1212 MPFROM2SHORT(TRUE, CRA_SELECTED));
1213 }
1214 else if (pciDa[x]->flags & CNRITEM_NEWER) {
1215 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1216 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1217 MPFROM2SHORT(TRUE, CRA_SELECTED));
1218 }
1219 }
1220 SleepIfNeeded(&itdSleep, 0);
1221 } // for
1222 break;
1223
1224 case IDM_SELECTOLDER:
1225 for (x = 0; x < numS; x++) {
1226 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1227 if (pciSa[x]->flags & CNRITEM_OLDER) {
1228 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1229 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1230 MPFROM2SHORT(TRUE, CRA_SELECTED));
1231 }
1232 else if (pciDa[x]->flags & CNRITEM_OLDER) {
1233 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1234 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1235 MPFROM2SHORT(TRUE, CRA_SELECTED));
1236 }
1237 }
1238 SleepIfNeeded(&itdSleep, 0);
1239 } // for
1240 break;
1241
1242 case IDM_DESELECTBOTH:
1243 for (x = 0; x < numS; x++) {
1244 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1245 pciSa[x]->flags & CNRITEM_EXISTS) {
[929]1246 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1247 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1248 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1249 fUpdateHideButton = TRUE;
1250 }
1251 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1252 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1253 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1254 fUpdateHideButton = TRUE;
1255 }
[924]1256 }
1257 SleepIfNeeded(&itdSleep, 0);
1258 } // for
1259 break;
1260
1261 case IDM_DESELECTONE:
1262 for (x = 0; x < numS; x++) {
1263 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1264 if (~pciSa[x]->flags & CNRITEM_EXISTS) {
[929]1265 if (*pciSa[x]->pszFileName) {
1266 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
1267 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1268 MPFROM2SHORT(FALSE, CRA_SELECTED));
1269 fUpdateHideButton = TRUE;
1270 }
1271 }
1272 else if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1273 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1274 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1275 fUpdateHideButton = TRUE;
1276 }
[924]1277 }
1278 }
1279 SleepIfNeeded(&itdSleep, 0);
1280 } // for
1281 break;
1282
1283 case IDM_DESELECTBIGGER:
1284 for (x = 0; x < numS; x++) {
1285 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1286 if (pciSa[x]->flags & CNRITEM_LARGER) {
[929]1287 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1288 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1289 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1290 fUpdateHideButton = TRUE;
1291 }
[924]1292 }
1293 else if (pciDa[x]->flags & CNRITEM_LARGER) {
[929]1294 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1295 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1296 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1297 fUpdateHideButton = TRUE;
1298 }
[924]1299 }
1300 }
1301 SleepIfNeeded(&itdSleep, 0);
1302 } // for
1303 break;
1304
1305 case IDM_DESELECTSMALLER:
1306 for (x = 0; x < numS; x++) {
1307 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1308 if (pciSa[x]->flags & CNRITEM_SMALLER) {
[929]1309 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1310 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1311 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1312 fUpdateHideButton = TRUE;
1313 }
[924]1314 }
1315 else if (pciDa[x]->flags & CNRITEM_SMALLER) {
[929]1316 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1317 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1318 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1319 fUpdateHideButton = TRUE;
1320 }
[924]1321 }
1322 }
1323 SleepIfNeeded(&itdSleep, 0);
1324 } // for
1325 break;
1326
1327 case IDM_DESELECTNEWER:
1328 for (x = 0; x < numS; x++) {
1329 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1330 if (pciSa[x]->flags & CNRITEM_NEWER) {
[929]1331 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1332 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1333 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1334 fUpdateHideButton = TRUE;
1335 }
[924]1336 }
1337 else if (pciDa[x]->flags & CNRITEM_NEWER) {
[929]1338 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1339 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1340 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1341 fUpdateHideButton = TRUE;
1342 }
[924]1343 }
1344 }
1345 SleepIfNeeded(&itdSleep, 0);
1346 } // for
1347 break;
1348
1349 case IDM_DESELECTOLDER:
1350 for (x = 0; x < numS; x++) {
1351 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1352 if (pciSa[x]->flags & CNRITEM_OLDER) {
[929]1353 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1354 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1355 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1356 fUpdateHideButton = TRUE;
1357 }
[924]1358 }
1359 else if (pciDa[x]->flags & CNRITEM_OLDER) {
[929]1360 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[924]1361 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1362 MPFROM2SHORT(FALSE, CRA_SELECTED));
[929]1363 fUpdateHideButton = TRUE;
1364 }
[924]1365 }
1366 }
1367 SleepIfNeeded(&itdSleep, 0);
1368 } // for
1369 break;
1370
1371 default:
1372 break;
[929]1373 } // switch
[924]1374
1375 if (reset) {
1376 while (numS) {
1377 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD,
1378 MPFROMP(pciSa), MPFROM2SHORT((min(numS, 65535)), 0));
1379 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD,
1380 MPFROMP(pciDa), MPFROM2SHORT((min(numD, 65535)), 0));
1381 numS -= min(numS, 65535);
[1175]1382 SleepIfNeeded(&itdSleep, 0); // 12 Jan 08 SHL
[924]1383 } // while
1384 }
1385
[1039]1386 free(pciSa);
1387 free(pciDa);
[929]1388
1389 if (fUpdateHideButton) {
1390 if (WinQueryButtonCheckstate(hwnd,COMP_HIDENOTSELECTED) == 1)
1391 WinCheckButton(hwnd, COMP_HIDENOTSELECTED, 2);
1392 }
1393
1394 WinPostMsg(hwnd, WM_TIMER, MPFROMLONG(ID_TIMER), 0); // Force update
[924]1395 DosPostEventSem(CompactSem);
1396}
1397
1398/**
[748]1399 * Build FILELIST given pathname
1400 */
1401
[907]1402static VOID FillDirList(CHAR *str, UINT skiplen, BOOL recurse,
1403 FILELIST ***list, UINT *pnumfiles, UINT *pnumalloc)
[551]1404{
[748]1405 CHAR *enddir;
1406 ULONG x;
[551]1407 CHAR *maskstr;
[841]1408 PFILEFINDBUF4L pffbArray;
1409 PFILEFINDBUF4L pffbFile;
[551]1410 HDIR hDir;
[783]1411 ULONG ulFindCnt;
[841]1412 ULONG ulBufBytes = sizeof(FILEFINDBUF4L) * FilesToGet;
[551]1413 APIRET rc;
[1000]1414 static BOOL fDone;
[2]1415
[748]1416 if (!str || !*str) {
[773]1417 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
[2]1418 return;
[748]1419 }
1420
[846]1421 // DbgMsg(pszSrcFile, __LINE__, "FillDirList start %s", str);
1422
[1000]1423 maskstr = xmalloc(CCHMAXPATH + 100, pszSrcFile, __LINE__);
[551]1424 if (!maskstr)
[2]1425 return;
[783]1426 pffbArray = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
1427 if (!pffbArray) {
[1039]1428 free(maskstr);
[2]1429 return;
1430 }
1431 x = strlen(str);
[551]1432 memcpy(maskstr, str, x + 1);
[2]1433 enddir = maskstr + x;
[551]1434 if (*(enddir - 1) != '\\') {
[2]1435 *enddir = '\\';
1436 enddir++;
1437 *enddir = 0;
1438 }
1439 *enddir = '*';
1440 *(enddir + 1) = 0;
1441 hDir = HDIR_CREATE;
1442 DosError(FERR_DISABLEHARDERR);
[783]1443 ulFindCnt = FilesToGet;
[838]1444 rc = xDosFindFirst(maskstr, &hDir,
[907]1445 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
[838]1446 FILE_SYSTEM | FILE_HIDDEN |
1447 (recurse ? FILE_DIRECTORY : 0),
[841]1448 pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
[551]1449 if (!rc) {
[783]1450 do {
1451 pffbFile = pffbArray;
1452 for (x = 0; x < ulFindCnt; x++) {
1453 if (pffbFile->attrFile & FILE_DIRECTORY) {
[517]1454 // Skip . and ..
[551]1455 if (recurse &&
[783]1456 (pffbFile->achName[0] != '.' ||
1457 (pffbFile->achName[1] &&
1458 (pffbFile->achName[1] != '.' || pffbFile->achName[2])))) {
[551]1459 if (fForceUpper)
[783]1460 strupr(pffbFile->achName);
[551]1461 else if (fForceLower)
[783]1462 strlwr(pffbFile->achName);
1463 memcpy(enddir, pffbFile->achName, pffbFile->cchName + 1);
[907]1464 FillDirList(maskstr, skiplen, recurse, list, pnumfiles, pnumalloc);
[551]1465 }
1466 }
1467 else {
1468 if (fForceUpper)
[783]1469 strupr(pffbFile->achName);
[551]1470 else if (fForceLower)
[783]1471 strlwr(pffbFile->achName);
[1175]1472 memcpy(enddir, pffbFile->achName, pffbFile->cchName + 1);
1473 if (strlen(maskstr) > CCHMAXPATH) {
[1000]1474 // Complain if pathnames exceeds max
1475 DosFindClose(hDir);
[1175]1476 free(pffbArray);
1477 free(maskstr);
[1000]1478 if (!fDone) {
1479 fDone = TRUE;
1480 saymsg(MB_OK | MB_ICONASTERISK,
1481 HWND_DESKTOP,
1482 GetPString(IDS_WARNINGTEXT),
1483 "One or more of your files has a full path name that exceeds the OS/2 maximum");
[1175]1484 }
1485 return;
[1000]1486 }
[783]1487 if (AddToFileList(maskstr + skiplen,
[907]1488 pffbFile, list, pnumfiles, pnumalloc)) {
[551]1489 goto Abort;
[783]1490 }
[551]1491 }
[841]1492 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
[783]1493 } // for
[2]1494 DosError(FERR_DISABLEHARDERR);
[783]1495 ulFindCnt = FilesToGet;
[850]1496 rc = xDosFindNext(hDir, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
[783]1497 } while (!rc);
1498
1499Abort:
1500
[2]1501 DosFindClose(hDir);
[846]1502 DosSleep(0);
[2]1503 }
[783]1504
1505 if (rc && rc != ERROR_NO_MORE_FILES) {
1506 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
1507 GetPString(IDS_CANTFINDDIRTEXT), maskstr);
1508 }
1509
[1009]1510 xfree(maskstr, pszSrcFile, __LINE__);
1511 xfree(pffbArray, pszSrcFile, __LINE__);
[846]1512
1513 // DbgMsg(pszSrcFile, __LINE__, "FillDirList finish %s", str);
[2]1514}
1515
[924]1516/**
1517 * Compare names for qsort
1518 */
[2]1519
[551]1520static int CompNames(const void *n1, const void *n2)
[316]1521{
[919]1522 FILELIST *fl1 = *(FILELIST **)n1;
1523 FILELIST *fl2 = *(FILELIST **)n2;
[2]1524
[551]1525 return stricmp(fl1->fname, fl2->fname);
[2]1526}
1527
[316]1528//=== FillCnrsThread() Fill left and right containers ===
[2]1529
[751]1530static VOID FillCnrsThread(VOID *args)
[316]1531{
[919]1532 COMPARE *cmp = (COMPARE *)args;
[551]1533 HAB hab;
1534 HMQ hmq;
1535 BOOL notified = FALSE;
[907]1536 ITIMER_DESC itdSleep = { 0 };
[751]1537
[551]1538 HWND hwndLeft, hwndRight;
[748]1539 CHAR szBuf[CCHMAXPATH];
1540 CNRINFO cnri;
[2]1541
[1009]1542# ifdef FORTIFY
1543 // 10 May 08 SHL fixme to suppress W111
1544 Fortify_EnterScope();
[1063]1545# endif
[1009]1546
[748]1547 if (!cmp) {
[773]1548 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
[1063]1549# ifdef FORTIFY
[1009]1550 // 10 May 08 SHL fixme to suppress W111
1551 Fortify_LeaveScope();
[1063]1552# endif
[1335]1553 return; // 10 Dec 08 SHL was _endthread
[748]1554 }
[2]1555
[846]1556 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread enter");
1557
[2]1558 DosError(FERR_DISABLEHARDERR);
1559
[907]1560 InitITimer(&itdSleep, 500); // Sleep every 500 mSec
1561
[2]1562 hab = WinInitialize(0);
[551]1563 if (!hab)
1564 Win_Error(NULLHANDLE, NULLHANDLE, pszSrcFile, __LINE__, "WinInitialize");
[362]1565 else {
[551]1566 hmq = WinCreateMsgQueue(hab, 0);
1567 if (!hmq)
1568 Win_Error(NULLHANDLE, NULLHANDLE, pszSrcFile, __LINE__,
1569 "WinCreateMsgQueue");
[362]1570 else {
[551]1571 INT x;
[907]1572 UINT l;
1573 UINT r;
[919]1574 // UINT cntr;
[551]1575 FILELIST **filesl = NULL;
1576 FILELIST **filesr = NULL;
[907]1577 UINT numallocl = 0;
1578 UINT numallocr = 0;
[897]1579 INT ret = 0;
[769]1580 UINT lenl; // Directory prefix length
1581 UINT lenr;
[748]1582 UINT recsNeeded;
[907]1583 UINT recsGotten;
[551]1584 PCNRITEM pcilFirst;
1585 PCNRITEM pcirFirst;
[907]1586 PCNRITEM pcilLast;
1587 PCNRITEM pcirLast;
[551]1588 PCNRITEM pcil;
1589 PCNRITEM pcir;
1590 RECORDINSERT ri;
1591 CHAR *pch;
[2]1592
[551]1593 WinCancelShutdown(hmq, TRUE);
[535]1594 IncrThreadUsage();
[907]1595
[551]1596 hwndLeft = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
1597 hwndRight = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
[2]1598 lenl = strlen(cmp->leftdir);
[551]1599 if (cmp->leftdir[strlen(cmp->leftdir) - 1] != '\\')
1600 lenl++;
[2]1601 lenr = strlen(cmp->rightdir);
[551]1602 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
1603 lenr++;
[2]1604 priority_normal();
[748]1605 // Clear containers
[751]1606 RemoveCnrItems(hwndRight, NULL, 0, CMA_FREE | CMA_INVALIDATE);
1607 RemoveCnrItems(hwndLeft, NULL, 0, CMA_FREE | CMA_INVALIDATE);
[917]1608 cmp->cmp->totalleft = 0;
1609 cmp->cmp->totalright = 0;
[2]1610
[748]1611 // Build list of all files in left directory
[551]1612 if (fForceLower)
1613 strlwr(cmp->leftdir);
1614 else if (fForceUpper)
1615 strupr(cmp->leftdir);
1616 FillDirList(cmp->leftdir, lenl, cmp->includesubdirs,
[907]1617 &filesl, &cmp->cmp->totalleft, &numallocl);
[2]1618
[551]1619 if (filesl)
[917]1620 qsort(filesl, cmp->cmp->totalleft, sizeof(CHAR *), CompNames);
[748]1621
[846]1622 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread sorted filesl");
1623
[748]1624 // Build list of all files in right directory
[551]1625 if (!*cmp->rightlist) {
1626 if (fForceLower)
1627 strlwr(cmp->rightdir);
1628 else if (fForceUpper)
1629 strupr(cmp->rightdir);
1630 FillDirList(cmp->rightdir, lenr, cmp->includesubdirs,
[907]1631 &filesr, &cmp->cmp->totalright, &numallocr);
[2]1632 }
[551]1633 else {
[748]1634 // Use snapshot file
[551]1635 FILE *fp;
[841]1636 FILEFINDBUF4L fb4;
[551]1637 CHAR str[CCHMAXPATH * 2], *p;
[2]1638
[551]1639 memset(&fb4, 0, sizeof(fb4));
1640 fp = fopen(cmp->rightlist, "r");
1641 if (!fp)
1642 Runtime_Error(pszSrcFile, __LINE__, "can not open %s (%d)",
1643 cmp->rightlist, errno);
[362]1644 else {
[551]1645 while (!feof(fp)) {
[748]1646 // First get name of directory
[551]1647 if (!xfgets_bstripcr(str, sizeof(str), fp, pszSrcFile, __LINE__))
1648 break; // EOF
1649 p = str;
1650 if (*p == '\"') {
[748]1651 // Quoted
[551]1652 p++;
1653 if (*p && *p != '\"') {
1654 p = strchr(p, '\"');
1655 if (p) {
1656 *p = 0;
1657 if (*(str + 1)) {
1658 strcpy(cmp->rightdir, str + 1);
1659 if (fForceUpper)
1660 strupr(cmp->rightdir);
1661 else if (fForceLower)
1662 strlwr(cmp->rightdir);
1663 p = cmp->rightdir + (strlen(cmp->rightdir) - 1);
1664 if (p - cmp->rightdir > 3 && *p == '\\')
1665 *p = 0; // Chop trailing slash
1666 break;
1667 }
1668 }
1669 }
1670 }
[748]1671 } // while !EOF
[2]1672
[748]1673 memset(&cnri, 0, sizeof(cnri));
1674 cnri.cb = sizeof(cnri);
1675 cnri.pszCnrTitle = cmp->rightdir;
1676 if (!WinSendMsg(hwndRight, CM_SETCNRINFO,
1677 MPFROMP(&cnri), MPFROMLONG(CMA_CNRTITLE))) {
1678 Win_Error(hwndRight, cmp->hwnd, pszSrcFile, __LINE__, "CM_SETCNRINFO");
[551]1679 }
[748]1680
[551]1681 if (*cmp->rightdir) {
[769]1682 lenr = strlen(cmp->rightdir);
1683 if (cmp->rightdir[strlen(cmp->rightdir) - 1] != '\\')
1684 lenr++;
[551]1685 while (!feof(fp)) {
1686 if (!xfgets_bstripcr
1687 (str, sizeof(str), fp, pszSrcFile, __LINE__))
1688 break;
1689 p = str;
1690 if (*p == '\"') {
1691 p++;
1692 if (*p && *p != '\"') {
1693 p = strchr(p, '\"');
1694 if (p) {
1695 *p = 0;
1696 p++;
1697 if (*p == ',') {
1698 p++;
1699 if (!cmp->includesubdirs && atol(p) > lenr)
1700 continue;
1701 p = strchr(p, ',');
1702 if (p) {
1703 p++;
[846]1704 // 27 Sep 07 SHL fixme to do ULONGLONG conversion
[551]1705 fb4.cbFile = atol(p);
1706 p = strchr(p, ',');
1707 if (p) {
1708 p++;
1709 fb4.fdateLastWrite.year = atol(p) - 1980;
1710 p = strchr(p, '/');
1711 if (p) {
1712 p++;
1713 fb4.fdateLastWrite.month = atol(p);
1714 p = strchr(p, '/');
1715 if (p) {
1716 p++;
1717 fb4.fdateLastWrite.day = atol(p);
1718 p = strchr(p, ',');
1719 if (p) {
1720 p++;
1721 fb4.ftimeLastWrite.hours = atol(p);
1722 p = strchr(p, ':');
1723 if (p) {
1724 p++;
1725 fb4.ftimeLastWrite.minutes = atol(p);
1726 p = strchr(p, ':');
1727 if (p) {
1728 p++;
1729 fb4.ftimeLastWrite.twosecs = atol(p);
1730 p = strchr(p, ',');
1731 if (p) {
1732 p++;
1733 fb4.attrFile = atol(p);
1734 p = strchr(p, ',');
1735 if (p) {
1736 p++;
1737 fb4.cbList = atol(p) * 2;
1738 if (fForceUpper)
1739 strupr(str + 1);
1740 else if (fForceLower)
1741 strlwr(str + 1);
1742 if (AddToFileList((str + 1) + lenr,
1743 &fb4,
1744 &filesr,
[917]1745 &cmp->cmp->totalright,
[551]1746 &numallocr))
1747 break;
1748 }
1749 }
1750 }
1751 }
1752 }
1753 }
1754 }
1755 }
1756 }
1757 }
1758 }
1759 }
1760 }
[748]1761 } // while
1762 } // if have rightdir
[551]1763 fclose(fp);
1764 }
[748]1765 } // if snapshot file
[316]1766
[551]1767 if (filesr)
[917]1768 qsort(filesr, cmp->cmp->totalright, sizeof(CHAR *), CompNames);
[2]1769
[846]1770 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread sorted filesr");
1771
[748]1772 // We now have two lists of files, both sorted.
1773 // Count total number of container entries required on each side
[2]1774 l = r = 0;
[316]1775 recsNeeded = 0;
[551]1776 while ((filesl && filesl[l]) || (filesr && filesr[r])) {
[748]1777
1778 if (filesl && filesl[l]) {
1779 if (filesr && filesr[r])
1780 x = stricmp(filesl[l]->fname, filesr[r]->fname);
[551]1781 else
[748]1782 x = -1; // Left side list longer
[551]1783 }
[748]1784 else
1785 x = +1; // Right side list longer
1786
1787 if (x <= 0)
1788 l++; // On left side
1789 if (x >= 0)
1790 r++; // On right side
1791
1792 recsNeeded++; // Keep count of how many entries req'd
1793
1794 } // while
1795
[907]1796 // Say building list - fixme to post?
[551]1797 WinSendMsg(cmp->hwnd, UM_CONTAINERHWND, MPVOID, MPVOID);
[748]1798
1799 // Now insert records into the containers
[551]1800 if (recsNeeded) {
1801 pcilFirst = WinSendMsg(hwndLeft,
1802 CM_ALLOCRECORD,
[751]1803 MPFROMLONG(EXTRA_RECORD_BYTES),
[551]1804 MPFROMLONG(recsNeeded));
1805 if (!pcilFirst) {
[742]1806 Win_Error(hwndLeft, cmp->hwnd, pszSrcFile, __LINE__, "CM_ALLOCRECORD %u failed",
1807 recsNeeded);
[551]1808 recsNeeded = 0;
1809 }
[316]1810 }
[362]1811 if (recsNeeded) {
[551]1812 pcirFirst = WinSendMsg(hwndRight, CM_ALLOCRECORD,
[751]1813 MPFROMLONG(EXTRA_RECORD_BYTES),
[551]1814 MPFROMLONG(recsNeeded));
1815 if (!pcirFirst) {
[742]1816 Win_Error(hwndRight, cmp->hwnd, pszSrcFile, __LINE__, "CM_ALLOCRECORD %u failed",
1817 recsNeeded);
[551]1818 recsNeeded = 0;
[751]1819 FreeCnrItemList(hwndLeft, pcilFirst);
[551]1820 }
[2]1821 }
[748]1822
[362]1823 if (recsNeeded) {
[748]1824
[846]1825 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread filling");
1826
[919]1827 l = 0;
1828 r = 0;
[551]1829 pcil = pcilFirst;
1830 pcir = pcirFirst;
[919]1831 pcilLast = NULL;
1832 pcirLast = NULL;
[907]1833
1834 recsGotten = 0;
[919]1835 cmp->cmp->totalleft = 0;
1836 cmp->cmp->totalright = 0;
[907]1837
[551]1838 while ((filesl && filesl[l]) || (filesr && filesr[r])) {
[907]1839
[919]1840 // 12 Jan 08 SHL fixme to have message in string table
[907]1841 if (!pcil) {
[919]1842 Runtime_Error(pszSrcFile, __LINE__, "Insufficient memory or %u items (%u)",
1843 recsNeeded, recsGotten);
[907]1844 break;
1845 }
1846
[919]1847 // 12 Jan 08 SHL fixme to have message in string table
[907]1848 if (!pcir) {
[919]1849 Runtime_Error(pszSrcFile, __LINE__, "Insufficient memory or %u items (%u)",
1850 recsNeeded, recsGotten);
[907]1851 break;
1852 }
1853 recsGotten++;
[551]1854 pcir->hwndCnr = hwndRight;
[919]1855 pcir->rc.hptrIcon = (HPOINTER)0;
[551]1856 pcil->hwndCnr = hwndLeft;
[919]1857 pcil->rc.hptrIcon = (HPOINTER)0;
[748]1858
1859 if (filesl && filesl[l]) {
1860 if (filesr && filesr[r])
1861 x = stricmp(filesl[l]->fname, filesr[r]->fname);
1862 else
1863 x = -1; // Left side list longer
1864 }
1865 else
1866 x = +1; // Right side list longer
1867
1868 if (x <= 0) {
[769]1869 // File appears on left side
[919]1870 cmp->cmp->totalleft++;
[769]1871 BldFullPathName(szBuf, cmp->leftdir, filesl[l]->fname);
1872 pcil->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__);
[748]1873 pcil->pszDisplayName = pcil->pszFileName + lenl;
1874 pcil->attrFile = filesl[l]->attrFile;
[751]1875 pcil->pszDispAttr = FileAttrToString(pcil->attrFile);
[748]1876 pcil->cbFile = filesl[l]->cbFile;
[919]1877 // 12 Jan 08 SHL fixme to used cached size here too
1878 CommaFmtULL(szBuf, sizeof(szBuf), pcil->cbFile, ' ');
1879 pcil->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__);
[748]1880 pcil->easize = filesl[l]->easize;
1881 pcil->date.day = filesl[l]->date.day;
1882 pcil->date.month = filesl[l]->date.month;
1883 pcil->date.year = filesl[l]->date.year + 1980;
1884 pcil->time.seconds = filesl[l]->time.twosecs * 2;
1885 pcil->time.minutes = filesl[l]->time.minutes;
1886 pcil->time.hours = filesl[l]->time.hours;
1887 pcil->ladate.day = filesl[l]->ladate.day;
1888 pcil->ladate.month = filesl[l]->ladate.month;
1889 pcil->ladate.year = filesl[l]->ladate.year + 1980;
1890 pcil->latime.seconds = filesl[l]->latime.twosecs * 2;
1891 pcil->latime.minutes = filesl[l]->latime.minutes;
1892 pcil->latime.hours = filesl[l]->latime.hours;
1893 pcil->crdate.day = filesl[l]->crdate.day;
1894 pcil->crdate.month = filesl[l]->crdate.month;
1895 pcil->crdate.year = filesl[l]->crdate.year + 1980;
1896 pcil->crtime.seconds = filesl[l]->crtime.twosecs * 2;
1897 pcil->crtime.minutes = filesl[l]->crtime.minutes;
1898 pcil->crtime.hours = filesl[l]->crtime.hours;
1899 if (*cmp->dcd.mask.szMask) {
[919]1900 if (!Filter((PMINIRECORDCORE)pcil, (PVOID)&cmp->dcd.mask)) {
[748]1901 pcil->rc.flRecordAttr |= CRA_FILTERED;
1902 pcir->rc.flRecordAttr |= CRA_FILTERED;
1903 }
1904 }
1905 } // if on left
1906
1907 if (x >= 0) {
[769]1908 // File appears on right side
[919]1909 cmp->cmp->totalright++;
[773]1910 BldFullPathName(szBuf, cmp->rightdir, filesr[r]->fname);
[769]1911 pcir->pszFileName = xstrdup(szBuf, pszSrcFile, __LINE__); // 31 Jul 07 SHL
[748]1912 pcir->pszDisplayName = pcir->pszFileName + lenr;
1913 pcir->attrFile = filesr[r]->attrFile;
1914 // pcir->rc.hptrIcon = hptrFile;
[751]1915 pcir->pszDispAttr = FileAttrToString(pcir->attrFile);
[748]1916 pcir->cbFile = filesr[r]->cbFile;
[919]1917 // 12 Jan 08 SHL fixme to used cached size here too
1918 CommaFmtULL(szBuf, sizeof(szBuf), pcir->cbFile, ' ');
1919 pcir->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__);
[748]1920 pcir->easize = filesr[r]->easize;
1921 pcir->date.day = filesr[r]->date.day;
1922 pcir->date.month = filesr[r]->date.month;
1923 pcir->date.year = filesr[r]->date.year + 1980;
1924 pcir->time.seconds = filesr[r]->time.twosecs * 2;
1925 pcir->time.minutes = filesr[r]->time.minutes;
1926 pcir->time.hours = filesr[r]->time.hours;
1927 pcir->ladate.day = filesr[r]->ladate.day;
1928 pcir->ladate.month = filesr[r]->ladate.month;
1929 pcir->ladate.year = filesr[r]->ladate.year + 1980;
1930 pcir->latime.seconds = filesr[r]->latime.twosecs * 2;
1931 pcir->latime.minutes = filesr[r]->latime.minutes;
1932 pcir->latime.hours = filesr[r]->latime.hours;
1933 pcir->crdate.day = filesr[r]->crdate.day;
1934 pcir->crdate.month = filesr[r]->crdate.month;
1935 pcir->crdate.year = filesr[r]->crdate.year + 1980;
1936 pcir->crtime.seconds = filesr[r]->crtime.twosecs * 2;
1937 pcir->crtime.minutes = filesr[r]->crtime.minutes;
1938 pcir->crtime.hours = filesr[r]->crtime.hours;
[790]1939 // Bypass check if already filtered on left side
1940 if (~pcir->rc.flRecordAttr & CRA_FILTERED &&
[748]1941 *cmp->dcd.mask.szMask) {
1942 if (!Filter((PMINIRECORDCORE)pcir, (PVOID)&cmp->dcd.mask)) {
1943 pcil->rc.flRecordAttr |= CRA_FILTERED;
1944 pcir->rc.flRecordAttr |= CRA_FILTERED;
1945 }
1946 }
1947 } // if on right
1948
1949 if (x == 0) {
1950 // File appears on both sides
[769]1951 pcil->flags |= CNRITEM_EXISTS;
1952 pcir->flags |= CNRITEM_EXISTS;
1953 pch = szBuf;
[748]1954 // Subject field holds status messages
1955 *pch = 0;
1956 if (pcil->cbFile + pcil->easize > pcir->cbFile + pcir->easize) {
1957 pcil->flags |= CNRITEM_LARGER;
1958 pcir->flags |= CNRITEM_SMALLER;
1959 strcpy(pch, GetPString(IDS_LARGERTEXT));
1960 pch += 6;
1961 }
1962 else if (pcil->cbFile + pcil->easize <
1963 pcir->cbFile + pcir->easize) {
1964 pcil->flags |= CNRITEM_SMALLER;
1965 pcir->flags |= CNRITEM_LARGER;
1966 strcpy(pch, GetPString(IDS_SMALLERTEXT));
1967 pch += 7;
[907]1968 }
1969 ret = TestCDates(&pcir->date, &pcir->time,
1970 &pcil->date, &pcil->time);
1971 if (ret == 1)
[924]1972 /* 13 Jan 08 SHL fixme to be gone
1973 ((pcil->date.year > pcir->date.year) ? TRUE :
[748]1974 (pcil->date.year < pcir->date.year) ? FALSE :
1975 (pcil->date.month > pcir->date.month) ? TRUE :
1976 (pcil->date.month < pcir->date.month) ? FALSE :
1977 (pcil->date.day > pcir->date.day) ? TRUE :
1978 (pcil->date.day < pcir->date.day) ? FALSE :
1979 (pcil->time.hours > pcir->time.hours) ? TRUE :
1980 (pcil->time.hours < pcir->time.hours) ? FALSE :
1981 (pcil->time.minutes > pcir->time.minutes) ? TRUE :
1982 (pcil->time.minutes < pcir->time.minutes) ? FALSE :
1983 (pcil->time.seconds > pcir->time.seconds) ? TRUE :
[924]1984 (pcil->time.seconds < pcir->time.seconds) ? FALSE : FALSE)
1985 */
1986 {
[748]1987 pcil->flags |= CNRITEM_NEWER;
1988 pcir->flags |= CNRITEM_OLDER;
[769]1989 if (pch != szBuf) {
[748]1990 strcpy(pch, ", ");
1991 pch += 2;
1992 }
1993 strcpy(pch, GetPString(IDS_NEWERTEXT));
1994 pch += 5;
1995 }
[907]1996 else if (ret == -1)
[924]1997 /* 13 Jan 08 SHL fixme to be gone
1998 ((pcil->date.year < pcir->date.year) ? TRUE :
1999 (pcil->date.year > pcir->date.year) ? FALSE :
2000 (pcil->date.month < pcir->date.month) ? TRUE :
2001 (pcil->date.month > pcir->date.month) ? FALSE :
2002 (pcil->date.day < pcir->date.day) ? TRUE :
2003 (pcil->date.day > pcir->date.day) ? FALSE :
2004 (pcil->time.hours < pcir->time.hours) ? TRUE :
2005 (pcil->time.hours > pcir->time.hours) ? FALSE :
2006 (pcil->time.minutes < pcir->time.minutes) ? TRUE :
2007 (pcil->time.minutes > pcir->time.minutes) ? FALSE :
2008 (pcil->time.seconds < pcir->time.seconds) ? TRUE :
2009 (pcil->time.seconds > pcir->time.seconds) ? FALSE :
2010 FALSE)
2011 */
2012 {
[748]2013 pcil->flags |= CNRITEM_OLDER;
2014 pcir->flags |= CNRITEM_NEWER;
[769]2015 if (pch != szBuf) {
[748]2016 strcpy(pch, ", ");
2017 pch += 2;
2018 }
2019 strcpy(pch, GetPString(IDS_OLDERTEXT));
2020 pch += 5;
2021 }
[769]2022 pcil->pszSubject = *szBuf ?
2023 xstrdup(szBuf, pszSrcFile, __LINE__) :
[751]2024 NullStr;
[748]2025
2026 } // if on both sides
2027
[1175]2028 if (x <= 0) {
[919]2029 free(filesl[l++]); // Done with item on left
[1175]2030 }
2031 if (x >= 0) {
2032 free(filesr[r++]); // Done with item on right
2033 }
[748]2034 // Ensure empty buffers point somewhere
2035 if (!pcil->pszFileName) {
2036 pcil->pszFileName = NullStr;
2037 pcil->pszDisplayName = pcil->pszFileName;
2038 }
2039
2040 if (!pcir->pszFileName) {
2041 pcir->pszFileName = NullStr;
2042 pcir->pszDisplayName = pcir->pszFileName;
2043 }
2044
[751]2045 pcil->rc.pszIcon = pcil->pszDisplayName;
2046 pcir->rc.pszIcon = pcir->pszDisplayName;
[748]2047
[762]2048 pcil->pszLongName = NullStr;
2049 pcir->pszLongName = NullStr;
[751]2050
[748]2051 if (!pcil->pszSubject)
2052 if (!pcir->pszSubject)
[790]2053 pcir->pszSubject = NullStr;
[748]2054
[751]2055 if (!pcil->pszDispAttr)
2056 pcil->pszDispAttr = NullStr;
2057 if (!pcir->pszDispAttr)
[790]2058 pcir->pszDispAttr = NullStr;
[751]2059
[907]2060 // Avoid hogging systems
2061 SleepIfNeeded(&itdSleep, 0);
[748]2062
[907]2063 pcilLast = pcil;
2064 pcirLast = pcir;
[919]2065 pcil = (PCNRITEM)pcil->rc.preccNextRecord;
2066 pcir = (PCNRITEM)pcir->rc.preccNextRecord;
[748]2067
2068 } // while filling left or right
2069
[907]2070 // If stopped early CM_ALLOCATERECORD partially failed
2071 // Free up container records we did not use on other side
[919]2072 // Free up items we did not insert in container
[907]2073 if (recsGotten < recsNeeded) {
2074 if (pcil) {
[919]2075 if (pcilLast)
2076 pcilLast->rc.preccNextRecord = NULL;
2077 else
2078 pcilFirst = NULL;
[907]2079 FreeCnrItemList(hwndLeft, pcil);
2080 }
2081 if (filesl) {
[1175]2082 for(; filesl[l]; l++) {
2083 free(filesl[l]);
2084 }
[907]2085 }
2086 if (pcir) {
[919]2087 if (pcirLast)
2088 pcirLast->rc.preccNextRecord = NULL;
2089 else
2090 pcirFirst = NULL;
[907]2091 FreeCnrItemList(hwndRight, pcir);
2092 }
2093 if (filesr) {
[1175]2094 for (; filesr[r]; r++) {
2095 free(filesr[r]);
2096 }
[907]2097 }
[917]2098 // Reduce count to match what is in containers
[907]2099 recsNeeded = recsGotten;
2100 } // if insufficient resources
2101
[1175]2102 xfree(filesl, pszSrcFile, __LINE__); // Free header - have already freed elements
[551]2103 filesl = NULL;
[1009]2104 xfree(filesr, pszSrcFile, __LINE__);
[551]2105 filesr = NULL;
[907]2106
2107 // Say inserting
[551]2108 WinSendMsg(cmp->hwnd, UM_CONTAINERDIR, MPVOID, MPVOID);
[748]2109
[907]2110 // Insert left side
[551]2111 memset(&ri, 0, sizeof(RECORDINSERT));
2112 ri.cb = sizeof(RECORDINSERT);
[919]2113 ri.pRecordOrder = (PRECORDCORE)CMA_END;
2114 ri.pRecordParent = (PRECORDCORE)NULL;
2115 ri.zOrder = (ULONG)CMA_TOP;
[551]2116 ri.cRecordsInsert = recsNeeded;
2117 ri.fInvalidateRecord = FALSE;
[919]2118
[551]2119 if (!WinSendMsg(hwndLeft, CM_INSERTRECORD,
2120 MPFROMP(pcilFirst), MPFROMP(&ri))) {
[742]2121 Win_Error(hwndLeft, cmp->hwnd, pszSrcFile, __LINE__, "CM_INSERTRECORD");
[751]2122 FreeCnrItemList(hwndLeft, pcilFirst);
[917]2123 cmp->cmp->totalleft = 0;
[551]2124 }
[748]2125
[907]2126 // Insert right side
[551]2127 memset(&ri, 0, sizeof(RECORDINSERT));
2128 ri.cb = sizeof(RECORDINSERT);
[919]2129 ri.pRecordOrder = (PRECORDCORE)CMA_END;
2130 ri.pRecordParent = (PRECORDCORE)NULL;
2131 ri.zOrder = (ULONG)CMA_TOP;
[551]2132 ri.cRecordsInsert = recsNeeded;
2133 ri.fInvalidateRecord = FALSE;
[751]2134
[551]2135 if (!WinSendMsg(hwndRight, CM_INSERTRECORD,
2136 MPFROMP(pcirFirst), MPFROMP(&ri))) {
[751]2137 Win_Error(hwndRight, cmp->hwnd, pszSrcFile, __LINE__, "CM_INSERTRECORD");
2138 RemoveCnrItems(hwndLeft, NULL, 0, CMA_FREE | CMA_INVALIDATE);
2139 FreeCnrItemList(hwndRight, pcirFirst);
[917]2140 cmp->cmp->totalright = 0;
[551]2141 }
[748]2142
[846]2143 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread filled");
2144
[748]2145 } // if recsNeeded
2146
[2]2147 Deselect(hwndLeft);
2148 Deselect(hwndRight);
[748]2149
[846]2150 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread deselected");
2151
[907]2152 // Request window update
[551]2153 if (!PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID))
2154 WinSendMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
[2]2155 notified = TRUE;
[748]2156
[846]2157 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread FILLED posted");
2158
[362]2159 if (filesl)
[748]2160 FreeList((CHAR **)filesl); // Must have failed to create container
[362]2161 if (filesr)
[748]2162 FreeList((CHAR **)filesr);
2163
[2]2164 WinDestroyMsgQueue(hmq);
[907]2165 } // if have queue
2166 if (!notified)
2167 PostMsg(cmp->hwnd, UM_CONTAINER_FILLED, MPVOID, MPVOID);
[535]2168 DecrThreadUsage();
[2]2169 WinTerminate(hab);
2170 }
[1039]2171 free(cmp);
[2]2172 DosPostEventSem(CompactSem);
[846]2173
[1009]2174# ifdef FORTIFY
[1038]2175 Fortify_LeaveScope();
[1063]2176# endif
[1009]2177
[846]2178 // DbgMsg(pszSrcFile, __LINE__, "FillCnrsThread exit");
[2]2179}
2180
[929]2181// fixme to be gone - use variable?
[773]2182#define hwndLeft (WinWindowFromID(hwnd,COMP_LEFTDIR))
2183#define hwndRight (WinWindowFromID(hwnd,COMP_RIGHTDIR))
[2]2184
[316]2185//=== CompareDlgProc() Compare directories dialog procedure ===
[2]2186
[551]2187MRESULT EXPENTRY CompareDlgProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
[316]2188{
[551]2189 COMPARE *cmp;
[773]2190 BOOL temp;
[907]2191 CHAR s[81];
[362]2192
[773]2193 static HPOINTER hptr;
[2]2194
[551]2195 switch (msg) {
2196 case WM_INITDLG:
[919]2197 cmp = (COMPARE *)mp2;
[551]2198 if (!cmp) {
2199 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2200 WinDismissDlg(hwnd, 0);
2201 }
2202 else {
2203 if (!hptr)
2204 hptr = WinLoadPointer(HWND_DESKTOP, FM3ModHandle, COMPARE_ICON);
2205 WinDefDlgProc(hwnd, WM_SETICON, MPFROMLONG(hptr), MPVOID);
2206 cmp->hwnd = hwnd;
[919]2207 WinSetWindowPtr(hwnd, QWL_USER, (PVOID)cmp);
[938]2208 {
[1175]2209 SWP swp;
2210 ULONG size = sizeof(SWP);
[938]2211
[1175]2212 PrfQueryProfileData(fmprof, FM3Str, "CompDir.Position", (PVOID) &swp, &size);
[1394]2213 swp.fl &= ~SWP_SIZE; // 04 Feb 09 SHL ignore saved size
[1175]2214 WinSetWindowPos(hwnd,
2215 HWND_TOP,
2216 swp.x,
2217 swp.y,
2218 swp.cx,
2219 swp.cy,
2220 swp.fl);
[938]2221 }
[551]2222 SetCnrCols(hwndLeft, TRUE);
2223 SetCnrCols(hwndRight, TRUE);
2224 WinSendMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2225 WinSendMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2226 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
2227 {
2228 USHORT ids[] = { COMP_LEFTDIR, COMP_RIGHTDIR, COMP_TOTALLEFT,
[751]2229 COMP_TOTALRIGHT, COMP_SELLEFT, COMP_SELRIGHT,
2230 0
2231 };
[919]2232 UINT x;
[1394]2233 for (x = 0; ids[x]; x++) {
2234 //fixme to allow user to change presparams 1-10-09 GKY
[551]2235 SetPresParams(WinWindowFromID(hwnd, ids[x]),
2236 &RGBGREY,
[1391]2237 &RGBBLACK, &RGBBLACK, FNT_8HELVETICA);
[924]2238 }
[2]2239 }
[929]2240 WinStartTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER, 500);
[551]2241 }
2242 break;
[2]2243
[551]2244 case UM_STRETCH:
2245 {
2246 SWP swp, swpC;
2247 LONG titl, szbx, szby, sz;
2248 HWND hwndActive;
[2]2249
[551]2250 WinQueryWindowPos(hwnd, &swp);
2251 if (!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
2252 hwndActive = WinQueryFocus(HWND_DESKTOP);
2253 szbx = SysVal(SV_CXSIZEBORDER);
2254 szby = SysVal(SV_CYSIZEBORDER);
2255 titl = SysVal(SV_CYTITLEBAR);
2256 titl += 26;
2257 swp.cx -= (szbx * 2);
2258 sz = (swp.cx / 8);
2259 WinQueryWindowPos(WinWindowFromID(hwnd, COMP_LEFTDIR), &swpC);
2260 WinSetWindowPos(WinWindowFromID(hwnd, COMP_LEFTDIR), HWND_TOP,
2261 szbx + 6,
2262 swpC.y,
2263 (swp.cx / 2) - (szbx + 6),
2264 ((swp.cy - swpC.y) - titl) - szby,
2265 SWP_MOVE | SWP_SIZE);
2266 WinSetWindowPos(WinWindowFromID(hwnd, COMP_RIGHTDIR), HWND_TOP,
2267 (swp.cx / 2) + (szbx + 6),
2268 swpC.y,
2269 (swp.cx / 2) - (szbx + 6),
2270 ((swp.cy - swpC.y) - titl) - szby,
2271 SWP_MOVE | SWP_SIZE);
2272 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALLEFTHDR), HWND_TOP,
2273 szbx + 6,
2274 ((swp.cy - titl) - szby) + 4,
2275 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2276 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALLEFT), HWND_TOP,
2277 sz + (szbx + 6),
2278 ((swp.cy - titl) - szby) + 4,
2279 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2280 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELLEFTHDR), HWND_TOP,
2281 (sz * 2) + (szbx + 6),
2282 ((swp.cy - titl) - szby) + 4,
2283 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2284 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELLEFT), HWND_TOP,
2285 (sz * 3) + (szbx + 6),
2286 ((swp.cy - titl) - szby) + 4,
2287 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2288 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALRIGHTHDR), HWND_TOP,
2289 (sz * 4) + (szbx + 6),
2290 ((swp.cy - titl) - szby) + 4,
2291 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2292 WinSetWindowPos(WinWindowFromID(hwnd, COMP_TOTALRIGHT), HWND_TOP,
2293 (sz * 5) + (szbx + 6),
2294 ((swp.cy - titl) - szby) + 4,
2295 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2296 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELRIGHTHDR), HWND_TOP,
2297 (sz * 6) + (szbx + 6),
2298 ((swp.cy - titl) - szby) + 4,
2299 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2300 WinSetWindowPos(WinWindowFromID(hwnd, COMP_SELRIGHT), HWND_TOP,
2301 (sz * 7) + (szbx + 6),
2302 ((swp.cy - titl) - szby) + 4,
2303 sz - (szbx + 6), 20, SWP_MOVE | SWP_SIZE);
2304 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_TOTALLEFT),
[919]2305 (HPS)0, FALSE, FALSE);
[551]2306 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_SELLEFT),
[919]2307 (HPS)0, FALSE, FALSE);
[551]2308 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_TOTALRIGHT),
[919]2309 (HPS)0, FALSE, FALSE);
[551]2310 PaintRecessedWindow(WinWindowFromID(hwnd, COMP_SELRIGHT),
[919]2311 (HPS)0, FALSE, FALSE);
2312 PaintRecessedWindow(hwndLeft, (HPS)0,
[551]2313 (hwndActive == hwndLeft), TRUE);
[919]2314 PaintRecessedWindow(hwndRight, (HPS)0,
[551]2315 (hwndActive == hwndRight), TRUE);
[2]2316 }
[551]2317 }
2318 return 0;
[2]2319
[551]2320 case WM_ADJUSTWINDOWPOS:
2321 PostMsg(hwnd, UM_STRETCH, MPVOID, MPVOID);
2322 break;
[2]2323
[551]2324 case UM_SETUP:
2325 {
2326 CNRINFO cnri;
2327 BOOL tempsubj;
[2]2328
[551]2329 cmp = INSTDATA(hwnd);
[919]2330 if (!cmp)
2331 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
2332 else {
[551]2333 cmp->dcd.size = sizeof(DIRCNRDATA);
2334 cmp->dcd.type = DIR_FRAME;
2335 cmp->dcd.hwndFrame = hwnd;
2336 cmp->dcd.hwndClient = hwnd;
2337 cmp->dcd.mask.attrFile = (FILE_DIRECTORY | FILE_ARCHIVED |
2338 FILE_READONLY | FILE_SYSTEM | FILE_HIDDEN);
[1065]2339 LoadDetailsSwitches("DirCmp", &cmp->dcd.ds);
2340 cmp->dcd.ds.detailslongname = FALSE;
2341 cmp->dcd.ds.detailsicon = FALSE; // TRUE;
[2]2342 }
[551]2343 memset(&cnri, 0, sizeof(CNRINFO));
2344 cnri.cb = sizeof(CNRINFO);
2345 WinSendDlgItemMsg(hwnd, COMP_LEFTDIR, CM_QUERYCNRINFO,
2346 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
2347 cnri.flWindowAttr |= (CA_OWNERDRAW | CV_MINI);
2348 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 68;
2349 WinSendDlgItemMsg(hwnd, COMP_LEFTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
2350 MPFROMLONG(CMA_FLWINDOWATTR | CMA_XVERTSPLITBAR));
2351 memset(&cnri, 0, sizeof(CNRINFO));
2352 cnri.cb = sizeof(CNRINFO);
2353 WinSendDlgItemMsg(hwnd, COMP_RIGHTDIR, CM_QUERYCNRINFO,
2354 MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
2355 cnri.flWindowAttr |= (CA_OWNERDRAW | CV_MINI);
2356 cnri.xVertSplitbar = DIR_SPLITBAR_OFFSET - 54;
2357 WinSendDlgItemMsg(hwnd, COMP_RIGHTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
2358 MPFROMLONG(CMA_FLWINDOWATTR | CMA_XVERTSPLITBAR));
2359 AdjustCnrColRO(hwndLeft, GetPString(IDS_FILENAMECOLTEXT), TRUE, FALSE);
2360 AdjustCnrColRO(hwndLeft, GetPString(IDS_LONGNAMECOLTEXT), TRUE, FALSE);
2361 AdjustCnrColRO(hwndRight, GetPString(IDS_FILENAMECOLTEXT), TRUE, FALSE);
2362 AdjustCnrColRO(hwndRight, GetPString(IDS_LONGNAMECOLTEXT), TRUE, FALSE);
[1065]2363 AdjustCnrColsForPref(hwndLeft, cmp->leftdir, &cmp->dcd.ds, TRUE);
2364 tempsubj = cmp->dcd.ds.detailssubject;
2365 cmp->dcd.ds.detailssubject = FALSE;
2366 AdjustCnrColsForPref(hwndRight, cmp->rightdir, &cmp->dcd.ds, TRUE);
[551]2367 if (*cmp->rightlist) {
2368 AdjustCnrColVis(hwndRight, GetPString(IDS_LADATECOLTEXT), FALSE,
2369 FALSE);
2370 AdjustCnrColVis(hwndRight, GetPString(IDS_LATIMECOLTEXT), FALSE,
2371 FALSE);
2372 AdjustCnrColVis(hwndRight, GetPString(IDS_CRDATECOLTEXT), FALSE,
2373 FALSE);
2374 AdjustCnrColVis(hwndRight, GetPString(IDS_CRTIMECOLTEXT), FALSE,
2375 FALSE);
2376 }
[1065]2377 cmp->dcd.ds.detailssubject = tempsubj;
[551]2378 }
2379 return 0;
[2]2380
[551]2381 case WM_DRAWITEM:
2382 if (mp2) {
[748]2383 POWNERITEM pown = (POWNERITEM)mp2;
[551]2384 PCNRDRAWITEMINFO pcown;
2385 PCNRITEM pci;
[2]2386
[748]2387 pcown = (PCNRDRAWITEMINFO)pown->hItem;
[551]2388 if (pcown) {
[919]2389 pci = (PCNRITEM)pcown->pRecord;
[748]2390 // 01 Aug 07 SHL if field null or blank, we draw
[929]2391 // fixme to document why - probably to optimize and bypass draw?
[748]2392 if (pci && (INT)pci != -1 && !*pci->pszFileName)
[551]2393 return MRFROMLONG(TRUE);
[2]2394 }
[551]2395 }
2396 return 0;
[2]2397
[551]2398 case UM_CONTAINERHWND:
[907]2399 // Building list
[551]2400 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPHOLDBLDLISTTEXT));
2401 return 0;
[2]2402
[551]2403 case UM_CONTAINERDIR:
[907]2404 // Filling container
[551]2405 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPHOLDFILLCNRTEXT));
2406 return 0;
[2]2407
[907]2408 case WM_TIMER:
2409 // Show current totals
2410 cmp = INSTDATA(hwnd);
2411 if (!cmp) {
2412 Runtime_Error(pszSrcFile, __LINE__, "pCompare NULL");
2413 WinDismissDlg(hwnd, 0);
2414 }
2415 else {
[929]2416 if (cmp->uOldTotalLeft != cmp->totalleft) {
2417 cmp->uOldTotalLeft = cmp->totalleft;
2418 sprintf(s, " %d", cmp->totalleft);
2419 WinSetDlgItemText(hwnd, COMP_TOTALLEFT, s);
2420 }
2421 if (cmp->uOldTotalRight != cmp->totalright) {
2422 cmp->uOldTotalRight = cmp->totalright;
2423 sprintf(s, " %d", cmp->totalright);
2424 WinSetDlgItemText(hwnd, COMP_TOTALRIGHT, s);
2425 }
2426 if (cmp->uOldSelLeft != cmp->selleft) {
2427 cmp->uOldSelLeft = cmp->selleft;
2428 sprintf(s, " %d", cmp->selleft);
2429 WinSetDlgItemText(hwnd, COMP_SELLEFT, s);
2430 }
2431 if (cmp->uOldSelRight != cmp->selright) {
2432 cmp->uOldSelRight = cmp->selright;
2433 sprintf(s, " %d", cmp->selright);
2434 WinSetDlgItemText(hwnd, COMP_SELRIGHT, s);
2435 }
[907]2436 }
2437 break;
2438
[551]2439 case UM_CONTAINER_FILLED:
2440 cmp = INSTDATA(hwnd);
2441 if (!cmp) {
2442 Runtime_Error(pszSrcFile, __LINE__, "pCompare NULL");
2443 WinDismissDlg(hwnd, 0);
2444 }
2445 else {
2446 cmp->filling = FALSE;
2447 WinEnableWindow(hwndLeft, TRUE);
2448 WinEnableWindow(hwndRight, TRUE);
2449 WinEnableWindowUpdate(hwndLeft, TRUE);
2450 WinEnableWindowUpdate(hwndRight, TRUE);
[929]2451 WinPostMsg(hwnd, WM_TIMER, MPFROMLONG(ID_TIMER), 0); // Force update
2452 // 12 Jan 08 SHL fixme to have SetButtonEnables(COMPARE* pcmp, BOOL fEnable)
[919]2453 // to replace duplicated code here and elsewhere
[551]2454 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), TRUE);
2455 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), TRUE);
2456 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), TRUE);
2457 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), TRUE);
2458 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), TRUE);
2459 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), TRUE);
2460 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), TRUE);
2461 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), TRUE);
2462 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), TRUE);
2463 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), TRUE);
2464 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), TRUE);
2465 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), TRUE);
2466 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), TRUE);
2467 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), TRUE);
2468 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER), TRUE);
2469 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), TRUE);
2470 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT), TRUE);
2471 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL), TRUE);
2472 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), TRUE);
2473 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), TRUE);
2474 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), TRUE);
2475 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), TRUE);
2476 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), TRUE);
2477 if (!*cmp->rightlist) {
2478 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), TRUE);
2479 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), TRUE);
2480 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), TRUE);
2481 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), TRUE);
2482 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), TRUE);
[362]2483 }
[551]2484 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS), TRUE);
[919]2485 WinEnableWindow(WinWindowFromID(hwnd, COMP_HIDENOTSELECTED), TRUE);
2486 if (*cmp->dcd.mask.szMask) {
2487 sprintf(s,
2488 GetPString(IDS_COMPREADYFILTEREDTEXT),
2489 cmp->dcd.mask.szMask);
2490 WinSetDlgItemText(hwnd, COMP_NOTE, s);
2491 }
[551]2492 else
2493 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
2494 }
2495 break;
2496
2497 case WM_INITMENU:
2498 cmp = INSTDATA(hwnd);
2499 if (cmp) {
2500 switch (SHORT1FROMMP(mp1)) {
2501 case IDM_COMMANDSMENU:
2502 SetupCommandMenu(cmp->dcd.hwndLastMenu, hwnd);
2503 break;
[2]2504 }
[551]2505 }
2506 break;
[2]2507
[551]2508 case WM_MENUEND:
2509 cmp = INSTDATA(hwnd);
2510 if (cmp) {
[919]2511 if ((HWND)mp2 == cmp->dcd.hwndLastMenu) {
[551]2512 MarkAll(hwndLeft, TRUE, FALSE, TRUE);
2513 MarkAll(hwndRight, TRUE, FALSE, TRUE);
2514 WinDestroyWindow(cmp->dcd.hwndLastMenu);
[919]2515 cmp->dcd.hwndLastMenu = (HWND)0;
[2]2516 }
[551]2517 }
2518 break;
[2]2519
[551]2520 case WM_CONTROL:
2521 switch (SHORT1FROMMP(mp1)) {
2522 case COMP_INCLUDESUBDIRS:
2523 switch (SHORT2FROMMP(mp1)) {
2524 case BN_CLICKED:
2525 cmp = INSTDATA(hwnd);
2526 if (cmp)
2527 *cmp->rightlist = 0;
2528 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
2529 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
2530 break;
[2]2531 }
2532 break;
[551]2533 case COMP_HIDENOTSELECTED:
2534 switch (SHORT2FROMMP(mp1)) {
2535 case BN_CLICKED:
2536 WinSendMsg(hwnd, UM_HIDENOTSELECTED, MPVOID, MPVOID);
2537 break;
2538 }
2539 break;
[2]2540
[551]2541 case COMP_LEFTDIR:
2542 case COMP_RIGHTDIR:
2543 switch (SHORT2FROMMP(mp1)) {
2544 case CN_KILLFOCUS:
2545 PaintRecessedWindow(WinWindowFromID(hwnd, SHORT1FROMMP(mp1)),
[919]2546 (HPS)0, FALSE, TRUE);
[551]2547 break;
[2]2548
[551]2549 case CN_SETFOCUS:
2550 PaintRecessedWindow(WinWindowFromID(hwnd, SHORT1FROMMP(mp1)),
[919]2551 (HPS)0, TRUE, TRUE);
[551]2552 break;
[2]2553
[551]2554 case CN_ENTER:
2555 if (mp2) {
[2]2556
[919]2557 PCNRITEM pci = (PCNRITEM)((PNOTIFYRECORDENTER)mp2)->pRecord;
[551]2558 HWND hwndCnr = WinWindowFromID(hwnd, SHORT1FROMMP(mp1));
[2]2559
[551]2560 SetShiftState();
2561 if (pci) {
[748]2562 if (pci->rc.flRecordAttr & CRA_INUSE || !pci || !*pci->pszFileName)
[551]2563 break;
2564 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
2565 MPFROM2SHORT(TRUE, CRA_INUSE));
2566 if (pci->attrFile & FILE_DIRECTORY) {
2567 if ((shiftstate & (KC_CTRL | KC_SHIFT)) == (KC_CTRL | KC_SHIFT))
[730]2568 OpenObject(pci->pszFileName, Settings, hwnd);
[551]2569 else
[730]2570 OpenObject(pci->pszFileName, Default, hwnd);
[551]2571 }
2572 else
2573 DefaultViewKeys(hwnd, hwnd, HWND_DESKTOP, NULL,
[730]2574 pci->pszFileName);
[551]2575 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS,
2576 MPFROMP(pci),
[919]2577 MPFROM2SHORT(FALSE,
2578 CRA_INUSE | (fUnHilite ? CRA_SELECTED : 0)));
[551]2579 }
2580 }
2581 break;
[2]2582
[551]2583 case CN_CONTEXTMENU:
2584 cmp = INSTDATA(hwnd);
2585 if (cmp) {
[919]2586 PCNRITEM pci = (PCNRITEM)mp2;
[551]2587 USHORT id = COMP_CNRMENU;
[2]2588
[551]2589 if (cmp->dcd.hwndLastMenu)
2590 WinDestroyWindow(cmp->dcd.hwndLastMenu);
[919]2591 cmp->dcd.hwndLastMenu = (HWND)0;
[551]2592 cmp->hwndCalling = WinWindowFromID(hwnd, SHORT1FROMMP(mp1));
2593 if (pci) {
[748]2594 if (!pci || !*pci->pszFileName || *cmp->rightlist)
[551]2595 break;
2596 id = COMP_MENU;
2597 WinSendMsg(cmp->hwndCalling, CM_SETRECORDEMPHASIS,
2598 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
2599 }
2600 cmp->dcd.hwndLastMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, id);
2601 if (cmp->dcd.hwndLastMenu) {
2602 if (id == COMP_CNRMENU) {
2603 if (SHORT1FROMMP(mp1) == COMP_RIGHTDIR)
2604 WinSendMsg(cmp->dcd.hwndLastMenu, MM_DELETEITEM,
2605 MPFROM2SHORT(IDM_SHOWSUBJECT, FALSE), MPVOID);
[1065]2606 SetDetailsSwitches(cmp->dcd.hwndLastMenu, &cmp->dcd.ds);
[551]2607 if (SHORT1FROMMP(mp1) == COMP_LEFTDIR)
2608 WinSendMsg(cmp->dcd.hwndLastMenu, MM_DELETEITEM,
2609 MPFROM2SHORT(IDM_LOADLISTFILE, 0), MPVOID);
2610 else if (*cmp->rightlist)
2611 WinSendMsg(cmp->dcd.hwndLastMenu, MM_DELETEITEM,
2612 MPFROM2SHORT(IDM_SAVELISTFILE, 0), MPVOID);
2613 }
2614 PopupMenu(hwnd, hwnd, cmp->dcd.hwndLastMenu);
2615 }
2616 }
2617 break;
[2]2618
[551]2619 case CN_INITDRAG:
2620 cmp = INSTDATA(hwnd);
2621 if (*cmp->rightlist && SHORT1FROMMP(mp1) == COMP_RIGHTDIR)
2622 break;
2623 DoFileDrag(WinWindowFromID(hwnd, SHORT1FROMMP(mp1)),
[919]2624 (HWND)0, mp2, NULL, NULL, TRUE);
[551]2625 break;
[2]2626
[551]2627 case CN_BEGINEDIT:
2628 case CN_REALLOCPSZ:
[929]2629 // fixme to be gone - field edits not allowed?
[551]2630 Runtime_Error(pszSrcFile, __LINE__,
2631 "CN_BEGINEDIT/CN_REALLOCPSZ unexpected");
2632 break;
[2]2633
[551]2634 case CN_EMPHASIS:
2635 {
[919]2636 PNOTIFYRECORDEMPHASIS pnre = mp2;
[929]2637 BOOL fSelected;
[919]2638 if (pnre->fEmphasisMask & CRA_SELECTED) {
[929]2639 // Select toggled
[919]2640 PCNRITEM pci = (PCNRITEM)pnre->pRecord;
[551]2641 if (pci) {
[919]2642 if (!*pci->pszFileName) {
[929]2643 // Slot empty
2644 // 17 Jan 08 SHL fixme to know how can get here
[919]2645 // 12 Jan 08 SHL fixme to know if select counts need update?
[551]2646 if (pci->rc.flRecordAttr & CRA_SELECTED)
2647 WinSendDlgItemMsg(hwnd, SHORT1FROMMP(mp1),
2648 CM_SETRECORDEMPHASIS,
2649 MPFROMP(pci),
2650 MPFROM2SHORT(FALSE, CRA_SELECTED));
2651 }
2652 else {
[929]2653 BOOL fUpdateHideButton = FALSE;
[551]2654 cmp = INSTDATA(hwnd);
[919]2655 if (SHORT1FROMMP(mp1) == COMP_LEFTDIR) {
[929]2656 fSelected = pci->rc.flRecordAttr & CRA_SELECTED;
2657 cmp->selleft += fSelected ? 1 : -1;
2658 if (!fSelected)
2659 fUpdateHideButton = TRUE;
[551]2660 }
[919]2661 else if (SHORT1FROMMP(mp1) == COMP_RIGHTDIR) {
[929]2662 fSelected = pci->rc.flRecordAttr & CRA_SELECTED;
2663 cmp->selright += fSelected ? 1 : -1;
2664 if (!fSelected)
2665 fUpdateHideButton = TRUE;
[551]2666 }
[919]2667 else {
2668 Runtime_Error(pszSrcFile, __LINE__,
2669 "mp1 %u unexpected", SHORT1FROMMP(mp1));
2670 }
[929]2671 if (fUpdateHideButton) {
[1029]2672 ULONG state = WinQueryButtonCheckstate(hwnd,COMP_HIDENOTSELECTED);
[929]2673 if (state == 1) {
2674 WinCheckButton(hwnd, COMP_HIDENOTSELECTED, 2);
2675 }
2676 }
[551]2677 }
2678 }
2679 }
2680 }
2681 break;
[2]2682
[551]2683 case CN_SCROLL:
2684 cmp = INSTDATA(hwnd);
2685 if (!cmp->forcescroll) {
[2]2686
[551]2687 PNOTIFYSCROLL pns = mp2;
[2]2688
[551]2689 if (pns->fScroll & CMA_VERTICAL) {
2690 cmp->forcescroll = TRUE;
[919]2691 // Scroll other window to match
2692 WinSendDlgItemMsg(hwnd,
2693 SHORT1FROMMP(mp1) == COMP_LEFTDIR ?
2694 COMP_RIGHTDIR : COMP_LEFTDIR,
2695 CM_SCROLLWINDOW,
2696 MPFROMSHORT(CMA_VERTICAL),
[551]2697 MPFROMLONG(pns->lScrollInc));
2698 cmp->forcescroll = FALSE;
2699 }
2700 }
2701 break;
[919]2702 } // switch COMP_LEFTDIR mp1
2703 break; // COMP_LEFTDIR / COMP_RIGHTDIR
2704 } // switch WM_CONTROL mp1
[551]2705 return 0; // WM_CONTROL
[2]2706
[551]2707 case UM_SETDIR:
2708 cmp = INSTDATA(hwnd);
2709 if (cmp) {
2710 COMPARE *forthread;
2711 CNRINFO cnri;
2712 cmp->includesubdirs = WinQueryButtonCheckstate(hwnd,
2713 COMP_INCLUDESUBDIRS);
2714 memset(&cnri, 0, sizeof(CNRINFO));
2715 cnri.cb = sizeof(CNRINFO);
2716 cnri.pszCnrTitle = cmp->leftdir;
2717 cnri.flWindowAttr = CV_DETAIL | CV_MINI |
[751]2718 CA_CONTAINERTITLE | CA_TITLESEPARATOR |
2719 CA_DETAILSVIEWTITLES | CA_OWNERDRAW;
[551]2720 WinSendDlgItemMsg(hwnd, COMP_LEFTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
2721 MPFROMLONG(CMA_CNRTITLE | CMA_FLWINDOWATTR));
2722 cnri.pszCnrTitle = cmp->rightdir;
2723 WinSendDlgItemMsg(hwnd, COMP_RIGHTDIR, CM_SETCNRINFO, MPFROMP(&cnri),
2724 MPFROMLONG(CMA_CNRTITLE | CMA_FLWINDOWATTR));
2725 WinCheckButton(hwnd, COMP_HIDENOTSELECTED, 0);
2726 cmp->filling = TRUE;
[1063]2727# ifdef FORTIFY
2728 Fortify_EnterScope();
2729# endif
[551]2730 forthread = xmalloc(sizeof(COMPARE), pszSrcFile, __LINE__);
2731 if (!forthread)
2732 WinDismissDlg(hwnd, 0);
2733 else {
2734 *forthread = *cmp;
2735 forthread->cmp = cmp;
[1335]2736 if (xbeginthread(FillCnrsThread,
2737 122880,
2738 forthread,
2739 pszSrcFile,
2740 __LINE__) == -1)
2741 {
[551]2742 WinDismissDlg(hwnd, 0);
[1175]2743 free(forthread);
2744# ifdef FORTIFY
2745 Fortify_LeaveScope();
2746# endif
[551]2747 }
[362]2748 else {
[551]2749 WinEnableWindowUpdate(hwndLeft, FALSE);
2750 WinEnableWindowUpdate(hwndRight, FALSE);
2751 cmp->selleft = cmp->selright = 0;
2752 WinSetDlgItemText(hwnd, COMP_NOTE,
2753 GetPString(IDS_COMPHOLDREADDISKTEXT));
2754 WinEnableWindow(hwndRight, FALSE);
2755 WinEnableWindow(hwndLeft, FALSE);
2756 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
2757 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
2758 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), FALSE);
2759 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), FALSE);
2760 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), FALSE);
2761 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), FALSE);
2762 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), FALSE);
2763 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), FALSE);
2764 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), FALSE);
2765 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), FALSE);
2766 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), FALSE);
2767 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), FALSE);
2768 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), FALSE);
2769 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), FALSE);
2770 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER), FALSE);
2771 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), FALSE);
2772 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), FALSE);
2773 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), FALSE);
2774 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), FALSE);
2775 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), FALSE);
2776 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), FALSE);
2777 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), FALSE);
2778 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), FALSE);
[919]2779 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT), FALSE);
[551]2780 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL), FALSE);
2781 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), FALSE);
2782 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), FALSE);
2783 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), FALSE);
[919]2784 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS), FALSE);
2785 WinEnableWindow(WinWindowFromID(hwnd, COMP_HIDENOTSELECTED), FALSE);
[551]2786 }
[2]2787 }
[551]2788 }
2789 return 0;
[2]2790
[551]2791 case UM_FILTER:
2792 cmp = INSTDATA(hwnd);
2793 if (cmp) {
2794 if (mp1) {
[1304]2795 //DosEnterCritSec(); // GKY 11-30-08 moved to SetMask
[919]2796 SetMask((CHAR *)mp1, &cmp->dcd.mask);
[1304]2797 //DosExitCritSec();
[2]2798 }
[919]2799 WinSetDlgItemText(hwnd, COMP_NOTE,
2800 GetPString(IDS_COMPHOLDFILTERINGTEXT));
[1175]2801 // cmp->dcd.suspendview = 1; // 12 Jan 08 SHL appears not to be used here
[919]2802 priority_idle(); // Don't hog resources
[551]2803 WinSendMsg(hwndLeft, CM_FILTER, MPFROMP(Filter),
2804 MPFROMP(&cmp->dcd.mask));
2805 WinSendMsg(hwndRight, CM_FILTER, MPFROMP(Filter),
2806 MPFROMP(&cmp->dcd.mask));
[919]2807 priority_normal();
[1175]2808 // cmp->dcd.suspendview = 0; // 12 Jan 08 SHL appears not to be used here
[919]2809 if (*cmp->dcd.mask.szMask) {
2810 sprintf(s,
2811 GetPString(IDS_COMPREADYFILTEREDTEXT),
2812 cmp->dcd.mask.szMask);
2813 WinSetDlgItemText(hwnd, COMP_NOTE, s);
2814 }
[551]2815 else
2816 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
2817 }
2818 return 0;
[2]2819
[551]2820 case UM_HIDENOTSELECTED:
2821 cmp = INSTDATA(hwnd);
2822 if (cmp) {
[1029]2823 ULONG wasHidden = WinQueryButtonCheckstate(hwnd,
[929]2824 COMP_HIDENOTSELECTED);
[316]2825
[1175]2826 // cmp->dcd.suspendview = 1; // 12 Jan 08 SHL appears not to be used here
[929]2827 if (wasHidden != 1) {
2828 // Hide if not selected on both sides
[551]2829 BOOL needRefresh = FALSE;
2830 HWND hwndl = WinWindowFromID(cmp->hwnd, COMP_LEFTDIR);
2831 HWND hwndr = WinWindowFromID(cmp->hwnd, COMP_RIGHTDIR);
2832 PCNRITEM pcil = WinSendMsg(hwndl, CM_QUERYRECORD, MPVOID,
2833 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
2834 PCNRITEM pcir = WinSendMsg(hwndr, CM_QUERYRECORD, MPVOID,
2835 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
2836
[919]2837 while (pcil && (INT)pcil != -1 && pcir && (INT)pcir != -1) {
[551]2838 if (~pcil->rc.flRecordAttr & CRA_SELECTED &&
2839 ~pcir->rc.flRecordAttr & CRA_SELECTED) {
[929]2840 // 17 Jan 08 SHL fixme to optimize refresh
[551]2841 pcil->rc.flRecordAttr |= CRA_FILTERED;
2842 pcir->rc.flRecordAttr |= CRA_FILTERED;
2843 needRefresh = TRUE;
[316]2844 }
[551]2845 pcil = WinSendMsg(hwndl, CM_QUERYRECORD, MPFROMP(pcil),
2846 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
2847 pcir = WinSendMsg(hwndr, CM_QUERYRECORD, MPFROMP(pcir),
2848 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[748]2849 } // while
[551]2850 if (needRefresh) {
2851 WinSendMsg(hwndl, CM_INVALIDATERECORD,
2852 MPVOID, MPFROM2SHORT(0, CMA_REPOSITION));
2853 WinSendMsg(hwndr, CM_INVALIDATERECORD,
2854 MPVOID, MPFROM2SHORT(0, CMA_REPOSITION));
[316]2855 }
2856 }
[551]2857 else {
[929]2858 // Unhide
[551]2859 WinSendMsg(hwndLeft, CM_FILTER, MPFROMP(Filter),
2860 MPFROMP(&cmp->dcd.mask));
2861 WinSendMsg(hwndRight, CM_FILTER, MPFROMP(Filter),
2862 MPFROMP(&cmp->dcd.mask));
2863 }
[1175]2864 // cmp->dcd.suspendview = 0; // 12 Jan 08 SHL appears not to be used here
[919]2865 if (*cmp->dcd.mask.szMask) {
2866 sprintf(s,
2867 GetPString(IDS_COMPREADYFILTEREDTEXT),
2868 cmp->dcd.mask.szMask);
2869 WinSetDlgItemText(hwnd, COMP_NOTE, s);
2870 }
[551]2871 else
2872 WinSetDlgItemText(hwnd, COMP_NOTE, GetPString(IDS_COMPREADYTEXT));
[929]2873 WinCheckButton(hwnd, COMP_HIDENOTSELECTED, wasHidden != 1 ? 1 : 0);
[551]2874 }
2875 return 0;
[316]2876
[551]2877 case WM_COMMAND:
2878 switch (SHORT1FROMMP(mp1)) {
2879 case IDM_COMPARE:
2880 cmp = INSTDATA(hwnd);
2881 if (cmp) {
2882 PCNRITEM pci;
2883 CHAR ofile[CCHMAXPATH];
[2]2884
[919]2885 pci = (PCNRITEM)WinSendMsg(cmp->hwndCalling,
2886 CM_QUERYRECORDEMPHASIS,
2887 MPFROMLONG(CMA_FIRST),
2888 MPFROMSHORT(CRA_CURSORED));
[748]2889 // 01 Aug 07 SHL
2890 if (pci && *pci->pszFileName) {
[551]2891 if (cmp->hwndCalling == hwndLeft)
2892 strcpy(ofile, cmp->rightdir);
2893 else
2894 strcpy(ofile, cmp->leftdir);
2895 if (ofile[strlen(ofile) - 1] != '\\')
2896 strcat(ofile, "\\");
[751]2897 strcat(ofile, pci->pszDisplayName);
[551]2898 if (*compare) {
2899 CHAR *fakelist[3];
[730]2900 fakelist[0] = pci->pszFileName;
[551]2901 fakelist[1] = ofile;
2902 fakelist[2] = NULL;
2903 ExecOnList(hwnd, compare,
[907]2904 WINDOWED | SEPARATEKEEP, NULL, fakelist, NULL,
2905 pszSrcFile, __LINE__);
[551]2906 }
2907 else {
2908 FCOMPARE fc;
2909 memset(&fc, 0, sizeof(fc));
2910 fc.size = sizeof(fc);
2911 fc.hwndParent = hwnd;
[730]2912 strcpy(fc.file1, pci->pszFileName);
[551]2913 strcpy(fc.file2, ofile);
2914 WinDlgBox(HWND_DESKTOP, hwnd,
[919]2915 CFileDlgProc, FM3ModHandle, FCMP_FRAME, (PVOID)&fc);
[551]2916 }
2917 }
2918 }
2919 break;
[2]2920
[551]2921 case COMP_FILTER:
2922 case IDM_FILTER:
2923 cmp = INSTDATA(hwnd);
2924 if (cmp) {
2925 BOOL empty = FALSE;
2926 PCNRITEM pci;
2927 CHAR *p;
2928 BOOL temp;
[2]2929
[551]2930 if (!*cmp->dcd.mask.szMask) {
2931 empty = TRUE;
2932 temp = fSelectedAlways;
2933 fSelectedAlways = TRUE;
[748]2934 pci = (PCNRITEM)CurrentRecord(hwnd);
[551]2935 fSelectedAlways = temp;
[748]2936 // 01 Aug 07 SHL
2937 if (pci && ~pci->attrFile & FILE_DIRECTORY) {
[730]2938 p = strrchr(pci->pszFileName, '\\');
[551]2939 if (p) {
2940 p++;
2941 strcpy(cmp->dcd.mask.szMask, p);
2942 }
2943 }
2944 }
2945 cmp->dcd.mask.fNoAttribs = TRUE;
2946 cmp->dcd.mask.attrFile = ALLATTRS;
2947 cmp->dcd.mask.antiattr = 0;
2948 if (WinDlgBox(HWND_DESKTOP, hwnd, PickMaskDlgProc,
2949 FM3ModHandle, MSK_FRAME, MPFROMP(&cmp->dcd.mask))) {
2950 cmp->dcd.mask.attrFile = ALLATTRS;
2951 cmp->dcd.mask.antiattr = 0;
2952 WinSendMsg(hwnd, UM_FILTER, MPVOID, MPVOID);
2953 }
2954 else if (empty) {
2955 *cmp->dcd.mask.szMask = 0;
2956 cmp->dcd.mask.attrFile = ALLATTRS;
2957 cmp->dcd.mask.antiattr = 0;
2958 }
2959 }
2960 break;
[2]2961
[551]2962 case IDM_SHOWSUBJECT:
2963 case IDM_SHOWEAS:
2964 case IDM_SHOWSIZE:
2965 case IDM_SHOWLWDATE:
2966 case IDM_SHOWLWTIME:
2967 case IDM_SHOWLADATE:
2968 case IDM_SHOWLATIME:
2969 case IDM_SHOWCRDATE:
2970 case IDM_SHOWCRTIME:
2971 case IDM_SHOWATTR:
2972 cmp = INSTDATA(hwnd);
2973 if (cmp) {
2974 DIRCNRDATA dcd1;
2975 BOOL tempsubj;
[2]2976
[551]2977 dcd1 = cmp->dcd;
2978 AdjustDetailsSwitches(hwndLeft,
[919]2979 (HWND)0, SHORT1FROMMP(mp1),
[1065]2980 cmp->leftdir, "DirCmp", &cmp->dcd.ds, TRUE);
2981 tempsubj = cmp->dcd.ds.detailssubject;
[551]2982 cmp->dcd = dcd1;
[1065]2983 cmp->dcd.ds.detailssubject = FALSE;
[551]2984 AdjustDetailsSwitches(hwndRight,
2985 cmp->dcd.hwndLastMenu, SHORT1FROMMP(mp1),
[1065]2986 cmp->rightdir, "DirCmp", &cmp->dcd.ds, TRUE);
2987 cmp->dcd.ds.detailssubject = tempsubj;
[551]2988 }
2989 break;
[2]2990
[551]2991 case IDM_LOADLISTFILE:
2992 cmp = INSTDATA(hwnd);
2993 if (cmp) {
2994 CHAR fullname[CCHMAXPATH];
[2]2995
[551]2996 strcpy(fullname, "*.PMD");
2997 if (insert_filename(HWND_DESKTOP, fullname, TRUE, FALSE) &&
2998 *fullname && !strchr(fullname, '*') && !strchr(fullname, '?')) {
2999 strcpy(cmp->rightlist, fullname);
3000 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
3001 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
3002 }
3003 }
3004 break;
[2]3005
[551]3006 case IDM_SAVELISTFILE:
3007 cmp = INSTDATA(hwnd);
3008 if (cmp) {
3009 SNAPSTUFF *sf;
3010 CHAR fullname[CCHMAXPATH];
[2]3011
[551]3012 strcpy(fullname, "*.PMD");
3013 if (export_filename(HWND_DESKTOP, fullname, 1) && *fullname &&
3014 !strchr(fullname, '*') && !strchr(fullname, '?')) {
3015 sf = xmallocz(sizeof(SNAPSTUFF), pszSrcFile, __LINE__);
3016 if (sf) {
3017 strcpy(sf->filename, fullname);
3018 if (hwndLeft == cmp->hwndCalling)
3019 strcpy(sf->dirname, cmp->leftdir);
3020 else
3021 strcpy(sf->dirname, cmp->rightdir);
3022 sf->recurse = cmp->includesubdirs;
[1335]3023 if (xbeginthread(StartSnap,
3024 65536,
3025 sf,
3026 pszSrcFile,
3027 __LINE__) == -1)
3028 {
[1039]3029 free(sf);
[551]3030 }
3031 }
3032 }
3033 }
3034 break;
[2]3035
[551]3036 case COMP_SETDIRS:
3037 cmp = INSTDATA(hwnd);
3038 if (cmp) {
3039 WALK2 wa;
3040 memset(&wa, 0, sizeof(wa));
3041 wa.size = sizeof(wa);
3042 strcpy(wa.szCurrentPath1, cmp->leftdir);
3043 strcpy(wa.szCurrentPath2, cmp->rightdir);
[919]3044 if (WinDlgBox(HWND_DESKTOP,
3045 hwnd,
3046 WalkTwoCmpDlgProc,
3047 FM3ModHandle,
3048 WALK2_FRAME,
[551]3049 MPFROMP(&wa)) &&
[769]3050 !IsFile(wa.szCurrentPath1) &&
3051 !IsFile(wa.szCurrentPath2)) {
[551]3052 strcpy(cmp->leftdir, wa.szCurrentPath1);
3053 strcpy(cmp->rightdir, wa.szCurrentPath2);
3054 *cmp->rightlist = 0;
3055 PostMsg(hwnd, UM_SETUP, MPVOID, MPVOID);
3056 PostMsg(hwnd, UM_SETDIR, MPVOID, MPVOID);
3057 }
3058 }
3059 break;
[2]3060
[551]3061 case COMP_COPYLEFT:
3062 case COMP_MOVELEFT:
3063 case COMP_COPYRIGHT:
3064 case COMP_MOVERIGHT:
3065 case COMP_DELETELEFT:
3066 case COMP_DELETERIGHT:
3067 cmp = INSTDATA(hwnd);
3068 if (cmp) {
3069 COMPARE *forthread;
[2]3070
[551]3071 cmp->filling = TRUE;
3072 forthread = xmalloc(sizeof(COMPARE), pszSrcFile, __LINE__);
3073 if (forthread) {
3074 *forthread = *cmp;
3075 forthread->cmp = cmp;
3076 forthread->action = SHORT1FROMMP(mp1);
[1335]3077 if (xbeginthread(ActionCnrThread,
3078 122880,
3079 forthread,
3080 pszSrcFile,
3081 __LINE__) == -1)
3082 {
[1039]3083 free(forthread);
[551]3084 }
3085 else {
3086 WinEnableWindowUpdate(hwndLeft, FALSE);
3087 WinEnableWindowUpdate(hwndRight, FALSE);
3088 switch (SHORT1FROMMP(mp1)) {
3089 case COMP_DELETELEFT:
3090 case COMP_DELETERIGHT:
3091 WinSetDlgItemText(hwnd, COMP_NOTE,
3092 GetPString(IDS_COMPHOLDDELETINGTEXT));
3093 break;
3094 case COMP_MOVELEFT:
3095 case COMP_MOVERIGHT:
3096 WinSetDlgItemText(hwnd, COMP_NOTE,
3097 GetPString(IDS_COMPHOLDMOVINGTEXT));
3098 break;
3099 case COMP_COPYLEFT:
3100 case COMP_COPYRIGHT:
3101 WinSetDlgItemText(hwnd, COMP_NOTE,
3102 GetPString(IDS_COMPHOLDCOPYINGTEXT));
3103 break;
3104 default:
[919]3105 Runtime_Error(pszSrcFile, __LINE__, "mp1 %u unexpected", SHORT1FROMMP(mp1));
[551]3106 }
3107 WinEnableWindow(hwndRight, FALSE);
3108 WinEnableWindow(hwndLeft, FALSE);
3109 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
3110 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
3111 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), FALSE);
3112 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), FALSE);
3113 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), FALSE);
3114 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), FALSE);
3115 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), FALSE);
3116 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), FALSE);
3117 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), FALSE);
3118 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), FALSE);
3119 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), FALSE);
3120 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), FALSE);
3121 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), FALSE);
3122 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), FALSE);
[919]3123 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER), FALSE);
[551]3124 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), FALSE);
3125 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), FALSE);
3126 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), FALSE);
3127 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), FALSE);
3128 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), FALSE);
3129 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), FALSE);
3130 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), FALSE);
3131 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), FALSE);
[919]3132 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT), FALSE);
3133 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL), FALSE);
[551]3134 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), FALSE);
3135 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), FALSE);
3136 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), FALSE);
[919]3137 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS), FALSE);
3138 WinEnableWindow(WinWindowFromID(hwnd, COMP_HIDENOTSELECTED), FALSE);
[551]3139 }
3140 }
3141 }
3142 break;
[2]3143
[551]3144 case DID_OK:
[938]3145 {
[1175]3146 SWP swp;
3147 ULONG size = sizeof(SWP);
[938]3148
[1175]3149 WinQueryWindowPos(hwnd, &swp);
3150 PrfWriteProfileData(fmprof, FM3Str, "CompDir.Position", (PVOID) &swp,
3151 size);
[938]3152 }
[551]3153 WinDismissDlg(hwnd, 0);
3154 break;
3155 case DID_CANCEL:
[938]3156 {
[1175]3157 SWP swp;
3158 ULONG size = sizeof(SWP);
[938]3159
[1175]3160 WinQueryWindowPos(hwnd, &swp);
3161 PrfWriteProfileData(fmprof, FM3Str, "CompDir.Position", (PVOID) &swp,
3162 size);
[938]3163 }
[551]3164 WinDismissDlg(hwnd, 1);
3165 break;
[2]3166
[551]3167 case IDM_HELP:
3168 if (hwndHelp)
3169 WinSendMsg(hwndHelp, HM_DISPLAY_HELP,
3170 MPFROM2SHORT(HELP_COMPARE, 0), MPFROMSHORT(HM_RESOURCEID));
3171 break;
[2]3172
[551]3173 case IDM_DESELECTALL:
3174 case IDM_SELECTNEWER:
3175 case IDM_SELECTOLDER:
3176 case IDM_SELECTBIGGER:
3177 case IDM_SELECTSMALLER:
3178 case IDM_DESELECTNEWER:
3179 case IDM_DESELECTOLDER:
3180 case IDM_DESELECTBIGGER:
3181 case IDM_DESELECTSMALLER:
3182 case IDM_DESELECTONE:
3183 case IDM_DESELECTBOTH:
3184 case IDM_SELECTBOTH:
3185 case IDM_SELECTONE:
3186 case IDM_SELECTSAMECONTENT:
[748]3187 case IDM_SELECTIDENTICAL: // Name, size and time
3188 case IDM_SELECTSAME: // Name and size
[551]3189 case IDM_INVERT:
3190 cmp = INSTDATA(hwnd);
3191 if (!cmp)
3192 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
3193 else {
3194 COMPARE *forthread;
3195
3196 cmp->filling = TRUE;
3197 forthread = xmalloc(sizeof(COMPARE), pszSrcFile, __LINE__);
3198 if (forthread) {
3199 *forthread = *cmp;
3200 forthread->cmp = cmp;
3201 forthread->action = SHORT1FROMMP(mp1);
[1335]3202 if (xbeginthread(SelectCnrsThread,
3203 65536,
3204 forthread,
3205 pszSrcFile,
3206 __LINE__) == -1)
3207 {
[1039]3208 free(forthread);
[551]3209 }
[362]3210 else {
[551]3211 WinEnableWindowUpdate(hwndLeft, FALSE);
3212 WinEnableWindowUpdate(hwndRight, FALSE);
3213 switch (SHORT1FROMMP(mp1)) {
3214 case IDM_DESELECTALL:
3215 case IDM_DESELECTNEWER:
3216 case IDM_DESELECTOLDER:
3217 case IDM_DESELECTBIGGER:
3218 case IDM_DESELECTSMALLER:
3219 case IDM_DESELECTONE:
3220 case IDM_DESELECTBOTH:
3221 WinSetDlgItemText(hwnd, COMP_NOTE,
3222 GetPString(IDS_COMPHOLDDESELTEXT));
3223 break;
3224 case IDM_INVERT:
3225 WinSetDlgItemText(hwnd, COMP_NOTE,
3226 GetPString(IDS_COMPHOLDINVERTTEXT));
3227 break;
3228 default:
3229 WinSetDlgItemText(hwnd, COMP_NOTE,
3230 GetPString(IDS_COMPHOLDSELTEXT));
3231 break;
3232 }
3233 WinEnableWindow(hwndRight, FALSE);
3234 WinEnableWindow(hwndLeft, FALSE);
3235 WinEnableWindow(WinWindowFromID(hwnd, DID_OK), FALSE);
3236 WinEnableWindow(WinWindowFromID(hwnd, DID_CANCEL), FALSE);
3237 WinEnableWindow(WinWindowFromID(hwnd, COMP_COLLECT), FALSE);
3238 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBOTH), FALSE);
3239 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTONE), FALSE);
3240 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTNEWER), FALSE);
3241 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTOLDER), FALSE);
3242 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTBIGGER), FALSE);
3243 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSMALLER), FALSE);
3244 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBOTH), FALSE);
3245 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTONE), FALSE);
3246 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTNEWER), FALSE);
3247 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTOLDER), FALSE);
3248 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTBIGGER), FALSE);
[919]3249 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTSMALLER), FALSE);
[551]3250 WinEnableWindow(WinWindowFromID(hwnd, IDM_DESELECTALL), FALSE);
[919]3251 WinEnableWindow(WinWindowFromID(hwnd, COMP_INCLUDESUBDIRS), FALSE);
3252 WinEnableWindow(WinWindowFromID(hwnd, COMP_HIDENOTSELECTED), FALSE);
[551]3253 WinEnableWindow(WinWindowFromID(hwnd, COMP_SETDIRS), FALSE);
3254 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETELEFT), FALSE);
3255 WinEnableWindow(WinWindowFromID(hwnd, COMP_DELETERIGHT), FALSE);
3256 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYLEFT), FALSE);
3257 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVELEFT), FALSE);
3258 WinEnableWindow(WinWindowFromID(hwnd, COMP_COPYRIGHT), FALSE);
3259 WinEnableWindow(WinWindowFromID(hwnd, COMP_MOVERIGHT), FALSE);
[919]3260 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAMECONTENT), FALSE);
3261 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTIDENTICAL), FALSE);
[551]3262 WinEnableWindow(WinWindowFromID(hwnd, IDM_SELECTSAME), FALSE);
3263 WinEnableWindow(WinWindowFromID(hwnd, IDM_INVERT), FALSE);
3264 WinEnableWindow(WinWindowFromID(hwnd, COMP_FILTER), FALSE);
3265 }
3266 }
3267 }
3268 break;
[2]3269
[551]3270 case COMP_COLLECT:
3271 cmp = INSTDATA(hwnd);
[773]3272 if (!cmp)
3273 Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
3274 else {
3275 CHAR **listl;
3276 CHAR **listr = NULL;
[551]3277 if (!Collector) {
3278 SWP swp;
3279 HWND hwndC;
[773]3280 if (!fAutoTile &&
3281 !ParentIsDesktop(hwnd, cmp->hwndParent) &&
3282 !fExternalCollector &&
3283 !strcmp(realappname, FM3Str)) {
[551]3284 GetNextWindowPos(cmp->hwndParent, &swp, NULL, NULL);
[773]3285 }
3286 hwndC = StartCollector(fExternalCollector ||
3287 strcmp(realappname, FM3Str) ?
3288 HWND_DESKTOP :
3289 cmp->hwndParent,
3290 4);
[551]3291 if (hwndC) {
[773]3292 if (!fAutoTile &&
3293 !ParentIsDesktop(hwnd, cmp->hwndParent) &&
3294 !fExternalCollector &&
3295 !strcmp(realappname, FM3Str)) {
3296 WinSetWindowPos(hwndC, HWND_TOP,
3297 swp.x, swp.y, swp.cx, swp.cy,
3298 SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ZORDER);
3299 }
3300 else if (!ParentIsDesktop(hwnd, cmp->hwndParent) &&
3301 fAutoTile &&
3302 !strcmp(realappname, FM3Str)) {
[551]3303 TileChildren(cmp->hwndParent, TRUE);
[773]3304 }
[924]3305 DosSleep(1); // 12 Jan 08 SHL Let screen update
[551]3306 PostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(COMP_COLLECT, 0), MPVOID);
3307 break;
3308 }
3309 }
3310 else
3311 StartCollector(cmp->hwndParent, 4);
[2]3312
[773]3313 temp = fSelectedAlways;
3314 fSelectedAlways = TRUE;
3315 listl = BuildList(hwndLeft);
3316 if (!*cmp->rightlist)
3317 listr = BuildList(hwndRight);
3318 fSelectedAlways = temp;
3319
[551]3320 if (listl || listr) {
3321 if (Collector) {
[773]3322 // 07 Aug 07 SHL Avoid collected from empty list
3323 if (listl && listl[0] && *listl[0]) {
3324 if (PostMsg(Collector, WM_COMMAND,
3325 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(listl)))
3326 listl = NULL; // Collector will free
[551]3327 }
[773]3328 if (listr && listr[0] && *listr[0]) {
3329 if (PostMsg(Collector, WM_COMMAND,
3330 MPFROM2SHORT(IDM_COLLECTOR, 0), MPFROMP(listr)))
3331 listr = NULL; // Collector will free
[551]3332 }
3333 WinSetWindowPos(WinQueryWindow(WinQueryWindow(Collector,
3334 QW_PARENT),
[773]3335 QW_PARENT),
3336 HWND_TOP, 0, 0, 0, 0,
[551]3337 SWP_ACTIVATE);
3338 }
[773]3339 FreeList(listl);
3340 FreeList(listr);
[551]3341 }
[2]3342 }
[551]3343 break;
3344 }
3345 return 0;
[2]3346
[551]3347 case WM_CLOSE:
[929]3348 // 18 Jan 08 SHL fixme to hold off if thread busy?
[551]3349 WinDismissDlg(hwnd, 0);
3350 return 0;
[2]3351
[551]3352 case WM_DESTROY:
3353 cmp = INSTDATA(hwnd);
3354 if (cmp) {
[929]3355 // 17 Jan 08 SHL fixme to know if stop really needed?
3356 WinStopTimer(WinQueryAnchorBlock(hwnd), hwnd, ID_TIMER);
[551]3357 if (cmp->dcd.hwndLastMenu)
3358 WinDestroyWindow(cmp->dcd.hwndLastMenu);
3359 if (cmp->dcd.hwndObject) {
[919]3360 WinSetWindowPtr(cmp->dcd.hwndObject, QWL_USER, (PVOID)NULL);
[551]3361 if (!PostMsg(cmp->dcd.hwndObject, WM_CLOSE, MPVOID, MPVOID))
3362 WinSendMsg(cmp->dcd.hwndObject, WM_CLOSE, MPVOID, MPVOID);
[2]3363 }
[1039]3364 free(cmp);
[551]3365 }
3366 EmptyCnr(hwndLeft);
3367 EmptyCnr(hwndRight);
3368 DosPostEventSem(CompactSem);
3369 break;
[2]3370 }
[551]3371 return WinDefDlgProc(hwnd, msg, mp1, mp2);
[2]3372}
[783]3373
3374#pragma alloc_text(COMPAREDIR,FillCnrsThread,FillDirList,CompNames,BldFullPathName)
3375#pragma alloc_text(COMPAREDIR1,CompareDlgProc)
3376#pragma alloc_text(COMPAREDIR2,SelectCnrsThread,ActionCnrThread)
3377#pragma alloc_text(COMPAREFILE,CFileDlgProc,CompareFilesThread)
3378#pragma alloc_text(SNAPSHOT,SnapShot,StartSnap)
[924]3379#pragma alloc_text(COMPSELECT,CompSelect)
[783]3380
Note: See TracBrowser for help on using the repository browser.