• Hello Guest! Welcome to ConsoleCrunch, to help support our site check out the premium upgrades HERE! to get exclusive access to our hidden content.
  • Unable to load portions of the website...
    If you use an ad blocker addon, you should disable it because it interferes with several elements of the site and blocks more than just adverts.
  • Read Rules Before Posting Post Virus Scans with every program.

[VB.NET]Auto Up******

1UP

Member
Now I'm sure there are more then 1 way to do this (and possibly easier ways) but this is just one way I figured out how to update software with just a text file.

Ive used it for a few projects and did notice some problems with the code, of which I will also go over so you don't end up with a program hanging when you goto use this yourself.

First of all I'll be going over multi-threading and reading a file from the internet and then compare it to what you are currently using.


To get us started:

If you are using a webserver simply making a text file called versionnumber.txt (or call it whatever you want, you'll just need to remember to change the code later on)


We need to set our imports:

Code:
Imports System.Net
Imports System.IO
Imports System.Threading

Our module level variable:

Code:
Private WithEvents _Downloader As WebFileDownloader

Now we are going to make a Sub routine so we can call this at anytime down the road if we need it.
Code:
Public Sub Update()
  Dim prodVersion As String = System.Text.Encoding.ASCII.GetString((webclient.DownloadData("http://www.arenagamerz.com/downloads/launcher/versionNumber.txt")))
  Dim updatelink As String = "http://www.arenagamerz.com/downloads/launcher/arenagamerzLauncher.exe"
  Dim UpdateLocation As String = My.Computer.FileSystem.CurrentDirectory

  'Updater
  If Me.ProductVersion() = prodVersion Then

  Else
  MsgBox("New Update available. Downloading")
  Try


  Try
  _Downloader = New WebFileDownloader
  _Downloader.DownloadFileWithProgress(updatelink, UpdateLocation & GetFileNameFromURL(updatelink))
  Catch ex As Exception
  MessageBox.Show("Error: " & ex.Message)
  End Try
  Catch ex As Exception

  End Try

  End If
  End Sub

This code (when called) will look for the specified filename on whatever server you are trying to get to. In this case we are looking for:
"http://www.arenagamerz.com/downloads/launcher/versionNumber.txt"

Updatelocation is where the updated client will be placed (you can make that anywhere you want, for the sake of this post I just made it the directory where this program is , which will cause a problem with overwritting)

Now there is a piece missing from this which is the function for getfilenamefromURL which will look like this:

Code:
Private Function GetFileNameFromURL(ByVal URL As String) As String
  If URL.IndexOf("/"c) = -1 Then Return String.Empty

  Return "\" & URL.Substring(URL.LastIndexOf("/"c) + 1)
  End Function

This is what is used to get the file name to download.

If you were to do this in FormLoad the program would hang because it's going out to the net to see if the initial file exists, if it doesn't it will take a long time to error out and the form won't appear for a while. So to make it so the form will appear and still do the check we are going to put this Sub in a thread.

Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'Start a new thread for the update Sub
  Dim updateApp As Thread
  updateApp = New Thread(AddressOf Me.Update)
  updateApp.Start()

And that's all there is to it
 
Did you really make all of these o-o?
 
You made all of these tutorials?
 
General chit-chat
Help Users
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Keonhacai5vip11 is our newest member. Welcome!
  • Chat Bot:
    smoore99 is our newest member. Welcome!
  • Chat Bot:
    Pagliosa is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    prototypefox is our newest member. Welcome!
  • Chat Bot:
    maogege is our newest member. Welcome!
  • Chat Bot:
    ShadowPsy974 is our newest member. Welcome!
  • Chat Bot:
    Ghost8099 is our newest member. Welcome!
  • @ Ghost8099:
    Yurrrrrr
  • @ Ghost8099:
    Can we get a new link here brotha
  • Chat Bot:
    Mason Fo has left the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    wzxcvcv is our newest member. Welcome!
  • Chat Bot:
    cnood is our newest member. Welcome!
  • Chat Bot:
    zoumar is our newest member. Welcome!
  • Chat Bot:
    bestsmmlike is our newest member. Welcome!
  • Chat Bot:
    josuelton silva is our newest member. Welcome!
  • Chat Bot:
    josuelton silva has posted a new reply in the thread "Console ID #8671".
  • Chat Bot:
    ideasforlifetv is our newest member. Welcome!
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    Christo has joined the room.
  • Chat Bot:
    QM|T_JinX has joined the room.
  • Chat Bot:
    MATthewN is our newest member. Welcome!
      Chat Bot: MATthewN is our newest member. Welcome!
      Back
      Top