Changeset 1341 for trunk/dirsize.c


Ignore:
Timestamp:
Dec 14, 2008, 11:18:26 PM (17 years ago)
Author:
Steven Levine
Message:

Ticket 26: add thread 1 exception handler support to applets

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dirsize.c

    r1220 r1341  
    1212  06 Jan 04 SHL Total drives >4GB better
    1313  08 Jul 08 SHL Avoid WARNALL warning
     14  14 Dec 08 SHL Add exception handler support
     15  14 Dec 08 SHL Drop NEVER used code
    1416
    1517***********************************************************************/
    1618
    1719#include <string.h>
    18 #include <ctype.h>
     20#include <ctype.h>                      // toupper
    1921
    2022#define INCL_DOS
    2123#define INCL_WIN
     24#define INCL_DOSEXCEPTIONS              // XCTP_...
     25#define INCL_DOSERRORS                  // NO_ERROR
    2226
    2327#include "dll\fm3dll.h"
    24 #include "dll\fm3dll2.h"                        // #define's for UM_*, control id's, etc.
    25 #include "dll\notebook.h"                       // Data declaration(s)
    26 #include "dll\info.h"                           // Data declaration(s)
    27 #include "dll\mainwnd.h"                        // Data declaration(s)
     28#include "dll\fm3dll2.h"                // #define's for UM_*, control id's, etc.
     29#include "dll\info.h"                   // driveflags
     30#include "dll\mainwnd.h"                // FM3ModHandle
    2831#include "dll\fm3dlg.h"
    29 #include "dll\valid.h"                          // CheckDrive
    30 #include "dll\init.h"                           // InitFM3DLL
    31 #include "dll\dirsize.h"                        // DirSizeProc
     32#include "dll\valid.h"                  // CheckDrive
     33#include "dll\init.h"                   // InitFM3DLL
     34#include "dll\dirsize.h"                // DirSizeProc
     35#include "dll\errutil.h"                // Error reporting
     36#include "dll\excputil.h"               // Exception handlers
     37
     38static PSZ pszSrcFile = __FILE__;
    3239
    3340MRESULT EXPENTRY DirMainProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     
    5562
    5663      for (x = 2; x < 26; x++) {
    57         if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
    58           *dirname = (CHAR) x + 'A';
    59           WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_INSERTITEM,
    60                             MPFROM2SHORT(LIT_END, 0), MPFROMP(dirname));
    61           if (first) {
    62             WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_SELECTITEM,
    63                               MPFROMSHORT(0), MPFROMSHORT(TRUE));
    64             first = FALSE;
    65           }
    66         }
     64        if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
     65          *dirname = (CHAR) x + 'A';
     66          WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_INSERTITEM,
     67                            MPFROM2SHORT(LIT_END, 0), MPFROMP(dirname));
     68          if (first) {
     69            WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_SELECTITEM,
     70                              MPFROMSHORT(0), MPFROMSHORT(TRUE));
     71            first = FALSE;
     72          }
     73        }
    6774      }
    6875    }
     
    7986      struct
    8087      {
    81         ULONG serial;
    82         CHAR volumelength;
    83         CHAR volumelabel[CCHMAXPATH];
     88        ULONG serial;
     89        CHAR volumelength;
     90        CHAR volumelabel[CCHMAXPATH];
    8491      }
    8592      volser;
     
    96103      WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "");
    97104      WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
    98                         MPFROM2SHORT(SMA_SLIDERARMPOSITION,
    99                                      SMA_INCREMENTVALUE), MPFROMSHORT(0));
     105                        MPFROM2SHORT(SMA_SLIDERARMPOSITION,
     106                                     SMA_INCREMENTVALUE), MPFROMSHORT(0));
    100107      removable = CheckDrive(toupper(*curdir), FileSystem, &type);
    101108      if (removable != -1) {
    102         if (type & DRIVE_ZIPSTREAM)
    103           WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Zipstream drive");
    104         else if (type & DRIVE_REMOTE)
    105           WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Remote drive");
    106         else if (type & DRIVE_VIRTUAL)
    107             WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Virtual drive");
    108         else if (type & DRIVE_RAMDISK)
    109           WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Ramdisk");
    110         else {
    111           sprintf(s, "Local drive%s", (removable) ? " (removable)" : "");
    112           WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, s);
    113         }
    114         sprintf(s, "IFS:  %s", FileSystem);
    115         WinSetDlgItemText(hwnd, DIRSIZE_IFS, s);
    116         memset(&volser, 0, sizeof(volser));
    117         DosError(FERR_DISABLEHARDERR);
    118         if (!DosQueryFSInfo(toupper(*curdir) - '@', FSIL_VOLSER,
    119                             &volser, (ULONG) sizeof(volser))) {
    120           sprintf(s, "Label:  %s", volser.volumelabel);
    121           WinSetDlgItemText(hwnd, DIRSIZE_LABEL, s);
    122         }
    123         if (!DosQueryFSInfo(toupper(*curdir) - '@',
    124                             FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
    125           percentfree = fsa.cUnit ? (USHORT)((fsa.cUnitAvail * 100) / fsa.cUnit) : 0;   // 27 May 08 SHL
    126           if (!percentfree && fsa.cUnitAvail)
    127             percentfree = 1;
    128           percentused = 100 - percentfree;
    129           sprintf(s, "Units free:  %lu", fsa.cUnitAvail);
    130           WinSetDlgItemText(hwnd, DIRSIZE_UNITSFREE, s);
    131           sprintf(s, "Unit size:  %lu x %u = %lu",
    132                   fsa.cSectorUnit,
    133                   fsa.cbSector, fsa.cSectorUnit * fsa.cbSector);
    134           WinSetDlgItemText(hwnd, DIRSIZE_UNITSIZE, s);
    135           sprintf(s, "Units used:  %lu", fsa.cUnit - fsa.cUnitAvail);
    136           WinSetDlgItemText(hwnd, DIRSIZE_UNITSUSED, s);
    137           sprintf(s, "Bytes free:  %.0f",
    138                   (float)fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector));
    139           WinSetDlgItemText(hwnd, DIRSIZE_BYTESFREE, s);
    140           sprintf(s, "Bytes used:  %.0f",
    141                   (float)(fsa.cUnit - fsa.cUnitAvail) *
    142                   (fsa.cSectorUnit * fsa.cbSector));
    143           WinSetDlgItemText(hwnd, DIRSIZE_BYTESUSED, s);
    144           sprintf(s, "Percent used:  %u%%", percentused);
    145           WinSetDlgItemText(hwnd, DIRSIZE_PERCENT, s);
    146           WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
    147                             MPFROM2SHORT(SMA_SLIDERARMPOSITION,
    148                                         SMA_INCREMENTVALUE),
    149                             MPFROMSHORT(percentused));
    150           WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), TRUE);
    151         }
     109        if (type & DRIVE_ZIPSTREAM)
     110          WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Zipstream drive");
     111        else if (type & DRIVE_REMOTE)
     112          WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Remote drive");
     113        else if (type & DRIVE_VIRTUAL)
     114            WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Virtual drive");
     115        else if (type & DRIVE_RAMDISK)
     116          WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Ramdisk");
     117        else {
     118          sprintf(s, "Local drive%s", (removable) ? " (removable)" : "");
     119          WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, s);
     120        }
     121        sprintf(s, "IFS:  %s", FileSystem);
     122        WinSetDlgItemText(hwnd, DIRSIZE_IFS, s);
     123        memset(&volser, 0, sizeof(volser));
     124        DosError(FERR_DISABLEHARDERR);
     125        if (!DosQueryFSInfo(toupper(*curdir) - '@', FSIL_VOLSER,
     126                            &volser, (ULONG) sizeof(volser))) {
     127          sprintf(s, "Label:  %s", volser.volumelabel);
     128          WinSetDlgItemText(hwnd, DIRSIZE_LABEL, s);
     129        }
     130        if (!DosQueryFSInfo(toupper(*curdir) - '@',
     131                            FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
     132          percentfree = fsa.cUnit ? (USHORT)((fsa.cUnitAvail * 100) / fsa.cUnit) : 0;   // 27 May 08 SHL
     133          if (!percentfree && fsa.cUnitAvail)
     134            percentfree = 1;
     135          percentused = 100 - percentfree;
     136          sprintf(s, "Units free:  %lu", fsa.cUnitAvail);
     137          WinSetDlgItemText(hwnd, DIRSIZE_UNITSFREE, s);
     138          sprintf(s, "Unit size:  %lu x %u = %lu",
     139                  fsa.cSectorUnit,
     140                  fsa.cbSector, fsa.cSectorUnit * fsa.cbSector);
     141          WinSetDlgItemText(hwnd, DIRSIZE_UNITSIZE, s);
     142          sprintf(s, "Units used:  %lu", fsa.cUnit - fsa.cUnitAvail);
     143          WinSetDlgItemText(hwnd, DIRSIZE_UNITSUSED, s);
     144          sprintf(s, "Bytes free:  %.0f",
     145                  (float)fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector));
     146          WinSetDlgItemText(hwnd, DIRSIZE_BYTESFREE, s);
     147          sprintf(s, "Bytes used:  %.0f",
     148                  (float)(fsa.cUnit - fsa.cUnitAvail) *
     149                  (fsa.cSectorUnit * fsa.cbSector));
     150          WinSetDlgItemText(hwnd, DIRSIZE_BYTESUSED, s);
     151          sprintf(s, "Percent used:  %u%%", percentused);
     152          WinSetDlgItemText(hwnd, DIRSIZE_PERCENT, s);
     153          WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
     154                            MPFROM2SHORT(SMA_SLIDERARMPOSITION,
     155                                        SMA_INCREMENTVALUE),
     156                            MPFROMSHORT(percentused));
     157          WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), TRUE);
     158        }
    152159      }
    153160      else {
    154         WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Drive not ready.");
    155         WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), FALSE);
     161        WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Drive not ready.");
     162        WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), FALSE);
    156163      }
    157164    }
     
    163170      switch (SHORT2FROMMP(mp1)) {
    164171      case LN_ENTER:
    165         WinPostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
    166         break;
     172        WinPostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
     173        break;
    167174      case LN_SELECT:
    168         {
    169           SHORT x;
    170 
    171           x = (SHORT) WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
    172                                         LM_QUERYSELECTION,
    173                                         MPFROMSHORT(LIT_FIRST), MPVOID);
    174           if (x >= 0) {
    175             WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
    176                               LM_QUERYITEMTEXT,
    177                               MPFROM2SHORT(x, sizeof(curdir)),
    178                               MPFROMP(curdir));
    179             WinPostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
    180           }
    181         }
    182         break;
     175        {
     176          SHORT x;
     177
     178          x = (SHORT) WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
     179                                        LM_QUERYSELECTION,
     180                                        MPFROMSHORT(LIT_FIRST), MPVOID);
     181          if (x >= 0) {
     182            WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
     183                              LM_QUERYITEMTEXT,
     184                              MPFROM2SHORT(x, sizeof(curdir)),
     185                              MPFROMP(curdir));
     186            WinPostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
     187          }
     188        }
     189        break;
    183190      }
    184191      break;
     
    194201    case DID_OK:
    195202      if (*curdir) {
    196         WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_HIDE);
    197         WinDlgBox(HWND_DESKTOP, hwnd,
    198                   DirSizeProc, FM3ModHandle, DSZ_FRAME, curdir);
    199         WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOW);
     203        WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_HIDE);
     204        WinDlgBox(HWND_DESKTOP, hwnd,
     205                  DirSizeProc, FM3ModHandle, DSZ_FRAME, curdir);
     206        WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOW);
    200207      }
    201208      else
    202         DosBeep(50, 100);
     209        DosBeep(50, 100);
    203210      break;
    204211    }
    205212    return 0;
    206   }                                     // switch
     213  } // switch
    207214  return WinDefDlgProc(hwnd, msg, mp1, mp2);
    208215}
    209 
    210 #ifdef NEVER                            // 05 Jan 08 SHL fixme to be gone?
    211 
    212 VOID APIENTRY deinit(ULONG why)
    213 {
    214   if (fmprof)
    215     PrfCloseProfile(fmprof);
    216   fmprof = (HINI) 0;
    217 
    218   flushall();
    219 
    220   DosExitList(EXLST_REMOVE, deinit);
    221 }
    222 
    223 #endif
    224216
    225217int main(int argc, char *argv[])
     
    227219  HAB hab;
    228220  HMQ hmq;
    229   static CHAR fullname[CCHMAXPATH];
    230   INT x;
     221  CHAR fullname[CCHMAXPATH] = { 0 };    // 14 Dec 08 SHL was static
     222  UINT x;
    231223  ULONG rcl;
     224  APIRET regRet;
     225  EXCEPTIONREGISTRATIONRECORD regRec = { NULL, NULL };
    232226
    233227  DosError(FERR_DISABLEHARDERR);
    234   *fullname = 0;
     228
     229  regRec.ExceptionHandler = HandleException;
     230  regRet = DosSetExceptionHandler(&regRec);
     231  if (regRet != NO_ERROR) {
     232    DbgMsg(pszSrcFile, __LINE__,
     233           "DosSetExceptionHandler failed with error %u", regRet);
     234  }
     235
    235236  for (x = 1; x < argc; x++) {
    236237    if (!strchr("/;,`\'", *argv[x]) &&
    237         !*fullname && (IsRoot(argv[x]) || IsFile(argv[x]) == 0)) {
     238        !*fullname && (IsRoot(argv[x]) || IsFile(argv[x]) == 0)) {
    238239      if (IsRoot(argv[x]))
    239         strcpy(fullname, argv[x]);
     240        strcpy(fullname, argv[x]);
    240241      else if (DosQueryPathInfo(argv[x],
    241                                 FIL_QUERYFULLNAME,
    242                                 fullname, sizeof(fullname)))
    243         *fullname = 0;
     242                                FIL_QUERYFULLNAME,
     243                                fullname, sizeof(fullname)))
     244        *fullname = 0;                  // Forget name
    244245    }
    245246  }
    246 
    247 # ifdef NEVER
    248   DosExitList(EXLST_ADD, deinit);
    249 # endif
    250247
    251248  hab = WinInitialize(0);
     
    254251    if (hmq) {
    255252      if (InitFM3DLL(hab, argc, argv)) {
    256         if (!*fullname)
    257           rcl = WinDlgBox(HWND_DESKTOP,
    258                           HWND_DESKTOP, DirMainProc, 0, DIRSIZE_FRAME, NULL);
    259         else
    260           rcl = WinDlgBox(HWND_DESKTOP,
    261                           HWND_DESKTOP,
    262                           DirSizeProc, FM3ModHandle, DSZ_FRAME, fullname);
    263         if (rcl == DID_ERROR)
    264           rcl = WinGetLastError(hab);
     253        if (!*fullname)
     254          rcl = WinDlgBox(HWND_DESKTOP,
     255                          HWND_DESKTOP, DirMainProc, 0, DIRSIZE_FRAME, NULL);
     256        else
     257          rcl = WinDlgBox(HWND_DESKTOP,
     258                          HWND_DESKTOP,
     259                          DirSizeProc, FM3ModHandle, DSZ_FRAME, fullname);
     260        if (rcl == DID_ERROR)
     261          rcl = WinGetLastError(hab);
    265262      }
    266263      WinDestroyMsgQueue(hmq);
     
    270267  return 0;
    271268
    272 }                                       // main
     269} // main
Note: See TracChangeset for help on using the changeset viewer.