home *** CD-ROM | disk | FTP | other *** search
/ Dictionnaire Multimedia Multilingue / dictionarvizual.iso / setup1.bas < prev    next >
BASIC Source File  |  1993-04-27  |  26KB  |  778 lines

  1.  
  2. Sub AddShareIfNeeded (SharePath$, ShareFile$)
  3.     On Error GoTo ShareError
  4.  
  5.     fh% = FreeFile
  6.     Open "C:\AUTOEXEC.BAT" For Input As fh%
  7.  
  8.     fFound% = 0
  9.     While Not fFound% And Not EOF(fh%)
  10.     Line Input #fh%, Temp1$
  11.     If InStr(1, UCase$(Temp1$), "REM") = 0 And InStr(1, Temp1$, ";") = 0 And InStr(1, UCase$(Temp1$), "SHARE") > 0 Then
  12.        fFound% = True
  13.     End If
  14.     Wend
  15.  
  16.     Close #fh%
  17.  
  18.     If Not fFound% Then
  19.     MsgBox "Please add <PATH>SHARE.EXE /L:500 to your AUTOEXEC.BAT"
  20.     End If
  21.  
  22.     Exit Sub
  23. ShareError:
  24.     Close #fh%, #fh2%
  25.     Exit Sub
  26. End Sub
  27.  
  28. '-------------------------------------------------------
  29. ' Centers the passed form just above center on the screen
  30. '-------------------------------------------------------
  31. Sub CenterForm (x As Form)
  32.   
  33.     Screen.MousePointer = 11
  34.     x.Top = (Screen.Height * .85) / 2 - x.Height / 2
  35.     x.Left = Screen.Width / 2 - x.Width / 2
  36.     Screen.MousePointer = 0
  37.  
  38. End Sub
  39.  
  40. Sub ConcatSplitFiles (firstfile$, cSplit%)
  41.     Dim x%, fh1%, fh2%, outfile$, outfileLen&, CopyLeftOver&, CopyChunk#, filevar$
  42.     Dim iFileMax%, iFile%, y%
  43.  
  44.     For x% = 2 To cSplit%
  45.     
  46.     fh1% = FreeFile
  47.     Open Left$(firstfile$, Len(firstfile$) - 1) + Format$(1) For Binary As fh1%
  48.         
  49.     fh2% = FreeFile
  50.     outfile$ = Left$(firstfile$, Len(firstfile$) - 1) + Format$(x%)
  51.     Open outfile$ For Binary As fh2%
  52.         
  53.     ' Goto the end of file (plus one bytes) to start writing data
  54.     Seek #fh1%, LOF(fh1%) + 1
  55.  
  56.     outfileLen& = LOF(fh2%)
  57.     CopyLeftOver& = outfileLen& Mod 10
  58.     CopyChunk# = (outfileLen& - CopyLeftOver&) / 10
  59.     filevar$ = String$(CopyLeftOver&, 32)
  60.     Get #fh2%, , filevar$
  61.     Put #fh1%, , filevar$
  62.     filevar$ = String$(CopyChunk#, 32)
  63.     iFileMax% = 10
  64.     For iFile% = 1 To iFileMax%
  65.         Get #fh2%, , filevar$
  66.         Put #fh1%, , filevar$
  67.     Next iFile%
  68.  
  69.     Close fh1%, fh2%
  70.     y% = SetTime(outfile$, firstfile$)
  71.     Kill outfile$
  72.  
  73.     Next x%
  74.     
  75.     FileCopy Left$(firstfile$, Len(firstfile$) - 1) + Format$(1), firstfile$
  76.     Kill Left$(firstfile$, Len(firstfile$) - 1) + Format$(1)
  77. End Sub
  78.  
  79. '---------------------------------------------------------------
  80. ' Copies file SrcFilename from SourcePath to DestinationPath.
  81. '
  82. ' Returns 0 if it could not find the file, or other runtime
  83. ' error occurs.  Otherwise, returns true.
  84. '
  85. ' If the source file is older, the function returns success (-1)
  86. ' even though no file was copied, since no error occurred.
  87. '---------------------------------------------------------------
  88. Function CopyFile (ByVal SourcePath As String, ByVal DestinationPath As String, ByVal SrcFilename As String, ByVal DestFileName As String)
  89. ' ----- VerInstallFile() flags -----
  90.     Const VIFF_FORCEINSTALL% = &H1, VIFF_DONTDELETEOLD% = &H2
  91.     Const OF_DELETE% = &H200
  92.     Const VIF_TEMPFILE& = &H1
  93.     Const VIF_MISMATCH& = &H2
  94.     Const VIF_SRCOLD& = &H4
  95.  
  96.     Const VIF_DIFFLANG& = &H8
  97.     Const VIF_DIFFCODEPG& = &H10
  98.     Const VIF_DIFFTYPE& = &H20
  99.     Const VIF_WRITEPROT& = &H40
  100.     Const VIF_FILEINUSE& = &H80
  101.     Const VIF_OUTOFSPACE& = &H100
  102.     Const VIF_ACCESSVIOLATION& = &H200
  103.     Const VIF_SHARINGVIOLATION = &H400
  104.     Const VIF_CANNOTCREATE = &H800
  105.     Const VIF_CANNOTDELETE = &H1000
  106.     Const VIF_CANNOTRENAME = &H2000
  107.     Const VIF_CANNOTDELETECUR = &H4000
  108.     Const VIF_OUTOFMEMORY = &H8000
  109.  
  110.     Const VIF_CANNOTREADSRC = &H10000
  111.     Const VIF_CANNOTREADDST = &H20000
  112.  
  113.     Const VIF_BUFFTOOSMALL = &H40000
  114.     Dim TmpOFStruct As OFStruct
  115.     On Error GoTo ErrorCopy
  116.  
  117.     Screen.MousePointer = 11
  118.  
  119.     '--------------------------------------
  120.     ' Add ending \ symbols to path variables
  121.     '--------------------------------------
  122.     If Right$(SourcePath$, 1) <> "\" Then
  123.     SourcePath$ = SourcePath$ + "\"
  124.     End If
  125.     If Right$(DestinationPath$, 1) <> "\" Then
  126.     DestinationPath$ = DestinationPath$ + "\"
  127.     End If
  128.     
  129.     '----------------------------
  130.     ' Update status dialog info
  131.     '----------------------------
  132.     Statusdlg.Label1.Caption = "Source file: " + Chr$(10) + Chr$(13) + UCase$(SourcePath$ + SrcFilename$)
  133.     Statusdlg.Label1.Refresh
  134.     Statusdlg.Label2.Caption = "Destination file: " + Chr$(10) + Chr$(13) + UCase$(DestinationPath$ + DestFileName$)
  135.     Statusdlg.Label2.Refresh
  136.  
  137.     '-----------------------------------------
  138.     ' Check the validity of the path and file
  139.     '-----------------------------------------
  140. CheckForExist:
  141.     If Not FileExists(SourcePath$ + SrcFilename$) Then
  142.     Screen.MousePointer = 0
  143.     x% = MsgBox("Error occurred while attempting to copy file.  Could not locate file: """ + SourcePath$ + SrcFilename$ + """", 34, "SETUP")
  144.     Screen.MousePointer = 11
  145.     If x% = 3 Then
  146.         CopyFile = False
  147.     ElseIf x% = 4 Then
  148.         GoTo CheckForExist
  149.     ElseIf x% = 5 Then
  150.         GoTo SkipThisFile
  151.     End If
  152.     Else
  153.     '-------------------------------------------------
  154.     ' VerInstallFile installs the file. We need to initialize
  155.     ' some arguments for the temp file that is created by the call
  156.     '-------------------------------------------------
  157. TryToCopyAgain:
  158.     CurrDir$ = String$(255, 0)
  159.     TmpFile$ = String$(255, 0)
  160.     lpwTempFileLen% = 255
  161.     InFileVer$ = GetFileVersion(SourcePath$ + SrcFilename$)
  162.     OutFileVer$ = GetFileVersion(DestinationPath$ + DestFileName$)
  163.     
  164.     ' Install if no version info is available
  165.     If Len(InFileVer$) <> 0 And Len(OutFileVer$) <> 0 Then
  166.         ' Don't install older or same version of file
  167.         If InFileVer$ <= OutFileVer$ Then
  168.         UpdateStatus GetFileSize(SourcePath$ + SrcFilename$)
  169.         CopyFile = True
  170.         Exit Function
  171.         End If
  172.     End If
  173.  
  174.     Result& = VerInstallFile&(0, SrcFilename$, DestFileName$, SourcePath$, DestinationPath$, CurrDir$, TmpFile$, lpwTempFileLen%)
  175.  
  176.     '--------------------------------------------
  177.     ' After copying, update the installation meter
  178.     '---------------------------------------------
  179.     
  180.     S$ = DestinationPath$
  181.     If Right$(S$, 1) <> "\" Then S$ = S$ + "\"
  182.     S$ = S$ + DestFileName$
  183.     If Not TryAgain% Then UpdateStatus GetFileSize(S$)
  184.  
  185.     '--------------------------------
  186.     ' There are many return values that you can test for.
  187.     ' The constants are listed above.
  188.     ' The following lines of code return will set the Function to
  189.     ' True if the VerInstallFile call was successful.
  190.     '
  191.     ' If the call was unsuccessful due to a different language on the
  192.     ' users machine, VerInstallFile is called again to force installation.
  193.     ' You can change this to not install if you choose.
  194.     ' Be careful about using FORCEINSTALL.  Other flags could be
  195.     ' set which indicate that this file should not be overridden.
  196.     '
  197.     ' Under any other circumstance, the tempfile created by VerInstallFile
  198.     ' is removed using OpenFile and the CopyFile function returns false.
  199.     '--------------------------------------------------------
  200.     
  201.     If Result& = 0 Or (Result& And VIF_SRCOLD&) = VIF_SRCOLD& Then
  202.         CopyFile = True
  203.     ElseIf (Result& And VIF_DIFFLANG&) = VIF_DIFFLANG& Then
  204.         Result& = VerInstallFile&(VIFF_FORCEINSTALL%, SrcFilename$, DestFileName$, SourcePath$, DestinationPath$, CurrDir$, TmpFile$, lpwTempFileLen%)
  205.         CopyFile = True
  206.     ElseIf (Result& And VIF_WRITEPROT&) = VIF_WRITEPROT& Then
  207.         Result& = VerInstallFile&(VIFF_FORCEINSTALL%, SrcFilename$, DestFileName$, SourcePath$, winSysDir$ + "\", CurrDir$, TmpFile$, lpwTempFileLen%)
  208.         CopyFile = True
  209.     ElseIf (Result& And VIF_CANNOTREADSRC) = VIF_CANNOTREADSRC Then
  210.         ' VerInstallFile does will not handle compressed files that have been split.
  211.         ' Use VB's FileCopy stmt
  212.         FileCopy SourcePath$ + SrcFilename$, DestinationPath$ + DestFileName$
  213.         CopyFile = True
  214.     Else
  215.         Screen.MousePointer = 0
  216.         If (Result& And VIF_FILEINUSE&) = VIF_FILEINUSE& Then
  217.         x% = MsgBox(DestFileName$ & " is in use. Please close all applications and re-attempt Setup.", 34)
  218.         If x% = 3 Then
  219.             CopyFile = False
  220.         ElseIf x% = 4 Then
  221.             TryAgain% = True
  222.             GoTo TryToCopyAgain
  223.         ElseIf x% = 5 Then
  224.             CopyFile = True
  225.             GoTo SkipThisFile
  226.         End If
  227.         Else
  228.         MsgBox DestFileName$ & " could not be installed."
  229.         CopyFile = False
  230.         End If
  231.         Screen.MousePointer = 11
  232.     End If
  233.  
  234.     If (Result& And V