BN+ Discussions Forum Index BN's Blog

BN+ Discussions

A place for open source software and programming support

Display the calendar
The time now is Sat May 25, 2013 1:01 pm
All times are UTC + 0
View posts since last visit
View unanswered posts

Calendar event jegi1
May 28 1964(49 year old)
Calendar event JonasR
May 26 1991(22 year old)
Calendar event nick
May 25 1994(19 year old)

 Forum index » .Net » Visual Basic » Control library

Moderators: Global Moderators
Post new topic  Reply to topic View previous topicView next topic
Page 1 of 1 [3 Posts]  
   
[RTS]BN+VS* Offline

Site Admin


Joined: 20 Aug 2007
Posts: 399
Location: Infront of a computer screen

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger 
 [VB.Net 2005] UpdateDialog
[v1.0.0] checks if there are updates avaible and displays download/install functionallity

Description: Dialog that checks if there are updates avaible for the application and displays download/install functionallity

This class and all of it's dependencies and extensions are included in the BN+ Framework. It is recommended you use the framework instead of loose classes unless you need to make customizations for maximum code integrity.

Download source: Click here

Version: 1.0.0
Stability: Stable
Known issues: None

Related classes: Updater
Dependent on: BN+ Framework 2.0.2.x or higher

Strict: Yes
Explicit: Yes

Copyright: You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.

An update has been found, and details are displayed.
http://code.bn2vs.com/files/updatedailog_updateavaible.gif

The user has chosen to install the update, and the needed files are being downloaded.
http://code.bn2vs.com/files/updatedailog_downloading.gif



UpdateDialog1.0.0.txt
 Description   Source code of class UpdateDialog version 1.0.0 txt

 Download 
 Filename   UpdateDialog1.0.0.txt
 Filesize   18 KB
 Downloaded   145 Time(s)

_________________
Check out Jeroen De Dauw's blog or youtube channel
"There are 10 kinds of programmers. Those who understand binary and those who don't."



Post Posted: Thu Feb 26, 2009 3:00 pm

 Last edited by [RTS]BN+VS* on Thu Feb 26, 2009 4:14 pm; edited 3 times in total
Reply with quote Back to top Go to bottom

   
Google





 Posted: Thu Feb 26, 2009 3:00 pm
Back to top Go to bottom

   
[RTS]BN+VS* Offline

Site Admin


Joined: 20 Aug 2007
Posts: 399
Location: Infront of a computer screen

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger 
Update Dialog source code

Code
'************************************************'
' BN+ Framework                                  '
' By De Dauw Jeroen - jeroendedauw@gmail.com     '
'************************************************'
' Namespace Bn.Dialogs                           '
' Class UpdateDialog v1.0.0 - February 2009      '
'************************************************'
' Copyright 2009 - BN+ Discussions               '
' http://code.bn2vs.com                          '
'************************************************'

Option Strict On : Option Explicit On

Imports Bn.Classes
Imports Bn.Core
Imports Bn.Utilities

Namespace Bn.Dialogs

#Region " Public Class UpdateDialog "
    ''' <summary>Dialog that checks if there are updates avaible for the application and displays download/install functionallity</summary>
    ''' <remarks>Class UpdateDialog v1.0.0, by De Dauw Jeroen - February 2009</remarks>
    Public Class UpdateDialog
        Inherits System.Windows.Forms.Form

