| 1 | 
 | 
|---|
| 2 | /***********************************************************************
 | 
|---|
| 3 | 
 | 
|---|
| 4 |   $Id: update.c 1326 2008-12-09 02:18:36Z gyoung $
 | 
|---|
| 5 | 
 | 
|---|
| 6 |   Update Container record/list
 | 
|---|
| 7 | 
 | 
|---|
| 8 |   Copyright (c) 1993-98 M. Kimes
 | 
|---|
| 9 |   Copyright (c) 2003, 2008 Steven H. Levine
 | 
|---|
| 10 | 
 | 
|---|
| 11 |   12 Feb 03 SHL Standardize EA math
 | 
|---|
| 12 |   10 Jan 04 SHL Add some intermin large drive error avoidance
 | 
|---|
| 13 |   25 May 05 SHL Rework for ULONGLONG
 | 
|---|
| 14 |   25 May 05 SHL Rework for FillInRecordFromFFB
 | 
|---|
| 15 |   06 Jun 05 SHL Drop unused code
 | 
|---|
| 16 |   22 Jul 06 SHL Use wrappers
 | 
|---|
| 17 |   20 Feb 07 GKY Add SelectDriveIcon()
 | 
|---|
| 18 |   09 Mar 07 GKY Cleanup SelectDriveIcon using "driveflag =" from Steven
 | 
|---|
| 19 |   02 Aug 07 SHL Sync with CNRITEM mods
 | 
|---|
| 20 |   20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
 | 
|---|
| 21 | 
 | 
|---|
| 22 | ***********************************************************************/
 | 
|---|
| 23 | 
 | 
|---|
| 24 | #include <stdlib.h>
 | 
|---|
| 25 | #include <string.h>
 | 
|---|
| 26 | #include <ctype.h>
 | 
|---|
| 27 | 
 | 
|---|
| 28 | #define INCL_DOS
 | 
|---|
| 29 | #define INCL_WIN
 | 
|---|
| 30 | #define INCL_LONGLONG
 | 
|---|
| 31 | 
 | 
|---|
| 32 | #include "fm3dll.h"
 | 
|---|
| 33 | #include "fm3dll2.h"                    // #define's for UM_*, control id's, etc.
 | 
|---|
| 34 | #include "update.h"
 | 
|---|
| 35 | #include "init.h"                       // Data declaration(s)
 | 
|---|
| 36 | #include "notebook.h"                   // Data declaration(s)
 | 
|---|
| 37 | #include "info.h"                       // Data declaration(s)
 | 
|---|
| 38 | #include "newview.h"                    // Data declarations
 | 
|---|
| 39 | #include "fm3str.h"
 | 
|---|
| 40 | #include "errutil.h"                    // Dos_Error...
 | 
|---|
| 41 | #include "filldir.h"                    // FillInRecordFromFFB
 | 
|---|
| 42 | #include "dircnrs.h"
 | 
|---|
| 43 | #include "flesh.h"                      // Flesh, Stubby
 | 
|---|
| 44 | #include "findrec.h"                    // FindCnrRecord
 | 
|---|
| 45 | #include "valid.h"                      // IsFullName
 | 
|---|
| 46 | #include "wrappers.h"                   // xDosFindFirst
 | 
|---|
| 47 | #include "misc.h"                       // PostMsg
 | 
|---|
| 48 | #include "fortify.h"
 | 
|---|
| 49 | 
 | 
|---|
| 50 | static PSZ pszSrcFile = __FILE__;
 | 
|---|
| 51 | 
 | 
|---|
| 52 | HPOINTER SelectDriveIcon(PCNRITEM pci)
 | 
|---|
| 53 | {
 | 
|---|
| 54 |     UINT driveflag = driveflags[toupper(*pci->pszFileName) - 'A'];
 | 
|---|
| 55 |     *pci->pszFileName = toupper(*pci->pszFileName);
 | 
|---|
| 56 |               if (isalpha(*pci->pszFileName) &&
 | 
|---|
| 57 |                   toupper(*pci->pszFileName) > 'B') {
 | 
|---|
| 58 |                 if (driveflag & DRIVE_CDROM)
 | 
|---|
| 59 |                   pci->rc.hptrIcon = hptrCDROM;
 | 
|---|
| 60 |                 else
 | 
|---|
| 61 |                   pci->rc.hptrIcon =
 | 
|---|
| 62 |                      (driveflag & DRIVE_REMOVABLE) ? hptrRemovable
 | 
|---|
| 63 |                     :(driveflag & DRIVE_VIRTUAL) ? hptrVirtual
 | 
|---|
| 64 |                     :(driveflag & DRIVE_REMOTE) ? hptrRemote
 | 
|---|
| 65 |                     :(driveflag & DRIVE_RAMDISK) ? hptrRamdisk
 | 
|---|
| 66 |                     :(driveflag & DRIVE_ZIPSTREAM) ? hptrZipstrm : hptrDrive;
 | 
|---|
| 67 |               }
 | 
|---|
| 68 |               else
 | 
|---|
| 69 |                 pci->rc.hptrIcon = hptrFloppy;
 | 
|---|
| 70 |                 return pci->rc.hptrIcon;
 | 
|---|
| 71 | }
 | 
|---|
| 72 | PCNRITEM UpdateCnrRecord(HWND hwndCnr, CHAR * filename, BOOL partial,
 | 
|---|
| 73 |                          DIRCNRDATA * dcd)
 | 
