Private Function CheckForFile(FileName) As Boolean
'Check if file exists
CheckForFile = (Dir(FileName) <> "")
End Function
Private Sub Patch()
On Error GoTo err
Dim intLocalVer As Integer
Dim b() As Byte
Dim intRemoteVer As Integer
Dim strRemoteVer As String
Dim doUpdate As Boolean
'1. Open the local version file and read in the number
Open App.Path & "\curversion.dat" For Input As #1
intLocalVer = CInt(Input(LOF(1), 1))
Close 1
'2. Download the remote version file and read in the number
' Note: This is all one line:
Text1.Text = "Connecting..."
b() = InetUpdate.OpenURL("http://www.ofpnam.com/hammy/comref/remotever.dat", 1)
Text1.Text = "Connecting..." & vbNewLine & "Connected"
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..."
strRemoteVer = ""
For t = 0 To UBound(b)
strRemoteVer = strRemoteVer + Chr(b(t))
Next
intRemoteVer = Int(strRemoteVer)
'3. Compare numbers
If intRemoteVer > intLocalVer Then
'Note: This is all one line:
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available"
Text1.SelStart = Len(Text1.Text)
upd = MsgBox("New version available, would you like to update it now? " & vbNewLine & "Please be patient, This may take a few minutes depending on connection speed.", vbYesNo Or vbQuestion)
If upd = vbYes Then
doUpdate = True
End If
If upd = vbNo Then
doUpdate = False
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Canceled"
Text1.SelStart = Len(Text1.Text)
'Pause 2
End If
Else
'MsgBox "You have the most recent version of this program."
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "You have the most recent version!"
Text1.SelStart = Len(Text1.Text)
'Pause 2
doUpdate = False
End If
'4. If doupdate = True, then download the latest program exe from the site
If doUpdate Then
'Note: This is all one line:
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Downloading..."
Text1.SelStart = Len(Text1.Text)
b() = InetUpdate.OpenURL("http://www.ofpnam.com/hammy/comref/1200.exe", 1)
Open App.Path & "\1200.exe" For Binary Access Write As #1
Put #1, , b()
Close 1
b() = InetUpdate.OpenURL("http://www.ofpnam.com/hammy/comref/1200r.txt", 1)
Open App.Path & "\1200r.txt" For Binary As #1
Put #1, , b()
Close #1
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Downloading..." & vbNewLine & "Download Complete!" & vbNewLine & "Installing..."
Text1.SelStart = Len(Text1.Text)
'Name App.Path & "\ComRef.exe" As App.Path & "\OComRef.exe"
Kill App.Path & "\ComRef.exe"
'Kill App.Path & "\ComRef.exe"
If CheckForFile(App.Path & "\Readme.doc") Then
Kill App.Path & "\Readme.doc"
Else
Kill App.Path & "\Readme.txt"
End If
Name App.Path & "\1200r.txt" As App.Path & "\Readme.doc"
Name App.Path & "\1200.exe" As App.Path & "\ComRef.exe"
'Kill App.Path & "\OComRef.exe"
'Now save the current version into the local version file
Open App.Path & "\curversion.dat" For Output As #1
Print #1, strRemoteVer
Close 1
Text1.Text = "Connecting..." & vbNewLine & "Connected" & vbNewLine & "Checking for updates..." & vbNewLine & "Update available" & vbNewLine & "Downloading..." & vbNewLine & "Download Complete!" & vbNewLine & "Installing..." & vbNewLine & "Installation Complete!" & vbNewLine & "Update was successful"
Text1.SelStart = Len(Text1.Text)
End If
err:
If err.Number = 13 Then
MsgBox "Error connecting, please make sure you are connected to the internet.", vbCritical
Text1.Text = "Connecting..." & vbNewLine & "Could not connect to server"
'Else
'MsgBox err.Number & vbNewLine & err.Description
End If
If err.Number = 53 Then
MsgBox "Error finding files" & vbNewLine & "Please make sure the files: ComRef.exe, Update.exe, Readme.txt Or Readme.doc, and curversion.dat are in the same directory", vbCritical
End If
End Sub
Public Sub Form_Unload(cancel As Integer)
On Error GoTo weeee:
Shell App.Path & "\ComRef", vbNormalFocus
GoTo end2
weeee:
MsgBox "Could not find ComRef.exe, Update may have not been successful"
GoTo end2
end2:
Dim frm As Form
For Each frm In Forms
Unload frm
Set frm = Nothing
Next
End Sub
Private Sub Timer1_Timer()
Patch
Timer1.Enabled = False
End Sub