Skip to content

Commit

Permalink
Fixed issues with Update.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeqMacaw committed Nov 20, 2019
1 parent a7201d7 commit 9f29c9c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
23 changes: 15 additions & 8 deletions Crowbar/Core/Updater/Updater.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Public Class Updater
Public StatusMessage As String
Public UpdateIsAvailable As Boolean
Public DownloadIsEnabled As Boolean
Public UpdateIsEnabled As Boolean
End Class

Public Sub CheckForUpdate(ByVal given_ProgressChanged As ProgressChangedEventHandler, ByVal given_RunWorkerCompleted As RunWorkerCompletedEventHandler)
Expand All @@ -40,7 +41,6 @@ Public Class Updater
Private Sub CheckForUpdate_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs)
Dim bw As BackgroundWorkerEx = CType(sender, BackgroundWorkerEx)

Dim appVersion As Version = Nothing
Dim fileSize As ULong = 0

'FROM: https://www.codeproject.com/Questions/1255767/Could-not-create-SSL-TLS-secure-channel
Expand Down Expand Up @@ -77,7 +77,7 @@ Public Class Updater
Dim appNameVersion As String = CType(root("name"), String)
'NOTE: Must append ".0.0" to version so that Version comparisons are correct.
Dim appVersionText As String = appNameVersion.Replace("Crowbar ", "") + ".0.0"
appVersion = New Version(appVersionText)
Me.theAppVersion = New Version(appVersionText)

'Dim appVersionIsNewer As Boolean = appVersion > My.Application.Info.Version
'Dim appVersionIsOlder As Boolean = appVersion < My.Application.Info.Version
Expand All @@ -103,22 +103,23 @@ Public Class Updater
Dim outputInfo As New Updater.StatusOutputInfo()
outputInfo.UpdateIsAvailable = False
Dim updateCheckStatusMessage As String
If appVersion Is Nothing Then
If Me.theAppVersion Is Nothing Then
updateCheckStatusMessage = "Unable to get update info. Please try again later. "
ElseIf appVersion = My.Application.Info.Version Then
ElseIf Me.theAppVersion = My.Application.Info.Version Then
updateCheckStatusMessage = "Crowbar is up to date. "
ElseIf appVersion > My.Application.Info.Version Then
updateCheckStatusMessage = "Update to version " + appVersion.ToString(2) + " available. Size: " + MathModule.ByteUnitsConversion(fileSize) + " "
ElseIf Me.theAppVersion > My.Application.Info.Version Then
updateCheckStatusMessage = "Update to version " + Me.theAppVersion.ToString(2) + " available. Size: " + MathModule.ByteUnitsConversion(fileSize) + " "
outputInfo.UpdateIsAvailable = True
Else
'NOTE: Should not get here if versioning is done correctly.
updateCheckStatusMessage = ""
updateCheckStatusMessage = "Crowbar is up to date. "
End If
Dim now As DateTime = DateTime.Now()
Dim lastCheckedMessage As String = "Last checked: " + now.ToLongDateString() + " " + now.ToShortTimeString()

outputInfo.StatusMessage = updateCheckStatusMessage + lastCheckedMessage
outputInfo.DownloadIsEnabled = Me.theDownloadTaskIsEnabled
outputInfo.UpdateIsEnabled = Me.theUpdateTaskIsEnabled
e.Result = outputInfo
End Try
End Sub
Expand All @@ -145,6 +146,10 @@ Public Class Updater
End Sub

Private Sub DownloadAfterCheckForUpdate()
If Me.theUpdateTaskIsEnabled AndAlso Me.theAppVersion <= My.Application.Info.Version Then
Exit Sub
End If

Me.theLocalPathFileName = Path.Combine(Me.theLocalPath, Me.theLocalFileName)
Me.theLocalPathFileName = FileManager.GetTestedPathFileName(Me.theLocalPathFileName)

Expand Down Expand Up @@ -267,7 +272,7 @@ Public Class Updater
#If DEBUG Then
crowbarOrLauncherExeProcess.StartInfo.CreateNoWindow = False
#Else
lzmaExeProcess.StartInfo.CreateNoWindow = True
crowbarOrLauncherExeProcess.StartInfo.CreateNoWindow = True
#End If
crowbarOrLauncherExeProcess.Start()
Application.Exit()
Expand Down Expand Up @@ -329,6 +334,8 @@ Public Class Updater
Private theUpdateRunWorkerCompletedHandler As RunWorkerCompletedEventHandler
Private theUpdateTaskIsEnabled As Boolean

Private theAppVersion As Version = Nothing

#End Region

End Class
Binary file modified Crowbar/Resources/CrowbarLauncher.exe
Binary file not shown.
9 changes: 6 additions & 3 deletions Crowbar/Widgets/Main Tabs/UpdateUserControl.vb
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ Public Class UpdateUserControl
Me.CheckForUpdateTextBox.Text = CType(outputInfo.StatusMessage, String)
NotifyUpdateAvailable(outputInfo.UpdateIsAvailable)

If outputInfo.DownloadIsEnabled Then
If outputInfo.UpdateIsEnabled AndAlso Not outputInfo.UpdateIsAvailable Then
Me.theCurrentProgressBar.Text = "No available update."
Me.theCurrentProgressBar.Value = 0
ElseIf outputInfo.DownloadIsEnabled AndAlso Not (outputInfo.UpdateIsEnabled AndAlso Not outputInfo.UpdateIsAvailable) Then
Me.theCurrentProgressBar.Text = "Starting download..."
Me.theCurrentProgressBar.Value = 0
End If
Expand All @@ -159,12 +162,12 @@ Public Class UpdateUserControl
Try
File.Delete(pathFileName)
Catch ex As Exception
Me.theCurrentProgressBar.Text += "WARNING: Problem deleting incomplete downloaded file: """ + pathFileName + """"
Me.theCurrentProgressBar.Text += "WARNING: Problem deleting incomplete downloaded file: """ + Path.GetFileName(pathFileName) + """"
End Try
End If
Else
If File.Exists(pathFileName) Then
Me.theCurrentProgressBar.Text = "Download complete. Downloaded file: """ + pathFileName + """" + Me.theCurrentProgressBar.Text
Me.theCurrentProgressBar.Text = "Downloaded file: """ + Path.GetFileName(pathFileName) + """ " + Me.theCurrentProgressBar.Text
Me.GotoDownloadFileButton.Enabled = True
Me.theDownloadedPathFileName = pathFileName
Else
Expand Down

0 comments on commit 9f29c9c

Please sign in to comment.