
Originally Posted by
Hawk_
OMG thank you hawky.
I wanna see how you guys would make something similar to my auto updater but better.
Program Idea: auto updater
Additional Information: has to auto update from a ftp site
Features: same as above, progress bar for download &checking if download is needed
GUI Ideas: nothing special
[php]'This code is fully self-written.
'(c) Blubb1337
'Enjoy
Imports System.IO
Imports System.Text
Imports System.Net
'Since a lot of people seem to need a proper downloader, I decided 2 release a PROPER updater
'Most updater use my.network.downloadfile, however this does not show progress and it generally sucks!
'This updater uses a webclient. Using a webclient, you can display the current progress, the received bytes
'and the total bytes to receive.
'You also have a download completed event.
'How to use this?
'This is really easy, the only thing you need to change -> 4 Variables
'links
'Private Const _version As String = "http:/version.txt"
'Private Const _FileToDL As String = "http:/Recorder.exe"
'Private Const _log As String = "http://changelog.txt"
'name
'Private Const _Name As String = "Recorder"
'I think this is pretty self-explanatory. You sure don't need to have a log, you can just take it out.
'Furthermore, this updater uses multithread to check the newest version/load the checklog.
'Usually the program executes one sub/function/action after another. With multithreads you can run
'different subs/functions or whatever at the same time!
'You may also change the prioritys of the multithreads
'If you want to unpack a file after it has been downloaded, you can go for the sharpziplibrary:
'http://www.mpgh.net/forum/33-visual-basics/126996-tutorial-unzipping-vb-net.html
'Sub ExtractZip(ByVal FileToUnzip As String, ByVal WhereToSave As String, Optional ByVal Password As String = "")
'Dim fz As New FastZip
' fz.Password = Password
' fz.ExtractZip(FileToUnzip, WhereToSave, "")
' End Sub
Public Class Form1
#Region "Declarations"
'new webclient to for downloading
WithEvents webC As New Net.WebClient
Private apppath As String = Application.StartupPath & "\"
Private filename As String
'avoid the same filename twice
Private i As Integer = 1
'received/total bytes
Private total, current As Integer
'links
Private Const _version As String = "http://version.txt"
Private Const _FileToDL As String = "http://Recorder.exe"
Private Const _log As String = "http://changelog.txt"
'name
Private Const _Name As String = "Recorder"
'get a pages source code
Private Function loadPage(ByVal page As String)
Dim req As WebRequest = WebRequest.Create(page)
Dim resp As WebResponse = req.GetResponse()
Dim s As Stream = resp.GetResponseStream()
Dim sr As StreamReader = New StreamReader(s, Encoding.ASCII)
Dim doc As String = sr.ReadToEnd()
Return doc
End Function
#End Region
#Region "Download/Progress"
Private Sub cmdDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDownload.Click
If cmdDownload.Text = "Download" Then
'start backgroundworker
bgwDownload****nWorkerAsync()
Else
'start the program
Process.Start(filename)
'end this application
Application.Exit()
End If
End Sub
Private Sub webC_DownloadFileCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles webC.DownloadFileCompleted
' MsgBox("Download complete." & vbNewLine & vbNewLine _
' & "Saved at: " & filename)
cmdDownload.Text = "Start " & _Name
cmdDownload.Enabled = True
End Sub
Private Sub webC_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles webC.DownloadProgressChanged
current = e.BytesReceived 'bytes it dled already
total = e.TotalBytesToReceive 'total bytes it has to dl
If total <> current Then 'if they are not the same
cmdDownload.Enabled = False
End If
pbProgress.Value = e.ProgressPercentage 'show the procent percentage
'pbProgress.Text = CInt(current / 1024) & "/" & CInt(total / 1024) & " KB received | " & e.ProgressPercentage & " %"
lblprogress.Text = CInt(current / 1024) & "/" & CInt(total / 1024) & " KB received | " & e.ProgressPercentage & " %"
End Sub
Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bgwDownload.DoWork
'start downloading the file
webC.DownloadFileAsync(New Uri(_FileToDL), filename)
End Sub
#End Region
#Region "Startup"
Private Sub UpdateApp_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'to avoid threadovertaking actions -> program would just end
Control.CheckForIllegalCrossThreadCalls = False
'multithread so multiple things can be done at the same time -> load changelog
Dim cl As New Threading.Thread(AddressOf changelog)
cl.Priority = Threading.ThreadPriority.Highest
cl.Start()
'show the current version of the application
lblCurV.Text &= Application.ProductVersion
'to not replace the old version
Do While IO.File.Exists(apppath & _Name & "_Updated - " & i & ".exe")
i += 1
Loop
filename = apppath & _Name & "_Updated - " & i & ".exe"
End Sub
Private Sub changelog()
txtChangeLog.Text = loadPage(_log)
End Sub
Private Sub newversion()
lblNewV.Text &= loadPage(_version)
End Sub
Private Sub UpdateApp_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
Dim checkv As New Threading.Thread(AddressOf newversion)
checkv.Priority = Threading.ThreadPriority.Highest
checkv.Start()
End Sub
#End Region
End Class [/php]
Updater for MPGH.rar - Jotti's malware scan
VirusTotal - Free Online Virus, Malware and URL Scanner
