source: trunk/dll/select.c@ 769

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

Rework compare directories select/deselect logic
Sanitize CNRITEM_EXISTS usage
Correct BldFullPathName typo

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.8 KB
RevLine 
[123]1
2/***********************************************************************
3
4 $Id: select.c 769 2007-08-06 02:24:09Z stevenhl $
5
[362]6 Container item selection support routines
7
[123]8 Copyright (c) 1993-98 M. Kimes
[672]9 Copyright (c) 2004, 2007 Steven H. Levine
[123]10
[158]11 01 Aug 04 SHL Rework lstrip/rstrip usage
12 25 May 05 SHL Rework for ULONGLONG
[204]13 06 Jun 05 SHL Drop unused code
[317]14 06 Jul 06 SHL Support compare content (IDM_SELECTSAMECONTENT)
[362]15 13 Jul 06 SHL Use Runtime_Error
[406]16 29 Jul 06 SHL Use xfgets_bstripcr
[442]17 15 Aug 06 SHL Rework SetMask args and logic
[603]18 06 Apr 07 GKY Work around PM DragInfo and DrgFreeDISH limits
[618]19 19 Apr 07 SHL Sync with NumItemsToUnhilite mods
[672]20 12 May 07 SHL Use dcd->ulItemsToUnHilite
[690]21 14 Jun 07 SHL SelectAll: make odd expression go away
[751]22 02 Aug 07 SHL Sync with CNRITEM mods
[762]23 04 Aug 07 SHL Use Runtime_Error
[769]24 05 Aug 07 SHL Rework SpecialSelect to use CNRITEM_EXISTS and
25 not use pszFileName since CNRITEM_EXISTS set implies
26 pszFileName not null
[123]27
28***********************************************************************/
29
[2]30#define INCL_DOS
31#define INCL_WIN
[158]32#define INCL_LONGLONG
33#include <os2.h>
[2]34
35#include <stdio.h>
36#include <stdlib.h>
37#include <string.h>
38#include <share.h>
[317]39#include <io.h>
[158]40
[2]41#include "fm3dll.h"
42#include "fm3str.h"
43
44#pragma alloc_text(SELECT,UnHilite,SelectAll,DeselectAll,MarkAll,SetMask)
45#pragma alloc_text(SELECT,SelectList)
46#pragma alloc_text(SELECT1,Deselect,HideAll,RemoveAll,ExpandAll,InvertAll)
47
[362]48static PSZ pszSrcFile = __FILE__;
49
[672]50VOID UnHilite(HWND hwndCnr, BOOL all, CHAR *** list, ULONG ulItemsToUnHilite)
[317]51{
[2]52 PCNRITEM pci;
[603]53 INT numfiles = 0, numalloc = 0, x = 0;
[551]54 INT attribute = CRA_CURSORED;
[2]55
[362]56 if (all && list && *list) {
[2]57 FreeList(*list);
58 *list = NULL;
59 }
[551]60 pci = (PCNRITEM) CurrentRecord(hwndCnr);
[748]61 if (pci && (INT)pci != -1) {
[362]62 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[2]63 attribute = CRA_SELECTED;
[551]64 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
65 MPFROMSHORT(attribute));
[2]66 }
[748]67 while (pci && (INT)pci != -1) {
[551]68 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
69 MPFROM2SHORT(FALSE, CRA_SELECTED));
[362]70 if (!all)
[690]71 break;
[618]72 // Count is one extra to ensure non-zero elsewhere
[672]73 // x is 0 based index
74 if (x + 2 == ulItemsToUnHilite)
[690]75 break;
[362]76 if (list)
[730]77 AddToList(pci->pszFileName, list, &numfiles, &numalloc);
[551]78 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
79 MPFROMP(pci), MPFROMSHORT(CRA_SELECTED));
[603]80 x++;
[2]81 }
82 }
83}
84
[551]85VOID SelectList(HWND hwndCnr, BOOL partial, BOOL deselect, BOOL clearfirst,
[748]86 PCNRITEM pciParent, PSZ filename, CHAR ** list)
[362]87{
[2]88
[551]89 PCNRITEM pci;
[2]90 register INT x;
[551]91 BOOL foundone = FALSE;
[766]92 ULONG errs = 0;
[2]93
[362]94 if (clearfirst && !deselect)
[672]95 UnHilite(hwndCnr, TRUE, NULL, 0);
[362]96 if (list && list[0]) {
[551]97 for (x = 0; list[x]; x++) {
[2]98 pci = FindCnrRecord(hwndCnr,
[551]99 list[x], pciParent, partial, partial, TRUE);
[362]100 if (pci) {
[551]101 WinSendMsg(hwndCnr,
102 CM_SETRECORDEMPHASIS,
103 MPFROMP(pci),
104 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
105 CRA_SELECTED));
106 foundone = TRUE;
[2]107 }
108 }
[362]109 if (!foundone)
110 Runtime_Error(pszSrcFile, __LINE__, "select failed");
[2]111 }
[362]112 else if (filename && *filename) {
[2]113
114 FILE *fp;
[551]115 CHAR input[1024], *p;
[2]116
[551]117 fp = _fsopen(filename, "r", SH_DENYNO);
[362]118 if (fp) {
119 while (!feof(fp)) {
[551]120 if (!xfgets_bstripcr(input, sizeof(input), fp, pszSrcFile, __LINE__))
121 break;
122 if (*input == '\"') {
123 memmove(input, input + 1, strlen(input) + 1);
124 lstrip(input);
125 p = strchr(input, '\"');
126 if (p)
127 *p = 0;
128 rstrip(input);
129 }
130 else {
131 p = strchr(input, ' ');
132 if (p)
133 *p = 0;
134 }
135 /* input now contains name of file to select */
136 pci = FindCnrRecord(hwndCnr,
137 input, pciParent, partial, partial, TRUE);
138 if (pci) /* found it? */
139 WinSendMsg(hwndCnr,
140 CM_SETRECORDEMPHASIS,
141 MPFROMP(pci),
142 MPFROM2SHORT((SHORT) ((deselect) ? FALSE : TRUE),
143 CRA_SELECTED));
144 else
145 errs++;
[766]146 if (errs > 50) { /* prevent runaway on bad file */
[2]147
[551]148 APIRET ret;
[2]149
[551]150 ret = saymsg(MB_YESNO,
151 hwndCnr,
152 GetPString(IDS_POSSIBLEERRORTEXT),
153 GetPString(IDS_MAYNOTBELISTTEXT), filename);
154 if (ret == MBID_NO)
155 break;
[766]156 errs = 0;
[551]157 }
[2]158 }
159 fclose(fp);
160 }
161 }
162}
163
[748]164VOID SelectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
165 PSZ text, BOOL is_arc)
[362]166{
[2]167
[551]168 PCNRITEM pci;
169 BOOL markit;
[748]170 PSZ file;
171 PSZ pszToMatch;
[551]172 MASK Mask;
[748]173 INT x;
[551]174 ULONG textlen = 0;
[2]175
[362]176 if (text)
[2]177 textlen = strlen(text);
[551]178 memset(&Mask, 0, sizeof(Mask));
[442]179 if (maskstr)
[551]180 SetMask(maskstr, &Mask);
181 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
182 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]183 while (pci && (INT)pci != -1) {
184
[2]185 markit = FALSE;
[748]186
187 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
[362]188 if (!is_arc) {
[748]189 if (files && ~pci->attrFile & FILE_DIRECTORY)
[551]190 markit = TRUE;
[748]191 if (dirs && pci->attrFile & FILE_DIRECTORY)
[551]192 markit = TRUE;
[2]193 }
194 else
[551]195 markit = TRUE;
[442]196 if (maskstr && *maskstr && markit) {
[551]197 markit = FALSE;
[748]198 // Point a filename part
[730]199 file = strrchr(pci->pszFileName, '\\');
[551]200 if (!file)
[730]201 file = strrchr(pci->pszFileName, ':');
[551]202 if (file)
203 file++;
204 else
[730]205 file = pci->pszFileName;
[551]206 for (x = 0; Mask.pszMasks[x]; x++) {
207 if (*Mask.pszMasks[x]) {
[748]208 if ((strchr(Mask.pszMasks[x], '\\') ||
209 strchr(Mask.pszMasks[x], ':')))
210 pszToMatch = pci->pszFileName;
211 else
212 pszToMatch = file;
[551]213 if (*Mask.pszMasks[x] != '/') {
[748]214 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE)) {
[551]215 markit = TRUE;
[690]216 }
[551]217 }
218 else {
[748]219 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
[551]220 markit = FALSE;
221 break;
222 }
223 }
224 }
[690]225 } // for
[2]226 }
227 }
228
[748]229 if (markit && text && *text) {
230 if (~pci->attrFile & FILE_DIRECTORY) {
231 PSZ input;
232 markit = FALSE;
233 input = xmalloc(65537, pszSrcFile, __LINE__);
234 if (input) {
235 ULONG pos;
236 LONG len;
237 FILE *inputFile;
[2]238
[748]239 if ((inputFile = _fsopen(pci->pszFileName, "rb", SH_DENYNO)) != NULL) {
240 pos = ftell(inputFile);
241 while (!feof(inputFile)) {
242 if (pos)
243 fseek(inputFile, pos - 256, SEEK_SET);
244 len = fread(input, 1, 65536, inputFile);
245 if (len >= 0) {
246 if (findstring(text, textlen, input, len, FALSE)) {
247 markit = TRUE;
248 break;
249 }
250 }
251 else
[551]252 break;
253 }
[748]254 fclose(inputFile);
[551]255 }
[748]256 free(input);
[766]257 DosSleep(1);
[551]258 }
[2]259 }
[748]260 else
261 markit = FALSE;
[2]262 }
[748]263
[362]264 if (markit)
[551]265 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
266 MPFROM2SHORT(TRUE, CRA_SELECTED));
267 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
268 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
269 } // while
[2]270}
271
[748]272VOID DeselectAll(HWND hwndCnr, BOOL files, BOOL dirs, PSZ maskstr,
273 PSZ text, BOOL is_arc)
[362]274{
[551]275 PCNRITEM pci;
276 BOOL unmarkit;
[748]277 PSZ file;
278 PSZ pszToMatch;
[551]279 MASK Mask;
280 register INT x;
281 ULONG textlen = 0;
[2]282
[362]283 if (text)
[2]284 textlen = strlen(text);
[551]285 memset(&Mask, 0, sizeof(Mask));
[442]286 if (maskstr && *maskstr)
[551]287 SetMask(maskstr, &Mask);
288 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
289 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]290 while (pci && (INT)pci != -1) {
[2]291 unmarkit = FALSE;
[748]292 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
[362]293 if (!is_arc) {
[748]294 if (files && ~pci->attrFile & FILE_DIRECTORY)
[551]295 unmarkit = TRUE;
296 if (dirs && (pci->attrFile & FILE_DIRECTORY))
297 unmarkit = TRUE;
[2]298 }
299 else
[551]300 unmarkit = TRUE;
[442]301 if (maskstr && *maskstr && unmarkit) {
[551]302 unmarkit = FALSE;
[730]303 file = strrchr(pci->pszFileName, '\\');
[551]304 if (!file)
[730]305 file = strrchr(pci->pszFileName, ':');
[551]306 if (file)
307 file++;
308 else
[730]309 file = pci->pszFileName;
[551]310 for (x = 0; Mask.pszMasks[x]; x++) {
311 if (*Mask.pszMasks[x]) {
[748]312 if (strchr(Mask.pszMasks[x], '\\') ||
313 strchr(Mask.pszMasks[x], ':'))
314 pszToMatch = pci->pszFileName;
315 else
316 pszToMatch = file;
[551]317 if (*Mask.pszMasks[x] != '/') {
[748]318 if (wildcard(pszToMatch, Mask.pszMasks[x], FALSE))
[551]319 unmarkit = TRUE;
320 }
321 else {
[748]322 if (wildcard(pszToMatch, Mask.pszMasks[x] + 1, FALSE)) {
[551]323 unmarkit = FALSE;
324 break;
325 }
326 }
327 }
328 }
[2]329 }
330 }
331
[748]332 if (unmarkit && text && *text) {
333 if (~pci->attrFile & FILE_DIRECTORY) {
334 PSZ input;
335 unmarkit = FALSE;
336 input = xmalloc(65537, pszSrcFile, __LINE__);
337 if (input) {
338 ULONG pos;
339 LONG len;
340 FILE *inputFile;
[2]341
[748]342 if ((inputFile = _fsopen(pci->pszFileName, "rb", SH_DENYNO)) != NULL) {
343 pos = ftell(inputFile);
344 while (!feof(inputFile)) {
345 if (pos)
346 fseek(inputFile, pos - 256, SEEK_SET);
347 len = fread(input, 1, 65536, inputFile);
348 if (len >= 0) {
349 if (findstring(text, textlen, input, len, FALSE)) {
350 unmarkit = TRUE;
351 break;
352 }
353 }
354 else
[551]355 break;
356 }
[748]357 fclose(inputFile);
[551]358 }
[748]359 free(input);
[766]360 DosSleep(1);
[551]361 }
[2]362 }
[748]363 else
364 unmarkit = FALSE;
[2]365 }
[748]366
[362]367 if (unmarkit)
[551]368 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, pci,
369 MPFROM2SHORT(FALSE, CRA_SELECTED | CRA_CURSORED |
370 CRA_INUSE | CRA_SOURCE));
371 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
372 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]373 }
374}
375
[551]376VOID Deselect(HWND hwndCnr)
[317]377{
[2]378 PCNRITEM pcil;
379
[551]380 pcil = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
381 MPFROMLONG(CMA_FIRST),
382 MPFROMSHORT(CRA_SELECTED));
[748]383 while (pcil && (INT)pcil != -1) {
[551]384 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pcil),
385 MPFROM2SHORT(FALSE, CRA_SELECTED));
386 pcil = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pcil),
387 MPFROMSHORT(CRA_SELECTED));
[2]388 }
389}
390
[317]391//=== HideAll() Hide all selected records ===
[2]392
[551]393VOID HideAll(HWND hwndCnr)
[317]394{
[551]395 PCNRITEM pci, pciH;
396 INT attribute = CRA_CURSORED;
397 CNRINFO cnri;
398 BOOL didone = FALSE;
[2]399
[551]400 memset(&cnri, 0, sizeof(CNRINFO));
[2]401 cnri.cb = sizeof(CNRINFO);
[551]402 WinSendMsg(hwndCnr, CM_QUERYCNRINFO, MPFROMP(&cnri),
403 MPFROMLONG(sizeof(CNRINFO)));
404 pci = (PCNRITEM) CurrentRecord(hwndCnr);
[748]405 if (pci && (INT)pci != -1) {
[362]406 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[2]407 attribute = CRA_SELECTED;
[551]408 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
409 MPFROMSHORT(attribute));
[2]410 }
411 }
[748]412 while (pci && (INT)pci != -1) {
[551]413 pciH = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
414 MPFROMSHORT(attribute));
415 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
416 MPFROM2SHORT(FALSE, CRA_CURSORED | CRA_SELECTED |
417 CRA_INUSE | CRA_SOURCE));
[2]418 pci->rc.flRecordAttr |= CRA_FILTERED;
419 didone = TRUE;
[362]420 if (fSyncUpdates) {
421 if (cnri.flWindowAttr & CV_DETAIL)
[551]422 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
423 MPFROM2SHORT(0, CMA_REPOSITION | CMA_ERASE));
[2]424 else
[551]425 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPFROMP(&pci),
426 MPFROM2SHORT(1, CMA_REPOSITION | CMA_ERASE));
[2]427 }
428 pci = pciH;
429 }
[362]430 if (didone && !fSyncUpdates)
[551]431 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
432 MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
[2]433}
434
[551]435VOID MarkAll(HWND hwndCnr, BOOL quitit, BOOL target, BOOL source)
[317]436{
[2]437 PCNRITEM pci;
[551]438 INT attribute = CRA_CURSORED;
[2]439
[362]440 if (quitit)
[618]441 attribute = target ? CRA_TARGET : source ? CRA_SOURCE : CRA_INUSE;
[551]442 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS,
443 MPFROMLONG(CMA_FIRST), MPFROMSHORT(attribute));
[748]444 if (pci && (INT)pci != -1) {
[362]445 if (attribute == CRA_CURSORED) {
446 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[551]447 attribute = CRA_SELECTED;
448 pci =
449 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
450 MPFROMSHORT(attribute));
[2]451 }
452 }
453 }
[748]454 while (pci && (INT)pci != -1) {
[551]455 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
456 MPFROM2SHORT(!quitit,
[618]457 target ? CRA_TARGET : source ? CRA_SOURCE :
458 CRA_INUSE));
[551]459 pci =
460 WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
461 MPFROMSHORT(attribute));
[2]462 }
463}
464
[551]465VOID RemoveAll(HWND hwndCnr, ULONGLONG * pullTotalBytes,
466 ULONG * pulTotalFiles)
[317]467{
[2]468 PCNRITEM pci;
[551]469 INT attribute = CRA_CURSORED;
470 BOOL didone = FALSE;
[2]471
[551]472 pci = (PCNRITEM) CurrentRecord(hwndCnr);
[748]473 if (pci && (INT)pci != -1) {
[362]474 if (pci->rc.flRecordAttr & CRA_SELECTED) {
[2]475 attribute = CRA_SELECTED;
[551]476 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
477 MPFROMSHORT(attribute));
[2]478 }
479 }
[748]480 while (pci && (INT)pci != -1) {
481 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
[2]482 didone = TRUE;
[158]483 if (pulTotalFiles)
[689]484 *pulTotalFiles -= 1;
[158]485 if (pullTotalBytes)
[551]486 *pullTotalBytes -= (pci->cbFile + pci->easize);
487 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
488 MPFROM2SHORT(0, CRA_SELECTED));
[362]489 if (fSyncUpdates)
[751]490 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE | CMA_INVALIDATE);
[2]491 else
[751]492 RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE);
[362]493 if (attribute == CRA_CURSORED)
[551]494 break;
495 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMLONG(CMA_FIRST),
496 MPFROMSHORT(attribute));
[2]497 }
498 else
[551]499 pci = WinSendMsg(hwndCnr, CM_QUERYRECORDEMPHASIS, MPFROMP(pci),
500 MPFROMSHORT(attribute));
[2]501 }
[362]502 if (didone && !fSyncUpdates)
[551]503 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
504 MPFROM2SHORT(0, CMA_REPOSITION));
[2]505}
506
[442]507//== SetMask() Convert mask string to array of pointers to masks ==
508
[551]509VOID SetMask(PSZ maskstr, MASK * mask)
[317]510{
[442]511 UINT x;
512 PSZ p;
[2]513
[442]514 if (maskstr)
[551]515 strcpy(mask->szMask, maskstr); // Got new mask string
[442]516 // Build array of pointers
517 p = mask->szMaskCopy;
[551]518 strcpy(p, mask->szMask);
[442]519 // Allow up to 25 masks - ignore extras
520 for (x = 0; *p && x < 25; x++) {
521 mask->pszMasks[x] = p;
[362]522 while (*p && *p != ';')
[442]523 p++; // Find separator
[362]524 if (*p) {
[442]525 *p = 0; // Replace ;
[2]526 p++;
527 }
[551]528 } // for
[442]529 mask->pszMasks[x] = NULL; // Mark end
[2]530}
531
[551]532VOID ExpandAll(HWND hwndCnr, BOOL expand, PCNRITEM pciParent)
[317]533{
[2]534 PCNRITEM pci;
535
[362]536 if (!pciParent)
[551]537 pciParent = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(NULL),
538 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[362]539 if (pciParent) {
[748]540 if (expand && ~pciParent->rc.flRecordAttr & CRA_EXPANDED)
[551]541 WinSendMsg(hwndCnr, CM_EXPANDTREE, MPFROMP(pciParent), MPVOID);
[362]542 else if (!expand && (pciParent->rc.flRecordAttr & CRA_EXPANDED))
[551]543 WinSendMsg(hwndCnr, CM_COLLAPSETREE, MPFROMP(pciParent), MPVOID);
544 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
545 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[362]546 if (pci)
[766]547 DosSleep(1);
[748]548 while (pci && (INT)pci != -1) {
[551]549 ExpandAll(hwndCnr, expand, pci);
550 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
551 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]552 }
553 }
[748]554 DosSleep(1);
[2]555}
556
[551]557VOID InvertAll(HWND hwndCnr)
[317]558{
[2]559 PCNRITEM pci;
560
[551]561 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPVOID,
562 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[748]563 while (pci && (INT)pci != -1) {
564 if (~pci->rc.flRecordAttr & CRA_FILTERED) {
565 if (~pci->rc.flRecordAttr & CRA_SELECTED)
[551]566 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
567 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]568 else
[551]569 WinSendMsg(hwndCnr, CM_SETRECORDEMPHASIS, MPFROMP(pci),
570 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]571 }
[551]572 pci = (PCNRITEM) WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
573 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]574 }
575}
576
[204]577#pragma alloc_text (SELECT3,SpecialSelect)
[2]578#pragma alloc_text(SELECT4,FreeCnrs,SpecialSelect2,CompSSNames,CompSSNamesB)
579
[762]580/**
581 * Do select actions for compare directories containers
582 *
583 */
584
[551]585VOID SpecialSelect(HWND hwndCnrS, HWND hwndCnrD, INT action, BOOL reset)
[317]586{
[551]587 PCNRITEM pciS, pciD, *pciSa = NULL, *pciDa = NULL;
588 CNRINFO cnri;
589 BOOL slow = FALSE;
[769]590 UINT x, numD, numS;
[2]591
[762]592 if (!hwndCnrS || !hwndCnrD) {
593 Runtime_Error(pszSrcFile, __LINE__, "hwndCnrS %p hwndCnrD %p", hwndCnrS, hwndCnrD);
[2]594 return;
[762]595 }
[2]596
[551]597 memset(&cnri, 0, sizeof(CNRINFO));
[2]598 cnri.cb = sizeof(CNRINFO);
[551]599 WinSendMsg(hwndCnrD, CM_QUERYCNRINFO, MPFROMP(&cnri),
600 MPFROMLONG(sizeof(CNRINFO)));
[769]601 numD = cnri.cRecords;
[551]602 memset(&cnri, 0, sizeof(CNRINFO));
[2]603 cnri.cb = sizeof(CNRINFO);
[551]604 WinSendMsg(hwndCnrS, CM_QUERYCNRINFO, MPFROMP(&cnri),
605 MPFROMLONG(sizeof(CNRINFO)));
[769]606 numS = cnri.cRecords;
[362]607 if (!numD || numS != numD) {
[762]608 Runtime_Error(pszSrcFile, __LINE__, "numD %u != numS %u", numD, numS);
[2]609 return;
610 }
[551]611 pciDa = xmalloc(sizeof(PCNRITEM) * numD, pszSrcFile, __LINE__);
[362]612 if (!pciDa)
[2]613 return;
614
[551]615 pciSa = xmalloc(sizeof(PCNRITEM) * numS, pszSrcFile, __LINE__);
[362]616 if (!pciSa) {
617 free(pciDa);
[2]618 return;
619 }
620
621Restart:
622
[551]623 memset(pciDa, 0, sizeof(PCNRITEM) * numD);
624 memset(pciSa, 0, sizeof(PCNRITEM) * numS);
[2]625
[769]626 pciD = (PCNRITEM)WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPVOID,
[551]627 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[2]628 x = 0;
[748]629 while (pciD && (INT)pciD != -1 && x < numD) {
[362]630 if (reset)
[2]631 pciD->flags = 0;
632 pciDa[x] = pciD;
633 x++;
[362]634 if (!slow)
[551]635 pciD = (PCNRITEM) pciD->rc.preccNextRecord;
[2]636 else
[551]637 pciD = (PCNRITEM) WinSendMsg(hwndCnrD, CM_QUERYRECORD, MPFROMP(pciD),
638 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[362]639 if (!(x % 500))
[769]640 DosSleep(1L);
641 // else if (!(x % 50))
642 // DosSleep(0L);
[762]643 } // while
644
[362]645 if (numD != x) {
646 if (!slow) {
[2]647 slow = TRUE;
648 goto Restart;
649 }
650 free(pciDa);
651 free(pciSa);
[762]652 Runtime_Error(pszSrcFile, __LINE__, "numD %u != x %lu", numD, x);
[2]653 return;
654 }
655
[551]656 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPVOID,
657 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[2]658 x = 0;
[748]659 while (pciS && (INT)pciS != -1 && x < numS) {
[362]660 if (reset)
[2]661 pciS->flags = 0;
662 pciSa[x] = pciS;
663 x++;
[362]664 if (!slow)
[551]665 pciS = (PCNRITEM) pciS->rc.preccNextRecord;
[2]666 else
[551]667 pciS = (PCNRITEM) WinSendMsg(hwndCnrS, CM_QUERYRECORD, MPFROMP(pciS),
668 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[362]669 if (!(x % 500))
[769]670 DosSleep(1L);
671 // else if (!(x % 50))
672 // DosSleep(0L);
[762]673 } // while
674
[362]675 if (numS != x) {
676 if (!slow) {
[2]677 slow = TRUE;
678 goto Restart;
679 }
680 free(pciSa);
681 free(pciDa);
[551]682 Runtime_Error(pszSrcFile, __LINE__, "numS (%lu) != x (%lu)", numS, x);
[2]683 return;
684 }
685
[769]686 // 05 Aug 07 SHL fixme to know what sets reset
[362]687 if (reset) {
[769]688 // Update flags for files that exist on both sides
[551]689 for (x = 0; x < numS; x++) {
[748]690
[769]691 // 05 Aug 07 SHL fixme to know if should clear first
[730]692 if (!*pciSa[x]->pszFileName || !*pciDa[x]->pszFileName)
[551]693 continue;
[748]694
[769]695 pciSa[x]->flags |= CNRITEM_EXISTS; // File exists on both sides
[2]696 pciDa[x]->flags |= CNRITEM_EXISTS;
[362]697 if (pciSa[x]->cbFile + pciSa[x]->easize >
[551]698 pciDa[x]->cbFile + pciDa[x]->easize) {
699 pciSa[x]->flags |= CNRITEM_LARGER;
700 pciDa[x]->flags |= CNRITEM_SMALLER;
[2]701 }
[362]702 else if (pciSa[x]->cbFile + pciSa[x]->easize <
[551]703 pciDa[x]->cbFile + pciDa[x]->easize) {
704 pciSa[x]->flags |= CNRITEM_SMALLER;
705 pciDa[x]->flags |= CNRITEM_LARGER;
[2]706 }
[362]707 if ((pciSa[x]->date.year > pciDa[x]->date.year) ? TRUE :
[551]708 (pciSa[x]->date.year < pciDa[x]->date.year) ? FALSE :
709 (pciSa[x]->date.month > pciDa[x]->date.month) ? TRUE :
710 (pciSa[x]->date.month < pciDa[x]->date.month) ? FALSE :
711 (pciSa[x]->date.day > pciDa[x]->date.day) ? TRUE :
712 (pciSa[x]->date.day < pciDa[x]->date.day) ? FALSE :
713 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? TRUE :
714 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? FALSE :
715 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? TRUE :
716 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? FALSE :
717 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? TRUE :
718 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? FALSE : FALSE) {
719 pciSa[x]->flags |= CNRITEM_NEWER;
720 pciDa[x]->flags |= CNRITEM_OLDER;
[2]721 }
[362]722 else if ((pciSa[x]->date.year < pciDa[x]->date.year) ? TRUE :
[551]723 (pciSa[x]->date.year > pciDa[x]->date.year) ? FALSE :
724 (pciSa[x]->date.month < pciDa[x]->date.month) ? TRUE :
725 (pciSa[x]->date.month > pciDa[x]->date.month) ? FALSE :
726 (pciSa[x]->date.day < pciDa[x]->date.day) ? TRUE :
727 (pciSa[x]->date.day > pciDa[x]->date.day) ? FALSE :
728 (pciSa[x]->time.hours < pciDa[x]->time.hours) ? TRUE :
729 (pciSa[x]->time.hours > pciDa[x]->time.hours) ? FALSE :
730 (pciSa[x]->time.minutes < pciDa[x]->time.minutes) ? TRUE :
731 (pciSa[x]->time.minutes > pciDa[x]->time.minutes) ? FALSE :
732 (pciSa[x]->time.seconds < pciDa[x]->time.seconds) ? TRUE :
733 (pciSa[x]->time.seconds > pciDa[x]->time.seconds) ? FALSE :
734 FALSE) {
735 pciSa[x]->flags |= CNRITEM_OLDER;
736 pciDa[x]->flags |= CNRITEM_NEWER;
[2]737 }
[362]738 if (!(x % 500))
[769]739 DosSleep(1L);
740 // else if (!(x % 50))
741 // DosSleep(0L);
742 } // for
743 } // if reset
[2]744
[551]745 switch (action) {
746 case IDM_SELECTIDENTICAL:
747 for (x = 0; x < numS; x++) {
[769]748 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
749 pciSa[x]->flags & CNRITEM_EXISTS &&
750 ~pciSa[x]->flags & CNRITEM_SMALLER &&
751 ~pciSa[x]->flags & CNRITEM_LARGER &&
752 ~pciSa[x]->flags & CNRITEM_NEWER &&
753 ~pciSa[x]->flags & CNRITEM_OLDER) {
754 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
755 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
756 MPFROM2SHORT(TRUE, CRA_SELECTED));
757 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
758 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
759 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]760 }
[769]761 if (!(x % 500))
762 DosSleep(1L);
763 // else if (!(x % 50))
764 // DosSleep(0L);
765 } // for
[551]766 break;
[2]767
[551]768 case IDM_SELECTSAME:
769 for (x = 0; x < numS; x++) {
[748]770 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
771 pciSa[x]->flags & CNRITEM_EXISTS &&
772 ~pciSa[x]->flags & CNRITEM_SMALLER &&
773 ~pciSa[x]->flags & CNRITEM_LARGER) {
774 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
[551]775 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
776 MPFROM2SHORT(TRUE, CRA_SELECTED));
[748]777 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
[551]778 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
779 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]780 }
[551]781 if (!(x % 500))
[769]782 DosSleep(1L);
783 // else if (!(x % 50))
784 // DosSleep(0L);
[551]785 }
786 break;
[2]787
[551]788 case IDM_SELECTSAMECONTENT:
789 for (x = 0; x < numS; x++) {
790 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
[769]791 pciSa[x]->flags & CNRITEM_EXISTS)
[748]792 {
[551]793 FILE *fp1 = NULL;
794 FILE *fp2 = NULL;
795 BOOL gotMatch = FALSE;
796 UINT errLineNo = 0;
797 UINT compErrno = 0;
798 CHAR buf1[1024];
799 CHAR buf2[1024];
800 HAB hab = WinQueryAnchorBlock(hwndCnrS);
[317]801
[769]802 if (!*pciSa[x]->pszFileName ||
803 !*pciDa[x]->pszFileName) {
804 Runtime_Error(pszSrcFile, __LINE__,
805 "CNRITEM_EXISTS set with null file name for index %u", x);
806 break;
807 }
808
[730]809 fp1 = _fsopen(pciSa[x]->pszFileName, "rb", SH_DENYNO);
[551]810 if (!fp1) {
811 errLineNo = __LINE__;
812 compErrno = errno;
813 }
814 else {
[730]815 fp2 = _fsopen(pciDa[x]->pszFileName, "rb", SH_DENYNO);
[551]816 if (!fp2) {
[362]817 errLineNo = __LINE__;
818 compErrno = errno;
[317]819 }
820 else {
[551]821 size_t len1 = filelength(fileno(fp1));
822 size_t len2 = filelength(fileno(fp2));
823
824 if (len1 == len2) {
825 setbuf(fp1, NULL);
826 setbuf(fp2, NULL);
827 while (WinIsWindow(hab, hwndCnrS)) {
828 size_t numread1 = fread(buf1, 1, 1024, fp1);
829 size_t numread2 = fread(buf2, 1, 1024, fp2);
830
831 if (!numread1 || !numread2 || numread1 != numread2) {
832 if (ferror(fp1) || ferror(fp2)) {
833 errLineNo = __LINE__;
834 compErrno = errno;
[317]835 }
[551]836 else if (feof(fp1) && feof(fp2))
837 gotMatch = TRUE;
838 break;
839 }
840 else if (memcmp(buf1, buf2, numread1))
841 break;
[690]842 } // while
843 } // same len
[551]844 }
845 }
[317]846
[551]847 if (fp1)
848 fclose(fp1);
[317]849
[551]850 if (fp2)
851 fclose(fp2);
[317]852
[551]853 if (errLineNo) {
854 Runtime_Error(pszSrcFile, errLineNo,
855 "error %d while comparing", compErrno);
856 }
[769]857
[551]858 if (gotMatch) {
[748]859 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
[551]860 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
861 MPFROM2SHORT(TRUE, CRA_SELECTED));
[748]862 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
[551]863 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
864 MPFROM2SHORT(TRUE, CRA_SELECTED));
865 }
866 }
867 if (!(x % 500))
[769]868 DosSleep(1L);
869 // else if (!(x % 50))
870 // DosSleep(0L);
871 } // for
[551]872 break;
[317]873
[551]874 case IDM_SELECTBOTH:
875 for (x = 0; x < numS; x++) {
[748]876 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
877 pciSa[x]->flags & CNRITEM_EXISTS) {
878 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
[551]879 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
880 MPFROM2SHORT(TRUE, CRA_SELECTED));
[748]881 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
[551]882 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
883 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]884 }
[551]885 if (!(x % 500))
[769]886 DosSleep(1L);
887 // else if (!(x % 50))
888 // DosSleep(0L);
[551]889 }
890 break;
[2]891
[551]892 case IDM_SELECTONE:
893 for (x = 0; x < numS; x++) {
[748]894 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
[769]895 ~pciSa[x]->flags & CNRITEM_EXISTS) {
896 if (*pciSa[x]->pszFileName) {
897 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED) {
898 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
899 MPFROM2SHORT(TRUE, CRA_SELECTED));
900 }
901 }
902 else if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED) {
[551]903 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
904 MPFROM2SHORT(TRUE, CRA_SELECTED));
[769]905 }
[551]906 }
907 if (!(x % 500))
[769]908 DosSleep(1L);
909 // else if (!(x % 50))
910 // DosSleep(0L);
[551]911 }
912 break;
[2]913
[551]914 case IDM_SELECTBIGGER:
915 for (x = 0; x < numS; x++) {
[769]916 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
917 if (pciSa[x]->flags & CNRITEM_LARGER) {
918 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
919 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
920 MPFROM2SHORT(TRUE, CRA_SELECTED));
921 }
922 else if (pciDa[x]->flags & CNRITEM_LARGER) {
923 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
924 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
925 MPFROM2SHORT(TRUE, CRA_SELECTED));
926 }
[2]927 }
[551]928 if (!(x % 500))
[769]929 DosSleep(1L);
930 // else if (!(x % 50))
931 // DosSleep(0L);
[551]932 }
933 break;
[2]934
[551]935 case IDM_SELECTSMALLER:
936 for (x = 0; x < numS; x++) {
[769]937 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
938 if (pciSa[x]->flags & CNRITEM_SMALLER) {
939 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
940 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
941 MPFROM2SHORT(TRUE, CRA_SELECTED));
942 }
943 else if (pciDa[x]->flags & CNRITEM_SMALLER) {
944 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
945 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
946 MPFROM2SHORT(TRUE, CRA_SELECTED));
947 }
[2]948 }
[551]949 if (!(x % 500))
[769]950 DosSleep(1L);
951 // else if (!(x % 50))
952 // DosSleep(0L);
[551]953 }
954 break;
[2]955
[551]956 case IDM_SELECTNEWER:
957 for (x = 0; x < numS; x++) {
[769]958 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
959 if (pciSa[x]->flags & CNRITEM_NEWER) {
960 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
961 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
962 MPFROM2SHORT(TRUE, CRA_SELECTED));
963 }
964 else if (pciDa[x]->flags & CNRITEM_NEWER) {
965 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
966 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
967 MPFROM2SHORT(TRUE, CRA_SELECTED));
968 }
[2]969 }
[551]970 if (!(x % 500))
[769]971 DosSleep(1L);
972 // else if (!(x % 50))
973 // DosSleep(0L);
[551]974 }
975 break;
[2]976
[551]977 case IDM_SELECTOLDER:
978 for (x = 0; x < numS; x++) {
[769]979 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
980 if (pciSa[x]->flags & CNRITEM_OLDER) {
981 if (~pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
982 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
983 MPFROM2SHORT(TRUE, CRA_SELECTED));
984 }
985 else if (pciDa[x]->flags & CNRITEM_OLDER) {
986 if (~pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
987 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
988 MPFROM2SHORT(TRUE, CRA_SELECTED));
989 }
[2]990 }
[551]991 if (!(x % 500))
[769]992 DosSleep(1L);
993 // else if (!(x % 50))
994 // DosSleep(0L);
[551]995 }
996 break;
[2]997
[551]998 case IDM_DESELECTBOTH:
999 for (x = 0; x < numS; x++) {
[748]1000 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED &&
1001 pciSa[x]->flags & CNRITEM_EXISTS) {
[551]1002 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1003 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1004 MPFROM2SHORT(FALSE, CRA_SELECTED));
1005 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1006 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1007 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1008 }
[551]1009 if (!(x % 500))
[769]1010 DosSleep(1L);
1011 // else if (!(x % 50))
1012 // DosSleep(0L);
[551]1013 }
1014 break;
[2]1015
[551]1016 case IDM_DESELECTONE:
1017 for (x = 0; x < numS; x++) {
[769]1018 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1019 if (~pciSa[x]->flags & CNRITEM_EXISTS) {
1020 if (*pciSa[x]->pszFileName) {
1021 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1022 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1023 MPFROM2SHORT(FALSE, CRA_SELECTED));
1024 }
1025 else if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1026 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1027 MPFROM2SHORT(FALSE, CRA_SELECTED));
1028 }
[2]1029 }
[551]1030 if (!(x % 500))
[769]1031 DosSleep(1L);
1032 // else if (!(x % 50))
1033 // DosSleep(0L);
[551]1034 }
1035 break;
[2]1036
[551]1037 case IDM_DESELECTBIGGER:
1038 for (x = 0; x < numS; x++) {
[769]1039 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1040 if (pciSa[x]->flags & CNRITEM_LARGER) {
1041 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1042 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1043 MPFROM2SHORT(FALSE, CRA_SELECTED));
1044 }
1045 else if (pciDa[x]->flags & CNRITEM_LARGER) {
1046 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1047 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1048 MPFROM2SHORT(FALSE, CRA_SELECTED));
1049 }
[2]1050 }
[551]1051 if (!(x % 500))
[769]1052 DosSleep(1L);
1053 // else if (!(x % 50))
1054 // DosSleep(0L);
[551]1055 }
1056 break;
[2]1057
[551]1058 case IDM_DESELECTSMALLER:
1059 for (x = 0; x < numS; x++) {
[769]1060 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1061 if (pciSa[x]->flags & CNRITEM_SMALLER) {
1062 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1063 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1064 MPFROM2SHORT(FALSE, CRA_SELECTED));
1065 }
1066 else if (pciDa[x]->flags & CNRITEM_SMALLER) {
1067 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1068 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1069 MPFROM2SHORT(FALSE, CRA_SELECTED));
1070 }
[2]1071 }
[551]1072 if (!(x % 500))
[769]1073 DosSleep(1L);
1074 // else if (!(x % 50))
1075 // DosSleep(0L);
[551]1076 }
1077 break;
[2]1078
[551]1079 case IDM_DESELECTNEWER:
1080 for (x = 0; x < numS; x++) {
[769]1081 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1082 if (pciSa[x]->flags & CNRITEM_NEWER) {
1083 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1084 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1085 MPFROM2SHORT(FALSE, CRA_SELECTED));
1086 }
1087 else if (pciDa[x]->flags & CNRITEM_NEWER) {
1088 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1089 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1090 MPFROM2SHORT(FALSE, CRA_SELECTED));
1091 }
[2]1092 }
[551]1093 if (!(x % 500))
[769]1094 DosSleep(1L);
1095 // else if (!(x % 50))
1096 // DosSleep(0L);
[551]1097 }
1098 break;
[2]1099
[551]1100 case IDM_DESELECTOLDER:
1101 for (x = 0; x < numS; x++) {
[769]1102 if (~pciSa[x]->rc.flRecordAttr & CRA_FILTERED) {
1103 if (pciSa[x]->flags & CNRITEM_OLDER) {
1104 if (pciSa[x]->rc.flRecordAttr & CRA_SELECTED)
1105 WinSendMsg(hwndCnrS, CM_SETRECORDEMPHASIS, MPFROMP(pciSa[x]),
1106 MPFROM2SHORT(FALSE, CRA_SELECTED));
1107 }
1108 else if (pciDa[x]->flags & CNRITEM_OLDER) {
1109 if (pciDa[x]->rc.flRecordAttr & CRA_SELECTED)
1110 WinSendMsg(hwndCnrD, CM_SETRECORDEMPHASIS, MPFROMP(pciDa[x]),
1111 MPFROM2SHORT(FALSE, CRA_SELECTED));
1112 }
[2]1113 }
[551]1114 if (!(x % 500))
[769]1115 DosSleep(1L);
1116 // else if (!(x % 50))
1117 // DosSleep(0L);
[551]1118 }
1119 break;
[2]1120
[551]1121 default:
1122 break;
[2]1123 }
1124
[362]1125 if (reset) {
1126 while (numS) {
[551]1127 WinSendMsg(hwndCnrS, CM_INVALIDATERECORD,
1128 MPFROMP(pciSa), MPFROM2SHORT((min(numS, 65535)), 0));
[748]1129 DosSleep(1);
[551]1130 WinSendMsg(hwndCnrD, CM_INVALIDATERECORD,
1131 MPFROMP(pciDa), MPFROM2SHORT((min(numD, 65535)), 0));
1132 numS -= min(numS, 65535);
[362]1133 if (numS)
[748]1134 DosSleep(1);
[2]1135 }
1136 }
1137
1138 free(pciSa);
1139 free(pciDa);
1140 DosPostEventSem(CompactSem);
1141}
1142
[551]1143struct SS
1144{
1145 PCNRITEM pci;
1146 BOOL unique, all, smallest, largest, newest, oldest;
[2]1147};
1148
[551]1149struct Cnr
1150{
1151 HWND hwndCnr;
1152 ULONG numfiles;
[2]1153 struct SS *ss;
1154};
1155
[551]1156static int CompSSNamesB(const void *s1, const void *s2)
[317]1157{
[2]1158 struct SS *ss2 = (struct SS *)s2;
1159
[748]1160 return stricmp((PSZ)s1, ss2->pci->pszFileName);
[2]1161}
1162
[551]1163static int CompSSNames(const void *s1, const void *s2)
[317]1164{
[2]1165 struct SS *ss1 = (struct SS *)s1;
1166 struct SS *ss2 = (struct SS *)s2;
1167
[551]1168 return stricmp(ss1->pci->pszFileName, ss2->pci->pszFileName);
[2]1169}
1170
[551]1171VOID FreeCnrs(struct Cnr * Cnrs, INT numw)
[317]1172{
[2]1173 register INT z;
1174
[551]1175 for (z = 0; z < numw; z++) {
[362]1176 if (Cnrs[z].ss)
[2]1177 free(Cnrs[z].ss);
1178 }
1179 free(Cnrs);
1180 DosPostEventSem(CompactSem);
1181}
1182
[762]1183/**
1184 * Do select actions for single container
1185 *
1186 */
1187
[551]1188VOID SpecialSelect2(HWND hwndParent, INT action)
[317]1189{
[551]1190 PCNRITEM pci;
1191 HENUM henum;
1192 HWND hwnd;
1193 register INT numwindows = 0, w, x, z, cmp;
1194 struct Cnr *Cnrs = NULL;
1195 struct SS *bsres;
[2]1196
[362]1197 if (!hwndParent)
[2]1198 return;
1199
1200 /* count directory containers, build array of hwnds */
1201 henum = WinBeginEnumWindows(hwndParent);
[362]1202 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE) {
[551]1203 if (WinWindowFromID(WinWindowFromID(hwnd, FID_CLIENT), DIR_CNR)) {
1204 Cnrs =
1205 xrealloc(Cnrs, (numwindows + 1) * sizeof(struct Cnr), pszSrcFile,
1206 __LINE__);
[362]1207 if (!Cnrs) {
[551]1208 Notify(GetPString(IDS_OUTOFMEMORY));
1209 return;
[2]1210 }
[551]1211 memset(&Cnrs[numwindows], 0, sizeof(struct Cnr));
[2]1212 Cnrs[numwindows].hwndCnr = WinWindowFromID(WinWindowFromID(hwnd,
[551]1213 FID_CLIENT),
1214 DIR_CNR);
[2]1215 numwindows++;
1216 }
1217 }
1218 WinEndEnumWindows(henum);
[362]1219 if (numwindows < 2) {
[551]1220 FreeCnrs(Cnrs, numwindows);
[362]1221 Runtime_Error(pszSrcFile, __LINE__, "expected two windows");
[2]1222 Notify(GetPString(IDS_COMPSEL2ORMORETEXT));
1223 return;
1224 }
[362]1225 if (numwindows > 4) {
[2]1226 WinSendMsg(Cnrs[0].
[551]1227 hwndCnr,
1228 UM_NOTIFY, MPFROMP(GetPString(IDS_BUILDINGLISTSTEXT)), MPVOID);
[748]1229 DosSleep(1);
[2]1230 }
1231
1232 /* count records, build array of pointers to records */
[551]1233 for (z = 0; z < numwindows; z++) {
1234 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
1235 CM_QUERYRECORD,
1236 MPVOID,
1237 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[2]1238 x = 0;
[748]1239 while (pci && (INT)pci != -1) {
1240 if (~pci->rc.flRecordAttr & CRA_FILTERED &&
1241 ~pci->attrFile & FILE_DIRECTORY) {
[551]1242 Cnrs[z].ss =
1243 xrealloc(Cnrs[z].ss, (x + 1) * sizeof(struct SS), pszSrcFile,
1244 __LINE__);
1245 if (!Cnrs[z].ss) {
1246 FreeCnrs(Cnrs, numwindows);
1247 Notify(GetPString(IDS_OUTOFMEMORY));
1248 return;
1249 }
1250 memset(&Cnrs[z].ss[x], 0, sizeof(struct SS));
1251 Cnrs[z].ss[x].pci = pci;
1252 x++;
[2]1253 }
[551]1254 pci = (PCNRITEM) WinSendMsg(Cnrs[z].hwndCnr,
1255 CM_QUERYRECORD,
1256 MPFROMP(pci),
1257 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]1258 }
[748]1259 DosSleep(1);
[2]1260 Cnrs[z].numfiles = x;
[362]1261 if (Cnrs[z].numfiles)
[551]1262 qsort(Cnrs[z].ss, Cnrs[z].numfiles, sizeof(struct SS), CompSSNames);
[2]1263 }
1264
[551]1265 for (z = 0; z < numwindows; z++) {
1266 for (x = 0; x < Cnrs[z].numfiles; x++) {
[2]1267 Cnrs[z].ss[x].all = Cnrs[z].ss[x].unique = Cnrs[z].ss[x].newest =
[551]1268 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].smallest =
1269 Cnrs[z].ss[x].largest = TRUE;
1270 for (w = 0; w < numwindows; w++) {
1271 if (w != z && Cnrs[w].numfiles) {
1272 bsres = (struct SS *)bsearch(Cnrs[z].ss[x].pci->pszFileName,
1273 Cnrs[w].ss, Cnrs[w].numfiles,
1274 sizeof(struct SS), CompSSNamesB);
1275 if (bsres) {
1276 Cnrs[z].ss[x].unique = FALSE;
1277 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize >
1278 bsres->pci->cbFile + bsres->pci->easize)
1279 Cnrs[z].ss[x].smallest = FALSE;
1280 if (Cnrs[z].ss[x].pci->cbFile + Cnrs[z].ss[x].pci->easize <
1281 bsres->pci->cbFile + bsres->pci->easize)
1282 Cnrs[z].ss[x].largest = FALSE;
1283 cmp =
1284 (Cnrs[z].ss[x].pci->date.year >
1285 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year <
1286 bsres->pci->date.
1287 year) ? FALSE : (Cnrs[z].
1288 ss[x].pci->
1289 date.month >
1290 bsres->pci->
1291 date.
1292 month) ? TRUE
1293 : (Cnrs[z].ss[x].pci->date.month <
1294 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
1295 day >
1296 bsres->pci->date.
1297 day) ? TRUE : (Cnrs[z].
1298 ss[x].pci->
1299 date.day <
1300 bsres->
1301 pci->date.
1302 day) ?
1303 FALSE : (Cnrs[z].ss[x].pci->time.hours >
1304 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
1305 time.hours <
1306 bsres->pci->time.
1307 hours) ? FALSE
1308 : (Cnrs[z].ss[x].pci->time.minutes >
1309 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
1310 minutes <
1311 bsres->pci->time.
1312 minutes) ? FALSE
1313 : (Cnrs[z].ss[x].pci->time.seconds >
1314 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
1315 seconds <
1316 bsres->pci->time.
1317 seconds) ? FALSE : FALSE;
1318 if (!cmp)
1319 Cnrs[z].ss[x].newest = FALSE;
1320 cmp =
1321 (Cnrs[z].ss[x].pci->date.year <
1322 bsres->pci->date.year) ? TRUE : (Cnrs[z].ss[x].pci->date.year >
1323 bsres->pci->date.
1324 year) ? FALSE : (Cnrs[z].
1325 ss[x].pci->
1326 date.month <
1327 bsres->pci->
1328 date.
1329 month) ? TRUE
1330 : (Cnrs[z].ss[x].pci->date.month >
1331 bsres->pci->date.month) ? FALSE : (Cnrs[z].ss[x].pci->date.
1332 day <
1333 bsres->pci->date.
1334 day) ? TRUE : (Cnrs[z].
1335 ss[x].pci->
1336 date.day >
1337 bsres->
1338 pci->date.
1339 day) ?
1340 FALSE : (Cnrs[z].ss[x].pci->time.hours <
1341 bsres->pci->time.hours) ? TRUE : (Cnrs[z].ss[x].pci->
1342 time.hours >
1343 bsres->pci->time.
1344 hours) ? FALSE
1345 : (Cnrs[z].ss[x].pci->time.minutes <
1346 bsres->pci->time.minutes) ? TRUE : (Cnrs[z].ss[x].pci->time.
1347 minutes >
1348 bsres->pci->time.
1349 minutes) ? FALSE
1350 : (Cnrs[z].ss[x].pci->time.seconds <
1351 bsres->pci->time.seconds) ? TRUE : (Cnrs[z].ss[x].pci->time.
1352 seconds >
1353 bsres->pci->time.
1354 seconds) ? FALSE : FALSE;
1355 if (!cmp)
1356 Cnrs[z].ss[x].oldest = FALSE;
1357 cmp = 0;
1358 break;
1359 }
1360 else
1361 Cnrs[z].ss[x].all = FALSE;
1362 }
[2]1363 }
[362]1364 if (Cnrs[z].ss[x].unique)
[551]1365 Cnrs[z].ss[x].oldest = Cnrs[z].ss[x].newest = Cnrs[z].ss[x].all =
1366 Cnrs[z].ss[x].largest = Cnrs[z].ss[x].smallest = FALSE;
[748]1367 DosSleep(1);
[2]1368 }
[766]1369 DosSleep(1);
[2]1370 }
1371
[551]1372 switch (action) {
1373 case IDM_SELECTBOTH:
1374 for (z = 0; z < numwindows; z++) {
1375 for (x = 0; x < Cnrs[z].numfiles; x++) {
1376 if (Cnrs[z].ss[x].all)
1377 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1378 MPFROMP(Cnrs[z].ss[x].pci),
1379 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1380 }
[748]1381 DosSleep(1);
[551]1382 }
1383 break;
1384 case IDM_SELECTMORE:
1385 for (z = 0; z < numwindows; z++) {
1386 for (x = 0; x < Cnrs[z].numfiles; x++) {
1387 if (!Cnrs[z].ss[x].unique)
1388 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1389 MPFROMP(Cnrs[z].ss[x].pci),
1390 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1391 }
[748]1392 DosSleep(1);
[551]1393 }
1394 break;
1395 case IDM_SELECTONE:
1396 for (z = 0; z < numwindows; z++) {
1397 for (x = 0; x < Cnrs[z].numfiles; x++) {
1398 if (Cnrs[z].ss[x].unique)
1399 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1400 MPFROMP(Cnrs[z].ss[x].pci),
1401 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1402 }
[748]1403 DosSleep(1);
[551]1404 }
1405 break;
1406 case IDM_SELECTNEWER:
1407 for (z = 0; z < numwindows; z++) {
1408 for (x = 0; x < Cnrs[z].numfiles; x++) {
1409 if (Cnrs[z].ss[x].newest)
1410 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1411 MPFROMP(Cnrs[z].ss[x].pci),
1412 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1413 }
[748]1414 DosSleep(1);
[551]1415 }
1416 break;
1417 case IDM_SELECTOLDER:
1418 for (z = 0; z < numwindows; z++) {
1419 for (x = 0; x < Cnrs[z].numfiles; x++) {
1420 if (Cnrs[z].ss[x].oldest)
1421 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1422 MPFROMP(Cnrs[z].ss[x].pci),
1423 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1424 }
[748]1425 DosSleep(1);
[551]1426 }
1427 break;
1428 case IDM_SELECTBIGGER:
1429 for (z = 0; z < numwindows; z++) {
1430 for (x = 0; x < Cnrs[z].numfiles; x++) {
1431 if (Cnrs[z].ss[x].largest)
1432 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1433 MPFROMP(Cnrs[z].ss[x].pci),
1434 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1435 }
[748]1436 DosSleep(1);
[551]1437 }
1438 break;
1439 case IDM_SELECTSMALLER:
1440 for (z = 0; z < numwindows; z++) {
1441 for (x = 0; x < Cnrs[z].numfiles; x++) {
1442 if (Cnrs[z].ss[x].smallest)
1443 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1444 MPFROMP(Cnrs[z].ss[x].pci),
1445 MPFROM2SHORT(TRUE, CRA_SELECTED));
[2]1446 }
[748]1447 DosSleep(1);
[551]1448 }
1449 break;
[2]1450
[551]1451 case IDM_DESELECTBOTH:
1452 for (z = 0; z < numwindows; z++) {
1453 for (x = 0; x < Cnrs[z].numfiles; x++) {
1454 if (Cnrs[z].ss[x].all)
1455 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1456 MPFROMP(Cnrs[z].ss[x].pci),
1457 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1458 }
[748]1459 DosSleep(1);
[551]1460 }
1461 break;
1462 case IDM_DESELECTMORE:
1463 for (z = 0; z < numwindows; z++) {
1464 for (x = 0; x < Cnrs[z].numfiles; x++) {
1465 if (!Cnrs[z].ss[x].unique)
1466 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1467 MPFROMP(Cnrs[z].ss[x].pci),
1468 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1469 }
[748]1470 DosSleep(1);
[551]1471 }
1472 break;
1473 case IDM_DESELECTONE:
1474 for (z = 0; z < numwindows; z++) {
1475 for (x = 0; x < Cnrs[z].numfiles; x++) {
1476 if (Cnrs[z].ss[x].unique)
1477 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1478 MPFROMP(Cnrs[z].ss[x].pci),
1479 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1480 }
[748]1481 DosSleep(1);
[551]1482 }
1483 break;
1484 case IDM_DESELECTNEWER:
1485 for (z = 0; z < numwindows; z++) {
1486 for (x = 0; x < Cnrs[z].numfiles; x++) {
1487 if (Cnrs[z].ss[x].newest)
1488 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1489 MPFROMP(Cnrs[z].ss[x].pci),
1490 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1491 }
[748]1492 DosSleep(1);
[551]1493 }
1494 break;
1495 case IDM_DESELECTOLDER:
1496 for (z = 0; z < numwindows; z++) {
1497 for (x = 0; x < Cnrs[z].numfiles; x++) {
1498 if (Cnrs[z].ss[x].oldest)
1499 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1500 MPFROMP(Cnrs[z].ss[x].pci),
1501 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1502 }
[748]1503 DosSleep(1);
[551]1504 }
1505 break;
1506 case IDM_DESELECTBIGGER:
1507 for (z = 0; z < numwindows; z++) {
1508 for (x = 0; x < Cnrs[z].numfiles; x++) {
1509 if (Cnrs[z].ss[x].largest)
1510 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1511 MPFROMP(Cnrs[z].ss[x].pci),
1512 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1513 }
[748]1514 DosSleep(1);
[551]1515 }
1516 break;
1517 case IDM_DESELECTSMALLER:
1518 for (z = 0; z < numwindows; z++) {
1519 for (x = 0; x < Cnrs[z].numfiles; x++) {
1520 if (Cnrs[z].ss[x].smallest)
1521 WinSendMsg(Cnrs[z].hwndCnr, CM_SETRECORDEMPHASIS,
1522 MPFROMP(Cnrs[z].ss[x].pci),
1523 MPFROM2SHORT(FALSE, CRA_SELECTED));
[2]1524 }
[748]1525 DosSleep(1);
[551]1526 }
1527 break;
[2]1528 }
1529
[551]1530 FreeCnrs(Cnrs, numwindows);
[2]1531}
Note: See TracBrowser for help on using the repository browser.