source: trunk/dll/filldir.c@ 737

Last change on this file since 737 was 737, checked in by Steven Levine, 18 years ago

More ticket #24 updates

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