#Region "Events"
        ''' <summary>Occurs when no internet connection is found when attempting to download a file with the dialog's updater</summary>
        Public Event NoConnectionFound As Delegates.EventHandler

        ''' <summary>Occurs when the update info is changed</summary>
        Public Event InfoChanged As Delegates.EventHandler

        ''' <summary>Occurs when the DownloadIfAvaible property is changed</summary>
        Public Event DownloadIfAvaibleChanged As Delegates.EventHandler
        ''' <summary>Occurs when the AutoInitiateSearch property is changed</summary>
        Public Event AutoInitiateSearchChanged As Delegates.EventHandler
        ''' <summary>Occurs when the AutoInitiateUpdate property is changed</summary>
        Public Event AutoInitiateUpdateChanged As Delegates.EventHandler
        ''' <summary>Occurs when the DisplayAsUpdaterChanged property is changed</summary>
        Public Event DisplayAsUpdaterChanged As Delegates.EventHandler
        ''' <summary>Occurs when the ShowReleaseDateChanged property is changed</summary>
        Public Event ShowReleaseDateChanged As Delegates.EventHandler
#End Region

#Region "Fields"
        ' The updater used for getting the required info and downloading the updater application
        Private WithEvents m_updater As New Updater

        ' Fields to hold properties determening how the dialog should function or display information
        Private m_initSearch, m_downloadIfAvalible, m_initUpdate, m_displayAsUpdater, m_showReleaseDate As Boolean
#End Region

#Region "Constructors"
        ''' <summary>Create a new instance</summary>
        Public Sub New()
            ' Initialize the designer generated layout
            Me.InitializeComponent()

            ' Set the default values of the properties
            Me.AutoInitiateSearch = True
            Me.DownloadIfAvaible = False
            Me.AutoInitiateUpdate = True
            Me.DisplayAsUpdater = False
            Me.ShowReleaseDate = True
        End Sub
#End Region

