Skip to content

Commit

Permalink
Show version numbers in the update check messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jamaa committed Jun 4, 2023
1 parent 0440029 commit 272645d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 36 deletions.
1 change: 1 addition & 0 deletions source/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Version 2.3.2
-------------
CHANGED:
* Analysis function GoodnessOfFit: more warnings in the log if not all data is usable
* Show version numbers in the update check messages

Version 2.3.1
-------------
Expand Down
51 changes: 44 additions & 7 deletions source/Controllers/WaveController.vb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ Friend Class WaveController
View.Show()
End Sub

''' <summary>
''' Returns the current version of Wave
''' </summary>
''' <remarks>only considers major, minor and build numbers, omitting the auto-generated revision number</remarks>
''' <returns>the current version number</returns>
Private ReadOnly Property CurrentVersion As Version
Get
Dim v As Version = Reflection.Assembly.GetExecutingAssembly.GetName().Version()
Return New Version($"{v.Major}.{v.Minor}.{v.Build}")
End Get
End Property

Private selectionMade As Boolean 'Flag zeigt an, ob bereits ein Auswahlbereich ausgewählt wurde

''' <summary>
Expand Down Expand Up @@ -205,9 +217,9 @@ Friend Class WaveController
Private Async Sub View_Load(sender As System.Object, e As System.EventArgs)
'Check for update
Try
Dim updateAvailable As Boolean
updateAvailable = Await _model.CheckForUpdate()
If updateAvailable Then
Dim latestVersion As Version = Await GetLatestVersion()
If CurrentVersion < latestVersion Then
'show update available notification
View.ToolStripButton_UpdateNotification.Visible = True
End If
Catch ex As Exception
Expand Down Expand Up @@ -1169,22 +1181,47 @@ Friend Class WaveController
''' </summary>
Private Async Sub CheckForUpdate_Click(sender As Object, e As EventArgs)
Try
Dim updateAvailable As Boolean = Await _model.CheckForUpdate()
If updateAvailable Then
'get latest version from server
Dim latestVersion As Version = Await GetLatestVersion()

'compare versions
If CurrentVersion < latestVersion Then
'Update is available
View.ToolStripButton_UpdateNotification.Visible = True
Dim resp As MsgBoxResult = MsgBox($"A new version is available!{eol}Click OK to go to downloads.bluemodel.org to get it.", MsgBoxStyle.OkCancel)
Dim resp As MsgBoxResult = MsgBox($"A new version {latestVersion} is available!{eol}Click OK to go to downloads.bluemodel.org to download it.", MsgBoxStyle.OkCancel Or MsgBoxStyle.Exclamation)
If resp = MsgBoxResult.Ok Then
Process.Start(urlDownload)
End If
Else
'No update available
View.ToolStripButton_UpdateNotification.Visible = False
MsgBox("You are already up to date!", MsgBoxStyle.Information)
MsgBox($"Currently used version {CurrentVersion} is up to date!", MsgBoxStyle.Information)
End If

Catch ex As Exception
MsgBox("Error while checking for update:" & eol & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub

''' <summary>
''' Checks for a newer version on the server
''' </summary>
''' <returns>True if a newer version is available</returns>
Private Async Function GetLatestVersion() As Threading.Tasks.Task(Of Version)

'retrieve latest version number from server
Dim client As New Net.Http.HttpClient()
Dim s As String = Await client.GetStringAsync(urlUpdateCheck)
Dim latestVersion As New Version(s)
#If Not DEBUG Then
'TODO: Logging is not thread-safe and causes an exception in debug mode!
Log.AddLogEntry(Log.levels.debug, "CheckUpdate: Latest version on server: " & latestVersion.ToString())
#End If

Return latestVersion

End Function

''' <summary>
''' About Click
''' </summary>
Expand Down
29 changes: 0 additions & 29 deletions source/Wave.vb
Original file line number Diff line number Diff line change
Expand Up @@ -765,35 +765,6 @@ Public Class Wave

End Sub

''' <summary>
''' Checks for a newer version on the server
''' </summary>
''' <returns>True if a newer version is available</returns>
Friend Async Function CheckForUpdate() As Threading.Tasks.Task(Of Boolean)


'get current version (only consider major, minor and build numbers, omitting the auto-generated revision number)
Dim v As Version = Reflection.Assembly.GetExecutingAssembly.GetName().Version()
Dim currentVersion As New Version($"{v.Major}.{v.Minor}.{v.Build}")

'retrieve latest version number from server
Dim client As New Net.Http.HttpClient()
Dim s As String = Await client.GetStringAsync(urlUpdateCheck)
Dim latestVersion As New Version(s)
#If Not DEBUG Then
'TODO: Logging is not thread-safe and causes an exception in debug mode!
Log.AddLogEntry(Log.levels.debug, "CheckUpdate: Latest version on server: " & latestVersion.ToString())
#End If

'compare versions
If currentVersion < latestVersion Then
Return True
Else
Return False
End If

End Function

Friend Sub HighlightTimestampsHandler(timestamps As List(Of DateTime))
RaiseEvent HighlightTimestamps(timestamps)
End Sub
Expand Down

0 comments on commit 272645d

Please sign in to comment.