Changeset 1335 for trunk/dll/arccnrs.c


Ignore:
Timestamp:
Dec 13, 2008, 12:49:02 AM (17 years ago)
Author:
Steven Levine
Message:

Ticket 26: Add exception handlers to all threads using xbeginthread

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/arccnrs.c

    r1334 r1335  
    5858  19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
    5959  25 Aug 08 GKY Check TMP directory space warn if lee than 5 MiB prevent archiver from opening if
    60                 less than 10 KiB (It hangs and can't be closed)
     60                less than 10 KiB (It hangs and can't be closed)
    6161  08 Nov 08 GKY Add WaitChildThread to fix hang caused by viewer trying to open a file before
    62                 the archiver process closes. (Ticket 58)
     62                the archiver process closes. (Ticket 58)
    6363  23 Nov 08 JBS Ticket 284: Support archivers with no Start or End of list strings
    6464  29 Nov 08 GKY Add flag to tell CheckListProc file is in an archive so it won't try to open it.
    6565  29 Nov 08 GKY Remove or replace with a mutex semaphore DosEnterCriSec where appropriate.
    6666  30 Nov 08 GKY Add the option of creating a subdirectory from the arcname
    67                 for the extract path to arc container.
     67                for the extract path to arc container.
    6868  02 Dec 08 JBS Ticket 284: Changed string indicating no Start/End of list strings.
    6969  03 Dec 08 GKY Subdirectory from the arcname for the extract path only created if an "extract"
    70                 menu option is selected.
     70                menu option is selected.
     71  10 Dec 08 SHL Integrate exception handler support
    7172
    7273***********************************************************************/
     
    7879#include <share.h>                      // SH_DENYWR
    7980#include <limits.h>                     // ULONG_MAX
    80 #include <process.h>                    // _beginthread
     81// #include <process.h>                 // _beginthread // 10 Dec 08 SHL
    8182
    8283#if 0
     
    107108#include "strutil.h"                    // GetPString
    108109#include "notebook.h"                   // CfgDlgProc
    109 #include "worker.h"                     // Action, MassAction
     110#include "worker.h"             // Action, MassAction
    110111#include "avv.h"                        // ArcReviewDlgProc, rewrite_archiverbb2
    111112#include "chklist.h"                    // CenterOverWindow, CheckListProc
    112113#include "common.h"                     // CommonCreateTextChildren, CommonFrameWndProc, CommonTextPaint
    113                                         // CommonTextButton
     114                                // CommonTextButton
    114115#include "draglist.h"                   // DoFileDrag, DragOne
    115116#include "valid.h"                      // GetDesktopName, TestCDates
     
    121122#include "srchpath.h"                   // RunFM2Util
    122123#include "misc.h"                       // Broadcast, CheckMenu, CurrentRecord, SayFilter, SaySort
    123                                         // DrawTargetEmphasis, IsFm2Window
     124                                // DrawTargetEmphasis, IsFm2Window
    124125#include "select.h"                     // SelectAll, SelectList
    125126#include "findrec.h"                    // ShowCnrRecord
     
    141142#include "literal.h"                    // wildcard
    142143#include "wrappers.h"                   // xrealloc
    143 #include "misc.h"                       // AdjustCnrColVis, QuickPopup, SetSortChecks, SwitchCommand
     144#include "misc.h"               // AdjustCnrColVis, QuickPopup, SetSortChecks, SwitchCommand
    144145#include "select.h"                     // DeselectAll, InvertAll
    145146#include "strips.h"                     // bstrip
    146147#include "dirs.h"                       // save_dir2
    147148#include "fortify.h"
     149#include "excputil.h"                   // 06 May 08 SHL added
    148150
    149151#define ARCFLAGS_REALDIR    0x00000001
     
    207209      priority_normal();
    208210      ret = runemf2(WaitChild->RunFlags, WaitChild->hwndClient, pszSrcFile, __LINE__,
    209                     WaitChild->pszDirectory, WaitChild->pszEnvironment,
    210                     WaitChild->formatstring, WaitChild->CmdLine);
     211                    WaitChild->pszDirectory, WaitChild->pszEnvironment,
     212                    WaitChild->formatstring, WaitChild->CmdLine);
    211213      if (ret != -1) {
    212         if (IsFile(WaitChild->filename) == 1)
    213           PostMsg(WaitChild->hwndCnr, UM_ENTER, MPFROMP(filename), MPVOID);
     214        if (IsFile(WaitChild->filename) == 1)
     215          PostMsg(WaitChild->hwndCnr, UM_ENTER, MPFROMP(filename), MPVOID);
    214216      }
    215217      DecrThreadUsage();
     
    223225  Fortify_LeaveScope();
    224226#  endif
    225   _endthread();
     227  // _endthread();                      // 10 Dec 08 SHL
    226228}
    227229
     
    578580  if (CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) == 1)
    579581    saymsg(MB_OK,
    580            HWND_DESKTOP,
    581            NullStr,
    582            GetPString(IDS_ARCTMPDRIVESPACELIMITED),
    583            ArcTempRoot);
     582           HWND_DESKTOP,
     583           NullStr,
     584           GetPString(IDS_ARCTMPDRIVESPACELIMITED),
     585           ArcTempRoot);
    584586  MakeTempName(arctemp, ArcTempRoot, 2);
    585587
     
    681683    if (fp) {
    682684      gotstart = !info->startlist ||            // If list has no start marker
    683                  !*info->startlist ||
    684                  (stricmp(info->startlist, NO_START_OF_ARCHIVER_LIST_STRING) == 0);
     685                 !*info->startlist ||
     686                 (stricmp(info->startlist, NO_START_OF_ARCHIVER_LIST_STRING) == 0);
    685687
    686688      while (!feof(fp) && !gotend && !*pStopFlag) {
     
    15811583      CHAR *s = (CHAR *) mp1, *p, *pp; // filename[CCHMAXPATH];
    15821584      WAITCHILD *WaitChild;
    1583       APIRET rc;
    15841585
    15851586      WaitChild = xmallocz(sizeof(WAITCHILD), pszSrcFile, __LINE__);
    15861587      if (!WaitChild)
    1587         return 0;
     1588        return 0;
    15881589      if (s) {
    15891590        if (!dcd->info->extract) {
     
    15921593          return 0;
    15931594        }
    1594         sprintf(WaitChild->CmdLine, "%s %s %s",
    1595                                     dcd->info->exwdirs ? dcd->info->exwdirs :
     1595        sprintf(WaitChild->CmdLine, "%s %s %s",
     1596                                    dcd->info->exwdirs ? dcd->info->exwdirs :
    15961597                                    dcd->info->extract,
    1597                                     BldQuotedFileName(szQuotedArcName, dcd->arcname),
    1598                                     BldQuotedFileName(szQuotedMemberName, s));
    1599         /*runemf2(SEPARATE | ASYNCHRONOUS | WAIT |
    1600                 (fArcStuffVisible ? 0 : BACKGROUND),
     1598                                    BldQuotedFileName(szQuotedArcName, dcd->arcname),
     1599                                    BldQuotedFileName(szQuotedMemberName, s));
     1600        /*runemf2(SEPARATE | ASYNCHRONOUS | WAIT |
     1601                (fArcStuffVisible ? 0 : BACKGROUND),
    16011602                , pszSrcFile, __LINE__, dcd->workdir, NULL,
    16021603                "%s %s %s",
     
    16231624          p++;
    16241625        }
    1625         free(s);
    1626         WaitChild->RunFlags = SEPARATE | ASYNCHRONOUS | WAIT |
    1627                               (fArcStuffVisible ? 0 : BACKGROUND);
    1628         WaitChild->hwndClient = dcd->hwndClient;
    1629         WaitChild->pszDirectory = xstrdup(dcd->workdir, pszSrcFile, __LINE__);
    1630         WaitChild->pszEnvironment = NULL;
    1631         strcpy(WaitChild->formatstring, "%s");
    1632         WaitChild->hwndCnr = dcd->hwndCnr;
    1633         rc = _beginthread(WaitChildThread, NULL, 65536, WaitChild);
    1634         if (rc == -1)
    1635           Runtime_Error(pszSrcFile, __LINE__,
    1636                         GetPString(IDS_COULDNTSTARTTHREADTEXT));
    1637         //if (IsFile(filename) == 1) {
    1638 #if 0 // 06 Oct 07 SHL fixme to be gone - set to 0 for ticket #58 testing
    1639           if (fViewChild && fArcStuffVisible)
    1640             DosSleep(100);  // Allow unzip session to finish closing 14 Mar 07 SHL
    1641 #endif
    1642           //WinSendMsg(WaitChild->hwndCnr, UM_ENTER, MPFROMP(filename), MPVOID);
    1643 
     1626        free(s);
     1627        WaitChild->RunFlags = SEPARATE | ASYNCHRONOUS | WAIT |
     1628                              (fArcStuffVisible ? 0 : BACKGROUND);
     1629        WaitChild->hwndClient = dcd->hwndClient;
     1630        WaitChild->pszDirectory = xstrdup(dcd->workdir, pszSrcFile, __LINE__);
     1631        WaitChild->pszEnvironment = NULL;
     1632        strcpy(WaitChild->formatstring, "%s");
     1633        WaitChild->hwndCnr = dcd->hwndCnr;
     1634        xbeginthread(WaitChildThread,
     1635                     65536,
     1636                     WaitChild,
     1637                     pszSrcFile,
     1638                     __LINE__);
    16441639      }
    16451640    }
     
    17071702                  strlen(li->list[x]) + 5 > MaxComLineStrg) {
    17081703                runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
    1709                         (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
    1710                         hwnd, pszSrcFile, __LINE__,
     1704                        (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
     1705                        hwnd, pszSrcFile, __LINE__,
    17111706                        NULL, NULL, "%s", szBuffer);
    17121707                *p = 0;
     
    17391734            ck.list = li->list;
    17401735            ck.cmd = li->type;
    1741             ck.prompt = prompt;
    1742             ck.flags = CHECK_ARCHIVE;
     1736            ck.prompt = prompt;
     1737            ck.flags = CHECK_ARCHIVE;
    17431738            sprintf(prompt, GetPString(IDS_ARCCNRDELREFTEXT),
    17441739                    (li->type == IDM_DELETE) ?
     
    18271822              UINT numfiles = 0, numalloc = 0;
    18281823
    1829               if (li->targetpath && fFileNameCnrPath &&
    1830                   stricmp(lastextractpath, li->targetpath)) {
    1831                 strcpy(lastextractpath, li->targetpath);
    1832                 SetDir(dcd->hwndParent, hwnd, li->targetpath, 1);
    1833               }
     1824              if (li->targetpath && fFileNameCnrPath &&
     1825                  stricmp(lastextractpath, li->targetpath)) {
     1826                strcpy(lastextractpath, li->targetpath);
     1827                SetDir(dcd->hwndParent, hwnd, li->targetpath, 1);
     1828              }
    18341829              for (x = 0; li->list[x]; x++) {
    1835                 BldFullPathName(fullname, li->targetpath, li->list[x]);
    1836                 //Check if file already exists on disk warn if it does.
     1830                BldFullPathName(fullname, li->targetpath, li->list[x]);
     1831                //Check if file already exists on disk warn if it does.
    18371832                if (IsFile(fullname) != -1) {
    18381833                  AddToList(li->list[x], &exfiles, &numfiles, &numalloc);
     
    18431838                }
    18441839              }
    1845               if (exfiles && numfiles) {
     1840              if (exfiles && numfiles) {
    18461841
    18471842                CHECKLIST ckl;
     
    18521847                ckl.list = exfiles;
    18531848                ckl.prompt = prompt;
    1854                 ckl.cmd = li->type;
    1855                 ckl.flags = CHECK_ARCHIVE;
     1849                ckl.cmd = li->type;
     1850                ckl.flags = CHECK_ARCHIVE;
    18561851                sprintf(prompt,
    18571852                        GetPString(IDS_REPLACEWARNTEXT),
     
    19071902              z = x;
    19081903              runemf2(SEPARATE | WINDOWED | WAIT |
    1909                       (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
    1910                       hwnd, pszSrcFile, __LINE__,
     1904                      (fArcStuffVisible ? 0 : BACKGROUND | MINIMIZED),
     1905                      hwnd, pszSrcFile, __LINE__,
    19111906                      li->targetpath, NULL, "%s", pszCmdLine);
    19121907              *endofit = 0;
     
    20412036              else if (li->type == IDM_PRINT) {
    20422037                strcpy(li->targetpath, printer);
    2043                 if (_beginthread(PrintListThread, NULL, 65536, (PVOID) li) !=
    2044                     -1) {
    2045                   Runtime_Error(pszSrcFile, __LINE__,
    2046                                 GetPString(IDS_COULDNTSTARTTHREADTEXT));
    2047                   li = NULL;
     2038                // 10 Dec 08 SHL correct error handling - looked backward
     2039                if (xbeginthread(PrintListThread,
     2040                                 65536,
     2041                                 li,
     2042                                 pszSrcFile,
     2043                                 __LINE__) != -1)
     2044                {
     2045                  li = NULL;            // Ensure not freed here
    20482046                }
     2047
    20492048              }
    20502049              else if (li->type == IDM_VIEWARCHIVE) {
     
    20932092                  wk->li = li;
    20942093                  strcpy(wk->directory, dcd->directory);
    2095                   if (_beginthread(Action, NULL, 122880, (PVOID) wk) == -1) {
    2096                     Runtime_Error(pszSrcFile, __LINE__,
    2097                                   GetPString(IDS_COULDNTSTARTTHREADTEXT));
     2094                  if (xbeginthread(Action,
     2095                                   122880,
     2096                                   wk,
     2097                                   pszSrcFile,
     2098                                   __LINE__) == -1)
     2099                  {
    20982100                    free(wk);
    20992101                    FreeListInfo((LISTINFO *) mp1);
     
    21882190          }
    21892191          break;
    2190         }
     2192        } // switch
    21912193      }
    21922194      if (li->type != IDM_OPENDEFAULT && li->type != IDM_OPENSETTINGS)
     
    22942296                         CM_SEARCHSTRING,
    22952297                         MPFROMP(&srch), MPFROMLONG(CMA_FIRST));
    2296         if (pci && (INT) pci != -1) {
    2297 
    2298           USHORT attrib = CRA_CURSORED;
     2298        if (pci && (INT) pci != -1) {
     2299
     2300          USHORT attrib = CRA_CURSORED;
    22992301
    23002302
     
    24412443                           CM_QUERYRECORDEMPHASIS,
    24422444                           MPFROMLONG(CMA_FIRST), MPFROMSHORT(CRA_CURSORED));
    2443           if (pci && (INT) pci != -1) {
     2445          if (pci && (INT) pci != -1) {
    24442446            if (fSplitStatus && hwndStatus2) {
    24452447              if (dcd->ullTotalBytes)
     
    25942596        }
    25952597        WinSendMsg(hwnd, CM_SORTRECORD, MPFROMP(ArcSort), MPFROMP(dcd));
    2596         if (_beginthread(MakeObjWin, NULL, 245760, (PVOID) dcd) == -1) {
    2597           Runtime_Error(pszSrcFile, __LINE__,
    2598                         GetPString(IDS_COULDNTSTARTTHREADTEXT));
     2598        if (xbeginthread(MakeObjWin,
     2599                         245760,
     2600                         dcd,
     2601                         pszSrcFile,
     2602                         __LINE__) == -1)
     2603        {
    25992604          PostMsg(hwnd, WM_CLOSE, MPVOID, MPVOID);
    26002605          return 0;
     
    26372642          if (!SetDir(dcd->hwndParent, hwnd, s, 0)) {
    26382643            if (stricmp(dcd->directory, s)) {
    2639               //DosEnterCritSec();  //GKY 11-29-08
    2640               DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
    2641               strcpy(lastextractpath, s);
    2642               DosReleaseMutexSem(hmtxFM2Globals);
     2644              //DosEnterCritSec();  //GKY 11-29-08
     2645              DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
     2646              strcpy(lastextractpath, s);
     2647              DosReleaseMutexSem(hmtxFM2Globals);
    26432648              //DosExitCritSec();
    26442649            }
     
    26712676      printf("%s %d UM_ENTER %s\n",__FILE__, __LINE__, filename); fflush(stdout);
    26722677      if (IsFile(filename) != 1) {
    2673         free(mp1);
    2674         return 0;
     2678        free(mp1);
     2679        return 0;
    26752680      }
    26762681      WinQueryWindowPos(dcd->hwndFrame, &swp);
     
    28032808      }
    28042809      else if (mp1 && IsFile(mp1) == 1 &&
    2805                CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
     2810               CheckDriveSpaceAvail(ArcTempRoot, ullDATFileSpaceNeeded, ullTmpSpaceNeeded) != 2) {
    28062811        StartArcCnr(HWND_DESKTOP,
    28072812                    dcd->hwndFrame, (CHAR *) mp1, 4, (ARC_TYPE *) mp2);
     
    30233028      case IDM_ARCEXTRACTEXIT:
    30243029      case IDM_ARCEXTRACT:
    3025         if (dcd->directory && fFileNameCnrPath &&
    3026             stricmp(lastextractpath, dcd->directory)) {
    3027           strcpy(lastextractpath, dcd->directory);
    3028           SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
    3029         }
     3030        if (dcd->directory && fFileNameCnrPath &&
     3031            stricmp(lastextractpath, dcd->directory)) {
     3032          strcpy(lastextractpath, dcd->directory);
     3033          SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
     3034        }
    30303035        if (dcd->info->extract)
    30313036          runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
     
    30403045      case IDM_ARCEXTRACTWDIRSEXIT:
    30413046      case IDM_ARCEXTRACTWDIRS:
    3042         if (dcd->directory && fFileNameCnrPath &&
    3043             stricmp(lastextractpath, dcd->directory)) {
    3044           strcpy(lastextractpath, dcd->directory);
    3045           SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
    3046         }
     3047        if (dcd->directory && fFileNameCnrPath &&
     3048            stricmp(lastextractpath, dcd->directory)) {
     3049          strcpy(lastextractpath, dcd->directory);
     3050          SetDir(dcd->hwndParent, hwnd, dcd->directory, 1);
     3051        }
    30473052        if (dcd->info->exwdirs)
    30483053          runemf2(SEPARATE | WINDOWED | ASYNCHRONOUS |
     
    30873092        if (mp2) {
    30883093          if (stricmp(dcd->directory, (CHAR *) mp2)) {
    3089             //DosEnterCritSec(); //GKY 11-29-08
    3090             DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
     3094            //DosEnterCritSec(); //GKY 11-29-08
     3095            DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
    30913096            strcpy(lastextractpath, (CHAR *) mp2);
    3092             MakeValidDir(lastextractpath);
    3093             DosReleaseMutexSem(hmtxFM2Globals);
     3097            MakeValidDir(lastextractpath);
     3098            DosReleaseMutexSem(hmtxFM2Globals);
    30943099            //DosExitCritSec();
    30953100          }
     
    37463751          else
    37473752            strcpy(dcd->directory, extractpath);
    3748         }
    3749         if (!*dcd->directory && fFileNameCnrPath && dcd->arcname) {
    3750           strcpy(fullname, dcd->arcname);
    3751           p = strrchr(fullname, '.');
    3752           if (p)
    3753            *p = 0;
    3754           else {
    3755             p = fullname + strlen(fullname);
    3756             p--;
    3757             *p = 0;
    3758           }
    3759           strcpy(dcd->directory, fullname);
    3760         }
     3753        }
     3754        if (!*dcd->directory && fFileNameCnrPath && dcd->arcname) {
     3755          strcpy(fullname, dcd->arcname);
     3756          p = strrchr(fullname, '.');
     3757          if (p)
     3758           *p = 0;
     3759          else {
     3760            p = fullname + strlen(fullname);
     3761            p--;
     3762            *p = 0;
     3763          }
     3764          strcpy(dcd->directory, fullname);
     3765        }
    37613766        if (!*dcd->directory && *lastextractpath) {
    3762           //DosEnterCritSec();  //GKY 11-29-08
    3763           DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
    3764           strcpy(dcd->directory, lastextractpath);
    3765           DosReleaseMutexSem(hmtxFM2Globals);
     3767          //DosEnterCritSec();  //GKY 11-29-08
     3768          DosRequestMutexSem(hmtxFM2Globals, SEM_INDEFINITE_WAIT);
     3769          strcpy(dcd->directory, lastextractpath);
     3770          DosReleaseMutexSem(hmtxFM2Globals);
    37663771          //DosExitCritSec();
    37673772        }
     
    37913796        dcd->dontclose = (flags & 4) != 0;
    37923797        dcd->info = info;
    3793         dcd->sortFlags = DefArcSortFlags;
     3798        dcd->sortFlags = DefArcSortFlags;
    37943799        {
    37953800          PFNWP oldproc;
     
    39033908                            SWP_ACTIVATE);
    39043909          }
    3905         }
     3910        }
    39063911      }
    39073912#     ifdef FORTIFY
Note: See TracChangeset for help on using the changeset viewer.