Skip to content

Commit fa439f8

Browse files
committed
Added update checker
Minor fix to progress bar, initializes to 0 to avoid starting at 100% after recent uncompression.
1 parent 31105f2 commit fa439f8

File tree

3 files changed

+109
-2
lines changed

3 files changed

+109
-2
lines changed

CompactGUI/MainWindow.xaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,18 @@
340340
</Storyboard>
341341
</VisualState>
342342
</VisualStateGroup>
343-
343+
344344
</VisualStateManager.VisualStateGroups>
345345

346+
<!--Update Banner-->
347+
<Grid x:Name="uiUpdateBanner" VerticalAlignment="Bottom" Height="30" Panel.ZIndex="2" Background="#FF468E56" Visibility="Collapsed" d:Visibility="Visible" Cursor="Hand" MouseUp="uiUpdateBanner_MouseUp">
348+
<Grid.Effect>
349+
<DropShadowEffect Direction="90" Opacity="0.15" BlurRadius="6"/>
350+
</Grid.Effect>
346351

352+
<TextBlock x:Name="uiUpdateText" d:Text="update available - v3.0a2" FontSize="14" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White"/>
353+
</Grid>
354+
347355
<!--Main information section / results of analysis-->
348356
<Grid x:Name="grid" Height="800" VerticalAlignment="Top" Panel.ZIndex="1">
349357
<Grid.Background>

CompactGUI/MainWindow.xaml.vb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Class MainWindow
1515

1616
WikiHandler.GetUpdatedJSON()
1717

18+
FireAndForgetCheckForUpdates()
19+
1820
End Sub
1921

2022

@@ -40,6 +42,14 @@ Class MainWindow
4042

4143
End Sub
4244

45+
Private Async Sub FireAndForgetCheckForUpdates()
46+
47+
Dim ret = Await UpdateHandler.CheckForUpdate(True)
48+
If ret Then
49+
uiUpdateBanner.Visibility = Visibility.Visible
50+
uiUpdateText.Text = "update available - v" & UpdateHandler.NewVersion.ToString
51+
End If
52+
End Sub
4353

4454
Private Sub FireAndForgetGetSteamHeader()
4555

@@ -150,7 +160,7 @@ Class MainWindow
150160
uiProgPercentage.Text = val.Item1 & "%"
151161
uiCurrentFileCompress.Text = val.Item2.Replace(activeFolder.folderName, "")
152162
End Sub)
153-
163+
progress.Report((0, ""))
154164
Dim exclist As New List(Of String)({".vanim_c", ".vmat_c", ".vxml_c", ".vjs_c", ".res", ".vcfg", ".vphys_c", ".vseq_c", ".vpcf_c", ".cab", ".webm"})
155165

156166
Dim cm As New Compactor(activeFolder.folderName, comboBoxSelectCompressionMode.SelectedIndex, exclist)
@@ -172,6 +182,7 @@ Class MainWindow
172182
uiProgPercentage.Text = val.Item1 & "%"
173183
uiCurrentFileCompress.Text = val.Item2.Replace(selectedFolder, "")
174184
End Sub)
185+
progress.Report((0, ""))
175186

176187
Dim compressedFilesList = activeFolder.analysisResults.Where(Function(res) res.CompressedSize < res.UncompressedSize).Select(Of String)(Function(f) f.FileName)
177188

@@ -187,4 +198,9 @@ Class MainWindow
187198
If Not successfullySent Then btnSubmitToWiki.IsEnabled = True
188199
End Sub
189200

201+
Private Sub uiUpdateBanner_MouseUp(sender As Object, e As MouseButtonEventArgs)
202+
203+
Process.Start(New ProcessStartInfo("https://github.com/IridiumIO/CompactGUI/releases/") With {.UseShellExecute = True})
204+
205+
End Sub
190206
End Class

CompactGUI/UpdateHandler.vb

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Imports System.Net.Http
2+
Imports System.Text.Json
3+
Public Class UpdateHandler
4+
5+
Public Shared CurrentVersion As New SemVersion(3, 0, 0, "alpha", 3)
6+
Public Shared NewVersion As SemVersion
7+
Shared UpdateURL As String = "https://raw.githubusercontent.com/IridiumIO/CompactGUI/database/version.json"
8+
Shared Async Function CheckForUpdate(includePrerelease As Boolean) As Task(Of Boolean)
9+
10+
Using httpclient As New HttpClient
11+
Dim ret = Await httpclient.GetStringAsync(UpdateURL)
12+
Dim jVer = JsonSerializer.Deserialize(Of Dictionary(Of String, SemVersion))(ret)
13+
Dim newV As SemVersion = If(includePrerelease, jVer("Latest"), jVer("LatestNonPreRelease"))
14+
NewVersion = newV
15+
If newV > CurrentVersion Then Return True
16+
End Using
17+
Return False
18+
19+
End Function
20+
21+
22+
Class SemVersion : Implements IComparable(Of SemVersion)
23+
Property Major As Integer
24+
Property Minor As Integer
25+
Property Patch As Integer
26+
Property PreRelease As String
27+
Property PreReleaseMinor As Integer
28+
29+
Sub New()
30+
End Sub
31+
32+
Sub New(major As Integer, minor As Integer, patch As Integer)
33+
Me.Major = major
34+
Me.Minor = minor
35+
Me.Patch = patch
36+
End Sub
37+
38+
Sub New(major As Integer, minor As Integer, patch As Integer, prerelease As String, prereleaseminor As Integer)
39+
Me.Major = major
40+
Me.Minor = minor
41+
Me.Patch = patch
42+
Me.PreRelease = prerelease.ToLower
43+
Me.PreReleaseMinor = prereleaseminor
44+
End Sub
45+
46+
Public Function CompareTo(other As SemVersion) As Integer Implements IComparable(Of SemVersion).CompareTo
47+
If other.Major - Me.Major <> 0 Then Return other.Major - Me.Major
48+
If other.Minor - Me.Minor <> 0 Then Return other.Minor - Me.Minor
49+
If other.Patch - Me.Patch <> 0 Then Return other.Patch - Me.Patch
50+
If Not String.Equals(Me.PreRelease, other.PreRelease) Then
51+
If Me.PreRelease = "" Then Return -1
52+
If other.PreRelease = "" Then Return 1
53+
Return String.Compare(other.PreRelease, Me.PreRelease)
54+
End If
55+
If other.PreReleaseMinor - Me.PreReleaseMinor <> 0 Then Return other.PreReleaseMinor - Me.PreReleaseMinor
56+
Return 0
57+
58+
End Function
59+
60+
Public Shared Operator <(ByVal lhs As SemVersion, ByVal rhs As SemVersion) As Boolean
61+
Dim comparer = lhs.CompareTo(rhs)
62+
If comparer <= 0 Then Return False
63+
Return True
64+
End Operator
65+
66+
Public Shared Operator >(ByVal lhs As SemVersion, ByVal rhs As SemVersion) As Boolean
67+
Dim comparer = lhs.CompareTo(rhs)
68+
If comparer >= 0 Then Return False
69+
Return True
70+
End Operator
71+
72+
Public Overrides Function ToString() As String
73+
Return $"{Major}.{Minor}.{Patch}-{PreRelease}.{PreReleaseMinor}"
74+
End Function
75+
76+
Public Function IsPreRelease() As Boolean
77+
If PreRelease = "" Then Return True
78+
Return False
79+
End Function
80+
81+
End Class
82+
83+
End Class

0 commit comments

Comments
 (0)