|---|
| 74 | {
 | 
|---|
| 75 |   PCNRITEM pci;
 | 
|---|
| 76 |   FILEFINDBUF4L ffb;
 | 
|---|
| 77 |   HDIR hDir = HDIR_CREATE;
 | 
|---|
| 78 |   ULONG nm = 1;
 | 
|---|
| 79 |   ULONG oldemphasis = 0;
 | 
|---|
| 80 |   APIRET status;
 | 
|---|
| 81 | 
 | 
|---|
| 82 |   if (!filename || !*filename)
 | 
|---|
| 83 |     return (PCNRITEM) NULL;
 | 
|---|
| 84 |   if (IsFullName(filename)) {
 | 
|---|
| 85 |     if (driveflags[toupper(*filename) - 'A'] & DRIVE_NOTWRITEABLE)
 | 
|---|
| 86 |       /* ignore non-writeable drives */
 | 
|---|
| 87 |       return (PCNRITEM) NULL;
 | 
|---|
| 88 |   }
 | 
|---|
| 89 |   status = xDosFindFirst(filename,
 | 
|---|
| 90 |                          &hDir,
 | 
|---|
| 91 |                          FILE_NORMAL | FILE_DIRECTORY |
 | 
|---|
| 92 |                          FILE_ARCHIVED | FILE_READONLY |
 | 
|---|
| 93 |                          FILE_HIDDEN | FILE_SYSTEM,
 | 
|---|
| 94 |                          &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL);
 | 
|---|
| 95 |   if (!status) {
 | 
|---|
| 96 |     /* file exists */
 | 
|---|
| 97 |     DosFindClose(hDir);
 | 
|---|
| 98 |     if (!dcd)
 | 
|---|
| 99 |       dcd = INSTDATA(hwndCnr);
 | 
|---|
| 100 | /*
 | 
|---|
| 101 |     if(dcd->type == TREE_FRAME &&
 | 
|---|
| 102 |        !(ffb.attrFile & FILE_DIRECTORY))
 | 
|---|
| 103 |       return (PCNRITEM)NULL;
 | 
|---|
| 104 | */
 | 
|---|
| 105 |     if (dcd->type == ARC_FRAME)
 | 
|---|
| 106 |       return (PCNRITEM) NULL;
 | 
|---|
| 107 |     if (*dcd->directory) {
 | 
|---|
| 108 | 
 | 
|---|
| 109 |       CHAR *p, temp;
 | 
|---|
| 110 | 
 | 
|---|
| 111 |       p = strrchr(filename, '\\');
 | 
|---|
| 112 |       if (p) {
 | 
|---|
| 113 |         if (p < filename + 3)
 | 
|---|
| 114 |           p++;
 | 
|---|
| 115 |         temp = *p;
 | 
|---|
| 116 |         *p = 0;
 | 
|---|
| 117 |         if (stricmp(filename, dcd->directory)) {
 | 
|---|
| 118 |           *p = temp;
 | 
|---|
| 119 |           return (PCNRITEM) NULL;
 | 
|---|
| 120 |         }
 | 
|---|
| 121 |         *p = temp;
 | 
|---|
| 122 |       }
 | 
|---|
| 123 |       else
 | 
|---|
| 124 |         return (PCNRITEM) NULL;
 | 
|---|
| 125 |     }
 | 
|---|
| 126 |     pci = FindCnrRecord(hwndCnr,
 | 
|---|
| 127 |                         filename, (PCNRITEM) NULL, partial, FALSE, TRUE);
 | 
|---|
| 128 |   Update:
 | 
|---|
| 129 |     if (pci) {                          /* update record? */
 | 
|---|
| 130 |       if ((!fForceUpper && !fForceLower && strcmp(pci->pszFileName, filename)) ||
 | 
|---|
| 131 |           pci->cbFile != ffb.cbFile || pci->attrFile != ffb.attrFile ||
 | 
|---|
| 132 |           pci->easize != CBLIST_TO_EASIZE(ffb.cbList) || pci->date.day !=
 | 
|---|
| 133 |           ffb.fdateLastWrite.day || pci->date.month != ffb.fdateLastWrite.month ||
 | 
|---|
| 134 |           pci->date.year != ffb.fdateLastWrite.year + 1980 || pci->time.seconds !=
 | 
|---|
| 135 |           ffb.ftimeLastWrite.twosecs * 2 || pci->time.minutes != ffb.ftimeLastWrite.minutes ||
 | 
|---|
| 136 |           pci->time.hours != ffb.ftimeLastWrite.hours || pci->ladate.day !=
 | 
|---|
| 137 |           ffb.fdateLastAccess.day || pci->ladate.month != ffb.fdateLastAccess.month ||
 | 
|---|
| 138 |           pci->ladate.year != ffb.fdateLastAccess.year + 1980 || pci->latime.seconds !=
 | 
|---|
| 139 |           ffb.ftimeLastAccess.twosecs * 2 || pci->latime.minutes !=
 | 
|---|
| 140 |           ffb.ftimeLastAccess.minutes || pci->latime.hours != ffb.ftimeLastAccess.hours) {      /* changed; update */
 | 
|---|
| 141 |         *ffb.achName = 0;
 | 
|---|
| 142 |         ffb.cchName = 0;
 | 
|---|
| 143 |         FillInRecordFromFFB(hwndCnr, pci, filename, &ffb, partial, dcd);
 | 
|---|
| 144 |         if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 145 |         SelectDriveIcon(pci);
 | 
|---|
| 146 |         oldemphasis = pci->rc.flRecordAttr & (CRA_SELECTED | CRA_CURSORED);
 | 
|---|
| 147 |         if (oldemphasis)
 | 
|---|
| 148 |           WinSendMsg(hwndCnr,
 | 
|---|
| 149 |                      CM_SETRECORDEMPHASIS,
 | 
|---|
| 150 |                      MPFROMP(pci), MPFROM2SHORT(FALSE, oldemphasis));
 | 
|---|
| 151 |         WinSendMsg(hwndCnr,
 | 
|---|
| 152 |                    CM_INVALIDATERECORD, MPFROMP(&pci), MPFROM2SHORT(1,
 | 
|---|
| 153 |                                                                     /* CMA_ERASE | */
 | 
|---|
| 154 |                                                                     CMA_TEXTCHANGED));
 | 
|---|
| 155 |         if (oldemphasis)
 | 
|---|
| 156 |           WinSendMsg(hwndCnr,
 | 
|---|
| 157 |                      CM_SETRECORDEMPHASIS,
 | 
|---|
| 158 |                      MPFROMP(pci), MPFROM2SHORT(TRUE, oldemphasis));
 | 
|---|
| 159 |       }
 | 
|---|
| 160 |       else                              /* existed, unchanged, do nothing but return */
 | 
|---|
| 161 |         return pci;
 | 
|---|
| 162 |     }
 | 
|---|
| 163 |     else {                              /* add record */
 | 
|---|
| 164 |       if (dcd->type == DIR_FRAME) {
 | 
|---|
| 165 | 
 | 
|---|
| 166 |         RECORDINSERT ri;
 | 
|---|
| 167 |         ULONGLONG ullTotalBytes;
 | 
|---|
| 168 | 
 | 
|---|
| 169 |         pci = WinSendMsg(hwndCnr,
 | 
|---|
| 170 |                          CM_ALLOCRECORD,
 | 
|---|
| 171 |                          MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
 | 
|---|
| 172 |         if (pci) {
 | 
|---|
| 173 |           *ffb.achName = 0;
 | 
|---|
| 174 |           ullTotalBytes = FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 175 |                                               pci,
 | 
|---|
| 176 |                                               filename, &ffb, partial, dcd);
 | 
|---|
| 177 |           if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 178 |           SelectDriveIcon(pci);
 | 
|---|
| 179 |           memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 180 |           ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 181 |           ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 182 |           ri.pRecordParent = (PRECORDCORE) NULL;
 | 
|---|
| 183 |           ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 184 |           ri.cRecordsInsert = 1;
 | 
|---|
| 185 |           ri.fInvalidateRecord = TRUE;
 | 
|---|
| 186 |           if (WinSendMsg(hwndCnr,
 | 
|---|
| 187 |                          CM_INSERTRECORD,
 | 
|---|
| 188 |                          MPFROMP(pci), MPFROMP(&ri)) && ullTotalBytes) {
 | 
|---|
| 189 |             dcd->ullTotalBytes += ullTotalBytes;
 | 
|---|
| 190 |             PostMsg(hwndCnr, UM_RESCAN, MPVOID, MPVOID);
 | 
|---|
| 191 |             if (pci->attrFile & FILE_DIRECTORY) {
 | 
|---|
| 192 |               if (fInitialDriveScan)
 | 
|---|
| 193 |                 Stubby(hwndCnr, pci);
 | 
|---|
| 194 |               else {
 | 
|---|
| 195 |                 while (StubbyScanCount != 0)
 | 
|---|
| 196 |                   DosSleep(50);
 | 
|---|
| 197 |                 Stubby(hwndCnr, pci);
 | 
|---|
| 198 |               }
 | 
|---|
| 199 |             }
 | 
|---|
| 200 |           }
 | 
|---|
| 201 |         }
 | 
|---|
| 202 |       }
 | 
|---|
| 203 |       else if (ffb.attrFile & FILE_DIRECTORY) {
 | 
|---|
| 204 | 
 | 
|---|
| 205 |         /* check all parts and insert as required */
 | 
|---|
| 206 |         CHAR *p, temp;
 | 
|---|
| 207 |         PCNRITEM pciParent = NULL, pciT;
 | 
|---|
| 208 | 
 | 
|---|
| 209 |         p = strchr(filename, '\\');
 | 
|---|
| 210 |         if (p) {
 | 
|---|
| 211 |           while (p && *p) {
 | 
|---|
| 212 |             if (p < filename + 3)
 | 
|---|
| 213 |               p++;
 | 
|---|
| 214 |             temp = *p;
 | 
|---|
| 215 |             *p = 0;
 | 
|---|
| 216 |             pciT = FindCnrRecord(hwndCnr,
 | 
|---|
| 217 |                                  filename, NULL, partial, FALSE, TRUE);
 | 
|---|
| 218 |             if (!pciT || (INT) pciT == -1) {
 | 
|---|
| 219 |               pci = WinSendMsg(hwndCnr,
 | 
|---|
| 220 |                                CM_ALLOCRECORD,
 | 
|---|
| 221 |                                MPFROMLONG(EXTRA_RECORD_BYTES),
 | 
|---|
| 222 |                                MPFROMLONG(1));
 | 
|---|
| 223 |               if (pci) {
 | 
|---|
| 224 | 
 | 
|---|
| 225 |                 RECORDINSERT ri;
 | 
|---|
| 226 | 
 | 
|---|
| 227 |                 *ffb.achName = 0;
 | 
|---|
| 228 |                 FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 229 |                                     pci, filename, &ffb, partial, dcd);
 | 
|---|
| 230 |                 if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 231 |                 SelectDriveIcon(pci);
 | 
|---|
| 232 |                 memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 233 |                 ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 234 |                 ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 235 |                 ri.pRecordParent = (PRECORDCORE) pciParent;
 | 
|---|
| 236 |                 ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 237 |                 ri.cRecordsInsert = 1;
 | 
|---|
| 238 |                 ri.fInvalidateRecord = TRUE;
 | 
|---|
| 239 |                 if (WinSendMsg(hwndCnr,
 | 
|---|
| 240 |                                CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
 | 
|---|
| 241 |                   Flesh(hwndCnr, pci);
 | 
|---|
| 242 |                   *p = temp;
 | 
|---|
| 243 |                   pci = FindCnrRecord(hwndCnr,
 | 
|---|
| 244 |                                       filename, pciT, partial, FALSE, TRUE);
 | 
|---|
| 245 |                   if (pci)
 | 
|---|
| 246 |                     goto Update;
 | 
|---|
| 247 |                 }
 | 
|---|
| 248 |               }
 | 
|---|
| 249 |             }
 | 
|---|
| 250 |             else {
 | 
|---|
| 251 |               pciParent = pciT;
 | 
|---|
| 252 |               if (!(pciT->rc.flRecordAttr & CRA_EXPANDED)) {
 | 
|---|
| 253 |                 Flesh(hwndCnr, pciT);
 | 
|---|
| 254 |                 *p = temp;
 | 
|---|
| 255 |                 pci = FindCnrRecord(hwndCnr,
 | 
|---|
| 256 |                                     filename, pciT, partial, FALSE, TRUE);
 | 
|---|
| 257 |                 if (pci)
 | 
|---|
| 258 |                   goto Update;
 | 
|---|
| 259 |               }
 | 
|---|
| 260 |             }
 | 
|---|
| 261 |             *p = temp;
 | 
|---|
| 262 |             p = strchr(p + ((temp == '\\') ? 1 : 0), '\\');
 | 
|---|
| 263 |           }
 | 
|---|
| 264 |         }
 | 
|---|
| 265 |         pci = WinSendMsg(hwndCnr,
 | 
|---|
| 266 |                          CM_ALLOCRECORD,
 | 
|---|
| 267 |                          MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
 | 
|---|
| 268 |         if (pci) {
 | 
|---|
| 269 | 
 | 
|---|
| 270 |           RECORDINSERT ri;
 | 
|---|
| 271 |           ULONGLONG ullTotalBytes;
 | 
|---|
| 272 | 
 | 
|---|
| 273 |           *ffb.achName = 0;
 | 
|---|
| 274 |           ullTotalBytes = FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 275 |                                               pci,
 | 
|---|
| 276 |                                               filename, &ffb, partial, dcd);
 | 
|---|
| 277 |           if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 278 |           SelectDriveIcon(pci);
 | 
|---|
| 279 |           memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 280 |           ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 281 |           ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 282 |           ri.pRecordParent = (PRECORDCORE) pciParent;
 | 
|---|
| 283 |           ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 284 |           ri.cRecordsInsert = 1;
 | 
|---|
| 285 |           ri.fInvalidateRecord = TRUE;
 | 
|---|
| 286 |           if (WinSendMsg(hwndCnr,
 | 
|---|
| 287 |                          CM_INSERTRECORD,
 | 
|---|
| 288 |                          MPFROMP(pci), MPFROMP(&ri)) && ullTotalBytes) {
 | 
|---|
| 289 |             if (dcd->type == DIR_FRAME) {
 | 
|---|
| 290 |               dcd->ullTotalBytes += ullTotalBytes;
 | 
|---|
| 291 |             }
 | 
|---|
| 292 |             if (fInitialDriveScan)
 | 
|---|
| 293 |               Stubby(hwndCnr, pci);
 | 
|---|
| 294 |             else {
 | 
|---|
| 295 |               while (StubbyScanCount != 0)
 | 
|---|
| 296 |                 DosSleep(50);
 | 
|---|
| 297 |               Stubby(hwndCnr, pci);
 | 
|---|
| 298 |             }
 | 
|---|
| 299 |           }
 | 
|---|
| 300 |         }
 | 
|---|
| 301 |       }
 | 
|---|
| 302 |     }
 | 
|---|
| 303 |   }
 | 
|---|
| 304 |   else if ((pci = FindCnrRecord(hwndCnr,
 | 
|---|
| 305 |                                 filename,
 | 
|---|
| 306 |                                 (PCNRITEM) NULL,
 | 
|---|
| 307 |                                 partial,
 | 
|---|
| 308 |                                 FALSE,
 | 
|---|
| 309 |                                 TRUE)) !=
 | 
|---|
| 310 |            NULL && (INT) pci != -1 && strlen(pci->pszFileName) > 3) {
 | 
|---|
| 311 |     /* file doesn't exist; delete record */
 | 
|---|
| 312 |     if (!dcd)
 | 
|---|
| 313 |       dcd = INSTDATA(hwndCnr);
 | 
|---|
| 314 |     if (pci->rc.flRecordAttr & CRA_SELECTED)
 | 
|---|
| 315 |       WinSendMsg(hwndCnr,
 | 
|---|
| 316 |                  CM_SETRECORDEMPHASIS,
 | 
|---|
| 317 |                  MPFROMP(pci), MPFROM2SHORT(FALSE, CRA_SELECTED));
 | 
|---|
| 318 |     if (dcd->type == DIR_FRAME)
 | 
|---|
| 319 |       dcd->ullTotalBytes -= pci->cbFile + pci->easize;
 | 
|---|
| 320 |     RemoveCnrItems(hwndCnr, pci, 1, CMA_FREE | CMA_INVALIDATE);
 | 
|---|
| 321 |     pci = NULL;
 | 
|---|
| 322 |     PostMsg(hwndCnr, UM_RESCAN, MPVOID, MPVOID);
 | 
|---|
| 323 |   }
 | 
|---|
| 324 |   return pci;
 | 
|---|
| 325 | }
 | 
