Info on Creating a Live Updater - Download code

a_jam_sandwich

Well-known member
Joined
Dec 10, 2002
Messages
367
Location
Uk
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.

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
 
Ive come to a BIG problem

Downloading from the LAN connection works great
Donwloading from a modem (Only One Though) come up with the error (403) access to this page is forbiddon

Anyone Help
 
This is a great bit of code....

I want to implement it into my app but Ill have multiple files to update and not always the same files. Can this work on whole folders? ie look at a folder on my website and download the entire contents of that folder. If not do you know how hard it would be to unzip and zip file automatically when it has finished downloading?

Russ
 
OK

I miss understood the files. Wow. This really is good code..

I am getting errors though when trying to use subfolders. Can someone just clarify how its supposed to work if I need to put a file in a subdirectory on the local machine ?

I have this as my update.dat file but it genrates errors.

Code:
[VERSIONLIST]
VERSION=1.2.2

updateinformation=Welcome to the updater for Project Database Suite

[UPDATELIST]

# If the version is > 1 e.g. 1.0.1 - 1.0.0 = 1 where 1.0.1 is download version then download
# all files marked FILE# *numbers must be in sequence*

# you can include subfolders e.g. myfolder/myfile the subfolder is the folder located on the
# computer being downloaded to NOT the HTTP server

#FILE1=<FILENAME>
#FILE2=<FILENAME>
#FILE3=<FILENAME>
#FILE4=<FILENAME>

FILE1=lists/folders.lst

# If the version is > 1 e.g. 1.0.2 - 1.0.0 = 2 where 1.0.1 is download version then download
# all files marked FILE-UPDATE# *numbers must be in sequence*

#FILE-UPDATE1=<FILENAME>
#FILE-UPDATE2=<FILENAME>
#FILE-UPDATE3=<FILENAME>
#FILE-UPDATE4=<FILENAME>

FILE-UPDATE1=folders.lst

# Created by Andrew Duff, (C) 2003

This is the line in the log file...
Code:
05/04/2003 15:46:54     ERRROR Could not find a part of the path "D:\Development Resources\Downloads\Updater.Net\bin\TEST\Downloading_lists\folders.lst"., 76

Russ
 
I figured that one out as well. It did work when the folder existed.

Im going to try to extend your code if you dont mind. I want to be able to create folders, delete files and possible executre ReadMe files when a user updates the app. It should only be a small extension to make all that possible though.

Russ
 
Its there to be changed if you look out on www.codeconcepts.co.uk Ill be adding controls there including a control for downloading a lot more user friendly than this app

Btw post your code once your done and share the wealth

Andy
 
Last edited by a moderator:
I have been working on an extended version of LiveUpdater that includes the ability to create local folders, delete local files and execute a downloaded file. Its also uses xml rather than ini and dat. Its early days but you can get it here

Download project here

Its a little buggy, but Im working on it.
 
Last edited by a moderator:
Back
Top