Changeset 1891 for trunk/dll/flesh.c


Ignore:
Timestamp:
Jan 31, 2020, 3:47:37 AM (6 years ago)
Author:
Steven Levine
Message:

Rework FreeCnrItem to ensure all CNRITEMs deleted.
Use WinSendMsg CMA_NEXT.
Was using preccNextRecord which is not recommended because control does
not maintain linkage after inserts and deletes.
Note: arccnrs.c still needs to be reworked to use common functions from filldir.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/flesh.c

    r1890 r1891  
    66  Drive tree container management
    77
    8   Copyright (c) 1993-98 M. Kimes
    9   Copyright (c) 2005, 2015 Steven H. Levine
     8  Copyright (c) 1993-1998 M. Kimes
     9  Copyright (c) 2005-2020 Steven H. Levine
    1010
    1111  24 May 05 SHL Rework Win_Error usage
     
    3838  23 Aug 15 GKY Fixed code to notify on drive with no subdirectories in first 64 entries
    3939  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
     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
    4343  26 Sep 15 GKY Changes to speed up ExpandAll
    4444  26 Sep 15 GKY WaitFleshWorkListEmpty now gives error message and returns if semaphore request
    45                 fails more than 5 consecutive times.
     45                fails more than 5 consecutive times.
    4646  27 Sep 15 GKY DosSleep times in WaitFleshWorkListEmpty set by caller
    4747  10 Oct 15 GKY Don't use Flesh thread for floppy drive scans fix them getting mistakenly identified
    48                 as directories and add nonexistent subdirectories.
     48                as directories and add nonexistent subdirectories.
     49  25 Jan 20 SHL Complain if AddFleshWorkRequest returns empty string
     50  27 Jan 20 SHL Avoid more traps if passed bogus pciParent
    4951
    5052***********************************************************************/
     
    8183
    8284#ifdef PMPRINTF
    83 #define  _PMPRINTF_                     // Enable debug macros
     85#define _PMPRINTF_                      // Enable debug macros
    8486#include "PMPRINTF.H"
    8587#endif
     
    9294static INT tidFleshWorkListThread = -1; // 2015-08-08 SHL
    9395
    94 static PCSZ pszFleshFocusPath;  // 2015-08-20 SHL
     96static PCSZ pszFleshFocusPath;          // 2015-08-20 SHL
    9597
    9698#pragma data_seg(GLOBAL1)
     
    193195                ri.cRecordsInsert = 1;
    194196                ri.fInvalidateRecord = FALSE;
    195                 if (!WinSendMsg(hwndCnr,
     197                if (!WinSendMsg(hwndCnr,
    196198                                CM_INSERTRECORD, MPFROMP(pciL), MPFROMP(&ri)))
    197199                  FreeCnrItem(hwndCnr, pciL);
     
    223225 * @param hwnCnr is container to receive CNRITEMs
    224226 * @param pciParent is CNRITEM to have children inserted
    225  * @return TRUE if OK, FALSE is error detected
     227 * @return TRUE if OK, FALSE if error detected
    226228 */
    227229
     
    241243  if (!pciParent->fleshed) {
    242244    pciL = (PCNRITEM)WinSendMsg(hwndCnr,
    243                                 CM_QUERYRECORD,
    244                                 MPFROMP(pciParent),
    245                                 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
     245                                CM_QUERYRECORD,
     246                                MPFROMP(pciParent),
     247                                MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
    246248    // Added by Stubby to create plus sign run Stubby on it here and skip it in ProcessDirectory
    247249    if (pciL && (INT)pciL != -1) {
    248250      AddFleshWorkRequest(hwndCnr, pciL, eStubby);
    249       // 2015-08-06 SHL FIXME to ensure this can not happen
    250       if (!*pciL->pszFileName || !strcmp(pciL->pszFileName, NullStr))
    251         Runtime_Error(pszSrcFile, __LINE__, "Flesh called with pci %p pszFileName (null)",
    252                       pciL);
     251      /* Under some condtions AddFleshWorkRequest will return before pciL is populated
     252         2015-08-06 SHL FIXME to ensure pciL->szFileName not empty string
     253         2020-01-25 SHL FIXME to ensure pciL->szFileName not null
     254      */
     255      if (!pciL->pszFileName || !*pciL->pszFileName || !strcmp(pciL->pszFileName, NullStr))
     256        DosSleep(250);
     257      if (!pciL->pszFileName || !*pciL->pszFileName || !strcmp(pciL->pszFileName, NullStr)) {
     258        Runtime_Error(pszSrcFile, __LINE__, "Flesh called with pci %p pszFileName %p = %s",
     259                      pciL,
     260                      pciL ? pciL->pszFileName : 0,
     261                      pciL ? pciL->pszFileName ? pciL->pszFileName : "(null)" : "(null)");
     262        return FALSE;
     263      }
     264
    253265    }
    254266    dcd = INSTDATA(hwndCnr);
     
    269281                     dcd,
    270282                     NULL,              // total files
    271                      NULL,               // total bytes
    272                      (pciL && (INT)pciL != -1) ? pciL->pszDisplayName : 0);
     283                     NULL,              // total bytes
     284                     (pciL && (INT)pciL != -1) ? pciL->pszDisplayName : 0);
    273285    pciParent->fleshed = TRUE;
    274286    return TRUE;
     
    296308                                MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
    297309    if (!pciL || (INT)pciL == -1)
    298       break;   
     310      break;
    299311    RemoveCnrItems(hwndCnr, pciL, 1, CMA_FREE);
    300312    removed = TRUE;
     
    305317               CM_INVALIDATERECORD,
    306318               MPFROMP(&pciParent),
    307                MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
     319               MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
    308320    pciParent->fleshed = FALSE;
    309321    DosSleep(1); // Let container items go away
     
    347359  static BOOL brokenlan = FALSE, isbroken = FALSE;
    348360
    349   if (!pciParent || (INT)pciParent == -1 || !*pciParent->pszFileName
    350       || pciParent->pszFileName == NullStr || !hwndCnr)
     361  // 2020-01-27 SHL FIXME to doc how can get here with unitialized pciParent
     362  if (!pciParent || (INT)pciParent == -1||
     363      !pciParent->pszFileName ||
     364      !*pciParent->pszFileName ||
     365      pciParent->pszFileName == NullStr ||
     366      !hwndCnr) {
    351367    return FALSE;
     368  }
     369
    352370  // Build wildcard
    353371  len = strlen(pciParent->pszFileName);
     
    507525              (pffb->achName[1] != '.' || pffb->achName[2]))))
    508526        {
    509           // Got directory other than . or .. (or a file)
     527          // Got directory other than . or .. (or a file)
    510528          isadir = TRUE;
    511529          break;
     
    530548          }
    531549          else {
    532             RECORDINSERT ri;
    533             CHAR szBuffer[CCHMAXPATH + 14];
    534             CHAR *p;
    535             HPOINTER hptr;
    536 
    537             p = strchr(wildcard, '*');
    538             *p = 0;;
    539             BldFullPathName(szBuffer, wildcard, pffb->achName);
    540             pci->pszFileName =  xstrdup(szBuffer, pszSrcFile, __LINE__);
    541             p = strrchr(pci->pszFileName, '\\');
    542             p++;
    543             pci->pszDisplayName = p;
    544             pci->rc.pszIcon = pci->pszDisplayName;
    545             if (fForceUpper)
    546               strupr(pci->pszFileName);
    547             else if (fForceLower)
    548               strlwr(pci->pszFileName);
    549          
    550             flags = driveflags[toupper(*pci->pszFileName) - 'A'];
    551          
    552             // get an icon to use with it
    553             if (pffb->attrFile & FILE_DIRECTORY) {
    554               // is directory
    555               if (fNoIconsDirs ||
    556                   (flags & DRIVE_NOLOADICONS) ||
    557                   !isalpha(*pci->pszFileName)) {
    558                 hptr = (HPOINTER) 0;
    559               }
    560               else
    561                 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
    562             }
    563             else {
    564               // is file
    565               if (fNoIconsFiles ||
    566                   (flags & DRIVE_NOLOADICONS) ||
    567                   !isalpha(*pci->pszFileName)) {
    568                 hptr = (HPOINTER) 0;
    569               }
    570               else
    571                 hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
    572          
    573               if (!hptr || IsDefaultIcon(hptr))
    574                 hptr = IDFile(pci->pszFileName);
    575             }
    576          
    577             if (!hptr) {
    578               hptr = pffb->attrFile & FILE_DIRECTORY ?
    579                      hptrDir : pffb->attrFile & FILE_SYSTEM ?
    580                      hptrSystem : pffb->attrFile & FILE_HIDDEN ?
    581                      hptrHidden : pffb->attrFile & FILE_READONLY ?
    582                      hptrReadonly : hptrFile;
    583             }
    584             pci->rc.hptrIcon = hptr;
     550            RECORDINSERT ri;
     551            CHAR szBuffer[CCHMAXPATH + 14];
     552            CHAR *p;
     553            HPOINTER hptr;
     554
     555            p = strchr(wildcard, '*');
     556            *p = 0;;
     557            BldFullPathName(szBuffer, wildcard, pffb->achName);
     558            pci->pszFileName = xstrdup(szBuffer, pszSrcFile, __LINE__);
     559            p = strrchr(pci->pszFileName, '\\');
     560            p++;
     561            pci->pszDisplayName = p;
     562            pci->rc.pszIcon = pci->pszDisplayName;
     563            if (fForceUpper)
     564              strupr(pci->pszFileName);
     565            else if (fForceLower)
     566              strlwr(pci->pszFileName);
     567
     568            flags = driveflags[toupper(*pci->pszFileName) - 'A'];
     569
     570            // get an icon to use with it
     571            if (pffb->attrFile & FILE_DIRECTORY) {
     572              // is directory
     573              if (fNoIconsDirs ||
     574                  (flags & DRIVE_NOLOADICONS) ||
     575                  !isalpha(*pci->pszFileName)) {
     576                hptr = (HPOINTER) 0;
     577              }
     578              else
     579                hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
     580            }
     581            else {
     582              // is file
     583              if (fNoIconsFiles ||
     584                  (flags & DRIVE_NOLOADICONS) ||
     585                  !isalpha(*pci->pszFileName)) {
     586                hptr = (HPOINTER) 0;
     587              }
     588              else
     589                hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
     590
     591              if (!hptr || IsDefaultIcon(hptr))
     592                hptr = IDFile(pci->pszFileName);
     593            }
     594
     595            if (!hptr) {
     596              hptr = pffb->attrFile & FILE_DIRECTORY ?
     597                     hptrDir : pffb->attrFile & FILE_SYSTEM ?
     598                     hptrSystem : pffb->attrFile & FILE_HIDDEN ?
     599                     hptrHidden : pffb->attrFile & FILE_READONLY ?
     600                     hptrReadonly : hptrFile;
     601            }
     602            pci->rc.hptrIcon = hptr;
    585603            memset(&ri, 0, sizeof(RECORDINSERT));
    586604            ri.cb = sizeof(RECORDINSERT);
     
    590608            ri.cRecordsInsert = 1;
    591609            ri.fInvalidateRecord = TRUE;
    592             if (!WinSendMsg(hwndCnr,
     610            if (!WinSendMsg(hwndCnr,
    593611                            CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
    594612              // Assume busy and try again
    595               DosSleep(50); 
     613              DosSleep(50);
    596614              WinSetFocus(HWND_DESKTOP, hwndCnr);
    597               if (WinIsWindow((HAB)0, hwndCnr)) {
     615              if (WinIsWindow((HAB)0, hwndCnr)) {
    598616                if (!WinSendMsg(hwndCnr,
    599617                                CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
     
    602620                  FreeCnrItem(hwndCnr, pci);
    603621                }
    604                 else
    605                   ok = TRUE;
     622                else
     623                  ok = TRUE;
    606624              }
    607625            }
     
    652670
    653671HMTX hmtxFleshWork;
    654 HEV  hevFleshWorkListChanged;
     672HEV hevFleshWorkListChanged;
    655673
    656674/**
     
    691709 */
    692710
    693 
    694711BOOL AddFleshWorkRequest(HWND hwndCnr, PCNRITEM pci, FLESHWORKACTION action)
    695712{
     
    702719    return FALSE;
    703720
    704 
    705721  xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
    706722
     
    749765 * @parse pszFileName is dependent pathName
    750766 */
    751 
    752767
    753768VOID WaitFleshWorkListEmpty(PCSZ pszDirName, ULONG ulSleep)
     
    761776  INT rcCount = 0;
    762777
    763   if (tid == 1 || tid == tidFleshWorkListThread) { // 11 Oct 15 GKY Fixme did we intend to keep this
     778  // 11 Oct 15 GKY FIXME did we intend to keep this
     779  if (tid == 1 || tid == tidFleshWorkListThread) {
    764780    Runtime_Error(pszSrcFile, __LINE__, "WaitFleshWorkListEmpty called by tid %u", tid);
    765     return;             // Avoid hang
     781    return;                             // Avoid hang
    766782  }
    767783  // Can not wait if call from thread 1 or FleshWorkListThread
     
    775791      rc = xDosRequestMutexSem(hmtxFleshWork, SEM_INDEFINITE_WAIT);
    776792      if (rc) {
    777         rcCount++;
    778         if (rcCount < 6)
    779           continue;                     // Maybe should return ???
    780         else {
    781           Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
    782                     PCSZ_DOSREQUESTMUTEXSEM);
    783           return;
    784         }
     793        rcCount++;
     794        if (rcCount < 6)
     795          continue;                     // Maybe should return ???
     796        else {
     797          Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
     798                    PCSZ_DOSREQUESTMUTEXSEM);
     799          return;
     800        }
    785801
    786802      }
     
    800816      if (!item) {
    801817        if (waited)
    802           DosSleep(ulSleep);            // Let PM do some work
     818          DosSleep(ulSleep);            // Let PM do some work
    803819        break;                          // Dependents gone from work list
    804820      }
     
    871887          if (!item) {
    872888            xfree((PSZ)pszFleshFocusPath, pszSrcFile, __LINE__);
    873             pszFleshFocusPath = NULL;           // Revert to normal
     889            pszFleshFocusPath = NULL;   // Revert to normal
    874890          }
    875891          else
     
    886902        // Wait for new items to be added to list
    887903        if (!item) {
    888           ULONG ul;
    889           xDosWaitEventSem(hevFleshWorkListChanged, SEM_INDEFINITE_WAIT);
    890           xDosResetEventSem(hevFleshWorkListChanged, &ul);
    891           continue;
     904          ULONG ul;
     905          xDosWaitEventSem(hevFleshWorkListChanged, SEM_INDEFINITE_WAIT);
     906          xDosResetEventSem(hevFleshWorkListChanged, &ul);
     907          continue;
    892908        }
    893909
    894         if (WinIsWindow((HAB)0, item->hwndCnr)) {
     910        if (WinIsWindow((HAB)0, item->hwndCnr)) {
    895911
    896912          switch (item->action) {
    897           case eUnFlesh:
    898             UnFlesh(item->hwndCnr, item->pci);
     913          case eUnFlesh:
     914            UnFlesh(item->hwndCnr, item->pci);
    899915            break;
    900916          case eFleshEnv:
     
    902918            break;
    903919          case eStubby:
    904             priority_bumped();
    905             Stubby(item->hwndCnr, item->pci);
    906             priority_normal();
     920            priority_bumped();
     921            Stubby(item->hwndCnr, item->pci);
     922            priority_normal();
    907923            break;
    908924          case eFlesh:
     
    915931          } // switch
    916932
    917 
    918933        } // if window
    919934
Note: See TracChangeset for help on using the changeset viewer.