Changeset 762 for trunk/dll/arccnrs.c


Ignore:
Timestamp:
Aug 5, 2007, 1:19:21 AM (18 years ago)
Author:
Steven Levine
Message:

Use two pass logic to free CNRITEMs and ARCITEMs
Rename pszLongname to pszLongName
More compare directories rework
Make directory sizes item draw placement deterministic - how did it ever work?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/arccnrs.c

    r751 r762  
    6161#include <limits.h>
    6262#include <process.h>                    // _beginthread
     63
     64#if 0
    6365#include <malloc.h>                     // _heapchk
     66#endif
    6467
    6568#include "fm3dll.h"
     
    317320{
    318321  // DbgMsg(pszSrcFile, __LINE__, "FreeArcItemData %p", pai);
    319 
    320   if (pai->pszFileName && pai->pszFileName != NullStr)
    321     xfree(pai->pszFileName);
     322  PSZ psz;
     323
     324  if (pai->pszFileName && pai->pszFileName != NullStr) {
     325    psz = pai->pszFileName;
     326    pai->pszFileName = NullStr;
     327    free(psz);
     328  }
    322329}
    323330
    324331/**
    325  * Remove item from archive container and free associated storage if requested
     332 * Remove item(s) from archive container and free associated storage if requested
     333 * @param paiFirst points to first item to remove or NULL to remove all
     334 * @param usCnt is remove count or 0 to remove all
    326335 */
    327336
    328 static VOID RemoveArcItems(HWND hwnd, PARCITEM pai, USHORT usCnt, USHORT usFlags)
     337static VOID RemoveArcItems(HWND hwnd, PARCITEM paiFirst, USHORT usCnt, USHORT usFlags)
    329338{
    330   if (usCnt == 0) {
    331     if (pai != NULL)
    332       Runtime_Error(pszSrcFile, __LINE__, "pai not NULL");
    333     else {
    334       for (;;) {
     339  INT remaining = usCnt;
     340  PARCITEM pai;
     341
     342  if ((usCnt && !paiFirst) || (!usCnt && paiFirst))
     343    Runtime_Error(pszSrcFile, __LINE__, "paiFirst %p usCnt %u mismatch", paiFirst, usCnt);
     344  else {
     345    // Free our buffers if free requested
     346    if (usFlags & CMA_FREE) {
     347      if (paiFirst)
     348        pai = paiFirst;
     349      else {
    335350        pai = (PARCITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
    336351                                   MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
    337         if (!pai)
     352        if ((INT)pai == -1) {
     353          Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
     354          remaining = -1;
     355          pai = NULL;
     356        }
     357      }
     358      while (pai) {
     359        FreeArcItemData(pai);
     360        pai = (PARCITEM)pai->rc.preccNextRecord;
     361        if (remaining && --remaining == 0)
    338362          break;
    339         else if ((INT)pai == -1) {
    340           Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
    341           break;
    342         }
    343         else
    344           RemoveArcItems(hwnd, pai, 1, usFlags);
    345363      }
    346364    }
    347365  }
    348   else if (usCnt != 1)
    349     Runtime_Error(pszSrcFile, __LINE__, "count not 1");
    350   else {
    351     // DbgMsg(pszSrcFile, __LINE__, "RemoveArcItems %p %u %s", pai, usCnt, pai->pszFileName);
    352 
    353     if (usFlags & CMA_FREE)
    354       FreeArcItemData(pai);
    355 
    356     if ((INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&pai), MPFROM2SHORT(usCnt, usFlags)) == -1) {
     366
     367  // DbgMsg(pszSrcFile, __LINE__, "RemoveArcItems %p %u %s", pai, usCnt, pai->pszFileName);
     368
     369  if (remaining != - 1) {
     370    remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&paiFirst), MPFROM2SHORT(usCnt, usFlags));
     371    if (remaining == -1) {
    357372      // Win_Error2(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,IDS_CMREMOVEERRTEXT);
    358       Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pai %p", hwnd, pai);
     373      Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pai %p cnt %u", hwnd, paiFirst, usCnt);
    359374    }
    360375  }
     
    362377
    363378/**
    364  * Empty all records from an archive container and free associated storage and
    365  * Free up field infos
     379 * Empty all records from an archive container and
     380 * free associated storage and free up field infos
    366381 */
    367382
    368383static VOID EmptyArcCnr(HWND hwnd)
    369384{
    370 #if 1 // fixme to disable or to be configurable
     385#if 0 // fixme to disable or to be configurable
    371386  {
    372387    int state = _heapchk();
    373388    if (state != _HEAPOK)
    374389      Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
     390    else
     391      DbgMsg(pszSrcFile, __LINE__, "_memavl %u", _memavl());
    375392  }
    376393#endif
     
    659676                pai->flags = ARCFLAGS_REALDIR;
    660677              pai->pszFileName = xstrdup(fname,pszSrcFile, __LINE__);
    661               pai->pszDisplayName = pai->pszFileName;
    662               pai->rc.pszIcon = pai->pszDisplayName;
     678              pai->pszDisplayName = pai->pszFileName;
     679              pai->rc.pszIcon = pai->pszDisplayName;
    663680              if (fdate)
    664681                strcpy(pai->szDate, fdate);
     
    12111228      cni.pDragInfo = (PDRAGINFO) mp1;
    12121229      li = DoFileDrop(dcd->hwndCnr,
    1213                       dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
     1230                      dcd->directory, FALSE, MPVOID, MPFROMP(&cni));
    12141231      CheckPmDrgLimit(cni.pDragInfo);
    12151232      if (li) {
     
    18431860              if (li->type == IDM_MCIPLAY) {
    18441861
    1845                 FILE *fp;
     1862                FILE *fp;
    18461863
    18471864                fp = xfopen("$FM2PLAY.$$$", "w", pszSrcFile, __LINE__);
     
    18511868                    fprintf(fp, "%s\n", li->list[x]);
    18521869                  fprintf(fp, ";end\n");
    1853                   fclose(fp);
    1854                   RunFM2Util("FM2PLAY.EXE", "/@$FM2PLAY.$$$");
    1855                 }
     1870                  fclose(fp);
     1871                  RunFM2Util("FM2PLAY.EXE", "/@$FM2PLAY.$$$");
     1872                }
    18561873              }
    18571874              else if (li->type == IDM_PRINT) {
     
    22422259      }
    22432260      if ((dcd->arcfilled && !dcd->totalfiles) ||
    2244           !IsArcThere(hwnd, dcd->arcname))
     2261          !IsArcThere(hwnd, dcd->arcname))
    22452262        PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
    22462263    }
     
    26112628          WinSetFocus(HWND_DESKTOP,
    26122629                      hwndActive == hwnd ?
    2613                         WinWindowFromID(dcd->hwndClient, ARC_EXTRACTDIR) :
    2614                         hwnd);
     2630                        WinWindowFromID(dcd->hwndClient, ARC_EXTRACTDIR) :
     2631                        hwnd);
    26152632        }
    26162633        break;
     
    31113128          DosBeep(500, 100);            // fixme to know why beep?
    31123129          li = DoFileDrop(hwnd, dcd->arcname, FALSE, mp1, mp2);
    3113           DosBeep(50, 100);             // fixme to know why beep?
    3114           CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
     3130          DosBeep(50, 100);             // fixme to know why beep?
     3131          CheckPmDrgLimit(((PCNRDRAGINFO)mp2)->pDragInfo);
    31153132          if (li) {
    31163133            li->type = li->type == DO_MOVE ? IDM_ARCHIVEM : IDM_ARCHIVE;
Note: See TracChangeset for help on using the changeset viewer.