Changeset 1684 for trunk/src


Ignore:
Timestamp:
Nov 10, 1999, 1:19:42 PM (26 years ago)
Author:
phaller
Message:

Fix: erroneous filter data for GetOpenFileName/GetSaveFileName now tolerated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/comdlg32/comdlg32.cpp

    r1677 r1684  
    1 /* $Id: comdlg32.cpp,v 1.18 1999-11-09 22:38:57 phaller Exp $ */
     1/* $Id: comdlg32.cpp,v 1.19 1999-11-10 12:18:28 phaller Exp $ */
    22
    33/*
     
    6464  a->hwndOwner = Win32ToOS2Handle(a->hwndOwner);
    6565#endif
     66
     67
     68/*****************************************************************************
     69 * Name      : iFileDlg_ScanFilterToken
     70 * Purpose   : scan for valid / invalid filter tokens and
     71 *             advance array pointer
     72 * Parameters:
     73 * Variables :
     74 * Result    :
     75 * Remark    :
     76 * Status    :
     77 *
     78 * Author    :
     79 *****************************************************************************/
     80
     81// scan filter tokens for validity
     82static BOOL iFileDlg_ScanFilterToken( LPSTR *plpstrPair )
     83{
     84  LPSTR lpstrTemp;
     85  LPSTR lpstrNext;
     86  BOOL  fOK = TRUE;
     87
     88  lpstrTemp = *plpstrPair;
     89  if (lpstrTemp[0] != 0)
     90  {
     91    // get filter description
     92    lpstrTemp = lpstrTemp + strlen(lpstrTemp);
     93    lpstrNext = lpstrTemp + 1;
     94    if (lpstrNext[0] == 0)
     95      fOK = FALSE;
     96    else
     97    {
     98      // get filter mask
     99      lpstrTemp = lpstrNext;
     100      lpstrTemp = lpstrTemp + strlen(lpstrTemp);
     101      lpstrTemp++;
     102    }
     103
     104    if (fOK)
     105      *plpstrPair = lpstrTemp;
     106  }
     107  return fOK;
     108}
     109
     110
     111/*****************************************************************************
     112 * Name      : iFileDlg_CleanFilterArray
     113 * Purpose   : remove erroneous array entries at the end to prevent
     114 *             Open32 complain about them but open the file dialog
     115 *             instead.
     116 * Parameters:
     117 * Variables :
     118 * Result    :
     119 * Remark    :
     120 * Status    :
     121 *
     122 * Author    :
     123 *****************************************************************************/
     124
     125static DWORD iFileDlg_CleanFilterArray( LPSTR lpstrFilters)
     126{
     127   DWORD  dwCount = 0;
     128   LPSTR  lpstrTemp;
     129
     130   if (lpstrFilters && *lpstrFilters)
     131   {
     132     lpstrTemp = lpstrFilters;
     133     while (lpstrTemp[0] != 0)
     134     {
     135        // if an invalid filter token is found, such as found
     136        // in NT4's Regedit e. g., return number of proper
     137        // filter tokens.
     138        // Here however, as were calling Open32, we need
     139        // to correct the filter array.
     140        if (iFileDlg_ScanFilterToken(&lpstrTemp) == FALSE)
     141        {
     142          //@@@PH two alternative methods:
     143          // - copy array to new, corrected array while scanning tokens
     144          // - just overwrite bogus characters at the end of the array
     145          *lpstrTemp++ = 0; // try string termination
     146          *lpstrTemp   = 0;
     147          return dwCount;
     148        }
     149
     150        dwCount++;
     151     }
     152   }
     153   return dwCount;
     154}
     155
     156
    66157/*****************************************************************************
    67158 * Name      :
     
    82173
    83174  if(lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE)) {
    84         return GetFileDialog95A(lpofn, SAVE_DIALOG);
     175   return GetFileDialog95A(lpofn, SAVE_DIALOG);
    85176  }
    86177
    87178  COMDLG32_CHECKHOOK(lpofn, OFN_ENABLEHOOK, WNDPROC)
    88179
    89   //@@@PH 1999/11/09 needs to be fixed
     180  //Note: fix IBM's proper error checking for NT's lazy check
     181  if (lpofn->lpstrFilter != NULL)
     182    iFileDlg_CleanFilterArray((LPSTR)lpofn->lpstrFilter);
     183
    90184  return(O32_GetSaveFileName(lpofn));
    91185}
     186
    92187
    93188/*****************************************************************************
     
    114209
    115210  if(lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE)) {
    116         return GetFileDialog95W(lpofn, SAVE_DIALOG);
     211   return GetFileDialog95W(lpofn, SAVE_DIALOG);
    117212  }
    118213
     
    237332  COMDLG32_CHECKHOOK(lpofn, OFN_ENABLEHOOK, WNDPROC)
    238333
    239   //@@@PH 1999/11/09 needs to be fixed
     334  //Note: fix IBM's proper error checking for NT's lazy check
     335  if (lpofn->lpstrFilter != NULL)
     336    iFileDlg_CleanFilterArray((LPSTR)lpofn->lpstrFilter);
     337
    240338  return(O32_GetOpenFileName(lpofn));
    241339}
     
    264362
    265363  if(lpofn->Flags & (OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE)) {
    266         return GetFileDialog95W(lpofn, OPEN_DIALOG);
     364   return GetFileDialog95W(lpofn, OPEN_DIALOG);
    267365  }
    268366
Note: See TracChangeset for help on using the changeset viewer.