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