AutoUpdate (2)




Dim Remote_VerDownload As String
Dim CurVer As String
Dim RemoteVer As String
Dim strFileName As String
Dim FTPHostname As String
Dim Response As String
Dim pathname As String
Dim filename As String
Dim IPaddress As String
'Below is all the Update Data Holders

Dim Data1 As String
Dim Data2 As String
Dim Data3 As String
Dim Data4 As String
'Data5 - Data10 is added for expansion and is not being 'used yet.

Dim Data5 As String
Dim Data6 As String
Dim Data7 As String
Dim Data8 As String
Dim Data9 As String
Dim Data10 As String
Dim StartPath As String
Dim EndPath As String
Dim CurrentIP As String
Private Sub Cmd1_Click()
StartPath = App.Path & "/remote_ver.txt"
EndPath = App.Path & "/cur_ver.txt"
On Error Resume Next
FileCopy StartPath, EndPath
Kill StartPath
Unload Updatefrm
End Sub

Sub Form_Load()
'Our version file is called cur_ver.txt

'Remote version file is called remote_ve

' r.txt

'First we download the remote_ver.txt fi

' le from the server.

'Second we compare the numbers in the fi

' les.

'If cur_ver.txt is < remote_ver.txt t

' hen download a list 'file.

'The list file is called list.txt .

'This file contains a list of all the up

' dated files and 'downloads them.

'This is done by reading each line in th

' e list.txt file and 'adding the filename

'

'onto a getfile (XXX".txt") or something

' similar.

Open App.Path & "\IP.txt" For Input As #1
Line Input #1, CurrentIP
Close #1
Updatefrm.Show
Txt1.Text = "Checking If theres any updates."
Call Download'Downloads remote version file
End Sub

Sub Download()
'Below is basic stuff needed for the pro

' gram to work 'right.

Inet1.AccessType = icUseDefault
Inet1.Protocol = icFTP
Inet1.RemoteHost = CurrentIP
Inet1.RemotePort = "21" ' The Port to connect 'to.
'Change the username and password to wha

' t ever is 'needed for your ftp server.

'Note that for this to work right the us

' ername and 'password MUST be uppercase.

'Don't ask me why but its the only way I

' could get it'to work right.

Inet1.UserName = "PURTOPIA"
Inet1.Password = "PURTOPIA"
filename = "remote_ver.txt"
Call FTPLogin
Call getfile
Do While Inet1.StillExecuting
DoEvents
Loop
strFileName = "remote_ver.txt"
Call FileFound
If FileFound = True Then
Call VersionCheck'Checks the two version files.
End If
End Sub

Sub getfile()
FTPLogin
Inet1.Execute FTPHostname, "GET " & filename & " " & pathname & filename
Do While Inet1.StillExecuting
DoEvents
Loop
Exit Sub
End Sub

Sub FTPLogin()
With Inet1
.Password = "PURTOPIA"
.UserName = "PURTOPIA"
End With
End Sub

Sub VersionCheck()
'Opens the cur_ver.txt file and reads th

' e first line

Open App.Path & "\cur_ver.txt" For Input As #1
Line Input #1, CurVer
Close #1
'Opens the remote_ver.txt file and reads

' the first line

Open App.Path & "\remote_ver.txt" For Input As #1
Line Input #1, RemoteVer
Close #1
If CurVer < RemoteVer Then
Call Download2
End If
If CurVer = RemoteVer Then
Call NoUpdates
End If
End Sub

Sub NoUpdates()
Txt1.Text = "No updates found.."
End Sub

Function FileFound() As Boolean
Dim lpFindFileData As WIN32_FIND_DATA
Dim hFindFirst As Long
hFindFirst = FindFirstFile(strFileName, lpFindFileData)
If hFindFirst > 0 Then
FindClose hFindFirst
FileFound = True
Else
FileFound = False
End If
End Function

Sub Download2()
Txt1.Text = "A Update has been found.."
filename = "lists.txt"
Call FTPLogin
Call getfile
Do While Inet1.StillExecuting
DoEvents
Loop
strFileName = "lists.txt"
Call FileFound
If FileFound = True Then
Call Update
End If
End Sub

Sub Update()
Txt1.Text = "Downloading updated files..."
'Opens the lists.txt file and reads each

' line and gives the 'infomation a Data1 -

' Data10 string

Open App.Path & "\lists.txt" For Input As #1
Line Input #1, Data1
Line Input #1, Data2
Line Input #1, Data3
Line Input #1, Data4
Close #1
Call Download3
End Sub

Sub Download3()
filename = Data1
Call FTPLogin
Call getfile
Do While Inet1.StillExecuting
DoEvents
Loop
filename = Data2
Call getfile
Do While Inet1.StillExecuting
DoEvents
Loop
filename = Data3
Call getfile
Do While Inet1.StillExecuting
DoEvents
Loop
filename = Data4
Call getfile
Do While Inet1.StillExecuting
DoEvents
Loop
Txt1.Text = "Update Completed... Please Restart Now."
End Sub

---------------PASTE CODE BELOW IN A MODULE1.bas----------
'**************************************

'Windows API/Global Declarations for :Fi

'

' leFound()

'**************************************

Public Const MAX_PATH = 260
Type FILETIME ' 8 Bytes
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Type WIN32_FIND_DATA ' 318 Bytes
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved_ As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Declare Function FindFirstFile& Lib "kernel32" _
Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData _
As WIN32_FIND_DATA)
Public Declare Function FindClose Lib "kernel32" _
(ByVal hFindFile As Long) As Long
Richiede il controllo Inet










( autoupdate2.html )- by Paolo Puglisi - Modifica del 17/12/2023