source: trunk/dll/filldir.c@ 1316

Last change on this file since 1316 was 1316, checked in by Gregg Young, 17 years ago

Code clean up -- remove redundant code; move code to match openwatcom requirements etc.

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