#Region "Public methods"
        ''' <summary>Show the form</summary>
        Public Overloads Sub Show(Optional ByVal initSearch As Boolean = Nothing)
            MyBase.Show()
            If initSearch <> Nothing Then Me.AutoInitiateSearch = initSearch
            If Me.AutoInitiateSearch Then Me.CheckForUpdates()
        End Sub

        ''' <summary>Show the form as dialog</summary>
        Public Overloads Sub ShowDialog(Optional ByVal initSearch As Boolean = Nothing)
            If initSearch <> Nothing Then Me.AutoInitiateSearch = initSearch
            If Me.AutoInitiateSearch Then Me.CheckForUpdates()
            MyBase.ShowDialog()
        End Sub

        ''' <summary>Check for updates</summary>
        Public Sub CheckForUpdates(Optional ByVal downloadIfAvaible As Boolean = Nothing)
            If downloadIfAvaible <> Nothing Then Me.DownloadIfAvaible = downloadIfAvaible
            Updater.CheckForUpdates()
        End Sub

        ''' <summary>Download the update</summary>
        Public Sub DownloadUpdate()
            showDownloading()
            Updater.DownloadUpdate()
        End Sub

        ''' <summary>Run the update</summary>
        Public Sub RunUpdate()
            Updater.RunUpdate()
        End Sub
#End Region

#Region "Private methods"

#Region "Interafction handlers"
        Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles btnUpdate.Click
            Select Case True
                Case Me.AutoInitiateUpdate, btnUpdate.Text = "&Download" : Me.DownloadUpdate()
                Case btnUpdate.Text = "&Update" : Me.RunUpdate()
            End Select
        End Sub

        Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles btnCancel.Click
            Me.Dispose()
        End Sub
#End Region

#Region "Action result display"
        Private Sub updater_NoUpdateInfoFound() Handles m_updater.NoUpdateInfoFound
            showNothingFound()
        End Sub

        Private Sub updater_UpdateInfoDownloaded() Handles m_updater.UpdateInfoDownloaded
            Select Case True
                Case Me.DownloadIfAvaible : Me.DownloadUpdate()
                Case Not Updater.FoundUpdate : showNothingFound()
                Case Else : showUpdate()
            End Select
        End Sub

        Private Sub updater_error() Handles m_updater.NoUpdateFileFound, m_updater.UpdateAborted
            showError()
        End Sub

        Private Sub updater_UpdateFileDownloaded() Handles m_updater.UpdateFileDownloaded
            If Me.AutoInitiateUpdate Then
                Me.RunUpdate()
            Else
                showDownloadFinished()
            End If
        End Sub

        Private Sub updater_UpdateStarted() Handles m_updater.UpdateStarted
            showUpdating()
        End Sub

        ''' <summary>Change the interface to it's "no updates found" mode</summary>
        Private Sub showNothingFound()
            toggleProgBar(False)
            lblHeaderStatus.Text = "No Updates Found"
            lblDetailedStatus.Text = "There are no new updates avaible. If not disabled via the options, this application will check periodically for new updates."
        End Sub

        ''' <summary>Change the interface to it's "an update has been found" mode</summary>
        Private Sub showUpdate()
            Dim release As String = ""

            If Me.ShowReleaseDate And Me.Updater.Info.updateReleaseDate > 0 Then
                release = vbNewLine & "This version was released on " & UnixTimeStampToDateTime(Me.Updater.Info.updateReleaseDate).ToLongDateString & "."
            End If

            toggleProgBar(False)

            lblHeaderStatus.Text = "A new update is avaible"
            lblDetailedStatus.Text = Me.Updater.ApplicationName & " version " & Me.Updater.UpdateVersion & " is avaible!" & release

            If Me.Info.updateComments IsNot Nothing Then
                If Me.Info.updateComments.Length > 0 Then lblDetailedStatus.Text &= (vbNewLine & Me.Info.updateComments)
            End If

            With btnUpdate
                .Text = If(Me.AutoInitiateUpdate, "&Update", "&Download")
                .Enabled = True
                .Focus()
            End With
        End Sub

        Private Sub showDownloading()
            toggleProgBar(True)

            lblHeaderStatus.Text = "Downloading " & If(Me.DisplayAsUpdater, "updater", "update")
            lblDetailedStatus.Text = "Downloading " & Me.Updater.ApplicationName & " version " & Me.Updater.UpdateVersion & If(Me.DisplayAsUpdater, " updater.", ".")

            btnUpdate.Enabled = False
        End Sub

        Private Sub showDownloadFinished()
            toggleProgBar(False)

            lblHeaderStatus.Text = "Update ready to install"
            lblDetailedStatus.Text = Me.Updater.ApplicationName & " version " & Me.Updater.UpdateVersion & " is ready to be installed."

            With btnUpdate
                .Text = "&Update"
                .Enabled = True
                .Focus()
            End With
        End Sub

        Private Sub showUpdating()
            toggleProgBar(False)

            lblHeaderStatus.Text = If(Me.DisplayAsUpdater, "Launching updater...", "Updating...")
            lblDetailedStatus.Text = If(Me.DisplayAsUpdater, "Please wait while the updater is being launched.", "Please wait while the update is being installed.")

            btnUpdate.Text = "&Update"
            btnUpdate.Enabled = False
            btnCancel.Enabled = False
        End Sub

        Private Sub showError()
            toggleProgBar(False)

            lblHeaderStatus.Text = "An error occured"
            lblDetailedStatus.Text = "The update could not be installed. Please try again later."

            btnUpdate.Enabled = False
            btnCancel.Focus()
        End Sub

        Private Sub showNoConnection()
            toggleProgBar(False)

            lblHeaderStatus.Text = "No connection"
            lblDetailedStatus.Text = "Unable to connect to the update server. Please try again later."

            btnUpdate.Enabled = False
            btnCancel.Focus()
        End Sub

        Private Sub toggleProgBar(ByVal visible As Boolean)
            pBarSearching.Visible = visible
            lblDetailedStatus.Height = If(visible, 18, 66)
        End Sub
#End Region

#Region "Event raisers"
        Private Sub updater_InfoChanged() Handles m_updater.InfoChanged
            RaiseEvent InfoChanged(Me, New EventArgs)
        End Sub

        Private Sub updater_NoConnectionFound() Handles m_updater.NoConnectionFound
            showNoConnection()
            RaiseEvent NoConnectionFound(Me, New EventArgs)
        End Sub
#End Region

#End Region

#Region "Properties"
        ''' <summary>Gets or sets the object containing info about the update</summary>
        Public Property Info() As Updater.UpdateInfo
            Get
                Return Me.Updater.Info
            End Get
            Set(ByVal value As Updater.UpdateInfo)
                If Me.Updater.Info IsNot value Then Me.Updater.Info = value
            End Set
        End Property

        ''' <summary>Gets or sets the class for getting and downloading update info and update files</summary>
        Public Property Updater() As Updater
            Get
                Return m_updater
            End Get
            Set(ByVal value As Updater)
                m_updater = value
            End Set
        End Property

        ''' <summary>Gets or sets if the dialog should start to search for an update when initiated</summary>
        Public Property AutoInitiateSearch() As Boolean
            Get
                Return m_initSearch
            End Get
            Set(ByVal value As Boolean)
                If m_initSearch <> value Then
                    m_initSearch = value
                    RaiseEvent AutoInitiateSearchChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        ''' <summary>Gets or sets if the dialog should start to download the update when there is one avaible</summary>
        Public Property DownloadIfAvaible() As Boolean
            Get
                Return m_downloadIfAvalible
            End Get
            Set(ByVal value As Boolean)
                If m_downloadIfAvalible <> value Then
                    m_downloadIfAvalible = value
                    RaiseEvent DownloadIfAvaibleChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        ''' <summary>Gets or sets if the dialog should start the updater application when downloaded</summary>
        Public Property AutoInitiateUpdate() As Boolean
            Get
                Return m_initUpdate
            End Get
            Set(ByVal value As Boolean)
                If m_initUpdate <> value Then
                    m_initUpdate = value
                    RaiseEvent AutoInitiateUpdateChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        ''' <summary>Gets or sets if the dialog should display that an updateR is downloaded. If not, it will display that an update is downloaded</summary>
        Public Property DisplayAsUpdater() As Boolean
            Get
                Return m_displayAsUpdater
            End Get
            Set(ByVal value As Boolean)
                If m_displayAsUpdater <> value Then
                    m_displayAsUpdater = value
                    RaiseEvent AutoInitiateUpdateChanged(Me, New EventArgs)
                End If
            End Set
        End Property

        ''' <summary>Gets or sets if the dialog should display the release date of the application</summary>
        Public Property ShowReleaseDate() As Boolean
            Get
                Return m_showReleaseDate
            End Get
            Set(ByVal value As Boolean)
                If m_showReleaseDate <> value Then
                    m_showReleaseDate = value
                    RaiseEvent ShowReleaseDateChanged(Me, New EventArgs)
                End If
            End Set
        End Property
