| 1 |  | 
|---|
| 2 | /*********************************************************************** | 
|---|
| 3 |  | 
|---|
| 4 | $Id: update.c 557 2007-03-09 18:38:41Z gyoung $ | 
|---|
| 5 |  | 
|---|
| 6 | Update Container record/list | 
|---|
| 7 |  | 
|---|
| 8 | Copyright (c) 1993-98 M. Kimes | 
|---|
| 9 | Copyright (c) 2003, 2006 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 |  | 
|---|
| 20 | ***********************************************************************/ | 
|---|
| 21 |  | 
|---|
| 22 | #define INCL_DOS | 
|---|
| 23 | #define INCL_WIN | 
|---|
| 24 | #define INCL_LONGLONG | 
|---|
| 25 | #include <os2.h> | 
|---|
| 26 |  | 
|---|
| 27 | #include <stdarg.h> | 
|---|
| 28 | #include <stdio.h> | 
|---|
| 29 | #include <stdlib.h> | 
|---|
| 30 | #include <string.h> | 
|---|
| 31 | #include <ctype.h> | 
|---|
| 32 |  | 
|---|
| 33 | #include "fm3dll.h" | 
|---|
| 34 | #include "fm3str.h" | 
|---|
| 35 |  | 
|---|
| 36 | static PSZ pszSrcFile = __FILE__; | 
|---|
| 37 |  | 
|---|
| 38 | #pragma alloc_text(UPDATECNR,UpdateCnrRecord,UpdateCnrList) | 
|---|
| 39 |  | 
|---|
| 40 | HPOINTER SelectDriveIcon(PCNRITEM pci) | 
|---|
| 41 | { | 
|---|
| 42 | UINT driveflag = driveflags[toupper(*pci->szFileName) - 'A']; | 
|---|
| 43 | *pci->szFileName = toupper(*pci->szFileName); | 
|---|
| 44 | if (isalpha(*pci->szFileName) && | 
|---|
| 45 | toupper(*pci->szFileName) > '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 | FILEFINDBUF4 ffb; | 
|---|
| 65 | HDIR hDir = HDIR_CREATE; | 
|---|
| 66 | ULONG nm = 1L; | 
|---|
| 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 = DosFindFirst(filename, | 
|---|
| 83 | &hDir, | 
|---|
| 84 | FILE_NORMAL | FILE_DIRECTORY | | 
|---|
| 85 | FILE_ARCHIVED | FILE_READONLY | | 
|---|
| 86 | FILE_HIDDEN | FILE_SYSTEM, | 
|---|
| 87 | &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZE); | 
|---|
| 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->szFileName, 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->szFileName) < 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(1L)); | 
|---|
| 177 | if (pci) { | 
|---|
| 178 | *ffb.achName = 0; | 
|---|
| 179 | ullTotalBytes = FillInRecordFromFFB(hwndCnr, | 
|---|
| 180 | pci, | 
|---|
| 181 | filename, &ffb, partial, dcd); | 
|---|
| 182 | if (strlen(pci->szFileName) < 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 = 1L; | 
|---|
| 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(1L)); | 
|---|
| 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->szFileName) < 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 = 1L; | 
|---|
| 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(1L)); | 
|---|
| 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->szFileName) < 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 = 1L; | 
|---|
| 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->szFileName) > 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 | WinSendMsg(hwndCnr, | 
|---|
| 317 | CM_REMOVERECORD, | 
|---|
| 318 | MPFROMP(&pci), MPFROM2SHORT(1, CMA_FREE | CMA_INVALIDATE)); | 
|---|
| 319 | pci = (PCNRITEM) NULL; | 
|---|
| 320 | PostMsg(hwndCnr, UM_RESCAN, MPVOID, MPVOID); | 
|---|
| 321 | } | 
|---|
| 322 | #ifdef DEBUG | 
|---|
| 323 | { | 
|---|
| 324 | char s[CCHMAXPATH + 80]; | 
|---|
| 325 |  | 
|---|
| 326 | sprintf(s, "%s:%s%s%s%s%s", filename, (existed) ? " Existed" : "", | 
|---|
| 327 | (updated) ? " Updated" : "", (added) ? " Added" : "", | 
|---|
| 328 | (deleted) ? " Deleted" : "", (found) ? " Found" : ""); | 
|---|
| 329 | WinSetWindowText(WinQueryWindow(hwndMain, QW_PARENT), s); | 
|---|
| 330 | } | 
|---|
| 331 | #endif | 
|---|
| 332 | return pci; | 
|---|
| 333 | } | 
|---|
| 334 |  | 
|---|
| 335 | BOOL UpdateCnrList(HWND hwndCnr, CHAR ** filename, INT howmany, BOOL partial, | 
|---|
| 336 | DIRCNRDATA * dcd) | 
|---|
| 337 | { | 
|---|
| 338 | PCNRITEM pci, *pciList = NULL; | 
|---|
| 339 | FILEFINDBUF4 ffb; | 
|---|
| 340 | HDIR hDir; | 
|---|
| 341 | ULONG nm = 1L; | 
|---|
| 342 | INT x; | 
|---|
| 343 | INT numlist = 0; | 
|---|
| 344 | INT numremain; | 
|---|
| 345 | BOOL repos = FALSE; | 
|---|
| 346 | BOOL ret = FALSE; | 
|---|
| 347 | APIRET status; | 
|---|
| 348 |  | 
|---|
| 349 | if (!dcd) | 
|---|
| 350 | dcd = INSTDATA(hwndCnr); | 
|---|
| 351 | if (!dcd) { | 
|---|
| 352 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT); | 
|---|
| 353 | return ret; | 
|---|
| 354 | } | 
|---|
| 355 | if (!filename || !howmany || !filename[0]) | 
|---|
| 356 | return ret; | 
|---|
| 357 | { | 
|---|
| 358 | CNRINFO cnri; | 
|---|
| 359 |  | 
|---|
| 360 | memset(&cnri, 0, sizeof(CNRINFO)); | 
|---|
| 361 | cnri.cb = sizeof(CNRINFO); | 
|---|
| 362 | WinSendMsg(hwndCnr, | 
|---|
| 363 | CM_QUERYCNRINFO, MPFROMP(&cnri), MPFROMLONG(sizeof(CNRINFO))); | 
|---|
| 364 | numremain = cnri.cRecords; | 
|---|
| 365 | } | 
|---|
| 366 | pciList = xmalloc(sizeof(PCNRITEM) * howmany, pszSrcFile, __LINE__); | 
|---|
| 367 | if (pciList) { | 
|---|
| 368 | for (x = 0; filename[x] && x < howmany; x++) { | 
|---|
| 369 | if (IsFullName(filename[x])) { | 
|---|
| 370 | if (driveflags[toupper(*filename[x]) - 'A'] & DRIVE_NOTWRITEABLE) | 
|---|
| 371 | /* ignore non-writeable drives */ | 
|---|
| 372 | continue; | 
|---|
| 373 | } | 
|---|
| 374 | hDir = HDIR_CREATE; | 
|---|
| 375 | status = DosFindFirst(filename[x], | 
|---|
| 376 | &hDir, | 
|---|
| 377 | FILE_NORMAL | FILE_DIRECTORY | | 
|---|
| 378 | FILE_ARCHIVED | FILE_READONLY | | 
|---|
| 379 | FILE_HIDDEN | FILE_SYSTEM, | 
|---|
| 380 | &ffb, sizeof(ffb), &nm, FIL_QUERYEASIZE); | 
|---|
| 381 | if (!status) { | 
|---|
| 382 | /* file exists */ | 
|---|
| 383 | DosFindClose(hDir); | 
|---|
| 384 | //      if(dcd->type == TREE_FRAME && !(ffb.attrFile & FILE_DIRECTORY)) | 
|---|
| 385 | //        continue; | 
|---|
| 386 | if (dcd->type == DIR_FRAME && *dcd->directory) { | 
|---|
| 387 |  | 
|---|
| 388 | CHAR *p, temp; | 
|---|
| 389 |  | 
|---|
| 390 | p = strrchr(filename[x], '\\'); | 
|---|
| 391 | if (p) { | 
|---|
| 392 | if (p < filename[x] + 3) | 
|---|
| 393 | p++; | 
|---|
| 394 | temp = *p; | 
|---|
| 395 | *p = 0; | 
|---|
| 396 | if (stricmp(filename[x], dcd->directory)) { | 
|---|
| 397 | *p = temp; | 
|---|
| 398 | continue; | 
|---|
| 399 | } | 
|---|
| 400 | *p = temp; | 
|---|
| 401 | } | 
|---|
| 402 | else | 
|---|
| 403 | continue; | 
|---|
| 404 | } | 
|---|
| 405 | ret = TRUE; | 
|---|
| 406 | pci = FindCnrRecord(hwndCnr, | 
|---|
| 407 | filename[x], | 
|---|
| 408 | (PCNRITEM) NULL, partial, FALSE, TRUE); | 
|---|
| 409 | if (pci) { | 
|---|
| 410 | /* update record? */ | 
|---|
| 411 | if ((!fForceUpper && !fForceLower && | 
|---|
| 412 | strcmp(pci->szFileName, filename[x])) || | 
|---|
| 413 | pci->cbFile != ffb.cbFile || pci->attrFile != ffb.attrFile || | 
|---|
| 414 | pci->easize != CBLIST_TO_EASIZE(ffb.cbList) || | 
|---|
| 415 | pci->date.day != ffb.fdateLastWrite.day || | 
|---|
| 416 | pci->date.month != ffb.fdateLastWrite.month || | 
|---|
| 417 | pci->date.year != ffb.fdateLastWrite.year + 1980 || | 
|---|
| 418 | pci->time.seconds != ffb.ftimeLastWrite.twosecs * 2 || | 
|---|
| 419 | pci->time.minutes != ffb.ftimeLastWrite.minutes || | 
|---|
| 420 | pci->time.hours != ffb.ftimeLastWrite.hours || | 
|---|
| 421 | pci->ladate.day != ffb.fdateLastAccess.day || | 
|---|
| 422 | pci->ladate.month != ffb.fdateLastAccess.month || | 
|---|
| 423 | pci->ladate.year != ffb.fdateLastAccess.year + 1980 || | 
|---|
| 424 | pci->latime.seconds != ffb.ftimeLastAccess.twosecs * 2 || | 
|---|
| 425 | pci->latime.minutes != ffb.ftimeLastAccess.minutes || | 
|---|
| 426 | pci->latime.hours != ffb.ftimeLastAccess.hours) { | 
|---|
| 427 | /* changed; update */ | 
|---|
| 428 | pciList[numlist++] = pci; | 
|---|
| 429 | *ffb.achName = 0; | 
|---|
| 430 | ffb.cchName = 0; | 
|---|
| 431 | FillInRecordFromFFB(hwndCnr, | 
|---|
| 432 | pci, filename[x], &ffb, partial, dcd); | 
|---|
| 433 | if (IsRoot(pci->szFileName)) | 
|---|
| 434 | SelectDriveIcon(pci); | 
|---|
| 435 | WinSendMsg(hwndCnr, | 
|---|
| 436 | CM_SETRECORDEMPHASIS, | 
|---|
| 437 | MPFROMP(pci), | 
|---|
| 438 | MPFROM2SHORT(FALSE, CRA_SELECTED | CRA_CURSORED)); | 
|---|
| 439 | } | 
|---|
| 440 | } | 
|---|
| 441 | else { | 
|---|
| 442 | /* add record */ | 
|---|
| 443 | if (dcd->type == DIR_FRAME) { | 
|---|
| 444 | RECORDINSERT ri; | 
|---|
| 445 | ULONGLONG ullTotalBytes; | 
|---|
| 446 |  | 
|---|
| 447 | pci = WinSendMsg(hwndCnr, | 
|---|
| 448 | CM_ALLOCRECORD, | 
|---|
| 449 | MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1L)); | 
|---|
| 450 | if (pci) { | 
|---|
| 451 | ret = TRUE; | 
|---|
| 452 | *ffb.achName = 0; | 
|---|
| 453 | ullTotalBytes = FillInRecordFromFFB(hwndCnr, | 
|---|
| 454 | pci, | 
|---|
| 455 | filename[x], | 
|---|
| 456 | &ffb, partial, dcd); | 
|---|
| 457 | if (strlen(pci->szFileName) < 4) | 
|---|
| 458 | SelectDriveIcon(pci); | 
|---|
| 459 | memset(&ri, 0, sizeof(RECORDINSERT)); | 
|---|
| 460 | ri.cb = sizeof(RECORDINSERT); | 
|---|
| 461 | ri.pRecordOrder = (PRECORDCORE) CMA_END; | 
|---|
| 462 | ri.pRecordParent = (PRECORDCORE) NULL; | 
|---|
| 463 | ri.zOrder = (USHORT) CMA_TOP; | 
|---|
| 464 | ri.cRecordsInsert = 1L; | 
|---|
| 465 | ri.fInvalidateRecord = FALSE; | 
|---|
| 466 | if (WinSendMsg(hwndCnr, | 
|---|
| 467 | CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) { | 
|---|
| 468 | if (ullTotalBytes) { | 
|---|
| 469 | dcd->ullTotalBytes += ullTotalBytes; | 
|---|
| 470 | numremain++; | 
|---|
| 471 | } | 
|---|
| 472 | repos = TRUE; | 
|---|
| 473 | if (pci->attrFile & FILE_DIRECTORY) | 
|---|
| 474 | Stubby(hwndCnr, pci); | 
|---|
| 475 | } | 
|---|
| 476 | else | 
|---|
| 477 | WinSendMsg(hwndCnr, | 
|---|
| 478 | CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(1)); | 
|---|
| 479 | } | 
|---|
| 480 | } | 
|---|
| 481 | else if (ffb.attrFile & FILE_DIRECTORY) { | 
|---|
| 482 | /* check all parts and insert as required */ | 
|---|
| 483 | CHAR *p, temp; | 
|---|
| 484 | PCNRITEM pciParent = NULL, pciT; | 
|---|
| 485 |  | 
|---|
| 486 | p = strchr(filename[x], '\\'); | 
|---|
| 487 | if (p) { | 
|---|
| 488 | while (p && *p) { | 
|---|
| 489 | if (p < filename[x] + 3) | 
|---|
| 490 | p++; | 
|---|
| 491 | temp = *p; | 
|---|
| 492 | *p = 0; | 
|---|
| 493 | pciT = FindCnrRecord(hwndCnr, | 
|---|
| 494 | filename[x], NULL, partial, FALSE, TRUE); | 
|---|
| 495 | if (!pciT || (INT) pciT == -1) { | 
|---|
| 496 | pci = WinSendMsg(hwndCnr, | 
|---|
| 497 | CM_ALLOCRECORD, | 
|---|
| 498 | MPFROMLONG(EXTRA_RECORD_BYTES), | 
|---|
| 499 | MPFROMLONG(1L)); | 
|---|
| 500 | if (pci) { | 
|---|
| 501 |  | 
|---|
| 502 | RECORDINSERT ri; | 
|---|
| 503 | ULONGLONG ullTotalBytes; | 
|---|
| 504 |  | 
|---|
| 505 | ret = TRUE; | 
|---|
| 506 | *ffb.achName = 0; | 
|---|
| 507 | ullTotalBytes = FillInRecordFromFFB(hwndCnr, | 
|---|
| 508 | pci, | 
|---|
| 509 | filename[x], | 
|---|
| 510 | &ffb, partial, dcd); | 
|---|
| 511 | if (strlen(pci->szFileName) < 4) | 
|---|
| 512 | SelectDriveIcon(pci); | 
|---|
| 513 | memset(&ri, 0, sizeof(RECORDINSERT)); | 
|---|
| 514 | ri.cb = sizeof(RECORDINSERT); | 
|---|
| 515 | ri.pRecordOrder = (PRECORDCORE) CMA_END; | 
|---|
| 516 | ri.pRecordParent = (PRECORDCORE) pciParent; | 
|---|
| 517 | ri.zOrder = (USHORT) CMA_TOP; | 
|---|
| 518 | ri.cRecordsInsert = 1L; | 
|---|
| 519 | ri.fInvalidateRecord = FALSE; | 
|---|
| 520 | if (WinSendMsg(hwndCnr, | 
|---|
| 521 | CM_INSERTRECORD, | 
|---|
| 522 | MPFROMP(pci), MPFROMP(&ri))) { | 
|---|
| 523 | if (ullTotalBytes) { | 
|---|
| 524 | numremain++; | 
|---|
| 525 | if (dcd->type == DIR_FRAME) | 
|---|
| 526 | dcd->ullTotalBytes += ullTotalBytes; | 
|---|
| 527 | } | 
|---|
| 528 | repos = TRUE; | 
|---|
| 529 | } | 
|---|
| 530 | else | 
|---|
| 531 | WinSendMsg(hwndCnr, | 
|---|
| 532 | CM_FREERECORD, | 
|---|
| 533 | MPFROMP(&pci), MPFROMSHORT(1)); | 
|---|
| 534 | } | 
|---|
| 535 | } | 
|---|
| 536 | else | 
|---|
| 537 | pciParent = pciT; | 
|---|
| 538 | *p = temp; | 
|---|
| 539 | p = strchr(p + ((temp == '\\') ? 1 : 0), '\\'); | 
|---|
| 540 | } | 
|---|
| 541 | } | 
|---|
| 542 | { | 
|---|
| 543 | pci = WinSendMsg(hwndCnr, | 
|---|
| 544 | CM_ALLOCRECORD, | 
|---|
| 545 | MPFROMLONG(EXTRA_RECORD_BYTES), | 
|---|
| 546 | MPFROMLONG(1L)); | 
|---|
| 547 | if (pci) { | 
|---|
| 548 |  | 
|---|
| 549 | RECORDINSERT ri; | 
|---|
| 550 | ULONGLONG ullTotalBytes; | 
|---|
| 551 |  | 
|---|
| 552 | ret = TRUE; | 
|---|
| 553 | *ffb.achName = 0; | 
|---|
| 554 | ullTotalBytes = FillInRecordFromFFB(hwndCnr, | 
|---|
| 555 | pci, | 
|---|
| 556 | filename[x], | 
|---|
| 557 | &ffb, partial, dcd); | 
|---|
| 558 | if (strlen(pci->szFileName) < 4) | 
|---|
| 559 | SelectDriveIcon(pci); | 
|---|
| 560 | memset(&ri, 0, sizeof(RECORDINSERT)); | 
|---|
| 561 | ri.cb = sizeof(RECORDINSERT); | 
|---|
| 562 | ri.pRecordOrder = (PRECORDCORE) CMA_END; | 
|---|
| 563 | ri.pRecordParent = (PRECORDCORE) pciParent; | 
|---|
| 564 | ri.zOrder = (USHORT) CMA_TOP; | 
|---|
| 565 | ri.cRecordsInsert = 1L; | 
|---|
| 566 | ri.fInvalidateRecord = FALSE; | 
|---|
| 567 | if (WinSendMsg(hwndCnr, | 
|---|
| 568 | CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) { | 
|---|
| 569 | if (ullTotalBytes) { | 
|---|
| 570 | numremain++; | 
|---|
| 571 | if (dcd->type == DIR_FRAME) | 
|---|
| 572 | dcd->ullTotalBytes += ullTotalBytes; | 
|---|
| 573 | } | 
|---|
| 574 | repos = TRUE; | 
|---|
| 575 | Stubby(hwndCnr, pci); | 
|---|
| 576 | } | 
|---|
| 577 | else | 
|---|
| 578 | WinSendMsg(hwndCnr, | 
|---|
| 579 | CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(1)); | 
|---|
| 580 | } | 
|---|
| 581 | } | 
|---|
| 582 | } | 
|---|
| 583 | } | 
|---|
| 584 | } | 
|---|
| 585 | else if ((pci = FindCnrRecord(hwndCnr, | 
|---|
| 586 | filename[x], | 
|---|
| 587 | (PCNRITEM) NULL, | 
|---|
| 588 | partial, | 
|---|
| 589 | FALSE, | 
|---|
| 590 | TRUE)) != NULL && | 
|---|
| 591 | (INT) pci != -1 && !IsRoot(pci->szFileName)) { | 
|---|
| 592 | /* file doesn't exist; delete record */ | 
|---|
| 593 | if (pci->rc.flRecordAttr & CRA_SELECTED) | 
|---|
| 594 | WinSendMsg(hwndCnr, | 
|---|
| 595 | CM_SETRECORDEMPHASIS, | 
|---|
| 596 | MPFROMP(pci), MPFROM2SHORT(FALSE, CRA_SELECTED)); | 
|---|
| 597 | if (dcd->type == DIR_FRAME) | 
|---|
| 598 | dcd->ullTotalBytes -= (pci->cbFile + pci->easize); | 
|---|
| 599 | if (WinSendMsg(hwndCnr, | 
|---|
| 600 | CM_REMOVERECORD, | 
|---|
| 601 | MPFROMP(&pci), | 
|---|
| 602 | MPFROM2SHORT(1, | 
|---|
| 603 | CMA_FREE | (numremain == | 
|---|
| 604 | 1 ? CMA_INVALIDATE : 0)))) { | 
|---|
| 605 | numremain--; | 
|---|
| 606 | repos = TRUE; | 
|---|
| 607 | } | 
|---|
| 608 | } | 
|---|
| 609 | }                                   // for | 
|---|
| 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 | } | 
|---|