source: trunk/dll/filldir.c@ 739

Last change on this file since 739 was 739, 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.4 KB
Line 
1
2/***********************************************************************
3
4 $Id: filldir.c 739 2007-07-24 04:06:59Z 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->pszDisplayName;
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->pszDisplayName;
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[] = " :\\";
986 CHAR szFileSystem[CCHMAXPATH];
987 FILESTATUS4 fsa4;
988 APIRET rc;
989 BOOL drivesbuilt = FALSE;
990 ULONG startdrive = 3;
991
992 static BOOL didonce = FALSE;
993
994 fDummy = TRUE;
995 *suggest = 0;
996 for (x = 0; x < 26; x++) {
997 driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
998 DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
999 DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
1000 }
1001 memset(driveserial, -1, sizeof(driveserial));
1002
1003 DosError(FERR_DISABLEHARDERR);
1004 if (!DosQuerySysInfo(QSV_BOOT_DRIVE,
1005 QSV_BOOT_DRIVE,
1006 (PVOID) &startdrive,
1007 (ULONG) sizeof(ULONG)) &&
1008 startdrive)
1009 {
1010 driveflags[startdrive - 1] |= DRIVE_BOOT;
1011 }
1012
1013 DosError(FERR_DISABLEHARDERR);
1014 rc = DosQCurDisk(&ulCurDriveNum, &ulDriveMap);
1015 if (rc) {
1016 Dos_Error(MB_CANCEL,
1017 rc,
1018 HWND_DESKTOP,
1019 pszSrcFile, __LINE__, GetPString(IDS_FILLDIRQCURERRTEXT));
1020 exit(0);
1021 }
1022
1023 // Calc number of drive items to create
1024 for (x = 0; x < 26; x++) {
1025 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE))
1026 numtoinsert++;
1027 }
1028
1029 if (numtoinsert) {
1030 pciFirst = WinSendMsg(hwndCnr,
1031 CM_ALLOCRECORD,
1032 MPFROMLONG(EXTRA_RECORD_BYTES2),
1033 MPFROMLONG((ULONG) numtoinsert));
1034 }
1035
1036 if (!pciFirst) {
1037 Win_Error2(hwndCnr, hwndCnr, pszSrcFile, __LINE__, IDS_CMALLOCRECERRTEXT);
1038 exit(0);
1039 }
1040
1041 pci = pciFirst;
1042 for (x = 0; x < 26; x++) {
1043 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
1044
1045 CHAR s[80];
1046 ULONG flags = 0;
1047 ULONG size = sizeof(ULONG);
1048
1049 *szDrive = (CHAR)x + 'A'; // Build path spec
1050
1051 sprintf(s, "%c.DriveFlags", toupper(*szDrive));
1052 if (PrfQueryProfileData(fmprof, appname, s, &flags, &size) &&
1053 size == sizeof(ULONG)) {
1054 driveflags[toupper(*szDrive) - 'A'] |= flags;
1055 }
1056
1057 if (x > 1) {
1058 // Hard drive (2..N)
1059 if (!(driveflags[x] & DRIVE_NOPRESCAN)) {
1060 *szFileSystem = 0;
1061 drvtype = 0;
1062 removable = CheckDrive(*szDrive, szFileSystem, &drvtype);
1063 driveserial[x] = -1;
1064 if (removable != -1) {
1065 struct {
1066 ULONG serial;
1067 CHAR volumelength;
1068 CHAR volumelabel[CCHMAXPATH];
1069 } volser;
1070
1071 DosError(FERR_DISABLEHARDERR);
1072 if (!DosQueryFSInfo((ULONG) x,
1073 FSIL_VOLSER, &volser, sizeof(volser))) {
1074 driveserial[x] = volser.serial;
1075 }
1076 }
1077 else
1078 driveflags[x] |= DRIVE_INVALID;
1079
1080 memset(&fsa4, 0, sizeof(FILESTATUS4));
1081 driveflags[x] |= removable == -1 || removable == 1 ?
1082 DRIVE_REMOVABLE : 0;
1083 if (drvtype & DRIVE_REMOTE)
1084 driveflags[x] |= DRIVE_REMOTE;
1085 if (!stricmp(szFileSystem,RAMFS)) {
1086 driveflags[x] |= DRIVE_RAMDISK;
1087 driveflags[x] &= ~DRIVE_REMOTE;
1088 }
1089 if (!stricmp(szFileSystem,NDFS32)) {
1090 driveflags[x] |= DRIVE_VIRTUAL;
1091 driveflags[x] &= ~DRIVE_REMOTE;
1092 }
1093 if (!stricmp(szFileSystem,NTFS))
1094 driveflags[x] |= DRIVE_NOTWRITEABLE;
1095 if (strcmp(szFileSystem, HPFS) &&
1096 strcmp(szFileSystem, JFS) &&
1097 strcmp(szFileSystem, ISOFS) &&
1098 strcmp(szFileSystem, CDFS) &&
1099 strcmp(szFileSystem, FAT32) &&
1100 strcmp(szFileSystem, NDFS32) &&
1101 strcmp(szFileSystem, RAMFS) &&
1102 strcmp(szFileSystem, NTFS) &&
1103 strcmp(szFileSystem, HPFS386)) {
1104 driveflags[x] |= DRIVE_NOLONGNAMES;
1105 }
1106
1107 if (!strcmp(szFileSystem, CDFS) || !strcmp(szFileSystem,ISOFS)) {
1108 removable = 1;
1109 driveflags[x] |= DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE |
1110 DRIVE_CDROM;
1111 }
1112 else if (!stricmp(szFileSystem, CBSIFS)) {
1113 driveflags[x] |= DRIVE_ZIPSTREAM;
1114 driveflags[x] &= ~DRIVE_REMOTE;
1115 if (drvtype & DRIVE_REMOVABLE)
1116 driveflags[x] |= DRIVE_REMOVABLE;
1117 if (!(drvtype & DRIVE_NOLONGNAMES))
1118 driveflags[x] &= ~DRIVE_NOLONGNAMES;
1119 }
1120
1121 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1122 // if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum) // 23 Jul 07 SHL
1123 if ((ULONG)(toupper(*szDrive) - '@') == ulCurDriveNum)
1124 pci->rc.flRecordAttr |= (CRA_CURSORED | CRA_SELECTED);
1125
1126 if (removable == 0) {
1127 // Fixed volume
1128 pci->attrFile |= FILE_DIRECTORY;
1129 DosError(FERR_DISABLEHARDERR);
1130 rc = DosQueryPathInfo(szDrive,
1131 FIL_QUERYEASIZE,
1132 &fsa4, (ULONG) sizeof(FILESTATUS4));
1133 // ERROR_BAD_NET_RSP = 58
1134 if (rc == 58) {
1135 DosError(FERR_DISABLEHARDERR);
1136 rc = DosQueryPathInfo(szDrive,
1137 FIL_STANDARD,
1138 &fsa4, (ULONG) sizeof(FILESTATUS3));
1139 fsa4.cbList = 0;
1140 }
1141 if (rc && !didonce) {
1142 // Guess drive letter
1143 if (!*suggest) {
1144 *suggest = '/';
1145 suggest[1] = 0;
1146 }
1147 sprintf(suggest + strlen(suggest), "%c" , toupper(*szDrive));
1148 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
1149 pci->pszDisplayName = pci->pszFileName;
1150 pci->rc.pszIcon = pci->pszDisplayName;
1151 pci->attrFile = FILE_DIRECTORY;
1152 strcpy(pci->szDispAttr, "----D-");
1153 pci->pszDispAttr = pci->szDispAttr;
1154 driveserial[x] = -1;
1155 }
1156 else
1157 FillInRecordFromFSA(hwndCnr, pci, szDrive, &fsa4, TRUE, NULL);
1158 }
1159 else {
1160 // Removable volume
1161 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
1162 pci->pszDisplayName = pci->pszFileName;
1163 pci->rc.pszIcon = pci->pszDisplayName;
1164 pci->attrFile = FILE_DIRECTORY;
1165 strcpy(pci->szDispAttr, "----D-");
1166 pci->pszDispAttr = pci->szDispAttr;
1167 }
1168 SelectDriveIcon(pci);
1169 }
1170 else {
1171 pci->rc.hptrIcon = hptrDunno;
1172 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
1173 pci->pszDisplayName = pci->pszFileName;
1174 pci->rc.pszIcon = pci->pszFileName;
1175 pci->attrFile = FILE_DIRECTORY;
1176 strcpy(pci->szDispAttr, "----D-");
1177 pci->pszDispAttr = pci->szDispAttr;
1178 driveserial[x] = -1;
1179 }
1180 }
1181 else {
1182 // diskette drive (A or B)
1183 pci->rc.hptrIcon = hptrFloppy;
1184 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
1185 pci->pszDisplayName = pci->pszFileName;
1186 pci->rc.pszIcon = pci->pszDisplayName;
1187 pci->attrFile = FILE_DIRECTORY;
1188 strcpy(pci->szDispAttr, "----D-");
1189 pci->pszDispAttr = pci->szDispAttr;
1190 driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
1191 driveserial[x] = -1;
1192 }
1193 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1194 pci = (PCNRITEM) pci->rc.preccNextRecord; /* next rec */
1195 }
1196 else if (!(ulDriveMap & (1L << x)))
1197 driveflags[x] |= DRIVE_INVALID;
1198 } // for drives
1199
1200 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
1201 drivesbuilt = TRUE;
1202
1203 /* insert the drives */
1204 if (numtoinsert && pciFirst) {
1205 RECORDINSERT ri;
1206
1207 memset(&ri, 0, sizeof(RECORDINSERT));
1208 ri.cb = sizeof(RECORDINSERT);
1209 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1210 ri.pRecordParent = (PRECORDCORE) NULL;
1211 ri.zOrder = (ULONG) CMA_TOP;
1212 ri.cRecordsInsert = numtoinsert;
1213 ri.fInvalidateRecord = FALSE;
1214 if (!WinSendMsg(hwndCnr,
1215 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri)))
1216 {
1217 Win_Error2(hwndCnr, hwndCnr, pszSrcFile, __LINE__,
1218 IDS_CMINSERTERRTEXT);
1219 }
1220 }
1221
1222 /* move cursor onto the default drive rather than the first drive */
1223 if (!fSwitchTree) {
1224 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1225 CM_QUERYRECORD,
1226 MPVOID,
1227 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1228 while (pci && (INT) pci != -1) {
1229 if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum) {
1230 WinSendMsg(hwndCnr,
1231 CM_SETRECORDEMPHASIS,
1232 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
1233 break;
1234 }
1235 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1236 CM_QUERYRECORD,
1237 MPFROMP(pci),
1238 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1239 }
1240 }
1241
1242 if (hwndParent) {
1243 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1244 MAIN_DRIVELIST),
1245 LM_DELETEALL, MPVOID, MPVOID);
1246 }
1247
1248 if (fShowEnv) {
1249 RECORDINSERT ri;
1250
1251 pciParent = WinSendMsg(hwndCnr,
1252 CM_ALLOCRECORD,
1253 MPFROMLONG(EXTRA_RECORD_BYTES2), MPFROMLONG(1));
1254 if (pciParent) {
1255 pciParent->flags |= RECFLAGS_ENV;
1256 pciParent->pszFileName = xstrdup(GetPString(IDS_ENVVARSTEXT), pszSrcFile, __LINE__);
1257 //pciParent->pszFileName = pciParent->szFileName;
1258 pciParent->rc.hptrIcon = hptrEnv;
1259 pciParent->rc.pszIcon = pciParent->pszFileName;
1260 strcpy(pciParent->szDispAttr, "------");
1261 pciParent->pszDispAttr = pciParent->szDispAttr;
1262 memset(&ri, 0, sizeof(RECORDINSERT));
1263 ri.cb = sizeof(RECORDINSERT);
1264 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1265 ri.pRecordParent = (PRECORDCORE) NULL;
1266 ri.zOrder = (ULONG) CMA_TOP;
1267 ri.cRecordsInsert = 1;
1268 ri.fInvalidateRecord = FALSE;
1269 if (WinSendMsg(hwndCnr,
1270 CM_INSERTRECORD, MPFROMP(pciParent), MPFROMP(&ri))) {
1271
1272 char *p, *pp;
1273
1274 p = GetPString(IDS_ENVVARNAMES);
1275 while (*p == ' ')
1276 p++;
1277 while (*p) {
1278 *szFileSystem = 0;
1279 pp = szFileSystem;
1280 while (*p && *p != ' ')
1281 *pp++ = *p++;
1282 *pp = 0;
1283 while (*p == ' ')
1284 p++;
1285 if (*szFileSystem &&
1286 (!stricmp(szFileSystem, "LIBPATH") || getenv(szFileSystem))) {
1287 pci = WinSendMsg(hwndCnr,
1288 CM_ALLOCRECORD,
1289 MPFROMLONG(EXTRA_RECORD_BYTES2),
1290 MPFROMLONG(1));
1291 if (pci) {
1292 CHAR fname[CCHMAXPATH];
1293 pci->flags |= RECFLAGS_ENV;
1294 sprintf(fname, "%%%s%%", szFileSystem);
1295 pci->pszFileName = xstrdup(fname, pszSrcFile, __LINE__);
1296 pci->rc.hptrIcon = hptrEnv;
1297 pci->rc.pszIcon = pci->pszFileName;
1298 strcpy(pci->szDispAttr, "------");
1299 pci->pszDispAttr = pci->szDispAttr;
1300 memset(&ri, 0, sizeof(RECORDINSERT));
1301 ri.cb = sizeof(RECORDINSERT);
1302 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1303 ri.pRecordParent = (PRECORDCORE) pciParent;
1304 ri.zOrder = (ULONG) CMA_TOP;
1305 ri.cRecordsInsert = 1;
1306 ri.fInvalidateRecord = FALSE;
1307 if (!WinSendMsg(hwndCnr,
1308 CM_INSERTRECORD,
1309 MPFROMP(pci), MPFROMP(&ri))) {
1310 Win_Error2(hwndCnr, hwndCnr, pszSrcFile, __LINE__,
1311 IDS_CMINSERTERRTEXT);
1312 WinSendMsg(hwndCnr, CM_FREERECORD, MPFROMP(&pci),
1313 MPFROMSHORT(1));
1314 }
1315 }
1316 }
1317 }
1318 WinSendMsg(hwndCnr,
1319 CM_INVALIDATERECORD,
1320 MPFROMP(&pciParent),
1321 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1322 }
1323 else
1324 WinSendMsg(hwndCnr,
1325 CM_FREERECORD, MPFROMP(&pciParent), MPFROMSHORT(1));
1326 }
1327 } // if show env
1328
1329 x = 0;
1330 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1331 CM_QUERYRECORD,
1332 MPVOID,
1333 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1334 while (pci && (INT) pci != -1) {
1335 pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
1336 CM_QUERYRECORD,
1337 MPFROMP(pci),
1338 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1339 if (!(pci->flags & RECFLAGS_ENV)) {
1340 if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum ||
1341 toupper(*pci->pszFileName) > 'B')
1342 {
1343 if (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_INVALID) &&
1344 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOPRESCAN) &&
1345 (!fNoRemovableScan ||
1346 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_REMOVABLE)))
1347 {
1348 if (!Stubby(hwndCnr, pci) && !DRIVE_RAMDISK) {
1349 WinSendMsg(hwndCnr,
1350 CM_INVALIDATERECORD,
1351 MPFROMP(&pci),
1352 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1353 goto SkipBadRec;
1354 }
1355 }
1356 }
1357 else {
1358 WinSendMsg(hwndCnr,
1359 CM_INVALIDATERECORD,
1360 MPFROMP(&pci),
1361 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1362 }
1363
1364 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1365 MAIN_DRIVELIST),
1366 LM_INSERTITEM,
1367 MPFROM2SHORT(LIT_SORTASCENDING, 0),
1368 MPFROMP(pci->pszFileName));
1369 }
1370 SkipBadRec:
1371 x++;
1372 pci = pciNext;
1373 }
1374 if (hwndParent)
1375 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1376 MAIN_DRIVELIST), LM_SELECTITEM,
1377 MPFROM2SHORT(0, 0), MPFROMLONG(TRUE));
1378
1379 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1380 CM_QUERYRECORD,
1381 MPVOID,
1382 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
1383 while (pci && (INT) pci != -1) {
1384 pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
1385 CM_QUERYRECORD,
1386 MPFROMP(pci),
1387 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1388 if (pci->flags & RECFLAGS_ENV) {
1389 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1390 CM_QUERYRECORD,
1391 MPFROMP(pci),
1392 MPFROM2SHORT(CMA_FIRSTCHILD,
1393 CMA_ITEMORDER));
1394 while (pci && (INT) pci != -1) {
1395 if (pci->flags & RECFLAGS_ENV)
1396 FleshEnv(hwndCnr, pci);
1397 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1398 CM_QUERYRECORD,
1399 MPFROMP(pci),
1400 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1401 }
1402 break;
1403 }
1404 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1405 CM_QUERYRECORD,
1406 MPFROMP(pci),
1407 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1408 }
1409
1410 if (!drivesbuilt && hwndMain)
1411 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
1412 DosSleep(33L);
1413 fDummy = FALSE;
1414 DosPostEventSem(CompactSem);
1415
1416 {
1417 BYTE info;
1418 BOOL includesyours = FALSE;
1419
1420 if (*suggest || (!(driveflags[1] & DRIVE_IGNORE) && fFirstTime)) {
1421 if (!DosDevConfig(&info, DEVINFO_FLOPPY) && info == 1) {
1422 if (!*suggest) {
1423 *suggest = '/';
1424 suggest[1] = 0;
1425 }
1426 else
1427 memmove(suggest + 2, suggest + 1, strlen(suggest));
1428 suggest[1] = 'B';
1429 }
1430 }
1431 if (*suggest) {
1432 for (x = 2; x < 26; x++) {
1433 if (driveflags[x] & DRIVE_IGNORE) {
1434 includesyours = TRUE;
1435 sprintf(suggest + strlen(suggest), "%c", (char)(x + 'A'));
1436 }
1437 }
1438 strcat(suggest, " %*");
1439 if (saymsg(MB_YESNO | MB_ICONEXCLAMATION,
1440 (hwndParent) ? hwndParent : hwndCnr,
1441 GetPString(IDS_SUGGESTTITLETEXT),
1442 GetPString(IDS_SUGGEST1TEXT),
1443 (includesyours) ? GetPString(IDS_SUGGEST2TEXT) : NullStr,
1444 suggest) == MBID_YES) {
1445 char s[64];
1446
1447 sprintf(s, "PARAMETERS=%s", suggest);
1448 WinCreateObject(WPProgram, "FM/2", s, FM3Folder, CO_UPDATEIFEXISTS);
1449 WinCreateObject(WPProgram,
1450 "FM/2 Lite", s, FM3Folder, CO_UPDATEIFEXISTS);
1451 WinCreateObject(WPProgram,
1452 "Archive Viewer/2", s, FM3Tools, CO_UPDATEIFEXISTS);
1453 WinCreateObject(WPProgram,
1454 "Dir Sizes", s, FM3Tools, CO_UPDATEIFEXISTS);
1455 WinCreateObject(WPProgram,
1456 "Visual Tree", s, FM3Tools, CO_UPDATEIFEXISTS);
1457 WinCreateObject(WPProgram,
1458 "Visual Directory", s, FM3Tools, CO_UPDATEIFEXISTS);
1459 WinCreateObject(WPProgram,
1460 "Global File Viewer", s, FM3Tools, CO_UPDATEIFEXISTS);
1461 WinCreateObject(WPProgram, "Databar", s, FM3Tools, CO_UPDATEIFEXISTS);
1462 }
1463 }
1464 }
1465
1466 didonce = TRUE;
1467
1468} // FillTreeCnr
Note: See TracBrowser for help on using the repository browser.