Skip to content

Commit 9c47d90

Browse files
committed
Improvements to update checker
1 parent 18c4266 commit 9c47d90

File tree

5 files changed

+58
-17
lines changed

5 files changed

+58
-17
lines changed

DiskImageTool/DiskImageTool.vbproj

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<ProductName>DiskImageTool</ProductName>
3131
<PublisherName>Digitoxin</PublisherName>
3232
<ApplicationRevision>0</ApplicationRevision>
33-
<ApplicationVersion>1.30.0.%2a</ApplicationVersion>
33+
<ApplicationVersion>1.31.0.%2a</ApplicationVersion>
3434
<UseApplicationTrust>false</UseApplicationTrust>
3535
<PublishWizardCompleted>true</PublishWizardCompleted>
3636
<BootstrapperEnabled>true</BootstrapperEnabled>
@@ -54,6 +54,7 @@
5454
<OutputPath>bin\Release\</OutputPath>
5555
<DocumentationFile>DiskImageTool.xml</DocumentationFile>
5656
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
57+
<DebugSymbols>true</DebugSymbols>
5758
</PropertyGroup>
5859
<PropertyGroup>
5960
<OptionExplicit>On</OptionExplicit>
@@ -86,6 +87,9 @@
8687
<ApplicationManifest>My Project\app.manifest</ApplicationManifest>
8788
</PropertyGroup>
8889
<ItemGroup>
90+
<Reference Include="CompactJson, Version=1.2.3.0, Culture=neutral, processorArchitecture=MSIL">
91+
<HintPath>..\packages\CompactJson.1.2.3\lib\net472\CompactJson.dll</HintPath>
92+
</Reference>
8993
<Reference Include="Hb.Windows.Forms.HexBox2, Version=2.0.1.35160, Culture=neutral, PublicKeyToken=e0e5adf0ebc99863, processorArchitecture=MSIL">
9094
<SpecificVersion>False</SpecificVersion>
9195
<HintPath>..\..\Hb.Hexeditor2\sources\Hb.Windows.Forms.HexBox\bin\Release\Hb.Windows.Forms.HexBox2.dll</HintPath>
@@ -289,6 +293,7 @@
289293
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
290294
</None>
291295
<None Include="App.config" />
296+
<None Include="packages.config" />
292297
</ItemGroup>
293298
<ItemGroup>
294299
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">

DiskImageTool/Functions.vb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,26 @@ Module Functions
141141
Private Function ConvertHexToByte(Hex As String, <Out> ByRef b As Byte) As Boolean
142142
Return Byte.TryParse(Hex, NumberStyles.HexNumber, Thread.CurrentThread.CurrentCulture, b)
143143
End Function
144+
145+
<DllImport("shell32.dll")>
146+
Private Function SHGetKnownFolderPath(<MarshalAs(UnmanagedType.LPStruct)> ByVal rfid As Guid,
147+
ByVal dwFlags As UInt32,
148+
ByVal hToken As IntPtr,
149+
ByRef pszPath As IntPtr) As Int32
150+
End Function
151+
152+
Public Function GetDownloadsFolder() As String
153+
154+
Dim Result As String = ""
155+
Dim ppszPath As IntPtr
156+
Dim rfid = New Guid("{374DE290-123F-4565-9164-39C4925E467B}")
157+
158+
If SHGetKnownFolderPath(rfid, 0, 0, ppszPath) = 0 Then
159+
Result = Marshal.PtrToStringUni(ppszPath)
160+
Marshal.FreeCoTaskMem(ppszPath)
161+
End If
162+
163+
Return Result
164+
End Function
165+
144166
End Module

DiskImageTool/MainForm.vb

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Imports System.IO
33
Imports System.Net
44
Imports System.Text
5-
Imports System.Text.RegularExpressions
65
Imports DiskImageTool.DiskImage
76
Imports BootSectorOffsets = DiskImageTool.DiskImage.BootSector.BootSectorOffsets
87
Imports BootSectorSizes = DiskImageTool.DiskImage.BootSector.BootSectorSizes
@@ -444,9 +443,8 @@ Public Class MainForm
444443
Private Sub CheckForUpdates()
445444
Dim DownloadVersion As String = ""
446445
Dim DownloadURL As String = ""
446+
Dim Body As String = ""
447447
Dim UpdateAvailable As Boolean = False
448-
Dim Regex As Regex
449-
Dim Match As Match
450448

