source: trunk/dll/filldir.c@ 730

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

Preliminary work on variable sized container buffers. Removes szFileName etc. Builds fine but traps.

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