a_jam_sandwich
Well-known member
for those of you looking to create Live updaters and were wondering how heres so code me and tHe_cLeanER have put together with progress bar support and saving to files.
Should be fairly easy to understand, Ill have a program soon as a Live Updater in test at the mo.
It will support versioning from a standard HTTP server
sURL is where your requesting your download from e.g.
www.mysite.com/files/
filename is the file your downloading
myprogram.exe
incase you were wondering
Code:
Function DownloadChunks(ByVal sURL As String, ByVal pProgress As ProgressBar, ByVal Filename As String)
Dim wRemote As System.Net.WebRequest
Dim URLReq As HttpWebRequest
Dim URLRes As HttpWebResponse
Dim FileStreamer As New FileStream(Filename, FileMode.Create)
Dim bBuffer(999) As Byte
Dim iBytesRead As Integer
Try
URLReq = WebRequest.Create(sURL)
URLRes = URLReq.GetResponse
Dim sChunks As Stream = URLReq.GetResponse.GetResponseStream
pProgress.Maximum = URLRes.ContentLength
Do
iBytesRead = sChunks.Read(bBuffer, 0, 1000)
FileStreamer.Write(bBuffer, 0, iBytesRead)
If pProgress.Value + iBytesRead <= pProgress.Maximum Then
pProgress.Value += iBytesRead
Else
pProgress.Value = pProgress.Maximum
End If
Loop Until iBytesRead = 0
pProgress.Value = pProgress.Maximum
sChunks.Close()
FileStreamer.Close()
Return sResponseData
Catch
MsgBox(Err.Description)
End Try
End Function
Should be fairly easy to understand, Ill have a program soon as a Live Updater in test at the mo.
It will support versioning from a standard HTTP server
sURL is where your requesting your download from e.g.
www.mysite.com/files/
filename is the file your downloading
myprogram.exe
incase you were wondering