|---|
| 326 | 
 | 
|---|
| 327 | BOOL UpdateCnrList(HWND hwndCnr, CHAR ** filename, INT howmany, BOOL partial,
 | 
|---|
| 328 |                    DIRCNRDATA * dcd)
 | 
|---|
| 329 | {
 | 
|---|
| 330 |   PCNRITEM pci, *pciList = NULL;
 | 
|---|
| 331 |   FILEFINDBUF4L ffb;
 | 
|---|
| 332 |   HDIR hDir;
 | 
|---|
| 333 |   ULONG nm = (ULONG) howmany;
 | 
|---|
| 334 |   INT x;
 | 
|---|
| 335 |   INT numlist = 0;
 | 
|---|
| 336 |   INT numremain;
 | 
|---|
| 337 |   BOOL repos = FALSE;
 | 
|---|
| 338 |   BOOL ret = FALSE;
 | 
|---|
| 339 |   APIRET status;
 | 
|---|
| 340 | 
 | 
|---|
| 341 |   if (!dcd)
 | 
|---|
| 342 |     dcd = INSTDATA(hwndCnr);
 | 
|---|
| 343 |   if (!dcd) {
 | 
|---|
| 344 |     Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
 | 
|---|
| 345 |     return ret;
 | 
|---|
| 346 |   }
 | 
|---|
| 347 |   if (!filename || !howmany || !filename[0])
 | 
|---|
| 348 |     return ret;
 | 
|---|
| 349 |   {
 | 
|---|
| 350 |     CNRINFO cnri;
 | 
|---|
| 351 | 
 | 
|---|
| 352 |     memset(&cnri, 0, sizeof(CNRINFO));
 | 
|---|
| 353 |     cnri.cb = sizeof(CNRINFO);
 | 
|---|
| 354 |     WinSendMsg(hwndCnr,
 | 
|---|
| 355 |                CM_QUERYCNRINFO, MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO)));
 | 
