[TUT]Updater

Posts 1–12 of 12 · Page 1 of 1
[TUT]Updater
Ok finally i have finished my auto updater - it updates by your app passing arguments to the updater.exe in a Process.Start, it cannot be opened by clicking on it, it just says the program has stopped working. For the program to recognise there is a new update you need to upload a new version.ini file onto the same link as its previous one(again you can do this with Fileden just set option to Overwrite) with a higher version number than before(just a single number e.g 1 or 2 or 14) then when the program downloads the version.ini it checks if that version is higher than the .INI file on your computer and if this is true then it initiates update. On the internet you need links for a version.ini file(SEE BELOW FOR HOW IT SHOULD BE SET OUT) and your download link(a .zip or .exe DIRECT LINK). i suggest FileDen as it allows direct links for .zip(hardly any sites let you download a .exe) and this is what you need for this to work. First you need to obtain the updater.exe by building the project i have attached at the bottom. Then put the updater.exe in the directory of wherever your application is. Also you need to put code into your project in the specified places and change a few links.
Code for your project
Delete the #Region and #End Region parts and copy and paste the wherever the region says( Variables Go at the top not in a sub but inside the class )
Code:
      Imports System.Runtime.InteropServices
      Imports System.Text
      #Region " VARIABLES "
          Dim downloadedINIpath As String = "http://www.example.com/version.ini"
          Dim fullpath1 As String = IO.Path.Combine(Application.StartupPath, "settings.ini") 'Path of local .INI file
          Dim fullpath2 As String = IO.Path.Combine(Application.StartupPath, "version.ini") 'Path of downloaded .INI file
          Dim Version As String = My.Application******.Version.ToString 'DONT EDIT
      #End Region

      #Region " ON FORM CLOSING "
          Dim fullpath3 As String = IO.Path.Combine(Application.StartupPath, "version.ini") 'Updates Path of downloaded .INI file
          Dim fileExists As Boolean = My.Computer.FileSystem.FileExists(fullpath3)
              If fileExists = True Then
                  My.Computer.FileSystem.DeleteFile(fullpath3, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently) 'Clean up version.ini when app is shutdown
              End If
      #End Region

      #Region " ON FORM LOAD "
      If My.Computer.FileSystem.FileExists(fullpath1) = False Then
                      INIReadWrite.WriteINI(fullpath1, "settings", "version", Version) 'Write new local .INI file if it doesn't exist
                  Else
                      If INIReadWrite.ReadINI(fullpath1, "settings", "version") <> Version Then
                          INIReadWrite.WriteINI(fullpath1, "settings", "version", Version)
                      End If
                  End If
              If My.Computer.FileSystem.FileExists(IO.Path.Combine(Application.StartupPath, "version.ini")) Then
                  My.Computer.FileSystem.DeleteFile(IO.Path.Combine(Application.StartupPath, "version.ini"), FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently) 'If previous downloaded .INI file still exists then delete it
              End If
              My.Computer.Network.DownloadFile(downloadedINIpath, fullpath2) 'Download new .INI file
              If INIReadWrite.ReadINI(fullpath2, "settings", "version") > INIReadWrite.ReadINI(fullpath1, "settings", "version") Then 'Check the downloaded .INI file version against the local .INI files version
                  If MsgBox("A new update is available, do you want to update now?", MsgBoxStyle.YesNo, "New update") = MsgBoxResult.Yes Then 'If new update found, ask if they want to update now

                      Try
          Dim a1 As String = """http://www.example.com/myapp(.zip/.exe)""" 'Address of new program to download(Change this to yours(can be either .zip or .exe file extensions))
          Dim a2 As String = """" & Application.StartupPath & """" 'Download it to the applications folder
          Dim a3 As String = """" & My.Application******.AssemblyName & """" 'Gives updater the applications name
          Dim a4 As String = a1 & " " & a2 & " " & a3
                          Process.Start("Updater.exe", a4) 'Start the updater
                      Catch ex As Exception
                          Application.Exit() 'If cannot start for some reason, exit the program.
                      End Try
                  End If
              Else
              End If
      #End Region

          Class INIReadWrite

              <DllImport("kernel32.dll", SetLastError:=True)> _
              Private Shared Function GetPrivateProfileString(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As StringBuilder, ByVal nSize As Integer, ByVal lpFileName As String) As Integer
              End Function

              <DllImport("kernel32.dll", SetLastError:=True)> _
              Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Boolean
              End Function
              Public Shared Function ReadINI(ByVal File As String, ByVal Section As String, ByVal Key As String) As String
                  Dim sb As New StringBuilder(500)
                  GetPrivateProfileString(Section, Key, "", sb, sb.Capacity, File)
                  Return sb.ToString
              End Function

              Public Shared Sub WriteINI(ByVal File As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
                  WritePrivateProfileString(Section, Key, Value, File)
              End Sub

          End Class
This is how your version.ini should look like:
Code:
[settings]
version=1.0.0.0
(Put whatever version you want here - if it is more than the one on your computer it will update)
To Get the Updater.exe you need to BUILD the project(Not Debug, only build because it wont run as i said earlier in this post.)
I have no problem with you using it in your project or whatever as long as you dont call it your own.
Please give me some feedback as well on this as it took me a long time to make. Thankyou
Nice one, but there are much faster method via internet.

I.E

[php]
Dim build As Integer = 1
Dim q As Integer = Nothing

Dim clien As New Net.WebClient
q = clien.DownloadString("http://ZOMGPRO.********.com/resources/Version.txt")
If q = build Then
MsgBox("Your version is the latest!")

ElseIf MessageBox.Show("Your version is outdated, would you like to update?", "Outdated software detected!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'do your downloading etc here, that stuff is pretty straightforward.
End If
[/php]

That's just an easy way to quickly detect whether the version is the latest or not. Via your own hosting site (in this case ********) you host a .txt document with content "0" ONLY and it quickly reads that, and compares it to the inbuilt build number, if they do not match, a prompt to download the new software is called. If you release an updated version of your software, it's a simple matter of deleting the previous "Version.txt" file from yola, and creating a new one with content "1" or something like that. On your next version of the program all you have to do is declare the integer "build" with the same integer used in Version.txt

Hope that was clear.

J-Deezy.
Quote Originally Posted by Jason View Post
Nice one, but there are much faster method via internet.

I.E

[php]
Dim build As Integer = 1
Dim q As Integer = Nothing

Dim clien As New Net.WebClient
q = clien.DownloadString("http://ZOMGPRO.********.com/resources/Version.txt")
If q = build Then
MsgBox("Your version is the latest!")

ElseIf MessageBox.Show("Your version is outdated, would you like to update?", "Outdated software detected!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
'do your downloading etc here, that stuff is pretty straightforward.
End If
[/php]

That's just an easy way to quickly detect whether the version is the latest or not. Via your own hosting site (in this case ********) you host a .txt document with content "0" ONLY and it quickly reads that, and compares it to the inbuilt build number, if they do not match, a prompt to download the new software is called. If you release an updated version of your software, it's a simple matter of deleting the previous "Version.txt" file from yola, and creating a new one with content "1" or something like that. On your next version of the program all you have to do is declare the integer "build" with the same integer used in Version.txt

Hope that was clear.

J-Deezy.
I luv you man.
Webclients <3

Give more detailed information.
Quote Originally Posted by Blubb1337 View Post
Webclients <3

Give more detailed information.
Me or Lone Rider?
FYI Updaters are banned on MPGH, so don't make any releases containing updaters
Quote Originally Posted by Lolland View Post
FYI Updaters are banned on MPGH, so don't make any releases containing updaters
Correction: AUTO updaters are banned. You can get away with an updater that says "go get the latest version at MPGH" instead of downloading the file. It means the user has to get off their lazy ass but it works. I know this cause that's what I did with xInfinity's updater after the rule came in /
Yah but code is appreciated, shows a higher variety to do things.
Way too long, when it is hardly a task of 10 -15 lines !! Anyways, thnx for sharing !!
Np i like sharing it but i didnt know it could faster.
But if it is usefull thanks would help
Bump,
More Reactions? :P
Quote Originally Posted by Lone Rider View Post
Bump,
More Reactions? :P
Dude, the most active members of the section have spoken !! /yea
Posts 1–12 of 12 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

None

Talk with us