source: trunk/dll/filldir.c@ 214

Last change on this file since 214 was 214, checked in by root, 20 years ago

Rework WinLoadFileIcon enables
Rework IDFile

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.3 KB
RevLine 
[31]1
2/***********************************************************************
3
4 $Id: filldir.c 214 2005-06-18 03:51:49Z root $
5
6 Fill Directory Tree Containers
7
8 Copyright (c) 1993-98 M. Kimes
[167]9 Copyright (c) 2001, 2005 Steven H. Levine
[31]10
[145]11 12 Sep 02 SHL Rework symbols to understand code
12 08 Feb 03 SHL DropHelp: calc EA size consistently
13 11 Jun 03 SHL Add JFS and FAT32 support
14 10 Jan 04 SHL ProcessDirectory: avoid most large drive failures
15 24 May 05 SHL Rework Win_Error usage
[167]16 24 May 05 SHL Rework for CNRITEM.szSubject
17 25 May 05 SHL Rework for ULONGLONG
18 25 May 05 SHL Rework FillInRecordFromFFB
19 25 May 05 SHL Rework FillTreeCnr
[174]20 28 May 05 SHL Drop stale debug code
[188]21 05 Jun 05 SHL Comments
[214]22 09 Jun 05 SHL Rework WinLoadFileIcon enables
23 09 Jun 05 SHL Rework IDFile
[31]24
25***********************************************************************/
26
[2]27#define INCL_DOS
28#define INCL_WIN
[167]29#define INCL_LONGLONG
30#include <os2.h>
[2]31
32#include <stdarg.h>
33#include <stdio.h>
34#include <stdlib.h>
35#include <string.h>
36#include <ctype.h>
37#include <time.h>
[167]38
[2]39#include "fm3dll.h"
40#include "fm3str.h"
41
42#pragma alloc_text(FILLDIR,FillInRecordFromFFB,FillInRecordFromFSA,IDFile)
43#pragma alloc_text(FILLDIR1,ProcessDirectory,FillDirCnr,FillTreeCnr)
44
45
[214]46static HPOINTER IDFile(PSZ p)
[90]47{
[2]48 HPOINTER hptr;
[214]49 ULONG cmp;
50 CHAR cmps[4];
[2]51
[214]52 p = strrchr(p,'.');
53 if (p && !p[4])
54 {
55 cmps[0] = '.';
56 cmps[1] = toupper(p[1]);
57 cmps[2] = toupper(p[2]);
58 cmps[3] = toupper(p[3]);
59
60 cmp = *(ULONG *)cmps;
61
62 if (cmp == *(ULONG *)".EXE" || cmp == *(ULONG *)".CMD" ||
63 cmp == *(ULONG *)".BAT" || cmp == *(ULONG *)".COM")
64 hptr = hptrApp;
65 else if (cmp == *(ULONG *)".ZIP" || cmp == *(ULONG *)".LZH" ||
66 cmp == *(ULONG *)".ARJ" || cmp == *(ULONG *)".ARC" ||
67 cmp == *(ULONG *)".ZOO" || cmp == *(ULONG *)".RAR")
68 hptr = hptrArc;
69 else if (cmp == *(ULONG *)".BMP" || cmp == *(ULONG *)".ICO" ||
70 cmp == *(ULONG *)".PTR" || cmp == *(ULONG *)".GIF" ||
71 cmp == *(ULONG *)".TIF" || cmp == *(ULONG *)".PCX" ||
72 cmp == *(ULONG *)".TGA" || cmp == *(ULONG *)".XBM")
73 hptr = hptrArt;
74 else
75 hptr = (HPOINTER)0;
76 }
77 else
78 hptr = (HPOINTER)0;
79
[2]80 return hptr;
81}
82
83
[214]84static BOOL IsDefaultIcon(HPOINTER hptr)
85{
86 HPOINTER hptr2;
87 HPOINTER hptr3;
88 LONG l;
89 UINT u;
90
91 static HPOINTER hptrPMFile;
92 static HPOINTER hptrWPSFile;
93
94 if (!hptrPMFile)
95 {
96# if 0 // fixme to be gone
97 for (l = 1; l <= SPTR_CPTR; l++)
98 {
99 hptr3 = WinQuerySysPointer(HWND_DESKTOP,l,FALSE);
100 fprintf(stderr, "0x%08lx SPTR %ld\n", hptr3, l);
101 }
102# endif // fixme to be gone
103 hptrPMFile = WinQuerySysPointer(HWND_DESKTOP,SPTR_FILE,FALSE);
104 }
105# if 0 // fixme to be gone
106 else
107 {
108 hptr2 = WinQuerySysPointer(HWND_DESKTOP,SPTR_FILE,FALSE);
109 if (hptr2 != hptrPMFile)
110 {
111 saymsg(0, NULLHANDLE, "*Debug*", "ptr changed from %lx to %lx", hptrPMFile, hptr2);
112 hptrPMFile = hptr2;
113 fprintf(stderr, "0x%08lx SPTR_FILE changed\n", hptrPMFile);
114 }
115 }
116# endif // fixme to be gone
117
118 // try to guess WPS default file icon
119 hptr2 = (HPOINTER)0;
120 for (u = 0; !hptrWPSFile && u < 10; u++)
121 {
122 char szFileName[CCHMAXPATH];
123 char *psz;
124
125 psz = getenv("TMP");
126 if (!psz && *psz)
127 psz = getenv("TEMP");
128 if (psz && *psz)
129 {
130 strcpy(szFileName, psz);
131 psz = szFileName + strlen(szFileName) - 1;
132 if (*psz != '\\')
133 {
134 psz++;
135 *psz++ = '\\';
136 }
137 }
138 else
139 psz = szFileName;
140
141 sprintf(psz,"%08x.%03x",rand() & 0xffffffff, rand() & 0xfff);
142 if (IsFile(szFileName) != 1)
143 {
144 FILE *fp = fopen(szFileName,"w");
145 if (fp)
146 {
147 fclose(fp);
148 hptr3 = WinLoadFileIcon(szFileName, FALSE);
149# if 0 // fixme to be gone
150 fprintf(stderr, "0x%08lx %s\n", hptr3, szFileName);
151# endif // fixme to be gone
152 unlinkf("%s", szFileName);
153 if (!hptr2)
154 hptr2 = hptr3;
155 else if (hptr3 == hptr3)
156 {
157 hptrWPSFile = hptr3; // Got same icon twice
158 break;
159 }
160 }
161 }
162 DosSleep(rand() % 100);
163
164 } // for
165
166 return hptr == hptrPMFile || hptr == hptrWPSFile;
167
168} // IsDefaultIcon
169
170
[167]171ULONGLONG FillInRecordFromFFB(HWND hwndCnr,PCNRITEM pci, const PSZ pszDirectory,
[214]172 const PFILEFINDBUF4 pffb,const BOOL partial,
173 DIRCNRDATA *dcd)
[31]174{
[2]175 /* fill in a container record from a FILEFINDBUF4 structure */
176
[167]177 CHAR attrstring[] = "RHS\0DA";
178 CHAR *p;
179 HPOINTER hptr;
180 UINT x;
181 UINT y;
182 UINT t;
[2]183
184 pci->hwndCnr = hwndCnr;
185 t = strlen(pszDirectory);
186 memcpy(pci->szFileName,pszDirectory,t + 1);
187 /* note! we cheat below, and accept the full pathname in pszDirectory
188 if !*pffb->achName. speeds up and simplifies processing elsewhere
[167]189 (like in update.c)
190 */
191 if (*pffb->achName)
192 {
[2]193 p = pci->szFileName + (t - 1);
[167]194 if (*p != '\\') {
[2]195 p++;
196 *p = '\\';
197 }
198 p++;
199 memcpy(p,pffb->achName,pffb->cchName + 1);
200 }
201 /* load the object's Subject, if required */
[167]202 if (pffb->cbList > 4L &&
203 dcd && fLoadSubject &&
204 (isalpha(*pci->szFileName) &&
205 !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADSUBJS)))
206 {
[2]207 APIRET rc;
208 EAOP2 eaop;
209 PGEA2LIST pgealist;
210 PFEA2LIST pfealist;
211 PGEA2 pgea;
212 PFEA2 pfea;
213 CHAR *value;
214
215 pgealist = malloc(sizeof(GEA2LIST) + 32);
[167]216 if (pgealist)
217 {
[2]218 memset(pgealist,0,sizeof(GEA2LIST) + 32);
219 pgea = &pgealist->list[0];
220 strcpy(pgea->szName,SUBJECT);
221 pgea->cbName = strlen(pgea->szName);
[188]222 pgea->oNextEntryOffset = 0;
[2]223 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
224 pfealist = malloc(1532);
[167]225 if (pfealist)
226 {
[214]227 memset(pfealist,0,1532);
228 pfealist->cbList = 1024;
229 eaop.fpGEA2List = pgealist;
230 eaop.fpFEA2List = pfealist;
231 eaop.oError = 0;
232 rc = DosQueryPathInfo(pci->szFileName,FIL_QUERYEASFROMLIST,
233 (PVOID)&eaop,(ULONG)sizeof(EAOP2));
234 if (!rc) {
235 pfea = &eaop.fpFEA2List->list[0];
236 value = pfea->szName + pfea->cbName + 1;
237 value[pfea->cbValue] = 0;
238 if (*(USHORT *)value == EAT_ASCII)
239 strncpy(pci->szSubject,value + (sizeof(USHORT) * 2),39);
240 pci->szSubject[39] = 0;
241 }
242 free(pfealist);
[2]243 }
244 free(pgealist);
245 }
246 }
[167]247 pci->pszSubject = pci->szSubject;
[2]248 /* load the object's longname */
[167]249 *pci->szLongname = 0;
250 if (pffb->cbList > 4L &&
251 dcd && fLoadLongnames &&
252 (isalpha(*pci->szFileName) &&
253 (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLONGNAMES) &&
254 !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADLONGS)))
255 {
[2]256 APIRET rc;
257 EAOP2 eaop;
258 PGEA2LIST pgealist;
259 PFEA2LIST pfealist;
260 PGEA2 pgea;
261 PFEA2 pfea;
262 CHAR *value;
263
264 pgealist = malloc(sizeof(GEA2LIST) + 32);
[167]265 if (pgealist)
266 {
[2]267 memset(pgealist,0,sizeof(GEA2LIST) + 32);
268 pgea = &pgealist->list[0];
269 strcpy(pgea->szName,LONGNAME);
270 pgea->cbName = strlen(pgea->szName);
[188]271 pgea->oNextEntryOffset = 0;
[2]272 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
273 pfealist = malloc(1532);
[167]274 if (pfealist) {
[214]275 memset(pfealist,0,1532);
276 pfealist->cbList = 1024;
277 eaop.fpGEA2List = pgealist;
278 eaop.fpFEA2List = pfealist;
279 eaop.oError = 0;
280 rc = DosQueryPathInfo(pci->szFileName,FIL_QUERYEASFROMLIST,
281 (PVOID)&eaop,(ULONG)sizeof(EAOP2));
282 if (!rc)
[167]283 {
[214]284 pfea = &eaop.fpFEA2List->list[0];
285 value = pfea->szName + pfea->cbName + 1;
286 value[pfea->cbValue] = 0;
287 if (*(USHORT *)value == EAT_ASCII)
288 strncpy(pci->szLongname,value + (sizeof(USHORT) * 2),CCHMAXPATHCOMP);
289 pci->szLongname[CCHMAXPATHCOMP - 1] = 0;
290 }
291 free(pfealist);
[2]292 }
293 free(pgealist);
294 }
295 }
[167]296 pci->pszLongname = pci->szLongname;
[2]297
298 /* do anything required to case of filename */
[167]299 if (fForceUpper)
[2]300 strupr(pci->szFileName);
[167]301 else if (fForceLower)
[2]302 strlwr(pci->szFileName);
303
304 /* get an icon to use with it */
[167]305 if (pffb->attrFile & FILE_DIRECTORY)
306 {
[214]307 // is directory
308 if (fNoIconsDirs ||
309 (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADICONS) ||
310 !isalpha(*pci->szFileName))
311 {
312 hptr = (HPOINTER)0;
313 }
314 else
[2]315 hptr = WinLoadFileIcon(pci->szFileName, FALSE);
316 }
[167]317 else
318 {
[214]319 // is file
320 if (fNoIconsFiles ||
321 (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADICONS) ||
322 !isalpha(*pci->szFileName))
[167]323 {
[214]324 hptr = (HPOINTER)0;
[167]325 }
[42]326 else
[214]327 hptr = WinLoadFileIcon(pci->szFileName, FALSE);
[167]328
[214]329 if (!hptr || IsDefaultIcon(hptr))
330 hptr = IDFile(pci->szFileName);
[2]331 }
[214]332
[167]333 if (!hptr)
334 {
[214]335 hptr = pffb->attrFile & FILE_DIRECTORY ?
336 hptrDir :
337 pffb->attrFile & FILE_SYSTEM ?
338 hptrSystem :
339 pffb->attrFile & FILE_HIDDEN ?
340 hptrHidden :
341 pffb->attrFile & FILE_READONLY ?
342 hptrReadonly :
343 hptrFile;
[167]344 }
[2]345
346 /* decide where to point for the container's title text */
[167]347 if (partial)
348 {
[2]349 p = strrchr(pci->szFileName,'\\');
[167]350 if (!p)
351 {
[2]352 p = strrchr(pci->szFileName,':');
[167]353 if (!p)
[214]354 p = pci->szFileName;
[2]355 else
[214]356 p++;
[2]357 }
[167]358 else if ((dcd && dcd->type == TREE_FRAME) ||
[214]359 (!(pffb->attrFile & FILE_DIRECTORY) || !*(p + 1)))
[167]360 {
[2]361 p++;
[167]362 }
363 if (!*p)
[2]364 p = pci->szFileName;
365 }
366 else
367 p = pci->szFileName;
368 /* now fill the darned thing in... */
369 pci->pszFileName = p;
370 pci->date.day = pffb->fdateLastWrite.day;
371 pci->date.month = pffb->fdateLastWrite.month;
372 pci->date.year = pffb->fdateLastWrite.year + 1980;
373 pci->time.seconds = pffb->ftimeLastWrite.twosecs * 2;
374 pci->time.minutes = pffb->ftimeLastWrite.minutes;
375 pci->time.hours = pffb->ftimeLastWrite.hours;
376 pci->ladate.day = pffb->fdateLastAccess.day;
377 pci->ladate.month = pffb->fdateLastAccess.month;
378 pci->ladate.year = pffb->fdateLastAccess.year + 1980;
379 pci->latime.seconds = pffb->ftimeLastAccess.twosecs * 2;
380 pci->latime.minutes = pffb->ftimeLastAccess.minutes;
381 pci->latime.hours = pffb->ftimeLastAccess.hours;
382 pci->crdate.day = pffb->fdateCreation.day;
383 pci->crdate.month = pffb->fdateCreation.month;
384 pci->crdate.year = pffb->fdateCreation.year + 1980;
385 pci->crtime.seconds = pffb->ftimeCreation.twosecs * 2;
386 pci->crtime.minutes = pffb->ftimeCreation.minutes;
387 pci->crtime.hours = pffb->ftimeCreation.hours;
[51]388 pci->easize = CBLIST_TO_EASIZE(pffb->cbList);
[2]389 pci->cbFile = pffb->cbFile;
390 pci->attrFile = pffb->attrFile;
391 /* build attribute string for display */
392 y = 0;
[167]393 for (x = 0; x < 6; x++)
394 {
395 if (attrstring[x])
396 {
397 pci->szDispAttr[y++] =
[214]398 (CHAR)((pci->attrFile & (1 << x)) ? attrstring[x] : '-');
[167]399 }
400 }
[2]401 pci->szDispAttr[5] = 0;
402 pci->pszDispAttr = pci->szDispAttr;
403 pci->rc.pszIcon = pci->pszFileName;
404 pci->rc.hptrIcon = hptr;
405
406 /* check to see if record should be visible */
[167]407 if (dcd && (*dcd->mask.szMask || dcd->mask.antiattr ||
408 ((dcd->mask.attrFile &
409 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)) !=
410 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))))
411 {
412 if (*dcd->mask.szMask || dcd->mask.antiattr)
413 {
[2]414 if(!Filter((PMINIRECORDCORE)pci,(PVOID)&dcd->mask))
[214]415 pci->rc.flRecordAttr |= CRA_FILTERED;
[2]416 }
417 else if((!(dcd->mask.attrFile & FILE_HIDDEN) &&
[214]418 (pci->attrFile & FILE_HIDDEN)) ||
419 (!(dcd->mask.attrFile & FILE_SYSTEM) &&
420 (pci->attrFile & FILE_SYSTEM)) ||
421 (!(dcd->mask.attrFile & FILE_READONLY) &&
422 (pci->attrFile & FILE_READONLY)) ||
423 (!(dcd->mask.attrFile & FILE_ARCHIVED) &&
424 (pci->attrFile & FILE_ARCHIVED)))
[167]425 {
[2]426 pci->rc.flRecordAttr |= CRA_FILTERED;
[167]427 }
[2]428 }
429
430 return pffb->cbFile + pci->easize;
431
[167]432} // FillInRecordFromFFB
[2]433
[167]434
435ULONGLONG FillInRecordFromFSA(HWND hwndCnr,
[214]436 PCNRITEM pci,
[167]437 const PSZ pszFileName,
[214]438 const PFILESTATUS4 pfsa4,
439 const BOOL partial,
440 DIRCNRDATA *dcd) // Optional
[31]441{
[2]442 HPOINTER hptr;
[167]443 CHAR attrstring[] = "RHS\0DA";
[2]444 register CHAR *p;
[167]445 register INT x;
446 register INT y;
[2]447
448 /* fill in a container record from a FILESTATUS4 structure */
449
450 pci->hwndCnr = hwndCnr;
451 strcpy(pci->szFileName,pszFileName);
452 /* load the object's Subject, if required */
[167]453 if (pfsa4->cbList > 4L &&
454 dcd &&
455 fLoadSubject &&
456 (!isalpha(*pci->szFileName) ||
457 !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADSUBJS)))
458 {
[2]459 APIRET rc;
460 EAOP2 eaop;
461 PGEA2LIST pgealist;
462 PFEA2LIST pfealist;
463 PGEA2 pgea;
464 PFEA2 pfea;
465 CHAR *value;
466
467 pgealist = malloc(sizeof(GEA2LIST) + 32);
[167]468 if (pgealist) {
[2]469 memset(pgealist,0,sizeof(GEA2LIST) + 32);
470 pgea = &pgealist->list[0];
471 strcpy(pgea->szName,SUBJECT);
472 pgea->cbName = strlen(pgea->szName);
[188]473 pgea->oNextEntryOffset = 0;
[2]474 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
475 pfealist = malloc(1532);
[167]476 if (pfealist) {
[214]477 memset(pfealist,0,1532);
478 pfealist->cbList = 1024;
479 eaop.fpGEA2List = pgealist;
480 eaop.fpFEA2List = pfealist;
481 eaop.oError = 0;
482 rc = DosQueryPathInfo(pci->szFileName,FIL_QUERYEASFROMLIST,
483 (PVOID)&eaop,
484 (ULONG)sizeof(EAOP2));
485 if (!rc) {
486 pfea = &eaop.fpFEA2List->list[0];
487 value = pfea->szName + pfea->cbName + 1;
488 value[pfea->cbValue] = 0;
489 if (*(USHORT *)value == EAT_ASCII)
490 strncpy(pci->szSubject,value + (sizeof(USHORT) * 2),39);
491 pci->szSubject[39] = 0;
492 }
493 free(pfealist);
[2]494 }
495 free(pgealist);
496 }
497 }
[167]498 pci->pszSubject = pci->szSubject;
499 *pci->szLongname = 0;
500 if (pfsa4->cbList > 4L &&
501 dcd &&
502 fLoadLongnames &&
503 (!isalpha(*pci->szFileName) ||
504 ((driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLONGNAMES) &&
505 !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADLONGS))))
[51]506 {
[2]507 APIRET rc;
508 EAOP2 eaop;
509 PGEA2LIST pgealist;
510 PFEA2LIST pfealist;
511 PGEA2 pgea;
512 PFEA2 pfea;
513 CHAR *value;
514
515 pgealist = malloc(sizeof(GEA2LIST) + 32);
[167]516 if (pgealist) {
[2]517 memset(pgealist,0,sizeof(GEA2LIST) + 32);
518 pgea = &pgealist->list[0];
519 strcpy(pgea->szName,LONGNAME);
520 pgea->cbName = strlen(pgea->szName);
[188]521 pgea->oNextEntryOffset = 0;
[2]522 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
523 pfealist = malloc(1532);
[167]524 if (pfealist) {
[214]525 memset(pfealist,0,1532);
526 pfealist->cbList = 1024;
527 eaop.fpGEA2List = pgealist;
528 eaop.fpFEA2List = pfealist;
529 eaop.oError = 0;
530 rc = DosQueryPathInfo(pci->szFileName,FIL_QUERYEASFROMLIST,
531 (PVOID)&eaop,(ULONG)sizeof(EAOP2));
532 if (!rc) {
533 pfea = &eaop.fpFEA2List->list[0];
534 value = pfea->szName + pfea->cbName + 1;
535 value[pfea->cbValue] = 0;
536 if (*(USHORT *)value == EAT_ASCII)
537 strncpy(pci->szLongname,value + (sizeof(USHORT) * 2),CCHMAXPATHCOMP);
538 pci->szLongname[CCHMAXPATHCOMP - 1] = 0;
539 }
540 free(pfealist);
[2]541 }
542 free(pgealist);
543 }
544 }
[167]545 pci->pszLongname = pci->szLongname;
546 if (fForceUpper)
[2]547 strupr(pci->szFileName);
[167]548 else if (fForceLower)
[2]549 strlwr(pci->szFileName);
550
[214]551 if (pfsa4->attrFile & FILE_DIRECTORY)
552 {
553 if (fNoIconsDirs ||
554 (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADICONS) ||
555 !isalpha(*pci->szFileName))
556 {
557 hptr = (HPOINTER)0;
558 }
559 else
[2]560 hptr = WinLoadFileIcon(pci->szFileName, FALSE);
561 }
[167]562 else
563 {
[214]564 if (fNoIconsFiles ||
565 (driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOLOADICONS) ||
566 !isalpha(*pci->szFileName))
[167]567 {
[214]568 hptr = IDFile(pci->szFileName);
[2]569 }
[214]570 else
571 hptr = WinLoadFileIcon(pci->szFileName, FALSE);
[2]572 }
[167]573 if (!hptr)
[214]574 {
575 hptr = pfsa4->attrFile & FILE_DIRECTORY ?
576 hptrDir :
577 pfsa4->attrFile & FILE_SYSTEM ?
578 hptrSystem :
579 pfsa4->attrFile & FILE_HIDDEN ?
580 hptrHidden :
581 pfsa4->attrFile & FILE_READONLY ?
582 hptrReadonly :
583 hptrFile;
584 }
[2]585
[214]586 if (partial)
587 {
[2]588 p = strrchr(pci->szFileName,'\\');
[167]589 if (!p) {
[214]590 p = strrchr(pci->szFileName,':');
[167]591 if (!p)
[214]592 p = pci->szFileName;
[2]593 else
[214]594 p++;
[2]595 }
[167]596 else if ((dcd && dcd->type == TREE_FRAME) ||
[214]597 !(pfsa4->attrFile & FILE_DIRECTORY) ||
[167]598 !*(p + 1))
[2]599 p++;
[167]600 if (!*p)
[2]601 p = pci->szFileName;
602 }
603 else
604 p = pci->szFileName;
605 pci->pszFileName = p;
606 pci->date.day = pfsa4->fdateLastWrite.day;
607 pci->date.month = pfsa4->fdateLastWrite.month;
608 pci->date.year = pfsa4->fdateLastWrite.year + 1980;
609 pci->time.seconds = pfsa4->ftimeLastWrite.twosecs * 2;
610 pci->time.minutes = pfsa4->ftimeLastWrite.minutes;
611 pci->time.hours = pfsa4->ftimeLastWrite.hours;
612 pci->ladate.day = pfsa4->fdateLastAccess.day;
613 pci->ladate.month = pfsa4->fdateLastAccess.month;
614 pci->ladate.year = pfsa4->fdateLastAccess.year + 1980;
615 pci->latime.seconds = pfsa4->ftimeLastAccess.twosecs * 2;
616 pci->latime.minutes = pfsa4->ftimeLastAccess.minutes;
617 pci->latime.hours = pfsa4->ftimeLastAccess.hours;
618 pci->crdate.day = pfsa4->fdateCreation.day;
619 pci->crdate.month = pfsa4->fdateCreation.month;
620 pci->crdate.year = pfsa4->fdateCreation.year + 1980;
621 pci->crtime.seconds = pfsa4->ftimeCreation.twosecs * 2;
622 pci->crtime.minutes = pfsa4->ftimeCreation.minutes;
623 pci->crtime.hours = pfsa4->ftimeCreation.hours;
[51]624 pci->easize = CBLIST_TO_EASIZE(pfsa4->cbList);
[2]625 pci->cbFile = pfsa4->cbFile;
626 pci->attrFile = pfsa4->attrFile;
627 y = 0;
628 for(x = 0;x < 6;x++)
[167]629 if (attrstring[x])
[2]630 pci->szDispAttr[y++] = (CHAR)((pci->attrFile & (1 << x)) ?
[214]631 attrstring[x] : '-');
[2]632 pci->szDispAttr[5] = 0;
633 pci->pszDispAttr = pci->szDispAttr;
634 pci->rc.pszIcon = pci->pszFileName;
635 pci->rc.hptrIcon = hptr;
636
[167]637 if (dcd &&
638 (*dcd->mask.szMask || dcd->mask.antiattr ||
639 ((dcd->mask.attrFile &
[214]640 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)) !=
641 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))))
[167]642 {
643 if (*dcd->mask.szMask || dcd->mask.antiattr)
644 {
645 if (!Filter((PMINIRECORDCORE)pci,(PVOID)&dcd->mask))
[214]646 pci->rc.flRecordAttr |= CRA_FILTERED;
[2]647 }
[167]648 else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
[214]649 (pci->attrFile & FILE_HIDDEN)) ||
650 (!(dcd->mask.attrFile & FILE_SYSTEM) &&
651 (pci->attrFile & FILE_SYSTEM)) ||
652 (!(dcd->mask.attrFile & FILE_READONLY) &&
653 (pci->attrFile & FILE_READONLY)) ||
654 (!(dcd->mask.attrFile & FILE_ARCHIVED) &&
655 (pci->attrFile & FILE_ARCHIVED)))
[2]656 pci->rc.flRecordAttr |= CRA_FILTERED;
657 }
658
659 return pfsa4->cbFile + pci->easize;
660
[167]661} // FillInRecordFromFSA
[2]662
[167]663
664VOID ProcessDirectory(const HWND hwndCnr, const PCNRITEM pciParent,
[214]665 const CHAR *szDirBase, const BOOL filestoo,
666 const BOOL recurse,const BOOL partial,
667 CHAR *stopflag,
[167]668 DIRCNRDATA *dcd, // Optional
669 ULONG *pulTotalFiles, // Optional
670 PULONGLONG pullTotalBytes) // Optional
[31]671{
[2]672 /* put all the directories (and files if filestoo is TRUE) from a
673 * directory into the container. recurse through subdirectories if
674 * recurse is TRUE.
675 */
676
[42]677 PSZ pszFileSpec;
[2]678 INT t;
[167]679 PFILEFINDBUF4 paffbFound;
680 PFILEFINDBUF4 *papffbSelected;
681 PFILEFINDBUF4 pffbFile;
682 PFILEFINDBUF4 paffbTotal = NULL;
683 PFILEFINDBUF4 paffbTemp;
[2]684 HDIR hdir = HDIR_CREATE;
[167]685 ULONG ulFileCnt;
686 ULONG ulExtraBytes;
687 ULONG ulM = 1;
[188]688 ULONG ulTotal = 0;
[167]689 ULONGLONG ullBytes;
690 ULONGLONG ullTotalBytes;
691 ULONG ulReturnFiles = 0;
692 ULONGLONG ullReturnBytes = 0;
[2]693 PCH pchEndPath;
694 APIRET rc;
[167]695 PCNRITEM pci;
696 PCNRITEM pciFirst;
697 PCNRITEM pcit;
[2]698 RECORDINSERT ri;
[167]699 PBYTE pByte;
700 PBYTE pByte2;
701 BOOL ok = TRUE;
[2]702
[167]703 if (isalpha(*szDirBase) && szDirBase[1] == ':' && szDirBase[2] == '\\')
704 {
705 // if (!(driveflags[toupper(*szDirBase) - 'A'] & DRIVE_NOLONGNAMES))
[2]706 ulExtraBytes = EXTRA_RECORD_BYTES;
[167]707 // else
708 // ulExtraBytes = EXTRA_RECORD_BYTES2;
709 if ((driveflags[toupper(*szDirBase) - 'A'] & DRIVE_REMOTE) && fRemoteBug)
[214]710 ulM = 1; /* file system gets confused */
[167]711 else if (driveflags[toupper(*szDirBase) - 'A'] & DRIVE_ZIPSTREAM)
[2]712 ulM = min(FilesToGet,225); /* anything more is wasted */
713 else
714 ulM = FilesToGet; /* full-out */
715 }
[167]716 else
717 {
[2]718 ulExtraBytes = EXTRA_RECORD_BYTES;
719 ulM = FilesToGet;
720 }
[167]721 if (OS2ver[0] == 20 && OS2ver[1] < 30)
[2]722 ulM = min(ulM,(65535 / sizeof(FILEFINDBUF4)));
723
[167]724 ulFileCnt = ulM;
[42]725 pszFileSpec = malloc(CCHMAXPATH + 2);
[90]726 paffbFound = malloc((ulM + 1) * sizeof(FILEFINDBUF4));
727 papffbSelected = malloc((ulM + 1) * sizeof(PFILEFINDBUF4));
[167]728 if (paffbFound && papffbSelected && pszFileSpec) {
[2]729 t = strlen(szDirBase);
[42]730 memcpy(pszFileSpec,szDirBase,t + 1);
731 pchEndPath = pszFileSpec + t;
[167]732 if (*(pchEndPath - 1) != '\\') {
[2]733 memcpy(pchEndPath,"\\",2);
734 pchEndPath++;
735 }
736 memcpy(pchEndPath,"*",2);
737 DosError(FERR_DISABLEHARDERR);
[42]738 rc = DosFindFirst(pszFileSpec, &hdir,
[214]739 FILE_NORMAL | ((filestoo) ? FILE_DIRECTORY :
740 MUST_HAVE_DIRECTORY) | FILE_READONLY |
741 FILE_ARCHIVED | FILE_SYSTEM | FILE_HIDDEN,
742 paffbFound, ulM * sizeof(FILEFINDBUF4),
743 &ulFileCnt, FIL_QUERYEASIZE);
[2]744 priority_normal();
745 *pchEndPath = 0;
[167]746 if (!rc)
747 {
748 while (!rc)
749 {
[214]750 /*
751 * remove . and .. from list if present
752 * also counter file system bugs that sometimes
753 * allows normal files to slip through when
754 * only directories should appear (only a few
755 * network file systems exhibit such a problem).
756 */
757 register ULONG x;
[2]758
[214]759 if (stopflag && *stopflag)
760 goto Abort;
761 pByte = (PBYTE)paffbFound;
762 for (x = 0;x < ulFileCnt;)
[174]763 {
[214]764 pffbFile = (PFILEFINDBUF4)pByte;
765 if (!*pffbFile->achName ||
766 (!filestoo && !(pffbFile->attrFile & FILE_DIRECTORY)) ||
767 (((pffbFile->attrFile & FILE_DIRECTORY) &&
768 pffbFile->achName[0] == '.') &&
769 (!pffbFile->achName[1] || (pffbFile->achName[1] == '.' &&
770 !pffbFile->achName[2]))))
[174]771 {
[214]772 ulFileCnt--; // Got . or ..
[174]773 }
[214]774 else
775 papffbSelected[x++] = pffbFile; // Count file
776 if (!pffbFile->oNextEntryOffset)
[174]777 {
[214]778 ulFileCnt = x; // Adjust count
779 break;
780 }
781 pByte += pffbFile->oNextEntryOffset;
782 }
783 if (ulFileCnt)
[174]784 {
[214]785 if (stopflag && *stopflag)
786 goto Abort;
787 if (fSyncUpdates)
[167]788 {
[214]789 pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
790 MPFROMLONG(ulExtraBytes),
791 MPFROMLONG(ulFileCnt));
792 if (pciFirst)
[167]793 {
[214]794 register INT i;
[174]795
[214]796 pci = pciFirst;
797 ullTotalBytes = 0;
798 for(i = 0; i < ulFileCnt; i++) {
799 pffbFile = papffbSelected[i];
800 ullBytes = FillInRecordFromFFB(hwndCnr,pci,pszFileSpec,
801 pffbFile,partial,dcd);
802 pci = (PCNRITEM)pci->rc.preccNextRecord;
803 ullTotalBytes += ullBytes;
804 }
805 if (ulFileCnt)
[167]806 {
[214]807 memset(&ri,0,sizeof(RECORDINSERT));
808 ri.cb = sizeof(RECORDINSERT);
809 ri.pRecordOrder = (PRECORDCORE) CMA_END;
810 ri.pRecordParent = (PRECORDCORE) pciParent;
811 ri.zOrder = (ULONG) CMA_TOP;
812 ri.cRecordsInsert = ulFileCnt;
813 ri.fInvalidateRecord = (!fSyncUpdates && dcd &&
814 dcd->type == DIR_FRAME) ?
815 FALSE : TRUE;
816 if (!WinSendMsg(hwndCnr,
817 CM_INSERTRECORD,
818 MPFROMP(pciFirst),
819 MPFROMP(&ri)))
[167]820 {
[214]821 DosSleep(100);
822 WinSetFocus(HWND_DESKTOP,hwndCnr);
823 if (!WinSendMsg(hwndCnr,
824 CM_INSERTRECORD,
825 MPFROMP(pciFirst),
826 MPFROMP(&ri)))
[90]827 {
[214]828 Win_Error(hwndCnr,HWND_DESKTOP,__FILE__,__LINE__,
829 GetPString(IDS_FILLDIRERR2TEXT));
830 ok = FALSE;
831 ullTotalBytes = 0;
832 if (WinIsWindow((HAB)0,hwndCnr))
[174]833 {
[214]834 pci = pciFirst;
835 while (pci)
[167]836 {
[214]837 pcit = (PCNRITEM)pci->rc.preccNextRecord;
838 WinSendMsg(hwndCnr,
839 CM_FREERECORD,
840 MPFROMP(&pci),
841 MPFROMSHORT(1));
842 pci = pcit;
843 }
844 }
845 }
846 }
847 }
848 }
849 else
[167]850 {
[214]851 Win_Error(hwndCnr,HWND_DESKTOP,__FILE__,__LINE__,
852 GetPString(IDS_FILLDIRERR3TEXT));
853 ok = FALSE;
854 ullTotalBytes = 0;
855 }
856 if (ok)
[174]857 {
[214]858 ullReturnBytes += ullTotalBytes;
859 ulReturnFiles += ulFileCnt;
860 }
861 }
862 else
[174]863 {
[214]864 paffbTemp = realloc(paffbTotal,sizeof(FILEFINDBUF4) *
865 (ulFileCnt + ulTotal));
866 if (paffbTemp)
[174]867 {
[214]868 paffbTotal = paffbTemp;
869 for(x = 0;x < ulFileCnt;x++)
870 paffbTotal[x + ulTotal] = *papffbSelected[x];
871 ulTotal += ulFileCnt;
872 }
873 else
[174]874 {
[214]875 saymsg(MB_ENTER,
876 HWND_DESKTOP,
877 GetPString(IDS_ERRORTEXT),
878 GetPString(IDS_OUTOFMEMORY));
879 break;
880 }
881 }
882 }
883 if (stopflag && *stopflag)
884 goto Abort;
885 ulFileCnt = ulM;
886 DosError(FERR_DISABLEHARDERR);
887 rc = DosFindNext(hdir, paffbFound, ulM * sizeof(FILEFINDBUF4),
888 &ulFileCnt);
889 priority_normal();
890 if (rc)
891 DosError(FERR_DISABLEHARDERR);
[2]892 }
893 DosFindClose(hdir);
894
[167]895 if (paffbFound || papffbSelected) {
[214]896 if (paffbFound)
897 free(paffbFound);
898 if (papffbSelected)
899 free(papffbSelected);
900 papffbSelected = NULL;
901 paffbFound = NULL;
[2]902 }
903
[167]904 if (ulTotal && paffbTotal)
905 {
906
[214]907 if (stopflag && *stopflag)
908 goto Abort;
[167]909
[214]910 pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
911 MPFROMLONG(ulExtraBytes),
912 MPFROMLONG(ulTotal));
913 if (pciFirst)
[167]914 {
[214]915 register INT i;
[2]916
[214]917 pci = pciFirst;
918 ullTotalBytes = 0;
919 pByte2 = (PBYTE)paffbTotal;
920 for(i = 0; i < ulTotal; i++)
[167]921 {
[214]922 pffbFile = (PFILEFINDBUF4)pByte2;
923 ullBytes = FillInRecordFromFFB(hwndCnr,pci,pszFileSpec,
924 pffbFile,partial,dcd);
925 pci = (PCNRITEM)pci->rc.preccNextRecord;
926 ullTotalBytes += ullBytes;
[167]927
[214]928 pByte2 += sizeof(FILEFINDBUF4);
929 }
930 if (ulTotal)
[167]931 {
[214]932 memset(&ri,0,sizeof(RECORDINSERT));
933 ri.cb = sizeof(RECORDINSERT);
934 ri.pRecordOrder = (PRECORDCORE) CMA_END;
935 ri.pRecordParent = (PRECORDCORE) pciParent;
936 ri.zOrder = (ULONG) CMA_TOP;
937 ri.cRecordsInsert = ulTotal;
938 ri.fInvalidateRecord = (!fSyncUpdates && dcd &&
939 dcd->type == DIR_FRAME) ?
940 FALSE : TRUE;
941 if (!WinSendMsg(hwndCnr,CM_INSERTRECORD,
942 MPFROMP(pciFirst),MPFROMP(&ri)))
[167]943 {
[214]944 DosSleep(100);
945 WinSetFocus(HWND_DESKTOP,hwndCnr);
946 if (!WinSendMsg(hwndCnr,CM_INSERTRECORD,
947 MPFROMP(pciFirst),MPFROMP(&ri)))
948 {
949 Win_Error(hwndCnr,HWND_DESKTOP,__FILE__,__LINE__,
950 GetPString(IDS_FILLDIRERR5TEXT));
951 ok = FALSE;
952 ullTotalBytes = 0;
953 if (WinIsWindow((HAB)0,hwndCnr))
[167]954 {
[214]955 pci = pciFirst;
956 while (pci)
[167]957 {
[214]958 pcit = (PCNRITEM)pci->rc.preccNextRecord;
959 WinSendMsg(hwndCnr,CM_FREERECORD,
960 MPFROMP(&pci),MPFROMSHORT(1));
961 pci = pcit;
962 }
963 }
964 }
965 }
966 }
967 }
968 else
[167]969 {
[214]970 Win_Error(hwndCnr,HWND_DESKTOP,__FILE__,__LINE__,
971 GetPString(IDS_FILLDIRERR3TEXT));
972 ok = FALSE;
973 ullTotalBytes = 0;
974 }
975 if (ok)
[167]976 {
[214]977 ullReturnBytes += ullTotalBytes;
978 ulReturnFiles += ulFileCnt;
979 }
[2]980 }
981 }
982
[167]983 if (!fSyncUpdates && dcd && dcd->type == DIR_FRAME)
[2]984 WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPVOID,
[214]985 MPFROM2SHORT(0,CMA_ERASE));
[2]986 }
987Abort:
[167]988 if (paffbTotal || papffbSelected || paffbFound || pszFileSpec)
989 {
990 if (paffbTotal)
[42]991 free(paffbTotal);
[167]992 if (pszFileSpec)
[42]993 free(pszFileSpec);
[167]994 if (paffbFound)
[42]995 free(paffbFound);
[167]996 if (papffbSelected)
[42]997 free(papffbSelected);
[2]998 }
[167]999 if (recurse)
1000 {
[2]1001 pci = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
[214]1002 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[167]1003 while (pci && (INT)pci != -1)
1004 {
1005 if (pci->attrFile & FILE_DIRECTORY)
[214]1006 Stubby(hwndCnr,pci);
[2]1007 pci = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
[214]1008 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]1009 }
1010 }
1011
[167]1012 if (pulTotalFiles)
1013 *pulTotalFiles = ulReturnFiles;
[2]1014
[167]1015 if (pullTotalBytes)
1016 *pullTotalBytes = ullReturnBytes;
[2]1017
[167]1018} // ProcessDirectory
1019
1020
1021VOID FillDirCnr(HWND hwndCnr,
[214]1022 CHAR *pszDirectory,
1023 DIRCNRDATA *dcd,
1024 PULONGLONG pullTotalBytes)
[90]1025{
[167]1026 ProcessDirectory(hwndCnr,
[214]1027 (PCNRITEM)NULL,
[167]1028 pszDirectory,
1029 TRUE,
1030 FALSE,
1031 TRUE,
[214]1032 dcd ? &dcd->stopflag : NULL,
[167]1033 dcd,
1034 NULL,
1035 pullTotalBytes);
[2]1036 DosPostEventSem(CompactSem);
1037
[167]1038} // FillDirCnr
[2]1039
[167]1040
1041VOID FillTreeCnr(HWND hwndCnr,HWND hwndParent)
[90]1042{
[188]1043 ULONG ulDriveNum,ulDriveMap,numtoinsert = 0,drvtype;
[2]1044 PCNRITEM pci,pciFirst = NULL,pciNext,pciParent = NULL;
1045 INT x,removable;
1046 CHAR szDrive[] = " :\\",FileSystem[CCHMAXPATH],suggest[32];
1047 FILESTATUS4 fsa4;
1048 APIRET rc;
1049 BOOL drivesbuilt = FALSE;
1050 static BOOL didonce = FALSE;
1051
1052 fDummy = TRUE;
1053 *suggest = 0;
[167]1054 for (x = 0;x < 26;x++)
[2]1055 driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
[214]1056 DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
1057 DRIVE_INCLUDEFILES | DRIVE_SLOW);
[2]1058 memset(driveserial,-1,sizeof(driveserial));
1059 {
1060 ULONG startdrive = 3L;
1061
1062 DosError(FERR_DISABLEHARDERR);
[167]1063 if (!DosQuerySysInfo(QSV_BOOT_DRIVE,
[214]1064 QSV_BOOT_DRIVE,
1065 (PVOID)&startdrive,
1066 (ULONG)sizeof(ULONG)) &&
[2]1067 startdrive)
1068 driveflags[startdrive - 1] |= DRIVE_BOOT;
1069 }
1070 DosError(FERR_DISABLEHARDERR);
1071 rc = DosQCurDisk(&ulDriveNum,
[214]1072 &ulDriveMap);
[167]1073 if (rc)
1074 {
[2]1075 Dos_Error(MB_CANCEL,
[214]1076 rc,
1077 HWND_DESKTOP,
1078 __FILE__,
1079 __LINE__,
1080 GetPString(IDS_FILLDIRERR6TEXT));
[2]1081 exit(0);
1082 }
1083 for(x = 0;x < 26;x++)
[167]1084 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE))
[2]1085 numtoinsert++;
[167]1086 if (numtoinsert)
[2]1087 pciFirst = WinSendMsg(hwndCnr,
[214]1088 CM_ALLOCRECORD,
1089 MPFROMLONG(EXTRA_RECORD_BYTES2),
1090 MPFROMLONG((ULONG)numtoinsert));
[167]1091 if (pciFirst)
1092 {
[2]1093 pci = pciFirst;
1094 for(x = 0;x < 26;x++) {
[167]1095 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE))
1096 {
[214]1097 *szDrive = (CHAR)x + 'A';
[2]1098
[214]1099 {
1100 CHAR s[80];
1101 ULONG flags = 0;
[167]1102 ULONG size = sizeof(ULONG);
[2]1103
[214]1104 sprintf(s,"%c.DriveFlags",toupper(*szDrive));
1105 if (PrfQueryProfileData(fmprof,appname,s,&flags,&size) &&
1106 size == sizeof(ULONG))
[167]1107 {
[214]1108 driveflags[toupper(*szDrive) - 'A'] |= flags;
[167]1109 }
[214]1110 }
[2]1111
[214]1112 if (x > 1)
[167]1113 {
[214]1114 if (!(driveflags[x] & DRIVE_NOPRESCAN))
[167]1115 {
[214]1116 *FileSystem = 0;
1117 drvtype = 0;
1118 removable = CheckDrive(*szDrive,FileSystem,&drvtype);
1119 driveserial[x] = -1;
1120 if (removable != -1)
[167]1121 {
[214]1122 struct {
1123 ULONG serial;
1124 CHAR volumelength;
1125 CHAR volumelabel[CCHMAXPATH];
1126 } volser;
[2]1127
[214]1128 DosError(FERR_DISABLEHARDERR);
1129 if (!DosQueryFSInfo((ULONG)x,
1130 FSIL_VOLSER,
1131 &volser,
1132 sizeof(volser)))
1133 {
1134 driveserial[x] = volser.serial;
[167]1135 }
[214]1136 }
1137 else
1138 driveflags[x] |= DRIVE_INVALID;
1139 memset(&fsa4,0,sizeof(FILESTATUS4));
1140 driveflags[x] |= ((removable == -1 || removable == 1) ?
1141 DRIVE_REMOVABLE : 0);
1142 if (drvtype & DRIVE_REMOTE)
1143 driveflags[x] |= DRIVE_REMOTE;
1144 if (strcmp(FileSystem,HPFS) &&
1145 strcmp(FileSystem,JFS) &&
1146 strcmp(FileSystem,CDFS) &&
1147 strcmp(FileSystem,FAT32) &&
1148 strcmp(FileSystem,HPFS386))
[70]1149 {
[214]1150 driveflags[x] |= DRIVE_NOLONGNAMES;
[70]1151 }
[214]1152 if (!strcmp(FileSystem,CDFS))
[167]1153 {
[214]1154 removable = 1;
1155 driveflags[x] |= DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE |
1156 DRIVE_CDROM;
1157 }
1158 else if (!stricmp(FileSystem,CBSIFS))
[70]1159 {
[214]1160 driveflags[x] |= DRIVE_ZIPSTREAM;
1161 driveflags[x] &= ~DRIVE_REMOTE;
1162 if (drvtype & DRIVE_REMOVABLE)
1163 driveflags[x] |= DRIVE_REMOVABLE;
1164 if (!(drvtype & DRIVE_NOLONGNAMES))
1165 driveflags[x] &= ~DRIVE_NOLONGNAMES;
1166 }
[2]1167
[214]1168 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1169 if ((ULONG)(toupper(*pci->szFileName) - '@') == ulDriveNum)
1170 pci->rc.flRecordAttr |= (CRA_CURSORED | CRA_SELECTED);
[2]1171
[214]1172 if (removable == 0)
[167]1173 {
[214]1174 pci->attrFile |= FILE_DIRECTORY;
1175 DosError(FERR_DISABLEHARDERR);
1176 rc = DosQueryPathInfo(szDrive,
1177 FIL_QUERYEASIZE,
1178 &fsa4,
1179 (ULONG)sizeof(FILESTATUS4));
1180 if (rc == 58)
[167]1181 {
[214]1182 DosError(FERR_DISABLEHARDERR);
1183 rc = DosQueryPathInfo(szDrive,
1184 FIL_STANDARD,
1185 &fsa4,
1186 (ULONG)sizeof(FILESTATUS3));
1187 fsa4.cbList = 0;
1188 }
1189 if (rc && !didonce)
[167]1190 {
[214]1191 if (!*suggest)
[167]1192 {
[214]1193 *suggest = '/';
1194 suggest[1] = 0;
1195 }
1196 sprintf(suggest + strlen(suggest),
1197 "%c",
1198 toupper(*szDrive));
1199 strcpy(pci->szFileName,szDrive);
1200 pci->pszFileName = pci->szFileName;
1201 pci->rc.pszIcon = pci->pszFileName;
1202 pci->attrFile = FILE_DIRECTORY;
1203 strcpy(pci->szDispAttr,"----D-");
1204 pci->pszDispAttr = pci->szDispAttr;
1205 driveserial[x] = -1;
1206 }
1207 else
1208 FillInRecordFromFSA(hwndCnr,
1209 pci,
1210 szDrive,
1211 &fsa4,
1212 TRUE,
1213 NULL);
1214 }
1215 else
[167]1216 {
[214]1217 strcpy(pci->szFileName,szDrive);
1218 pci->pszFileName = pci->szFileName;
1219 pci->rc.pszIcon = pci->pszFileName;
1220 pci->attrFile = FILE_DIRECTORY;
1221 strcpy(pci->szDispAttr,"----D-");
1222 pci->pszDispAttr = pci->szDispAttr;
1223 }
1224 *pci->szFileName = toupper(*pci->szFileName);
1225 if (driveflags[x] & DRIVE_CDROM)
1226 pci->rc.hptrIcon = hptrCDROM;
1227 else
1228 pci->rc.hptrIcon = (driveflags[x] & DRIVE_REMOVABLE) ?
1229 hptrRemovable :
1230 (driveflags[x] & DRIVE_REMOTE) ?
1231 hptrRemote :
1232 (driveflags[x] & DRIVE_ZIPSTREAM) ?
1233 hptrZipstrm : hptrDrive;
1234 }
1235 else
[167]1236 {
[214]1237 pci->rc.hptrIcon = hptrDunno;
1238 strcpy(pci->szFileName,szDrive);
1239 pci->pszFileName = pci->szFileName;
1240 pci->rc.pszIcon = pci->pszFileName;
1241 pci->attrFile = FILE_DIRECTORY;
1242 strcpy(pci->szDispAttr,"----D-");
1243 pci->pszDispAttr = pci->szDispAttr;
1244 driveserial[x] = -1;
1245 }
1246 }
1247 else
[167]1248 {
[214]1249 pci->rc.hptrIcon = hptrFloppy;
1250 strcpy(pci->szFileName,szDrive);
1251 pci->pszFileName = pci->szFileName;
1252 pci->rc.pszIcon = pci->pszFileName;
1253 pci->attrFile = FILE_DIRECTORY;
1254 strcpy(pci->szDispAttr,"----D-");
1255 pci->pszDispAttr = pci->szDispAttr;
1256 driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
1257 driveserial[x] = -1;
1258 }
1259 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1260 pci = (PCNRITEM)pci->rc.preccNextRecord; /* next rec */
[2]1261 }
[167]1262 else if (!(ulDriveMap & (1L << x)))
[214]1263 driveflags[x] |= DRIVE_INVALID;
[2]1264 }
1265 PostMsg(hwndMain,
[214]1266 UM_BUILDDRIVES,
1267 MPVOID,
1268 MPVOID);
[2]1269 drivesbuilt = TRUE;
1270 /* insert the drives */
[167]1271 if (numtoinsert && pciFirst)
1272 {
[2]1273 RECORDINSERT ri;
1274
1275 memset(&ri,0,sizeof(RECORDINSERT));
1276 ri.cb = sizeof(RECORDINSERT);
1277 ri.pRecordOrder = (PRECORDCORE)CMA_END;
1278 ri.pRecordParent = (PRECORDCORE)NULL;
1279 ri.zOrder = (ULONG)CMA_TOP;
1280 ri.cRecordsInsert = numtoinsert;
1281 ri.fInvalidateRecord = FALSE;
[167]1282 if (!WinSendMsg(hwndCnr,
[214]1283 CM_INSERTRECORD,
1284 MPFROMP(pciFirst),
1285 MPFROMP(&ri)))
1286 Win_Error(hwndCnr,hwndCnr,__FILE__,__LINE__,
1287 GetPString(IDS_FILLDIRERR5TEXT));
[2]1288 }
1289 /* move cursor onto the default drive rather than the first drive */
[167]1290 if (!fSwitchTree)
1291 {
[2]1292 pci = (PCNRITEM)WinSendMsg(hwndCnr,
[214]1293 CM_QUERYRECORD,
1294 MPVOID,
1295 MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
[167]1296 while(pci && (INT)pci != -1)
1297 {
[214]1298 if ((ULONG)(toupper(*pci->szFileName) - '@') == ulDriveNum)
[167]1299 {
[214]1300 WinSendMsg(hwndCnr,
1301 CM_SETRECORDEMPHASIS,
1302 MPFROMP(pci),
1303 MPFROM2SHORT(TRUE,CRA_CURSORED));
1304 break;
1305 }
1306 pci = (PCNRITEM)WinSendMsg(hwndCnr,
1307 CM_QUERYRECORD,
1308 MPFROMP(pci),
1309 MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
[2]1310 }
1311 }
1312
[167]1313 if (hwndParent)
[2]1314 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent,QW_PARENT),
[214]1315 MAIN_DRIVELIST),
1316 LM_DELETEALL,
1317 MPVOID,
1318 MPVOID);
[2]1319
[167]1320 if (fShowEnv)
1321 {
[2]1322 RECORDINSERT ri;
1323
1324 pciParent = WinSendMsg(hwndCnr,
[214]1325 CM_ALLOCRECORD,
1326 MPFROMLONG(EXTRA_RECORD_BYTES2),
1327 MPFROMLONG(1));
[167]1328 if (pciParent)
1329 {
[214]1330 pciParent->flags |= RECFLAGS_ENV;
1331 strcpy(pciParent->szFileName,GetPString(IDS_ENVVARSTEXT));
1332 pciParent->pszFileName = pciParent->szFileName;
1333 pciParent->rc.hptrIcon = hptrEnv;
1334 pciParent->rc.pszIcon = pciParent->pszFileName;
1335 strcpy(pciParent->szDispAttr,"------");
1336 pciParent->pszDispAttr = pciParent->szDispAttr;
1337 memset(&ri,0,sizeof(RECORDINSERT));
1338 ri.cb = sizeof(RECORDINSERT);
1339 ri.pRecordOrder = (PRECORDCORE)CMA_END;
1340 ri.pRecordParent = (PRECORDCORE)NULL;
1341 ri.zOrder = (ULONG)CMA_TOP;
1342 ri.cRecordsInsert = 1;
1343 ri.fInvalidateRecord = FALSE;
1344 if (WinSendMsg(hwndCnr,
1345 CM_INSERTRECORD,
1346 MPFROMP(pciParent),
1347 MPFROMP(&ri))) {
[2]1348
[214]1349 char *p,*pp;
[2]1350
[214]1351 p = GetPString(IDS_ENVVARNAMES);
1352 while(*p == ' ')
1353 p++;
1354 while (*p)
[167]1355 {
[214]1356 *FileSystem = 0;
1357 pp = FileSystem;
1358 while(*p && *p != ' ')
1359 *pp++ = *p++;
1360 *pp = 0;
1361 while(*p == ' ')
1362 p++;
1363 if (*FileSystem &&
1364 (!stricmp(FileSystem,"LIBPATH") ||
1365 getenv(FileSystem)))
[167]1366 {
[214]1367 pci = WinSendMsg(hwndCnr,
1368 CM_ALLOCRECORD,
1369 MPFROMLONG(EXTRA_RECORD_BYTES2),
1370 MPFROMLONG(1));
1371 if (pci)
[167]1372 {
[214]1373 pci->flags |= RECFLAGS_ENV;
1374 sprintf(pci->szFileName,
1375 "%%%s%%",
1376 FileSystem);
1377 pci->pszFileName = pci->szFileName;
1378 pci->rc.hptrIcon = hptrEnv;
1379 pci->rc.pszIcon = pci->pszFileName;
1380 strcpy(pci->szDispAttr,"------");
1381 pci->pszDispAttr = pci->szDispAttr;
1382 memset(&ri,0,sizeof(RECORDINSERT));
1383 ri.cb = sizeof(RECORDINSERT);
1384 ri.pRecordOrder = (PRECORDCORE)CMA_END;
1385 ri.pRecordParent = (PRECORDCORE)pciParent;
1386 ri.zOrder = (ULONG)CMA_TOP;
1387 ri.cRecordsInsert = 1;
1388 ri.fInvalidateRecord = FALSE;
1389 if (!WinSendMsg(hwndCnr,
1390 CM_INSERTRECORD,
1391 MPFROMP(pci),
1392 MPFROMP(&ri))) {
1393 Win_Error(hwndCnr,hwndCnr,__FILE__,__LINE__,
1394 GetPString(IDS_FILLDIRERR5TEXT));
1395 WinSendMsg(hwndCnr,
1396 CM_FREERECORD,
1397 MPFROMP(&pci),
1398 MPFROMSHORT(1));
1399 }
1400 }
1401 }
1402 }
1403 WinSendMsg(hwndCnr,
1404 CM_INVALIDATERECORD,
1405 MPFROMP(&pciParent),
1406 MPFROM2SHORT(1,CMA_ERASE | CMA_REPOSITION));
1407 }
1408 else
1409 WinSendMsg(hwndCnr,
1410 CM_FREERECORD,
1411 MPFROMP(&pciParent),
1412 MPFROMSHORT(1));
[2]1413 }
1414 }
1415
1416 x = 0;
1417 pci = (PCNRITEM)WinSendMsg(hwndCnr,
[214]1418 CM_QUERYRECORD,
1419 MPVOID,
1420 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[167]1421 while (pci && (INT)pci != -1)
1422 {
[2]1423 pciNext = (PCNRITEM)WinSendMsg(hwndCnr,
[214]1424 CM_QUERYRECORD,
1425 MPFROMP(pci),
1426 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[167]1427 if (!(pci->flags & RECFLAGS_ENV))
1428 {
[214]1429 if ((ULONG)(toupper(*pci->szFileName) - '@') == ulDriveNum ||
1430 toupper(*pci->szFileName) > 'B')
[167]1431 {
[214]1432 if (!(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_INVALID) &&
1433 !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_NOPRESCAN) &&
1434 (!fNoRemovableScan ||
1435 !(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_REMOVABLE)))
[167]1436 {
[214]1437 if (!Stubby(hwndCnr,pci))
[167]1438 {
[214]1439 WinSendMsg(hwndCnr,
1440 CM_INVALIDATERECORD,
1441 MPFROMP(&pci),
1442 MPFROM2SHORT(1,CMA_ERASE | CMA_REPOSITION));
1443 goto SkipBadRec;
1444 }
1445 }
1446 }
1447 else
1448 WinSendMsg(hwndCnr,
1449 CM_INVALIDATERECORD,
1450 MPFROMP(&pci),
1451 MPFROM2SHORT(1,CMA_ERASE | CMA_REPOSITION));
[167]1452
[214]1453 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent,QW_PARENT),
1454 MAIN_DRIVELIST),
1455 LM_INSERTITEM,
1456 MPFROM2SHORT(LIT_SORTASCENDING,0),
1457 MPFROMP(pci->szFileName));
[2]1458 }
1459SkipBadRec:
1460 x++;
1461 pci = pciNext;
1462 }
[167]1463 if (hwndParent)
[2]1464 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent,QW_PARENT),
[214]1465 MAIN_DRIVELIST),LM_SELECTITEM,MPFROM2SHORT(0,0),
1466 MPFROMLONG(TRUE));
[2]1467
1468 pci = (PCNRITEM)WinSendMsg(hwndCnr,
[214]1469 CM_QUERYRECORD,
1470 MPVOID,
1471 MPFROM2SHORT(CMA_FIRST,
1472 CMA_ITEMORDER));
[167]1473 while (pci && (INT)pci != -1)
1474 {
[2]1475 pciNext = (PCNRITEM)WinSendMsg(hwndCnr,
[214]1476 CM_QUERYRECORD,
1477 MPFROMP(pci),
1478 MPFROM2SHORT(CMA_NEXT,
1479 CMA_ITEMORDER));
[167]1480 if (pci->flags & RECFLAGS_ENV)
1481 {
[214]1482 pci = (PCNRITEM)WinSendMsg(hwndCnr,
1483 CM_QUERYRECORD,
1484 MPFROMP(pci),
1485 MPFROM2SHORT(CMA_FIRSTCHILD,
1486 CMA_ITEMORDER));
1487 while (pci && (INT)pci != -1)
[167]1488 {
[214]1489 if (pci->flags & RECFLAGS_ENV)
1490 FleshEnv(hwndCnr,pci);
1491 pci = (PCNRITEM)WinSendMsg(hwndCnr,
1492 CM_QUERYRECORD,
1493 MPFROMP(pci),
1494 MPFROM2SHORT(CMA_NEXT,
1495 CMA_ITEMORDER));
1496 }
1497 break;
[2]1498 }
1499 pci = (PCNRITEM)WinSendMsg(hwndCnr,
[214]1500 CM_QUERYRECORD,
1501 MPFROMP(pci),
1502 MPFROM2SHORT(CMA_NEXT,
1503 CMA_ITEMORDER));
[2]1504 }
1505
1506 }
[167]1507 else
1508 {
[145]1509 Win_Error(hwndCnr,hwndCnr,__FILE__,__LINE__,
[214]1510 GetPString(IDS_FILLDIRERR7TEXT));
[2]1511 exit(0);
1512 }
[167]1513 if (!drivesbuilt && hwndMain)
[2]1514 PostMsg(hwndMain,
[214]1515 UM_BUILDDRIVES,
1516 MPVOID,
1517 MPVOID);
[2]1518 DosSleep(33L);
1519 fDummy = FALSE;
1520 DosPostEventSem(CompactSem);
1521 {
1522 BYTE info;
1523 BOOL includesyours = FALSE;
1524
[167]1525 if (*suggest ||
[214]1526 (!(driveflags[1] & DRIVE_IGNORE) &&
1527 fFirstTime))
[167]1528 {
1529 if (!DosDevConfig(&info,
[214]1530 DEVINFO_FLOPPY) &&
1531 info == 1)
[167]1532 {
[214]1533 if (!*suggest)
[167]1534 {
[214]1535 *suggest = '/';
1536 suggest[1] = 0;
1537 }
1538 else
1539 memmove(suggest + 2,suggest + 1,strlen(suggest));
1540 suggest[1] = 'B';
[2]1541 }
1542 }
[167]1543 if (*suggest)
1544 {
1545 for(x = 2;x < 26;x++)
1546 {
[214]1547 if (driveflags[x] & DRIVE_IGNORE)
[167]1548 {
[214]1549 includesyours = TRUE;
1550 sprintf(suggest + strlen(suggest),
1551 "%c",
1552 (char)(x + 'A'));
1553 }
[2]1554 }
1555 strcat(suggest," %*");
[167]1556 if (saymsg(MB_YESNO | MB_ICONEXCLAMATION,
[214]1557 (hwndParent) ? hwndParent : hwndCnr,
1558 GetPString(IDS_SUGGESTTITLETEXT),
1559 GetPString(IDS_SUGGEST1TEXT),
1560 (includesyours) ? GetPString(IDS_SUGGEST2TEXT) : NullStr,
1561 suggest) == MBID_YES)
[167]1562 {
[214]1563 char s[64];
[2]1564
[214]1565 sprintf(s, "PARAMETERS=%s", suggest);
1566 WinCreateObject(WPProgram,
1567 "FM/2",
1568 s,
1569 FM3Folder,
1570 CO_UPDATEIFEXISTS);
1571 WinCreateObject(WPProgram,
1572 "FM/2 Lite",
1573 s,
1574 FM3Folder,
1575 CO_UPDATEIFEXISTS);
1576 WinCreateObject(WPProgram,
1577 "Archive Viewer/2",
1578 s,
1579 FM3Tools,
1580 CO_UPDATEIFEXISTS);
1581 WinCreateObject(WPProgram,
1582 "Dir Sizes",
1583 s,
1584 FM3Tools,
1585 CO_UPDATEIFEXISTS);
1586 WinCreateObject(WPProgram,
1587 "Visual Tree",
1588 s,
1589 FM3Tools,
1590 CO_UPDATEIFEXISTS);
1591 WinCreateObject(WPProgram,
1592 "Visual Directory",
1593 s,
1594 FM3Tools,
1595 CO_UPDATEIFEXISTS);
1596 WinCreateObject(WPProgram,
1597 "Global File Viewer",
1598 s,
1599 FM3Tools,
1600 CO_UPDATEIFEXISTS);
1601 WinCreateObject(WPProgram,
1602 "Databar",
1603 s,
1604 FM3Tools,
1605 CO_UPDATEIFEXISTS);
[2]1606 }
1607 }
1608 }
1609 didonce = TRUE;
1610
[167]1611} // FillTreeCnr
1612
Note: See TracBrowser for help on using the repository browser.