source: trunk/dll/filldir.c@ 920

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

Correct/enhance settings notebook navigation, ticket #188 (Steven)
Reopen settings notebook to last selected page unless overridden, ticket #188 (Steven)
More Compare Directory overflow tweaks (Steven)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 49.2 KB
RevLine 
[31]1
2/***********************************************************************
3
4 $Id: filldir.c 917 2008-01-11 21:41:56Z stevenhl $
5
6 Fill Directory Tree Containers
7
8 Copyright (c) 1993-98 M. Kimes
[907]9 Copyright (c) 2001, 2008 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)
[744]34 29 Jul 07 SHL Add CNRITEM free and remove support (ticket#24)
[751]35 02 Aug 07 SHL Add FileAttrToString
[756]36 03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
[760]37 04 Aug 07 SHL Update #pragma alloc_test for new functions
[775]38 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
[783]39 13 Aug 07 SHL Sync code with other FilesToGet usage and optimize
40 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
[856]41 04 Nov 07 GKY Use commaFmtULL to display large file sizes
[31]42
43***********************************************************************/
44
[2]45#include <stdlib.h>
46#include <string.h>
47#include <ctype.h>
[763]48
[783]49#if 0 // fixme to disable or to be configurable
[751]50#include <malloc.h> // _heapchk
[763]51#endif
[167]52
[907]53#define INCL_DOS
54#define INCL_WIN
55#define INCL_DOSERRORS
56#define INCL_LONGLONG
57
58#include "fm3str.h"
59#include "filldir.h"
60#include "errutil.h" // Dos_Error...
61#include "strutil.h" // GetPString
[2]62#include "fm3dll.h"
63
[359]64static PSZ pszSrcFile = __FILE__;
65
[751]66/**
67 * Return display string given standard file attribute mask
68 * @param fileAttr attribute mask in FILEFINDBUF format
69 * @return fixed length string for display
70 */
71
72const PSZ FileAttrToString(ULONG fileAttr)
73{
74 // From os2win.h
75 // FILE_ATTRIBUTE_READONLY 0x00000001
76 // FILE_ATTRIBUTE_HIDDEN 0x00000002
77 // FILE_ATTRIBUTE_SYSTEM 0x00000004
78 // 0x00000008
79 // FILE_ATTRIBUTE_DIRECTORY 0x00000010
80 // FILE_ATTRIBUTE_ARCHIVE 0x00000020
81
82 static CHAR *apszAttrString[] = {
83 // RHSDA
84 "-----",
85 "R----",
86 "-H---",
87 "RH---",
88 "--S--",
89 "R-S--",
90 "-HS--",
91 "RHS--",
92 "---D-",
93 "R--D-",
94 "-H-D-",
95 "RH-D-",
96 "--SD-",
97 "R-SD-",
98 "-HSD-",
99 "RHSD-",
100 "----A",
101 "R---A",
102 "-H--A",
103 "RH--A",
104 "--S-A",
105 "R-S-A",
106 "-HS-A",
107 "RHS-A",
108 "---DA",
109 "R--DA",
110 "-H-DA",
111 "RH-DA",
112 "--SDA",
113 "R-SDA",
114 "-HSDA",
115 "RHSDA"
116 };
117
118 fileAttr = ((fileAttr & 0x30) >> 1) | (fileAttr & 7); // Drop don't care bit from index
119
120 return apszAttrString[fileAttr];
121
122}
123
[214]124static HPOINTER IDFile(PSZ p)
[90]125{
[2]126 HPOINTER hptr;
[551]127 ULONG cmp;
[572]128 CHAR cmps[5];
[2]129
[551]130 p = strrchr(p, '.');
[572]131 if (p && !p[5]) {
[214]132 cmps[0] = '.';
133 cmps[1] = toupper(p[1]);
134 cmps[2] = toupper(p[2]);
135 cmps[3] = toupper(p[3]);
[572]136 cmps[4] = toupper(p[4]);
[214]137
[551]138 cmp = *(ULONG *) cmps;
[214]139
[551]140 if (cmp == *(ULONG *) ".EXE" || cmp == *(ULONG *) ".CMD" ||
141 cmp == *(ULONG *) ".BAT" || cmp == *(ULONG *) ".COM")
[214]142 hptr = hptrApp;
[551]143 else if (cmp == *(ULONG *) ".ZIP" || cmp == *(ULONG *) ".LZH" ||
144 cmp == *(ULONG *) ".ARJ" || cmp == *(ULONG *) ".ARC" ||
[552]145 cmp == *(ULONG *) ".ZOO" || cmp == *(ULONG *) ".RAR" ||
146 cmp == *(ULONG *) ".TAR" || cmp == *(ULONG *) ".TGZ" ||
147 cmp == *(ULONG *) ".GZ" || cmp == *(ULONG *) ".Z" ||
148 cmp == *(ULONG *) ".CAB" || cmp == *(ULONG *) ".BZ2")
[214]149 hptr = hptrArc;
[551]150 else if (cmp == *(ULONG *) ".BMP" || cmp == *(ULONG *) ".ICO" ||
151 cmp == *(ULONG *) ".PTR" || cmp == *(ULONG *) ".GIF" ||
152 cmp == *(ULONG *) ".TIF" || cmp == *(ULONG *) ".PCX" ||
[552]153 cmp == *(ULONG *) ".TGA" || cmp == *(ULONG *) ".XBM" ||
154 cmp == *(ULONG *) ".JPEG" || cmp == *(ULONG *) ".JPG" ||
155 cmp == *(ULONG *) ".PNG" || cmp == *(ULONG *) ".PSD" ||
156 cmp == *(ULONG *) ".LGO" || cmp == *(ULONG *) ".EPS" ||
157 cmp == *(ULONG *) ".RLE" || cmp == *(ULONG *) ".RAS" ||
158 cmp == *(ULONG *) ".PLC" || cmp == *(ULONG *) ".MSP" ||
159 cmp == *(ULONG *) ".IFF" || cmp == *(ULONG *) ".FIT" ||
160 cmp == *(ULONG *) ".DCX" || cmp == *(ULONG *) ".MAC" ||
161 cmp == *(ULONG *) ".SFF" || cmp == *(ULONG *) ".SGI" ||
162 cmp == *(ULONG *) ".XWD" || cmp == *(ULONG *) ".XPM" ||
163 cmp == *(ULONG *) ".WPG" || cmp == *(ULONG *) ".CUR" ||
164 cmp == *(ULONG *) ".PNM" || cmp == *(ULONG *) ".PPM" ||
165 cmp == *(ULONG *) ".PGM" || cmp == *(ULONG *) ".PBM")
[214]166 hptr = hptrArt;
167 else
[551]168 hptr = (HPOINTER) 0;
[214]169 }
170 else
[551]171 hptr = (HPOINTER) 0;
[214]172
[2]173 return hptr;
174}
175
[214]176static BOOL IsDefaultIcon(HPOINTER hptr)
177{
178 HPOINTER hptr2;
179 HPOINTER hptr3;
180 UINT u;
181
182 static HPOINTER hptrPMFile;
183 static HPOINTER hptrWPSFile;
184
[551]185 if (!hptrPMFile) {
186 hptrPMFile = WinQuerySysPointer(HWND_DESKTOP, SPTR_FILE, FALSE);
[214]187 }
188
189 // try to guess WPS default file icon
[551]190 hptr2 = (HPOINTER) 0;
191 for (u = 0; !hptrWPSFile && u < 10; u++) {
[214]192 char szFileName[CCHMAXPATH];
193 char *psz;
194
195 psz = getenv("TMP");
196 if (!psz && *psz)
197 psz = getenv("TEMP");
[551]198 if (psz && *psz) {
[214]199 strcpy(szFileName, psz);
200 psz = szFileName + strlen(szFileName) - 1;
[551]201 if (*psz != '\\') {
[214]202 psz++;
203 *psz++ = '\\';
204 }
205 }
206 else
207 psz = szFileName;
208
[551]209 sprintf(psz, "%08x.%03x", rand() & 0xffffffff, rand() & 0xfff);
210 if (IsFile(szFileName) != 1) {
211 FILE *fp = fopen(szFileName, "w");
212
213 if (fp) {
[214]214 fclose(fp);
215 hptr3 = WinLoadFileIcon(szFileName, FALSE);
216 unlinkf("%s", szFileName);
217 if (!hptr2)
218 hptr2 = hptr3;
[551]219 else if (hptr3 == hptr3) {
[214]220 hptrWPSFile = hptr3; // Got same icon twice
221 break;
222 }
223 }
224 }
225 DosSleep(rand() % 100);
226
[731]227 } // for
[214]228
229 return hptr == hptrPMFile || hptr == hptrWPSFile;
230
[731]231} // IsDefaultIcon
[214]232
[731]233ULONGLONG FillInRecordFromFFB(HWND hwndCnr,
234 PCNRITEM pci,
[551]235 const PSZ pszDirectory,
[841]236 const PFILEFINDBUF4L pffb,
[731]237 const BOOL partial,
[737]238 DIRCNRDATA *dcd)
[31]239{
[841]240 // fill in a container record from a FILEFINDBUF4L structure
[2]241
[551]242 CHAR *p;
243 HPOINTER hptr;
[2]244
245 pci->hwndCnr = hwndCnr;
[731]246
247 /* note that we cheat below, and accept the full pathname in pszDirectory
248 if !*pffb->achName. This speeds up and simplifies processing elsewhere
[167]249 (like in update.c)
[551]250 */
[763]251 if (!*pffb->achName) {
[773]252 pci->pszFileName = xstrdup(pszDirectory, pszSrcFile, __LINE__);
[763]253 strcpy(pci->pszFileName, pszDirectory);
254 }
[731]255 else {
256 INT c = strlen(pszDirectory);
257 INT c2 = pffb->cchName + 1;
258 if (pszDirectory[c - 1] != '\\')
259 c2++;
[773]260 pci->pszFileName = xmalloc(c + c2, pszSrcFile, __LINE__);
[731]261 memcpy(pci->pszFileName, pszDirectory, c + 1);
262 p = pci->pszFileName + c - 1;
[167]263 if (*p != '\\') {
[2]264 p++;
265 *p = '\\';
266 }
267 p++;
[551]268 memcpy(p, pffb->achName, pffb->cchName + 1);
[2]269 }
[731]270
[783]271 // load the object's Subject, if required
[756]272 pci->pszSubject = NullStr;
[167]273 if (pffb->cbList > 4L &&
274 dcd && fLoadSubject &&
[730]275 (isalpha(*pci->pszFileName) &&
[731]276 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADSUBJS)))
277 {
[551]278 APIRET rc;
279 EAOP2 eaop;
[2]280 PGEA2LIST pgealist;
281 PFEA2LIST pfealist;
[551]282 PGEA2 pgea;
283 PFEA2 pfea;
284 CHAR *value;
[2]285
[551]286 pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
[359]287 if (pgealist) {
[2]288 pgea = &pgealist->list[0];
[551]289 strcpy(pgea->szName, SUBJECT);
[2]290 pgea->cbName = strlen(pgea->szName);
[188]291 pgea->oNextEntryOffset = 0;
[2]292 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
[551]293 pfealist = xmallocz(1532, pszSrcFile, __LINE__);
[359]294 if (pfealist) {
[214]295 pfealist->cbList = 1024;
296 eaop.fpGEA2List = pgealist;
297 eaop.fpFEA2List = pfealist;
298 eaop.oError = 0;
[730]299 rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
[551]300 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
[214]301 if (!rc) {
302 pfea = &eaop.fpFEA2List->list[0];
303 value = pfea->szName + pfea->cbName + 1;
304 value[pfea->cbValue] = 0;
[551]305 if (*(USHORT *) value == EAT_ASCII)
[730]306 pci->pszSubject = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__);
[214]307 }
308 free(pfealist);
[2]309 }
310 free(pgealist);
311 }
312 }
[731]313 if (!pci->pszSubject)
[751]314 pci->pszSubject = NullStr;
[731]315
[783]316 // load the object's longname
[762]317 pci->pszLongName = 0;
[282]318 if (fLoadLongnames &&
319 dcd &&
320 pffb->cbList > 4L &&
[730]321 isalpha(*pci->pszFileName) &&
322 ~driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLONGNAMES &&
[731]323 ~driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADLONGS)
324 {
[551]325 APIRET rc;
326 EAOP2 eaop;
[2]327 PGEA2LIST pgealist;
328 PFEA2LIST pfealist;
[551]329 PGEA2 pgea;
330 PFEA2 pfea;
331 CHAR *value;
[2]332
[551]333 pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
[359]334 if (pgealist) {
[2]335 pgea = &pgealist->list[0];
[551]336 strcpy(pgea->szName, LONGNAME);
[2]337 pgea->cbName = strlen(pgea->szName);
[188]338 pgea->oNextEntryOffset = 0;
[2]339 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
[551]340 pfealist = xmallocz(1532, pszSrcFile, __LINE__);
[167]341 if (pfealist) {
[214]342 pfealist->cbList = 1024;
343 eaop.fpGEA2List = pgealist;
344 eaop.fpFEA2List = pfealist;
345 eaop.oError = 0;
[730]346 rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
[551]347 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
348 if (!rc) {
[214]349 pfea = &eaop.fpFEA2List->list[0];
350 value = pfea->szName + pfea->cbName + 1;
351 value[pfea->cbValue] = 0;
[551]352 if (*(USHORT *) value == EAT_ASCII)
[762]353 pci->pszLongName = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__);
[214]354 }
355 free(pfealist);
[2]356 }
357 free(pgealist);
358 }
359 }
[762]360 if (!pci->pszLongName)
361 pci->pszLongName = NullStr;
[731]362
[783]363 // do anything required to case of filename
[167]364 if (fForceUpper)
[730]365 strupr(pci->pszFileName);
[167]366 else if (fForceLower)
[730]367 strlwr(pci->pszFileName);
[2]368
[783]369 // get an icon to use with it
[551]370 if (pffb->attrFile & FILE_DIRECTORY) {
[214]371 // is directory
372 if (fNoIconsDirs ||
[730]373 (driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADICONS) ||
374 !isalpha(*pci->pszFileName)) {
[551]375 hptr = (HPOINTER) 0;
[214]376 }
377 else
[730]378 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
[2]379 }
[551]380 else {
[214]381 // is file
382 if (fNoIconsFiles ||
[730]383 (driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADICONS) ||
384 !isalpha(*pci->pszFileName)) {
[551]385 hptr = (HPOINTER) 0;
[167]386 }
[42]387 else
[730]388 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
[167]389
[214]390 if (!hptr || IsDefaultIcon(hptr))
[730]391 hptr = IDFile(pci->pszFileName);
[2]392 }
[214]393
[551]394 if (!hptr) {
[214]395 hptr = pffb->attrFile & FILE_DIRECTORY ?
[731]396 hptrDir : pffb->attrFile & FILE_SYSTEM ?
397 hptrSystem :
398 pffb->attrFile & FILE_HIDDEN ?
399 hptrHidden :
400 pffb->attrFile & FILE_READONLY ?
401 hptrReadonly : hptrFile;
[167]402 }
[2]403
[737]404 // Tell container what part of pathname to display
[551]405 if (partial) {
[730]406 p = strrchr(pci->pszFileName, '\\');
[551]407 if (!p) {
[730]408 p = strrchr(pci->pszFileName, ':');
[167]409 if (!p)
[730]410 p = pci->pszFileName;
[2]411 else
[214]412 p++;
[2]413 }
[167]414 else if ((dcd && dcd->type == TREE_FRAME) ||
[551]415 (!(pffb->attrFile & FILE_DIRECTORY) || !*(p + 1))) {
[2]416 p++;
[167]417 }
418 if (!*p)
[730]419 p = pci->pszFileName;
[2]420 }
421 else
[730]422 p = pci->pszFileName;
[737]423 pci->pszDisplayName = p;
424
[856]425 //comma format the file size for large file support
[859]426 {
[856]427 CHAR szBuf[30];
428 CommaFmtULL(szBuf, sizeof(szBuf), pffb->cbFile, ' ');
429 pci->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__);
430 }
431
[783]432 // now fill the darned thing in...
[551]433 pci->date.day = pffb->fdateLastWrite.day;
434 pci->date.month = pffb->fdateLastWrite.month;
435 pci->date.year = pffb->fdateLastWrite.year + 1980;
436 pci->time.seconds = pffb->ftimeLastWrite.twosecs * 2;
437 pci->time.minutes = pffb->ftimeLastWrite.minutes;
438 pci->time.hours = pffb->ftimeLastWrite.hours;
439 pci->ladate.day = pffb->fdateLastAccess.day;
440 pci->ladate.month = pffb->fdateLastAccess.month;
441 pci->ladate.year = pffb->fdateLastAccess.year + 1980;
[2]442 pci->latime.seconds = pffb->ftimeLastAccess.twosecs * 2;
443 pci->latime.minutes = pffb->ftimeLastAccess.minutes;
[551]444 pci->latime.hours = pffb->ftimeLastAccess.hours;
445 pci->crdate.day = pffb->fdateCreation.day;
446 pci->crdate.month = pffb->fdateCreation.month;
447 pci->crdate.year = pffb->fdateCreation.year + 1980;
[2]448 pci->crtime.seconds = pffb->ftimeCreation.twosecs * 2;
449 pci->crtime.minutes = pffb->ftimeCreation.minutes;
[551]450 pci->crtime.hours = pffb->ftimeCreation.hours;
451 pci->easize = CBLIST_TO_EASIZE(pffb->cbList);
452 pci->cbFile = pffb->cbFile;
453 pci->attrFile = pffb->attrFile;
[751]454 pci->pszDispAttr = FileAttrToString(pci->attrFile);
[739]455 pci->rc.pszIcon = pci->pszDisplayName;
[551]456 pci->rc.hptrIcon = hptr;
[2]457
[783]458 // check to see if record should be visible
[167]459 if (dcd && (*dcd->mask.szMask || dcd->mask.antiattr ||
[551]460 ((dcd->mask.attrFile &
461 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))
462 !=
463 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))))
[167]464 {
[551]465 if (*dcd->mask.szMask || dcd->mask.antiattr) {
466 if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
[214]467 pci->rc.flRecordAttr |= CRA_FILTERED;
[2]468 }
[551]469 else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
470 (pci->attrFile & FILE_HIDDEN)) ||
471 (!(dcd->mask.attrFile & FILE_SYSTEM) &&
472 (pci->attrFile & FILE_SYSTEM)) ||
473 (!(dcd->mask.attrFile & FILE_READONLY) &&
474 (pci->attrFile & FILE_READONLY)) ||
475 (!(dcd->mask.attrFile & FILE_ARCHIVED) &&
476 (pci->attrFile & FILE_ARCHIVED))) {
[2]477 pci->rc.flRecordAttr |= CRA_FILTERED;
[167]478 }
[2]479 }
480
481 return pffb->cbFile + pci->easize;
482
[731]483} // FillInRecordFromFFB
[2]484
[841]485ULONGLONG FillInRecordFromFSA(HWND hwndCnr, PCNRITEM pci,
[907]486 const PSZ pszFileName,
487 const PFILESTATUS4L pfsa4,
488 const BOOL partial, DIRCNRDATA * dcd) // Optional
[31]489{
[551]490 HPOINTER hptr;
[731]491 CHAR *p;
[2]492
[841]493 // fill in a container record from a FILESTATUS4L structure
[2]494
495 pci->hwndCnr = hwndCnr;
[773]496 pci->pszFileName = xstrdup(pszFileName, pszSrcFile, __LINE__);
[763]497 strcpy(pci->pszFileName, pszFileName);
[731]498
[783]499 // load the object's Subject, if required
[756]500 pci->pszSubject = NullStr;
[841]501 if (pfsa4->cbList > 4 &&
[167]502 dcd &&
503 fLoadSubject &&
[730]504 (!isalpha(*pci->pszFileName) ||
[731]505 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADSUBJS)))
506 {
[551]507 APIRET rc;
508 EAOP2 eaop;
[2]509 PGEA2LIST pgealist;
510 PFEA2LIST pfealist;
[551]511 PGEA2 pgea;
512 PFEA2 pfea;
513 CHAR *value;
[2]514
[551]515 pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
[167]516 if (pgealist) {
[2]517 pgea = &pgealist->list[0];
[551]518 strcpy(pgea->szName, SUBJECT);
[2]519 pgea->cbName = strlen(pgea->szName);
[188]520 pgea->oNextEntryOffset = 0;
[2]521 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
[551]522 pfealist = xmallocz(1532, pszSrcFile, __LINE__);
[167]523 if (pfealist) {
[214]524 pfealist->cbList = 1024;
525 eaop.fpGEA2List = pgealist;
526 eaop.fpFEA2List = pfealist;
527 eaop.oError = 0;
[730]528 rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
[551]529 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
[214]530 if (!rc) {
531 pfea = &eaop.fpFEA2List->list[0];
532 value = pfea->szName + pfea->cbName + 1;
533 value[pfea->cbValue] = 0;
[551]534 if (*(USHORT *) value == EAT_ASCII)
[731]535 pci->pszSubject = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__);
[214]536 }
537 free(pfealist);
[2]538 }
539 free(pgealist);
540 }
541 }
[731]542 if (!pci->pszSubject)
[751]543 pci->pszSubject = NullStr;
[731]544
[762]545 pci->pszLongName = 0;
[282]546 if (fLoadLongnames &&
[167]547 dcd &&
[282]548 pfsa4->cbList > 4L &&
[730]549 isalpha(*pci->pszFileName) &&
550 ~driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLONGNAMES &&
[731]551 ~driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADLONGS)
552 {
[551]553 APIRET rc;
554 EAOP2 eaop;
[2]555 PGEA2LIST pgealist;
556 PFEA2LIST pfealist;
[551]557 PGEA2 pgea;
558 PFEA2 pfea;
559 CHAR *value;
[2]560
[551]561 pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
[167]562 if (pgealist) {
[2]563 pgea = &pgealist->list[0];
[551]564 strcpy(pgea->szName, LONGNAME);
[2]565 pgea->cbName = strlen(pgea->szName);
[188]566 pgea->oNextEntryOffset = 0;
[2]567 pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
[551]568 pfealist = xmallocz(1532, pszSrcFile, __LINE__);
[167]569 if (pfealist) {
[214]570 pfealist->cbList = 1024;
571 eaop.fpGEA2List = pgealist;
572 eaop.fpFEA2List = pfealist;
573 eaop.oError = 0;
[730]574 rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
[551]575 (PVOID) & eaop, (ULONG) sizeof(EAOP2));
[214]576 if (!rc) {
577 pfea = &eaop.fpFEA2List->list[0];
[731]578 value = pfea->szName + pfea->cbName + 1; // Point at EA value
579 value[pfea->cbValue] = 0; // Terminate
580 if (*(USHORT *) value == EAT_ASCII) {
581 p = value + sizeof(USHORT) * 2; // Point at value string
[762]582 pci->pszLongName = xstrdup(p, pszSrcFile, __LINE__);
[731]583 }
[214]584 }
585 free(pfealist);
[2]586 }
587 free(pgealist);
588 }
589 }
[762]590 if (!pci->pszLongName)
591 pci->pszLongName = NullStr;
[731]592
[167]593 if (fForceUpper)
[730]594 strupr(pci->pszFileName);
[167]595 else if (fForceLower)
[730]596 strlwr(pci->pszFileName);
[2]597
[551]598 if (pfsa4->attrFile & FILE_DIRECTORY) {
[214]599 if (fNoIconsDirs ||
[730]600 (driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADICONS) ||
601 !isalpha(*pci->pszFileName)) {
[551]602 hptr = (HPOINTER) 0;
[214]603 }
604 else
[730]605 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
[2]606 }
[551]607 else {
[214]608 if (fNoIconsFiles ||
[730]609 (driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOLOADICONS) ||
610 !isalpha(*pci->pszFileName)) {
611 hptr = IDFile(pci->pszFileName);
[2]612 }
[214]613 else
[730]614 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
[2]615 }
[551]616 if (!hptr) {
[214]617 hptr = pfsa4->attrFile & FILE_DIRECTORY ?
[551]618 hptrDir :
619 pfsa4->attrFile & FILE_SYSTEM ?
620 hptrSystem :
621 pfsa4->attrFile & FILE_HIDDEN ?
622 hptrHidden : pfsa4->attrFile & FILE_READONLY ? hptrReadonly : hptrFile;
[214]623 }
[2]624
[737]625 // Tell container what part of pathname to display
[551]626 if (partial) {
[730]627 p = strrchr(pci->pszFileName, '\\');
[167]628 if (!p) {
[730]629 p = strrchr(pci->pszFileName, ':');
[167]630 if (!p)
[730]631 p = pci->pszFileName;
[2]632 else
[214]633 p++;
[2]634 }
[167]635 else if ((dcd && dcd->type == TREE_FRAME) ||
[551]636 !(pfsa4->attrFile & FILE_DIRECTORY) || !*(p + 1))
[2]637 p++;
[167]638 if (!*p)
[730]639 p = pci->pszFileName;
[2]640 }
641 else
[730]642 p = pci->pszFileName;
[737]643 pci->pszDisplayName = p;
644
[856]645 //comma format the file size for large file support
[859]646 {
647 CHAR szBuf[30];
[856]648 CommaFmtULL(szBuf, sizeof(szBuf), pfsa4->cbFile, ' ');
649 pci->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__);
650 }
[551]651 pci->date.day = pfsa4->fdateLastWrite.day;
652 pci->date.month = pfsa4->fdateLastWrite.month;
653 pci->date.year = pfsa4->fdateLastWrite.year + 1980;
654 pci->time.seconds = pfsa4->ftimeLastWrite.twosecs * 2;
655 pci->time.minutes = pfsa4->ftimeLastWrite.minutes;
656 pci->time.hours = pfsa4->ftimeLastWrite.hours;
657 pci->ladate.day = pfsa4->fdateLastAccess.day;
658 pci->ladate.month = pfsa4->fdateLastAccess.month;
659 pci->ladate.year = pfsa4->fdateLastAccess.year + 1980;
[2]660 pci->latime.seconds = pfsa4->ftimeLastAccess.twosecs * 2;
661 pci->latime.minutes = pfsa4->ftimeLastAccess.minutes;
[551]662 pci->latime.hours = pfsa4->ftimeLastAccess.hours;
663 pci->crdate.day = pfsa4->fdateCreation.day;
664 pci->crdate.month = pfsa4->fdateCreation.month;
665 pci->crdate.year = pfsa4->fdateCreation.year + 1980;
[2]666 pci->crtime.seconds = pfsa4->ftimeCreation.twosecs * 2;
667 pci->crtime.minutes = pfsa4->ftimeCreation.minutes;
[551]668 pci->crtime.hours = pfsa4->ftimeCreation.hours;
669 pci->easize = CBLIST_TO_EASIZE(pfsa4->cbList);
670 pci->cbFile = pfsa4->cbFile;
671 pci->attrFile = pfsa4->attrFile;
[751]672 pci->pszDispAttr = FileAttrToString(pci->attrFile);
[739]673 pci->rc.pszIcon = pci->pszDisplayName;
[551]674 pci->rc.hptrIcon = hptr;
[2]675
[167]676 if (dcd &&
677 (*dcd->mask.szMask || dcd->mask.antiattr ||
678 ((dcd->mask.attrFile &
[551]679 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)) !=
680 (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)))) {
681 if (*dcd->mask.szMask || dcd->mask.antiattr) {
682 if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
[214]683 pci->rc.flRecordAttr |= CRA_FILTERED;
[2]684 }
[167]685 else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
[214]686 (pci->attrFile & FILE_HIDDEN)) ||
687 (!(dcd->mask.attrFile & FILE_SYSTEM) &&
688 (pci->attrFile & FILE_SYSTEM)) ||
689 (!(dcd->mask.attrFile & FILE_READONLY) &&
690 (pci->attrFile & FILE_READONLY)) ||
691 (!(dcd->mask.attrFile & FILE_ARCHIVED) &&
692 (pci->attrFile & FILE_ARCHIVED)))
[2]693 pci->rc.flRecordAttr |= CRA_FILTERED;
694 }
695
696 return pfsa4->cbFile + pci->easize;
697
[731]698} // FillInRecordFromFSA
[2]699
[737]700VOID ProcessDirectory(const HWND hwndCnr,
701 const PCNRITEM pciParent,
702 const CHAR *szDirBase,
703 const BOOL filestoo,
704 const BOOL recurse,
705 const BOOL partial,
706 CHAR *stopflag,
707 DIRCNRDATA *dcd, // Optional
708 ULONG *pulTotalFiles, // Optional
[167]709 PULONGLONG pullTotalBytes) // Optional
[31]710{
[2]711 /* put all the directories (and files if filestoo is TRUE) from a
712 * directory into the container. recurse through subdirectories if
713 * recurse is TRUE.
714 */
715
[551]716 PSZ pszFileSpec;
717 INT t;
[841]718 PFILEFINDBUF4L paffbFound;
719 PFILEFINDBUF4L *papffbSelected;
720 PFILEFINDBUF4L pffbFile;
721 PFILEFINDBUF4L paffbTotal = NULL;
722 PFILEFINDBUF4L paffbTemp;
[551]723 HDIR hdir = HDIR_CREATE;
[783]724 ULONG ulFindCnt;
725 ULONG ulFindMax;
726 ULONG ulSelCnt;
[551]727 ULONG ulTotal = 0;
728 ULONGLONG ullBytes;
729 ULONGLONG ullTotalBytes;
730 ULONG ulReturnFiles = 0;
731 ULONGLONG ullReturnBytes = 0;
732 PCH pchEndPath;
733 APIRET rc;
734 PCNRITEM pci;
735 PCNRITEM pciFirst;
736 RECORDINSERT ri;
737 BOOL ok = TRUE;
[783]738 ULONG ulBufBytes;
739 ULONG x;
[2]740
[551]741 if (isalpha(*szDirBase) && szDirBase[1] == ':' && szDirBase[2] == '\\') {
[167]742 if ((driveflags[toupper(*szDirBase) - 'A'] & DRIVE_REMOTE) && fRemoteBug)
[783]743 ulFindMax = 1; // file system gets confused
[167]744 else if (driveflags[toupper(*szDirBase) - 'A'] & DRIVE_ZIPSTREAM)
[783]745 ulFindMax = min(FilesToGet, 225); // anything more is wasted
[2]746 else
[783]747 ulFindMax = FilesToGet; // full-out
[2]748 }
[551]749 else {
[783]750 ulFindMax = FilesToGet;
[2]751 }
[167]752 if (OS2ver[0] == 20 && OS2ver[1] < 30)
[841]753 ulFindMax = min(ulFindMax, (65535 / sizeof(FILEFINDBUF4L)));
[2]754
[841]755 ulBufBytes = ulFindMax * sizeof(FILEFINDBUF4L);
[783]756
[551]757 pszFileSpec = xmalloc(CCHMAXPATH + 2, pszSrcFile, __LINE__);
[783]758 paffbFound = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
[841]759 papffbSelected = xmalloc(sizeof(PFILEFINDBUF4L) * ulFindMax, pszSrcFile, __LINE__);
[783]760
[167]761 if (paffbFound && papffbSelected && pszFileSpec) {
[2]762 t = strlen(szDirBase);
[551]763 memcpy(pszFileSpec, szDirBase, t + 1);
[42]764 pchEndPath = pszFileSpec + t;
[167]765 if (*(pchEndPath - 1) != '\\') {
[551]766 memcpy(pchEndPath, "\\", 2);
[2]767 pchEndPath++;
768 }
[551]769 memcpy(pchEndPath, "*", 2);
[2]770 DosError(FERR_DISABLEHARDERR);
[783]771 ulFindCnt = ulFindMax;
[838]772 rc = xDosFindFirst(pszFileSpec,
773 &hdir,
774 FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
775 FILE_SYSTEM | FILE_HIDDEN |
776 (filestoo ? FILE_DIRECTORY : MUST_HAVE_DIRECTORY),
777 paffbFound,
778 ulBufBytes,
779 &ulFindCnt,
[841]780 FIL_QUERYEASIZEL);
[2]781 priority_normal();
782 *pchEndPath = 0;
[551]783 if (!rc) {
[783]784 do {
[214]785 /*
786 * remove . and .. from list if present
787 * also counter file system bugs that sometimes
788 * allows normal files to slip through when
789 * only directories should appear (only a few
790 * network file systems exhibit such a problem).
791 */
[2]792
[214]793 if (stopflag && *stopflag)
794 goto Abort;
[783]795 pffbFile = paffbFound;
796 ulSelCnt = 0;
797 for (;;) {
[214]798 if (!*pffbFile->achName ||
[783]799 (!filestoo && ~pffbFile->attrFile & FILE_DIRECTORY) ||
800 (pffbFile->attrFile & FILE_DIRECTORY &&
[534]801 pffbFile->achName[0] == '.' &&
802 (!pffbFile->achName[1] ||
[551]803 (pffbFile->achName[1] == '.' && !pffbFile->achName[2])))) {
[783]804 // ulFindCnt--; // Got . or .. or file to be skipped
[174]805 }
[214]806 else
[783]807 papffbSelected[ulSelCnt++] = pffbFile; // Remember selected file
[551]808 if (!pffbFile->oNextEntryOffset) {
[783]809 // ulFindCnt = ulSelCnt; // Remember number selected
[214]810 break;
811 }
[841]812 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
[763]813 } // for
[783]814 if (ulSelCnt) {
815 // One or more entries selected
[214]816 if (stopflag && *stopflag)
817 goto Abort;
[551]818 if (fSyncUpdates) {
[214]819 pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
[783]820 MPFROMLONG(EXTRA_RECORD_BYTES),
821 MPFROMLONG(ulSelCnt));
[359]822 if (!pciFirst) {
[551]823 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
824 IDS_CMALLOCRECERRTEXT);
[359]825 ok = FALSE;
826 ullTotalBytes = 0;
827 }
828 else {
[907]829 // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
[214]830 pci = pciFirst;
831 ullTotalBytes = 0;
[783]832 // Insert selected in container
833 for (x = 0; x < ulSelCnt; x++) {
834 pffbFile = papffbSelected[x];
[551]835 ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
836 pffbFile, partial, dcd);
837 pci = (PCNRITEM) pci->rc.preccNextRecord;
[214]838 ullTotalBytes += ullBytes;
[731]839 } // for
[783]840 // 13 Aug 07 SHL ulSelCnt checked already?
841 // if (ulSelCnt) {
842 memset(&ri, 0, sizeof(RECORDINSERT));
843 ri.cb = sizeof(RECORDINSERT);
844 ri.pRecordOrder = (PRECORDCORE) CMA_END;
845 ri.pRecordParent = (PRECORDCORE) pciParent;
846 ri.zOrder = (ULONG) CMA_TOP;
847 ri.cRecordsInsert = ulSelCnt;
848 ri.fInvalidateRecord =
849 !fSyncUpdates && dcd && dcd->type == DIR_FRAME ?
[551]850 FALSE : TRUE;
[783]851 if (!WinSendMsg(hwndCnr,
852 CM_INSERTRECORD,
853 MPFROMP(pciFirst), MPFROMP(&ri))) {
854 DosSleep(10); // Give GUI time to work
855 WinSetFocus(HWND_DESKTOP, hwndCnr);
[214]856 if (!WinSendMsg(hwndCnr,
857 CM_INSERTRECORD,
[551]858 MPFROMP(pciFirst), MPFROMP(&ri))) {
[783]859 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
860 IDS_CMINSERTERRTEXT);
861 ok = FALSE;
862 ullTotalBytes = 0;
863 if (WinIsWindow((HAB) 0, hwndCnr))
864 FreeCnrItemList(hwndCnr, pciFirst);
[214]865 }
[783]866 // }
[214]867 }
868 }
[551]869 if (ok) {
[214]870 ullReturnBytes += ullTotalBytes;
[783]871 ulReturnFiles += ulSelCnt;
[214]872 }
[783]873 } // if sync updates
[551]874 else {
[783]875 // Append newly selected entries to aggregate list
[359]876 paffbTemp = xrealloc(paffbTotal,
[841]877 sizeof(FILEFINDBUF4L) * (ulSelCnt + ulTotal),
[551]878 pszSrcFile, __LINE__);
879 if (paffbTemp) {
[783]880 // 13 Aug 07 SHL fixme to optimize copy
[214]881 paffbTotal = paffbTemp;
[783]882 for (x = 0; x < ulSelCnt; x++)
[214]883 paffbTotal[x + ulTotal] = *papffbSelected[x];
[783]884 ulTotal += ulSelCnt;
[214]885 }
[551]886 else {
[214]887 saymsg(MB_ENTER,
888 HWND_DESKTOP,
[551]889 GetPString(IDS_ERRORTEXT), GetPString(IDS_OUTOFMEMORY));
[214]890 break;
891 }
892 }
[783]893 } // if entries selected
[214]894 if (stopflag && *stopflag)
[551]895 goto Abort;
[214]896 DosError(FERR_DISABLEHARDERR);
[783]897 ulFindCnt = ulFindMax;
[850]898 rc = xDosFindNext(hdir, paffbFound, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
[214]899 priority_normal();
900 if (rc)
901 DosError(FERR_DISABLEHARDERR);
[783]902 } while (!rc);
903
[2]904 DosFindClose(hdir);
905
[783]906 if (paffbFound) {
907 free(paffbFound);
[214]908 paffbFound = NULL;
[2]909 }
[783]910 if (papffbSelected) {
911 free(papffbSelected);
912 papffbSelected = NULL;
913 }
[2]914
[551]915 if (ulTotal && paffbTotal) {
[167]916
[214]917 if (stopflag && *stopflag)
918 goto Abort;
[167]919
[214]920 pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
[783]921 MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(ulTotal));
[359]922 if (!pciFirst) {
[551]923 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
924 IDS_CMALLOCRECERRTEXT);
[359]925 ok = FALSE;
926 ullTotalBytes = 0;
927 }
928 else {
[907]929 // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
[214]930 pci = pciFirst;
931 ullTotalBytes = 0;
[783]932 pffbFile = paffbTotal;
933 for (x = 0; x < ulTotal; x++) {
[551]934 ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
935 pffbFile, partial, dcd);
936 pci = (PCNRITEM) pci->rc.preccNextRecord;
[214]937 ullTotalBytes += ullBytes;
[783]938 // Can not use offset since we have merged lists - this should be equivalent
[841]939 pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
[214]940 }
[551]941 if (ulTotal) {
942 memset(&ri, 0, sizeof(RECORDINSERT));
943 ri.cb = sizeof(RECORDINSERT);
944 ri.pRecordOrder = (PRECORDCORE) CMA_END;
945 ri.pRecordParent = (PRECORDCORE) pciParent;
946 ri.zOrder = (ULONG) CMA_TOP;
947 ri.cRecordsInsert = ulTotal;
948 ri.fInvalidateRecord = (!fSyncUpdates && dcd &&
949 dcd->type == DIR_FRAME) ? FALSE : TRUE;
950 if (!WinSendMsg(hwndCnr, CM_INSERTRECORD,
951 MPFROMP(pciFirst), MPFROMP(&ri))) {
[783]952 DosSleep(10); // Give GUI time to work
[551]953 WinSetFocus(HWND_DESKTOP, hwndCnr);
954 if (!WinSendMsg(hwndCnr, CM_INSERTRECORD,
955 MPFROMP(pciFirst), MPFROMP(&ri))) {
956 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
957 IDS_CMINSERTERRTEXT);
[214]958 ok = FALSE;
959 ullTotalBytes = 0;
[751]960 if (WinIsWindow((HAB) 0, hwndCnr))
961 FreeCnrItemList(hwndCnr, pciFirst);
[214]962 }
963 }
964 }
965 }
[551]966 if (ok) {
[214]967 ullReturnBytes += ullTotalBytes;
[783]968 ulReturnFiles += ulFindCnt;
[214]969 }
[2]970 }
971 }
972
[783]973 if (rc && rc != ERROR_NO_MORE_FILES) {
974 Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
975 GetPString(IDS_CANTFINDDIRTEXT), pszFileSpec);
976 }
977
[167]978 if (!fSyncUpdates && dcd && dcd->type == DIR_FRAME)
[551]979 WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
980 MPFROM2SHORT(0, CMA_ERASE));
[2]981 }
982Abort:
[783]983 if (paffbTotal)
984 free(paffbTotal);
985 if (pszFileSpec)
986 free(pszFileSpec);
987 if (paffbFound)
988 free(paffbFound);
989 if (papffbSelected)
990 free(papffbSelected);
991
[551]992 if (recurse) {
[2]993 pci = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
[214]994 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[762]995 while (pci && (INT)pci != -1) {
[167]996 if (pci->attrFile & FILE_DIRECTORY)
[551]997 Stubby(hwndCnr, pci);
[2]998 pci = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
[214]999 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]1000 }
1001 }
1002
[167]1003 if (pulTotalFiles)
1004 *pulTotalFiles = ulReturnFiles;
[2]1005
[167]1006 if (pullTotalBytes)
1007 *pullTotalBytes = ullReturnBytes;
[2]1008
[731]1009} // ProcessDirectory
[167]1010
1011VOID FillDirCnr(HWND hwndCnr,
[551]1012 CHAR * pszDirectory,
1013 DIRCNRDATA * dcd, PULONGLONG pullTotalBytes)
[90]1014{
[167]1015 ProcessDirectory(hwndCnr,
[551]1016 (PCNRITEM) NULL,
[167]1017 pszDirectory,
[737]1018 TRUE, // filestoo
1019 FALSE, // recurse
1020 TRUE, // partial
1021 dcd ? &dcd->stopflag : NULL,
1022 dcd,
1023 NULL,
1024 pullTotalBytes);
[2]1025 DosPostEventSem(CompactSem);
1026
[762]1027#if 0 // fixme to be gone or to be configurable
[751]1028 {
1029 int state = _heapchk();
1030 if (state != _HEAPOK)
1031 Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
[763]1032 else
1033 DbgMsg(pszSrcFile, __LINE__, "_memavl %u", _memavl());
[751]1034 }
1035#endif
1036
[731]1037} // FillDirCnr
[2]1038
[551]1039VOID FillTreeCnr(HWND hwndCnr, HWND hwndParent)
[90]1040{
[731]1041 ULONG ulCurDriveNum, ulDriveMap, numtoinsert = 0, drvtype;
[551]1042 PCNRITEM pci, pciFirst = NULL, pciNext, pciParent = NULL;
1043 INT x, removable;
[731]1044 CHAR suggest[32];
[739]1045 CHAR szDrive[] = " :\\";
1046 CHAR szFileSystem[CCHMAXPATH];
[841]1047 FILESTATUS4L fsa4;
[551]1048 APIRET rc;
1049 BOOL drivesbuilt = FALSE;
[739]1050 ULONG startdrive = 3;
1051
[2]1052 static BOOL didonce = FALSE;
1053
1054 fDummy = TRUE;
1055 *suggest = 0;
[689]1056 for (x = 0; x < 26; x++) {
[2]1057 driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
[214]1058 DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
[552]1059 DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
[689]1060 }
[551]1061 memset(driveserial, -1, sizeof(driveserial));
[739]1062
1063 DosError(FERR_DISABLEHARDERR);
1064 if (!DosQuerySysInfo(QSV_BOOT_DRIVE,
1065 QSV_BOOT_DRIVE,
1066 (PVOID) &startdrive,
1067 (ULONG) sizeof(ULONG)) &&
1068 startdrive)
[2]1069 {
[739]1070 driveflags[startdrive - 1] |= DRIVE_BOOT;
1071 }
[2]1072
1073 DosError(FERR_DISABLEHARDERR);
[731]1074 rc = DosQCurDisk(&ulCurDriveNum, &ulDriveMap);
[551]1075 if (rc) {
[2]1076 Dos_Error(MB_CANCEL,
[214]1077 rc,
1078 HWND_DESKTOP,
[551]1079 pszSrcFile, __LINE__, GetPString(IDS_FILLDIRQCURERRTEXT));
[2]1080 exit(0);
1081 }
[739]1082
[731]1083 // Calc number of drive items to create
[689]1084 for (x = 0; x < 26; x++) {
[167]1085 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE))
[2]1086 numtoinsert++;
[689]1087 }
[739]1088
[689]1089 if (numtoinsert) {
[2]1090 pciFirst = WinSendMsg(hwndCnr,
[214]1091 CM_ALLOCRECORD,
[751]1092 MPFROMLONG(EXTRA_RECORD_BYTES),
[551]1093 MPFROMLONG((ULONG) numtoinsert));
[689]1094 }
[739]1095
[359]1096 if (!pciFirst) {
[744]1097 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, IDS_CMALLOCRECERRTEXT);
[907]1098 // 04 Jan 08 SHL fixme not just up and die
[359]1099 exit(0);
1100 }
[689]1101
[907]1102 // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
[739]1103 pci = pciFirst;
1104 for (x = 0; x < 26; x++) {
1105 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
[2]1106
[739]1107 CHAR s[80];
1108 ULONG flags = 0;
1109 ULONG size = sizeof(ULONG);
[2]1110
[739]1111 *szDrive = (CHAR)x + 'A'; // Build path spec
[731]1112
[739]1113 sprintf(s, "%c.DriveFlags", toupper(*szDrive));
1114 if (PrfQueryProfileData(fmprof, appname, s, &flags, &size) &&
1115 size == sizeof(ULONG)) {
1116 driveflags[toupper(*szDrive) - 'A'] |= flags;
1117 }
[2]1118
[739]1119 if (x > 1) {
1120 // Hard drive (2..N)
1121 if (!(driveflags[x] & DRIVE_NOPRESCAN)) {
1122 *szFileSystem = 0;
1123 drvtype = 0;
1124 removable = CheckDrive(*szDrive, szFileSystem, &drvtype);
1125 driveserial[x] = -1;
1126 if (removable != -1) {
1127 struct {
1128 ULONG serial;
1129 CHAR volumelength;
1130 CHAR volumelabel[CCHMAXPATH];
1131 } volser;
[2]1132
[739]1133 DosError(FERR_DISABLEHARDERR);
1134 if (!DosQueryFSInfo((ULONG) x,
1135 FSIL_VOLSER, &volser, sizeof(volser))) {
1136 driveserial[x] = volser.serial;
[731]1137 }
[739]1138 }
1139 else
1140 driveflags[x] |= DRIVE_INVALID;
[731]1141
[841]1142 memset(&fsa4, 0, sizeof(FILESTATUS4L));
[739]1143 driveflags[x] |= removable == -1 || removable == 1 ?
1144 DRIVE_REMOVABLE : 0;
1145 if (drvtype & DRIVE_REMOTE)
1146 driveflags[x] |= DRIVE_REMOTE;
1147 if (!stricmp(szFileSystem,RAMFS)) {
1148 driveflags[x] |= DRIVE_RAMDISK;
1149 driveflags[x] &= ~DRIVE_REMOTE;
1150 }
1151 if (!stricmp(szFileSystem,NDFS32)) {
1152 driveflags[x] |= DRIVE_VIRTUAL;
1153 driveflags[x] &= ~DRIVE_REMOTE;
1154 }
1155 if (!stricmp(szFileSystem,NTFS))
1156 driveflags[x] |= DRIVE_NOTWRITEABLE;
1157 if (strcmp(szFileSystem, HPFS) &&
1158 strcmp(szFileSystem, JFS) &&
1159 strcmp(szFileSystem, ISOFS) &&
1160 strcmp(szFileSystem, CDFS) &&
1161 strcmp(szFileSystem, FAT32) &&
1162 strcmp(szFileSystem, NDFS32) &&
1163 strcmp(szFileSystem, RAMFS) &&
1164 strcmp(szFileSystem, NTFS) &&
1165 strcmp(szFileSystem, HPFS386)) {
1166 driveflags[x] |= DRIVE_NOLONGNAMES;
1167 }
[534]1168
[739]1169 if (!strcmp(szFileSystem, CDFS) || !strcmp(szFileSystem,ISOFS)) {
1170 removable = 1;
1171 driveflags[x] |= DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE |
1172 DRIVE_CDROM;
1173 }
1174 else if (!stricmp(szFileSystem, CBSIFS)) {
1175 driveflags[x] |= DRIVE_ZIPSTREAM;
1176 driveflags[x] &= ~DRIVE_REMOTE;
1177 if (drvtype & DRIVE_REMOVABLE)
1178 driveflags[x] |= DRIVE_REMOVABLE;
1179 if (!(drvtype & DRIVE_NOLONGNAMES))
1180 driveflags[x] &= ~DRIVE_NOLONGNAMES;
1181 }
[2]1182
[739]1183 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
1184 // if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum) // 23 Jul 07 SHL
1185 if ((ULONG)(toupper(*szDrive) - '@') == ulCurDriveNum)
1186 pci->rc.flRecordAttr |= (CRA_CURSORED | CRA_SELECTED);
[2]1187
[739]1188 if (removable == 0) {
1189 // Fixed volume
1190 pci->attrFile |= FILE_DIRECTORY;
1191 DosError(FERR_DISABLEHARDERR);
1192 rc = DosQueryPathInfo(szDrive,
[841]1193 FIL_QUERYEASIZEL,
1194 &fsa4, (ULONG) sizeof(FILESTATUS4L));
[739]1195 // ERROR_BAD_NET_RSP = 58
1196 if (rc == 58) {
[214]1197 DosError(FERR_DISABLEHARDERR);
1198 rc = DosQueryPathInfo(szDrive,
[841]1199 FIL_STANDARDL,
[847]1200 &fsa4, (ULONG) sizeof(FILESTATUS4L));
[739]1201 fsa4.cbList = 0;
1202 }
1203 if (rc && !didonce) {
1204 // Guess drive letter
1205 if (!*suggest) {
1206 *suggest = '/';
1207 suggest[1] = 0;
[214]1208 }
[739]1209 sprintf(suggest + strlen(suggest), "%c" , toupper(*szDrive));
[773]1210 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
[763]1211 strcpy(pci->pszFileName, szDrive);
[739]1212 pci->pszDisplayName = pci->pszFileName;
1213 pci->rc.pszIcon = pci->pszDisplayName;
[214]1214 pci->attrFile = FILE_DIRECTORY;
[751]1215 pci->pszDispAttr = FileAttrToString(pci->attrFile);
[739]1216 driveserial[x] = -1;
[731]1217 }
[739]1218 else
1219 FillInRecordFromFSA(hwndCnr, pci, szDrive, &fsa4, TRUE, NULL);
[214]1220 }
[551]1221 else {
[739]1222 // Removable volume
[773]1223 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
[763]1224 strcpy(pci->pszFileName, szDrive);
[739]1225 pci->pszDisplayName = pci->pszFileName;
1226 pci->rc.pszIcon = pci->pszDisplayName;
[214]1227 pci->attrFile = FILE_DIRECTORY;
[751]1228 pci->pszDispAttr = FileAttrToString(pci->attrFile);
[214]1229 }
[739]1230 SelectDriveIcon(pci);
[214]1231 }
[551]1232 else {
[739]1233 pci->rc.hptrIcon = hptrDunno;
[773]1234 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
[763]1235 strcpy(pci->pszFileName, szDrive);
[739]1236 pci->pszDisplayName = pci->pszFileName;
[214]1237 pci->rc.pszIcon = pci->pszFileName;
1238 pci->attrFile = FILE_DIRECTORY;
[751]1239 pci->pszDispAttr = FileAttrToString(pci->attrFile);
[214]1240 driveserial[x] = -1;
1241 }
[2]1242 }
[739]1243 else {
1244 // diskette drive (A or B)
1245 pci->rc.hptrIcon = hptrFloppy;
[773]1246 pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
[763]1247 strcpy(pci->pszFileName, szDrive);
[739]1248 pci->pszDisplayName = pci->pszFileName;
1249 pci->rc.pszIcon = pci->pszDisplayName;
1250 pci->attrFile = FILE_DIRECTORY;
[751]1251 pci->pszDispAttr = FileAttrToString(pci->attrFile);
[739]1252 driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
1253 driveserial[x] = -1;
1254 }
1255 pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
[783]1256 pci = (PCNRITEM) pci->rc.preccNextRecord; // next rec
[739]1257 }
1258 else if (!(ulDriveMap & (1L << x)))
1259 driveflags[x] |= DRIVE_INVALID;
1260 } // for drives
[689]1261
[739]1262 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
1263 drivesbuilt = TRUE;
[2]1264
[783]1265 // insert the drives
[739]1266 if (numtoinsert && pciFirst) {
1267 RECORDINSERT ri;
1268
1269 memset(&ri, 0, sizeof(RECORDINSERT));
1270 ri.cb = sizeof(RECORDINSERT);
1271 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1272 ri.pRecordParent = (PRECORDCORE) NULL;
1273 ri.zOrder = (ULONG) CMA_TOP;
1274 ri.cRecordsInsert = numtoinsert;
1275 ri.fInvalidateRecord = FALSE;
1276 if (!WinSendMsg(hwndCnr,
1277 CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri)))
1278 {
[744]1279 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
[739]1280 IDS_CMINSERTERRTEXT);
[2]1281 }
[739]1282 }
[689]1283
[783]1284 // move cursor onto the default drive rather than the first drive
[739]1285 if (!fSwitchTree) {
1286 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1287 CM_QUERYRECORD,
1288 MPVOID,
1289 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[762]1290 while (pci && (INT)pci != -1) {
[739]1291 if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum) {
1292 WinSendMsg(hwndCnr,
1293 CM_SETRECORDEMPHASIS,
1294 MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
1295 break;
1296 }
[551]1297 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1298 CM_QUERYRECORD,
[739]1299 MPFROMP(pci),
1300 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]1301 }
[739]1302 }
[2]1303
[739]1304 if (hwndParent) {
1305 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1306 MAIN_DRIVELIST),
1307 LM_DELETEALL, MPVOID, MPVOID);
1308 }
[2]1309
[739]1310 if (fShowEnv) {
1311 RECORDINSERT ri;
[2]1312
[739]1313 pciParent = WinSendMsg(hwndCnr,
1314 CM_ALLOCRECORD,
[751]1315 MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
[739]1316 if (pciParent) {
1317 pciParent->flags |= RECFLAGS_ENV;
[773]1318 pciParent->pszFileName = xstrdup(GetPString(IDS_ENVVARSTEXT), pszSrcFile, __LINE__);
[763]1319 strcpy(pciParent->pszFileName, GetPString(IDS_ENVVARSTEXT));
1320 pciParent->pszDisplayName = pciParent->pszFileName; // 03 Aug 07 SHL
[739]1321 pciParent->rc.hptrIcon = hptrEnv;
1322 pciParent->rc.pszIcon = pciParent->pszFileName;
[751]1323 pciParent->pszDispAttr = FileAttrToString(0);
[739]1324 memset(&ri, 0, sizeof(RECORDINSERT));
1325 ri.cb = sizeof(RECORDINSERT);
1326 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1327 ri.pRecordParent = (PRECORDCORE) NULL;
1328 ri.zOrder = (ULONG) CMA_TOP;
1329 ri.cRecordsInsert = 1;
1330 ri.fInvalidateRecord = FALSE;
1331 if (WinSendMsg(hwndCnr,
1332 CM_INSERTRECORD, MPFROMP(pciParent), MPFROMP(&ri))) {
[2]1333
[739]1334 char *p, *pp;
[2]1335
[739]1336 p = GetPString(IDS_ENVVARNAMES);
1337 while (*p == ' ')
1338 p++;
1339 while (*p) {
1340 *szFileSystem = 0;
1341 pp = szFileSystem;
1342 while (*p && *p != ' ')
1343 *pp++ = *p++;
1344 *pp = 0;
[551]1345 while (*p == ' ')
[214]1346 p++;
[739]1347 if (*szFileSystem &&
1348 (!stricmp(szFileSystem, "LIBPATH") || getenv(szFileSystem))) {
1349 pci = WinSendMsg(hwndCnr,
1350 CM_ALLOCRECORD,
[751]1351 MPFROMLONG(EXTRA_RECORD_BYTES),
[739]1352 MPFROMLONG(1));
1353 if (pci) {
1354 CHAR fname[CCHMAXPATH];
1355 pci->flags |= RECFLAGS_ENV;
1356 sprintf(fname, "%%%s%%", szFileSystem);
1357 pci->pszFileName = xstrdup(fname, pszSrcFile, __LINE__);
1358 pci->rc.hptrIcon = hptrEnv;
1359 pci->rc.pszIcon = pci->pszFileName;
[751]1360 pci->pszDispAttr = FileAttrToString(0);
[739]1361 memset(&ri, 0, sizeof(RECORDINSERT));
1362 ri.cb = sizeof(RECORDINSERT);
1363 ri.pRecordOrder = (PRECORDCORE) CMA_END;
1364 ri.pRecordParent = (PRECORDCORE) pciParent;
1365 ri.zOrder = (ULONG) CMA_TOP;
1366 ri.cRecordsInsert = 1;
1367 ri.fInvalidateRecord = FALSE;
1368 if (!WinSendMsg(hwndCnr,
1369 CM_INSERTRECORD,
1370 MPFROMP(pci), MPFROMP(&ri))) {
[744]1371 Win_Error2(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
[739]1372 IDS_CMINSERTERRTEXT);
[751]1373 FreeCnrItem(hwndCnr, pci);
[214]1374 }
1375 }
1376 }
1377 }
[739]1378 WinSendMsg(hwndCnr,
1379 CM_INVALIDATERECORD,
1380 MPFROMP(&pciParent),
1381 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
[2]1382 }
[739]1383 else
[751]1384 FreeCnrItem(hwndCnr, pciParent);
[739]1385 }
1386 } // if show env
[2]1387
[739]1388 x = 0;
1389 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1390 CM_QUERYRECORD,
1391 MPVOID,
1392 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[762]1393 while (pci && (INT)pci != -1) {
[739]1394 pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
1395 CM_QUERYRECORD,
1396 MPFROMP(pci),
1397 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1398 if (!(pci->flags & RECFLAGS_ENV)) {
1399 if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum ||
1400 toupper(*pci->pszFileName) > 'B')
1401 {
1402 if (!(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_INVALID) &&
1403 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_NOPRESCAN) &&
1404 (!fNoRemovableScan ||
1405 !(driveflags[toupper(*pci->pszFileName) - 'A'] & DRIVE_REMOVABLE)))
1406 {
1407 if (!Stubby(hwndCnr, pci) && !DRIVE_RAMDISK) {
1408 WinSendMsg(hwndCnr,
1409 CM_INVALIDATERECORD,
1410 MPFROMP(&pci),
1411 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1412 goto SkipBadRec;
[214]1413 }
1414 }
[739]1415 }
1416 else {
1417 WinSendMsg(hwndCnr,
1418 CM_INVALIDATERECORD,
1419 MPFROMP(&pci),
1420 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
1421 }
[167]1422
[739]1423 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1424 MAIN_DRIVELIST),
1425 LM_INSERTITEM,
1426 MPFROM2SHORT(LIT_SORTASCENDING, 0),
1427 MPFROMP(pci->pszFileName));
[2]1428 }
[739]1429 SkipBadRec:
1430 x++;
1431 pci = pciNext;
1432 }
1433 if (hwndParent)
1434 WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
1435 MAIN_DRIVELIST), LM_SELECTITEM,
1436 MPFROM2SHORT(0, 0), MPFROMLONG(TRUE));
[2]1437
[739]1438 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1439 CM_QUERYRECORD,
1440 MPVOID,
1441 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[762]1442 while (pci && (INT)pci != -1) {
[739]1443 pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
[551]1444 CM_QUERYRECORD,
1445 MPFROMP(pci),
[739]1446 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1447 if (pci->flags & RECFLAGS_ENV) {
[551]1448 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1449 CM_QUERYRECORD,
1450 MPFROMP(pci),
[739]1451 MPFROM2SHORT(CMA_FIRSTCHILD,
1452 CMA_ITEMORDER));
[762]1453 while (pci && (INT)pci != -1) {
[739]1454 if (pci->flags & RECFLAGS_ENV)
1455 FleshEnv(hwndCnr, pci);
1456 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1457 CM_QUERYRECORD,
1458 MPFROMP(pci),
1459 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1460 }
1461 break;
[2]1462 }
[739]1463 pci = (PCNRITEM) WinSendMsg(hwndCnr,
1464 CM_QUERYRECORD,
1465 MPFROMP(pci),
1466 MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
1467 }
[2]1468
[167]1469 if (!drivesbuilt && hwndMain)
[551]1470 PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
[783]1471 DosSleep(16); // 05 Aug 07 GKY 33
[2]1472 fDummy = FALSE;
1473 DosPostEventSem(CompactSem);
[739]1474
[2]1475 {
1476 BYTE info;
1477 BOOL includesyours = FALSE;
1478
[917]1479 // 10 Jan 08 SHL fixme to understand fFirstTime
[551]1480 if (*suggest || (!(driveflags[1] & DRIVE_IGNORE) && fFirstTime)) {
1481 if (!DosDevConfig(&info, DEVINFO_FLOPPY) && info == 1) {
1482 if (!*suggest) {
[214]1483 *suggest = '/';
1484 suggest[1] = 0;
1485 }
1486 else
[551]1487 memmove(suggest + 2, suggest + 1, strlen(suggest));
[214]1488 suggest[1] = 'B';
[2]1489 }
1490 }
[551]1491 if (*suggest) {
1492 for (x = 2; x < 26; x++) {
1493 if (driveflags[x] & DRIVE_IGNORE) {
[214]1494 includesyours = TRUE;
[551]1495 sprintf(suggest + strlen(suggest), "%c", (char)(x + 'A'));
[214]1496 }
[2]1497 }
[551]1498 strcat(suggest, " %*");
[167]1499 if (saymsg(MB_YESNO | MB_ICONEXCLAMATION,
[214]1500 (hwndParent) ? hwndParent : hwndCnr,
1501 GetPString(IDS_SUGGESTTITLETEXT),
1502 GetPString(IDS_SUGGEST1TEXT),
1503 (includesyours) ? GetPString(IDS_SUGGEST2TEXT) : NullStr,
[551]1504 suggest) == MBID_YES) {
[214]1505 char s[64];
[2]1506
[214]1507 sprintf(s, "PARAMETERS=%s", suggest);
[551]1508 WinCreateObject(WPProgram, "FM/2", s, FM3Folder, CO_UPDATEIFEXISTS);
[214]1509 WinCreateObject(WPProgram,
[551]1510 "FM/2 Lite", s, FM3Folder, CO_UPDATEIFEXISTS);
[214]1511 WinCreateObject(WPProgram,
[551]1512 "Archive Viewer/2", s, FM3Tools, CO_UPDATEIFEXISTS);
[214]1513 WinCreateObject(WPProgram,
[551]1514 "Dir Sizes", s, FM3Tools, CO_UPDATEIFEXISTS);
[214]1515 WinCreateObject(WPProgram,
[551]1516 "Visual Tree", s, FM3Tools, CO_UPDATEIFEXISTS);
[214]1517 WinCreateObject(WPProgram,
[551]1518 "Visual Directory", s, FM3Tools, CO_UPDATEIFEXISTS);
[214]1519 WinCreateObject(WPProgram,
[551]1520 "Global File Viewer", s, FM3Tools, CO_UPDATEIFEXISTS);
1521 WinCreateObject(WPProgram, "Databar", s, FM3Tools, CO_UPDATEIFEXISTS);
[2]1522 }
1523 }
1524 }
[739]1525
[2]1526 didonce = TRUE;
1527
[731]1528} // FillTreeCnr
[743]1529
1530
1531/**
1532 * Empty all records from a container and free associated storage and
1533 * Free up field infos
1534 */
1535
1536VOID EmptyCnr(HWND hwnd)
1537{
1538 PFIELDINFO pfi;
1539
[762]1540#if 0 // fixme to be gone or to be configurable
[751]1541 {
1542 int state = _heapchk();
1543 if (state != _HEAPOK)
1544 Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
1545 }
1546#endif
1547
[743]1548 // Remove all records
1549 RemoveCnrItems(hwnd, NULL, 0, CMA_FREE);
1550
1551 // Remove field info descriptors
1552 pfi = (PFIELDINFO) WinSendMsg(hwnd, CM_QUERYDETAILFIELDINFO, MPVOID,
1553 MPFROMSHORT(CMA_FIRST));
[745]1554 if (pfi &&
1555 (INT)WinSendMsg(hwnd, CM_REMOVEDETAILFIELDINFO, MPVOID,
1556 MPFROM2SHORT(0, CMA_FREE)) == -1) {
1557 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVEDETAILFIELDINFO hwnd %x", hwnd);
1558 }
[743]1559}
1560
1561/**
1562 * Free storage associated with container item
1563 */
1564
[751]1565VOID FreeCnrItemData(PCNRITEM pci)
[743]1566{
[762]1567 PSZ psz;
[745]1568 // DbgMsg(pszSrcFile, __LINE__, "FreeCnrItemData %p", pci);
1569
[762]1570 if (pci->pszSubject && pci->pszSubject != NullStr) {
[743]1571
[762]1572 psz = pci->pszSubject;
1573 pci->pszSubject = NullStr;
1574 free(psz);
1575 }
[743]1576
[762]1577 // +1 in case long name pointing after last backslash
1578 if (pci->pszLongName &&
1579 pci->pszLongName != NullStr &&
1580 pci->pszLongName != pci->pszFileName &&
1581 pci->pszLongName != pci->pszDisplayName &&
1582 pci->pszLongName != pci->pszDisplayName + 1) {
1583 psz = pci->pszLongName;
1584 pci->pszLongName = NullStr;
1585 free(psz);
1586 }
1587
1588 if (pci->pszFileName && pci->pszFileName != NullStr) {
1589 psz = pci->pszFileName;
1590 pci->pszFileName = NullStr;
1591 free(psz);
1592 }
[857]1593
1594 if (pci->pszFmtFileSize && pci->pszFmtFileSize != NullStr) {
1595 psz = pci->pszFmtFileSize;
1596 pci->pszFmtFileSize = NullStr;
1597 free(psz);
1598 }
[743]1599}
1600
1601/**
[762]1602 * Free single container item and associated storage
[743]1603 */
1604
[762]1605VOID FreeCnrItem(HWND hwnd, PCNRITEM pci)
[743]1606{
[745]1607 // DbgMsg(pszSrcFile, __LINE__, "FreeCnrItem hwnd %x pci %p", hwnd, pci);
1608
[743]1609 FreeCnrItemData(pci);
1610
[762]1611 if (!WinSendMsg(hwnd, CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(1))) {
[744]1612 // Win_Error2(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,IDS_CMFREEERRTEXT);
[773]1613 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,
1614 "CM_FREERECORD hwnd %x pci %p file %s",
[783]1615 hwnd, pci,
[773]1616 pci && pci->pszFileName ? pci->pszFileName : "n/a");
[743]1617 }
1618}
1619
1620/**
[751]1621 * Free container item list and associated storage
[743]1622 */
1623
[751]1624VOID FreeCnrItemList(HWND hwnd, PCNRITEM pciFirst)
[743]1625{
[751]1626 PCNRITEM pci = pciFirst;
1627 PCNRITEM pciNext;
[762]1628 USHORT usCount;
[751]1629
[762]1630 for (usCount = 0; pci; usCount++) {
[751]1631 pciNext = (PCNRITEM) pci->rc.preccNextRecord;
[762]1632 FreeCnrItemData(pci);
[751]1633 pci = pciNext;
1634 }
[762]1635
1636 if (usCount) {
1637 if (!WinSendMsg(hwnd, CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(usCount))) {
1638 // Win_Error2(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,IDS_CMFREEERRTEXT);
1639 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_FREERECORD hwnd %x pci %p cnt %u", hwnd, pci, usCount);
1640 }
1641 }
[751]1642}
1643
1644/**
1645 * Remove item(s) from container and free associated storage if requested
[762]1646 * @param pciFirst points to first item to remove or NULL to remove all
1647 * @param usCnt is remove count or 0 to remove all
[751]1648 * @returns count of items remaining in container or -1 if error
1649 */
1650
[762]1651INT RemoveCnrItems(HWND hwnd, PCNRITEM pciFirst, USHORT usCnt, USHORT usFlags)
[751]1652{
[762]1653 INT remaining = usCnt;
1654 PCNRITEM pci;
[751]1655
[762]1656 if ((usCnt && !pciFirst) || (!usCnt && pciFirst)) {
1657 Runtime_Error(pszSrcFile, __LINE__, "pciFirst %p usCnt %u mismatch", pciFirst, usCnt);
[751]1658 remaining = -1;
[762]1659 }
1660 else {
1661 // Free our buffers if free requested
1662 if (usFlags & CMA_FREE) {
1663 if (pciFirst)
1664 pci = pciFirst;
1665 else {
[743]1666 pci = (PCNRITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
[744]1667 MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
[762]1668 if ((INT)pci == -1) {
[744]1669 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
[751]1670 remaining = -1;
[762]1671 pci = NULL;
1672 }
1673 }
1674 while (pci) {
[850]1675 // 12 Sep 07 SHL dwg drivebar crash testing - ticket# ???
[907]1676 static PCNRITEM pciLast; // 12 Sep 07 SHL
1677 ULONG ulSize = sizeof(*pci);
1678 ULONG ulAttr;
[850]1679 APIRET apiret = DosQueryMem((PVOID)pci, &ulSize, &ulAttr);
1680 if (apiret)
[907]1681 Dos_Error(MB_ENTER, apiret, HWND_DESKTOP, pszSrcFile, __LINE__,
[850]1682 "DosQueryMem failed pci %p pciLast %p", pci, pciLast);
[762]1683 FreeCnrItemData(pci);
[850]1684 pciLast = pci;
[762]1685 pci = (PCNRITEM)pci->rc.preccNextRecord;
1686 if (remaining && --remaining == 0)
[744]1687 break;
[762]1688 }
[743]1689 }
1690 }
[745]1691
[762]1692 // DbgMsg(pszSrcFile, __LINE__, "RemoveCnrItems %p %u %s", pci, usCnt, pci->pszFileName);
[743]1693
[762]1694 if (remaining != - 1) {
1695 remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&pciFirst), MPFROM2SHORT(usCnt, usFlags));
[751]1696 if (remaining == -1) {
[744]1697 // Win_Error2(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,IDS_CMREMOVEERRTEXT);
[762]1698 Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pci %p cnt %u", hwnd, pciFirst, usCnt);
[743]1699 }
1700 }
[762]1701
[751]1702 return remaining;
[743]1703}
1704
[783]1705#pragma alloc_text(FILLDIR,FillInRecordFromFFB,FillInRecordFromFSA,IDFile)
1706#pragma alloc_text(FILLDIR1,ProcessDirectory,FillDirCnr,FillTreeCnr,FileAttrToString)
1707#pragma alloc_text(EMPTYCNR,EmptyCnr,FreeCnrItemData,FreeCnrItem,FreeCnrItemList,RemoveCnrItems)
1708
Note: See TracBrowser for help on using the repository browser.