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