Emcranks Auto Updater-VBForums
Results 1 to 13 of 13

Thread: Emcranks Auto Updater

  1. #1

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    562

    Emcranks Auto Updater

    Updated: 17/7/2010 [16:18 - Saturday]
    Fixed writing permissions.

    --------
    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 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 )
    VB.NET Code:
    1. Imports System.Runtime.InteropServices
    2. Imports System.Text
    3.  
    4. #Region " VARIABLES "
    5.     Dim downloadedINIpath As String = "http://www.example.com/version.ini"
    6.     Dim fullpath1 As String = IO.Path.Combine(FileIO.SpecialDirectories.CurrentUserApplicationData, "settings.ini") 'Path of local .INI file
    7.     Dim fullpath2 As String = IO.Path.Combine(FileIO.SpecialDirectories.CurrentUserApplicationData, "version.ini") 'Path of downloaded .INI file
    8. Dim newUpdaterPath As String = IO.Path.Combine(FileIO.SpecialDirectories.CurrentUserApplicationData, "Updater.exe") 'Path of Updater.exe
    9.     Dim Version As String = My.Application.Info.Version.ToString 'DONT EDIT
    10. #End Region
    11.  
    12. #Region " ON FORM CLOSING "
    13.     Dim fullpath3 As String = IO.Path.Combine(FileIO.SpecialDirectories.CurrentUserApplicationData, "version.ini") 'Updates Path of downloaded .INI file
    14.     Dim fileExists As Boolean = My.Computer.FileSystem.FileExists(fullpath3)
    15.         If fileExists = True Then
    16.             My.Computer.FileSystem.DeleteFile(fullpath3, FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently) 'Clean up version.ini when app is shutdown
    17.         End If
    18. #End Region
    19.  
    20. #Region " ON FORM LOAD "
    21.  
    22. If My.Computer.FileSystem.FileExists(fullpath1) = False Then
    23.                 INIReadWrite.WriteINI(fullpath1, "settings", "version", Version) 'Write new local .INI file if it doesn't exist
    24.             Else
    25.                 If INIReadWrite.ReadINI(fullpath1, "settings", "version") <> Version Then
    26.                     INIReadWrite.WriteINI(fullpath1, "settings", "version", Version)
    27.                 End If
    28.             End If
    29.         If My.Computer.FileSystem.FileExists(IO.Path.Combine(FileIO.SpecialDirectories.CurrentUserApplicationData, "version.ini")) Then
    30.             My.Computer.FileSystem.DeleteFile(IO.Path.Combine(FileIO.SpecialDirectories.CurrentUserApplicationData, "version.ini"), FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently) 'If previous downloaded .INI file still exists then delete it
    31.         End If
    32.         My.Computer.Network.DownloadFile(downloadedINIpath, fullpath2) 'Download new .INI file
    33.         If INIReadWrite.ReadINI(fullpath2, "settings", "version") <> INIReadWrite.ReadINI(fullpath1, "settings", "version") Then 'Check the downloaded .INI file version against the local .INI files version
    34.             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
    35.                 Try
    36.     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))
    37.     Dim a2 As String = """" & Application.StartupPath & """" 'Download it to the applications folder
    38.     Dim a3 As String = """" & My.Application.Info.AssemblyName & """" 'Gives updater the applications name
    39.     Dim a4 As String = a1 & " " & a2 & " " & a3
    40.                     Process.Start(newUpdaterPath, a4) 'Start the updater
    41.                 Catch ex As Exception
    42.                     Application.Exit() 'If cannot start for some reason, exit the program.
    43.                 End Try
    44.             End If
    45.         Else
    46.  
    47.         End If
    48. #End Region
    49.  
    50.     Class INIReadWrite
    51.  
    52.         <DllImport("kernel32.dll", SetLastError:=True)> _
    53.         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
    54.         End Function
    55.  
    56.         <DllImport("kernel32.dll", SetLastError:=True)> _
    57.         Private Shared Function WritePrivateProfileString(ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Boolean
    58.         End Function
    59.  
    60.         Public Shared Function ReadINI(ByVal File As String, ByVal Section As String, ByVal Key As String) As String
    61.             Dim sb As New StringBuilder(500)
    62.             GetPrivateProfileString(Section, Key, "", sb, sb.Capacity, File)
    63.             Return sb.ToString
    64.         End Function
    65.  
    66.         Public Shared Sub WriteINI(ByVal File As String, ByVal Section As String, ByVal Key As String, ByVal Value As String)
    67.             WritePrivateProfileString(Section, Key, Value, File)
    68.         End Sub
    69.  
    70.     End Class
    How your version.ini file should look
    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
    Attached Files Attached Files
    Last edited by Emcrank; Jul 17th, 2010 at 10:18 AM.

  2. #2
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,243

    Re: Emcranks Auto Updater

    Big text at the end of the post is not required. Also, all codebank files are required to have the source code, and not compiled binaries, no matter if you include a virus scan or not.

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Emcranks Auto Updater

    Thank you for your CodeBank submission.

    Per this CodeBank policy, I have removed your attachment.

    We welcome and appreciate all entries into our Codebank, but ask that source code only be included with anything attached.

    Thank you.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    562

    Re: Emcranks Auto Updater

    Ok can you delete this thread then please

  5. #5
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,595

    Re: Emcranks Auto Updater

    Why? Why not just post the project files so that people can use it?
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  6. #6

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    562

    Re: Emcranks Auto Updater

    Because i know people will download it and call it there own and it took me a long time to make.

  7. #7
    Junior Member ComputerDownloads's Avatar
    Join Date
    May 2010
    Posts
    26

    Re: Emcranks Auto Updater

    Quote Originally Posted by Emcrank View Post
    Because i know people will download it and call it there own and it took me a long time to make.
    Then why post it in the CodeBack ?

  8. #8

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    562

    Re: Emcranks Auto Updater

    erm because the program was the bit that took me a long time to make.

  9. #9
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    3,817

    Re: Emcranks Auto Updater

    Quote Originally Posted by Emcrank View Post
    erm because the program was the bit that took me a long time to make.
    If you're wanting to share it with people but not post the source code here then you'll need to share it on another site. Compiled files are not allowed here on vbf in any of the forums.

  10. #10
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,595

    Re: Emcranks Auto Updater

    Because i know people will download it and call it there own and it took me a long time to make.
    I can appreciate that but firstly I dont really think anyone will do that - secondly, look at the stuff that other people have put in the codebank... I'm sure a lot of it has taken much longer than however long it took you to make this. I know I personally have spent over 10 hours in total on just a single item that I've posted here and if you add up all of the threads I've posted in the codebank there is easily over 40 hours worth of my work - I'm not trying to show off or anything, I'm just using that as an example as obviously I dont know exactly how long other people have spent on items they have added.

    I know I've seen quite a few threads recently in the VB.NET forum asking about how to make an auto updater program for their app, so I think if this solution of yours works well then it would help a lot of people out.

    Oh and another benefit of putting the source code here is that people can give you advice on how it could be improved or alternative ways to do something, so you would benefit from it as well.

    EDIT: Plus I noticed you just edited your thread about moving a borderless form (here) so that the code is now very nearly identical to the code I posted in this post that I gave you a link to in your thread, the only difference is that you have taken some of my comments out. Now I have no problem with that, but I think its a bit unfair to say that you wont share something because you dont want other people passing it off as their own when you have just done pretty much exactly that
    Last edited by chris128; Jul 8th, 2010 at 02:46 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  11. #11

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    562

    Re: Emcranks Auto Updater

    You were the one that told me to use your code instead though, anyway i do understand what your saying. I will upload it all soon.

    EDIT: The project is uploaded and all the compiled code is removed.
    Last edited by Emcrank; Jul 8th, 2010 at 03:17 PM.

  12. #12
    PowerPoster formlesstree4's Avatar
    Join Date
    Jun 2008
    Location
    On the Internet
    Posts
    3,243

    Re: Emcranks Auto Updater

    The CodeBank is a place where we share our work with others. Whether or not it gets credit in other people's applications is a risk we take. If we wanted to, we could sell them instead on a different site, but we offer our stuff free and open source. My latest two submissions, I've spent several weeks on them (one of them, over a month and a half), and I put them out so that way others won't have to go through the same stuff I have. Credit is optional, and they're really SDK's for making their own content around it.

    It's common courtesy to give credit where credit's due, but posting a compiled EXE in the codebank is (as been stated) against the rules, and someone can just decompile it and get the source code anyway (or very close to it).

  13. #13

    Thread Starter
    Fanatic Member Emcrank's Avatar
    Join Date
    Jan 2009
    Posts
    562

    Re: Emcranks Auto Updater

    Err yes chris has just told me all this. Stop flaming me now. I get the idea.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.