source: trunk/dll/filldir.c@ 739

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

More ticket #24 updates

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