Results 1 to 13 of 13

Thread: AKLib.SimpleUpdater

  1. #1
    Hyperactive Member _powerade_'s Avatar
    Join Date
    Sep 08
    Location
    Kyrksæterøra, Norway
    Posts
    321

    AKLib.SimpleUpdater

    AKLib.SimpleUpdater
    A simple way to let your application install updates

    Written in Visual Studio 2010

    Edit: Changed the attachments to Zip


    Instructions:
    1. Download, extract and build the two attachments
      .
    2. Add a reference to AKLib from your designer
      .
    3. Copy SimpleUpdater.exe to your applications directory
      .
    4. Create a file called 'current.txt'

      • Layout of the file should be like this:
        Legend: The file that you want to update,current version,the folder where you want to download the update

        myApplication.exe,1.0.0.0,C:\MyApplication
        myDll.dll,1.0.0.0,C:\MyApplication
        etc...

      • Copy 'current.txt' to your applications directory

      .
    5. Create a file called 'recent.txt'
      • Layout of the file should be like this:
        Legend: File on update server,newest version,the url to the file

        myApplication.exe,2.0.0.0,http://www.myserver.com/updates/myApplication.upd
        myDll.dll,1.1.0.0,http://www.myserver.com/updates/myDll.upd
        etc...

      • Upload 'recent.txt' to your site

      .
    6. Usage:
      • From a Button.Click event:
        vb Code:
        1. Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        2.     Me.btnUpdate.Enabled = False
        3.  
        4.     Dim currentVersions As String = "C:\MyApplication\current.txt"
        5.     Dim recentVersions As String = "http://www.mySite.com/recent.txt"
        6.     Dim pathSimpleUpdater As String = "C:\MyApplication\SimpleUpdater.exe"
        7.  
        8.     AKLib.SimpleUpdater.FromDefinedList(currentVersions, recentVersions, pathSimpleUpdater)
        9.  
        10. End Sub

      • Ta-da

      .
    7. Credits to:

      .
    8. Disclaimer: There is basicly no error handling in this code, and I have only tested it on one computer, so is to be used at your own risk
    Attached Images Attached Images  
    Attached Files Attached Files
    Last edited by _powerade_; Aug 3rd, 2010 at 07:29 AM. Reason: Added zip instead of rar
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem

  2. #2
    Hyperactive Member _powerade_'s Avatar
    Join Date
    Sep 08
    Location
    Kyrksæterøra, Norway
    Posts
    321

    Re: AKLib.SimpleUpdater

    Sourcecode - AKLib.sln

    vb Code:
    1. '       AKLib by Arve Kjønsvik
    2. '    E-mail: a_kjonsvik@hotm***.com
    3. '    ''''''''''''''''''''''''''''''
    4. '    Modified by:
    5. '      
    6. '    Version history:
    7. '      Project started: July, 19th 2010
    8. '       v1.0.0.0    -   First release
    9.  
    10. Option Strict On
    11.  
    12. Imports System.IO
    13.  
    14. ''' <summary>
    15. ''' A simple way to update the files for your application.
    16. ''' SimpleUpdate will overwrite existing files without prompting (if newer).
    17. ''' </summary>
    18. Public Class SimpleUpdater
    19.     ''' <summary>
    20.     ''' Using a pre-defined list with files to update.
    21.     ''' </summary>
    22.     ''' <param name="pathPreDefinedList">Path to the file with the update-list.</param>
    23.     ''' <param name="urlNewUpdatesList">The update-list on the update-server.</param>
    24.     ''' <param name="pathToSimpleUpdater">This is the path to the SimpleUpdater.Exe.</param>
    25.     Public Shared Sub FromDefinedList(ByVal pathPreDefinedList As String, _
    26.                                       ByVal urlNewUpdatesList As String, _
    27.                                       ByVal pathToSimpleUpdater As String)
    28.  
    29.         'Checks to see if the user entered the correct path to the defined list
    30.         If Not File.Exists(pathPreDefinedList) Then
    31.             MessageBox.Show("The pre-defined list with updates could not be found!" & _
    32.                             Environment.NewLine & _
    33.                            "Please make sure you provided the correct path/filename.", _
    34.                            "File not found - AKLib", _
    35.                            MessageBoxButtons.OK, MessageBoxIcon.Error)
    36.             Exit Sub
    37.         End If
    38.  
    39.         'Checks to see if the user entered the correct path to the SimpleUpdater executable
    40.         If Not File.Exists(pathToSimpleUpdater) Then
    41.             MessageBox.Show("The SimpleUpdater executable could not be found." & _
    42.                             Environment.NewLine & _
    43.                            "Please make sure you provided the correct path/filename.", _
    44.                            "File not found - AKLib", _
    45.                            MessageBoxButtons.OK, MessageBoxIcon.Error)
    46.             Exit Sub
    47.         End If
    48.  
    49.         'Files are downloaded to this path
    50.         Dim tempPath As String = My.Computer.FileSystem.SpecialDirectories.Temp
    51.  
    52.         Try
    53.             'The path the textfile with the update-info is downloaded to
    54.             Dim pathDownloadTo As String = Path.Combine(tempPath, "simpleupdates_info.txt")
    55.  
    56.             'Try to download the textfile with the update-info into the path the user entered
    57.             My.Computer.Network.DownloadFile(urlNewUpdatesList, _
    58.                                              pathDownloadTo, "", "", False, 10000, True)
    59.  
    60.             'Creates a list we can add strings to
    61.             Dim updates As New List(Of String)
    62.  
    63.             'Adds strings to the list we just created
    64.             With updates
    65.                 .Add("[Caller]") 'Caller is the application SimpleUpdater will start after updating
    66.                 .Add(Path.Combine(My.Application.Info.DirectoryPath, _
    67.                                   My.Application.Info.AssemblyName & ".exe"))
    68.                 .Add("[Compare]")
    69.                 .Add(pathPreDefinedList)
    70.                 .Add("[Updates]")
    71.                 .Add(My.Computer.FileSystem.ReadAllText(pathDownloadTo))
    72.             End With
    73.  
    74.             'Create a new file in the temp-folder and write the update-info to it.
    75.             'This file will be used by SimpleUpdater.exe
    76.             Using sw As StreamWriter = New StreamWriter(Path.Combine(tempPath, _
    77.                                                                      "updates_new.txt"))
    78.                 For Each update In updates
    79.                     sw.WriteLine(update)
    80.                 Next
    81.             End Using
    82.  
    83.         Catch ex As Exception
    84.             'Downloading failed, this might show what caused the error
    85.             MessageBox.Show(Err.Description)
    86.             Exit Sub
    87.  
    88.         End Try
    89.  
    90.         'Create a new instance of ProcessStartInfo
    91.         Dim startInfo As New ProcessStartInfo(pathToSimpleUpdater)
    92.  
    93.         'Pass an argument to SimpleUpdater. SimpleUpdater won't start without this argument.
    94.         startInfo.Arguments = "/runupdate"
    95.  
    96.         'Start SimpleUpdater
    97.         Process.Start(startInfo)
    98.  
    99.         'Exit the current application while SimpleUpdate.Exe installs the updates
    100.         Application.Exit()
    101.  
    102.     End Sub
    103.  
    104. End Class

    Please make a comment if you have any suggestions and/or improvements.
    Last edited by _powerade_; Jul 27th, 2010 at 11:43 PM. Reason: typo
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem

  3. #3
    Hyperactive Member _powerade_'s Avatar
    Join Date
    Sep 08
    Location
    Kyrksæterøra, Norway
    Posts
    321

    Re: AKLib.SimpleUpdater

    Sourcecode - SimpleUpdater.sln

    vb Code:
    1. '    SimpleUpdater by Arve Kjønsvik
    2. '           Used by AKLib
    3. '    E-mail: a_kjonsvik@hotm***.com
    4. '    ''''''''''''''''''''''''''''''
    5. '    Modified by:
    6. '    
    7. '    Credits to:
    8. '      Zeljko    at vbforums.com
    9. '      chris128  at vbforums.com
    10. '
    11. '    Version history:
    12. '      Project started: July, 20th 2010
    13. '       v1.0.0.0    -   First release
    14.  
    15. Option Strict On
    16.  
    17. Imports System.IO
    18.  
    19. Public Class frmMain
    20.  
    21. #Region "Variables"
    22.     Dim listUpdates As New List(Of String)
    23.     Dim workerIsDone As Boolean = False
    24.     Dim updatingFile As Boolean = False
    25.     Dim updatingFilePath As String = String.Empty
    26.     Dim callerPath As String = String.Empty
    27.     Dim compareFile As String = String.Empty
    28. #End Region
    29.  
    30.     Private Sub frmMain_FormClosing(ByVal sender As Object, _
    31.                                     ByVal e As System.Windows.Forms.FormClosingEventArgs) _
    32.                                     Handles Me.FormClosing
    33.  
    34.         'If variable workerIsDone = True, the 'caller' will be
    35.         'started when SimpleUpdater is closing
    36.         If workerIsDone Then Process.Start(callerPath)
    37.  
    38.     End Sub
    39.  
    40.     Private Sub frmMain_Load(ByVal sender As System.Object, _
    41.                              ByVal e As System.EventArgs) _
    42.                              Handles MyBase.Load
    43.  
    44.         'Close the application if started with no arguments
    45.         If My.Application.CommandLineArgs.Count = 0 Then
    46.             MessageBox.Show("No arguments provided.", _
    47.                             My.Application.Info.AssemblyName, _
    48.                             MessageBoxButtons.OK, MessageBoxIcon.Error)
    49.             Me.Close()
    50.         End If
    51.  
    52.         'Getting the arguments
    53.         For Each argument In My.Application.CommandLineArgs
    54.             Select Case My.Application.CommandLineArgs.Item(0).ToLower
    55.                 Case "/runupdate"
    56.                     'The files downloaded by AKLib.SimpleUpdater is stored in this path
    57.                     Dim tempPath As String = My.Computer.FileSystem.SpecialDirectories.Temp
    58.  
    59.                     'Read the update-file made by AKLib.SimpleUpdater
    60.                     Using sr As StreamReader = New StreamReader(Path.Combine(tempPath, _
    61.                                                                 "updates_new.txt"))
    62.                         Do Until sr.EndOfStream
    63.                             listUpdates.Add(sr.ReadLine)
    64.                         Loop
    65.                     End Using
    66.  
    67.                     'Now we will work with and remove some of the information in the list we created
    68.                     With listUpdates
    69.                         'NOTE: This will only work with the current structure of the 'update_new.txt-file'.
    70.                         'If the structure of the file is changed, then this should probably be changed as well!
    71.                         .RemoveAt(0)            '[Caller]
    72.                         callerPath = .Item(0)   'Path. Assign to 'callerPath'
    73.                         .RemoveAt(0)            'Remove the path
    74.                         .RemoveAt(0)            '[Compare]
    75.                         compareFile = .Item(0)  'Path. Assign to 'compareFile'
    76.                         .RemoveAt(0)            'Remove the path
    77.                         .RemoveAt(0)            '[Updates]
    78.                         'The list should now only contain information about the files that might be updated
    79.                     End With
    80.  
    81.                     'Starting the BackgroundWorker
    82.                     worker.RunWorkerAsync()
    83.  
    84.                 Case Else
    85.                     'Incorrect argument
    86.                     MessageBox.Show("Incorrect argument.", My.Application.Info.AssemblyName, _
    87.                                                            MessageBoxButtons.OK, MessageBoxIcon.Error)
    88.                     Me.Close()
    89.  
    90.             End Select
    91.         Next
    92.  
    93.     End Sub
    94.  
    95.     Private Sub worker_DoWork(ByVal sender As System.Object, _
    96.                               ByVal e As System.ComponentModel.DoWorkEventArgs) _
    97.                               Handles worker.DoWork
    98.  
    99.         'Looping through the files to find out if they need to update
    100.         For Each update As String In listUpdates
    101.             'If compareFiles returns True, a update is available
    102.             If compareFiles(update) = True Then
    103.                 Dim updateName As String = String.Empty
    104.                 Dim updateVersion As String = String.Empty
    105.                 Dim updateURL As String = String.Empty
    106.  
    107.                 'Splitting up the updatefile, to make it easier to work with
    108.                 Dim splitUpdateFile As New List(Of String)
    109.                 splitUpdateFile.AddRange(update.Split(CType(",", Char)))
    110.  
    111.                 'Assigns values from the updatefile
    112.                 updateName = splitUpdateFile(0)
    113.                 updateVersion = splitUpdateFile(1)
    114.                 updateURL = splitUpdateFile(2)
    115.  
    116.                 'Download and install the updates
    117.                 Try
    118.                     'Add a new item to the Listbox in frmMain
    119.                     Me.lstUpdate.Items.Add( _
    120.                         Date.Now & " - Updating " & updateName & " to version " & updateVersion)
    121.  
    122.                     'Downloading
    123.                     My.Computer.Network.DownloadFile(updateURL, _
    124.                                                      Path.Combine(updatingFilePath, updateName), _
    125.                                                      "", "", False, 10000, True)
    126.  
    127.                 Catch ex As Exception
    128.                     Me.lstUpdate.Items.Add(Date.Now & " - " & ex.Message)
    129.  
    130.                 End Try
    131.  
    132.                 'A update has been installed
    133.                 updatingFile = True
    134.  
    135.             End If
    136.         Next
    137.  
    138.         'In no update has been installed, this line is added to the Listbox
    139.         If updatingFile = False Then Me.lstUpdate.Items.Add( _
    140.             Date.Now & " - All of your files were up to date.")
    141.  
    142.     End Sub
    143.  
    144.     Private Sub worker_RunWorkerCompleted(ByVal sender As Object, _
    145.                                           ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) _
    146.                                           Handles worker.RunWorkerCompleted
    147.         workerIsDone = True
    148.  
    149.         Me.lstUpdate.Items.Add(Date.Now & " - Done! Click 'OK' to continue...")
    150.  
    151.         Me.btnOK.Text = "OK"
    152.         Me.btnOK.Enabled = True
    153.  
    154.     End Sub
    155.  
    156.     ''' <summary>
    157.     ''' Compares the files in the update-list with the files in the new updates-list
    158.     ''' </summary>
    159.     ''' <param name="fileToCompare">The file that is compared</param>
    160.     ''' <returns>True if file needs to update</returns>
    161.     Private Function compareFiles(ByVal fileToCompare As String) As Boolean
    162.         Dim compareList As New List(Of String)
    163.         Dim updateNeeded As Boolean = False
    164.  
    165.         'Put the contents of the file into 'compareList'
    166.         Using sr As StreamReader = New StreamReader(compareFile)
    167.             Do Until sr.EndOfStream
    168.                 compareList.Add(sr.ReadLine)
    169.             Loop
    170.         End Using
    171.  
    172.         'Scan through compareList
    173.         For Each file In compareList
    174.             Dim name As String = String.Empty
    175.             Dim version As String = String.Empty
    176.  
    177.             'Splitting up the fileinfo that we are comparing with the
    178.             'fileinfo from the update-file
    179.             Dim splitFileInfo As New List(Of String)
    180.             splitFileInfo.AddRange(file.Split(CType(",", Char)))
    181.  
    182.             'Filename, version and the path(file) of the fileinfo we are comparing
    183.             name = splitFileInfo(0)
    184.             version = splitFileInfo(1)
    185.             updatingFilePath = splitFileInfo(2)
    186.  
    187.             'If the filename we got from splitting, is the same as the
    188.             'one thatwe are checking for update, then do the following
    189.             'code. Else we are going to the next file if available
    190.             If fileToCompare.ToLower.StartsWith(name.ToLower) Then
    191.  
    192.                 'Splitting up the fileinfo from the update-file
    193.                 Dim splitUpdateFileInfo As New List(Of String)
    194.                 splitUpdateFileInfo.AddRange(fileToCompare.Split(CType(",", Char)))
    195.  
    196.                 'We already know the name of the file that we are checking are correct,
    197.                 'so we are removing it from the list
    198.                 splitUpdateFileInfo.RemoveAt(0)
    199.  
    200.                 'Assign the version to a variable
    201.                 Dim versionUpdate As String = splitUpdateFileInfo(0)
    202.  
    203.                 'Comparing the two versions
    204.                 '' Credits to: Zeljko and chris128 at vbforums.com
    205.                 Dim versionOld As New Version(version)
    206.                 Dim versionNew As New Version(versionUpdate)
    207.  
    208.                 If versionNew > versionOld Then
    209.                     'VersionNew is higher, so it's going to update
    210.                     updateNeeded = True
    211.                     Exit For
    212.                 Else
    213.                     'VersionNew is the same or lower, so it's not going to update
    214.                     updateNeeded = False
    215.                     Exit For
    216.                 End If
    217.                 '' / Credits
    218.             End If
    219.         Next
    220.  
    221.         'Tells the BackgroundWorker to download and install a update
    222.         Return updateNeeded
    223.  
    224.     End Function
    225.  
    226.     Private Sub btnOK_Click(ByVal sender As System.Object, _
    227.                             ByVal e As System.EventArgs) _
    228.                             Handles btnOK.Click
    229.         Application.Exit()
    230.  
    231.     End Sub
    232.  
    233. End Class

    Please make a comment if you have any suggestions and/or improvements.
    Last edited by _powerade_; Aug 3rd, 2010 at 07:05 AM. Reason: removed some junk
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 09
    Location
    USA
    Posts
    3,823

    Re: AKLib.SimpleUpdater

    It's probably better to include the attachment as zip files instead of archives. Not everyone has the available apps to extract archive files.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5
    Hyperactive Member _powerade_'s Avatar
    Join Date
    Sep 08
    Location
    Kyrksæterøra, Norway
    Posts
    321

    Re: AKLib.SimpleUpdater

    Thank you, you are probably right, so I will change it when I got the time

    Edit: Fixed
    Last edited by _powerade_; Aug 3rd, 2010 at 07:06 AM.
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem

  6. #6
    New Member
    Join Date
    Sep 10
    Posts
    11

    Re: AKLib.SimpleUpdater

    is this method require FrontPage Extension on webserver?

  7. #7
    Hyperactive Member _powerade_'s Avatar
    Join Date
    Sep 08
    Location
    Kyrksæterøra, Norway
    Posts
    321

    Re: AKLib.SimpleUpdater

    Honestly, I don't know .

    I think someone else here on the forums should answer that. I just use a free online file-server, so I have no clue what you have to do or add if you are going to use your own server...

    -Arve
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem

  8. #8
    New Member
    Join Date
    Sep 10
    Posts
    11

    Re: AKLib.SimpleUpdater

    Ok, thanks, it's very helpfull. I think it's more simpler than update using "oneclick" publish feature on visual studio. ^_^

  9. #9
    Hyperactive Member _powerade_'s Avatar
    Join Date
    Sep 08
    Location
    Kyrksæterøra, Norway
    Posts
    321

    Re: AKLib.SimpleUpdater

    Thanks
    Arve K.

    Please mark your thread as resolved and add reputation to those who helped you solve your problem

  10. #10
    Member
    Join Date
    Jul 10
    Posts
    34

    Re: AKLib.SimpleUpdater

    Hi, I am learning VB I barely understand what you have explained,

    # Add a reference to AKLib from your designer What this means??
    .
    # Copy SimpleUpdater.exe to your applications directory (c:\pogram files?)&#231;

    And "From a Button.Click event:" from where... sorry, but I need come more detailed explaining..

  11. #11
    New Member
    Join Date
    Sep 10
    Posts
    11

    Re: AKLib.SimpleUpdater

    Quote Originally Posted by andreu22 View Post
    # Add a reference to AKLib from your designer What this means??
    .
    # Copy SimpleUpdater.exe to your applications directory (c:\pogram files?)
    First, you can add the AKLib components to your project, right click on project explorer, then click add reference...

    Then copy SimpleUpdater.exe. It depends on path of your application.

  12. #12
    Member
    Join Date
    Jul 10
    Posts
    34

    Re: AKLib.SimpleUpdater

    Ok, thanks, now it is clearer.

  13. #13
    Addicted Member
    Join Date
    Feb 10
    Posts
    197

    Re: AKLib.SimpleUpdater

    Very nice control, how would i go about adding in a progress bar to show the progress of files downloaded (progressbar max value would be the number of updates to be downloaded, value would increase after each updates done)

Posting Permissions

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