home *** CD-ROM | disk | FTP | other *** search
- // BINCODE.C
-
- /*****************************************************************************
-
- BINCODE.C - Generic Windows Setup program.
-
- This is the BINCODE.EXE program source.
- It will read the .INF file, and follow its format
- for copying files from floppy disk to the hard disk,
- and adding icons to the program manager.
-
- HISTORY: Created 08-08-90 Dave
- Fixed zillions of bugs 08/90 - 10/90
- Added Selva's Decompression 10/16/90
-
-
-
-
- Functions:
- ---------------------------------------------------------------------
-
- WinMain Main Program Entry Point
-
- CheckForEnoughDiskSpace This routine is called only if *all* of
- the files in the .INF file are tagged
- as "R" (required) in the flags. This
- routine checks to see if the destination
- disk has enough room to copy all of the
- files over.
-
- DisplayDialogBox Given the template name and the function
- name, displays a dialog box.
-
- WndProc The main window message filter. Even though
- this window is invisible, the code resides
- just to make the code clean and non-hackish.
-
- BackupProgmanIniFile Backs up the PROGMAN.INI file in case an
- obscure bug in progman trashes the ini file.
-
- *****************************************************************************/
-
- #include "windows.h"
-
- #define INMAIN
- #include "bincode.h"
- #undef INMAIN
-
- #include "gasgauge.h" // Code for the % gas gausge
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <dos.h>
-
- /********************* STATIC, GLOBAL VARIABLES ********************/
-
- extern int __argc; // # of Command line parameters
- extern char **__argv; // Command line parameter table
-
- /********************************************************************/
-
- int PASCAL WinMain( HANDLE hInstance, HANDLE hPrevInstance,
- LPSTR lpszCmdLine, int nCmdShow )
- {
- BOOL retval; // Return value. If FALSE, user aborted
- WNDCLASS wndclass ;
- MSG msg;
- BOOL realmode;
- HANDLE hCode;
- int i;
- BOOL UserDecides;
- char szMsg[255];
-
- // Look for magic word
-
- if (
- (__argv[1][0] != 'A') ||
- (__argv[1][1] != 'E') ||
- (__argv[1][2] != 'K') ||
- (__argv[1][3] != 'D') ||
- (__argv[1][4] != 'B')
- )
- {
- MessageBox ( GetFocus(), "Please run SETUP.EXE.", "Bincode",
- MB_OK | MB_ICONHAND );
- return FALSE;
- }
-
- lstrcpy ( (LPSTR)szCurrentInstallDir, (LPSTR)__argv[2] );
-
- if (hPrevInstance)
- {
- HWND hWnd;
-
- hWnd = FindWindow(szAppName, NULL);
- hWnd = GetLastActivePopup(hWnd);
- BringWindowToTop(hWnd);
- if (IsIconic(hWnd))
- ShowWindow(hWnd, SW_RESTORE);
- return FALSE;
- }
-
- SetErrorMode ( 1 ); // Blow off that stupid file I/O error box
-
- realmode = (!(GetWinFlags () & WF_PMODE )); // this is for the Dan bug
- if (realmode)
- {
- BackupProgmanIniFile (); // This is in case Program Pukes
- // due to an obscure bug
- hCode = GetCodeHandle ( (FARPROC)WndProc );
- GlobalFix ( hCode );
- }
-
- ghInst = hInstance; // Set the global variable
-
- if (!hPrevInstance)
- {
- wndclass.style = CS_HREDRAW | CS_VREDRAW ; // Redraw when resized
- wndclass.lpfnWndProc = WndProc ; // Messages go to WndProc
- wndclass.cbClsExtra = 0 ; // No extra info
- wndclass.cbWndExtra = 0 ; // No extra info
- wndclass.hInstance = hInstance ; // Set class for this instance
- wndclass.hIcon = LoadIcon (hInstance, szAppName) ;// Assign "Bincode" Icon from RC file
- wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ; // Use arrow cursor
- wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ; // White background
- wndclass.lpszMenuName = NULL ; // Use "Phone" menu from RC file
- wndclass.lpszClassName = szAppName ;
-
- if (!RegisterClass (&wndclass)) // Register the class
- return FALSE;
-
- if (!RegisterGasGauge ( hInstance )) // Register the Gas Guage class
- return FALSE;
-
- if (!ddeInit ( hInstance )) // Register and create DDE Window
- return FALSE;
- }
-
- ghWnd = CreateWindow (szAppName, "Setup", // Window Title, caption
- WS_OVERLAPPEDWINDOW, // Use normal window attributes
- 0, 0, 0, 0, // Invisible Window Coordinates
- NULL, // No parent
- NULL, // Use class menu
- hInstance, // This instance
- NULL) ; // No extra info
-
- if ((!ghWnd) || (!InitLZExpand(realmode)))
- {
- MessageBox ( NULL, "There is not enough memory to run Setup. "
- "Please quit one or more applications and "
- "run Setup again.",
- "Setup", MB_OK | MB_ICONHAND );
- retval = FALSE;
- } // Only continue if window was created
- else
- retval = TRUE;
-
- // Display the "Reading .INF file" box
- if (retval) retval = DisplayDialogBox ( (LPSTR)"STARTUPINFO", StartUpDlgProc );
-
- // Display the dialog box to allow user to select destination directory
- if (retval) retval = DisplayDialogBox ( (LPSTR)"INSTALLDIR", InstallDirDlgProc );
-
- // Display the dialog box to allow user to select files (if necessary)
- if (retval)
- {
- UserDecides = FALSE;
- for ( i = 0; i < NumFiles; i++ )
- if ( !FileInfo[i].bSelected ) // If there is an unselected file, then
- // we must let the user decide (bring up
- // Select files dialog box
- {
- UserDecides = TRUE;
- }
-
- if (UserDecides)
- #ifdef COMPLEXSETUP
- retval = DisplayDialogBox ( (LPSTR)"SELECTFILES", SelectDlgProc );
- #endif
- #ifdef SIMPLESETUP
- retval = CheckForEnoughDiskSpace ();
- #endif
- else
- retval = CheckForEnoughDiskSpace ();
- }
-
- // Display the "Copy Files...." dialog box, and copy the files
-
- SetCursor ( LoadCursor ( NULL, IDC_WAIT ));
-
- if (retval) retval = DisplayDialogBox ( (LPSTR)"FILECOPY", FileCopyDlgProc );
-
-
- GetPrivateProfileString ( "boot", "shell", "NONE", (LPSTR)szMsg, 128, "system.ini" );
- if (!lstrcmp ( (LPSTR)szMsg, (LPSTR)"progman.exe"))
- {
- // DIsplat the "Adding icons..." dialog box, and add the icons
- if (retval) retval = DisplayDialogBox ( (LPSTR)"ICONADD", IconCopyDlgProc );
- }
-
- SetCursor ( LoadCursor ( NULL, IDC_ARROW ));
-
- // Indicate sucess!
- if (retval)
- MessageBox ( ghWnd, "Installation Complete!", "Setup", MB_OK );
- else
- {
- wsprintf ( (LPSTR)szMsg, (LPSTR)"Setup has not completely installed %s. Please correct "
- "any problems and run Setup again.", (LPSTR)szPackageName );
- MessageBox ( GetFocus(), (LPSTR)szMsg, "Setup", MB_OK );
- }
-
- // Close the invisible parent window
- if (IsWindow(ghWnd))
- PostMessage ( ghWnd, WM_CLOSE, 0, 0L );
-
-
- // Message loop to keep things Petzoldian clean
- while (GetMessage(&msg,NULL,NULL,NULL))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
-
- // If the was copied to the temp dir from a floppy, then the
- // two parameters passed are the .EXE and .INF file to delete
-
- if (__argc > 3) // this means we have to commit suicide!
- {
- DosDelete (__argv[3]);
- DosDelete (__argv[4]);
- }
-
- // More on Dan bug
- if (realmode)
- {
- GlobalUnfix ( hCode );
- }
-
- DeInitLZExpand ( );
-
- return retval;
- }
- /********************************************************************/
- BOOL CheckForEnoughDiskSpace ( void)
- {
- LONG TotalRequired;
- LONG TotalNeeded;
- int i;
- char szMsg[255];
-
- TotalRequired = 0L;
-
- // Scan through .INF data strcutures to find out space requirements
- for ( i = 0; i < NumFiles; i++ )
- TotalRequired += FileInfo[i].BytesRequired;
-
- TotalNeeded = DosDiskFreeSpace ( DirInfo[0].szDirectory[0]-'@' );
-
- if (TotalRequired > TotalNeeded)
- {
- sprintf ( szMsg, "Setup needs %ldK of disk space to install %s. Please "
- "free enough disk space, or choose a different drive "
- "and/or directory.", TotalRequired/1024L, szPackageName );
-
- MessageBox ( ghWnd, (LPSTR)szMsg, (LPSTR)"Not Enough Disk Space", MB_OK | MB_ICONHAND );
- return FALSE;
- }
-
- return TRUE;
- }
- /********************************************************************/
- int DisplayDialogBox ( LPSTR TemplateName, FARPROC FunctionName )
- {
- FARPROC lpDialogProc;
- int RetVal;
-
- lpDialogProc = MakeProcInstance ( FunctionName, ghInst );
- RetVal = DialogBox ( ghInst, TemplateName, ghWnd, lpDialogProc );
- FreeProcInstance ( lpDialogProc );
- return RetVal;
- }
- /*******************************************************************/
- WINPROC WndProc ( WINDOWS_PARAMS )
- {
- switch (msg)
- {
- case WM_DESTROY:
-
- PostQuitMessage(0);
- break;
-
- default:
-
- return (DefWindowProc(hWnd, msg, wParam, lParam));
- }
-
- return 0L;
- }
- /*******************************************************************/
- //
- // Due to an obscure bug in Progman 3.00, if in real mode, there is
- // a possibility that the PROGMAN.INI file can get trashed when adding
- // a new group. We make a backup of it so of the crash happens, the
- // flame calling Product Support will get a kind voice saying
- // "Please copy your progman.bak to progman.ini".
- //
- //-------------------------------------------------------------------
- void BackupProgmanIniFile ( void )
- {
- char szCurDir[255];
- char szProgmanPath[255];
- char szProgmanBackupPath[255];
-
- GetWindowsDirectory ( (LPSTR)szCurDir, 254 );
- wsprintf ( (LPSTR)szProgmanPath, (LPSTR)"%s\\PROGMAN.INI", (LPSTR)szCurDir );
- wsprintf ( (LPSTR)szProgmanBackupPath, (LPSTR)"%s\\PROGMAN.BAK", (LPSTR)szCurDir );
- DosCopy ( (LPSTR)szProgmanPath, (LPSTR)szProgmanBackupPath );
- }
-
-
-
-