|---|
| 356 |     numremain = cnri.cRecords;
 | 
|---|
| 357 |   }
 | 
|---|
| 358 |   pciList = xmalloc(sizeof(PCNRITEM) * howmany, pszSrcFile, __LINE__);
 | 
|---|
| 359 |   if (pciList) {
 | 
|---|
| 360 |     for (x = 0; filename[x] && x < howmany; x++) {
 | 
|---|
| 361 |       if (IsFullName(filename[x])) {
 | 
|---|
| 362 |         if (driveflags[toupper(*filename[x]) - 'A'] & DRIVE_NOTWRITEABLE)
 | 
|---|
| 363 |           /* ignore non-writeable drives */
 | 
|---|
| 364 |           continue;
 | 
|---|
| 365 |       }
 | 
|---|
| 366 |       hDir = HDIR_CREATE;
 | 
|---|
| 367 |       status = xDosFindFirst(filename[x],
 | 
|---|
| 368 |                              &hDir,
 | 
|---|
| 369 |                              FILE_NORMAL | FILE_DIRECTORY |
 | 
|---|
| 370 |                              FILE_ARCHIVED | FILE_READONLY |
 | 
|---|
| 371 |                              FILE_HIDDEN | FILE_SYSTEM,
 | 
|---|
| 372 |                              &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZEL);
 | 
|---|
| 373 |       if (!status) {
 | 
|---|
| 374 |         /* file exists */
 | 
|---|
| 375 |         DosFindClose(hDir);
 | 
|---|
| 376 |         //      if(dcd->type == TREE_FRAME && !(ffb.attrFile & FILE_DIRECTORY))
 | 
|---|
| 377 |         //        continue;
 | 
|---|
| 378 |         if (dcd->type == DIR_FRAME && *dcd->directory) {
 | 
|---|
| 379 | 
 | 
|---|
| 380 |           CHAR *p, temp;
 | 
|---|
| 381 | 
 | 
|---|
| 382 |           p = strrchr(filename[x], '\\');
 | 
|---|
| 383 |           if (p) {
 | 
|---|
| 384 |             if (p < filename[x] + 3)
 | 
|---|
| 385 |               p++;
 | 
|---|
| 386 |             temp = *p;
 | 
|---|
| 387 |             *p = 0;
 | 
|---|
| 388 |             if (stricmp(filename[x], dcd->directory)) {
 | 
|---|
| 389 |               *p = temp;
 | 
|---|
| 390 |               continue;
 | 
|---|
| 391 |             }
 | 
|---|
| 392 |             *p = temp;
 | 
|---|
| 393 |           }
 | 
|---|
| 394 |           else
 | 
|---|
| 395 |             continue;
 | 
|---|
| 396 |         }
 | 
|---|
| 397 |         ret = TRUE;
 | 
|---|
| 398 |         pci = FindCnrRecord(hwndCnr,
 | 
|---|
| 399 |                             filename[x],
 | 
|---|
| 400 |                             (PCNRITEM) NULL, partial, FALSE, TRUE);
 | 
|---|
| 401 |         if (pci) {
 | 
|---|
| 402 |           /* update record? */
 | 
|---|
| 403 |           if ((!fForceUpper && !fForceLower &&
 | 
|---|
| 404 |                strcmp(pci->pszFileName, filename[x])) ||
 | 
|---|
| 405 |               pci->cbFile != ffb.cbFile || pci->attrFile != ffb.attrFile ||
 | 
|---|
| 406 |               pci->easize != CBLIST_TO_EASIZE(ffb.cbList) ||
 | 
|---|
| 407 |               pci->date.day != ffb.fdateLastWrite.day ||
 | 
|---|
| 408 |               pci->date.month != ffb.fdateLastWrite.month ||
 | 
|---|
| 409 |               pci->date.year != ffb.fdateLastWrite.year + 1980 ||
 | 
|---|
| 410 |               pci->time.seconds != ffb.ftimeLastWrite.twosecs * 2 ||
 | 
|---|
| 411 |               pci->time.minutes != ffb.ftimeLastWrite.minutes ||
 | 
|---|
| 412 |               pci->time.hours != ffb.ftimeLastWrite.hours ||
 | 
|---|
| 413 |               pci->ladate.day != ffb.fdateLastAccess.day ||
 | 
|---|
| 414 |               pci->ladate.month != ffb.fdateLastAccess.month ||
 | 
|---|
| 415 |               pci->ladate.year != ffb.fdateLastAccess.year + 1980 ||
 | 
|---|
| 416 |               pci->latime.seconds != ffb.ftimeLastAccess.twosecs * 2 ||
 | 
|---|
| 417 |               pci->latime.minutes != ffb.ftimeLastAccess.minutes ||
 | 
|---|
| 418 |               pci->latime.hours != ffb.ftimeLastAccess.hours) {
 | 
|---|
| 419 |             /* changed; update */
 | 
|---|
| 420 |             pciList[numlist++] = pci;
 | 
|---|
| 421 |             *ffb.achName = 0;
 | 
|---|
| 422 |             ffb.cchName = 0;
 | 
|---|
| 423 |             FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 424 |                                 pci, filename[x], &ffb, partial, dcd);
 | 
|---|
| 425 |             if (IsRoot(pci->pszFileName))
 | 
|---|
| 426 |             SelectDriveIcon(pci);
 | 
|---|
| 427 |             WinSendMsg(hwndCnr,
 | 
|---|
| 428 |                        CM_SETRECORDEMPHASIS,
 | 
|---|
| 429 |                        MPFROMP(pci),
 | 
|---|
| 430 |                        MPFROM2SHORT(FALSE, CRA_SELECTED | CRA_CURSORED));
 | 
|---|
| 431 |           }
 | 
|---|
| 432 |         }
 | 
|---|
| 433 |         else {
 | 
|---|
| 434 |           /* add record */
 | 
|---|
| 435 |           if (dcd->type == DIR_FRAME) {
 | 
|---|
| 436 |             RECORDINSERT ri;
 | 
|---|
| 437 |             ULONGLONG ullTotalBytes;
 | 
|---|
| 438 | 
 | 
|---|
| 439 |             pci = WinSendMsg(hwndCnr,
 | 
|---|
| 440 |                              CM_ALLOCRECORD,
 | 
|---|
| 441 |                              MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
 | 
|---|
| 442 |             if (pci) {
 | 
|---|
| 443 |               ret = TRUE;
 | 
|---|
| 444 |               *ffb.achName = 0;
 | 
|---|
| 445 |               ullTotalBytes = FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 446 |                                                   pci,
 | 
|---|
| 447 |                                                   filename[x],
 | 
|---|
| 448 |                                                   &ffb, partial, dcd);
 | 
|---|
| 449 |               if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 450 |                 SelectDriveIcon(pci);
 | 
|---|
| 451 |               memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 452 |               ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 453 |               ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 454 |               ri.pRecordParent = (PRECORDCORE) NULL;
 | 
|---|
| 455 |               ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 456 |               ri.cRecordsInsert = 1;
 | 
|---|
| 457 |               ri.fInvalidateRecord = FALSE;
 | 
|---|
| 458 |               if (WinSendMsg(hwndCnr,
 | 
|---|
| 459 |                              CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
 | 
|---|
| 460 |                 if (ullTotalBytes) {
 | 
|---|
| 461 |                   dcd->ullTotalBytes += ullTotalBytes;
 | 
|---|
| 462 |                   numremain++;
 | 
|---|
| 463 |                 }
 | 
|---|
| 464 |                 repos = TRUE;
 | 
|---|
| 465 |                 if (pci->attrFile & FILE_DIRECTORY) {
 | 
|---|
| 466 |                   if (fInitialDriveScan)
 | 
|---|
| 467 |                     Stubby(hwndCnr, pci);
 | 
|---|
| 468 |                   else {
 | 
|---|
| 469 |                     while (StubbyScanCount != 0)
 | 
|---|
| 470 |                       DosSleep(50);
 | 
|---|
| 471 |                     Stubby(hwndCnr, pci);
 | 
|---|
| 472 |                   }
 | 
|---|
| 473 |                 }
 | 
|---|
| 474 |               }
 | 
|---|
| 475 |               else
 | 
|---|
| 476 |                 FreeCnrItem(hwndCnr, pci);
 | 
|---|
| 477 |             }
 | 
|---|
| 478 |           }
 | 
|---|
| 479 |           else if (ffb.attrFile & FILE_DIRECTORY) {
 | 
|---|
| 480 |             /* check all parts and insert as required */
 | 
|---|
| 481 |             CHAR *p, temp;
 | 
|---|
| 482 |             PCNRITEM pciParent = NULL, pciT;
 | 
|---|
| 483 | 
 | 
|---|
| 484 |             p = strchr(filename[x], '\\');
 | 
|---|
| 485 |             if (p) {
 | 
|---|
| 486 |               while (p && *p) {
 | 
|---|
| 487 |                 if (p < filename[x] + 3)
 | 
|---|
| 488 |                   p++;
 | 
|---|
| 489 |                 temp = *p;
 | 
|---|
| 490 |                 *p = 0;
 | 
|---|
| 491 |                 pciT = FindCnrRecord(hwndCnr,
 | 
|---|
| 492 |                                      filename[x], NULL, partial, FALSE, TRUE);
 | 
|---|
| 493 |                 if (!pciT || (INT) pciT == -1) {
 | 
|---|
| 494 |                   pci = WinSendMsg(hwndCnr,
 | 
|---|
| 495 |                                    CM_ALLOCRECORD,
 | 
|---|
| 496 |                                    MPFROMLONG(EXTRA_RECORD_BYTES),
 | 
|---|
| 497 |                                    MPFROMLONG(1));
 | 
|---|
| 498 |                   if (pci) {
 | 
|---|
| 499 | 
 | 
|---|
| 500 |                     RECORDINSERT ri;
 | 
|---|
| 501 |                     ULONGLONG ullTotalBytes;
 | 
|---|
| 502 | 
 | 
|---|
| 503 |                     ret = TRUE;
 | 
|---|
| 504 |                     *ffb.achName = 0;
 | 
|---|
| 505 |                     ullTotalBytes = FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 506 |                                                         pci,
 | 
|---|
| 507 |                                                         filename[x],
 | 
|---|
| 508 |                                                         &ffb, partial, dcd);
 | 
|---|
| 509 |                     if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 510 |                       SelectDriveIcon(pci);
 | 
|---|
| 511 |                     memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 512 |                     ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 513 |                     ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 514 |                     ri.pRecordParent = (PRECORDCORE) pciParent;
 | 
|---|
| 515 |                     ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 516 |                     ri.cRecordsInsert = 1;
 | 
|---|
| 517 |                     ri.fInvalidateRecord = FALSE;
 | 
|---|
| 518 |                     if (WinSendMsg(hwndCnr,
 | 
|---|
| 519 |                                    CM_INSERTRECORD,
 | 
|---|
| 520 |                                    MPFROMP(pci), MPFROMP(&ri))) {
 | 
|---|
| 521 |                       if (ullTotalBytes) {
 | 
|---|
| 522 |                         numremain++;
 | 
|---|
| 523 |                         if (dcd->type == DIR_FRAME)
 | 
|---|
| 524 |                           dcd->ullTotalBytes += ullTotalBytes;
 | 
|---|
| 525 |                       }
 | 
|---|
| 526 |                       repos = TRUE;
 | 
|---|
| 527 |                     }
 | 
|---|
| 528 |                     else
 | 
|---|
| 529 |                       FreeCnrItem(hwndCnr, pci);
 | 
|---|
| 530 |                   }
 | 
|---|
| 531 |                 }
 | 
|---|
| 532 |                 else
 | 
|---|
| 533 |                   pciParent = pciT;
 | 
|---|
| 534 |                 *p = temp;
 | 
|---|
| 535 |                 p = strchr(p + ((temp == '\\') ? 1 : 0), '\\');
 | 
|---|
| 536 |               }
 | 
|---|
| 537 |             }
 | 
|---|
| 538 |             {
 | 
|---|
| 539 |               pci = WinSendMsg(hwndCnr,
 | 
|---|
| 540 |                                CM_ALLOCRECORD,
 | 
|---|
| 541 |                                MPFROMLONG(EXTRA_RECORD_BYTES),
 | 
|---|
| 542 |                                MPFROMLONG(1));
 | 
|---|
| 543 |               if (pci) {
 | 
|---|
| 544 | 
 | 
|---|
| 545 |                 RECORDINSERT ri;
 | 
|---|
| 546 |                 ULONGLONG ullTotalBytes;
 | 
|---|
| 547 | 
 | 
|---|
| 548 |                 ret = TRUE;
 | 
|---|
| 549 |                 *ffb.achName = 0;
 | 
|---|
| 550 |                 ullTotalBytes = FillInRecordFromFFB(hwndCnr,
 | 
|---|
| 551 |                                                     pci,
 | 
|---|
| 552 |                                                     filename[x],
 | 
|---|
| 553 |                                                     &ffb, partial, dcd);
 | 
|---|
| 554 |                 if (strlen(pci->pszFileName) < 4)
 | 
|---|
| 555 |                   SelectDriveIcon(pci);
 | 
|---|
| 556 |                 memset(&ri, 0, sizeof(RECORDINSERT));
 | 
|---|
| 557 |                 ri.cb = sizeof(RECORDINSERT);
 | 
|---|
| 558 |                 ri.pRecordOrder = (PRECORDCORE) CMA_END;
 | 
|---|
| 559 |                 ri.pRecordParent = (PRECORDCORE) pciParent;
 | 
|---|
| 560 |                 ri.zOrder = (USHORT) CMA_TOP;
 | 
|---|
| 561 |                 ri.cRecordsInsert = 1;
 | 
|---|
| 562 |                 ri.fInvalidateRecord = FALSE;
 | 
|---|
| 563 |                 if (WinSendMsg(hwndCnr,
 | 
|---|
| 564 |                                CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
 | 
|---|
| 565 |                   if (ullTotalBytes) {
 | 
|---|
| 566 |                     numremain++;
 | 
|---|
| 567 |                     if (dcd->type == DIR_FRAME)
 | 
|---|
| 568 |                       dcd->ullTotalBytes += ullTotalBytes;
 | 
|---|
| 569 |                   }
 | 
|---|
| 570 |                   repos = TRUE;
 | 
|---|
| 571 |                   if (fInitialDriveScan)
 | 
|---|
| 572 |                     Stubby(hwndCnr, pci);
 | 
|---|
| 573 |                   else {
 | 
|---|
| 574 |                     while (StubbyScanCount != 0)
 | 
|---|
| 575 |                       DosSleep(50);
 | 
|---|
| 576 |                     Stubby(hwndCnr, pci);
 | 
|---|
| 577 |                   }
 | 
|---|
| 578 |                 }
 | 
|---|
| 579 |                 else
 | 
|---|
| 580 |                   FreeCnrItem(hwndCnr, pci);
 | 
|---|
| 581 |               }
 | 
|---|
| 582 |             }
 | 
|---|
| 583 |           }
 | 
|---|
| 584 |         }
 | 
|---|
| 585 |       }
 | 
|---|
| 586 |       else if ((pci = FindCnrRecord(hwndCnr,
 | 
|---|
| 587 |                                     filename[x],
 | 
|---|
| 588 |                                     (PCNRITEM) NULL,
 | 
|---|
| 589 |                                     partial,
 | 
|---|
| 590 |                                     FALSE,
 | 
|---|
| 591 |                                     TRUE)) != NULL &&
 | 
|---|
| 592 |                (INT) pci != -1 && !IsRoot(pci->pszFileName)) {
 | 
|---|
| 593 |         /* file doesn't exist; delete record */
 | 
|---|
| 594 |         if (pci->rc.flRecordAttr & CRA_SELECTED)
 | 
|---|
| 595 |           WinSendMsg(hwndCnr,
 | 
|---|
| 596 |                      CM_SETRECORDEMPHASIS,
 | 
|---|
| 597 |                      MPFROMP(pci), MPFROM2SHORT(FALSE, CRA_SELECTED));
 | 
|---|
| 598 |         if (dcd->type == DIR_FRAME)
 | 
|---|
| 599 |           dcd->ullTotalBytes -= (pci->cbFile + pci->easize);
 | 
|---|
| 600 |         // 02 Aug 07 SHL rc check was wrong
 | 
|---|
| 601 |         if (RemoveCnrItems(hwndCnr, pci, 1,
 | 
|---|
| 602 |                            CMA_FREE |
 | 
|---|
| 603 |                            numremain == 1 ? CMA_INVALIDATE : 0) != -1) {
 | 
|---|
| 604 |           pci = NULL;
 | 
|---|
| 605 |           numremain--;
 | 
|---|
| 606 |           repos = TRUE;
 | 
|---|
| 607 |         }
 | 
|---|
| 608 |       }
 | 
|---|
| 609 |     } // for x
 | 
|---|
| 610 |   }
 | 
