source: trunk/dll/filldir.c@ 144

Last change on this file since 144 was 90, checked in by root, 21 years ago

ProcessDirectory: avoid most large drive failures

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