#End Region

#Region "Designer"
        'Form overrides dispose to clean up the component list.
        <System.Diagnostics.DebuggerNonUserCode()> _
        Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            Try
                If disposing AndAlso components IsNot Nothing Then
                    components.Dispose()
                End If
            Finally
                MyBase.Dispose(disposing)
            End Try
        End Sub

        'Required by the Windows Form Designer
        Private components As System.ComponentModel.IContainer

        'NOTE: The following procedure is required by the Windows Form Designer
        'It can be modified using the Windows Form Designer. 
        'Do not modify it using the code editor.
        <System.Diagnostics.DebuggerStepThrough()> _
        Private Sub InitializeComponent()
            Me.pBarSearching = New System.Windows.Forms.ProgressBar
            Me.btnUpdate = New System.Windows.Forms.Button
            Me.btnCancel = New System.Windows.Forms.Button
            Me.lblDetailedStatus = New System.Windows.Forms.Label
            Me.lblHeaderStatus = New System.Windows.Forms.Label
            Me.SuspendLayout()
            '
            'pBarSearching
            '
            Me.pBarSearching.Location = New System.Drawing.Point(12, 63)
            Me.pBarSearching.Name = "pBarSearching"
            Me.pBarSearching.Size = New System.Drawing.Size(380, 15)
            Me.pBarSearching.Style = System.Windows.Forms.ProgressBarStyle.Marquee
            Me.pBarSearching.TabIndex = 0
            '
            'btnUpdate
            '
            Me.btnUpdate.Enabled = False
            Me.btnUpdate.Location = New System.Drawing.Point(236, 111)
            Me.btnUpdate.Name = "btnUpdate"
            Me.btnUpdate.Size = New System.Drawing.Size(75, 23)
            Me.btnUpdate.TabIndex = 1
            Me.btnUpdate.Text = "&Update"
            Me.btnUpdate.UseVisualStyleBackColor = True
            '
            'btnCancel
            '
            Me.btnCancel.Location = New System.Drawing.Point(317, 111)
            Me.btnCancel.Name = "btnCancel"
            Me.btnCancel.Size = New System.Drawing.Size(75, 23)
            Me.btnCancel.TabIndex = 2
            Me.btnCancel.Text = "&Cancel"
            Me.btnCancel.UseVisualStyleBackColor = True
            '
            'lblDetailedStatus
            '
            Me.lblDetailedStatus.Location = New System.Drawing.Point(9, 42)
            Me.lblDetailedStatus.Name = "lblDetailedStatus"
            Me.lblDetailedStatus.Size = New System.Drawing.Size(383, 18)
            Me.lblDetailedStatus.TabIndex = 3
            Me.lblDetailedStatus.Text = "Searching for avaible software updates..."
            '
            'lblHeaderStatus
            '
            Me.lblHeaderStatus.BackColor = System.Drawing.SystemColors.ControlLightLight
            Me.lblHeaderStatus.Dock = System.Windows.Forms.DockStyle.Top
            Me.lblHeaderStatus.Font = New System.Drawing.Font("Arial", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
            Me.lblHeaderStatus.Location = New System.Drawing.Point(0, 0)
            Me.lblHeaderStatus.Name = "lblHeaderStatus"
            Me.lblHeaderStatus.Padding = New System.Windows.Forms.Padding(3, 0, 0, 0)
            Me.lblHeaderStatus.Size = New System.Drawing.Size(404, 29)
            Me.lblHeaderStatus.TabIndex = 4
            Me.lblHeaderStatus.Text = "Searching for updates"
            Me.lblHeaderStatus.TextAlign = System.Drawing.ContentAlignment.MiddleLeft
            '
            'UpdateDialog
            '
            Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
            Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
            Me.ClientSize = New System.Drawing.Size(404, 146)
            Me.Controls.Add(Me.lblHeaderStatus)
            Me.Controls.Add(Me.lblDetailedStatus)
            Me.Controls.Add(Me.btnCancel)
            Me.Controls.Add(Me.btnUpdate)
            Me.Controls.Add(Me.pBarSearching)
            Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
            Me.MaximizeBox = False
            Me.MinimizeBox = False
            Me.Name = "UpdateDialog"
            Me.ShowInTaskbar = False
            Me.Text = "Software-update"
            Me.ResumeLayout(False)

        End Sub
        Friend WithEvents pBarSearching As System.Windows.Forms.ProgressBar
        Friend WithEvents btnUpdate As System.Windows.Forms.Button
        Friend WithEvents btnCancel As System.Windows.Forms.Button
        Friend WithEvents lblDetailedStatus As System.Windows.Forms.Label
        Friend WithEvents lblHeaderStatus As System.Windows.Forms.Label
#End Region

    End Class
#End Region

End Namespace

_________________
Check out Jeroen De Dauw's blog or youtube channel
"There are 10 kinds of programmers. Those who understand binary and those who don't."



Post Posted: Thu Feb 26, 2009 3:02 pm
Reply with quote Back to top Go to bottom

   
[RTS]BN+VS* Offline

Site Admin


Joined: 20 Aug 2007
Posts: 399
Location: Infront of a computer screen

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger 
Some screenshots Razz



updateDailog-updateAvaible.gif
 Description   Screenshot of version 1.0.0
 Filesize   18.84 KB
 Viewed   169 Time(s)

updateDailog-updateAvaible.gif




updateDailog-downloading.gif
 Description   Screenshot of version 1.0.0
 Filesize   19.15 KB
 Viewed   170 Time(s)

updateDailog-downloading.gif


_________________
Check out Jeroen De Dauw's blog or youtube channel
"There are 10 kinds of programmers. Those who understand binary and those who don't."



Post Posted: Thu Feb 26, 2009 4:11 pm
Reply with quote Back to top Go to bottom

 
 
 
Display posts from previous   Sort by   
Page 1 of 1 [3 Posts]  
Post new topic  Reply to topic View previous topicView next topic

 Forum index » .Net » Visual Basic » Control library


Display the legend
Jump to:  



[ Time: 1.6877s ][ Queries: 30 (0.2526s) ][ Debug on ]