|---|
| 611 |   if (repos || (pciList && numlist)) {
 | 
|---|
| 612 |     QUERYRECORDRECT qrr;
 | 
|---|
| 613 |     RECTL rCnr, rCItem;
 | 
|---|
| 614 | 
 | 
|---|
| 615 |     pci = WinSendMsg(hwndCnr,
 | 
|---|
| 616 |                      CM_QUERYRECORDEMPHASIS,
 | 
|---|
| 617 |                      MPFROMLONG(CMA_FIRST), MPFROMLONG(CRA_CURSORED));
 | 
|---|
| 618 |     if (pci && (INT) pci != -1) {
 | 
|---|
| 619 |       memset(&qrr, 0, sizeof(QUERYRECORDRECT));
 | 
|---|
| 620 |       qrr.cb = sizeof(QUERYRECORDRECT);
 | 
|---|
| 621 |       qrr.pRecord = (PRECORDCORE) pci;
 | 
|---|
| 622 |       qrr.fRightSplitWindow = FALSE;
 | 
|---|
| 623 |       qrr.fsExtent = CMA_TEXT;
 | 
|---|
| 624 |       if (!WinSendMsg(hwndCnr,
 | 
|---|
| 625 |                       CM_QUERYRECORDRECT, MPFROMP(&rCItem), MPFROMP(&qrr)))
 | 
|---|
| 626 |         qrr.cb = 0;
 | 
|---|
| 627 |     }
 | 
|---|
| 628 |     if (pciList && numlist && !repos) {
 | 
|---|
| 629 |       WinSendMsg(hwndCnr,
 | 
|---|
| 630 |                  CM_INVALIDATERECORD,
 | 
|---|
| 631 |                  MPFROMP(pciList),
 | 
|---|
| 632 |                  MPFROM2SHORT(numlist,
 | 
|---|
| 633 |                               (repos ? CMA_NOREPOSITION :
 | 
|---|
| 634 |                                CMA_REPOSITION | CMA_ERASE)));
 | 
|---|
| 635 |     }
 | 
|---|
| 636 |     if (repos)
 | 
|---|
| 637 |       WinSendMsg(hwndCnr,
 | 
|---|
| 638 |                  CM_INVALIDATERECORD,
 | 
|---|
| 639 |                  MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
 | 
|---|
| 640 |     if (pci && (INT) pci != -1 && qrr.cb) {
 | 
|---|
| 641 |       WinSendMsg(hwndCnr,
 | 
|---|
| 642 |                  CM_QUERYVIEWPORTRECT,
 | 
|---|
| 643 |                  MPFROMP(&rCnr), MPFROM2SHORT(CMA_WINDOW, (SHORT) FALSE));
 | 
|---|
| 644 |       WinSendMsg(hwndCnr,
 | 
|---|
| 645 |                  CM_SCROLLWINDOW,
 | 
|---|
| 646 |                  MPFROMSHORT(CMA_VERTICAL),
 | 
|---|
| 647 |                  MPFROMLONG(rCnr.yTop - rCItem.yTop));
 | 
|---|
| 648 |     }
 | 
|---|
| 649 |   }
 | 
|---|
| 650 |   PostMsg(hwndCnr, UM_RESCAN, MPVOID, MPVOID);
 | 
|---|
| 651 |   if (pciList) {
 | 
|---|
| 652 |     free(pciList);
 | 
|---|
| 653 |     DosPostEventSem(CompactSem);
 | 
|---|
| 654 |   }
 | 
|---|
| 655 |   return ret;
 | 
|---|
| 656 | }
 | 
|---|
| 657 | 
 | 
|---|
| 658 | #pragma alloc_text(UPDATECNR,UpdateCnrRecord,UpdateCnrList)
 | 
|---|