Changeset 1444 for trunk/dll/mainwnd.c


Ignore:
Timestamp:
Jul 23, 2009, 1:24:23 AM (16 years ago)
Author:
Gregg Young
Message:

Rework of drivebar to rescan all drives and refresh media buttons and menu items grey out inappropriate menu items. Streamline Tree scan code and use semaphores to serialize access. Add NOEASUPPORT and LOCALHD driveflag; .LONGNAME usage fixes; (Tickets 377-386)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dll/mainwnd.c

    r1442 r1444  
    9292                listings in tree
    9393  13 Jul 09 GKY Fixed under allocation of memory in the paint code for the drivebar bitmap buttons
     94  22 Jul 09 GKY Drivebar enhancements add refresh removable, rescan all drives, drive button
     95                loads drive root directory in directory container or expands drive tree
     96                and rescans drive in tree container depending on container focus, greyed out
     97                inappropriate menu context choices
     98  22 Jul 09 GKY Code changes to use semaphores to serialize drive scanning
    9499
    95100***********************************************************************/
     
    171176#include "wrappers.h"                   // xfree
    172177#include "fortify.h"
    173 #include "filldir.h"                    // StubbyScanCount
    174178#include "excputil.h"                   // xbeginthread
    175179
     
    256260      HWND hwndB = (HWND) mp1;
    257261      USHORT id;
     262      CHAR s[90]= {0};
    258263
    259264      id = WinQueryWindowUShort(hwndB, QWS_ID);
    260       *dv = 0;
    261       *dv = id - IDM_DRIVEA + 'A';
    262       strcpy(dv + 1, ":");
    263       d = toupper(*dv);
    264       if (isalpha(d) && d > 'B' &&
    265           !(driveflags[d - 'A'] & (DRIVE_CDROM | DRIVE_INVALID |
    266                                    DRIVE_SLOW)) &&
    267           (!hwndBubble ||
    268            WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
    269           !WinQueryCapture(HWND_DESKTOP)) {
    270 
    271         FSALLOCATE fsa;
    272         CHAR s[90], szQty[38];
    273         ULONG ulPctFree;
    274         ULONGLONG ullFreeQty;
    275 
    276         if (!DosQueryFSInfo((d - 'A') + 1,
    277                             FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
    278           ullFreeQty = (ULONGLONG) fsa.cUnitAvail *
    279             (fsa.cSectorUnit * fsa.cbSector);
    280           ulPctFree = (fsa.cUnit && fsa.cUnitAvail) ?
    281             (fsa.cUnitAvail * 100) / fsa.cUnit : 0;
    282           CommaFmtULL(szQty, sizeof(szQty), ullFreeQty, ' ');
    283           sprintf(s, "%s %s (%lu%%) %s", dv, szQty, ulPctFree, GetPString(IDS_FREETEXT));
    284         }
    285         if ((!hwndBubble ||
    286              WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
    287             !WinQueryCapture(HWND_DESKTOP))
    288           WinSendMsg(hwndB, UM_SETUP6, MPFROMP(s), MPVOID);
    289       }
     265      switch (id) {
     266      case IDM_RESCAN:
     267        strcpy(s, GetPString(IDS_RESCANALLDRIVESTEXT));
     268        break;
     269
     270      case IDM_REFRESHREMOVABLES:
     271        strcpy(s, GetPString(IDS_REFRESHREMOVABLESTEXT));
     272        break;
     273
     274      default:
     275        *dv = 0;
     276        *dv = id - IDM_DRIVEA + 'A';
     277        strcpy(dv + 1, ":");
     278        d = toupper(*dv);
     279        if (isalpha(d) && d > 'B' &&
     280            !(driveflags[d - 'A'] & (DRIVE_CDROM | DRIVE_INVALID |
     281                                     DRIVE_SLOW)) &&
     282            (!hwndBubble ||
     283             WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
     284            !WinQueryCapture(HWND_DESKTOP)) {
     285 
     286          FSALLOCATE fsa;
     287          CHAR szQty[38];
     288          ULONG ulPctFree;
     289          ULONGLONG ullFreeQty;
     290 
     291          if (!DosQueryFSInfo((d - 'A') + 1,
     292                              FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
     293            ullFreeQty = (ULONGLONG) fsa.cUnitAvail *
     294              (fsa.cSectorUnit * fsa.cbSector);
     295            ulPctFree = (fsa.cUnit && fsa.cUnitAvail) ?
     296              (fsa.cUnitAvail * 100) / fsa.cUnit : 0;
     297            CommaFmtULL(szQty, sizeof(szQty), ullFreeQty, ' ');
     298            sprintf(s, "%s %s (%lu%%) %s", dv, szQty, ulPctFree, GetPString(IDS_FREETEXT));
     299          }
     300        }
     301      }
     302      if ((!hwndBubble ||
     303           WinQueryWindowULong(hwndBubble, QWL_USER) != hwndB) &&
     304          !WinQueryCapture(HWND_DESKTOP))
     305        WinSendMsg(hwndB, UM_SETUP6, MPFROMP(s), MPVOID);
    290306    }
    291307    return 0;
     
    323339      RestoreDirCnrState(hwndMain, (char *)mp1, FALSE);
    324340      WinEnableWindow(WinQueryWindow(hwndMain, QW_PARENT), TRUE);
    325       fNoTileUpdate = FALSE;
    326       //xfree((char *)mp1, pszSrcFile, __LINE__);
    327 //       if (fAutoTile)
    328 //         TileChildren(hwndMain, TRUE);
     341      fNoTileUpdate = FALSE; ;
    329342      break;
    330343    default:
    331344      Runtime_Error(pszSrcFile, __LINE__, "%u unexpected", mp2);
     345    }
     346    if (fInitialDriveScan) {
     347      DosPostEventSem(hevInitialCnrScanComplete);
     348      DosCloseEventSem(hevInitialCnrScanComplete);
     349      fInitialDriveScan = FALSE;
    332350    }
    333351    return 0;
     
    18351853
    18361854  case WM_COMMAND:
    1837     {
    1838       CHAR dv[4];
    1839 
    1840       *dv = SHORT1FROMMP(mp1) - IDM_DRIVEA + 'A';
    1841       strcpy(dv + 1, ":\\");
    1842       if (isalpha(*dv)) {
    1843 
    1844         HWND hwndActive;
    1845 
    1846         dv[1] = ':';
    1847         dv[2] = '\\';
    1848         dv[3] = 0;
    1849         hwndActive = TopWindow(hwnd, (HWND) 0);
    1850         if (hwndActive)
    1851           WinSendMsg(WinWindowFromID(hwndActive, FID_CLIENT),
    1852                      UM_DRIVECMD, MPFROMP(dv), MPVOID);
     1855    if (fInitialDriveScan)
     1856      DosWaitEventSem(hevInitialCnrScanComplete, SEM_INDEFINITE_WAIT);
     1857    switch(SHORT1FROMMP(mp1)) {
     1858    case IDM_RESCAN:
     1859      {
     1860        BOOL toggleTree = FALSE;
     1861 
     1862        if (!hwndTree) {
     1863          WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
     1864          toggleTree = TRUE;
     1865        }
     1866        WinSendMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_RESCAN, 0), MPVOID);
     1867        if (toggleTree)
     1868          WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
     1869      }
     1870      break;
     1871    case IDM_REFRESHREMOVABLES:
     1872      {
     1873        BOOL toggleTree = FALSE;
     1874 
     1875        if (!hwndTree) {
     1876          WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
     1877          toggleTree = TRUE;
     1878        }
     1879        WinSendMsg(hwndTree, WM_COMMAND, MPFROM2SHORT(IDM_REFRESHREMOVABLES, 0), MPVOID);
     1880        if (toggleTree)
     1881          WinSendMsg(hwndMain, WM_COMMAND, MPFROM2SHORT(IDM_VTREE, 0), MPVOID);
     1882      }
     1883      break;
     1884    default:
     1885      {
     1886        CHAR dv[4];
     1887 
     1888        *dv = SHORT1FROMMP(mp1) - IDM_DRIVEA + 'A';
     1889        strcpy(dv + 1, ":\\");
     1890        if (isalpha(*dv)) {
     1891 
     1892          HWND hwndActive;
     1893 
     1894          dv[1] = ':';
     1895          dv[2] = '\\';
     1896          dv[3] = 0;
     1897          hwndActive = TopWindow(hwnd, (HWND) 0);
     1898          if (hwndActive)
     1899            WinSendMsg(WinWindowFromID(hwndActive, FID_CLIENT),
     1900                       UM_DRIVECMD, MPFROMP(dv), MPVOID);
     1901        }
    18531902      }
    18541903    }
     
    18771926  switch (msg) {
    18781927  case WM_MOUSEMOVE:
    1879     if (fDrivebarHelp &&
    1880         (!hwndBubble ||
     1928    if (fDrivebarHelp && (!hwndBubble ||
    18811929         WinQueryWindowULong(hwndBubble, QWL_USER) != hwnd) &&
    18821930        !WinQueryCapture(HWND_DESKTOP)) {
    18831931      id = WinQueryWindowUShort(hwnd, QWS_ID);
    18841932      if (helpid != id) {
    1885         helpid = id;
     1933        helpid = id;
    18861934        PostMsg(MainObjectHwnd, UM_SETUP6, MPFROMLONG((ULONG) hwnd), MPVOID);
    18871935      }
     
    19051953
    19061954      id = WinQueryWindowUShort(hwnd, QWS_ID);
     1955      if (id == IDM_REFRESHREMOVABLES || id == IDM_RESCAN)
     1956        break;
    19071957      *szDrv = 0;
    19081958      x = id - IDM_DRIVEA;
     
    19221972                      RAMDISK_ICON :
    19231973                     (driveflags[x] & DRIVE_ZIPSTREAM) ?
    1924                       ZIPSTREAM_ICON : DRIVE_ICON;
     1974                      ZIPSTREAM_ICON :
     1975                     (driveflags[x] & DRIVE_LOCALHD) ?
     1976                      DRIVE_ICON : DONNO_ICON;
    19251977        }
    19261978        else
     
    20002052      hwndMenu = WinLoadMenu(HWND_DESKTOP, FM3ModHandle, MAIN_DRIVES);
    20012053      if (hwndMenu) {
    2002         BOOL rdy;
     2054        BOOL rdy, local;
    20032055        CHAR chDrv = *szDrv;
    20042056        UINT iDrv;
     
    20062058        strcat(szDrv, PCSZ_BACKSLASH);
    20072059        MakeValidDir(szDrv);
    2008         // Disable menus if MakeValidDir changes drive letter fixme this section doesn't do anything see treecnt.c
     2060        // Disable menus if MakeValidDir changes drive letter fixme this section doesn't do anything see treecnt.c
     2061        local = ~driveflags[iDrv] & DRIVE_REMOTE && ~driveflags[iDrv] & DRIVE_VIRTUAL &&
     2062                ~driveflags[iDrv] & DRIVE_RAMDISK;
    20092063        rdy = toupper(*szDrv) == toupper(chDrv);
    20102064        iDrv = toupper(*szDrv) - 'A';
    20112065        if (!rdy || ~driveflags[iDrv] & DRIVE_REMOTE)
    2012           WinEnableMenuItem(hwndMenu, IDM_DETACH, FALSE);
    2013 
    2014         if (!rdy || driveflags[iDrv] & DRIVE_NOTWRITEABLE) {
    2015           WinEnableMenuItem(hwndMenu, IDM_MKDIR, FALSE);
     2066          WinEnableMenuItem(hwndMenu, IDM_DETACH, FALSE);
     2067
     2068        if (!rdy || driveflags[iDrv] & DRIVE_NOTWRITEABLE)
     2069          WinEnableMenuItem(hwndMenu, IDM_MKDIR, FALSE);
     2070
     2071        if (!rdy || driveflags[iDrv] & DRIVE_NOTWRITEABLE || !local) {
    20162072          WinEnableMenuItem(hwndMenu, IDM_FORMAT, FALSE);
    20172073          WinEnableMenuItem(hwndMenu, IDM_OPTIMIZE, FALSE);
     
    20272083          WinEnableMenuItem(hwndMenu, IDM_ARCHIVE, FALSE);
    20282084          WinEnableMenuItem(hwndMenu, IDM_SIZES, FALSE);
    2029           WinEnableMenuItem(hwndMenu, IDM_SHOWALLFILES, FALSE);
     2085          WinEnableMenuItem(hwndMenu, IDM_SHOWALLFILES, FALSE);
     2086
     2087        if (!rdy || !local)
    20302088          WinEnableMenuItem(hwndMenu, IDM_CHKDSK, FALSE);
    20312089        }
     
    23012359        if (!hwndB)
    23022360          Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
    2303                     PCSZ_WINCREATEWINDOW);
     2361                    PCSZ_WINCREATEWINDOW);
    23042362        else {
    23052363          WinSetWindowPos(hwndB, HWND_BOTTOM, 0, 0, 0, 0, SWP_ZORDER);
     
    23072365      }
    23082366    }                                   // for
     2367    hwndB = WinCreateWindow(hwndT,
     2368                            WC_DRIVEBUTTONS,
     2369                            "#7001",
     2370                            BS_NOPOINTERFOCUS | BS_BITMAP | BS_PUSHBUTTON,
     2371                            0,
     2372                            0,
     2373                            DRIVE_BUTTON_WIDTH,
     2374                            DRIVE_BUTTON_HEIGHT,
     2375                            hwndT, HWND_TOP, IDM_REFRESHREMOVABLES, NULL, NULL);
     2376  if (!hwndB)
     2377    Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
     2378              PCSZ_WINCREATEWINDOW);
     2379  hwndB = WinCreateWindow(hwndT,
     2380                          WC_DRIVEBUTTONS,
     2381                          "#7000",
     2382                          BS_NOPOINTERFOCUS | BS_BITMAP | BS_PUSHBUTTON,
     2383                          0,
     2384                          0,
     2385                          DRIVE_BUTTON_WIDTH,
     2386                          DRIVE_BUTTON_HEIGHT,
     2387                          hwndT, HWND_TOP, IDM_RESCAN, NULL, NULL);
     2388  if (!hwndB)
     2389    Win_Error(hwndT, HWND_DESKTOP, pszSrcFile, __LINE__,
     2390              PCSZ_WINCREATEWINDOW);
    23092391  }                                     // if drivebar
    23102392  PostMsg(WinQueryWindow(hwndT, QW_PARENT),
     
    33283410                  }
    33293411                }
    3330                 //if (!PostMsg(hwndCnr, UM_SETUP2, NULL, NULL)) //These were being called twice
    3331                 //  WinSendMsg(hwndCnr, UM_SETUP2, NULL, NULL); //causing dup dir names in tree
     3412                if (!PostMsg(hwndCnr, UM_SETUP2, NULL, NULL))
     3413                  WinSendMsg(hwndCnr, UM_SETUP2, NULL, NULL);
    33323414              }
    33333415            }
     
    57265808      if (!add_setup(pszStatename))
    57275809        save_setups();
    5728     } else {
     5810    }
     5811    else {
    57295812      load_tools(NULL);
    57305813      PostMsg(hwndToolback, UM_SETUP2, MPVOID, MPVOID);
     5814      if (fInitialDriveScan) {
     5815        DosPostEventSem(hevInitialCnrScanComplete);
     5816        DosCloseEventSem(hevInitialCnrScanComplete);
     5817      }
    57315818    }
    57325819    PostMsg(MainObjectHwnd, UM_SETUP4, mp1, mp2);
Note: See TracChangeset for help on using the changeset viewer.