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