source: trunk/dll/filldir.c@ 705

Last change on this file since 705 was 705, checked in by Gregg Young, 18 years ago

Minor code cleanup fix ramdisk on states list & WORPLACE_PROCESS logic

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