source: trunk/dll/flesh.c@ 1878

Last change on this file since 1878 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 27.0 KB
RevLine 
[145]1
2/***********************************************************************
3
4 $Id: flesh.c 1877 2015-10-11 21:43:27Z gyoung $
5
[1856]6 Drive tree container management
[145]7
8 Copyright (c) 1993-98 M. Kimes
[1858]9 Copyright (c) 2005, 2015 Steven H. Levine
[145]10
11 24 May 05 SHL Rework Win_Error usage
[166]12 25 May 05 SHL Rework for ProcessDirectory
[284]13 28 May 05 SHL Clean while reading code
14 24 Oct 05 SHL Delete obsolete code
[340]15 22 Jul 06 SHL Check more run time errors
[515]16 19 Oct 06 SHL Stubby - correct . and .. detect
[574]17 22 Mar 07 GKY Use QWL_USER
[751]18 01 Aug 07 SHL Sync with CNRITEM mods
[775]19 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
[793]20 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
[985]21 29 Feb 08 GKY Use xfree where appropriate
[1299]22 24 Nov 08 GKY remove redundant code and minor speed up of Stubby
[1358]23 25 Dec 08 GKY Add ProcessDirectoryThread to allow optional recursive drive scan at startup.
24 25 Dec 08 GKY Add DRIVE_RSCANNED flag to monitor for the first recursive drive scan per session
[1471]25 to prevent duplicate directory names in tree following a copy before initial scan.
[1400]26 08 Mar 09 GKY Additional strings move to PCSZs in init.c
[1482]27 13 Dec 09 GKY Fixed separate paramenters. Please note that appname should be used in
[1856]28 profile calls for user settings that work and are setable in more than one
29 miniapp; FM3Str should be used for setting only relavent to FM/2 or that
30 aren't user settable; realappname should be used for setting applicable to
31 one or more miniapp but not to FM/2
[1662]32 17 Jan 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
33 04 Aug 12 GKY Fix trap on close during drive scan
[1837]34 02 Aug 15 GKY Fix trap in Stubby
[1856]35 03 Aug 15 SHL Document Stubby a bit better
36 07 Aug 15 SHL Rework to use AddFleshWorkRequest rather than direct calls to Stubby/Flesh/Unflesh
[1858]37 19 Aug 15 SHL Allow WaitFleshWorkListEmpty to wait for dependent items
[1864]38 23 Aug 15 GKY Fixed code to notify on drive with no subdirectories in first 64 entries
[1871]39 20 Sep 15 GKY Add code for Flesh to skip the directory entry added by Stubby (eliminate
40 use of NULL/Nullstr pszFileNames by Stubby). Add code in Stubby to insert a
41 complete container item. Add a flag to indicate when a directory needed to be
42 Fleshed
[1873]43 26 Sep 15 GKY Changes to speed up ExpandAll
44 26 Sep 15 GKY WaitFleshWorkListEmpty now gives error message and returns if semaphore request
45 fails more than 5 consecutive times.
[1874]46 27 Sep 15 GKY DosSleep times in WaitFleshWorkListEmpty set by caller
[1876]47 10 Oct 15 GKY Don't use Flesh thread for floppy drive scans fix them getting mistakenly identified
48 as directories and add nonexistent subdirectories.
[145]49
50***********************************************************************/
51
[907]52#include <stdlib.h>
53#include <string.h>
54#include <ctype.h>
[1831]55//#include <malloc.h>
[907]56
[2]57#define INCL_DOS
58#define INCL_DOSERRORS
59#define INCL_WIN
[907]60#define INCL_LONGLONG // dircnrs.h
[2]61
[1177]62#include "fm3dll.h"
[1207]63#include "draglist.h" // Data declaration(s)
64#include "notebook.h" // Data declaration(s)
65#include "info.h" // Data declaration(s)
66#include "init.h" // Data declaration(s)
67#include "mainwnd.h" // Data declaration(s)
[907]68#include "fm3str.h"
69#include "filldir.h" // FileAttrToString...
70#include "errutil.h" // Dos_Error...
71#include "strutil.h" // GetPString
[1155]72#include "flesh.h"
73#include "valid.h" // IsValidDir
[1856]74#include "misc.h" // LoadLibPath GetTidForThread
[1177]75#include "findrec.h" // FindCnrRecord
76#include "notify.h" // Notify
77#include "wrappers.h" // xfree
[1354]78#include "excputil.h" // xbeginthread
[1856]79#include "listutil.h" // List...
80#include "common.h" // IncrThreadUsage DecrThreadUsage
[1871]81#include "pathutil.h"
[1873]82#include "treecnr.h" // fExpandAll
[1831]83#if 0
84#define __PMPRINTF__
85#include "PMPRINTF.H"
86#endif
[2]87
[1207]88// Data definitions
[2]89#pragma data_seg(DATA1)
[340]90
91static PSZ pszSrcFile = __FILE__;
92
[1856]93
94static INT tidFleshWorkListThread = -1; // 2015-08-08 SHL
95
[1860]96static PCSZ pszFleshFocusPath; // 2015-08-20 SHL
[1877]97
[1207]98#pragma data_seg(GLOBAL1)
99ULONG NoBrokenNotify;
100BOOL fFilesInTree;
101
[1876]102//BOOL Flesh(HWND hwndCnr, PCNRITEM pciParent);
[1856]103
104BOOL Stubby(HWND hwndCnr, PCNRITEM pciParent);
105BOOL FleshEnv(HWND hwndCnr, PCNRITEM pciParent);
[1876]106//VOID UnFlesh(HWND hwndCnr, PCNRITEM pciParent);
[1856]107
108/**
109 * Insert CNRITEMs for members of PATH-like environment variable
110 * @param hwndCnr is the container to be populated
111 * @param pciParent is CNRITEM defining PATH-like environment variable
112 * @return TRUE if OK, FALSE is error detected
113 */
114
[551]115BOOL FleshEnv(HWND hwndCnr, PCNRITEM pciParent)
[175]116{
[551]117 PCNRITEM pciL;
[2]118 DIRCNRDATA *dcd;
[551]119 CHAR path[CCHMAXPATH + 12],
120 fullpath[CCHMAXPATH + 12], *env, *p, *pp, *var = NULL;
[2]121
[1858]122 if (!pciParent || (INT)pciParent == -1 || !hwndCnr)
[2]123 return FALSE;
[1856]124
[574]125 dcd = (DIRCNRDATA *) WinQueryWindowPtr(hwndCnr, QWL_USER);
[551]126 if (!dcd)
[2]127 return FALSE;
128
[730]129 strcpy(path, pciParent->pszFileName + 1);
[551]130 if (stricmp(path, GetPString(IDS_ENVVARSTEXT) + 1))
131 UnFlesh(hwndCnr, pciParent);
132 if (*path) {
[2]133 path[strlen(path) - 1] = 0;
[1400]134 if (!stricmp(path, PCSZ_LIBPATH)) {
[551]135 var = xmalloc(65536, pszSrcFile, __LINE__);
136 if (var)
137 LoadLibPath(var, 65536);
[2]138 env = var;
139 }
140 else
141 env = getenv(path);
[551]142 if (env && *env) {
[2]143 p = env;
[551]144 while (*p) {
145 pp = path;
146 while (*p == ';')
147 p++;
148 while (*p && *p != ';') {
149 *pp = *p;
150 p++;
151 pp++;
152 }
153 *pp = 0;
154 if (*path &&
155 strcmp(path, ".") &&
156 strcmp(path, ".\\") &&
157 strcmp(path, "..") &&
158 strcmp(path, "..\\") &&
159 strncmp(path, ".\\", 2) && strncmp(path, "..\\", 3)) {
160 if (!DosQueryPathInfo(path,
161 FIL_QUERYFULLNAME,
162 fullpath,
163 sizeof(fullpath)) && IsValidDir(fullpath)) {
164 pciL = FindCnrRecord(hwndCnr,
165 fullpath, pciParent, FALSE, FALSE, FALSE);
166 if (pciL) {
[1858]167 while (pciL && pciL != (PCNRITEM)-1 && pciL != pciParent)
[551]168 pciL = WinSendMsg(hwndCnr,
169 CM_QUERYRECORD,
170 MPFROMP(pciL),
171 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
172 }
173 if (!pciL) {
[2]174
[551]175 RECORDINSERT ri;
[2]176
[551]177 pciL = WinSendMsg(hwndCnr,
178 CM_ALLOCRECORD,
[751]179 MPFROMLONG(EXTRA_RECORD_BYTES),
[551]180 MPFROMLONG(1));
181 if (pciL) {
[730]182 pciL->pszFileName = xstrdup(fullpath, pszSrcFile, __LINE__);
[751]183 pciL->rc.pszIcon = pciL->pszFileName;
[551]184 if (!fNoIconsDirs &&
185 (!isalpha(*fullpath) ||
186 !(driveflags[toupper(*fullpath) - 'A'] &
187 DRIVE_NOLOADICONS)))
188 pciL->rc.hptrIcon = WinLoadFileIcon(fullpath, FALSE);
189 if (!pciL->rc.hptrIcon)
190 pciL->rc.hptrIcon = hptrDir;
191 pciL->attrFile = FILE_DIRECTORY;
[751]192 pciL->pszDispAttr = FileAttrToString(pciL->attrFile);
[551]193 memset(&ri, 0, sizeof(ri));
194 ri.cb = sizeof(ri);
[1858]195 ri.pRecordOrder = (PRECORDCORE)CMA_END;
196 ri.pRecordParent = (PRECORDCORE)pciParent;
197 ri.zOrder = (ULONG)CMA_TOP;
[551]198 ri.cRecordsInsert = 1;
199 ri.fInvalidateRecord = FALSE;
[1871]200 if (!WinSendMsg(hwndCnr,
[551]201 CM_INSERTRECORD, MPFROMP(pciL), MPFROMP(&ri)))
[751]202 FreeCnrItem(hwndCnr, pciL);
[551]203 }
204 }
205 }
206 }
[2]207 }
208 }
[1009]209 xfree(var, pszSrcFile, __LINE__);
[1858]210 pciL = (PCNRITEM)WinSendMsg(hwndCnr,
211 CM_QUERYRECORD,
212 MPFROMP(pciParent),
213 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
214 while (pciL && (INT)pciL != -1) {
[2]215 pciL->flags |= (RECFLAGS_NODRAG | RECFLAGS_UNDERENV);
216 WinSendMsg(hwndCnr,
[551]217 CM_INVALIDATERECORD, MPFROMP(&pciL), MPFROM2SHORT(1, 0));
[2]218 pciL = WinSendMsg(hwndCnr,
[551]219 CM_QUERYRECORD,
220 MPFROMP(pciL), MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
[2]221 }
222 }
223 return TRUE;
224}
225
[1856]226/**
227 * Insert CNRITEMs for all children of pciParent
228 * @param hwnCnr is container to receive CNRITEMs
229 * @param pciParent is CNRITEM to have children inserted
230 * @return TRUE if OK, FALSE is error detected
231 */
232
[551]233BOOL Flesh(HWND hwndCnr, PCNRITEM pciParent)
[166]234{
[551]235 PCNRITEM pciL;
[2]236 DIRCNRDATA *dcd;
[1856]237 BOOL includefiles;
[2]238
[1856]239 if (!pciParent || (INT)pciParent == -1 || !hwndCnr)
[2]240 return FALSE;
[1856]241
[1858]242 // 2015-08-13 SHL
243 if (fAmQuitting)
244 return FALSE;
[1856]245
[1871]246 if (!pciParent->fleshed) {
247 pciL = (PCNRITEM)WinSendMsg(hwndCnr,
248 CM_QUERYRECORD,
249 MPFROMP(pciParent),
250 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[1874]251 // Added by Stubby to create plus sign run Stubby on it here and skip it in ProcessDirectory
[1856]252 if (pciL && (INT)pciL != -1) {
[1871]253 AddFleshWorkRequest(hwndCnr, pciL, eStubby);
[1874]254 // 2015-08-06 SHL FIXME to ensure this can not happen
[1871]255 if (!*pciL->pszFileName || !strcmp(pciL->pszFileName, NullStr))
[1877]256 Runtime_Error(pszSrcFile, __LINE__, "Flesh called with pci %p pszFileName (null)",
257 pciL);
[1856]258 }
[1651]259 dcd = INSTDATA(hwndCnr);
260 if (dcd && dcd->size != sizeof(DIRCNRDATA))
261 dcd = NULL;
[1856]262
263 includefiles =
264 driveflags[toupper(*pciParent->pszFileName) - 'A'] & DRIVE_INCLUDEFILES ?
265 TRUE : fFilesInTree;
266
[1662]267 ProcessDirectory(hwndCnr,
[1856]268 pciParent,
269 pciParent->pszFileName,
270 includefiles, // filestoo
271 TRUE, // recurse
272 TRUE, // partial
273 NULL, // stop flag
274 dcd,
275 NULL, // total files
[1871]276 NULL, // total bytes
277 (pciL && (INT)pciL != -1) ? pciL->pszDisplayName : 0);
278 pciParent->fleshed = TRUE;
[1655]279 return TRUE;
[1651]280 }
[1856]281
[1655]282 return FALSE;
[2]283}
284
[1858]285/**
286 * Remove children from container
[1865]287 * @param pciParent is parent of children to be removed
[1858]288 */
[1856]289
[1858]290VOID UnFlesh(HWND hwndCnr, PCNRITEM pciParent)
[175]291{
[1856]292 BOOL removed = FALSE;
[2]293 PCNRITEM pciL;
294
[175]295 if (!pciParent || !hwndCnr)
[1858]296 return;
[551]297 for (;;) {
[1858]298 pciL = (PCNRITEM)WinSendMsg(hwndCnr,
299 CM_QUERYRECORD,
300 MPFROMP(pciParent),
301 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
[1856]302 if (!pciL || (INT)pciL == -1)
[1877]303 break;
[1856]304 RemoveCnrItems(hwndCnr, pciL, 1, CMA_FREE);
305 removed = TRUE;
306 } // for
307
308 if (removed) {
[2]309 WinSendMsg(hwndCnr,
[551]310 CM_INVALIDATERECORD,
311 MPFROMP(&pciParent),
[1871]312 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
313 pciParent->fleshed = FALSE;
314 DosSleep(1); // Let container items go away
[175]315 }
[1858]316 return;
[2]317}
318
[1482]319#define DDEPTH 64
[2]320
[1471]321/**
[1856]322 * Insert CNRITEM for 1st subdirectory [or file] of pciParent
323 * @param hwdCnr is container to be filled
324 * @param pciParent is CNRITEM to receive child record
325 * @return TRUE if record inserted, else FALSE
326 * Ensures that expand/collapse button displays if directory has children
327 * Secondary purpose is to detect broken LANs and inaccesible mapped drives
[1471]328 */
329
[551]330BOOL Stubby(HWND hwndCnr, PCNRITEM pciParent)
[175]331{
[1409]332 /**
[2]333 * this code is full of workarounds for screwed up LANs.
334 * let's hope all the current LAN programmers fall into
335 * a black hole and make way for people who can get it right...
336 */
337
[1471]338 BOOL ok = FALSE;
[847]339 FILEFINDBUF3 ffb[DDEPTH];
340 PFILEFINDBUF3 pffb;
[551]341 HDIR hDir = HDIR_CREATE;
[1856]342 ULONG nm, ulM = 1, total = 0, fl;
[1858]343 CHAR wildcard[CCHMAXPATH];
[551]344 register INT len;
345 APIRET rc, prc;
[1858]346 BOOL isadir = FALSE;
347 BOOL isremote;
348 BOOL includefiles;
[1482]349 ULONG ddepth = DDEPTH;
[1299]350 ULONG drvNum;
351 ULONG flags;
[551]352 static BOOL brokenlan = FALSE, isbroken = FALSE;
[2]353
[1858]354 if (!pciParent || (INT)pciParent == -1 || !*pciParent->pszFileName
[1832]355 || pciParent->pszFileName == NullStr || !hwndCnr)
[2]356 return FALSE;
[1856]357 // Build wildcard
[730]358 len = strlen(pciParent->pszFileName);
[1858]359 memcpy(wildcard, pciParent->pszFileName, len + 1);
360 if (wildcard[len - 1] != '\\')
361 wildcard[len++] = '\\';
362 wildcard[len++] = '*';
363 wildcard[len] = 0;
[2]364
[1858]365 // 2015-08-19 SHL FIXME to know how this can happen
366 if (!isalpha(*wildcard) || wildcard[1] != ':' || wildcard[2] != '\\') {
367 MakeFullName(wildcard);
368 }
[1299]369 drvNum = toupper(*pciParent->pszFileName) - 'A';
370 flags = driveflags[drvNum];
[1858]371 if (!isalpha(*wildcard) ||
372 wildcard[1] != ':' ||
373 wildcard[2] != '\\' || ((flags & DRIVE_IGNORE)))
[1856]374 return FALSE; // Not a directory or ignore requested
[2]375
[1856]376 includefiles = flags & DRIVE_INCLUDEFILES ? TRUE : fFilesInTree;
[2]377
[1856]378 isremote = flags & DRIVE_REMOTE ? TRUE : FALSE;
[2]379
[551]380 if (isremote) {
381 if (fRemoteBug) {
382 if (brokenlan) {
[1858]383 ddepth = (ULONG)-1;
[551]384 ddepth--;
[2]385 }
[761]386 ulM = 1;
[2]387 }
388 }
[551]389 else if (isbroken)
[2]390 ddepth = 14;
391
[1482]392 if (!fRemoteBug)
[1856]393 ulM = ddepth <= DDEPTH ? ddepth : 1;
[2]394
395 nm = ulM;
396
397 DosError(FERR_DISABLEHARDERR);
[1856]398
399 fl = includefiles ? FILE_DIRECTORY : MUST_HAVE_DIRECTORY;
[1858]400 rc = DosFindFirst(wildcard,
[847]401 &hDir,
402 FILE_NORMAL | fl |
403 FILE_READONLY | FILE_ARCHIVED |
404 FILE_SYSTEM | FILE_HIDDEN,
405 &ffb, ulM * sizeof(FILEFINDBUF3), &nm, FIL_STANDARD);
[761]406 if (ulM == 1 && !rc) {
[1856]407 // Loop looking for 1st directory (or file)
[2]408 do {
409 pffb = &ffb[0];
[551]410 if (!includefiles && !(pffb->attrFile & FILE_DIRECTORY) && !brokenlan) {
[1856]411 // Find returned file when only directories requested
[551]412 brokenlan = TRUE;
[1858]413 ddepth = (ULONG)-1;
[551]414 ddepth--;
415 if (!NoBrokenNotify) {
416 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
417 HWND_DESKTOP,
418 GetPString(IDS_LANERRORTITLETEXT),
419 GetPString(IDS_LANERRORTEXT));
420 if (prc == MBID_NO) {
421 saymsg(MB_ENTER,
422 HWND_DESKTOP,
423 GetPString(IDS_LANERROR2TITLETEXT),
424 GetPString(IDS_LANERROR2TEXT));
[847]425 NoBrokenNotify = 255;
[1505]426 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
[551]427 &NoBrokenNotify, sizeof(ULONG));
428 }
429 }
430 else {
431 NoBrokenNotify--;
[1505]432 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
[551]433 &NoBrokenNotify, sizeof(ULONG));
434 }
[2]435 }
[1856]436
[515]437 if (*pffb->achName &&
[551]438 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
439 (pffb->achName[0] != '.' ||
[515]440 (pffb->achName[1] &&
[551]441 (pffb->achName[1] != '.' || pffb->achName[2])))) {
[1856]442 // Got directory other than . or .. (or a file)
[551]443 DosFindClose(hDir);
444 isadir = TRUE;
445 goto Interruptus;
[2]446 }
[761]447 nm = 1;
[2]448 DosError(FERR_DISABLEHARDERR);
[1856]449 } while (++total < ddepth && !(rc = (DosFindNext(hDir,
450 &ffb,
451 sizeof(FILEFINDBUF3),
452 &nm))));
453 DosFindClose(hDir);
454
[730]455 if (toupper(*pciParent->pszFileName) > 'B' &&
[751]456 (*(pciParent->pszFileName + 1)) == ':' &&
[730]457 (*(pciParent->pszFileName + 2)) == '\\' && !(*(pciParent->pszFileName + 3))) {
[2]458
[1856]459 // Searching root of hard or remote drive and find reported error
[2]460 CHAR s[132];
461 sprintf(s,
[551]462 GetPString(IDS_NOSUBDIRSTEXT),
[730]463 total, toupper(*pciParent->pszFileName));
[551]464 if (rc && rc != ERROR_NO_MORE_FILES)
[1858]465 sprintf(&s[strlen(s)], GetPString(IDS_SEARCHERRORTEXT), rc, wildcard);
[847]466 else if (ddepth < 16)
[551]467 brokenlan = TRUE;
[2]468 Notify(s);
469 }
[1856]470 goto None; // Done
[2]471 }
[551]472 if (!rc) {
[2]473 DosFindClose(hDir);
[551]474 if (nm) {
[1353]475 PBYTE fb = (PBYTE)&ffb[0];
[551]476 for (len = 0; len < nm; len++) {
[847]477 pffb = (PFILEFINDBUF3) fb;
[551]478 if (!includefiles && !(pffb->attrFile & FILE_DIRECTORY)) {
[1856]479 // Got file(s), but did not ask for files
[551]480 if (!isbroken) {
481 isbroken = TRUE;
482 if (!NoBrokenNotify) {
483 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
484 HWND_DESKTOP,
485 GetPString(IDS_FSDERRORTITLETEXT),
486 GetPString(IDS_FSDERRORTEXT),
[1471]487 isremote ? GetPString(IDS_REMOTETEXT) :
488 GetPString(IDS_LOCALTEXT),
[1858]489 *wildcard);
[551]490 if (prc == MBID_NO) {
491 saymsg(MB_ENTER,
492 HWND_DESKTOP,
493 GetPString(IDS_FSDERROR2TITLETEXT),
494 GetPString(IDS_FSDERROR2TEXT));
[847]495 NoBrokenNotify = 255;
[1505]496 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
[551]497 &NoBrokenNotify, sizeof(ULONG));
498 }
499 }
500 else {
501 NoBrokenNotify--;
[1505]502 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
[551]503 &NoBrokenNotify, sizeof(ULONG));
504 }
[1856]505 } // if !broken
506 } // if !directory
507
[551]508 if (*pffb->achName &&
509 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
[1856]510 ((pffb->achName[0] && pffb->achName[0] != '.') ||
511 (pffb->achName[1] &&
512 (pffb->achName[1] != '.' || pffb->achName[2]))))
513 {
[1871]514 // Got directory other than . or .. (or a file)
[551]515 isadir = TRUE;
516 break;
517 }
518 fb += pffb->oNextEntryOffset;
[1353]519 } // for
[2]520
[551]521 Interruptus:
[2]522
[551]523 if (isadir) {
[2]524
[1856]525 // Insert CNRITEM for selected directory (or file)
[1471]526 PCNRITEM pci;
[2]527
[1471]528 if (WinIsWindow((HAB)0, hwndCnr)) {
529 pci = WinSendMsg(hwndCnr,
530 CM_ALLOCRECORD,
531 MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
532 if (!pci) {
533 Win_Error(hwndCnr, HWND_DESKTOP, __FILE__, __LINE__,
534 GetPString(IDS_RECORDALLOCFAILEDTEXT));
535 }
536 else {
[1871]537 RECORDINSERT ri;
538 CHAR szBuffer[CCHMAXPATH + 14];
539 CHAR *p;
540 HPOINTER hptr;
541
542 p = strchr(wildcard, '*');
543 *p = 0;;
544 BldFullPathName(szBuffer, wildcard, pffb->achName);
545 pci->pszFileName = xstrdup(szBuffer, pszSrcFile, __LINE__); //NullStr; // 2015-08-19 SHL FIXME to doc why
546 p = strrchr(pci->pszFileName, '\\');
547 p++;
548 pci->pszDisplayName = p; //NullStr;
549 pci->rc.pszIcon = pci->pszDisplayName;
550 if (fForceUpper)
551 strupr(pci->pszFileName);
552 else if (fForceLower)
553 strlwr(pci->pszFileName);
554
555 flags = driveflags[toupper(*pci->pszFileName) - 'A'];
556
557 // get an icon to use with it
558 if (pffb->attrFile & FILE_DIRECTORY) {
559 // is directory
560 if (fNoIconsDirs ||
561 (flags & DRIVE_NOLOADICONS) ||
562 !isalpha(*pci->pszFileName)) {
563 hptr = (HPOINTER) 0;
564 }
565 else
566 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
567 }
568 else {
569 // is file
570 if (fNoIconsFiles ||
571 (flags & DRIVE_NOLOADICONS) ||
572 !isalpha(*pci->pszFileName)) {
573 hptr = (HPOINTER) 0;
574 }
575 else
576 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
577
578 if (!hptr || IsDefaultIcon(hptr))
579 hptr = IDFile(pci->pszFileName);
580 }
581
582 if (!hptr) {
583 hptr = pffb->attrFile & FILE_DIRECTORY ?
584 hptrDir : pffb->attrFile & FILE_SYSTEM ?
585 hptrSystem : pffb->attrFile & FILE_HIDDEN ?
586 hptrHidden : pffb->attrFile & FILE_READONLY ?
587 hptrReadonly : hptrFile;
588 }
589 pci->rc.hptrIcon = hptr;
[1471]590 memset(&ri, 0, sizeof(RECORDINSERT));
591 ri.cb = sizeof(RECORDINSERT);
[1858]592 ri.pRecordOrder = (PRECORDCORE)CMA_END;
593 ri.pRecordParent = (PRECORDCORE)pciParent;
594 ri.zOrder = (ULONG)CMA_TOP;
[1471]595 ri.cRecordsInsert = 1;
[1856]596 ri.fInvalidateRecord = TRUE;
[1871]597 if (!WinSendMsg(hwndCnr,
[1471]598 CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
[1856]599 // Assume busy and try again
[1877]600 DosSleep(50);
[1856]601 WinSetFocus(HWND_DESKTOP, hwndCnr);
[1871]602 if (WinIsWindow((HAB)0, hwndCnr)) {
[1471]603 if (!WinSendMsg(hwndCnr,
604 CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
605 Win_Error(hwndCnr, HWND_DESKTOP, __FILE__, __LINE__,
606 GetPString(IDS_RECORDINSERTFAILEDTEXT));
607 FreeCnrItem(hwndCnr, pci);
608 }
[1871]609 else
[1876]610 ok = TRUE;
[1471]611 }
612 }
613 else
[1856]614 ok = TRUE;
[1471]615 }
616 }
[1856]617 } // if isadir
[2]618 }
[1864]619 } // if !rc
620 else if (toupper(*wildcard) > 'B' && wildcard[1] == ':' && wildcard[2] == '\\' &&
[1865]621 wildcard[3] == '*' && !wildcard[4]) {
[1864]622 // Is root and no subdirectories
623 CHAR s[162];
[1865]624
[1864]625 sprintf(s,
[1865]626 GetPString(IDS_NOSUBDIRS2TEXT),
627 nm,
628 toupper(*pciParent->pszFileName),
629 isremote ? GetPString(IDS_NOSUBDIRS3TEXT) : NullStr);
[1864]630 Notify(s);
[2]631 }
[1858]632 else if (toupper(*wildcard) > 'B' && rc != ERROR_NO_MORE_FILES) {
[1856]633 // Find for remote or hard drive failed with error
[2]634 CHAR s[CCHMAXPATH + 80];
[1858]635 sprintf(s, GetPString(IDS_SEARCHERRORTEXT), rc, wildcard);
[2]636 Notify(s);
637 }
638
639None:
640
641 DosError(FERR_DISABLEHARDERR);
[1471]642 return ok;
[1856]643} // Stubby
644
645// Stubby/Flesh/Unflesh work list item
646
647typedef struct {
648 LIST2 list;
649 HWND hwndCnr;
650 PCNRITEM pci;
651 FLESHWORKACTION action;
652} FLESHWORKITEM;
653typedef FLESHWORKITEM *PFLESHWORKITEM;
654
655// Stubby/Flesh/Unflesh work list
656LIST2 FleshWorkList;
657
658HMTX hmtxFleshWork;
659HEV hevFleshWorkListChanged;
660
661/**
[1858]662 * Check work list item pci matches passed pci
[1856]663 */
664
665BOOL WorkListItemMatches(PLIST2 item, PVOID data)
666{
667 return ((PFLESHWORKITEM)data)->pci == ((PFLESHWORKITEM)item)->pci;
[2]668}
[793]669
[1856]670/**
671 * Delete stale items from flesh queue
672 */
673
674VOID DeleteStaleFleshWorkListItems(PCNRITEM pci)
675{
676 FLESHWORKITEM match;
677 PLIST2 item;
678
679 match.pci = pci;
680
681 for (;;) {
682 item = List2Search(&FleshWorkList, WorkListItemMatches, &match);
683 if (!item)
684 break;
685 List2Delete(&FleshWorkList, item);
686 xfree(item, pszSrcFile, __LINE__);
687 }
688}
689
690/**
691 * Add item to flesh work list
692 * eUnFlesh requests get special handling
693 * eFlesh etc. items for the same CNRITEM are considered stale and are
694 * deleted because eUnFlesh will free the CNRITEM associated with the item
695 * before the work list item is processed
696 */
697
[1877]698
[1856]699BOOL AddFleshWorkRequest(HWND hwndCnr, PCNRITEM pci, FLESHWORKACTION action)
700{
701 PFLESHWORKITEM item = xmallocz(sizeof(FLESHWORKITEM), pszSrcFile, __LINE__);
702 item->hwndCnr = hwndCnr;
703 item->pci = pci;
704 item->action= action;
705
[1858]706 if (fAmQuitting)
707 return FALSE;
[1856]708
709
[1860]710 xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
[1856]711
712 // Delete stale requests
[1858]713 if (item->action == eUnFlesh)
[1856]714 DeleteStaleFleshWorkListItems(pci);
715
716 List2Append(&FleshWorkList, (PLIST2)item);
717
[1860]718 xDosReleaseMutexSem(hmtxFleshWork);
719 xDosPostEventSem(hevFleshWorkListChanged);
[1856]720
721 return TRUE;
722}
723
724/**
725 * Return TRUE if work list empty
726 * Advisory only
727 */
728
729BOOL IsFleshWorkListEmpty()
730{
731 return FleshWorkList.next == NULL;
732}
733
734/**
[1858]735 * Check if pci pathname is parent of child path name
736 * @param data is child path name
[1860]737 * @return TRUE if is work item path is parent of given path
[1858]738 */
739
740BOOL IsParentOfChildPath(PLIST2 item, PVOID data)
741{
742 UINT c;
743 if (!((PFLESHWORKITEM)item)->pci->pszFileName) {
[1861]744 Runtime_Error(pszSrcFile, __LINE__, "IsParentOfChildPath called with pci %p pszFileName (null)", ((PFLESHWORKITEM)item)->pci);
[1858]745 return FALSE;
746 }
747 c = strlen(((PFLESHWORKITEM)item)->pci->pszFileName);
[1865]748 // 2015-08-23 SHL FIXME to not trap for Gregg
749 return strncmp(((PFLESHWORKITEM)item)->pci->pszFileName, (PCSZ)data, c) == 0;
[1858]750}
751
752/**
753 * Wait until work list empty or until dependent items removed from list
[1856]754 * Advisory only
[1858]755 * @parse pszFileName is dependent pathName
[1856]756 */
757
[1877]758
[1874]759VOID WaitFleshWorkListEmpty(PCSZ pszDirName, ULONG ulSleep)
[1856]760{
[1858]761 APIRET rc;
762 PFLESHWORKITEM item;
[1856]763 INT tid = GetTidForThread();
[1860]764 BOOL pathSaved = FALSE;
[1867]765 BOOL waited;
[1860]766 PCSZ pszSavedFleshFocusPath;
[1873]767 INT rcCount = 0;
[1856]768
[1877]769 if (tid == 1 || tid == tidFleshWorkListThread) { // 11 Oct 15 GKY Fixme did we intend to keep this
[1856]770 Runtime_Error(pszSrcFile, __LINE__, "WaitFleshWorkListEmpty called by tid %u", tid);
771 return; // Avoid hang
772 }
773 // Can not wait if call from thread 1 or FleshWorkListThread
[1867]774 for (waited = FALSE; !IsFleshWorkListEmpty(); waited = TRUE) {
[1858]775 // 2015-08-13 SHL
776 if (fAmQuitting)
777 return;
778
[1860]779 // Just wait for dependents to be gone if path name given
780 if (pszDirName) {
781 rc = xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
[1873]782 if (rc) {
783 rcCount++;
784 if (rcCount < 6)
785 continue; // Maybe should return ???
786 else {
787 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
788 PCSZ_DOSREQUESTMUTEXSEM);
789 return;
790 }
[1860]791
[1873]792 }
793
[1860]794 if (!pathSaved) {
795 // Give priority to work items for parents of this path
796 pathSaved = TRUE;
797 pszSavedFleshFocusPath = pszFleshFocusPath;
798 pszFleshFocusPath = pszDirName;
[1858]799 }
800
[1860]801 item = (PFLESHWORKITEM)List2Search(&FleshWorkList, IsParentOfChildPath, (PVOID)pszDirName);
[1858]802
[1860]803 xDosReleaseMutexSem(hmtxFleshWork);
[1873]804 rcCount = 0;
[1858]805
[1867]806 if (!item) {
807 if (waited)
[1874]808 DosSleep(ulSleep); // Let PM do some work
[1858]809 break; // Dependents gone from work list
[1867]810 }
[1860]811 } // if pszDirName
[1874]812 DosSleep(ulSleep);
[1867]813 } // for
[1858]814
[1865]815 if (pathSaved) {
[1860]816 xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
817 pszFleshFocusPath = pszSavedFleshFocusPath;
818 xDosReleaseMutexSem(hmtxFleshWork);
819 }
[1858]820
[1856]821}
822
823/**
824 * Set focus drive to optimize work list processing
825 * @param chDriveLetter is upper case drive letter (A-Z)
826 */
827
[1860]828VOID SetFleshFocusPath(PCSZ pszPath) {
829 PCSZ pszOld;
830 PCSZ pszNew = strdup(pszPath);
831 xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
832 pszOld = pszFleshFocusPath;
833 pszFleshFocusPath = pszNew;
834 xDosReleaseMutexSem(hmtxFleshWork);
835 if (pszOld)
836 xfree((PVOID)pszOld, pszSrcFile, __LINE__);
[1856]837}
838
839/**
840 * Run Flesh, UnFlesh, FleshEnv, Stubby for directory for items in work list
841 */
842
843VOID FleshWorkThread(PVOID arg)
844{
845 HAB thab;
846 HMQ hmq = (HMQ)0;
847
848 // 2015-08-07 SHL FIXME to be gone
849 static INT ProcessDirCount = 0;
850
851 DosError(FERR_DISABLEHARDERR);
852
853# ifdef FORTIFY
854 Fortify_EnterScope();
855# endif
856
857 thab = WinInitialize(0);
858 if (thab) {
859 hmq = WinCreateMsgQueue(thab, 0);
860 if (hmq) {
861 IncrThreadUsage();
862 priority_normal();
863
[1858]864 // process list entries until time to die
865 for (;!fAmQuitting;) {
[1856]866
867 PFLESHWORKITEM item;
868
869 // 2015-08-07 SHL FIXME to use SMPSafe...
[1860]870 xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
[1856]871
872 // 2015-08-14 SHL
873 // Get next work list item and remove from list
[1860]874 // If focus path set, process parents of focus path first
875 if (pszFleshFocusPath) {
876 item = (PFLESHWORKITEM)List2Search(&FleshWorkList, IsParentOfChildPath, (PVOID)pszFleshFocusPath);
877 if (!item) {
878 xfree((PSZ)pszFleshFocusPath, pszSrcFile, __LINE__);
879 pszFleshFocusPath = NULL; // Revert to normal
880 }
[1856]881 else
882 List2Delete(&FleshWorkList, (PLIST2)item);
883 }
884 else
885 item = NULL;
886
887 if (!item)
888 item = (PFLESHWORKITEM)List2DeleteFirst(&FleshWorkList);
889
[1860]890 xDosReleaseMutexSem(hmtxFleshWork);
[1856]891
[1858]892 // Wait for new items to be added to list
[1856]893 if (!item) {
[1871]894 ULONG ul;
895 xDosWaitEventSem(hevFleshWorkListChanged, SEM_INDEFINITE_WAIT);
896 xDosResetEventSem(hevFleshWorkListChanged, &ul);
897 continue;
[1856]898 }
899
[1877]900 if (WinIsWindow((HAB)0, item->hwndCnr)) {
[1856]901
902 switch (item->action) {
[1871]903 case eUnFlesh:
904 UnFlesh(item->hwndCnr, item->pci);
[1856]905 break;
906 case eFleshEnv:
907 FleshEnv(item->hwndCnr, item->pci);
908 break;
909 case eStubby:
[1871]910 priority_bumped();
911 Stubby(item->hwndCnr, item->pci);
912 priority_normal();
[1865]913 break;
[1856]914 case eFlesh:
915 if (Flesh(item->hwndCnr, item->pci)) {
916 // 2015-08-06 SHL FIXME to report?
917 }
918 break;
919 default:
920 Runtime_Error(pszSrcFile, __LINE__, "item %u unexpected", item->action);
921 } // switch
922
923
924 } // if window
925
926 xfree(item, pszSrcFile, __LINE__);
927
928 } // for
929
930 WinDestroyMsgQueue(hmq);
931 }
932 DecrThreadUsage();
933 WinTerminate(thab);
934 }
935
936 ProcessDirCount++;
937 if (ProcessDirCount >= FixedVolume) {
938 ProcessDirCount = 0;
939 FixedVolume = 0;
940 }
941
942# ifdef FORTIFY
943 Fortify_LeaveScope();
944# endif
945
946}
947
948/**
949 * Allocate resources and start FleshWorkThread
950 * @return TRUE if OK
951 */
952
953BOOL StartFleshWorkThread()
954{
955 APIRET rc = DosCreateMutexSem(NULL, &hmtxFleshWork, 0L /* Not shared */, FALSE /* Not owned */);
956 if (rc) {
957 Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
958 PCSZ_DOSCREATEMUTEXSEM);
959 return FALSE;
960 }
961
[1860]962 rc = xDosCreateEventSem(NULL, &hevFleshWorkListChanged, 0 /* Not shared */, FALSE /* Reset */);
963 if (rc)
964 return FALSE; // Give up
[1856]965 tidFleshWorkListThread = xbeginthread(FleshWorkThread,
966 65536,
967 NULL,
968 pszSrcFile, __LINE__);
969 return tidFleshWorkListThread != -1;
970
971}
972
973#pragma alloc_text(FLESH,Flesh,FleshEnv,UnFlesh,Stubby,FleshWorkThread,StartFleshWorkThread,AddFleshWorkRequest)
Note: See TracBrowser for help on using the repository browser.