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