Skip to content

Commit

Permalink
Implemented update check for mod manager;
Browse files Browse the repository at this point in the history
  • Loading branch information
grasmann committed May 21, 2017
1 parent 8f9622f commit 1177c41
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions VMM/VMM.vbproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
<SubType>Form</SubType>
</Compile>
<Compile Include="function\Helpers\ModHelper.vb" />
<Compile Include="function\Objects\ModManagerUpdateCheck.vb" />
<Compile Include="function\Objects\VermintideMod.vb" />
<Compile Include="function\ProfileBakery.vb" />
<Compile Include="function\Objects\Settings.vb" />
Expand Down
30 changes: 30 additions & 0 deletions VMM/forms/About.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion VMM/forms/About.vb
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
Public Class About
Imports VMM

Public Class About

Private WithEvents _update_check As New ModManagerUpdateCheck

Private Sub _update_check_UpdateAvailable(File As ModuleModBrowser.file_info) Handles _update_check.UpdateAvailable
lbl_update.Visible = True
lbl_update.Text = String.Format("Update {0} is available.", File.Version)
btn_update.Visible = True
End Sub

Private Sub About_Load(sender As Object, e As EventArgs) Handles MyBase.Load
lbl_version.Text = Version.Current
End Sub

Private Sub About_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
lbl_update.Visible = False
btn_update.Visible = False
_update_check.CheckForUpdate()
End Sub
End Class
35 changes: 35 additions & 0 deletions VMM/function/Objects/ModManagerUpdateCheck.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Imports System.ComponentModel
Imports System.Net
Imports Newtonsoft.Json

Public Class ModManagerUpdateCheck

Private WithEvents _check_update As New BackgroundWorker

Public Event UpdateAvailable(File As ModuleModBrowser.file_info)

Public Sub CheckForUpdate()
If Not _check_update.IsBusy Then _check_update.RunWorkerAsync()
End Sub

Private Sub _check_update_RunWorkerCompleted(sender As Object, e As RunWorkerCompletedEventArgs) Handles _check_update.RunWorkerCompleted
Dim file As ModuleModBrowser.file_info = e.Result
RaiseEvent UpdateAvailable(file)
End Sub

Private Sub _check_update_DoWork(sender As Object, e As DoWorkEventArgs) Handles _check_update.DoWork
Try
Dim client As New WebClient
Dim json As String = client.DownloadString("http://www.vmf.heliohost.org/file_list.php?mode=manager")
Dim files As List(Of ModuleModBrowser.file_info) = JsonConvert.DeserializeObject(Of List(Of ModuleModBrowser.file_info))(json)
Dim file As ModuleModBrowser.file_info = files(files.Count - 1)
If Compare(file.Version, Current) Then
Debug.Print("New version available.")
e.Result = file
End If
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub

End Class

0 comments on commit 1177c41

Please sign in to comment.