source: trunk/dll/filldir.c@ 555

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

Added NTFS support (read only); minor dive icon code cleanup; update help files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 41.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: filldir.c 555 2007-03-04 05:01:14Z 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 (!stricmp(FileSystem,NTFS))
1043 driveflags[x] |= DRIVE_NOTWRITEABLE;
1044 if (strcmp(FileSystem, HPFS) &&
1045 strcmp(FileSystem, JFS) &&
1046 strcmp(FileSystem, ISOFS) &&
1047 strcmp(FileSystem, CDFS) &&
1048 strcmp(FileSystem, FAT32) &&
1049 strcmp(FileSystem, NDFS32) &&
1050 strcmp(FileSystem, RAMFS) &&
1051 strcmp(FileSystem, NTFS) &&
1052 strcmp(FileSystem, HPFS386)) {
1053 driveflags[x] |= DRIVE_NOLONGNAMES;
1054 }
1055
1056 if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem,ISOFS)) {
1057 removable = 1;
1058 driveflags[x] |= DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE |
1059 DRIVE_CDROM;
1060 }
1061 else if (!stricmp(FileSystem, CBSIFS)) {
1062 driveflags[x] |= DRIVE_ZIPSTREAM;
1063 driveflags[x] &= ~DRIVE_REMOTE;
1064 if (drvtype & DRIVE_REMOVABLE)
1065 driveflags[x] |= DRIVE_REMOVABLE;
1066 if (!(drvtype & DRIVE_NOLONGNAMES))
1067 driveflags[x] &= ~DRIVE_NOLONGNAMES;
1068 }
1069
1070 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1071 if ((ULONG) (toupper(*pci->szFileName) - '@') == ulDriveNum)
1072 pci->rc.flRecordAttr |= (CRA_CURSORED | CRA_SELECTED);
1073
1074 if (removable == 0) {
1075 pci->attrFile |= FILE_DIRECTORY;
1076 DosError(FERR_DISABLEHARDERR);
1077 rc = DosQueryPathInfo(szDrive,
1078 FIL_QUERYEASIZE,
1079 &fsa4, (ULONG) sizeof(FILESTATUS4));
1080 if (rc == 58) {
1081 DosError(FERR_DISABLEHARDERR);
1082 rc = DosQueryPathInfo(szDrive,
1083 FIL_STANDARD,
1084 &fsa4, (ULONG) sizeof(FILESTATUS3));
1085 fsa4.cbList = 0;
1086 }
1087 if (rc && !didonce) {
1088 if (!*suggest) {
1089 *suggest = '/';
1090 suggest[1] = 0;
1091 }
1092 sprintf(suggest + strlen(suggest), "%c" , toupper(*szDrive));
1093 strcpy(pci->szFileName, szDrive);
1094 pci->pszFileName = pci->szFileName;
1095 pci->rc.pszIcon = pci->pszFileName;
1096 pci->attrFile = FILE_DIRECTORY;
1097 strcpy(pci->szDispAttr, "----D-");
1098 pci->pszDispAttr = pci->szDispAttr;
1099 driveserial[x] = -1;
1100 }
1101 else
1102 FillInRecordFromFSA(hwndCnr, pci, szDrive, &fsa4, TRUE, NULL);
1103 }
1104 else {
1105 strcpy(pci->szFileName, szDrive);
1106 pci->pszFileName = pci->szFileName;
1107 pci->rc.pszIcon = pci->pszFileName;
1108 pci->attrFile = FILE_DIRECTORY;
1109 strcpy(pci->szDispAttr, "----D-");
1110 pci->pszDispAttr = pci->szDispAttr;
1111 }
1112 *pci->szFileName = toupper(*pci->szFileName);
1113 if (driveflags[x] & DRIVE_CDROM)
1114 pci->rc.hptrIcon = hptrCDROM;
1115 else
1116 pci->rc.hptrIcon = (driveflags[x] & DRIVE_REMOVABLE) ?
1117 hptrRemovable :
1118 (driveflags[x] & DRIVE_VIRTUAL) ?
1119 hptrVirtual :
1120 (driveflags[x] & DRIVE_REMOTE) ?
1121 hptrRemote :
1122 (driveflags[x] & DRIVE_RAMDISK) ?
1123 hptrRamdisk :
1124 (driveflags[x] & DRIVE_ZIPSTREAM) ?
1125 hptrZipstrm : hptrDrive;
1126 }
1127 else {
1128 pci->rc.hptrIcon = hptrDunno;
1129 strcpy(pci->szFileName, szDrive);
1130 pci->pszFileName = pci->szFileName;
1131 pci->rc.pszIcon = pci->pszFileName;
1132 pci->attrFile = FILE_DIRECTORY;
1133 strcpy(pci->szDispAttr, "----D-");
1134 pci->pszDispAttr = pci->szDispAttr;
1135 driveserial[x] = -1;
1136 }
1137 }
1138 else {
1139 pci->rc.hptrIcon = hptrFloppy;
1140 strcpy(pci->szFileName, szDrive);
1141 pci->pszFileName = pci->szFileName;
1142 pci->rc.pszIcon = pci->pszFileName;
1143 pci->attrFile = FILE_DIRECTORY;
1144 strcpy(pci->szDispAttr, "----D-");
1145 pci->pszDispAttr = pci->szDispAttr;
1146 driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
1147 driveserial[x] = -1;
1148 }
1149 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1150 pci = (PCNRITEM) pci->rc.preccNextRecord; /* next rec */
1151 }
1152 else if (!(ulDriveMap & (1L << x)))
1153 driveflags[x] |= DRIVE_INVALID;
1154 }
1155 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
1156 drivesbuilt = TRUE;
1157 /* insert the drives */
1158 if (numtoinsert && pciFirst) {
1159 RECORDINSERT ri;
1160
1161 memset(&ri, 0, sizeof(RECORDINSERT));
1162 ri.cb = sizeof(RECORDINSERT);
1163 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1164 ri.pRecordParent = (PRECORDCORE) NULL;
1165 ri.zOrder = (ULONG) CMA_TOP;
1166 ri.cRecordsInsert = numtoinsert;
1167 ri.fInvalidateRecord = FALSE;
1168 if (!WinSendMsg(hwndCnr,
1169 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri)))
1170 Win_Error2(hwndCnr, hwndCnr, pszSrcFile, __LINE__,
1171 IDS_CMINSERTERRTEXT);
1172 }
1173 /* move cursor onto the default drive rather than the first drive */
1174 if (!fSwitchTree) {
1175 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1176 CM_QUERYRECORD,
1177 MPVOID,
1178 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1179 while (pci && (INT) pci != -1) {
1180 if ((ULONG) (toupper(*pci->szFileName) - '@') == ulDriveNum) {
1181 WinSendMsg(hwndCnr,
1182 CM_SETRECORDEMPHASIS,
1183 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
1184 break;
1185 }
1186 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1187 CM_QUERYRECORD,
1188 MPFROMP(pci),
1189 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1190 }
1191 }
1192
1193 if (hwndParent)
1194 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1195 MAIN_DRIVELIST),
1196 LM_DELETEALL, MPVOID, MPVOID);
1197
1198 if (fShowEnv) {
1199 RECORDINSERT ri;
1200
1201 pciParent = WinSendMsg(hwndCnr,
1202 CM_ALLOCRECORD,
1203 MPFROMLONG(EXTRA_RECORD_BYTES2), MPFROMLONG(1));
1204 if (pciParent) {
1205 pciParent->flags |= RECFLAGS_ENV;
1206 strcpy(pciParent->szFileName, GetPString(IDS_ENVVARSTEXT));
1207 pciParent->pszFileName = pciParent->szFileName;
1208 pciParent->rc.hptrIcon = hptrEnv;
1209 pciParent->rc.pszIcon = pciParent->pszFileName;
1210 strcpy(pciParent->szDispAttr, "------");
1211 pciParent->pszDispAttr = pciParent->szDispAttr;
1212 memset(&ri, 0, sizeof(RECORDINSERT));
1213 ri.cb = sizeof(RECORDINSERT);
1214 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1215 ri.pRecordParent = (PRECORDCORE) NULL;
1216 ri.zOrder = (ULONG) CMA_TOP;
1217 ri.cRecordsInsert = 1;
1218 ri.fInvalidateRecord = FALSE;
1219 if (WinSendMsg(hwndCnr,
1220 CM_INSERTRECORD, MPFROMP(pciParent), MPFROMP(&ri))) {
1221
1222 char *p, *pp;
1223
1224 p = GetPString(IDS_ENVVARNAMES);
1225 while (*p == ' ')
1226 p++;
1227 while (*p) {
1228 *FileSystem = 0;
1229 pp = FileSystem;
1230 while (*p && *p != ' ')
1231 *pp++ = *p++;
1232 *pp = 0;
1233 while (*p == ' ')
1234 p++;
1235 if (*FileSystem &&
1236 (!stricmp(FileSystem, "LIBPATH") || getenv(FileSystem))) {
1237 pci = WinSendMsg(hwndCnr,
1238 CM_ALLOCRECORD,
1239 MPFROMLONG(EXTRA_RECORD_BYTES2),
1240 MPFROMLONG(1));
1241 if (pci) {
1242 pci->flags |= RECFLAGS_ENV;
1243 sprintf(pci->szFileName, "%%%s%%", FileSystem);
1244 pci->pszFileName = pci->szFileName;
1245 pci->rc.hptrIcon = hptrEnv;
1246 pci->rc.pszIcon = pci->pszFileName;
1247 strcpy(pci->szDispAttr, "------");
1248 pci->pszDispAttr = pci->szDispAttr;
1249 memset(&ri, 0, sizeof(RECORDINSERT));
1250 ri.cb = sizeof(RECORDINSERT);
1251 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1252 ri.pRecordParent = (PRECORDCORE) pciParent;
1253 ri.zOrder = (ULONG) CMA_TOP;
1254 ri.cRecordsInsert = 1;
1255 ri.fInvalidateRecord = FALSE;
1256 if (!WinSendMsg(hwndCnr,
1257 CM_INSERTRECORD,
1258 MPFROMP(pci), MPFROMP(&ri))) {
1259 Win_Error2(hwndCnr, hwndCnr, pszSrcFile, __LINE__,
1260 IDS_CMINSERTERRTEXT);
1261 WinSendMsg(hwndCnr, CM_FREERECORD, MPFROMP(&pci),
1262 MPFROMSHORT(1));
1263 }
1264 }
1265 }
1266 }
1267 WinSendMsg(hwndCnr,
1268 CM_INVALIDATERECORD,
1269 MPFROMP(&pciParent),
1270 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1271 }
1272 else
1273 WinSendMsg(hwndCnr,
1274 CM_FREERECORD, MPFROMP(&pciParent), MPFROMSHORT(1));
1275 }
1276 }
1277
1278 x = 0;
1279 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1280 CM_QUERYRECORD,
1281 MPVOID,
1282 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1283 while (pci && (INT) pci != -1) {
1284 pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
1285 CM_QUERYRECORD,
1286 MPFROMP(pci),
1287 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1288 if (!(pci->flags & RECFLAGS_ENV)) {
1289 if ((ULONG) (toupper(*pci->szFileName) - '@') == ulDriveNum ||
1290 toupper(*pci->szFileName) > 'B') {
1291 if (!(driveflags[toupper(*pci->szFileName) - 'A'] & DRIVE_INVALID)
1292 && !(driveflags[toupper(*pci->szFileName) - 'A'] &
1293 DRIVE_NOPRESCAN) && (!fNoRemovableScan
1294 ||
1295 !(driveflags
1296 [toupper(*pci->szFileName) -
1297 'A'] & DRIVE_REMOVABLE))) {
1298 if (!Stubby(hwndCnr, pci)) {
1299 WinSendMsg(hwndCnr,
1300 CM_INVALIDATERECORD,
1301 MPFROMP(&pci),
1302 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1303 goto SkipBadRec;
1304 }
1305 }
1306 }
1307 else
1308 WinSendMsg(hwndCnr,
1309 CM_INVALIDATERECORD,
1310 MPFROMP(&pci),
1311 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1312
1313 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1314 MAIN_DRIVELIST),
1315 LM_INSERTITEM,
1316 MPFROM2SHORT(LIT_SORTASCENDING, 0),
1317 MPFROMP(pci->szFileName));
1318 }
1319 SkipBadRec:
1320 x++;
1321 pci = pciNext;
1322 }
1323 if (hwndParent)
1324 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1325 MAIN_DRIVELIST), LM_SELECTITEM,
1326 MPFROM2SHORT(0, 0), MPFROMLONG(TRUE));
1327
1328 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1329 CM_QUERYRECORD,
1330 MPVOID,
1331 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1332 while (pci && (INT) pci != -1) {
1333 pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
1334 CM_QUERYRECORD,
1335 MPFROMP(pci),
1336 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1337 if (pci->flags & RECFLAGS_ENV) {
1338 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1339 CM_QUERYRECORD,
1340 MPFROMP(pci),
1341 MPFROM2SHORT(CMA_FIRSTCHILD,
1342 CMA_ITEMORDER));
1343 while (pci && (INT) pci != -1) {
1344 if (pci->flags & RECFLAGS_ENV)
1345 FleshEnv(hwndCnr, pci);
1346 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1347 CM_QUERYRECORD,
1348 MPFROMP(pci),
1349 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1350 }
1351 break;
1352 }
1353 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1354 CM_QUERYRECORD,
1355 MPFROMP(pci),
1356 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1357 }
1358
1359 }
1360 if (!drivesbuilt && hwndMain)
1361 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
1362 DosSleep(33L);
1363 fDummy = FALSE;
1364 DosPostEventSem(CompactSem);
1365 {
1366 BYTE info;
1367 BOOL includesyours = FALSE;
1368
1369 if (*suggest || (!(driveflags[1] & DRIVE_IGNORE) && fFirstTime)) {
1370 if (!DosDevConfig(&info, DEVINFO_FLOPPY) && info == 1) {
1371 if (!*suggest) {
1372 *suggest = '/';
1373 suggest[1] = 0;
1374 }
1375 else
1376 memmove(suggest + 2, suggest + 1, strlen(suggest));
1377 suggest[1] = 'B';
1378 }
1379 }
1380 if (*suggest) {
1381 for (x = 2; x < 26; x++) {
1382 if (driveflags[x] & DRIVE_IGNORE) {
1383 includesyours = TRUE;
1384 sprintf(suggest + strlen(suggest), "%c", (char)(x + 'A'));
1385 }
1386 }
1387 strcat(suggest, " %*");
1388 if (saymsg(MB_YESNO | MB_ICONEXCLAMATION,
1389 (hwndParent) ? hwndParent : hwndCnr,
1390 GetPString(IDS_SUGGESTTITLETEXT),
1391 GetPString(IDS_SUGGEST1TEXT),
1392 (includesyours) ? GetPString(IDS_SUGGEST2TEXT) : NullStr,
1393 suggest) == MBID_YES) {
1394 char s[64];
1395
1396 sprintf(s, "PARAMETERS=%s", suggest);
1397 WinCreateObject(WPProgram, "FM/2", s, FM3Folder, CO_UPDATEIFEXISTS);
1398 WinCreateObject(WPProgram,
1399 "FM/2 Lite", s, FM3Folder, CO_UPDATEIFEXISTS);
1400 WinCreateObject(WPProgram,
1401 "Archive Viewer/2", s, FM3Tools, CO_UPDATEIFEXISTS);
1402 WinCreateObject(WPProgram,
1403 "Dir Sizes", s, FM3Tools, CO_UPDATEIFEXISTS);
1404 WinCreateObject(WPProgram,
1405 "Visual Tree", s, FM3Tools, CO_UPDATEIFEXISTS);
1406 WinCreateObject(WPProgram,
1407 "Visual Directory", s, FM3Tools, CO_UPDATEIFEXISTS);
1408 WinCreateObject(WPProgram,
1409 "Global File Viewer", s, FM3Tools, CO_UPDATEIFEXISTS);
1410 WinCreateObject(WPProgram, "Databar", s, FM3Tools, CO_UPDATEIFEXISTS);
1411 }
1412 }
1413 }
1414 didonce = TRUE;
1415
1416} // FillTreeCnr
Note: See TracBrowser for help on using the repository browser.