source: trunk/dll/filldir.c@ 737

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

More ticket #24 updates

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