home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / win3 / programr / vbasic / setup1.exe / SETUP1.FRM (.txt) < prev   
Encoding:
Visual Basic Form  |  1993-07-09  |  15.0 KB  |  352 lines

  1. VERSION 2.00
  2. Begin Form Setup1 
  3.    BackColor       =   &H00400000&
  4.    Caption         =   "Test App Setup"
  5.    ClientHeight    =   2136
  6.    ClientLeft      =   1860
  7.    ClientTop       =   2616
  8.    ClientWidth     =   5640
  9.    ControlBox      =   0   'False
  10.    FillStyle       =   0  'Solid
  11.    FontBold        =   -1  'True
  12.    FontItalic      =   -1  'True
  13.    FontName        =   "MS Sans Serif"
  14.    FontSize        =   24
  15.    FontStrikethru  =   0   'False
  16.    FontUnderline   =   0   'False
  17.    ForeColor       =   &H00000000&
  18.    Height          =   2556
  19.    Icon            =   SETUP1.FRX:0000
  20.    Left            =   1812
  21.    LinkMode        =   1  'Source
  22.    LinkTopic       =   "Form3"
  23.    MaxButton       =   0   'False
  24.    MinButton       =   0   'False
  25.    ScaleHeight     =   178
  26.    ScaleMode       =   3  'Pixel
  27.    ScaleWidth      =   470
  28.    Top             =   2244
  29.    Width           =   5736
  30.    Begin Label Label2 
  31.       BorderStyle     =   1  'Fixed Single
  32.       Caption         =   "To customize this setup program, modify the FORM_LOAD event procedure in this form."
  33.       Height          =   435
  34.       Left            =   15
  35.       TabIndex        =   1
  36.       Top             =   15
  37.       Visible         =   0   'False
  38.       Width           =   5625
  39.    End
  40.    Begin Label Label1 
  41.       BorderStyle     =   1  'Fixed Single
  42.       Caption         =   "This label used for DDE connection to the Program Manager"
  43.       Height          =   390
  44.       Left            =   15
  45.       TabIndex        =   0
  46.       Top             =   525
  47.       Visible         =   0   'False
  48.       Width           =   5610
  49.    End
  50. Const APPNAME = "Loan Application"
  51. Const APPDIR = "C:\LOAN"    ' The default install directory
  52. Const fDataAccess% = False
  53. Const fODBC% = False
  54. Const fBtrieve% = False
  55. Const fOLE2% = False
  56. ' Set the total uncompressed file sizes
  57. ' by adding the sizes of the files
  58. Const WINSYSNEEDED = 40896  ' Files that go into WINDOWS and SYSTEM directory
  59. Const OTHERNEEDED = 12555   ' Files that don't go into the WINDOWS or SYSTEM directory
  60. Sub DrawBackground ()
  61.     Setup1.CurrentY = 5
  62.     Setup1.CurrentX = 5
  63.     Setup1.ForeColor = QBColor(15)
  64.     Print APPNAME + " Setup"
  65. End Sub
  66. Sub Form_Load ()
  67.     '----------
  68.     ' Initialize
  69.     '----------
  70.     dialogCaption$ = APPNAME + " Setup"
  71.     ShowMainForm dialogCaption$
  72.     winDrive$ = UCase$(Left$(winDir$, 1))
  73.     winDir$ = UCase$(GetWindowsDir$())
  74.     winSysDir$ = UCase$(GetWindowsSysDir$())
  75.     '----------------------------------------------------
  76.     ' Get Window version
  77.     '----------------------------------------------------
  78.     TheVerInfo& = GetVersion()
  79.     WinVer& = TheVerInfo& And &HFFFF&
  80.     If Val(Format$(WinVer& Mod 256) + "." + Format$(WinVer& \ 256)) >= 3.1 Then
  81.         gfWin31% = True
  82.     End If
  83.     '----------------------------------------------------
  84.     ' OLE 2.0 requires Win 3.1 or greater
  85.     '----------------------------------------------------
  86.     If fOLE2% And Not gfWin31% Then
  87.         MsgBox "This application requires Windows 3.1 or later"
  88.         GoTo ErrorSetup
  89.     End If
  90.     '----------------------------------------------------
  91.     ' SETUP.EXE passes the source drive in a command
  92.     ' argument.  If it is empty,  that means the user
  93.     ' executed this .exe directly.  In that case, show
  94.     ' a dialog to get the desired source directory.
  95.     '----------------------------------------------------
  96.     SourcePath$ = Command$
  97.     If SourcePath$ = "" Then
  98.         title$ = dialogCaption$
  99.         caption1$ = "Please enter the drive or path containing the " + APPNAME + " source files."
  100.         caption2$ = "Install From:"
  101.         defaultDrive$ = "A:"
  102.         defaultText$ = "A:\"
  103.         ShowPathDialog title$, caption1$, caption2$, defaultDrive$, defaultText$, SourcePath$, outButton$
  104.         If outButton$ = "exit" Then GoTo ErrorSetup
  105.     Else
  106.         If Right$(SourcePath$, 1) <> "\" Then
  107.             SourcePath$ = SourcePath$ + "\"
  108.         End If
  109.     End If
  110.     '--------------------
  111.     ' Get Destination Path
  112.     '--------------------
  113.     title$ = dialogCaption$
  114.     caption1$ = "If you want to install the test application in a different directory and/or drive, type the name of the directory."
  115.     caption2$ = "Install To:"
  116.     defaultDrive$ = "C:"
  117.     defaultText$ = APPDIR
  118.     ShowPathDialog title$, caption1$, caption2$, defaultDrive$, defaultText$, destPath$, outButton$
  119.     If outButton$ = "exit" Then GoTo ErrorSetup
  120.     '-----------------------------------------
  121.     ' Dim disk space variables as Long Integers
  122.     '-----------------------------------------
  123.     Dim winSpaceFree As Long
  124.     Dim sourceSpaceFree As Long
  125.     Dim destSpaceFree As Long
  126.     Dim totalNeeded As Long
  127.     '---------------------------------------------------------
  128.     ' If the Windows \SYSTEM directory is a subdirectory
  129.     ' of the Windows directory, the proper place for
  130.     ' installation of .VBXs and shared .DLLs is the
  131.     ' Windows \SYSTEM directory.
  132.     '
  133.     ' If the Windows \SYSTEM directory is *not* a subdirectory
  134.     ' of the Windows directory, then the user is running a
  135.     ' shared version of Windows, and the proper place for
  136.     ' installation of .VBXs and shared .DLLs is the
  137.     ' Windows directory.
  138.     '---------------------------------------------------------
  139.     If InStr(winSysDir$, winDir$) = 0 Then
  140.         winSysDir$ = winDir$
  141.     End If
  142.     '---------------------------------
  143.     ' Get Drive Letters of directories
  144.     '---------------------------------
  145.     destDrive$ = UCase$(Left$(destPath$, 1))
  146.     sourceDrive$ = UCase$(Left$(SourcePath$, 1))
  147.     '---------------------------------
  148.     ' Compute free disk space variables
  149.     '---------------------------------
  150.     winSpaceFree = GetDiskSpaceFree(winDrive$)
  151.     destSpaceFree = GetDiskSpaceFree(destDrive$)
  152.     '-----------------------------------------
  153.     ' Check for enough disk space.
  154.     '
  155.     ' Some components are being installed into the
  156.     ' Windows\SYSTEM directory.
  157.     '
  158.     ' So if the main destination path is on a
  159.     ' different drive than the drive with
  160.     ' the Windows \SYSTEM directory, we have to
  161.     ' check both drives.
  162.     '
  163.     ' An example of this is when the user is installing
  164.     ' the main product to drive D:, but the Windows
  165.     ' directory is on drive c:
  166.     ' -----------------------------------------
  167.     totalNeeded = WINSYSNEEDED + OTHERNEEDED
  168.     If winDrive$ = destDrive$ Then
  169.         If destSpaceFree < totalNeeded Then
  170.             MsgBox "There is not enough disk space on drive " + destDrive$ + ":   An estimated" + Str$(totalNeeded - destSpaceFree) + " additional bytes are needed.", 16, dialogCaption$
  171.             GoTo ErrorSetup
  172.         End If
  173.     Else
  174.         If winSpaceFree < WINSYSNEEDED Then
  175.             MsgBox "There is not enough disk space on drive " + winDrive$ + ":  An estimated" + Str$(WINSYSNEEDED - winSpaceFree) + " additional bytes are needed.", 16, dialogCaption$
  176.             GoTo ErrorSetup
  177.         End If
  178.         If destSpaceFree < OTHERNEEDED Then
  179.             MsgBox "There is not enough disk space on drive " + destDrive$ + ":  An estimated" + Str$(OTHERNEEDED - destSpaceFree) + " additional bytes are needed.", 16, dialogCaption$
  180.             GoTo ErrorSetup
  181.         End If
  182.         
  183.     End If
  184.     '----------------------------
  185.     ' Create destination directory
  186.     '----------------------------
  187.     If Not CreatePath(destPath$) Then GoTo ErrorSetup
  188.     '-----------------------------------------------------------
  189.     ' Show Status Dialog -- This stays up while copying files
  190.     ' It is required by the CopyFile routine
  191.     '-----------------------------------------------------------
  192.     ShowStatusDialog dialogCaption$, totalNeeded
  193.     '-----------
  194.     ' Copy Files
  195.     '-----------
  196.     ' Test to see if loan.exe is on the disk, if not then you know the user
  197.     ' did not insert the first disk
  198.     If Not PromptForNextDisk(1, SourcePath$ + "loan.ex_") Then GoTo ErrorSetup
  199.     ' Install loan.exe and grid.vbx in the destPath$
  200.     If Not CopyFile(SourcePath$, destPath$, "loan.ex_", "loan.exe") Then GoTo ErrorSetup
  201.     If Not CopyFile(SourcePath$, winSysDir$, "grid.vb_", "grid.vbx") Then GoTo ErrorSetup
  202.     ' If you have more than one distribution disk, call PromptForNextDisk after
  203.     ' you have installed all the files from the previous disk. This line tests to
  204.     ' see if foo.da_ is on disk 2. If not, you know the user has not inserted disk 2.
  205.     ' The call to PromptForNextDisk is commented out, since loan.exe can be installed
  206.     ' from a single distribution disk.
  207.     ' If Not PromptForNextDisk(2, SourcePath$ + "foo.da_") Then GoTo ErrorSetup
  208.     ' If Not CopyFile(SourcePath$, destPath$, "foo.da_", "foo.dat", 0) Then GoTo ErrorSetup
  209.     '--------------------------------------------------
  210.     ' File Copying is over, so unload the status dialog
  211.     '--------------------------------------------------
  212.     Unload StatusDlg
  213.     '-----------------------------------------------------------
  214.     ' Show static message while working on DDE to Program Manager
  215.     '-----------------------------------------------------------
  216.     ShowStaticMessageDialog dialogCaption$, "Creating Program Manager Icon..."
  217.     '--------------------------------------
  218.     ' Create program manager group and icon
  219.     '--------------------------------------
  220.     CreateProgManGroup Setup1, "My Loan Application", "LOAN.GRP"
  221.     CreateProgManItem Setup1, destPath$ + "LOAN.EXE", "My Loan Application"
  222.     '-------------------------------------------------
  223.     ' Since SETUP.EXE copies your setup program to the Windows
  224.     ' directory, it is possible for your user to
  225.     ' execute this program directly.
  226.     '
  227.     ' As a usability feature, you may wish to insert code
  228.     ' here to install a program manager icon that executes
  229.     ' your setup program in the windows drive.  This
  230.     ' allows th user to re-run setup at a later time to
  231.     ' install options that were not installed the first
  232.     ' time.
  233.     '-------------------------------------------------
  234.     '-------------------
  235.     ' Hide Static Message
  236.     '-------------------
  237.     MessageDlg.Hide
  238.     '--------------------------------------------------------------
  239.     ' If OLE2.DLL already exists, then ignore the OLE 2 flag.
  240.     ' Otherwise, if we are installing an application that uses
  241.     ' OLE 2.0, we need to register the OLE 2 DLL's via REGEDIT.EXE.
  242.     '
  243.     ' Do not copy OLE dlls unless you check the versions and assure
  244.     ' that the versions you plan to install postdate the ones on
  245.     ' the users machine.
  246.     '
  247.     '
  248.     ' The data access engine and OLE 2.0 need to have SHARE.EXE
  249.     ' loaded. Check AUTOEXEC.BAT and add if needed.  NOTE: If
  250.     ' running Window For WorkGroup, then do not add SHARE.  WFW
  251.     ' use its own sharing mechanism, VSHARE.386.
  252.     '----------------------------------------------------------
  253.     If fDataAccess% Or fOLE2% And Not FileExists(winSysDir$ + "\" + "OLE2.DLL") Then
  254.         ret$ = Space$(255)
  255.         x% = GetPrivateProfileString("BOOT", "NETWORK.DRV", "", ret$, Len(ret$), "SYSTEM.INI")
  256.         If x% Then ret$ = Left(ret$, x%)
  257.         If InStr(1, UCase$(ret$), "WFWNET.DRV") = 0 Then
  258.             AddShareIfNeeded winSysDir$, "SHARE.EXE"
  259.         End If
  260.     End If
  261.     '----------------------------
  262.     ' Need to register OLE 2.0 dlls
  263.     '----------------------------
  264.     If fOLE2% And Not FileExists(winSysDir$ + "\" + "OLE2.DLL") Then
  265.         x% = Shell("regedit /s ole2.reg")
  266.     End If
  267.     '-------------------------------------------------------
  268.     ' Do not change this if statement.  Used by Setup Wizard
  269.     '-------------------------------------------------------
  270.     If fODBC% Then
  271.         CreateProgManItem Setup1, destPath$ + "ODBCADM.EXE", "ODBC Administrator"
  272.         MsgBox "Before you can run a Visual Basic ODBC application using the SQL Server driver, you must first update the ODBC catalog of stored procedures.  These procedures are provided in the INSTCAT.SQL file.  Typically, the system administrator for SQL Server should install these procedures, using the SQL Server ISQL utility."
  273.     End If
  274.     '-------------------------------------------------------
  275.     ' Do not change this if statement.  Used by Setup Wizard
  276.     '-------------------------------------------------------
  277.     If fBtrieve% Then
  278.         ' See notes in Appendix C
  279.         retstr$ = String$(255, 32)
  280.         x% = GetPrivateProfileString%("BTRIEVE", "OPTIONS", "1", retstr$, Len(retstr$), "WIN.INI")
  281.         If x% <= 1 Then
  282.             x% = WritePrivateProfileString%("BTRIEVE", "OPTIONS", "/m:64 /p:4096 /b:16 /f:20 /l:40 /n:12 /t:" + destPath$ + "BTRIEVE.TRN", "WIN.INI")
  283.         End If
  284.     End If
  285.     '------------------
  286.     ' Show Final message
  287.     '------------------
  288.     MsgBox APPNAME + " Installation is Complete!", 48, dialogCaption$
  289. ExitSetup:
  290.     Setup1.Hide
  291.     RestoreProgMan         'Show the program manager
  292.     End
  293.     Exit Sub
  294. ErrorSetup:
  295.     MsgBox APPNAME + " is not properly installed.  Please re-run setup at a later time to install the Test Application properly.", 48, dialogCaption$
  296.     ChDrive winDrive$   ' Set back to hard disk
  297.     ChDir Left$(winDir$, Len(winDir$) - 1)
  298.     End
  299.     Exit Sub
  300. End Sub
  301. Sub Form_Paint ()
  302.     DrawBackground
  303. End Sub
  304. '---------------------------------------------------------------
  305. ' Sets the form's caption, Paints 3-D Background Text, Shows Form
  306. '---------------------------------------------------------------
  307. Sub ShowMainForm (Caption$)
  308.     Screen.MousePointer = 11
  309.     Setup1.Caption = Caption$
  310.     Setup1.Move 0, 0, Screen.Width, Screen.Height * .85
  311.     Setup1.Show
  312.     Setup1.Refresh
  313.     Setup1.ScaleMode = 2
  314.     Setup1.FontSize = 24
  315.     Setup1.FontBold = True
  316.     Setup1.FontItalic = True
  317.     DrawBackground
  318. End Sub
  319. Sub ShowPathDialog (title$, caption1$, caption2$, defaultDrive$, defaultText$, SourcePath$, outButton$)
  320.         Screen.MousePointer = 11
  321.         Load PathDlg
  322.         PathDlg.Caption = title$
  323.         PathDlg.Label1.Caption = caption1$
  324.         PathDlg.Label2.Caption = caption2$
  325.         PathDlg.inDrive.Tag = defaultDrive$
  326.         PathDlg.Text1.Text = defaultText$
  327.         PathDlg.Text1.SelStart = 0
  328.         PathDlg.Text1.SelLength = Len(defaultText$)
  329.         CenterForm PathDlg
  330.         Screen.MousePointer = 0
  331.         PathDlg.Show 1
  332.         
  333.         SourcePath$ = PathDlg.outPath.Tag
  334.         outButton$ = PathDlg.outButton.Tag
  335.         Unload PathDlg
  336. End Sub
  337. Sub ShowStaticMessageDialog (title$, Caption$)
  338.     Load MessageDlg
  339.     CenterForm MessageDlg
  340.     MessageDlg.Caption = title$
  341.     MessageDlg.Label.Caption = Caption$
  342.     MessageDlg.Show
  343.     MessageDlg.Refresh
  344. End Sub
  345. Sub ShowStatusDialog (title$, totalBytes As Long)
  346.     Load StatusDlg
  347.     StatusDlg.Caption = title$
  348.     StatusDlg.total.Tag = Str$(totalBytes)
  349.     CenterForm StatusDlg
  350.     StatusDlg.Show
  351. End Sub
  352.