source: trunk/dll/filldir.c@ 552

Last change on this file since 552 was 552, checked in by Gregg Young, 19 years ago

font cleanup; new image and archiver masks; messages moved to string file; new drive flags including David's icons mostly working

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