home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / CMD / SVGAINST / SVGAINST.C < prev    next >
C/C++ Source or Header  |  1995-04-14  |  93KB  |  2,716 lines

  1. /*DDK*************************************************************************/
  2. /*                                                                           */
  3. /* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
  4. /*                                                                           */
  5. /*    The following IBM OS/2 WARP source code is provided to you solely for  */
  6. /*    the purpose of assisting you in your development of OS/2 WARP device   */
  7. /*    drivers. You may use this code in accordance with the IBM License      */
  8. /*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
  9. /*    Copyright statement may not be removed.                                */
  10. /*                                                                           */
  11. /*****************************************************************************/
  12. /*SCCSID = %%s %%s %%s */
  13.  
  14. /****************************************************************************/
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*                                                                          */
  18. /****************************************************************************/
  19.  
  20. /*********************************************************************/
  21. /*                                                                   */
  22. /*  SOURCE FILE NAME: svgainst.c                                     */
  23. /*                                                                   */
  24. /*  DESCRIPTIVE NAME: Main source file for SVGA action routine DLL   */
  25. /*                                                                   */
  26. /*  FUNCTION: This contains the entry points for SVGAINST.DLL        */
  27. /*                                                                   */
  28. /*********************************************************************/
  29. #define  INCL_DOS
  30. #define  INCL_DOSERRORS
  31. #define  INCL_DOSPROCESS
  32. #define  INCL_DOSRESOURCES
  33. #define  INCL_WIN
  34.  
  35. #include <math.h>
  36. #include <stdio.h>
  37. #include <string.h>
  38. #include <memory.h>
  39. #include <malloc.h>
  40. #include <stdlib.h>
  41. #include <stddef.h>
  42. #include <ctype.h>
  43. #include <time.h>
  44. #include <process.h>
  45. #include "dispmain.h"
  46. #include "dispact.h"
  47. #include "svga.h"
  48.  
  49. /********************************************
  50.  *private function declarations for this module
  51.  *********************************************/
  52. VOID    APIENTRY svga_ParseAdapter(PDSPINSTL_CHAIN pInstalChain,
  53.                                    PADAPTERENTRY pAdpentry);
  54. VOID    APIENTRY svga_ParseMonitor(PDSPINSTL_CHAIN pInstalChain,
  55.                                    PVIDEOENTRY pVidentry);
  56. ULONG   APIENTRY svga_WriteResolution(PSZ pszConfig,PVIDEOENTRY pVidentry);
  57. ULONG   APIENTRY svga_WriteNewResolution(PVIDEOENTRY pVidEntry);
  58. ULONG   APIENTRY svga_GetCurrentResolution(VOID);
  59. INT     APIENTRY svga_WriteResolIni(PINIPARMS);
  60. INT     APIENTRY svga_WriteInterlIni(PINIPARMS);
  61. INT     APIENTRY svga_WriteRefrIni(PINIPARMS);
  62. ULONG   APIENTRY svga_UpWriteIni(PSZ pszApplication,PSZ pszKey,PSZ pszString);
  63. MRESULT EXPENTRY WaitSvgaDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
  64. //@TM  feature
  65. MRESULT EXPENTRY SelectSvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
  66. MRESULT EXPENTRY SvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2);
  67. APIRET  CreateSvgaTmpBat(CHAR *achBuffer );
  68. VOID    InitHelp( HWND *phwndHelpInstance );
  69. //@TM
  70. BOOL    OpenResolutionsFile(PRESOLUTIONS pResolutions,PULONG pulCount);
  71. APIRET  GetResolutionsData(PRESOLUTIONS pResolutions,
  72.                            PRESOLUTIONS pResolutionsToDisplay,
  73.                            HWND hwnd,
  74.                            PDSPINSTL_CHAIN  pInstalChain,
  75.                            BOOL fUseDefault,
  76.                            PULONG pulCount,
  77.                            PFN pfnGetNext,
  78.                            BOOL *fShowResolutionsToUser);
  79. BOOL   ReadResolutionsFile(PRESOLUTIONS pResolutions,HFILE hf,PULONG pulCount);
  80. VOID   RunSvga(PVOID);
  81. PSZ    strip_white(PSZ pszString);
  82. BOOL   ValidateResolutions(PRESOLUTIONS pResolutions,
  83.                            PRESOLUTIONS pResolutionsToDisplay,
  84.                            PDSPINSTL_CHAIN   pDspInstlHeadChain,
  85.                            BOOL fUseDefault,
  86.                            PULONG pulCount,
  87.                            ULONG ulCount,
  88.                            PFN pfnGetNext);
  89. BOOL   CompareResolutions(PSZ pszResolution,PRESOLUTIONS pSupportedResolutions,
  90.                             ULONG ulCount);
  91. APIRET APIENTRY GetDllHandle( PHMODULE phmodResource);
  92. VOID   APIENTRY WaitThread(PVOID);
  93. VOID   StringToResolution(PSZ pszString,PRESOLUTIONDATA pResolutionData);
  94. VOID   APIENTRY BuildSvgaNodes(PDSPINSTL_CHAIN pDspinstlChain,
  95.                                PRESOLUTIONS pSelectedResolutions,
  96.                                ULONG ulCount,
  97.                                LONG lDesignatedResolution);
  98. PSZ             GetSelectedResolution(PRESOLUTIONS pResolution,ULONG ulCount);
  99. PDSPINSTL_CHAIN GetLastElement(PDSPINSTL_CHAIN pDspInstlChain);
  100. USHORT APIENTRY16 Dos16GetPrty(USHORT usScope,PUSHORT pusPriority,USHORT pid);
  101. VOID   SvgaReportError(ULONG rc,PSZ pszMsg,HWND hwndOwner);
  102. VOID   svgaLog(PSZ pszMsg);
  103. USHORT SvgaMessageBox(ULONG rc,PSZ pszMsg,HWND hwndOwner);
  104. PSZ    GetDesignatedResolution(PDSPINSTL_CHAIN pChain,ULONG ulCount,
  105.                                LONG lDesignatedResolution);
  106.  
  107.                                                    /* Amol; D58319;12/09/92*/
  108. BOOL   CheckSVGAMem (PRESOLUTIONS, ULONG);
  109. BOOL   IsResolutionOver1Mg(PSZ pszResolution,PRESOLUTIONDATA  pResolution);
  110. BOOL   SelectResolutionForUser( PDSPINSTL_CHAIN pInstalChain,
  111.                               PRESOLUTIONS pResolutionsToDisplay,
  112.                               PULONG pulCount );
  113.  
  114. /*****************************************
  115.  *private data declarations
  116.  *****************************************/
  117. PSZ  pszConfig        = "MONITOR.CFG";       //name of  monitor file to pass
  118. PSZ  pszAdapter       = "ADAPTER.CFG";       //name of  adapter file to pass
  119. PSZ  pszDefMonKey;                           //default  monitor key
  120. PSZ  pszSelMonKey;                           //selected monitor key
  121. PSZ  pszDefAdpKey;
  122. PSZ  pszSelAdpKey;
  123. PSZ  pszResolutionString = NULL;                                           //CID
  124. RESOLUTIONS   ResolutionsArray[MAX_RESOLUTIONS];
  125. RESOLUTIONS   ResolutionsToDisplay[MAX_RESOLUTIONS];
  126. HMODULE hmodResource;
  127. BOOL    f1024K;                        /* Amol; Defect #58319; 12/09/92    */
  128. //@TMCHAR *szErrorMsg []=
  129. //@TM{
  130. //@TM   "A error has occurred reading the svgadata.pmi file",
  131. //@TM   "Unable to determine hardware configuration",
  132. //@TM   "Unable to resolve module handle",
  133. //@TM   "The current hardware configuration does not support the high resolution mode. \
  134. //@TM If you continue, your video support might be unusable.  Do you want to continue ?"
  135. //@TM};
  136.  
  137. CHAR   szResolution[SIZ_PARMS];
  138. CHAR   szInterLace [SIZ_PARMS];
  139. CHAR   szRefresh   [SIZ_PARMS];
  140. CHAR   szString1   [SIZ_PARMS];
  141. CHAR   szString2   [SIZ_PARMS];
  142. CHAR   szString3   [SIZ_PARMS];
  143.  
  144.  
  145. INIPARMS  IniParms [] =
  146. {
  147.      MONITOR_RES,      szResolution,szString1,svga_WriteResolIni,
  148.      MONITOR_VREFRESH, szRefresh   ,szString2,NULL,
  149.      MONITOR_INTERLACE,szInterLace ,szString3,NULL,
  150. };
  151. PFN  pfnLogFunction = NULL;
  152. TID  tidThread;
  153.  
  154. /****************************************************************\
  155.  *
  156.  *--------------------------------------------------------------
  157.  *
  158.  *  Name:Default_Primary
  159.  *
  160.  *  Purpose:This action routine handles svga specific routines that
  161.  *          need to be called from the display install utility for the
  162.  *          default primary selection.This routine does the following:
  163.  *        a)Gets a pointer to the head of the selected display install
  164.  *                 chain
  165.  *        b)Does the setup for the GetResolutionsData routine and calls it
  166.  *        c)If no error occurred call to have the resolutions displayed to
  167.  *          the user.
  168.  *        d)Call to have the linked list built,based upon the resoluition
  169.  *          the user has selected.
  170.  *
  171.  *
  172.  *  Returns:
  173.  *         Non-Zero -  Error occurred,User Aborted.
  174.  *          0        - Successful Operation,Continue
  175. \****************************************************************/
  176. LONG EXPENTRY Default_Primary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  177. {
  178.  
  179.     PRESOLUTIONS  pResolutions;
  180.     ULONG ulSelections = 0;
  181.     LONG lRetValue;
  182.     PDSPINSTL_CHAIN pHeadofChain;
  183.     BOOL fShowResolutionsToUser  = TRUE;
  184.     LONG lGetDesignated = -1;
  185.  
  186.  
  187.     pfnLogFunction = pInstalData->pfnLogFunction;
  188.  
  189.     /*
  190.      * If resolution string passed in make it global
  191.      */
  192.  
  193.     if( pInstalData->pszResolutionString )
  194.     {
  195.        pszResolutionString = malloc(
  196.                                 strlen( pInstalData->pszResolutionString)
  197.                                   + 1);
  198.        strcpy( pszResolutionString, pInstalData->pszResolutionString );
  199.     }
  200.  
  201.     /*
  202.      *start at the head
  203.      *of the chain
  204.      */
  205.     if((*pInstalData->pfnNextElementRoutine)(&pHeadofChain,
  206.                                              CHAIN_HEAD,
  207.                                              NULL) )
  208.     {
  209.           return(CANCEL_OPERATION);
  210.     }
  211.  
  212.    /*
  213.     *set up to get the supported resolutions
  214.     */
  215.     memset(ResolutionsArray,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  216.     memset(ResolutionsToDisplay,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  217.     /*
  218.      *get the resolutions data,setting the default flag
  219.      *to true.
  220.      */
  221.     if((lRetValue = GetResolutionsData(ResolutionsArray,
  222.                                        ResolutionsToDisplay,
  223.                                        hwnd,pHeadofChain,
  224.                                        TRUE,
  225.                                        &ulSelections,
  226.                                        pInstalData->pfnNextElementRoutine,
  227.                                        &fShowResolutionsToUser) ))
  228.     {
  229.          if (lRetValue != CONTINUE_WITH_ERR)
  230.              return(lRetValue);
  231.     }
  232.     if(fShowResolutionsToUser)
  233.     {
  234.          /*
  235.           *display the list of resolutions
  236.           */
  237.          if( lRetValue =  (*pInstalData->pfnSpecifyResolution)(hwnd,&ResolutionsToDisplay,
  238.                                                     ulSelections,
  239.                                                     FALSE) )
  240.          {
  241.                /*
  242.                 *user aborted
  243.                 */
  244.                return(lRetValue);
  245.          }
  246.     }
  247.     else
  248.     {
  249.           /*
  250.            *this should only be happening on speedway
  251.            *make sure the first one in our list is selected
  252.            */
  253.            lGetDesignated = 0;
  254.     }
  255.  
  256.  
  257.     /*
  258.      *build the key for the
  259.      *first node and set the next node to be the
  260.      *node that was selected
  261.      */
  262.     BuildSvgaNodes(pHeadofChain,
  263.                          ResolutionsToDisplay,
  264.                          ulSelections,
  265.                          lGetDesignated);
  266.  
  267.     return(lRetValue);
  268. }
  269.  
  270. /****************************************************************\
  271.  *
  272.  *--------------------------------------------------------------
  273.  *
  274.  *  Name:Default_Secondary
  275.  *
  276.  *  Purpose:This action routine handles the calling of the specify
  277.  *          adapter and specify monitor routines. The key that is
  278.  *          returned in the adapter structre is saved off so as to
  279.  *          used later while querying the .DSP files.
  280.  *
  281.  *
  282.  *
  283.  *  Usage:
  284.  *
  285.  *  Returns:
  286.  *          Non-Zero -  Error occurred,User Aborted.
  287.  *          0        - Successful Operation,Continue
  288. \****************************************************************/
  289. LONG EXPENTRY Default_Secondary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  290. {
  291.     ADAPTERENTRY adpentry;
  292.     VIDEOENTRY videntry;
  293.     LONG rc;
  294.     PDSPINSTL_CHAIN pDspChain;
  295.  
  296.  
  297.  
  298.     pfnLogFunction = pInstalData->pfnLogFunction;
  299.     /*
  300.      *start at the head
  301.      *of the chain
  302.      */
  303.     pDspChain = pInstalData->pHeadDspInstl_Chain;
  304.  
  305.     if((rc = (*pInstalData->pfnSpecifyVideoMonitor)(hwnd,pszConfig, &videntry)))
  306.     {
  307.         /*
  308.          *user aborted
  309.          */
  310.         return(CANCEL_OPERATION);
  311.     }
  312.     return(rc);
  313. }
  314. /****************************************************************\
  315.  *
  316.  *--------------------------------------------------------------
  317.  *
  318.  *  Name:Selected_Primary
  319.  
  320.  *  Purpose:This action routine handles svga specific routines that
  321.  *          need to be called from the display install utility for the
  322.  *          selected primary selection.This routine does the following:
  323.  *        a)Gets a pointer to the head of the selected display install
  324.  *                 chain
  325.  *        b)Does the setup for the GetResolutionsData routine and calls it
  326.  *        c)If no error occurred call to have the resolutions displayed to
  327.  *          the user.
  328.  *        d)Call to have the linked list built,based upon the resolution
  329.  *          the user has selected.
  330.  *        Note - Kenner
  331.  *        Changed the  usedefaultflag so that it is always true.
  332.  *        this will insure that only resolutions the hardware can support
  333.  *        are displayed to the customer.
  334.  *
  335.  *  Returns:
  336.  *          Non-Zero -  Error occurred,User Aborted.
  337.  *          0        - Successful Operation,Continue
  338. \****************************************************************/
  339. LONG EXPENTRY Selected_Primary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  340. {
  341.  
  342.     PRESOLUTIONS  pResolutions;
  343.     ULONG ulSelections = 0;
  344.     LONG lRetValue;
  345.     PDSPINSTL_CHAIN pHeadofChain;
  346.     BOOL fShowResolutionsToUser  = TRUE;
  347.     LONG lGetDesignated = -1;
  348.  
  349.  
  350.     pfnLogFunction = pInstalData->pfnLogFunction;
  351.  
  352.  
  353.     /*
  354.      * If resolution string passed in make it global
  355.      */
  356.  
  357.     if( pInstalData->pszResolutionString )
  358.     {
  359.        pszResolutionString = malloc(
  360.                                 strlen( pInstalData->pszResolutionString)
  361.                                   + 1);
  362.        strcpy( pszResolutionString, pInstalData->pszResolutionString );
  363.     }
  364.  
  365.     /*
  366.      *start at the head
  367.      *of the chain
  368.      */
  369.     if( (*pInstalData->pfnNextElementRoutine)(&pHeadofChain,
  370.                                               CHAIN_HEAD,
  371.                                               NULL) )
  372.     {
  373.           return(CANCEL_OPERATION);
  374.     }
  375.  
  376.    /*
  377.     *read in the resolutions file
  378.     */
  379.     memset(ResolutionsArray,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  380.     memset(ResolutionsToDisplay,0,sizeof(RESOLUTIONS) * MAX_RESOLUTIONS);
  381.     if((lRetValue = GetResolutionsData(ResolutionsArray,
  382.                                        ResolutionsToDisplay,
  383.                                        hwnd,pHeadofChain,
  384.                                        TRUE,
  385.                                        &ulSelections,
  386.                                        pInstalData->pfnNextElementRoutine,
  387.                                        &fShowResolutionsToUser) ))
  388.     {
  389.          if (lRetValue != CONTINUE_WITH_ERR)
  390.              return(lRetValue);
  391.     }
  392.     if(fShowResolutionsToUser)
  393.     {
  394.           if( lRetValue =  (*pInstalData->pfnSpecifyResolution)(hwnd,&ResolutionsToDisplay,
  395.                                                ulSelections,
  396.                                                FALSE) )
  397.           {
  398.                 return(lRetValue);
  399.  
  400.           }
  401.      }
  402.      else
  403.      {
  404.            /*
  405.             *this should only be happening on speedway
  406.             *make sure the first one in our list is selected
  407.             */
  408.             lGetDesignated = 0;
  409.      }
  410.  
  411.  
  412.  
  413.     /*
  414.      *build the key for the
  415.      *first node and set the next node to be the
  416.      *node that was selected
  417.      */
  418.     BuildSvgaNodes(pHeadofChain,
  419.                          ResolutionsToDisplay,
  420.                          ulSelections,
  421.                          lGetDesignated);
  422.     return(lRetValue);
  423. }
  424. /****************************************************************\
  425.  *
  426.  *--------------------------------------------------------------
  427.  *
  428.  *  Name:BuildSvgaNodes
  429.  *
  430.  *  Purpose:This routine will build the configuration node and the
  431.  *          associated key to look for in the dsp files.The next node
  432.  *          in the link will be set to the one that matches what the
  433.  *          user selected. The next link will be set to the first
  434.  *          node that does not have a resoulution associated with
  435.  *          it.
  436.  *          Updated 8-18-92 -Kenner
  437.  *          Check the first node that does not have a resolution
  438.  *          to see if HI-RESOLUTION was selected,if so reset the
  439.  *          key to pick up the hires fonts.
  440.  *
  441.  *         Head      ->      pszKey  = "C600x400x256"
  442.  *         NextNode  ->      pszKey  = "600x400x256"
  443.  *         NextNode  ->      pszKey  = "FONT_HI" || "FONT_LO"
  444.  *  Returns:
  445.  *        VOID
  446. \****************************************************************/
  447. VOID APIENTRY BuildSvgaNodes(PDSPINSTL_CHAIN pDspinstlChain,
  448.                               PRESOLUTIONS pSelectedResolutions,
  449.                               ULONG ulCount,
  450.                               LONG lGetDesignated)
  451. {
  452.      PSZ pszSelectedResolution;
  453.      PDSPINSTL_CHAIN pTempChain,pLastResolution;
  454.      CHAR    szTemp[MAX_SIZ_KEY];
  455.  
  456.     /*
  457.      *get the selected resolutions
  458.      */
  459.  
  460.      if( lGetDesignated == -1 || pszResolutionString != NULL)
  461.      {
  462.           pszSelectedResolution = GetSelectedResolution(pSelectedResolutions,ulCount);
  463.      }
  464.      else
  465.      {
  466.           /*
  467.            *get the reslution
  468.            *designated
  469.            */
  470.           pszSelectedResolution = GetDesignatedResolution(pDspinstlChain,ulCount,
  471.                                                           lGetDesignated);
  472.      }
  473.  
  474.      /*
  475.       *get the first node after the head of the
  476.       *list that does not have a associated resolution
  477.       */
  478.      pLastResolution = GetLastElement(pDspinstlChain);
  479.  
  480.      /*
  481.       *build the key for the head
  482.       *of our chain
  483.       */
  484.      memset( szTemp,0, sizeof( szTemp));
  485.      if( pDspinstlChain->pszKey )
  486.      {
  487.         strncpy( szTemp, pDspinstlChain->pszKey, strlen(pDspinstlChain->pszKey) + 1);
  488.         free(pDspinstlChain->pszKey);
  489.      }
  490.      pDspinstlChain->pszKey = malloc(MAX_SIZ_KEY);
  491.      *(pDspinstlChain->pszKey) = 'C';
  492.      *(pDspinstlChain->pszKey+1) = '\0';
  493.      strcat( pDspinstlChain->pszKey, szTemp);
  494.  
  495.      for(pTempChain = pDspinstlChain;pTempChain;
  496.                              pTempChain = pTempChain->pNextDspInstl)
  497.      {
  498.           /*
  499.            *find the right one in the node that matches what we have
  500.            *selected
  501.            */
  502.            if(pTempChain->pszResolution)
  503.            {
  504.                /*
  505.                 *found it
  506.                 */
  507.                if(!strcmp(pTempChain->pszResolution,
  508.                     pszSelectedResolution) )
  509.                {
  510.                   pDspinstlChain->pNextDspInstl =
  511.                     pTempChain;
  512.                   /*
  513.                    *we used to incorrectly use the resolution
  514.                    *as the key,should be using the key from
  515.                    *the dsc file to match the key
  516.                    *for the dsp file
  517.                    */
  518.  
  519.  
  520.                   strcat(pDspinstlChain->pszKey,pTempChain->pszKey);
  521.                   /*
  522.                    *set the next node to
  523.                    *start with the next node in the list
  524.                    *that does not have a resolution
  525.                    */
  526.                   pTempChain->pNextDspInstl = pLastResolution;
  527.                   /*
  528.                    *we should now be looking at the first diskette
  529.                    *that does not have a resolution,this should now
  530.                    *be the fonts diskette
  531.                    *check to see if the resoulution that was selected was
  532.                    *HI-RES if so reset the key to pick-up the hires font
  533.                    *dsp file
  534.                    */
  535. //                if(!strcmp(pszSelectedResolution,_1024_768_256 ) ||
  536. //                       !strcmp(pszSelectedResolution,_1024_768_16 ) )
  537. //                {
  538. //                      pLastResolution->pszKey = malloc(MAX_SIZ_KEY);
  539. //                      strcpy(pLastResolution->pszKey,FONT_HI);
  540. //                }
  541.  
  542.                   break;
  543.                }
  544.           }
  545.      }
  546.      return;
  547. }
  548. /****************************************************************\
  549.  *
  550.  *--------------------------------------------------------------
  551.  *
  552.  *  Name:GetLastElement()
  553.  *
  554.  *  Purpose:Returns the a pointer to the last node in the list
  555.  *          that contains a valid resolution.
  556.  *
  557.  *  Returns:
  558.  *          pDspTemp - will point to either the first node that does
  559.  *                     not have a resolution or the last node in
  560.  *                     the linked list whichever occurs first
  561. \****************************************************************/
  562. PDSPINSTL_CHAIN GetLastElement(PDSPINSTL_CHAIN pDspInstlChain)
  563. {
  564.      PDSPINSTL_CHAIN pDspTemp;
  565.  
  566.      /*
  567.       *the assumption for svga is that the first node is
  568.       *always null
  569.       */
  570.      for(pDspTemp = pDspInstlChain->pNextDspInstl;pDspTemp->pszResolution;)
  571.      {
  572.           if(!pDspTemp->pNextDspInstl)
  573.           {
  574.                pDspTemp = NULL;
  575.                break;
  576.           }
  577.           pDspTemp = pDspTemp->pNextDspInstl;
  578.      }
  579.      return(pDspTemp);
  580. }
  581. /****************************************************************\
  582.  *
  583.  *--------------------------------------------------------------
  584.  *
  585.  *  Name:GetSelectedResolution
  586.  *
  587.  *  Purpose: This routine will loop through the  list of pSelectedResolutions
  588.  *           for up to ulCount number of elements looking for the ulSelected
  589.  *           flag to be set to TRUE. A pointer to the first ulSelected
  590.  *           element will be returned or NULL if no selection was made.
  591.  *  Returns:
  592.  *          pszResolutions  = a pointer to the selected resolutions string
  593.  *                            or NULL if none was selected.
  594. \****************************************************************/
  595. PSZ GetSelectedResolution(PRESOLUTIONS pSelectedResolutions,ULONG ulCount)
  596. {
  597.      ULONG ulCounter;
  598.      PRESOLUTIONS pTemp;
  599.      PSZ pszResolutions = NULL;
  600.  
  601.  
  602.      for(ulCounter =0,pTemp = pSelectedResolutions; ulCounter < ulCount;
  603.                               pTemp++,ulCounter++)
  604.      {
  605.  
  606.           if(pTemp->ulSelected)
  607.           {
  608.                pszResolutions= pTemp->achResolutionString;
  609.                break;
  610.           }
  611.      }
  612.      return(pszResolutions);
  613. }
  614. /****************************************************************\
  615.  *
  616.  *--------------------------------------------------------------
  617.  *
  618.  *  Name:Selected_Secondary
  619.  *
  620.  *  Purpose:This action routine handles the calling of the specify
  621.  *          adapter and specify monitor routines. The key that is
  622.  *          returned in the adapter structre is saved off so as to
  623.  *          used later while querying the .DSP files.
  624.  *
  625.  *
  626.  *
  627.  *  Usage:This routine should be called when the user has selected
  628.  *        to install a secondary monitor/adapter.
  629.  *
  630.  *  Returns:
  631.  *          Non-Zero -  Erorr occurred,User Aborted.
  632.  *          0        - Successful Operation,Continue
  633. \****************************************************************/
  634. LONG EXPENTRY Selected_Secondary(HWND hwnd,PDSPINSTL_GLOBAL_DATA pInstalData)
  635. {
  636.     ADAPTERENTRY adpentry;
  637.     VIDEOENTRY videntry;
  638.     LONG rc;
  639.     PDSPINSTL_CHAIN pDspChain;
  640.  
  641.  
  642.     pfnLogFunction = pInstalData->pfnLogFunction;
  643.     /*
  644.      *start at the head
  645.      *of the chain
  646.      */
  647.     pDspChain = pInstalData->pHeadDspInstl_Chain;
  648.  
  649.     if(!(rc = (*pInstalData->pfnSpecifyDisplayAdapter)(hwnd,pszAdapter, &adpentry) ) )
  650.     {
  651.         /*
  652.          *parse out the adapter info
  653.          *and save the key
  654.          */
  655.         svga_ParseAdapter(pDspChain,&adpentry);
  656.         if((rc = (*pInstalData->pfnSpecifyVideoMonitor)(hwnd,pszConfig, &videntry)))
  657.         {
  658.               SvgaReportError(rc,NULL,hwnd);
  659.  
  660.         }
  661.  
  662.     }
  663.     return(rc);
  664. }
  665. /****************************************************************\
  666.  *
  667.  *--------------------------------------------------------------
  668.  *
  669.  *  Name:svga_ParseAdapter
  670.  *
  671.  *  Purpose:This routine will move over to the last argument in
  672.  *          the achParms buffer and save it off the the key that
  673.  *          is passed,pszKey is assumed to contain a buffer big
  674.  *          enough to hold the key
  675.  *  Returns:
  676.  *          VOID
  677. \****************************************************************/
  678. VOID  APIENTRY svga_ParseAdapter(PDSPINSTL_CHAIN pInstalChain,
  679.                                  PADAPTERENTRY pAdpentry)
  680. {
  681.  
  682.      SHORT sCount;
  683.      PSZ   pszEnd;
  684.      PDSPINSTL_CHAIN  pTempChain;
  685.  
  686.      /*
  687.       *move over to the key for the adapter
  688.       *and save it off
  689.       */
  690.      pszEnd = pAdpentry->achParms;
  691.      for(sCount= (pAdpentry->cParms -1);sCount;sCount--)
  692.      {
  693.           pszEnd = (pszEnd + strlen(pszEnd) +1);
  694.      }
  695.      /*
  696.       *start at the head of the
  697.       *chain and give every node
  698.       *a copy of the key that was selected
  699.       */
  700.      for(pTempChain = pInstalChain;pTempChain; )
  701.      {
  702.           strcpy(pTempChain->pszKey,pszEnd);
  703.           pTempChain = pTempChain->pNextDspInstl;
  704.      }
  705. }
  706. /****************************************************************\
  707.  *
  708.  *--------------------------------------------------------------
  709.  *
  710.  *  Name:svga_WriteNewResolution
  711.  *
  712.  *  Purpose:To parse the resolution strings and make the
  713.  *          updates to the ini file.
  714.  *  Returns:
  715.  *          Non Zero - Error occurred
  716.  *          0        - No error
  717. \****************************************************************/
  718. ULONG APIENTRY svga_WriteNewResolution(PVIDEOENTRY pVidEntry)
  719. {
  720.     ULONG  cbCount;
  721.     PSZ    pszDelimiter;
  722.     PSZ    pszApplicationName;
  723.     CHAR   szMonitorRes[SIZ_TOWRITE];
  724.     CHAR   szMonitorInt[SIZ_TOWRITE];
  725.     CHAR   szMonitorRef[SIZ_TOWRITE];
  726.     CHAR   szStringToWrite[C_MAX_VID_PARMS];
  727.     SHORT  sArgs;
  728.     ULONG  ulReturn = 0;
  729.     PINIPARMS pIniParms;
  730.  
  731.     do
  732.     {
  733.  
  734.            for(cbCount = 0;cbCount <pVidEntry->cVideoParms;cbCount++)
  735.            {
  736.                memset(szResolution,0,sizeof(szResolution) );
  737.                memset(szInterLace,0,sizeof(szInterLace) );
  738.                memset(szStringToWrite,0,C_MAX_VID_PARMS);
  739.  
  740.  
  741.                /*
  742.                 *parse the three substrings out
  743.                 */
  744.                 pIniParms= IniParms;
  745.                 for(pszDelimiter = pVidEntry->avidparm[cbCount].achParms,sArgs = 0;
  746.                                                        sArgs <pVidEntry->avidparm[cbCount].cParms;
  747.                                                        sArgs++,
  748.                                                        pIniParms++)
  749.                 {
  750.                     strcpy(pIniParms->pszParms,pszDelimiter);
  751.                     pszDelimiter = (pszDelimiter + (strlen(pszDelimiter) + 1) );
  752.                 }
  753.  
  754.  
  755.                 /*
  756.                  *write each one out to the ini file
  757.                  */
  758.                 pIniParms= IniParms;
  759.                 for(sArgs = 0;sArgs <pVidEntry->cVideoParms;
  760.                                                        sArgs++,
  761.                                                        pIniParms++)
  762.                 {
  763.  
  764.                      if( pIniParms->pfnWriteParmToIni(IniParms) )
  765.                      {
  766.                          /*
  767.                           *generate error
  768.                           */
  769.                           break;
  770.                      }
  771.                 }
  772.            }
  773.      }ONCE;
  774.  
  775.      return(ulReturn);
  776. }
  777. /****************************************************************\
  778.  *
  779.  *--------------------------------------------------------------
  780.  *
  781.  *  Name:svga_UpWriteIni
  782.  *
  783.  *  Purpose:Update the ini file.
  784.  *
  785.  *
  786.  *
  787.  *  Usage: Used to update the user ini,expects formed keys,and strings.
  788.  *
  789.  *
  790.  *  Returns:
  791.  *          0 - if successful execution completed
  792.  *          1 - if error
  793. \****************************************************************/
  794. ULONG APIENTRY svga_UpWriteIni(PSZ pszApplication,PSZ pszKey,PSZ pszString)
  795. {
  796.  
  797.     HINI   UserIni  =  HINI_USERPROFILE;
  798.     ULONG  ulReturn = 0;
  799.  
  800.     if(!PrfWriteProfileString(UserIni,
  801.                               pszApplication,
  802.                               pszKey,
  803.                               pszString) )
  804.      {
  805.          ulReturn = WRITE_INI_ERROR;
  806.      }
  807.      return(ulReturn);
  808. }
  809. /****************************************************************\
  810.  *
  811.  *--------------------------------------------------------------
  812.  *
  813.  *  Name:svga_WriteResolIni()
  814.  *
  815.  *  Purpose:Set up to right the resolution to the ini file
  816.  *          based on the arguments contained in the pIniParms
  817.  *          structure.
  818.  *
  819.  *  Returns:
  820.  *          0 - if successful execution completed
  821.  *          1 - if error
  822. \****************************************************************/
  823. INT   APIENTRY svga_WriteResolIni(PINIPARMS pIniParms)
  824. {
  825.      APIRET ulRet;
  826.  
  827.      /*
  828.       *write out the string to the ini
  829.       */
  830.      ulRet = svga_UpWriteIni(MONITOR_RES,
  831.                                  pIniParms->pszParms,
  832.                                  pIniParms[INDEX_VREFRESH].pszParms);
  833.  
  834.      return(!ulRet);
  835.  
  836. }
  837. /****************************************************************\
  838.  *
  839.  *--------------------------------------------------------------
  840.  *
  841.  *  Name:WaitThread
  842.  *
  843.  *  Purpose:This thread will sleep for SLEEP_TIME milliseconds,
  844.  *          query the process id of that was passed to in the
  845.  *          pWaitData structure.Once the process id we are interested
  846.  *          in,is no longer a valid process,this thread will post
  847.  *          the AM_QUIT message back to the owner of hwnd.
  848.  *          The session id that was passed to the thread in the
  849.  *          pWaitData structure will also be terminated.
  850.  *  Returns:
  851.  *          VOID
  852. \****************************************************************/
  853. VOID APIENTRY WaitThread(PVOID pvMessageData)
  854. {
  855.     PSVGAWAITDATA pWaitData;
  856.     RESULTCODES  Results;
  857.     ULONG ulProcessId;
  858.     USHORT usPriority,rc;
  859.     HWND hwndMain;
  860.  
  861.     pWaitData = (PSVGAWAITDATA)pvMessageData;
  862.  
  863.     do
  864.     {
  865.           /*
  866.            *
  867.            */
  868.            DosSleep(SLEEP_TIME);
  869.            if(rc = Dos16GetPrty(PRTYS_PROCESS,
  870.                              &usPriority,
  871.                              (USHORT)pWaitData->ulProcessid) )
  872.            {
  873.                if(rc == ERROR_INVALID_PROCID)
  874.                {
  875.                     break;
  876.                }
  877.  
  878.            }
  879.  
  880.      }FOREVER;
  881.  
  882.      /*
  883.       *send message back to the main loop
  884.       *that we are done
  885.       */
  886.      if(pWaitData->hwnd)
  887.      {
  888.           WinPostMsg(pWaitData->hwnd, AM_QUIT,(MPARAM)FALSE, 0);
  889.      }
  890.  
  891.  
  892.      /*
  893.       *kill off the session that svga.exe
  894.       *was started in
  895.       */
  896.       DosStopSession(0,pWaitData->ulSession);
  897.       DosExit(EXIT_THREAD,0);
  898. }
  899.  
  900. /****************************************************************\
  901.  *
  902.  *--------------------------------------------------------------
  903.  *
  904.  *  Name:WaitSvgaDlgProc()
  905.  *
  906.  *  Purpose:This routine throws up the Hardware determination in
  907.  *          progress dialog box,and waits for the AM_QUIT message
  908.  *          to be sent back to it. No buttons are enable on the
  909.  *          dialog box,so no other messages,except the default are
  910.  *          expected.
  911.  *  Returns:
  912.  *          TRUE is always returned.
  913. \****************************************************************/
  914. MRESULT EXPENTRY WaitSvgaDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2)
  915. {
  916.  
  917.     HWND     hwndListBox;
  918.     ULONG    iItem,ulCount;
  919.     static    SVGAWAITDATA WaitData;
  920.  
  921.  
  922.     switch (msg)
  923.     {
  924.         case WM_INITDLG:
  925.             hwndListBox = WinWindowFromID(hwnd, IDL_GENERAL);
  926.             CenterDialog(hwnd);
  927.  
  928.             /*
  929.              * Create a seperate thread to run svga.exe
  930.              */
  931.  
  932.             WaitData.hwnd = hwnd;
  933.  
  934.             if(DosCreateThread(&tidThread,
  935.                                (PFNTHREAD)RunSvga,
  936.                                (ULONG)&WaitData,
  937.                                FALSE,
  938.                                STACK_SIZE_THRD) )
  939.             {
  940.                 WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  941.             }
  942.  
  943. //91642            if( RunSvga(hwnd) )
  944. //91642            {
  945. //91642                WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  946. //91642            }
  947.  
  948.             break;
  949.  
  950.         case WM_CLOSE:
  951.             break;
  952.         /*
  953.          *our thread should send us this message
  954.          *when the svga process dies
  955.          */
  956.         case AM_QUIT:
  957. //91642           DosKillThread(tidThread);
  958.  
  959.              WinDismissDlg(hwnd,SHORT1FROMMP(mp1));
  960.              break;
  961.  
  962.         default:
  963.             return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  964.             break;
  965.     }
  966.     return 0L;
  967. }
  968.  
  969. /****************************************************************\
  970.  *
  971.  *-----------------------------------------------------------------------
  972.  *
  973.  *  Name:SelectSvgaUtilDlgProc()
  974.  *
  975.  *  Purpose:This routine is the main dialog procedure for selecting an SVGA
  976.  *          monitor configuration utility.
  977.  *
  978.  *  Called by: GetResolutionsData()
  979.  *
  980.  *  Calls to:  InitHelp()
  981.  *             CreateSvgaTmpBat()
  982.  *             SvgaUtilDlgProc()
  983.  *             SvgaReportError()
  984.  *
  985.  *  Returns:
  986.  *          (MPARAM)TRUE is returned on an error condition or WM_CANCEL
  987. \************************************************************************/
  988.  
  989. MRESULT EXPENTRY SelectSvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2)
  990. {
  991.     BOOL   fError;
  992.     APIRET apiRet;
  993.  
  994.     switch(msg)
  995.     {
  996.         case WM_INITDLG:
  997.              /*
  998.                initialize Help Manager
  999.              */
  1000.              InitHelp(&hwndHelpInstance);
  1001.              if (hwndHelpInstance)
  1002.                 WinAssociateHelpInstance(hwndHelpInstance, hwnd);
  1003.  
  1004.              CenterDialog(hwnd);
  1005.              break;
  1006.  
  1007.         case WM_COMMAND:
  1008.              switch (SHORT1FROMMP(mp1))
  1009.              {
  1010.  
  1011.                  case DID_OK:
  1012.  
  1013.                     apiRet = DID_OK;
  1014.  
  1015.                     /*
  1016.                      * Use Default Settings
  1017.                      */
  1018.  
  1019.                     if (SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDB_DEFAULTSETTINGS),
  1020.                                                 BM_QUERYCHECK, 0L, 0L)))
  1021.                     {
  1022.                          if (CreateSvgaTmpBat( NULL ))
  1023.                          {
  1024.                              SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1025.                                              NULL,
  1026.                                              hwnd);
  1027.  
  1028.                              apiRet = DID_ERROR;
  1029.                          }
  1030.  
  1031.                     }
  1032.                     else if (SHORT1FROMMR(WinSendMsg(WinWindowFromID(hwnd, IDB_SVGAUTIL),
  1033.                                                 BM_QUERYCHECK, 0L, 0L)))
  1034.                     {
  1035.  
  1036.                          apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1037.                                             HWND_DESKTOP,
  1038.                                             (PFNWP)SvgaUtilDlgProc,
  1039.                                             hmodResource,
  1040.                                             DLG_SVGAUTIL,
  1041.                                             NULL);
  1042.                     }
  1043.  
  1044.                     if (apiRet == DID_OK)
  1045.                         WinPostMsg(hwnd, AM_QUIT,0,0);
  1046.                     else if (apiRet == DID_ERROR)
  1047.                         WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  1048.                  break;
  1049.  
  1050.                  case DID_CANCEL:
  1051.                      WinPostMsg(hwnd, AM_QUIT,(MPARAM)TRUE, 0);
  1052.                      break;
  1053.  
  1054.              }
  1055.              break;
  1056.  
  1057.         case AM_QUIT:
  1058.              WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
  1059.              break;
  1060.  
  1061.         default:
  1062.             return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1063.                break;
  1064.  
  1065.     }
  1066.     return 0L;
  1067. }
  1068.  
  1069. /****************************************************************\
  1070.  *
  1071.  *-----------------------------------------------------------------------
  1072.  *
  1073.  *  Name:SvgaUtilDlgProc()
  1074.  *
  1075.  *  Purpose:This routine prompt the user for the SVGA display adapter
  1076.  *          utility file location and then creates the batch file
  1077.  *          used by RunSvga().
  1078.  *
  1079.  *  Called by: GetResolutionsData()
  1080.  *
  1081.  *  Calls to:  InitHelp()
  1082.  *             CreateSvgaTmpBat()
  1083.  *             SvgaReportError()
  1084.  *
  1085.  *  Returns:
  1086.  *          DID_OK, DID_CANCEL, DID_ERROR
  1087. \************************************************************************/
  1088.  
  1089. MRESULT EXPENTRY SvgaUtilDlgProc(HWND hwnd, ULONG  msg, MPARAM mp1, MPARAM mp2)
  1090. {
  1091.  
  1092.    FILEDLG  pfdFileDlg;
  1093.    static CHAR szTitle[CCHMAXPATH];
  1094.    PSZ pszFullFile = "*.*";
  1095.    HWND hwndWinFileDlg;
  1096.    PSVGAUTILDATA pUtilData;
  1097.    static       CHAR  pszSourceDir[] = "A:\\";
  1098.    PSZ          pszName;
  1099.    APIRET       apiRet;
  1100.    ULONG        ulBufLen;
  1101.    USHORT       i;
  1102.    FILESTATUS  FileBuf;
  1103.    BOOL        fError;
  1104.    CHAR        szBuffer[CCHMAXPATH];
  1105.  
  1106.  
  1107.     switch(msg)
  1108.     {
  1109.          case WM_INITDLG:
  1110.  
  1111.              if (hwndHelpInstance)
  1112.                 WinAssociateHelpInstance(hwndHelpInstance, hwnd);
  1113.  
  1114.             /*
  1115.              * malloc util data structure
  1116.              */
  1117.              pUtilData = malloc( sizeof( SVGAUTILDATA ) );
  1118.              pUtilData->pszBuffer = malloc( CCHMAXPATH );
  1119.              pUtilData->pszMsg = malloc( CCHMAXPATH );
  1120.              pUtilData->pszTitle = malloc( CCHMAXPATH );
  1121.              pUtilData->fParms = FALSE;
  1122.  
  1123.              pUtilData->hab = WinInitialize(0);
  1124.  
  1125.              /*
  1126.               * Load resource strings from dll
  1127.               */
  1128.              WinLoadString(pUtilData->hab, hmodResource, MSG_FILE_NOT_EXIST, CCHMAXPATH,
  1129.                   pUtilData->pszMsg);
  1130.              WinLoadString(pUtilData->hab, hmodResource, MSG_SVGAUTIL_NOT_FOUND, CCHMAXPATH,
  1131.                   pUtilData->pszTitle);
  1132.              WinLoadString(pUtilData->hab, hmodResource, MSG_FILEDLG_TITLE, CCHMAXPATH,
  1133.                   szTitle);
  1134.  
  1135.              WinSetWindowULong(hwnd, QWL_USER, (ULONG)pUtilData);
  1136.  
  1137.              CenterDialog(hwnd);
  1138.              WinPostMsg(hwnd,WM_INIT,0,0);
  1139.              break;
  1140.  
  1141.  
  1142.  
  1143.          case WM_INIT:
  1144.              WinSendDlgItemMsg(hwnd,      /* set text limit of entry field */
  1145.                       IDE_SOURCEDIR,
  1146.                       EM_SETTEXTLIMIT,
  1147.                       MPFROMSHORT(CCHMAXPATH -10),
  1148.                       (MPARAM)0L);
  1149.  
  1150.              WinSetDlgItemText(hwnd,   /* set source directory a:\ */
  1151.                      IDE_SOURCEDIR,
  1152.                      pszSourceDir);
  1153.  
  1154.  
  1155.              WinSetFocus(HWND_DESKTOP, WinWindowFromID(hwnd, IDE_SOURCEDIR));
  1156.  
  1157.              break;
  1158.  
  1159.          case AM_QUIT:
  1160.  
  1161.              pUtilData = (PSVGAUTILDATA)WinQueryWindowULong(hwnd, QWL_USER);
  1162.  
  1163.              free( pUtilData->pszBuffer );
  1164.              free( pUtilData->pszMsg );
  1165.              free( pUtilData->pszTitle );
  1166.              free( pUtilData );
  1167.              WinTerminate(pUtilData->hab);
  1168.              WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
  1169.              break;
  1170.  
  1171.          case WM_COMMAND:
  1172.  
  1173.              switch (SHORT1FROMMP(mp1))
  1174.              {
  1175.  
  1176.                  case DID_OK:
  1177.  
  1178.                      fError = FALSE;
  1179.                      fSvgaUtilPresent = FALSE;
  1180.  
  1181.                      pUtilData = (PSVGAUTILDATA)WinQueryWindowULong(hwnd, QWL_USER);
  1182.  
  1183.                      WinQueryDlgItemText( hwnd,
  1184.                                            IDE_SOURCEDIR,
  1185.                                            CCHMAXPATH - 10,
  1186.                                            pUtilData->pszBuffer );
  1187.                      /*
  1188.                       * If user selects okay without entering
  1189.                       * a utility program
  1190.                       */
  1191.  
  1192.                      if(!strcmp( pUtilData->pszBuffer, pszSourceDir) ||
  1193.                          strlen(pUtilData->pszBuffer) <= 3)
  1194.                      {
  1195.                             WinPostMsg(hwnd,WM_INIT,0,0);
  1196.                             break;
  1197.                      }
  1198.                      else
  1199.                      {
  1200.                           /*
  1201.                             parse buffer to first space character and
  1202.                             only copy name,  not parameters
  1203.                            */
  1204.  
  1205.                           pUtilData->fParms = FALSE;
  1206.                           ulBufLen = strlen( pUtilData->pszBuffer );
  1207.                           for( i=0; i<ulBufLen; i++ ) {
  1208.                              if( *((CHAR *)pUtilData->pszBuffer + i) == ' ')
  1209.                              {
  1210.                                  pszName =malloc( i );
  1211.                                  memcpy( pszName, pUtilData->pszBuffer, i );
  1212.                                  *(pszName + i) = '\0';
  1213.                                  pUtilData->fParms = TRUE;
  1214.                                  break;
  1215.                              }
  1216.                           }
  1217.  
  1218.                           if(!pUtilData->fParms)
  1219.                           {
  1220.                              pszName = strdup( pUtilData->pszBuffer );
  1221.                           }
  1222.  
  1223.                           /*
  1224.                            *make sure the program can be found
  1225.                            */
  1226.  
  1227.                            DosError( HARDERROR_DISABLE );
  1228.  
  1229.                            apiRet = DosQueryPathInfo( pszName,
  1230.                                                FIL_STANDARD,
  1231.                                                &FileBuf,
  1232.                                                sizeof( FileBuf ) );
  1233.  
  1234.                            DosError( HARDERROR_ENABLE );
  1235.  
  1236.                            if(apiRet) {
  1237.                               sprintf( szBuffer, pUtilData->pszMsg, pszName );
  1238.                               WinMessageBox( HWND_DESKTOP,
  1239.                                              hwnd,
  1240.                                              szBuffer,
  1241.                                              pUtilData->pszTitle,
  1242.                                              HELP_DLG_SELECTSVGAUTIL,
  1243.                                              MB_OK | MB_HELP | MB_INFORMATION | MB_MOVEABLE);
  1244.  
  1245.                              free( pszName );
  1246.                              WinPostMsg(hwnd,WM_INIT,0,0);
  1247.                              break;
  1248.                           }
  1249.  
  1250.                           fSvgaUtilPresent = TRUE;
  1251.  
  1252.                           if( CreateSvgaTmpBat( pUtilData->pszBuffer ) )
  1253.                           {
  1254.                               SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1255.                                               NULL,
  1256.                                               hwnd);
  1257.  
  1258.                                 fError = TRUE;
  1259.                           }
  1260.  
  1261.  
  1262.                           free( pszName );
  1263.                      }
  1264.  
  1265.                      (fError ? WinPostMsg(hwnd, AM_QUIT,(MPARAM)DID_ERROR, 0) :
  1266.                               WinPostMsg(hwnd, AM_QUIT,(MPARAM)DID_OK,0));
  1267.                      break;
  1268.  
  1269.                  case DID_LOCATE:
  1270.  
  1271.                            memset( &pfdFileDlg,0,sizeof(FILEDLG));
  1272.                            pfdFileDlg.cbSize = sizeof(FILEDLG);
  1273.                            pfdFileDlg.fl = FDS_HELPBUTTON | FDS_CENTER | FDS_OPEN_DIALOG;
  1274.                            pfdFileDlg.pszTitle = szTitle;
  1275.                            pUtilData = (PSVGAUTILDATA)WinQueryWindowULong(hwnd,
  1276.                                                                  QWL_USER);
  1277.                            WinQueryDlgItemText( hwnd,
  1278.                                                 IDE_SOURCEDIR,
  1279.                                                 CCHMAXPATH - 10,
  1280.                                                 pUtilData->pszBuffer );
  1281.                            pfdFileDlg.pszIDrive = "A:";
  1282.                            if(strcmp( pUtilData->pszBuffer, pszSourceDir ))
  1283.                            {
  1284.                               ulBufLen = strlen( pUtilData->pszBuffer );
  1285.                               for(i=0;i<ulBufLen;i++)
  1286.                               {
  1287.                                  if(*pUtilData->pszBuffer != ' ')
  1288.                                  {
  1289.                                     *pfdFileDlg.pszIDrive =
  1290.                                          *pUtilData->pszBuffer;
  1291.                                     break;
  1292.                                  }
  1293.                                  pUtilData->pszBuffer++;
  1294.                               }
  1295.                            }
  1296.  
  1297.                            strcpy( pfdFileDlg.szFullFile, pszFullFile );
  1298.  
  1299.                            hwndWinFileDlg = WinFileDlg( HWND_DESKTOP, hwnd, &pfdFileDlg );
  1300.  
  1301.                            if( hwndWinFileDlg && (pfdFileDlg.lReturn == DID_OK ) )
  1302.                            {
  1303.                                WinSetDlgItemText( hwnd, IDE_SOURCEDIR, pfdFileDlg.szFullFile );
  1304.                            }
  1305.                            break;
  1306.  
  1307.                  case DID_CANCEL:
  1308.                      WinPostMsg(hwnd, AM_QUIT,(MPARAM)DID_CANCEL, 0);
  1309.                      break;
  1310.  
  1311.  
  1312.                  default:
  1313.                      WinDismissDlg(hwnd, SHORT1FROMMP(mp1));
  1314.                      break;
  1315.  
  1316.              }
  1317.              break;
  1318.  
  1319.          default:
  1320.              return(WinDefDlgProc(hwnd, msg, mp1, mp2));
  1321.              break;
  1322.  
  1323.     }
  1324.  
  1325.     return 0L;
  1326.  
  1327. }
  1328.  
  1329. /****************************************************************\
  1330.  *
  1331.  *--------------------------------------------------------------
  1332.  *
  1333.  *  Name:GetResolutionsData()
  1334.  *
  1335.  *  Purpose:This routine should be used to determine which resolutions
  1336.  *          to display to the user. If the default flag is set,the
  1337.  *          svgadata.pmi file will be read,and the intersection of the
  1338.  *          dsc file and svgadata file will be displayed. Otherwise all
  1339.  *          of the resolutions the dsc file supports will be displayed.
  1340.  *
  1341.  *          pResolutions           - pointer to where to read in the
  1342.  *                                   resolutions from the svgadata.pmi
  1343.  *                                   file.
  1344.  *
  1345.  *          pResolutionsToDisplay  - pointer to the array of structures
  1346.  *                                   where to store the list of suppoted
  1347.  *                                   resolutions to display to the user.
  1348.  *
  1349.  *          hwnd                   - parent window handle
  1350.  *
  1351.  *          pInstalData            - pointer to the head of the list that
  1352.  *                                   contains the list of resolutions from
  1353.  *                                   the dsc file.
  1354.  *          fUseDefault            - flag to indicate whether to use
  1355.  *                                   only the intersection of the dsc
  1356.  *                                   resolutions and the svgadata.pmi
  1357.  *                                   resolutons.
  1358.  *          pulCount               - pointer to the number of supported
  1359.  *                                   resolutions to display
  1360.  *
  1361.  *  Returns:
  1362.  *          apiRet - re-map all error codes to CANCEL_OPERATION
  1363.  *                   ,forces the calling program to return to the main
  1364.  *                   panel
  1365.  *          0      - NO error
  1366. \****************************************************************/
  1367. APIRET  GetResolutionsData(PRESOLUTIONS pResolutions,
  1368.                            PRESOLUTIONS pResolutionsToDisplay,
  1369.                            HWND hwnd,
  1370.                            PDSPINSTL_CHAIN  pInstalChain,
  1371.                            BOOL fUseDefault,
  1372.                            PULONG pulCount,
  1373.                            PFN pfnGetNext,
  1374.                            BOOL *pulShowSelectionsToUser)
  1375. {
  1376.     APIRET apiRet = 0;
  1377.     HWND hwndMain;
  1378.     ULONG ulCount,ulSize;
  1379.     PVOID pVoid;
  1380.     static bOnce = TRUE;
  1381.     RESOLUTIONDATA  resData;
  1382.  
  1383.  
  1384.     do
  1385.     {
  1386.  
  1387.          /*
  1388.           *make sure we run svga.exe at least once,or if the
  1389.           *svgadata.pmi file does not exist
  1390.           */
  1391.          if(OpenResolutionsFile(pResolutions,&ulCount) || bOnce)
  1392.          {
  1393.               /*
  1394.                *get handle to our dll's resources
  1395.                */
  1396.               if(apiRet = GetDllHandle(&hmodResource) )
  1397.               {
  1398.                    SvgaReportError(MSG_GET_DLL_HANDLE,NULL,hwnd);
  1399.                    break;
  1400.               }
  1401.  
  1402.               /*
  1403.                * If a resolution string was passed in then run
  1404.                * unattended.
  1405.                */
  1406.               if( pszResolutionString )
  1407.               {
  1408.                     if (CreateSvgaTmpBat( NULL ))
  1409.                     {
  1410.                         SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1411.                                         NULL,
  1412.                                         hwnd);
  1413.  
  1414.                         apiRet = DID_ERROR;
  1415.                     }
  1416.  
  1417.                    apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1418.                                        HWND_DESKTOP,
  1419.                                        (PFNWP)WaitSvgaDlgProc,
  1420.                                        hmodResource,
  1421.                                        DLG_RUNSVGA,
  1422.                                        NULL);
  1423.  
  1424.               }
  1425.               else
  1426.               {
  1427.                   /*
  1428.                    * Prompt for svga utility, create svgatmp.bat
  1429.                    * If function fails don't run svgatmp.bat
  1430.                    */
  1431.  
  1432.                    if(!(apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1433.                                  HWND_DESKTOP,
  1434.                                 (PFNWP)SelectSvgaUtilDlgProc,
  1435.                                  hmodResource,
  1436.                                  DLG_SELECTSVGAUTIL,
  1437.                                  NULL)))
  1438.                    {
  1439.                        /*
  1440.                         *throw up a message box
  1441.                         *to indicate wait a moment
  1442.                         *while we run the svgatmp.bat
  1443.                         */
  1444.                        apiRet = WinDlgBox((HWND)HWND_DESKTOP,
  1445.                                            HWND_DESKTOP,
  1446.                                            (PFNWP)WaitSvgaDlgProc,
  1447.                                            hmodResource,
  1448.                                            DLG_RUNSVGA,
  1449.                                            NULL);
  1450.  
  1451.                        if( apiRet )
  1452.                        {
  1453.  
  1454.                           SvgaReportError(MSG_UNABLE_TO_DETERMINE_HARD,
  1455.                                   NULL,
  1456.                                   hwnd);
  1457.  
  1458.                        }
  1459.  
  1460.                    }
  1461.  
  1462.               }
  1463.  
  1464.          }
  1465.          /*
  1466.           *if we got no error while trying to run svga
  1467.           */
  1468.          if(!apiRet)
  1469.          {
  1470.              bOnce = FALSE;
  1471.              /*
  1472.               *we should have a valid file
  1473.               *by now
  1474.               */
  1475.              if(apiRet = OpenResolutionsFile(pResolutions,&ulCount) )
  1476.              {
  1477.                   /*
  1478.                    *report error if we still don't have something
  1479.                    *we can read
  1480.                    */
  1481.                    SvgaReportError(MSG_BAD_RESOLUTIONS_FILE,NULL,hwnd);
  1482.                    break;
  1483.              }
  1484.              apiRet = ValidateResolutions(pResolutions,
  1485.                                  pResolutionsToDisplay,
  1486.                                  pInstalChain,
  1487.                                  fUseDefault,
  1488.                                  pulCount,
  1489.                                  ulCount,
  1490.                                  pfnGetNext);
  1491.              /*
  1492.               *error or no resolutions that
  1493.               *match the dsc files
  1494.               */
  1495.  
  1496.              if(apiRet ||  !(*pulCount) )
  1497.              {
  1498. //D92820            apiRet = SvgaMessageBox(MSG_HARDWARE_CONFIG_ERROR,NULL,hwnd);
  1499. //D92820                  if(apiRet == MBID_YES )    /* never hits this code */
  1500. //D92820                   {
  1501. //D92820                        *pulShowSelectionsToUser = FALSE;
  1502. //D92820                        apiRet = 0;
  1503. //D92820                        apiRet = CONTINUE_WITH_ERR;
  1504. //D92820                   }
  1505.  
  1506.                  apiRet = CANCEL_OPERATION;
  1507.                  svgaLog("ERROR: High resolution mode not supported"); //NLS??
  1508.              }
  1509.              else if( pszResolutionString )
  1510.              {
  1511.                 /*
  1512.                  * compare the valid resolutions with the one passed
  1513.                  * to the action routine dll.
  1514.                  */
  1515.                  if(CompareResolutions( pszResolutionString,
  1516.                                         pResolutionsToDisplay,
  1517.                                         *pulCount ) == TRUE)
  1518.                  {
  1519.                     /*
  1520.                      * Select the resolution for the user bypassing the
  1521.                      * specify resolution dialog.
  1522.                      */
  1523.  
  1524.                     if( SelectResolutionForUser(pInstalChain,
  1525.                                                 pResolutionsToDisplay,
  1526.                                                 pulCount ) == TRUE )
  1527.                     {
  1528.                         *pulShowSelectionsToUser = FALSE;
  1529.  
  1530.                     }
  1531.  
  1532.                  }
  1533.                  else
  1534.                     pszResolutionString = NULL;
  1535.  
  1536.              }
  1537.  
  1538.          }
  1539.  
  1540.      }ONCE;
  1541.      if(apiRet)
  1542.      {
  1543.           if (apiRet != CONTINUE_WITH_ERR)
  1544.               apiRet = CANCEL_OPERATION;
  1545.      }
  1546.      return(apiRet);
  1547. }
  1548.  
  1549.  
  1550.  
  1551. /****************************************************************\
  1552.  *
  1553.  *--------------------------------------------------------------
  1554.  *
  1555.  *  Name:OpenResolutionsFile()
  1556.  *
  1557.  *  Purpose: This routine will open the svgadata.pmi file and if
  1558.  *           successful will call readresolutions file.
  1559.  *
  1560.  *  pResolutions  - pointer to a array of resolutions structures that
  1561.  *                  is expected to be large enough to hold all of the
  1562.  *                  supported resoulutions.
  1563.  *  pulCount     -  the count of supported resolutions will be stored
  1564.  *                  here.
  1565.  *  Returns:
  1566.  *          FALSE   - No Error occurred.
  1567.  *          TRUE    - Error occurred.
  1568. \****************************************************************/
  1569. BOOL OpenResolutionsFile(PRESOLUTIONS pResolutions,PULONG pulCount)
  1570. {
  1571.  
  1572.     BOOL fError =FALSE;
  1573.     HFILE    hf;
  1574.     ULONG    ulAction,rc;
  1575.     PSZ    pszResolutionsFile = RESOLUTIONS_FILE;
  1576.     ULONG  ulBootDrive;
  1577.  
  1578.     /*
  1579.      *set the boot drive
  1580.      */
  1581.     DosQuerySysInfo(QSV_BOOT_DRIVE,
  1582.                     QSV_BOOT_DRIVE,
  1583.                     &ulBootDrive,
  1584.                     sizeof(ulBootDrive));
  1585.     *pszResolutionsFile = (CHAR)(ulBootDrive + 'A' - 1);
  1586.     if(!(rc = DosOpen(pszResolutionsFile,
  1587.                        &hf,
  1588.                        &ulAction,
  1589.                        0,
  1590.                        FILE_ARCHIVED | FILE_READONLY | FILE_SYSTEM
  1591.                                      | FILE_HIDDEN,
  1592.                        FILE_OPEN,
  1593.                        OPEN_SHARE_DENYNONE | OPEN_ACCESS_READONLY,
  1594.                        NULL)))
  1595.     {
  1596.           if(ReadResolutionsFile(pResolutions,hf,pulCount) )
  1597.           {
  1598.                fError = TRUE;
  1599.           }
  1600.           DosClose(hf);
  1601.  
  1602.     }
  1603.     else
  1604.     {
  1605.           fError =TRUE;
  1606.     }
  1607.  
  1608.     return(fError);
  1609. }
  1610.  
  1611. /****************************************************************\
  1612.  *
  1613.  *--------------------------------------------------------------
  1614.  *
  1615.  *  Name:ReadResolutionsFile()
  1616.  *
  1617.  *  Purpose: This routine will read the  parameter file, and parse
  1618.  *           the graphics information and save the supported resolutions
  1619.  *           mode into the pResolutions structure that was passed.
  1620.  *           It is assumed the pResolutions structure is large enough to
  1621.  *           hold all of the supported resolutions.
  1622.  *
  1623.  *           pResolutions          - pointer to the list of structures
  1624.  *                                   where the resolutions will be stored.
  1625.  *           hfile                 - handle to the file that should have
  1626.  *                                   already been opened.
  1627.  *           pulCount              - where the number of supported resolutions
  1628.  *                                   that was placed in pResolutions will be
  1629.  *                                   stored.
  1630.  *  Returns:
  1631.  *          FALSE   - No error occurred.
  1632.  *          TRUE    - error occurred.
  1633. \****************************************************************/
  1634. BOOL ReadResolutionsFile(PRESOLUTIONS pResolutions,HFILE hf,PULONG pulCount)
  1635. {
  1636.      BOOL fError = TRUE;
  1637.      PVOID pvBuffer = NULL;
  1638.      FILESTATUS fstsFile;
  1639.      ULONG ulBytesRead,ulIndex;
  1640.      PSZ pszNextResolution,pszNextMode;
  1641.  
  1642.  
  1643.      do
  1644.      {
  1645.           *pulCount = 0;
  1646.           DosQueryFileInfo(hf,
  1647.                        FIL_STANDARD,
  1648.                        &fstsFile,
  1649.                        sizeof(FILESTATUS));                  /* get size of file */
  1650.  
  1651.           if(fstsFile.cbFile < (ULONG)-1)                 /* file size < 64K ? */
  1652.           {
  1653.                pvBuffer = malloc(fstsFile.cbFile + 1);
  1654.                if( pvBuffer)
  1655.                {
  1656.                   DosRead(hf,pvBuffer,fstsFile.cbFile,&ulBytesRead);
  1657.                   pszNextResolution = pvBuffer;
  1658.                   while(pszNextResolution)
  1659.                   {
  1660.                        /*
  1661.                         *get to the next graphics mode string
  1662.                         */
  1663.                        if(pszNextMode = strstr(pszNextResolution,GRAPHICS_MODE))
  1664.                        {
  1665.                             pszNextResolution = (strchr(pszNextMode,':') + 1);
  1666.                             pszNextResolution = strip_white(pszNextResolution);
  1667.                             ulIndex           = strcspn(pszNextResolution,".");
  1668.                             strncpy(pResolutions->achResolutionString,
  1669.                                       pszNextResolution,ulIndex);
  1670.                             pResolutions++;
  1671.                             (*pulCount)++;
  1672.                        }
  1673.                        else
  1674.                        {
  1675.                             pszNextResolution = NULL;
  1676.                        }
  1677.                   }
  1678.  
  1679.                   fError = FALSE;
  1680.                }
  1681.  
  1682.           }
  1683.           fError = FALSE;
  1684.  
  1685.      }ONCE;
  1686.  
  1687.      if(pvBuffer)
  1688.      {
  1689.           free(pvBuffer);
  1690.      }
  1691.      return(fError);
  1692. }
  1693.  
  1694. /*************************************************************
  1695.  *
  1696.  *
  1697.  *    Name: CreateSvgaTmpBat()
  1698.  *
  1699.  *    Purpose:   This function will make sure svga.exe exist, if
  1700.  *               so, it will create the svgatmp.bat file used by
  1701.  *               RunSvga()
  1702.  *
  1703.  *    Returns:  apiRet.
  1704.  *
  1705.  **************************************************************/
  1706. APIRET CreateSvgaTmpBat( CHAR *pszBuffer )
  1707.  {
  1708.       APIRET apiRet = 0;
  1709.       HFILE hFile;
  1710.       ULONG ulAction, ulTemp, ulBootDrive;
  1711.       PSZ   pszSvgaTmpBatFile = SVGATMP_BAT;
  1712.       CHAR  szSvgaFullProg[CCHMAXPATH];
  1713.       PSZ   pszArg1 = " ON";
  1714.       PSZ   pszArg2 = " INIT";
  1715.  
  1716.  
  1717.       memset( szSvgaFullProg,0, sizeof( szSvgaFullProg ) );
  1718.       /*
  1719.        ** get full program path for svga.exe
  1720.        */
  1721.       if(!(apiRet = DosSearchPath(SEARCH_ENVIRONMENT,
  1722.                         "PATH",
  1723.                          SVGA_PROGRAM,
  1724.                          szSvgaFullProg,
  1725.                          CCHMAXPATH)) )
  1726.       {
  1727.           /* get boot drive  */
  1728.           DosQuerySysInfo(QSV_BOOT_DRIVE,
  1729.                           QSV_BOOT_DRIVE,
  1730.                             &ulBootDrive,
  1731.                            sizeof(ulBootDrive));
  1732.  
  1733.           *pszSvgaTmpBatFile = (CHAR)(ulBootDrive + 'A' - 1);
  1734.  
  1735.           if(!(apiRet = DosOpen(pszSvgaTmpBatFile,
  1736.                      &hFile,
  1737.                      &ulAction,
  1738.                      0,
  1739.                      FILE_NORMAL,
  1740.                      FILE_TRUNCATE | FILE_CREATE,
  1741.                      OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE,
  1742.                      NULL)))
  1743.           {
  1744.               strcat( szSvgaFullProg, pszArg1 );
  1745.  
  1746.               if( fSvgaUtilPresent ){
  1747.                    strcat( pszBuffer, "\r\n" );
  1748.                    DosWrite(hFile, pszBuffer, strlen(pszBuffer),
  1749.                         &ulTemp);
  1750.                    DosWrite(hFile, szSvgaFullProg, strlen(szSvgaFullProg),
  1751.                         &ulTemp);
  1752.               }
  1753.               else{
  1754.                    strcat( szSvgaFullProg, pszArg2 );
  1755.                    DosWrite(hFile, szSvgaFullProg, strlen(szSvgaFullProg),
  1756.                         &ulTemp);
  1757.               }
  1758.  
  1759.               DosClose(hFile);
  1760.  
  1761.           }
  1762.  
  1763.       }
  1764.  
  1765.       return( apiRet );
  1766.  
  1767. }
  1768.  
  1769. /****************************************************************\
  1770.  *
  1771.  *--------------------------------------------------------------
  1772.  *
  1773.  *  Name:RunSvga
  1774.  *
  1775.  *  Purpose:This routine will run the dos batch file svgatmp.bat.
  1776.  *          If user has a Svga Utility, svga.exe will be passed
  1777.  *          the argument "ON", else svga.exe will be passed the
  1778.  *          arguement "ON DEFAULT". If the svga.exe is successfully
  1779.  *          started up in another session then, a separate thread will
  1780.  *          be started up,which will monitor the  process id that is
  1781.  *          passed to it.
  1782.  *
  1783.  *  Returns:
  1784.  *          Non - zero  - The system error number that occurred.
  1785.  *          0 - No Error occurred
  1786. \****************************************************************/
  1787. VOID RunSvga(PVOID pvMessageData)
  1788. {
  1789.     APIRET    apiRet = 0;
  1790.     ULONG     rc,ulSession,ulProcessId, ulBootDrive;
  1791.     CHAR      szArgs[CCHMAXPATH];
  1792.     CHAR      szFullProg[CCHMAXPATH];
  1793.     PSZ       pszSvgaTmpBatFile = SVGATMP_BAT;
  1794.     PSZ       pszCommandCom = "C:\\OS2\\MDOS\\COMMAND.COM";
  1795.     static PSZ  pszConfigSys = szConfigSys;
  1796.     static PSZ  pszAutoExecName = szAutoExecName;
  1797.     static PSZ  pszConfigDsp = szConfigDsp;
  1798.     static PSZ  pszAutoExecDsp = szAutoExecDsp;
  1799.     STARTDATA StartData;
  1800.     FILESTATUS fsts;
  1801.     static   PSVGAWAITDATA pWaitData;
  1802.     HQUEUE         hqueue;
  1803.     REQUESTDATA    requestData;
  1804.     ULONG          ulData;
  1805.     PSESSIONRESULT psesres;
  1806.     BYTE           bElemPrty;
  1807.     CHAR           szError[CCHMAXPATH];
  1808.  
  1809.     pWaitData = (PSVGAWAITDATA)pvMessageData;
  1810.  
  1811.     memset(szArgs,0,sizeof(szArgs) );
  1812.     memset(szFullProg,0,sizeof(szFullProg) );
  1813.     memset(&StartData,0,sizeof(StartData) );
  1814.  
  1815.     /*
  1816.      *make sure the program can be found, first search the
  1817.      *os2\mdos directory, if not found,  search the path.
  1818.      */
  1819.  
  1820.     DosQuerySysInfo(QSV_BOOT_DRIVE,
  1821.                     QSV_BOOT_DRIVE,
  1822.                     &ulBootDrive,
  1823.                     sizeof(ulBootDrive));
  1824.  
  1825.     *pszCommandCom = (CHAR)(ulBootDrive + 'A' - 1);
  1826.  
  1827.     if( apiRet = DosQueryPathInfo( pszCommandCom,
  1828.                                    1,
  1829.                                    &fsts, sizeof(fsts)))
  1830.     {
  1831.           apiRet = DosSearchPath(SEARCH_ENVIRONMENT,
  1832.                                 "PATH",
  1833.                                  COMMAND_COM,
  1834.                                  szFullProg,
  1835.                                  CCHMAXPATH);
  1836.     }
  1837.     else
  1838.       strcpy( szFullProg, pszCommandCom );
  1839.  
  1840.  
  1841.     if(!apiRet)
  1842.     {
  1843.  
  1844.          *pszSvgaTmpBatFile = (CHAR)(ulBootDrive + 'A' - 1);
  1845.  
  1846.          if( fSvgaUtilPresent ) {
  1847.  
  1848.              /* Before executing command.com, if svga utility present then
  1849.                   copy save config.sys and autoexec.bat to *.dsp )  */
  1850.  
  1851.              *pszConfigSys      = (CHAR)(ulBootDrive + 'A' - 1);
  1852.              *pszAutoExecName   = (CHAR)(ulBootDrive + 'A' - 1);
  1853.              *pszAutoExecDsp    = (CHAR)(ulBootDrive + 'A' - 1);
  1854.              *pszConfigDsp      = (CHAR)(ulBootDrive + 'A' - 1);
  1855.  
  1856.              DosCopy( pszConfigSys, pszConfigDsp, DCPY_EXISTING );
  1857.              DosCopy( pszAutoExecName, pszAutoExecDsp, DCPY_EXISTING );
  1858.  
  1859.          }
  1860.          strcpy( szArgs, "/C ");
  1861.          strcat( szArgs, pszSvgaTmpBatFile );
  1862.  
  1863.          StartData.Length = sizeof(StartData);
  1864.          StartData.Related   = SSF_RELATED_CHILD;
  1865.          StartData.FgBg      = SSF_FGBG_FORE;
  1866.          StartData.TraceOpt  = SSF_TRACEOPT_NONE;
  1867.          StartData.PgmTitle  = COMMAND_COM;
  1868.          StartData.PgmName   = szFullProg;
  1869.          StartData.PgmInputs = szArgs;
  1870.          StartData.TermQ     = "\\queues\\svgainst.que";
  1871.          StartData.Environment = NULL;
  1872.          StartData.InheritOpt = 0;
  1873.          StartData.SessionType = SSF_TYPE_VDM;
  1874.          StartData.PgmHandle  =  0;
  1875.  
  1876.          if(!(apiRet = DosCreateQueue(&hqueue,
  1877.                                      QUE_FIFO,
  1878.                                      "\\queues\\svgainst.que")))
  1879.          {
  1880.              apiRet  = DosStartSession(&StartData,
  1881.                                (PULONG)&pWaitData->ulSession,
  1882.                                (PPID)&pWaitData->ulProcessid);
  1883.  
  1884.              if( apiRet == 0 || apiRet == ERROR_SMG_START_IN_BACKGROUND)
  1885.              {
  1886.                 /* initialize data */
  1887.                 apiRet = 0;
  1888.                 requestData.ulData = -1;
  1889.                 requestData.pid    = pWaitData->ulSession;
  1890.  
  1891.                 while(!DosReadQueue( hqueue,
  1892.                                       &requestData,
  1893.                                       &ulData,
  1894.                                       (PPVOID)&psesres,
  1895.                                       0,
  1896.                                       DCWW_WAIT,
  1897.                                       &bElemPrty,
  1898.                                       NULL) &&
  1899.                                       requestData.ulData);
  1900.  
  1901.                 if(psesres->usResultCode)
  1902.                 {
  1903.                    apiRet = psesres->usResultCode;
  1904.                    sprintf(szError, "SVGA.EXE error:rc=%ld", apiRet);
  1905.                    svgaLog(szError);
  1906.  
  1907.                 }
  1908.  
  1909.              }
  1910.              else
  1911.              {
  1912.                 sprintf(szError, "DosStartSession error:rc=%ld",apiRet);
  1913.                 svgaLog(szError);
  1914.              }
  1915.  
  1916.              DosCloseQueue(hqueue);
  1917.          }
  1918.  
  1919.     }
  1920.     if( fSvgaUtilPresent )
  1921.     {
  1922.          DosCopy( pszConfigDsp, pszConfigSys, DCPY_EXISTING );
  1923.          DosCopy( pszAutoExecDsp, pszAutoExecName, DCPY_EXISTING);
  1924.          DosDelete( pszAutoExecDsp );
  1925.          DosDelete( pszConfigDsp );
  1926.     }
  1927.  
  1928.  
  1929.     (apiRet ? WinPostMsg(pWaitData->hwnd, AM_QUIT,(MPARAM)TRUE, 0)
  1930.         :     WinPostMsg(pWaitData->hwnd, AM_QUIT,(MPARAM)FALSE, 0));
  1931.  
  1932.  
  1933.     DosExit(EXIT_THREAD,0);
  1934.  
  1935. }
  1936.  
  1937. /****************************************************************\
  1938.  *
  1939.  *--------------------------------------------------------------
  1940.  *
  1941.  *  Name:strip_white
  1942.  *
  1943.  *  Purpose:strip leading blank character from a string.
  1944.  *
  1945.  *  Returns:
  1946.  *        Pointer to the first non-blank character in the string
  1947.  *        that is passed.
  1948. \****************************************************************/
  1949. PSZ strip_white(PSZ pszString)
  1950. {
  1951.      while(*pszString == ' ')
  1952.      {
  1953.           pszString++;
  1954.      }
  1955.      return(pszString);
  1956. }
  1957. /****************************************************************\
  1958.  *
  1959.  *--------------------------------------------------------------
  1960.  *
  1961.  *  Name:ValidateResolutions
  1962.  *
  1963.  *  Purpose:If we are not using the default supported resolutions
  1964.  *          or if we are using only the supported resolutions and
  1965.  *          they are correctly validated,the resolutions that are
  1966.  *          contained in the pDspChain will be saved in the
  1967.  *          pResolutionToDisplay Stucture. It is expected that the
  1968.  *          pResolutions stucture is large enough to hold all of the
  1969.  *          supported resolutions.
  1970.  *
  1971.  *
  1972.  *          pResolutions          - pointer to the list of supported resolutions
  1973.  *          pResolutionsToDisplay - pointer to the resolutions data structure
  1974.  *                                  where the resolutions from the dsc file
  1975.  *                                  are saved to.
  1976.  *          pInstalData           - pointer to the linked list of resolutions
  1977.  *                                  that was passed to us by the
  1978.  *                                  display install utility.
  1979.  *          fUseDefault           - flag to indicate whether to use the only
  1980.  *                                  default resolutions or not.
  1981.  *          pulCount              - The number of resolutions that were
  1982.  *                                  stored in the pResolutionsToDisplay
  1983.  *                                  structure.
  1984.  *          ulCount               - The number of supported resolutios
  1985.  *                                  in the pResolutions structure.
  1986.  *  Returns:
  1987.  *          FALSE  - Currently always returns FALSE.
  1988.  *          TRUE   - if error
  1989. \****************************************************************/
  1990. BOOL ValidateResolutions(PRESOLUTIONS     pResolutions,
  1991.                          PRESOLUTIONS     pResolutionsToDisplay,
  1992.                          PDSPINSTL_CHAIN  pInstalData,
  1993.                          BOOL fUseDefault,
  1994.                          PULONG pulCount,
  1995.                          ULONG ulCount,
  1996.                          PFN pfnGetNext)
  1997.  
  1998. {
  1999.  
  2000.      PDSPINSTL_CHAIN pDspChain;
  2001.  
  2002. /* Amol; Defect #58319; 12/09/92 */
  2003.      f1024K                         /* Check if SVGA card has more than    */
  2004.      = CheckSVGAMem                 /* 512K memory                         */
  2005.          (pResolutions, ulCount);
  2006.  
  2007.      *pulCount = 0;
  2008.      for(pDspChain = pInstalData;pDspChain;
  2009.                               pDspChain = pDspChain->pNextDspInstl)
  2010.      {
  2011.           /*
  2012.            *if we've got a resolution
  2013.            */
  2014.           if(pDspChain->pszResolution)
  2015.           {
  2016.                /*
  2017.                 *if we are not using the default include
  2018.                 *it  ||
  2019.                 *if we are using the default compare it
  2020.                 *against the resolutions the adapter card
  2021.                 *supports for this machine
  2022.                 */
  2023.                if(!fUseDefault  || CompareResolutions(pDspChain->pszResolution,
  2024.                                                   pResolutions,ulCount) )
  2025.                {
  2026.                     /*
  2027.                      *save off the resolutions that are supported
  2028.                      */
  2029.                      strcpy(pResolutionsToDisplay->achResolutionString,
  2030.                               pDspChain->pszResolution);
  2031.                      (*pulCount)++;
  2032.                      pResolutionsToDisplay++;
  2033.                }
  2034.           }
  2035.      }
  2036.      return(FALSE);
  2037. }
  2038. /****************************************************************\
  2039.  *
  2040.  *--------------------------------------------------------------
  2041.  *
  2042.  *  Name:SelectResolutionForUser
  2043.  *
  2044.  *  Purpose:To select the chain element that matches the resolution
  2045.  *          passed on the command using the /RES: parameter from
  2046.  *          DSPINSTL
  2047.  *
  2048.  *  Returns:
  2049.  *          TRUE  -   Selected Supported Resolution
  2050.  *          FALSE -   Not a supported Resolution
  2051. \****************************************************************/
  2052. BOOL SelectResolutionForUser( PDSPINSTL_CHAIN pInstalData,
  2053.                               PRESOLUTIONS pResolutionsToDisplay,
  2054.                               PULONG pulCount )
  2055. {
  2056.  
  2057.      PDSPINSTL_CHAIN pDspChain;
  2058.      RESOLUTIONDATA  resolutionParm;
  2059.      RESOLUTIONDATA  resolutionChain;
  2060.      BOOL    fSupported = FALSE;
  2061.  
  2062.      /*
  2063.       * Convert the resolution parameter passed
  2064.       */
  2065.  
  2066.      StringToResolution(pszResolutionString, &resolutionParm);
  2067.  
  2068.      for(pDspChain = pInstalData;pDspChain;
  2069.                                 pDspChain = pDspChain->pNextDspInstl)
  2070.      {
  2071.           /*
  2072.            *if we've got a resolution
  2073.            */
  2074.           if(pDspChain->pszResolution)
  2075.           {
  2076.              /*
  2077.               * Convert the resolution string from the DSC file
  2078.               */
  2079.  
  2080.              StringToResolution(pDspChain->pszResolution, &resolutionChain);
  2081.  
  2082.              /*
  2083.               * Compare the DSC resolution to the resolution
  2084.               * parameter passed on the command line
  2085.               */
  2086.  
  2087.              if((resolutionParm.Horiz == resolutionChain.Horiz) &&
  2088.                   (resolutionParm.Vert == resolutionChain.Vert) &&
  2089.                      (resolutionParm.Colors == resolutionChain.Colors))
  2090.              {
  2091.                  strcpy( pResolutionsToDisplay->achResolutionString,
  2092.                                   pDspChain->pszResolution );
  2093.  
  2094.                  pResolutionsToDisplay->ulSelected = TRUE;
  2095.                  *pulCount = 1;
  2096.                  fSupported = TRUE;
  2097.                  break;
  2098.  
  2099.              }
  2100.  
  2101.           }
  2102.  
  2103.      }
  2104.  
  2105.      return( fSupported );
  2106. }
  2107.  
  2108.  
  2109. /****************************************************************\
  2110.  *
  2111.  *--------------------------------------------------------------
  2112.  *
  2113.  *  Name:CompareResolutions
  2114.  *
  2115.  *  Purpose:To determine if the string pszResolution is contained in
  2116.  *          the list of supported resolutions (pSupportedResolutions).
  2117.  *          This routine will parse through ulResolutionCount number of
  2118.  *          items in the pSupportedResolutions strucuture that is passed.
  2119.  *  Returns:
  2120.  *          TRUE  -   Supported Resolution
  2121.  *          FALSE -   Not supported Resolution
  2122. \****************************************************************/
  2123. BOOL CompareResolutions(PSZ pszResolution,PRESOLUTIONS pSupportedResolutions,
  2124.                            ULONG ulResolutionCount)
  2125. {
  2126.     BOOL fSupported = FALSE;
  2127.     PRESOLUTIONS pTemp;
  2128.     ULONG ulCounter = 0;
  2129.     RESOLUTIONDATA  DscResolution,SupportedResolution;
  2130.  
  2131.  
  2132.     memset(&DscResolution,0,sizeof(RESOLUTIONDATA) );
  2133.     StringToResolution(pszResolution,&DscResolution);
  2134.     for(pTemp = pSupportedResolutions;ulCounter < ulResolutionCount;
  2135.                                    ulCounter++,
  2136.                                    pTemp++)
  2137.     {
  2138.                /*
  2139.                 *convert each one to resolution format
  2140.                 */
  2141.                memset(&SupportedResolution,0,sizeof(SupportedResolution) );
  2142.                StringToResolution(pTemp->achResolutionString,&SupportedResolution);
  2143.  
  2144.                /*
  2145.                 *does  the string match any of
  2146.                 *our  resoutions
  2147.                 */
  2148.  
  2149. /* Amol; Defect #58319; 12/09/1992  */
  2150.                /*
  2151.                 *if the video board has less than one meg of vram
  2152.                 *then filter out any drivers that need one meg
  2153.                 */
  2154.  
  2155.                if (!f1024K &&
  2156.                    IsResolutionOver1Mg (pszResolution, &DscResolution))
  2157.  
  2158.                   break;
  2159.  
  2160.               if(DscResolution.Horiz == SupportedResolution.Horiz)
  2161.               {
  2162.                     if(DscResolution.Vert == SupportedResolution.Vert)
  2163.                     {
  2164.                          if(DscResolution.Colors == SupportedResolution.Colors)
  2165.                          {
  2166.                               fSupported = TRUE;
  2167.                               break;
  2168.                          }
  2169.                     }
  2170.                }
  2171.     }
  2172.     return(fSupported);
  2173. }
  2174. /****************************************************************\
  2175.  *
  2176.  *--------------------------------------------------------------
  2177.  *
  2178.  *  Name:StringToResolution
  2179.  *
  2180.  *  Purpose: Convert a resolution in string format to
  2181.  *           it's corresponding parts and put them into
  2182.  *           the resolution data structure.
  2183.  *  Returns:
  2184.  *
  2185.  *          VOID - there is no error return.
  2186. \****************************************************************/
  2187. VOID StringToResolution(PSZ pszString,PRESOLUTIONDATA pResolutionData)
  2188. {
  2189.      PSZ pszTokens = "0123456789",pszNextToken;
  2190.      SHORT sPass;
  2191.  
  2192.  
  2193.      for(sPass = 0,pszNextToken = pszString; sPass < RESOLUTION_NUM; sPass++)
  2194.      {
  2195.           pszNextToken = strpbrk(pszNextToken,pszTokens);
  2196.           if(pszNextToken)
  2197.           {
  2198.                switch(sPass)
  2199.                {
  2200.                case 0:
  2201.                     pResolutionData->Horiz  = atoi(pszNextToken);
  2202.                     break;
  2203.                case 1:
  2204.                     pResolutionData->Vert = atoi(pszNextToken);
  2205.                     break;
  2206.                case 2:
  2207.                     pResolutionData->Colors = atoi(pszNextToken);
  2208.                     break;
  2209.                }
  2210.                pszNextToken = (pszNextToken + strspn(pszNextToken,pszTokens) );
  2211.           }
  2212.      }
  2213.      return;
  2214. }
  2215. //////////////////////////////////////////////////////////////////
  2216. //
  2217. //  Name: SvgaReportError
  2218. //
  2219. //  Purpose: Display error message.
  2220. //
  2221. //  Usage: Called when a fatal error occurrs while installing a
  2222. //         device driver.
  2223. //
  2224. //  Method: - Display message box with error message.
  2225. //          - Log error to logfile.
  2226. //
  2227. //  Returns:
  2228. //
  2229. //////////////////////////////////////////////////////////////////
  2230.  
  2231. VOID SvgaReportError(ULONG rc,PSZ pszMsg,HWND hwndOwner)
  2232. {
  2233. //@TM    PSZ  pszErrorTitle = "Svga Installation Error";
  2234.     HAB  hab;
  2235.     CHAR szMsg[CCHMAXPATH];
  2236.     CHAR szErrorTitle[CCHMAXPATH];
  2237.  
  2238.  
  2239.     WinAlarm(HWND_DESKTOP, WA_ERROR);
  2240.     hab = WinInitialize(0);
  2241.  
  2242. //@TM    if (!pszMsg)
  2243. //@TM    {
  2244. //@TM        pszMsg = szErrorMsg[rc];
  2245. //@TM    }
  2246.  
  2247.     WinLoadString(hab, hmodResource, rc, CCHMAXPATH,
  2248.            szMsg);
  2249.  
  2250.  
  2251.     WinLoadString(hab, hmodResource, MSG_SVGA_ERROR_TITLE, CCHMAXPATH,
  2252.            szErrorTitle);
  2253.  
  2254.     WinMessageBox(HWND_DESKTOP,
  2255.                   hwndOwner,
  2256.                   szMsg,
  2257.                   szErrorTitle,
  2258.                   MBX_INSTERROR,
  2259.                   MB_OK | MB_ERROR | MB_MOVEABLE | MB_SYSTEMMODAL);
  2260.  
  2261.  
  2262.  
  2263.     /*
  2264.      *log the error
  2265.      */
  2266.      svgaLog(szMsg);
  2267.  
  2268.      WinTerminate( hab );
  2269.  
  2270. } /* SvgaReportError() */
  2271.  
  2272. //////////////////////////////////////////////////////////////////
  2273. //
  2274. //  Name: CenterDialog
  2275. //
  2276. //  Purpose: Center a dialog box on the main window.
  2277. //
  2278. //  Usage: Called during the WM_INITDLG of all dialog window
  2279. //         procedures.
  2280. //
  2281. //  Method:
  2282. //
  2283. //  Returns:
  2284. //        VOID
  2285. //////////////////////////////////////////////////////////////////
  2286. VOID CenterDialog(HWND hwnd)
  2287. {
  2288.   SWP    swpDlgPos;                      /* structure for position of dialog */
  2289.   SWP    swpFramePos;                     /* structure for position of frame */
  2290.   POINTL ptlDesktop;                          /* height and width of desktop */
  2291.  
  2292.   /* get gesktop size */
  2293.   ptlDesktop.x = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  2294.   ptlDesktop.y = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  2295.  
  2296.   /* get dialog position */
  2297.   WinQueryWindowPos(hwnd, &swpDlgPos);
  2298.  
  2299.   if (WinIsWindowVisible(hwnd) &&      /* center everything but logo and */
  2300.       (hwnd != hwnd))                  /* and main frame on hwndMain     */
  2301.   {
  2302.     /* get frame position */
  2303.     WinQueryWindowPos(hwnd, &swpFramePos);
  2304.  
  2305.     /* center the dialog vertically on frame */
  2306.     swpDlgPos.y = (SHORT)((swpFramePos.cy / 2) - (swpDlgPos.cy / 2) + swpFramePos.y);
  2307.  
  2308.     /* center the dialog horizontally on frame */
  2309.     swpDlgPos.x = (SHORT)((swpFramePos.cx /2) - (swpDlgPos.cx /2) + swpFramePos.x);
  2310.   }
  2311.   else
  2312.   {
  2313.     /* center the dialog vertically on the desktop */
  2314.     swpDlgPos.y = (SHORT)((ptlDesktop.y / 2) - (LONG)(swpDlgPos.cy / 2));
  2315.  
  2316.     /* center the dialog horizontally on the desktop */
  2317.     swpDlgPos.x = (SHORT)((ptlDesktop.x /2) - (LONG)(swpDlgPos.cx /2));
  2318.   }
  2319.  
  2320.   /* be sure the dialog didn't go off the left edge of the screen */
  2321.   if (swpDlgPos.x < 0)
  2322.     swpDlgPos.x = 0;
  2323.  
  2324.   /* be sure the dialog didn't go off the bottom edge of the screen */
  2325.   if (swpDlgPos.y < 0)
  2326.     swpDlgPos.y = 0;
  2327.  
  2328.   /* be sure the dialog didn't go off the right edge of the screen */
  2329.   if (((LONG)swpDlgPos.x + (LONG)swpDlgPos.cx) > ptlDesktop.x)
  2330.     swpDlgPos.x = (SHORT)(ptlDesktop.x - (LONG)swpDlgPos.cx);
  2331.  
  2332.   /* be sure the dialog didn't go off the top edge of the screen */
  2333.   if (((LONG)swpDlgPos.y + (LONG)swpDlgPos.cy) > ptlDesktop.y)
  2334.     swpDlgPos.y = (SHORT)(ptlDesktop.y - (LONG)swpDlgPos.cy);
  2335.  
  2336.   /* reposition the dialog and make it visible. */
  2337.   WinSetWindowPos(hwnd,
  2338.                   HWND_TOP,
  2339.                   swpDlgPos.x,
  2340.                   swpDlgPos.y,
  2341.                   0, 0,
  2342.                   SWP_ACTIVATE | SWP_MOVE | SWP_ZORDER | SWP_SHOW);
  2343.  
  2344. } /* CenterDialog() */
  2345.  
  2346. /****************************************************************\
  2347.  *
  2348.  *--------------------------------------------------------------
  2349.  *
  2350.  *  Name:GetDllHandle
  2351.  *
  2352.  *  Purpose: Get a module resource handle to the svga.dll.
  2353.  *
  2354.  *
  2355.  *
  2356.  *  Usage:Pass a  pointer to a  resource handle to the routine. If
  2357.  *        error,the system error number is returned,else 0 is
  2358.  *        returned.
  2359.  *  Returns:
  2360.  *          apiRet - System Error number
  2361.  *          0 - if no error
  2362. \****************************************************************/
  2363. APIRET APIENTRY GetDllHandle( PHMODULE phmodResource)
  2364. {
  2365.      APIRET apiRet;
  2366.      CHAR szFailName[CCHMAXPATH];
  2367.      PSZ  pszModuleName = SVGA_MODULE;
  2368.      PSZ  pszModuleTemp = SVGA_MODULE;
  2369.      ULONG  ulDrive;
  2370.      CHAR szPath[CCHMAXPATH];
  2371.      PSZ  pchCur,pszTemp;
  2372.      ULONG ulSize;
  2373.  
  2374.      DosError(HARDERROR_DISABLE);
  2375.  
  2376.  
  2377.      memset(szFailName,0,sizeof(szFailName) );
  2378.      /*
  2379.       *try to load in from the dpath
  2380.       */
  2381.      if( pszTemp = strchr(pszModuleTemp,'.') )
  2382.      {
  2383.           *pszTemp = 0;
  2384.      }
  2385.      if(apiRet  = DosLoadModule(szFailName, 0,pszModuleTemp, phmodResource) )
  2386.      {
  2387.           /*
  2388.            *if not go out to the drives
  2389.            */
  2390.           for(ulDrive= 1; ulDrive <= MAXDRIVES;ulDrive++ )
  2391.           {
  2392.                /*
  2393.                 *build the paths for each drive,
  2394.                 *where oh,where might you be tonight
  2395.                 */
  2396.                memset(szPath,0,sizeof(szPath) );
  2397.                ulSize = sizeof(szPath) - 3;
  2398.                DosQueryCurrentDir(ulDrive,&szPath[3],&ulSize);
  2399.  
  2400.                szPath[0] = 'A' + ulDrive - 1;
  2401.                szPath[1] = ':';
  2402.                szPath[2] = '\\';
  2403.                if( (szPath[strlen(szPath)-1]) != '\\')
  2404.                {
  2405.                     strcat(szPath,"\\");
  2406.                }
  2407.                strcat(szPath,pszModuleName);
  2408.                /*
  2409.                 *try to load off this drive
  2410.                 */
  2411.                apiRet  = DosLoadModule(szFailName, sizeof(szFailName),
  2412.                                        szPath, phmodResource);
  2413.  
  2414.                if(!apiRet)
  2415.                {
  2416.                    /*
  2417.                     *we loaded,time to boogey out
  2418.                     */
  2419.                    break;
  2420.                }
  2421.           }
  2422.      }
  2423.      DosError(HARDERROR_ENABLE);
  2424.  
  2425.      return(apiRet);
  2426. }
  2427. /****************************************************************\
  2428.  *
  2429.  *--------------------------------------------------------------
  2430.  *
  2431.  *  Name: svgaLog
  2432.  *
  2433.  *  Purpose:   Generic logging routine for svga installation
  2434.  *             error. Note: this should be changed so that the
  2435.  *             display install utility can pass through a funciton
  2436.  *             pointer to it's own logging function.NOTE>>>>>>
  2437.  *
  2438.  *
  2439.  *
  2440.  *  Usage:
  2441.  *
  2442.  *  Method:
  2443.  *          -
  2444.  *
  2445.  *          -
  2446.  *          -
  2447.  *
  2448.  *          -
  2449.  *          -
  2450.  *
  2451.  *  Returns:
  2452.  *
  2453.  *          VOID
  2454. \****************************************************************/
  2455. VOID svgaLog(PSZ pszMsg)
  2456. {
  2457.      CHAR szDateTime [SIZ_DATE_TIME];
  2458.      CHAR *pszNull;
  2459.  
  2460.  
  2461.      memset(szDateTime,' ',sizeof(szDateTime) );
  2462.      _strdate(szDateTime);
  2463.      /*
  2464.       *get rid of the null and keep the date,time
  2465.       *on the same line in the log file
  2466.       */
  2467.      if( (pszNull = strchr(szDateTime,'\0') ) )
  2468.      {
  2469.           *pszNull = ' ';
  2470.      }
  2471.      _strtime( &szDateTime[SIZ_DATE_TIME /2]);
  2472.  
  2473.      if(pfnLogFunction)
  2474.      {
  2475.           (*pfnLogFunction)(szDateTime);
  2476.           (*pfnLogFunction)(pszMsg);
  2477.      }
  2478. }
  2479.  
  2480. //////////////////////////////////////////////////////////////////
  2481. //
  2482. //  Name: SvgaReportError
  2483. //
  2484. //  Purpose: Display error message.
  2485. //
  2486. //  Usage: Called when a fatal error occurrs while installing a
  2487. //         device driver.
  2488. //
  2489. //  Method: - Display message box with error message.
  2490. //          - Log error to logfile.
  2491. //
  2492. //  Returns:
  2493. //
  2494. //////////////////////////////////////////////////////////////////
  2495. USHORT SvgaMessageBox(ULONG rc,PSZ pszMsg,HWND hwndOwner)
  2496. {
  2497. //@TM    PSZ  pszErrorTitle = "Svga Installation Message";
  2498.     HAB  hab;
  2499.     USHORT usRc;
  2500.     CHAR szMsg[CCHMAXPATH];
  2501.     CHAR szErrorTitle[CCHMAXPATH];
  2502.  
  2503.  
  2504.     WinAlarm(HWND_DESKTOP, WA_ERROR);
  2505.     hab = WinInitialize(0);
  2506.  
  2507. //@TM    if (!pszMsg)
  2508. //@TM    {
  2509. //@TM        pszMsg = szErrorMsg[rc];
  2510. //@TM    }
  2511.  
  2512.     WinLoadString(hab, hmodResource, MSG_SVGA_INSTALL, CCHMAXPATH,
  2513.            szErrorTitle);
  2514.     WinLoadString(hab, hmodResource, rc, CCHMAXPATH,
  2515.            szMsg);
  2516.  
  2517.     usRc = WinMessageBox(HWND_DESKTOP,
  2518.                   hwndOwner,
  2519.                   szMsg,
  2520.                   szErrorTitle,
  2521.                   MBX_INSTERROR,
  2522.                   MB_YESNO | MB_ERROR | MB_MOVEABLE |
  2523.                   MB_DEFBUTTON2 | MB_SYSTEMMODAL);
  2524.  
  2525.      WinTerminate( hab );
  2526.      return(usRc);
  2527. }
  2528.  
  2529. /****************************************************************\
  2530.  *
  2531.  *--------------------------------------------------------------
  2532.  *
  2533.  *  Name:GetSelectedResolution
  2534.  *
  2535.  *  Purpose: This routine will loop through the  list of pSelectedResolutions
  2536.  *           for up to ulCount number of elements looking for the ulSelected
  2537.  *           flag to be set to TRUE. A pointer to the first ulSelected
  2538.  *           element will be returned or NULL if no selection was made.
  2539.  *  Returns:
  2540.  *          pszResolutions  = a pointer to the selected resolutions string
  2541.  *                            or NULL if none was selected.
  2542. \****************************************************************/
  2543. PSZ GetDesignatedResolution(PDSPINSTL_CHAIN pChain,
  2544.                             ULONG ulCount,
  2545.                             LONG lOffSetToGet)
  2546. {
  2547.  
  2548.      ULONG ulCounter;
  2549.      PSZ pszResolutions = NULL;
  2550.      PDSPINSTL_CHAIN  pTemp;
  2551.  
  2552.  
  2553.      for(ulCounter =0,pTemp = pChain; pTemp;
  2554.                               pTemp = pTemp->pNextDspInstl,ulCounter++)
  2555.      {
  2556.  
  2557.           if(pTemp->pszResolution)
  2558.           {
  2559.                pszResolutions= pTemp->pszResolution;
  2560.                break;
  2561.           }
  2562.      }
  2563.      return(pszResolutions);
  2564. }
  2565.  
  2566. /***************************************************************************/
  2567.  
  2568.  
  2569.                                                 /* Amol; D58319; 12/09/92  */
  2570. BOOL CheckSVGAMem (PRESOLUTIONS pResolutions, ULONG ulResolutionCount)
  2571. /*-------------------------------------------------------------------------*\
  2572.  *
  2573.  * This is a routine to check if 1024x768 resolution has been specified for
  2574.  * this SVGA card. If it has been, then the routine returns TRUE else returns
  2575.  * FALSE. If the 1024x768 resolution is indeed supported, then it means that
  2576.  * the card has at least 1 MB memory on it.
  2577.  *
  2578. \*-------------------------------------------------------------------------*/
  2579. {
  2580.    ULONG          ulCounter   =  0;
  2581.    RESOLUTIONDATA resData;
  2582.  
  2583.    for (; ulCounter < ulResolutionCount; ulCounter++)
  2584.    {
  2585.       StringToResolution               /* Convert string to resolution     */
  2586.          ((pResolutions + ulCounter)->achResolutionString, &resData);
  2587.  
  2588.       if ((resData.Horiz >= 1024)   && /* Does this support 1024x768x256 ? */
  2589.           (resData.Vert  >= 768)    &&
  2590.           (resData.Colors >= 256))
  2591.                                        /* Yes, it does support the above ! */
  2592.          return TRUE;                  /* Done - return TRUE status        */
  2593.    }
  2594.  
  2595.    return FALSE;                       /* Done - return FALSE status       */
  2596.  
  2597. } /* CheckSVGAMem */
  2598.  
  2599. /***************************************************************************/
  2600.  
  2601.  
  2602.                                                 /* Amol; D58319; 12/11/92  */
  2603. BOOL IsResolutionOver1Mg (PSZ pszResolution,PRESOLUTIONDATA  pResolutions)
  2604. /*-------------------------------------------------------------------------*\
  2605.  *
  2606.  * This is a routine to check if pszResolution specifies a driver requiring
  2607.  * 1 MB or more.
  2608.  *
  2609.  * The routine returns TRUE if the driver requires 1 MB or more else returns
  2610.  * FALSE.
  2611.  *
  2612. \*-------------------------------------------------------------------------*/
  2613. {
  2614.    PSZ  pszResCopy = strdup (pszResolution);
  2615.  
  2616.    strupr (pszResCopy);
  2617.  
  2618.    if ((pResolutions->Horiz  >= 1024)  && /* Check for 1024x768x256 mode   */
  2619.        (pResolutions->Vert   >=  768)  &&
  2620.        (pResolutions->Colors >=  256))
  2621.                                        /* This means more than 1 MB VRAM   */
  2622.       return TRUE;                     /* Done - return TRUE status        */
  2623.  
  2624.    if (strstr (pszResCopy, "1.0")   && /* Check if 1.0 MB was specified    */
  2625.        (strstr (pszResCopy, "MG")   ||
  2626.         strstr (pszResCopy, "MB")))
  2627.                                        /* 1.0 MB was NOT specified         */
  2628.       return TRUE;                     /* Done - return TRUE status        */
  2629.  
  2630.    return FALSE;                       /* Done - return FALSE status       */
  2631.  
  2632. }  /* IsResolutionOver1Mg */
  2633.  
  2634.  
  2635. //////////////////////////////////////////////////////////////////
  2636. //
  2637. //  Name: InitHelp
  2638. //
  2639. //  Purpose: Initializes the IPF help facility.
  2640. //
  2641. //  Usage: Called once during initialization of the program.
  2642. //
  2643. //  Method: Initializes the HELPINIT structure and creates the
  2644. //          help instance.
  2645. //
  2646. //  Returns:
  2647. //
  2648. //////////////////////////////////////////////////////////////////
  2649.  
  2650. VOID InitHelp(HWND *phwndHelpInstance)
  2651. {
  2652.   HELPINIT hmInitStruct;
  2653.   CHAR     szMsg[CCHMAXPATH];
  2654.   CHAR     szErrorTitle[CCHMAXPATH];
  2655.   CHAR     szMainTitle[CCHMAXPATH];
  2656.   PSZ      pszHelpFile = "C:\\OS2\\HELP\\DSPINSTL.HLP";
  2657.   static   HAB      hab;
  2658.   ULONG    ulBootDrive;
  2659.  
  2660.  
  2661. #ifndef RESPONSE_FILE
  2662.  
  2663.  
  2664.   hab = WinInitialize( 0 );
  2665.   WinLoadString(hab, hmodResource, MSG_MAINHELPTITLE, CCHMAXPATH,
  2666.          szMainTitle);
  2667.  
  2668.   DosQuerySysInfo(QSV_BOOT_DRIVE,
  2669.                   QSV_BOOT_DRIVE,
  2670.                   &ulBootDrive,
  2671.                   sizeof(ulBootDrive));
  2672.  
  2673.   *pszHelpFile = (CHAR)(ulBootDrive + 'A' - 1);
  2674.  
  2675.   /* inititalize help init structure */
  2676.   hmInitStruct.cb = sizeof(HELPINIT);
  2677.   hmInitStruct.ulReturnCode = 0;
  2678.   hmInitStruct.pszTutorialName = (PSZ)NULL;
  2679.   hmInitStruct.phtHelpTable = (PHELPTABLE)(0xffff0000 | MAIN_HELP_TABLE);
  2680.   hmInitStruct.hmodHelpTableModule = 0;
  2681.   hmInitStruct.hmodAccelActionBarModule = 0;
  2682.   hmInitStruct.idAccelTable = 0;
  2683.   hmInitStruct.idActionBar = 0;
  2684.   hmInitStruct.pszHelpWindowTitle = szMainTitle;
  2685.   hmInitStruct.fShowPanelId = (ULONG)CMIC_HIDE_PANEL_ID;
  2686.   hmInitStruct.pszHelpLibraryName = pszHelpFile;
  2687.  
  2688.   /* creating help instance */
  2689.   *phwndHelpInstance = WinCreateHelpInstance(hab, &hmInitStruct);
  2690.  
  2691.   if (!*phwndHelpInstance || hmInitStruct.ulReturnCode)
  2692.   {
  2693.         WinLoadString(hab, hmodResource, MSG_APPTITLE, CCHMAXPATH,
  2694.                szErrorTitle);
  2695.  
  2696.         WinLoadString(hab, hmodResource, MSG_HELPNOTAVAIL, CCHMAXPATH,
  2697.                szMsg);
  2698.  
  2699.         WinMessageBox(HWND_DESKTOP,
  2700.                       HWND_DESKTOP,
  2701.                       szMsg,
  2702.                       szErrorTitle,
  2703.                       0,
  2704.                       MB_OK | MB_INFORMATION | MB_MOVEABLE);
  2705.  
  2706.         if (*phwndHelpInstance)
  2707.         {
  2708.             WinDestroyHelpInstance(hwndHelpInstance);
  2709.         }
  2710.    }
  2711. #endif
  2712. } /* InitHelp() */
  2713.  
  2714. /**************************************************************************/
  2715.  
  2716.