source: trunk/dll/filldir.c@ 557

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

Changes for 3.05 beta mostly drive flag/tree related

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