451449
Cursor.Current = Cursors.WaitCursor
452450
Try
@@ -456,21 +454,27 @@ Public Class MainForm
456454
Dim Reader As New StreamReader(Response.GetResponseStream)
457455
Dim ResponseText = Reader.ReadToEnd
458456

459-
Regex = New Regex("""tag_name"":""v(\d+\.\d+(?:\.\d+)?(?:\.\d+)?)""")
460-
Match = Regex.Match(ResponseText)
461-
If Match.Success Then
462-
If Match.Groups.Count > 1 Then
463-
DownloadVersion = Match.Groups.Item(1).Value
457+
Dim json As Dictionary(Of String, Object) = CompactJson.Serializer.Parse(Of Dictionary(Of String, Object))(ResponseText)
458+
459+
If json.ContainsKey("tag_name") Then
460+
DownloadVersion = json.Item("tag_name").ToString
461+
If DownloadVersion.StartsWith("v", StringComparison.CurrentCultureIgnoreCase) Then
462+
DownloadVersion = DownloadVersion.Remove(0, 1)
464463
End If
465464
End If
466465

467-
Regex = New Regex("""browser_download_url"":""([^""]+)""")
468-
Match = Regex.Match(ResponseText)
469-
If Match.Success Then
470-
If Match.Groups.Count > 1 Then
471-
DownloadURL = Match.Groups.Item(1).Value
466+
If json.ContainsKey("assets") Then
467+
Dim assets() As Dictionary(Of String, Object) = CompactJson.Serializer.Parse(Of Dictionary(Of String, Object)())(json.Item("assets").ToString)
468+
If assets.Length > 0 Then
469+
If assets(0).ContainsKey("browser_download_url") Then
470+
DownloadURL = assets(0).Item("browser_download_url").ToString
471+
End If
472472
End If
473473
End If
474+
475+
If json.ContainsKey("body") Then
476+
Body = json.Item("body").ToString
477+
End If
474478
Catch
475479
MsgBox("An error occured while checking for updates. Please try again later.", MsgBoxStyle.Exclamation)
476480
Exit Sub
@@ -482,11 +486,17 @@ Public Class MainForm
482486
End If
483487

484488
If UpdateAvailable Then
485-
Dim Msg = "A New version Of " & My.Application.Info.Title & " Is available." & vbCrLf & vbCrLf & "Do you wish to download it at this time?"
489+
Dim Msg = My.Application.Info.Title & " v" & DownloadVersion & " Is available."
490+
If Body <> "" Then
491+
Msg = Msg & vbCrLf & vbCrLf & "Whats New" & vbCrLf & New String("—", 6) & vbCrLf & Body & vbCrLf
492+
End If
493+
Msg = Msg & vbCrLf & vbCrLf & "Do you wish to download it at this time?"
486494
If MsgBox(Msg, MsgBoxStyle.Question + MsgBoxStyle.YesNo + MsgBoxStyle.DefaultButton2) = MsgBoxResult.Yes Then
487495
Dim Dialog As New SaveFileDialog With {
488496
.Filter = "Zip Archive|*.zip",
489-
.FileName = Path.GetFileName(DownloadURL)
497+
.FileName = Path.GetFileName(DownloadURL),
498+
.InitialDirectory = GetDownloadsFolder(),
499+
.RestoreDirectory = True
490500
}
491501
Dialog.ShowDialog()
492502
If Dialog.FileName <> "" Then

DiskImageTool/My Project/AssemblyInfo.vb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ Imports System.Runtime.InteropServices
3131
' <Assembly: AssemblyVersion("1.0.*")>
3232

3333
<Assembly: AssemblyVersion("1.0.0.0")>
34-
<Assembly: AssemblyFileVersion("1.30.0.0")>
34+
<Assembly: AssemblyFileVersion("1.31.0.0")>

DiskImageTool/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="CompactJson" version="1.2.3" targetFramework="net472" />
4+
</packages>

0 commit comments

Comments
 (0)