source: trunk/dll/filldir.c@ 731

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

Correct ticket 24 pointer errors for Gregg

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