Feb 18, 2011 08:53 AM
(This post was last modified: Feb 19, 2011 03:58 AM by ManDoR.)
Hey everybody !
I've seen a lot of people that asked for an update system... I've seen some system, but not really working... So I give you mine :) It's not optimized, so if you have comment, please post ! :)
So here is the tut :
First, I explain you how it works : The system check the content of a file that is in your database : the number of your new version. If this number isn't equal as the version of the program, it opens the update form. In this form, there is a button, that when you click on it, save the content of the file where is saved the number of the newest version, and download it in your server. So you have to name your newest version same as the number that is in the file on your server ! After that, it UnRAR it, and install it...
Hope it will help you...
PS: Sorry if there are any french languages, I'm french :p
I've seen a lot of people that asked for an update system... I've seen some system, but not really working... So I give you mine :) It's not optimized, so if you have comment, please post ! :)
So here is the tut :
First, I explain you how it works : The system check the content of a file that is in your database : the number of your new version. If this number isn't equal as the version of the program, it opens the update form. In this form, there is a button, that when you click on it, save the content of the file where is saved the number of the newest version, and download it in your server. So you have to name your newest version same as the number that is in the file on your server ! After that, it UnRAR it, and install it...
Code for your main form, that check updates :
Code
Public Sub check_update()
Dim webResponse3 As System.Net.HttpWebResponse = Nothing
Dim webRequest3 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http:/www.example.com/the_file_where_is_saved_the_number_of_your_newest_version.html")
Try
webResponse3 = DirectCast(webRequest3.GetResponse(), System.Net.HttpWebResponse)
Dim srResp As System.IO.StreamReader
srResp = New System.IO.StreamReader(webResponse3.GetResponseStream())
Dim last_version As String
last_version = srResp.ReadToEnd
If Not derniere_version = "number version, like 1.2.2" Then
Me.Hide()
update.Show()
Me.Close()
Else
OtherForm.Show()
End If
Catch ex As Exception
MsgBox("Erreur while verifying update...")
OtherForm.Show()
End Try
End SubCode for your update form, that download and instal update (you need UnRAR.exe in the same folder of your app ! download : here):
Code
Public last_version as string
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
check_version()
If Not Dir("update.rar") = "" Then
Kill("update.rar")
End If
If My.Computer.Network.IsAvailable Then
Dim newfile As String = "update.rar"
Try
MsgBox("Download will start. If application freeze, don't worry, it's normal !")
My.Computer.Network.DownloadFile("http://www.frag-n-roses.com/downloads/Release v" & last_version & ".rar", newfile)
MsgBox("Download finished !" & vbCrLf & "Please wait while update system unzip updated program...")
UnRAR(".\update.rar", ".\")
Catch
MsgBox("Error while downloading !")
End Try
Else
MsgBox("You're NOT connected to internet ! Please check your connect...")
End If
End Sub
Public Sub check_version()
Dim webResponse3 As System.Net.HttpWebResponse = Nothing
Dim webRequest3 As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http:/www.example.com/the_file_where_is_saved_the_number_of_your_newest_version.html")
Try
webResponse3 = DirectCast(webRequest3.GetResponse(), System.Net.HttpWebResponse)
Dim srResp As System.IO.StreamReader
srResp = New System.IO.StreamReader(webResponse3.GetResponseStream())
last_version = srResp.ReadToEnd
Catch ex As Exception
End Try
End Sub
Private Function UnRAR(ByVal FileName As String, ByVal ExtractDir As String) As Boolean
Dim Success As Boolean = False
Dim CodeDeSorti As Integer
Try
Dim proc As New Process()
With proc
With .StartInfo
.UseShellExecute = False
#If DEBUG Then
.FileName = "UnRAR.exe"
#Else
.FileName = My.Application.Info.DirectoryPath & "UnRAR.exe"
#End If
.Arguments = " x -ibck -inul -or -y " & " """ & FileName & """ """ & ExtractDir & """"
.WorkingDirectory = ExtractDir
.WindowStyle = ProcessWindowStyle.Hidden
.CreateNoWindow = True
End With
.Start()
.WaitForExit()
CodeDeSorti = .ExitCode
.Close()
End With
If CodeDeSorti < 2 Then
Success = True
End If
Catch ex As Exception
MsgBox("UpDate system can't install updated program... Please do it yourself !" & vbCrLf & vbCrLf & "Program will close when you'll press OK...)")
End Try
Return Success
End FunctionHope it will help you...
PS: Sorry if there are any french languages, I'm french :p



