Mar 17th, 2005, 08:28 PM
#1
Thread Starter
Admodistrator
Another Auto-Downloader
K, first off most of this IS NOT my code. I modified it so that it was an auto-updater instead of just a downloader. Ive fixed numerous bugs and stuff...All you need is an inet1, listbox called lststat, label called lblstatus,command button called cmdcancel
VB Code:
-------------------------------------------------
Private m_GettingFileSize As Boolean
Private m_DownloadingFile As Boolean
Private m_DownloadingFileSize As Long
Private m_LocalSaveFile As String
Private m_FileSize As String
Private FirstResponse As Boolean
Dim ff As Integer
Dim exe As String
dim filesize as string
Private Sub cmdCancel_Click()
'On Error Resume Next
Inet1.Cancel
Unload Me
End Sub
Private Sub Form_Load()
filesize = # ' Okay this is how i do it, make filesize a number, compile your program and upload it. Then see how big it is on the ftp. Type the number in the filesize re-compile and upload. Then it will have the correct filesize.
If App.PrevInstance Then
End
End If
Dim RemoteFileToGet As String
'Name of the updated exe
RemoteFileToGet = "www.bazooka.com" 'THIS IS THE DOWNLOAD
FirstResponse = False
m_FileSize = GetHTTPFileSize(RemoteFileToGet)
lstStat.AddItem "Establishing file size & location..."
lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 ' \/
If Int(m_FileSize) \ 1024 <> filesize Then 'shows in kb instead of other stuff
MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
m_LocalSaveFile = App.Path & "\rarfile or zip.rar"
Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\name of .exe" & Chr(34)
Else
MsgBox "Your exe is updated as can be :) "
lstStat.AddItem "Done."
lblStatus.Caption = "0/0"
End If
End Sub
Private Function GetHTTPFileSize(strHTTPFile As String) As Long
On Error GoTo ErrorHandler
Dim GetValue As String
Dim GetSize As Long
m_GettingFileSize = True
Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
Do Until Inet1.StillExecuting = False
DoEvents
Loop
GetValue = Inet1.GetHeader("Content-length")
Do Until Inet1.StillExecuting = False
DoEvents
Loop
If IsNumeric(GetValue) = True Then
GetSize = CLng(GetValue)
Else
GetSize = -1
End If
If GetSize <= 0 Then GetSize = -1
m_GettingFileSize = False
GetHTTPFileSize = GetSize
Exit Function
ErrorHandler:
m_GettingFileSize = False
GetHTTPFileSize = -1
' MsgBox err.Number & err.Description
End Function
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData() As Byte
Dim FreeNr As Integer
Dim SizeDone As Long
Dim bDone As Boolean
Dim GetPerc As Integer
Select Case State
Case 1
lstStat.AddItem "Trying to find file..."
Case 2
lstStat.AddItem "File found"
Case 3
lstStat.AddItem "Asking for approval..."
Case 4
lstStat.AddItem "Accepted"
Case 5
lstStat.AddItem "Requesting file..."
Case 6
lstStat.AddItem "Request sent"
Case 7
If FirstResponse = False Then
lstStat.AddItem "Receiving response..."
FirstResponse = True
End If
Case 8
If FirstResponse = False Then
lstStat.AddItem "Response received"
FirstResponse = True
End If
Case 9
lstStat.AddItem "Disconnecting..."
Case 10
lstStat.AddItem "Disconnected"
Case 11
lstStat.AddItem "Error downloading file"
Call cmdCancel_Click
Case 12
If m_GettingFileSize = True Then
Exit Sub
End If
FreeNr = FreeFile
Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr
'this shows the status in real time
'kinda fancy
Do While Not bDone
vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
SizeDone = SizeDone + UBound(vtData)
lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb" 'lets it be shown in kb instead of bytes
GetPerc = (SizeDone / m_FileSize) * 100
If GetPerc > 100 Then GetPerc = 100
If GetPerc < 0 Then GetPerc = 0
Me.Caption = "AutoUpdater - " & GetPerc & "%"
Put #FreeNr, , vtData() 'chunk wegschrijven naar bestand
If UBound(vtData) = -1 Then
bDone = True 'Er zijn geen chunks meer, KLAAR DUS
Else
DoEvents 'Yield to other processes
End If
Loop
Close FreeNr
End Select
lstStat.ListIndex = lstStat.ListCount - 1
If GetPerc = 100 Then
Call cmdCancel_Click
End If
' If Len(err.Description) & Len(err.Source) = 0 Then
'Print vbNullString
' Else
' MsgBox err.Description & " Source : " & err.Source
' End If
End Sub
Mar 30th, 2005, 08:51 PM
#2
Thread Starter
Admodistrator
Re: Another Auto-Downloader
ive thought of a 100x better way to do it:
VB Code:
Private m_GettingFileSize As Boolean
Private m_DownloadingFile As Boolean
Private m_DownloadingFileSize As Long
Private m_LocalSaveFile As String
Private m_FileSize As String
Private FirstResponse As Boolean
Dim ff As Integer
Dim exe As String
Dim filesize As String
Dim x As String
Private Sub cmdCancel_Click()
'On Error Resume Next
Inet1.Cancel
Unload Me
End Sub
Private Sub Form_Load()
If Dir$(App.Path & "/version.txt") <> "" Then 'put inside the version your up to
Open App.Path & "/version.txt" For Input As #ff
Do Until EOF(ff)
Line Input #ff, version
Loop
Close #ff
Else
MsgBox "You deleted version.txt!!It is needed!"
End If
If App.PrevInstance Then
End
End If
x = Inet1.OpenURL("website.com/version.txt", icString) ' this should be the same number as version.txt, until you update. When you update put a new number and include the new version.txt
Dim RemoteFileToGet As String
'Name of the updated exe
RemoteFileToGet = "www.site.rar" 'THIS IS THE DOWNLOAD
FirstResponse = False
m_FileSize = GetHTTPFileSize(RemoteFileToGet)
lstStat.AddItem "Establishing file size & location..."
lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 'shows whole numbers
If x <> version Then
MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
m_LocalSaveFile = App.Path & "\site.rar" 'whatevr you wanna save the file as
Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\yay.exe" & Chr(34) 'just leave this
Else
MsgBox "Your as updated as can be :) "
lstStat.AddItem "Done."
lblStatus.Caption = "0/0"
End If
'error1:
' If err.Number = 0 Then
' MsgBox "Your missing updater.dll and cserver.dll"
'End If
End Sub
Private Function GetHTTPFileSize(strHTTPFile As String) As Long
On Error GoTo ErrorHandler
Dim GetValue As String
Dim GetSize As Long
m_GettingFileSize = True
Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
Do Until Inet1.StillExecuting = False
DoEvents
Loop
GetValue = Inet1.GetHeader("Content-length")
Do Until Inet1.StillExecuting = False
DoEvents
Loop
If IsNumeric(GetValue) = True Then
GetSize = CLng(GetValue)
Else
GetSize = -1
End If
If GetSize <= 0 Then GetSize = -1
m_GettingFileSize = False
GetHTTPFileSize = GetSize
Exit Function
ErrorHandler:
m_GettingFileSize = False
GetHTTPFileSize = -1
' MsgBox err.Number & err.Description
End Function
Private Sub Inet1_StateChanged(ByVal State As Integer)
'On Error g
Dim vtData() As Byte
Dim FreeNr As Integer
Dim SizeDone As Long
Dim bDone As Boolean
Dim GetPerc As Integer
Select Case State
Case 1
lstStat.AddItem "Trying to find file..."
Case 2
lstStat.AddItem "File found"
Case 3
lstStat.AddItem "Asking for approval..."
Case 4
lstStat.AddItem "Accepted"
Case 5
lstStat.AddItem "Requesting file..."
Case 6
lstStat.AddItem "Request sent"
Case 7
If FirstResponse = False Then
lstStat.AddItem "Receiving response..."
FirstResponse = True
End If
Case 8
If FirstResponse = False Then
lstStat.AddItem "Response received"
FirstResponse = True
End If
Case 9
lstStat.AddItem "Disconnecting..."
Case 10
lstStat.AddItem "Disconnected"
Case 11
lstStat.AddItem "Error downloading file"
Call cmdCancel_Click
Case 12
If m_GettingFileSize = True Then
Exit Sub
End If
FreeNr = FreeFile
Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr 'file downloading above
'this shows the status in real time
'kinda fancy
Do While Not bDone
vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
SizeDone = SizeDone + UBound(vtData)
lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb"
GetPerc = (SizeDone / m_FileSize) * 100
If GetPerc > 100 Then GetPerc = 100
If GetPerc < 0 Then GetPerc = 0
Me.Caption = "AutoUpdater - " & GetPerc & "%"
Put #FreeNr, , vtData() 'chunk wegschrijven naar bestand
If UBound(vtData) = -1 Then
bDone = True 'Er zijn geen chunks meer, KLAAR DUS
Else
DoEvents 'Yield to other processes
End If
Loop
Close FreeNr
End Select
lstStat.ListIndex = lstStat.ListCount - 1
If GetPerc = 100 Then
Call cmdCancel_Click
End If
' If Len(err.Description) & Len(err.Source) = 0 Then
'Print vbNullString
' Else
' MsgBox err.Description & " Source : " & err.Source
' End If
End Sub
May 10th, 2005, 02:22 AM
#3
PowerPoster
Re: Another Auto-Downloader
Originally Posted by
|2eM!x
K, first off most of this IS NOT my code. I modified it so that it was an auto-updater instead of just a downloader. Ive fixed numerous bugs and stuff...All you need is an inet1, listbox called lststat, label called lblstatus,command button called cmdcancel
VB Code:
-------------------------------------------------
Private m_GettingFileSize As Boolean
Private m_DownloadingFile As Boolean
Private m_DownloadingFileSize As Long
Private m_LocalSaveFile As String
Private m_FileSize As String
Private FirstResponse As Boolean
Dim ff As Integer
Dim exe As String
dim filesize as string
Private Sub cmdCancel_Click()
'On Error Resume Next
Inet1.Cancel
Unload Me
End Sub
Private Sub Form_Load()
filesize = # ' Okay this is how i do it, make filesize a number, compile your program and upload it. Then see how big it is on the ftp. Type the number in the filesize re-compile and upload. Then it will have the correct filesize.
If App.PrevInstance Then
End
End If
Dim RemoteFileToGet As String
'Name of the updated exe
RemoteFileToGet = "www.bazooka.com" 'THIS IS THE DOWNLOAD
FirstResponse = False
m_FileSize = GetHTTPFileSize(RemoteFileToGet)
lstStat.AddItem "Establishing file size & location..."
lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 ' \/
If Int(m_FileSize) \ 1024 <> filesize Then 'shows in kb instead of other stuff
MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
m_LocalSaveFile = App.Path & "\rarfile or zip.rar"
Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\name of .exe" & Chr(34)
Else
MsgBox "Your exe is updated as can be :) "
lstStat.AddItem "Done."
lblStatus.Caption = "0/0"
End If
End Sub
Private Function GetHTTPFileSize(strHTTPFile As String) As Long
On Error GoTo ErrorHandler
Dim GetValue As String
Dim GetSize As Long
m_GettingFileSize = True
Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
Do Until Inet1.StillExecuting = False
DoEvents
Loop
GetValue = Inet1.GetHeader("Content-length")
Do Until Inet1.StillExecuting = False
DoEvents
Loop
If IsNumeric(GetValue) = True Then
GetSize = CLng(GetValue)
Else
GetSize = -1
End If
If GetSize <= 0 Then GetSize = -1
m_GettingFileSize = False
GetHTTPFileSize = GetSize
Exit Function
ErrorHandler:
m_GettingFileSize = False
GetHTTPFileSize = -1
' MsgBox err.Number & err.Description
End Function
Private Sub Inet1_StateChanged(ByVal State As Integer)
Dim vtData() As Byte
Dim FreeNr As Integer
Dim SizeDone As Long
Dim bDone As Boolean
Dim GetPerc As Integer
Select Case State
Case 1
lstStat.AddItem "Trying to find file..."
Case 2
lstStat.AddItem "File found"
Case 3
lstStat.AddItem "Asking for approval..."
Case 4
lstStat.AddItem "Accepted"
Case 5
lstStat.AddItem "Requesting file..."
Case 6
lstStat.AddItem "Request sent"
Case 7
If FirstResponse = False Then
lstStat.AddItem "Receiving response..."
FirstResponse = True
End If
Case 8
If FirstResponse = False Then
lstStat.AddItem "Response received"
FirstResponse = True
End If
Case 9
lstStat.AddItem "Disconnecting..."
Case 10
lstStat.AddItem "Disconnected"
Case 11
lstStat.AddItem "Error downloading file"
Call cmdCancel_Click
Case 12
If m_GettingFileSize = True Then
Exit Sub
End If
FreeNr = FreeFile
Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr
'this shows the status in real time
'kinda fancy
Do While Not bDone
vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
SizeDone = SizeDone + UBound(vtData)
lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb" 'lets it be shown in kb instead of bytes
GetPerc = (SizeDone / m_FileSize) * 100
If GetPerc > 100 Then GetPerc = 100
If GetPerc < 0 Then GetPerc = 0
Me.Caption = "AutoUpdater - " & GetPerc & "%"
Put #FreeNr, , vtData() 'chunk wegschrijven naar bestand
If UBound(vtData) = -1 Then
bDone = True 'Er zijn geen chunks meer, KLAAR DUS
Else
DoEvents 'Yield to other processes
End If
Loop
Close FreeNr
End Select
lstStat.ListIndex = lstStat.ListCount - 1
If GetPerc = 100 Then
Call cmdCancel_Click
End If
' If Len(err.Description) & Len(err.Source) = 0 Then
'Print vbNullString
' Else
' MsgBox err.Description & " Source : " & err.Source
' End If
End Sub
Run-time error '6':
Overflow
VB Code:
GetPerc = (SizeDone / m_FileSize) * 100
May 10th, 2005, 02:27 AM
#4
PowerPoster
Re: Another Auto-Downloader
Originally Posted by
|2eM!x
ive thought of a 100x better way to do it:
VB Code:
Private m_GettingFileSize As Boolean
Private m_DownloadingFile As Boolean
Private m_DownloadingFileSize As Long
Private m_LocalSaveFile As String
Private m_FileSize As String
Private FirstResponse As Boolean
Dim ff As Integer
Dim exe As String
Dim filesize As String
Dim x As String
Private Sub cmdCancel_Click()
'On Error Resume Next
Inet1.Cancel
Unload Me
End Sub
Private Sub Form_Load()
If Dir$(App.Path & "/version.txt") <> "" Then 'put inside the version your up to
Open App.Path & "/version.txt" For Input As #ff
Do Until EOF(ff)
Line Input #ff, version
Loop
Close #ff
Else
MsgBox "You deleted version.txt!!It is needed!"
End If
If App.PrevInstance Then
End
End If
x = Inet1.OpenURL("website.com/version.txt", icString) ' this should be the same number as version.txt, until you update. When you update put a new number and include the new version.txt
Dim RemoteFileToGet As String
'Name of the updated exe
RemoteFileToGet = "www.site.rar" 'THIS IS THE DOWNLOAD
FirstResponse = False
m_FileSize = GetHTTPFileSize(RemoteFileToGet)
lstStat.AddItem "Establishing file size & location..."
lblStatus.Caption = "0/" & Int(m_FileSize) \ 1024 'shows whole numbers
If x <> version Then
MsgBox Int(m_FileSize) \ 1024 & "Download size" & filesize & "Your size"
m_LocalSaveFile = App.Path & "\site.rar" 'whatevr you wanna save the file as
Inet1.Execute RemoteFileToGet, "GET " & Chr(34) & App.Path & "\yay.exe" & Chr(34) 'just leave this
Else
MsgBox "Your as updated as can be :) "
lstStat.AddItem "Done."
lblStatus.Caption = "0/0"
End If
'error1:
' If err.Number = 0 Then
' MsgBox "Your missing updater.dll and cserver.dll"
'End If
End Sub
Private Function GetHTTPFileSize(strHTTPFile As String) As Long
On Error GoTo ErrorHandler
Dim GetValue As String
Dim GetSize As Long
m_GettingFileSize = True
Inet1.Execute strHTTPFile, "HEAD " & Chr(34) & strHTTPFile & Chr(34)
Do Until Inet1.StillExecuting = False
DoEvents
Loop
GetValue = Inet1.GetHeader("Content-length")
Do Until Inet1.StillExecuting = False
DoEvents
Loop
If IsNumeric(GetValue) = True Then
GetSize = CLng(GetValue)
Else
GetSize = -1
End If
If GetSize <= 0 Then GetSize = -1
m_GettingFileSize = False
GetHTTPFileSize = GetSize
Exit Function
ErrorHandler:
m_GettingFileSize = False
GetHTTPFileSize = -1
' MsgBox err.Number & err.Description
End Function
Private Sub Inet1_StateChanged(ByVal State As Integer)
'On Error g
Dim vtData() As Byte
Dim FreeNr As Integer
Dim SizeDone As Long
Dim bDone As Boolean
Dim GetPerc As Integer
Select Case State
Case 1
lstStat.AddItem "Trying to find file..."
Case 2
lstStat.AddItem "File found"
Case 3
lstStat.AddItem "Asking for approval..."
Case 4
lstStat.AddItem "Accepted"
Case 5
lstStat.AddItem "Requesting file..."
Case 6
lstStat.AddItem "Request sent"
Case 7
If FirstResponse = False Then
lstStat.AddItem "Receiving response..."
FirstResponse = True
End If
Case 8
If FirstResponse = False Then
lstStat.AddItem "Response received"
FirstResponse = True
End If
Case 9
lstStat.AddItem "Disconnecting..."
Case 10
lstStat.AddItem "Disconnected"
Case 11
lstStat.AddItem "Error downloading file"
Call cmdCancel_Click
Case 12
If m_GettingFileSize = True Then
Exit Sub
End If
FreeNr = FreeFile
Open App.Path & "\file your downloading.rar" For Binary Access Write As FreeNr 'file downloading above
'this shows the status in real time
'kinda fancy
Do While Not bDone
vtData = Inet1.GetChunk(1024, icByteArray) ' Get next chunk.
SizeDone = SizeDone + UBound(vtData)
lblStatus.Caption = SizeDone \ 1024 & "kb" & "/" & m_FileSize \ 1024 & "kb"
GetPerc = (SizeDone / m_FileSize) * 100
If GetPerc > 100 Then GetPerc = 100
If GetPerc < 0 Then GetPerc = 0
Me.Caption = "AutoUpdater - " & GetPerc & "%"
Put #FreeNr, , vtData() 'chunk wegschrijven naar bestand
If UBound(vtData) = -1 Then
bDone = True 'Er zijn geen chunks meer, KLAAR DUS
Else
DoEvents 'Yield to other processes
End If
Loop
Close FreeNr
End Select
lstStat.ListIndex = lstStat.ListCount - 1
If GetPerc = 100 Then
Call cmdCancel_Click
End If
' If Len(err.Description) & Len(err.Source) = 0 Then
'Print vbNullString
' Else
' MsgBox err.Description & " Source : " & err.Source
' End If
End Sub
Run-time error '52':
Bad file name or number
VB Code:
Open App.Path & "\version.txt" For Input As #ff
May 10th, 2005, 10:41 PM
#5
Thread Starter
Admodistrator
Re: Another Auto-Downloader
and at the request of brailleschool, a multifile downloader..with alot cleaner code
Attached Files
May 23rd, 2005, 08:17 PM
#6
Lively Member
Re: Another Auto-Downloader
Will this code execute the file after download?
Is it a way to get around the filesize being typed?
How hard is it to add execution of the file after download?
Thx
May 24th, 2005, 02:20 PM
#7
Thread Starter
Admodistrator
Re: Another Auto-Downloader
no, but use shell app.path & "\" & filename
to open after downloading..
to take out the amount being downloaded is easy...if you look thru the code you will see, if not post back
Jun 13th, 2005, 02:14 PM
#8
Member
Re: Another Auto-Downloader
Hello,
I'm using pretty much the same code as the in "autod.rar" except that instead of using HTTP I want to use FTP because I need to put the files being downloaded by the users in a private directory with an encrypted password on the server. And of course, I need the Progress Bar.
The problem is that using FTP, it seems that the GetChunk thing looks pretty much useless. With the UBound(vtData) Function, for example, I get -1 and the file as already been downloaded using the .Execute "GET" Operation in one chunk.
I've tried everything (I think!), is there any way around this? Can a password be used using HTTP???
I'm stuck!
~~~~~~~~~~~~~~~~~~~~
There's always something
~~~~~~~~~~~~~~~~~~~~
<Any link censored by moderator>
Jun 13th, 2005, 05:07 PM
#9
Thread Starter
Admodistrator
Re: Another Auto-Downloader
Im sorry birth, but i have no clue how to send a password over HTTP. Sorry
Jul 27th, 2005, 08:50 AM
#10
Junior Member
Re: Another Auto-Downloader
This code is almost what I'm looking for, I would like this to display the time taken to download all the files, this way I can test my internet connection, is there a way the time taken can be added to this code please, also a progress bar would be nice
Chetty
Jul 28th, 2005, 02:03 PM
#11
Thread Starter
Admodistrator
Re: Another Auto-Downloader
To get the time taken, just use gettickcount and use it before downloading, and while downloading.
To use the progressbar, use GetPerc on it
Jul 29th, 2005, 03:03 AM
#12
Junior Member
Re: Another Auto-Downloader
Thanks for the reply but I wish I was clever enough to understand what you are taking about, could you post an example please
Chetty
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Click Here to Expand Forum to Full Width