home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / w3_syst / setup.arj / DIALOGS.C < prev    next >
Encoding:
Text File  |  1991-06-25  |  36.4 KB  |  1,118 lines

  1. // DIALOGS.C - The code for the dialog boxes
  2.  
  3. /*****************************************************************************
  4.  
  5. CenterDialog          Centers a dialog box on the screen and changes
  6.                       the caption to relfect the "PACKAGENAME" field
  7.                       if the .INF file.
  8.  
  9. ReallyCancel          Displays a YES/NO MessageBox asking the user
  10.                       if they *really* want to cancel the app. If the
  11.                       user replies NO, then the focus of the message
  12.                       box is put on the IDOK button of the calling
  13.                       dialog.
  14.  
  15. StartUpDlgProc        This displays a dialog box saying "Reading .INF
  16.                       File...", and it kills itself when done. The
  17.                       timer code is to allow the message queue to clear
  18.                       and paint the dialog box. Also, it ensures the
  19.                       dialog box lives for at least 1/2 second, so the
  20.                       human can read it.
  21.  
  22. FixupDirectory        Checks the given filename to be sure that at least
  23.                       a drive letter has been indicated, and removes
  24.                       a trailing backslah character if there is one.
  25.  
  26. InstallDirDlgProc     Displays a dialog box that asks the user which
  27.                       directory to install the apps in.  Once user
  28.                       clicks IDOK button, the app tries to create the
  29.                       directory, and any child directories from the
  30.                       .INF file.  If there was a failure, the dialog
  31.                       warns the user and lets them try again. Calls
  32.                       the DosMakeDir function.
  33.          
  34. IndexGivenIndex       This routine converts a virtual (listbox position
  35.                       index) into a physical index for the FileInfo
  36.                       data structure.  Essentially, it searches the
  37.                       FileInfo structure for the first occurence of
  38.                       the Index field matching the given index. When
  39.                       this index is found, the physical array index
  40.                       of this FileInfo record is given.
  41.  
  42. AddItem               Sets or Resets the bSelected field in the FileInfo
  43.                       structure, given the virtual index, and it adds
  44.                       or deletes the item from the listbox. If the item's
  45.                       flags indicate that extra invisble files must also
  46.                       be selected or deseleted, then this routine will
  47.                       catch them also.
  48.  
  49. InPreviousSelection   Since the Multiselect listbox does not provide a
  50.                       way to determine the "current" selection, a few
  51.                       routines, like this one, must be used to figure
  52.                       the "lone star" item that was most recently
  53.                       selected.  The theory is: Keep a data strcuture
  54.                       that knows al the items selected.  When a new item
  55.                       is selected, check all the items selected versus
  56.                       the data strcuture, which should contain the previous
  57.                       state.  One item in the data structure should be
  58.                       different, this is the "lone star". This particular
  59.                       routine tells you if an index is in an array.
  60.       
  61. SelectDlgProc         This dialog allows the user to select or unselect
  62.                       file groups for installation.  This dialog is
  63.                       brought up only if the bSelected field of ANY
  64.                       FileInfo element is FALSE (which means the .INF
  65.                       file flags were not ALL "R").
  66.  
  67. InsertDiskDlgProc     If there is any type of file copying error,
  68.                       such as a sharing violation, copy error, file
  69.                       not found, ect, this dialog box asks the user
  70.                       to insert the install disk in the drive indicated
  71.                       in an edit control.  Due to a problem with Kernel,
  72.                       it is not possible to tell the user which type of
  73.                       erorr occured, only that *an* erorr occurred.
  74.  
  75. CreateSourceDir       Given a source directory reference number, this
  76.                       routine builds a null-terminated string that
  77.                       contains the fully qualified directory name, along
  78.                       with the subdirectory on the installation disk.
  79.  
  80. CreateSourceDisk      Same as CreateSourceDir, except the subdirectory
  81.                       on the installation disk is not included. This
  82.                       is displayed in the InsertDiskDlgProc's eit control.
  83.  
  84. ChangeSourceDir       If the user indicates a new installation disk, this
  85.                       routine changes the DiskInfo data structure so
  86.                       the program doesn't prompt the user for every file
  87.                       on the disk.
  88.  
  89. CreateDestDir         Given a destinataion directory reference number,
  90.                       this routine builds a null-terminated string that
  91.                       contains the fully qualified directory name, along
  92.                       with any child directories indicated in the
  93.                       [directories] section of the .INF file.
  94.  
  95. FileCopyDlgProc       This dialog displays the status of the file copying
  96.                       process, with the gas gauge.  If there is a file
  97.                       copying error, the InsetDiskDlgProc is called.
  98.  
  99. GetNextFileNumber     This routine finds the nect application that needs
  100.                       to be installed in the Program Manager.  If the
  101.                       app is to be installed in a new group, then the
  102.                       group is created.
  103.  
  104. IconCopyDlgProc       This dialog displays the status of the icon adding
  105.                       process, with the gas gauge. The user can cancel
  106.                       this process (foolishly, of course).
  107.  
  108. *****************************************************************************/
  109.  
  110. #include "windows.h"
  111.  
  112. #include <dos.h>
  113.  
  114. #include "bincode.h"
  115. #include "bincode1.h"
  116. #include "gasgauge.h"
  117.  
  118. char  szNewDisk[65];
  119. char  szNewDiskName[65];
  120.  
  121. extern LONG  FAR PASCAL ResetController ( void );
  122.  
  123. /********************************************************************/
  124. void CenterDialog ( HWND hDlg )
  125. {
  126.   RECT rc;
  127.  
  128.   GetWindowRect(hDlg,&rc);
  129.   SetWindowPos(hDlg,NULL,
  130.         (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
  131.         (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 3,
  132.          0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  133.  
  134.   SetWindowText ( hDlg, (LPSTR)szCaptionName );
  135. }
  136. /********************************************************************/
  137. void CenterDialogAtBottom ( HWND hDlg )
  138. {
  139.   RECT rc;
  140.  
  141.   GetWindowRect(hDlg,&rc);
  142.   SetWindowPos(hDlg,NULL,
  143.         (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
  144.         (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)),
  145.          0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
  146.  
  147.   SetWindowText ( hDlg, (LPSTR)szCaptionName );
  148. }
  149. /********************************************************************/
  150. BOOL ReallyCancel ( HWND hDlg )
  151. {
  152.   BOOL retval;
  153.  
  154.   retval =  (IDYES == MessageBox ( hDlg,
  155.                                    "Do you Really Want to exit Setup?",
  156.                                    "Setup",
  157.                                    MB_ICONQUESTION | MB_YESNO ));
  158.   if (!retval) SetFocus ( GetDlgItem ( hDlg, IDOK ));
  159.   return retval;
  160. }
  161. /********************************************************************/
  162. DLGPROC StartUpDlgProc ( DIALOG_PARAMS )
  163. {
  164.   switch (msg)
  165.     {
  166.     case WM_INITDIALOG:
  167.  
  168.       FillGlobalInfoStructures  ( );  // Need this for caption title...
  169.       CenterDialog ( hDlg );
  170.       SetTimer ( hDlg, 1, 500, NULL );
  171.       return FALSE;
  172.  
  173.     case WM_TIMER:
  174.  
  175.       KillTimer ( hDlg, 1 );
  176.  
  177.       FillDiskInfoStructures ();    // Get [disk]        info read in
  178.       FillFileInfoStructures ();    // Get [apps]        info read in
  179.       FillDirInfoStructures  ();    // Get [directories] info read in
  180.       FillProgmanInfoStructures (); // Get [progman]     info read in
  181.  
  182.       PostMessage ( hDlg, WM_COMMAND, IDCANCEL, 0L );
  183.       break;
  184.  
  185.     case WM_COMMAND:
  186.  
  187.       if (wParam == IDCANCEL)
  188.         EndDialog (hDlg, TRUE);
  189.       break;
  190.  
  191.     default:
  192.  
  193.       return FALSE;
  194.  
  195.     } // end switch
  196.  
  197.   return TRUE;
  198. }
  199. /********************************************************************/
  200. BOOL FixupDirectory ( char* DirName )
  201. {
  202.   int Len = lstrlen ( (LPSTR)DirName );
  203.  
  204.   if ( '\\' == DirName[Len-1] )
  205.     DirName[Len-1] = 0;           // whack off the backslash
  206.  
  207.   if (Len < 4) return FALSE;      // Gotta have at least a drive and a directory!
  208.  
  209.   if (
  210.       (!isalpha(DirName[0])) ||   // Make sure the drive letter
  211.       (DirName[1] != ':') ||      // colon
  212.       (DirName[2] != '\\')        // backslash is there
  213.      ) return FALSE;
  214.  
  215.   return TRUE;                    // Looks semi-okay, let's let
  216.                                   // DOS take it from here...
  217. }
  218. /********************************************************************/
  219. DLGPROC InstallDirDlgProc ( DIALOG_PARAMS )
  220. {
  221.   char  ChildDir[64];
  222.   int   i;
  223.   BOOL  Sucess;
  224.  
  225.   switch (msg)
  226.     {
  227.     case WM_INITDIALOG:
  228.  
  229.       CenterDialog ( hDlg );
  230.       SetDlgItemText ( hDlg, IDD_EDIT, (LPSTR)DirInfo[0].szDirectory );
  231.       SetDlgItemText ( hDlg, IDD_APPNAME, (LPSTR)szPackageName );
  232.       SetFocus ( GetDlgItem ( hDlg, IDD_EDIT ));
  233.       SendDlgItemMessage ( hDlg, IDD_EDIT, EM_LIMITTEXT, 53, 0L);
  234.       SendDlgItemMessage ( hDlg, IDD_EDIT, EM_SETSEL, 0, MAKELONG (0,32767));
  235.       return FALSE;
  236.  
  237.     case WM_COMMAND:
  238.  
  239.       switch (wParam)
  240.         {
  241.         case IDCANCEL:
  242.  
  243.           if (ReallyCancel( hDlg )) 
  244.             EndDialog ( hDlg, FALSE );
  245.           break;
  246.  
  247.         case IDOK:
  248.  
  249.           GetDlgItemText ( hDlg, IDD_EDIT, (LPSTR)DirInfo[0].szDirectory, 63 );
  250.           if (FixupDirectory(DirInfo[0].szDirectory))
  251.             {
  252.             if (DosMakeDir((LPSTR)DirInfo[0].szDirectory))  // If parent dir possible
  253.               {
  254.               Sucess = TRUE;
  255.               for ( i = 1; ((i < NumDirs) && (Sucess)); i++ )  // make the children if any
  256.                 {
  257.                 sprintf ( ChildDir, "%s%s", DirInfo[0].szDirectory, DirInfo[i].szDirectory );
  258.                 Sucess = DosMakeDir((LPSTR)ChildDir);
  259.                 }
  260.               if (Sucess) 
  261.                 EndDialog ( hDlg, TRUE );
  262.               else
  263.                 {
  264.                 MessageBox ( hDlg, "Setup is unable to create the sub-directory. "
  265.                                    "Please choose a different directory, or check "
  266.                                    "your hard disk and run Setup again.", 
  267.                                    "Setup", MB_OK | MB_ICONHAND );
  268.                 SetFocus ( GetDlgItem ( hDlg, IDD_EDIT ));
  269.                 }
  270.               }
  271.             else
  272.               {
  273.               MessageBox ( hDlg, "Setup was unable to create the directory.  Please "
  274.                                  "enter another directory, or check your hard disk "
  275.                                  "and run Setup again.", 
  276.                                  "Setup", MB_OK | MB_ICONHAND );
  277.               SetFocus ( GetDlgItem ( hDlg, IDD_EDIT ));
  278.               }
  279.             }
  280.           else
  281.             {
  282.             MessageBox ( hDlg, "Please enter a valid directory name, with drive "
  283.                                "letter and full path.  For example:  C:\WEP",
  284.                                "Setup", MB_OK | MB_ICONHAND );
  285.             SetFocus ( GetDlgItem ( hDlg, IDD_EDIT ));
  286.             }
  287.           break;
  288.    
  289.         default:
  290.  
  291.           return FALSE;
  292.         }
  293.       break;
  294.  
  295.     default:
  296.  
  297.       return FALSE;
  298.  
  299.     } // end switch
  300.  
  301.   return TRUE;
  302. }
  303.  
  304. #ifdef SIMPLESETUP
  305.  
  306.  
  307. // In the simple setup, this routine will NEVER get called, this is only
  308. // here so we dont have the unresolved export in the .DEF file.
  309.  
  310. DLGPROC SelectDlgProc( DIALOG_PARAMS )
  311. {
  312.   return FALSE;
  313. }
  314.  
  315. #endif
  316.  
  317. #ifdef COMPLEXSETUP
  318.  
  319. /*****************************************************************************/
  320. int IndexGivenIndex ( int Index )
  321. {
  322.   int i;
  323.  
  324.   for ( i = 0 ; i < NumFiles; i++ )
  325.     if (FileInfo[i].Index == Index) return i;
  326.   return 0;
  327. }
  328. /*****************************************************************************/
  329. void AddItem ( HWND hSourceListBox, HWND hDestListBox, 
  330.                int Index, BOOL bRemove )
  331. {
  332.   char szString[80], i;
  333.   int  NumToBackTrack, StartingSpot;
  334.  
  335.   if (Index == LB_ERR )
  336.     {
  337.     MessageBeep (0);
  338.     return;
  339.     }
  340.  
  341.   if (bRemove)
  342.     {
  343.     SendMessage (hDestListBox, LB_GETTEXT, Index, (LONG)(LPSTR)szString );
  344.     // Locate the string in the source listbox
  345.     Index = SendMessage ( hSourceListBox, LB_FINDSTRING, -1, (LONG)(LPSTR)szString );
  346.  
  347.     StartingSpot = IndexGivenIndex(Index);
  348.     for ( i = StartingSpot; 
  349.           i <= StartingSpot+FileInfo[StartingSpot].ExtraFiles; 
  350.           i++)
  351.       FileInfo[i].bSelected = FALSE;
  352.     
  353.     // Delete the string
  354.     Index = SendMessage ( hDestListBox, LB_FINDSTRING, -1, (LONG)(LPSTR)szString );
  355.     if (Index != LB_ERR)
  356.       SendMessage (hDestListBox, LB_DELETESTRING, Index, 0L );
  357.     else
  358.       MessageBeep (0);
  359.     return;
  360.     }
  361.   else
  362.     {
  363.     SendMessage (hSourceListBox, LB_GETTEXT, Index, (LONG)(LPSTR)szString );
  364.     StartingSpot = IndexGivenIndex(Index);
  365.     if (!FileInfo[StartingSpot].bSelected)
  366.       SendMessage (hDestListBox, LB_ADDSTRING, Index, (LONG)(LPSTR)szString );
  367.     for ( i = StartingSpot; i <= StartingSpot+FileInfo[StartingSpot].ExtraFiles; i++)
  368.       {
  369.       FileInfo[i].bSelected = TRUE;
  370.       }
  371.     }
  372. }
  373. /*****************************************************************************/
  374. //
  375. // Returns TRUE if SourceSelections[i] is also in PreviousSelections
  376.  
  377.  
  378. BOOL InPreviousSelection(int *SourceSelections, int *PreviousSourceSelections, 
  379.                          int i, int SizePreviousSource )
  380. {
  381.   int j;
  382.  
  383.   for ( j = 0; j < SizePreviousSource; j++ )
  384.     if (PreviousSourceSelections[j] == SourceSelections[i]) return TRUE;
  385.  
  386.   return FALSE;
  387. }
  388. /******************************************************************************\
  389. *
  390. *      Select Files Dialog
  391. *                                                                              |
  392. \******************************************************************************/
  393. DLGPROC SelectDlgProc( DIALOG_PARAMS )
  394. {
  395.   static int     i, j, index, LastToAdd, viscount, counter;
  396.   static HWND    hSourceList, hDestList, hDescriptionBox;
  397.          HBRUSH  hGrayBrush;
  398.   static LONG    SumTotal, TotalBytes, AvailableBytes;
  399.          char    szStatus[80];
  400.          char    szString[80];
  401.          int     tabs[2];
  402.  
  403.   static int     NumSourceSelections;
  404.   static int     SourceSelections[MAXFILES];
  405.  
  406.   static int     PreviousNumSourceSelections;
  407.   static int     PreviousSourceSelections[MAXFILES];
  408.  
  409.   static int     NumDestSelections;
  410.   static int     DestSelections[MAXFILES];
  411.  
  412.          int     Selections[MAXFILES];
  413.          
  414.   switch (msg)
  415.     {
  416.     case WM_INITDIALOG:
  417.  
  418.        CenterDialog ( hDlg );
  419.  
  420.        hSourceList      = GetDlgItem ( hDlg, IDD_LISTSELECT    );
  421.        hDestList        = GetDlgItem ( hDlg, IDD_LISTINSTALLED );
  422.        hDescriptionBox  = GetDlgItem ( hDlg, IDD_COMMENT       );
  423.  
  424.        tabs[0] = 60;   // Tab stop
  425.        tabs[1] = 65;   // Tab stop
  426.  
  427.        SendMessage ( hSourceList,   LB_SETTABSTOPS, 2, (LONG)(LPSTR)tabs);
  428.        SendMessage ( hDestList,     LB_SETTABSTOPS, 2, (LONG)(LPSTR)tabs);
  429.  
  430.        viscount = 0;
  431.        counter = 0;
  432.  
  433.        for ( i = 0; i < NumFiles; i++ )
  434.          if (!FileInfo[i].bInvisible) viscount++;
  435.  
  436.        SendMessage ( hSourceList, WM_SETREDRAW, FALSE, 0L );
  437.  
  438.        for ( i = 0; i < NumFiles; i++ )
  439.          if (!FileInfo[i].bInvisible)
  440.            {
  441.            if ( counter == (viscount-1))
  442.              SendMessage ( hSourceList, WM_SETREDRAW, TRUE, 0L );
  443.            sprintf ( szString, "%s\t%ldK", FileInfo[i].szDescription, FileInfo[i].BytesRequired/1024L ); 
  444.            SendMessage ( hSourceList, LB_ADDSTRING, 0, (LONG)(LPSTR)szString );
  445.            counter++;
  446.            }
  447.  
  448.        SetFocus ( GetDlgItem ( hDlg, IDCANCEL ));
  449.        return FALSE;
  450.  
  451.     case WM_COMMAND:
  452.  
  453.       switch (wParam)
  454.         {
  455.         case IDCANCEL:
  456.  
  457.           if (ReallyCancel( hDlg )) 
  458.             EndDialog ( hDlg, FALSE );
  459.           break;
  460.  
  461.         case IDOK:
  462.  
  463.           EndDialog (hDlg, TRUE);
  464.           break;
  465.  
  466.         case IDD_LISTSELECT:   // Look for notify messages here...
  467.  
  468.           // Clear the other listbox's selections if any...
  469.  
  470.           if (NumDestSelections = SendMessage ( hDestList,   LB_GETSELITEMS, 
  471.                                                 MAXFILES, (LONG)(LPSTR)DestSelections   ))
  472.             {
  473.             SendMessage ( hDestList,   LB_SETSEL, 0, (LONG)-1 );
  474.             InvalidateRect ( hDestList,   NULL, TRUE );
  475.             NumDestSelections = 0;
  476.             }
  477.  
  478.           switch (HIWORD (lParam))
  479.             {
  480.             case LBN_SELCHANGE:
  481.  
  482.               // Save the previous state
  483.  
  484.               PreviousNumSourceSelections = NumSourceSelections;
  485.               for ( i = 0; i < PreviousNumSourceSelections; i++)
  486.                 PreviousSourceSelections[i] = SourceSelections[i];                
  487.         
  488.               // Get the current state
  489.     
  490.               NumSourceSelections = SendMessage ( hSourceList, LB_GETSELITEMS, 
  491.                                                   MAXFILES, (LONG)(LPSTR)SourceSelections );
  492.  
  493.               // Now, let's figure out which one is the "new" selection...
  494.  
  495.               index = -1;
  496.  
  497.               // First, check to see if the user just selected one...
  498.  
  499.               for ( i = 0; (i < NumSourceSelections) && (index == -1); i++)
  500.                 if (!InPreviousSelection(SourceSelections,PreviousSourceSelections,
  501.                                          i,PreviousNumSourceSelections))
  502.                   index = SourceSelections[i];
  503.  
  504.               // If the user just de-selected one, then we look inversely
  505.  
  506.               if ( -1 == index )
  507.                 for ( i = 0; (i < PreviousNumSourceSelections) && (index == -1); i++)
  508.                   if (!InPreviousSelection(PreviousSourceSelections,SourceSelections,
  509.                                            i,NumSourceSelections))
  510.                     index = PreviousSourceSelections[i];
  511.  
  512.               // If index still is -1, then no selection changes were made,
  513.               // and we cant do squat. So we wont update comment.
  514.                
  515.               if (-1 != index)
  516.                 {
  517.                 // Fill in the comment window
  518.                 SetDlgItemText ( hDlg, IDD_COMMENT, FileInfo[IndexGivenIndex(index)].szComment );
  519.                 }
  520.  
  521.               break;
  522.            
  523.             default: 
  524.  
  525.               return FALSE;
  526.  
  527.             } // switch (HIWORD...
  528.  
  529.           break;
  530.  
  531.         case IDD_LISTINSTALLED:
  532.  
  533.           // If the user is clicking on the remove listbox, clear the comment
  534.           // box to avoid confusing their brain cells, if anything was selected.
  535.  
  536.           if (NumSourceSelections = SendMessage ( hSourceList, LB_GETSELITEMS, 
  537.                                                   MAXFILES, (LONG)(LPSTR)SourceSelections ))
  538.             {
  539.             SendMessage ( hSourceList, LB_SETSEL, 0, (LONG)-1 );
  540.             InvalidateRect ( hSourceList, NULL, TRUE );
  541.             SetDlgItemText ( hDlg, IDD_COMMENT, (LPSTR)"" );
  542.             NumSourceSelections = 0;
  543.             }
  544.           break;
  545.  
  546.         case IDD_ADD:
  547.  
  548.           // Update the listbox current selection tallies
  549.   
  550.           NumSourceSelections = SendMessage ( hSourceList, LB_GETSELITEMS, 
  551.                                               MAXFILES, (LONG)(LPSTR)SourceSelections );
  552.           NumDestSelections   = SendMessage ( hDestList,   LB_GETSELITEMS, 
  553.                                               MAXFILES, (LONG)(LPSTR)DestSelections   );
  554.  
  555.           for ( i = 0; i < NumSourceSelections; i++ )
  556.             if (!FileInfo[IndexGivenIndex(SourceSelections[i])].bSelected)
  557.               AddItem ( hSourceList, hDestList, SourceSelections[i], FALSE );
  558.  
  559.           SendMessage ( hSourceList, LB_SETSEL, 0, (LONG)-1 );
  560.           SendMessage ( hDestList,   LB_SETSEL, 0, (LONG)-1 );
  561.  
  562.           // These next two lines are to fix a bug in the MS Listbox
  563.  
  564.           InvalidateRect ( hSourceList, NULL, TRUE );
  565.           InvalidateRect ( hDestList,   NULL, TRUE );
  566.  
  567.           SetDlgItemText ( hDlg, IDD_COMMENT, (LPSTR)"" );
  568.           PostMessage( hDlg, WM_COMMAND, IDM_SHOWSTATUS, 0L );
  569.           break;
  570.  
  571.         case IDD_DELETE:
  572.  
  573.           // Update the listbox current selection tallies
  574.   
  575.           NumSourceSelections = SendMessage ( hSourceList, LB_GETSELITEMS, 
  576.                                               MAXFILES, (LONG)(LPSTR)SourceSelections );
  577.           NumDestSelections   = SendMessage ( hDestList,   LB_GETSELITEMS, 
  578.                                               MAXFILES, (LONG)(LPSTR)DestSelections   );
  579.  
  580.           // We have to do this backwards in order to delete the right ones...
  581.  
  582.           for ( i = NumDestSelections-1; i >= 0 ; i-- )
  583.             AddItem ( hSourceList, hDestList, DestSelections[i], TRUE );
  584.  
  585.           SendMessage ( hSourceList, LB_SETSEL, 0, (LONG)-1 );
  586.           SendMessage ( hDestList,   LB_SETSEL, 0, (LONG)-1 );
  587.  
  588.           // These next two lines are to fix a bug in the MS Listbox
  589.  
  590.           InvalidateRect ( hSourceList, NULL, TRUE );
  591.           InvalidateRect ( hDestList,   NULL, TRUE );
  592.  
  593.           PostMessage( hDlg, WM_COMMAND, IDM_SHOWSTATUS, 0L );
  594.           break;
  595.  
  596.         case IDD_ADDALL:
  597.  
  598.           // Find out the last item that will actually be added
  599.  
  600.           LastToAdd = viscount - 1;
  601.           while (LastToAdd && FileInfo[IndexGivenIndex(LastToAdd)].bSelected) 
  602.             LastToAdd--;
  603.  
  604.           SendMessage ( hDestList, WM_SETREDRAW, FALSE, 0L );
  605.           for ( i = 0; i < viscount; i++)
  606.             {
  607.             if ( i == LastToAdd)
  608.               SendMessage ( hDestList, WM_SETREDRAW, TRUE, 0L );
  609.             if (!FileInfo[IndexGivenIndex(i)].bSelected)
  610.               AddItem ( hSourceList, hDestList, i, FALSE );
  611.             }
  612.           PostMessage( hDlg, WM_COMMAND, IDM_SHOWSTATUS, 0L );
  613.           break;
  614.  
  615.         case IDM_SHOWSTATUS:
  616.  
  617.           TotalBytes = 0;
  618.           SumTotal   = 0;
  619.           for ( i = 0; i < NumFiles; i++ )
  620.             {
  621.             if (FileInfo[i].bSelected)
  622.                TotalBytes += FileInfo[i].BytesRequired;
  623.             SumTotal += FileInfo[IndexGivenIndex(i)].BytesRequired;
  624.             }
  625.  
  626.           // Dont let them install nothing
  627.  
  628.           if (!TotalBytes)
  629.             EnableWindow ( GetDlgItem ( hDlg, IDOK ), FALSE );
  630.           else
  631.             EnableWindow ( GetDlgItem ( hDlg, IDOK ), TRUE );
  632.  
  633.           AvailableBytes = DosDiskFreeSpace ( DirInfo[0].szDirectory[0]-'@' );
  634.  
  635.           sprintf (szStatus, "Disk Space Needed: %ldK", TotalBytes/1024L);
  636.           SetDlgItemText ( hDlg, IDD_KSELECTED, szStatus );
  637.           sprintf (szStatus, "Available: %ldK", AvailableBytes/1024L);
  638.           SetDlgItemText ( hDlg, IDD_KFREE, szStatus );
  639.           sprintf (szStatus, "Remaining: %ldK", AvailableBytes/1024L-TotalBytes/1024L );
  640.           SetDlgItemText ( hDlg, IDD_KREMAINING, szStatus );
  641.           if (SumTotal > AvailableBytes )
  642.             EnableWindow ( GetDlgItem ( hDlg, IDD_ADDALL), FALSE );
  643.  
  644.           break;
  645.         }
  646.       return TRUE;
  647.  
  648.     default: return FALSE;
  649.     }
  650.   return TRUE;
  651. }
  652.  
  653. #endif
  654.  
  655. /********************************************************************/
  656. DLGPROC InsertDiskDlgProc ( DIALOG_PARAMS )
  657. {
  658.   switch (msg)
  659.     {
  660.     case WM_INITDIALOG:
  661.  
  662.       MessageBeep (0);
  663.       CenterDialog ( hDlg );
  664.       SetDlgItemText ( hDlg, IDD_EDIT, (LPSTR) szNewDisk );
  665.       SetDlgItemText ( hDlg, IDD_TEXT, (LPSTR) szNewDiskName );
  666.       SetFocus ( GetDlgItem ( hDlg, IDD_EDIT ));
  667.       SendDlgItemMessage ( hDlg, IDD_EDIT, EM_LIMITTEXT, 53, 0L);
  668.       SendDlgItemMessage ( hDlg, IDD_EDIT, EM_SETSEL, 0, MAKELONG (0,32767));
  669.       return FALSE;
  670.  
  671.     case WM_COMMAND:
  672.  
  673.       switch (wParam)
  674.         {
  675.         case IDCANCEL:
  676.  
  677.           if (ReallyCancel( hDlg )) EndDialog ( hDlg, FALSE );
  678.           break;
  679.  
  680.         case IDOK:
  681.  
  682.           GetDlgItemText ( hDlg, IDD_EDIT, (LPSTR) szNewDisk, 64 );
  683.           EndDialog ( hDlg, TRUE );
  684.           break;
  685.    
  686.         default:
  687.  
  688.           return FALSE;
  689.         }
  690.       break;
  691.  
  692.     default:
  693.  
  694.       return FALSE;
  695.  
  696.     } // end switch
  697.  
  698.   return TRUE;
  699. }
  700. /********************************************************************/
  701. LPSTR CreateSourceDir ( int ReferenceNumber )
  702. {
  703.   static char szDirectory[65];
  704.   int    i, Index;
  705.  
  706.   Index = -1;
  707.  
  708.   for ( i = 0; i < NumDisks; i++ )
  709.     if ( DiskInfo[i].DiskNumber == FileInfo[ReferenceNumber].DiskNumber )
  710.       Index = i;
  711.  
  712.   if ( -1 == Index ) 
  713.     {
  714.     MessageBox ( GetFocus (), "BAD INF FILE!", "Setup", MB_OK );
  715.     return (LPSTR)NULL;
  716.     }
  717.  
  718.   sprintf ( szDirectory, "%s%s", DiskInfo[Index].szSrcDir, 
  719.                                  FileInfo[ReferenceNumber].szMasterSrcDir );
  720.  
  721.   return (LPSTR) szDirectory;
  722. }
  723. /********************************************************************/
  724. LPSTR CreateSourceDisk ( int ReferenceNumber )
  725. {
  726.   static char szDirectory[65];
  727.   int    i, Index;
  728.  
  729.   Index = -1;
  730.  
  731.   for ( i = 0; i < NumDisks; i++ )
  732.     if ( DiskInfo[i].DiskNumber == FileInfo[ReferenceNumber].DiskNumber )
  733.       Index = i;
  734.  
  735.   if ( -1 == Index ) 
  736.     {
  737.     MessageBox ( GetFocus (), "BAD INF FILE!", "Setup", MB_OK );
  738.     return (LPSTR)NULL;
  739.     }
  740.  
  741.   sprintf ( szDirectory,   DiskInfo[Index].szSrcDir    );
  742.   sprintf ( szNewDiskName, DiskInfo[Index].szDiskTitle );
  743.  
  744.   return (LPSTR) szDirectory;
  745. }
  746. /********************************************************************/
  747. void ChangeSourceDir ( int ReferenceNumber )
  748. {
  749.   int    i, Index;
  750.  
  751.   Index = -1;
  752.  
  753.   for ( i = 0; i < NumDisks; i++ )
  754.     if ( DiskInfo[i].DiskNumber == FileInfo[ReferenceNumber].DiskNumber )
  755.       Index = i;
  756.  
  757.   if ( -1 == Index ) 
  758.     {
  759.     MessageBox ( GetFocus (), "BAD INF FILE!", "Setup", MB_OK );
  760.     return (LPSTR)NULL;
  761.     }
  762.  
  763.   i = strlen ( szNewDisk );       // Add a backslah if needed
  764.   if (i >= 1) 
  765.     if (szNewDisk[i-1] != '\\')
  766.       {
  767.       szNewDisk[i  ] = '\\';
  768.       szNewDisk[i+1] = 0;
  769.       }
  770.  
  771.   sprintf ( DiskInfo[Index].szSrcDir, szNewDisk );
  772. }
  773. /********************************************************************/
  774. LPSTR CreateDestDir ( int ReferenceNumber )
  775. {
  776.   static char szDirectory[65];
  777.   int    i, Index;
  778.  
  779.   if ('0' == FileInfo[ReferenceNumber].DirectoryNumber )
  780.     sprintf ( szDirectory, "%s", DirInfo[0].szDirectory);      // Parent only
  781.   else
  782.     {
  783.     Index = FileInfo[ReferenceNumber].DirectoryNumber - 'A'+1;
  784.     sprintf ( szDirectory, "%s%s", DirInfo[0].szDirectory,      // Parent
  785.                                    DirInfo[Index].szDirectory); // Child
  786.     }
  787.  
  788.   return (LPSTR) szDirectory;
  789. }
  790. /********************************************************************/
  791. DLGPROC FileCopyDlgProc ( DIALOG_PARAMS )
  792. {
  793.   static int   FileNumber, CopyNumber;
  794.   static HWND  hGauge;
  795.          int   i, FileCount;
  796.          char  szMsg[80];
  797.          BOOL  Success;
  798.          MSG   message;
  799.  
  800.  
  801.   switch (msg)
  802.     {
  803.     case WM_INITDIALOG:
  804.  
  805.       CenterDialog ( hDlg );
  806.  
  807.       hGauge = GetDlgItem ( hDlg, IDD_GASGAUGE );
  808.  
  809.       FileNumber = 0;
  810.       CopyNumber = 0;
  811.  
  812.       FileCount = 0;
  813.       for ( i = 0; i < NumFiles; i++ )
  814.         if (FileInfo[i].bSelected) FileCount++;
  815.  
  816.       PostMessage ( hGauge, WM_COMMAND, GG_SETRANGE, (LONG)FileCount);
  817.       PostMessage ( hGauge, WM_COMMAND, GG_SETVALUE, 0L );
  818.  
  819.       SetTimer ( hDlg, 1, 1500, NULL );
  820.       
  821.       return FALSE;
  822.  
  823.  
  824.     case WM_TIMER:
  825.  
  826.       KillTimer ( hDlg, 1 );
  827.       PostMessage ( hDlg, WM_COMMAND, IDM_COPYFILE, 0L );
  828.       break;
  829.  
  830.     case WM_COMMAND:
  831.  
  832.       switch (wParam)
  833.         {
  834.         case IDCANCEL:
  835.  
  836.           if (ReallyCancel( hDlg )) EndDialog ( hDlg, FALSE );
  837.           break;
  838.  
  839.         case IDOK:
  840.  
  841.           EndDialog ( hDlg, TRUE );
  842.           break;
  843.  
  844.         case IDM_COPYFILE:
  845.  
  846.           if (FileInfo[FileNumber].bSelected)
  847.             {
  848.             SetDlgItemText ( hDlg, IDD_FILEDESCRIPTION, (LPSTR)FileInfo[FileNumber].szDescription  );
  849.             SetDlgItemText ( hDlg, IDD_SOURCEDIR      , CreateSourceDir (FileNumber )       );
  850.             SetDlgItemText ( hDlg, IDD_DESTDIR        , CreateDestDir (FileNumber )         );
  851.             SetDlgItemText ( hDlg, IDD_FILENAME       , (LPSTR)FileInfo[FileNumber].szFileName     );
  852.  
  853.  
  854.             SetCursor ( LoadCursor ( NULL, IDC_WAIT ));
  855.             
  856.             Success = CopyFile ( CreateSourceDir (FileNumber ),
  857.                                  CreateDestDir (FileNumber ),
  858.                                  (LPSTR)FileInfo[FileNumber].szFileName,
  859.                                  FileInfo[FileNumber].bCompressed );
  860.  
  861.             if (Success)
  862.               {
  863.               CopyNumber++;
  864.               PostMessage ( hGauge, WM_COMMAND, GG_SETVALUE, (LONG)CopyNumber );
  865.  
  866.               // This will allow task switching while copying, and
  867.               // The gas gauge can update itself.
  868.  
  869.               while (PeekMessage (&message, hDlg, 0, 0, PM_REMOVE))
  870.                 {
  871.                 TranslateMessage(&message);
  872.                 DispatchMessage(&message);
  873.                 }
  874.               }
  875.             else  // Copy Error!
  876.               {
  877.               if (!CopyError)  // If file not found
  878.                 {
  879.                 //ResetController();
  880.                 sprintf ( szNewDisk, CreateSourceDisk (FileNumber ));
  881.  
  882.  
  883.                 // Before prompting user for a new disk, let's try the directory
  884.                 // that setup came from
  885.  
  886.                 if ( lstrcmp ((LPSTR)szNewDisk,(LPSTR)szCurrentInstallDir) )
  887.                   {
  888.                   lstrcpy ( (LPSTR)szNewDisk,(LPSTR)szCurrentInstallDir);
  889.                   ChangeSourceDir (FileNumber);
  890.                   FileNumber--;                         // Backup and try again
  891.                   }
  892.                 else
  893.                   {
  894.                   if (Success = DisplayDialogBox ( (LPSTR)"INSERTDISK", InsertDiskDlgProc ))
  895.                     {
  896.                     BringWindowToTop ( hDlg );            // Pretty things up
  897.                     ChangeSourceDir (FileNumber);
  898.                     FileNumber--;                         // Backup and try again
  899.                     }
  900.                   else
  901.                     {
  902.     
  903.                     // Since we are aborting, we must clear out all those
  904.                     // WM_COMMAND-COPY messages and etc. Otherwise
  905.                     // the user has to cancel a bunch of times.
  906.     
  907.                     while (PeekMessage (&message, hDlg, 0, 0, PM_REMOVE))
  908.                       {
  909.                       if (message.message != WM_COMMAND)
  910.                         {                       
  911.                         TranslateMessage(&message);
  912.                         DispatchMessage(&message);
  913.                         }
  914.                       }
  915.                     EndDialog ( hDlg, FALSE );
  916.                     FileNumber--;                         // Just to be sure
  917.                     return TRUE;
  918.                     }
  919.                   }
  920.                 }
  921.               else   // File copying error
  922.                 {
  923.                 MessageBox ( hDlg, "An error occurred while copying files to your hard disk. "
  924.                                    "Please correct the problem and run Setup again.",
  925.                                    "Setup", MB_OK | MB_ICONHAND );
  926.                 
  927.                 while (PeekMessage (&message, hDlg, 0, 0, PM_REMOVE))
  928.                   {
  929.                   if (message.message != WM_COMMAND)
  930.                     {                       
  931.                     TranslateMessage(&message);
  932.                     DispatchMessage(&message);
  933.                     }
  934.                   }
  935.                 EndDialog ( hDlg, FALSE );
  936.                 FileNumber--;                         // Just to be sure
  937.                 return TRUE;
  938.                 }
  939.               }
  940.               
  941.             }
  942.  
  943.           FileNumber++;
  944.  
  945.           if (FileNumber < NumFiles)
  946.             PostMessage ( hDlg, WM_COMMAND, IDM_COPYFILE, 0L );
  947.           else
  948.             PostMessage ( hDlg, WM_COMMAND, IDOK, 0L );
  949.           break;
  950.    
  951.         default:
  952.  
  953.           return FALSE;
  954.         }
  955.       break;
  956.  
  957.     default:
  958.  
  959.       return FALSE;
  960.  
  961.     } // end switch
  962.  
  963.   return TRUE;
  964. }
  965. /********************************************************************/
  966. void GetNextFileNumber ( int *FileNumber, int *GroupNumber )
  967. {
  968.   BOOL bNextGroup     = FALSE;
  969.   BOOL bFoundNextItem = FALSE;
  970.  
  971.   do
  972.     {
  973.     while ((!bFoundNextItem) && ((*FileNumber) < NumFiles))
  974.       {
  975.       if (
  976.           (FileInfo[*FileNumber].bProgmanIcon) &&
  977.           ((int)(FileInfo[*FileNumber].ProgmanGroupNumber-'A') == (*GroupNumber))
  978.          )
  979.         bFoundNextItem = TRUE;
  980.       else
  981.         (*FileNumber)++;
  982.       }
  983.  
  984.     if (bFoundNextItem) return;
  985.  
  986.     // If we reach this line, then we have to move to the next group,
  987.     // which means it is time to add a progman group...
  988.  
  989.     (*GroupNumber)++;
  990.     *FileNumber = 0;   // Start at begining of list again...
  991.   
  992.     ProgmanManageGroup ( (LPSTR)PManInfo[*GroupNumber].szCaption, 
  993.                          (LPSTR)PManInfo[*GroupNumber].szGroupFilename,
  994.                          TRUE );   // TRUE  = delete group first
  995.  
  996.     ProgmanManageGroup ( (LPSTR)PManInfo[*GroupNumber].szCaption, 
  997.                          (LPSTR)PManInfo[*GroupNumber].szGroupFilename,
  998.                          FALSE );  // FALSE = Add group, not delete
  999.     }
  1000.   while ((*GroupNumber) < NumPManGroups );
  1001.  
  1002. }
  1003. /********************************************************************/
  1004. DLGPROC IconCopyDlgProc ( DIALOG_PARAMS )
  1005. {
  1006.   static int   FileNumber, CopyNumber, GroupNumber;
  1007.   static HWND  hGauge;
  1008.   static int   i, FileCount;
  1009.          char  szMsg[80];
  1010.          BOOL  Success;
  1011.          MSG   message;
  1012.  
  1013.  
  1014.   switch (msg)
  1015.     {
  1016.     case WM_INITDIALOG:
  1017.  
  1018.       CenterDialogAtBottom ( hDlg );
  1019.  
  1020.       hGauge = GetDlgItem ( hDlg, IDD_GASGAUGE );
  1021.  
  1022.       FileNumber  = 0;
  1023.       CopyNumber  = 0;
  1024.       GroupNumber = -1;
  1025.  
  1026.       FileCount = 0;
  1027.  
  1028.       for ( i = 0; i < NumFiles; i++ )
  1029.         if (FileInfo[i].bProgmanIcon) FileCount++;
  1030.  
  1031.       PostMessage ( hGauge, WM_COMMAND, GG_SETRANGE, (LONG)FileCount);
  1032.       PostMessage ( hGauge, WM_COMMAND, GG_SETVALUE, 0L );
  1033.  
  1034.       SetTimer ( hDlg, 1, 1500, NULL );
  1035.       
  1036.       return FALSE;
  1037.  
  1038.  
  1039.     case WM_TIMER:
  1040.  
  1041.       KillTimer ( hDlg, 1 );
  1042.       PostMessage ( hDlg, WM_COMMAND, IDM_ADDICON, 0L );
  1043.       break;
  1044.  
  1045.     case WM_COMMAND:
  1046.  
  1047.       switch (wParam)
  1048.         {
  1049.         case IDCANCEL:
  1050.  
  1051.           if (ReallyCancel( hDlg )) 
  1052.             {
  1053.             ProgManClose ( );
  1054.             EndDialog ( hDlg, FALSE );
  1055.             }
  1056.           break;
  1057.  
  1058.         case IDOK:
  1059.  
  1060.           EndDialog ( hDlg, TRUE );
  1061.           break;
  1062.  
  1063.         case IDM_ADDICON:
  1064.  
  1065.           // Get next Icon to copy.  If new group, create the group
  1066.           GetNextFileNumber ( &FileNumber, &GroupNumber );
  1067.           BringWindowToTop ( hDlg );  // We want to see!!
  1068.  
  1069.           SetDlgItemText ( hDlg, IDD_FILEDESCRIPTION, (LPSTR)FileInfo[FileNumber].szDescription  );
  1070.  
  1071.           wsprintf ( (LPSTR)szMsg, 
  1072.                      "%s\\%s", 
  1073.                      CreateDestDir (FileNumber ),
  1074.                      (LPSTR)FileInfo[FileNumber].szFileName );
  1075.  
  1076.           SetCursor ( LoadCursor ( NULL, IDC_WAIT ));
  1077.  
  1078.           ProgmanAddItem ( FileInfo[FileNumber].szProgManName, szMsg );
  1079.           FileNumber++;
  1080.  
  1081.           CopyNumber++;
  1082.           PostMessage ( hGauge, WM_COMMAND, GG_SETVALUE, (LONG)CopyNumber );
  1083.  
  1084.           // This will allow task switching while adding, and
  1085.           // The gas gauge can update itself.
  1086.  
  1087.           while (PeekMessage (&message, hDlg, 0, 0, PM_REMOVE))
  1088.             {
  1089.             TranslateMessage(&message);
  1090.             DispatchMessage(&message);
  1091.             }
  1092.  
  1093.           if (CopyNumber < FileCount)
  1094.             PostMessage ( hDlg, WM_COMMAND, IDM_ADDICON, 0L );
  1095.           else
  1096.             {
  1097.             ProgManClose ( );
  1098.             PostMessage ( hDlg, WM_COMMAND, IDOK, 0L );
  1099.             }
  1100.           break;
  1101.    
  1102.         default:
  1103.  
  1104.           return FALSE;
  1105.         }
  1106.       break;
  1107.  
  1108.     default:
  1109.  
  1110.       return FALSE;
  1111.  
  1112.     } // end switch
  1113.  
  1114.   return TRUE;
  1115. }
  1116.  
  1117.  
  1118.