rework updater
This commit is contained in:
@@ -1,44 +1,39 @@
|
|||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports System.Net
|
|
||||||
Imports System.Net.Http
|
Imports System.Net.Http
|
||||||
|
|
||||||
Imports WebDav
|
Imports Newtonsoft.Json
|
||||||
|
Imports Newtonsoft.Json.Converters
|
||||||
|
|
||||||
Public Class AppUpdater
|
Public Class AppUpdater
|
||||||
|
|
||||||
Private Const WEBDAV_URL As String = "https://cloud.pilzinsel64.de/public.php/webdav"
|
Private Class UpdateInfo
|
||||||
Private Const WEBDAV_KEY As String = "z4dGicDYmG2neG9"
|
<JsonConverter(GetType(StringEnumConverter))>
|
||||||
Private Const DOWNLOAD_URL As String = "https://cloud.pilzinsel64.de/s/z4dGicDYmG2neG9/download"
|
Public Property Version As Version
|
||||||
|
Public Property DownloadUrl As String
|
||||||
|
End Class
|
||||||
|
|
||||||
Public Shared Async Function Check() As Task(Of Boolean)
|
Private Const UPDATE_URL As String = "https://git.pilzinsel64.de/gaming/minecraft/minecraft-modpack-updater/-/snippets/3/raw??????????"
|
||||||
|
Private ReadOnly httpClient As New HttpClient
|
||||||
|
Private info As UpdateInfo
|
||||||
|
|
||||||
|
Public Async Function Check() As Task(Of Boolean)
|
||||||
Dim appFileName = Pilz.IO.Extensions.GetExecutablePath()
|
Dim appFileName = Pilz.IO.Extensions.GetExecutablePath()
|
||||||
Dim hasUpdate As Boolean = False
|
Dim hasUpdate As Boolean = False
|
||||||
Dim params As New WebDavClientParams With {
|
|
||||||
.BaseAddress = New Uri(WEBDAV_URL),
|
|
||||||
.Credentials = New NetworkCredential(WEBDAV_KEY, String.Empty)
|
|
||||||
}
|
|
||||||
|
|
||||||
Try
|
Try
|
||||||
Using client As New WebDavClient(params)
|
Dim result = Await httpClient.GetStringAsync(UPDATE_URL)
|
||||||
Dim result = Await client.Propfind(String.Empty)
|
info = JsonConvert.DeserializeObject(Of UpdateInfo)(result)
|
||||||
|
|
||||||
If result.IsSuccessful AndAlso result.Resources.Count <> 0 Then
|
If info IsNot Nothing AndAlso info.Version < New Version(Application.ProductVersion) Then
|
||||||
Dim resource = result.Resources(0)
|
|
||||||
Dim appModificationDate = File.GetLastWriteTimeUtc(appFileName)
|
|
||||||
Dim remoteModificationDate = resource.LastModifiedDate?.ToUniversalTime
|
|
||||||
|
|
||||||
If remoteModificationDate > appModificationDate Then
|
|
||||||
hasUpdate = True
|
hasUpdate = True
|
||||||
End If
|
End If
|
||||||
End If
|
|
||||||
End Using
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
Return hasUpdate
|
Return hasUpdate
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Shared Async Function Install() As Task
|
Public Async Function Install() As Task
|
||||||
Dim client As New HttpClient
|
Dim client As New HttpClient
|
||||||
Dim tempFileName = Path.GetTempFileName
|
Dim tempFileName = Path.GetTempFileName
|
||||||
Dim appFileName = Pilz.IO.Extensions.GetExecutablePath()
|
Dim appFileName = Pilz.IO.Extensions.GetExecutablePath()
|
||||||
@@ -54,7 +49,7 @@ Public Class AppUpdater
|
|||||||
Using tempFileStream As New FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)
|
Using tempFileStream As New FileStream(tempFileName, FileMode.Create, FileAccess.ReadWrite)
|
||||||
Dim downloadStream As Stream = Nothing
|
Dim downloadStream As Stream = Nothing
|
||||||
Try
|
Try
|
||||||
downloadStream = Await client.GetStreamAsync(DOWNLOAD_URL)
|
downloadStream = Await client.GetStreamAsync(info.DownloadUrl)
|
||||||
Await downloadStream.CopyToAsync(tempFileStream)
|
Await downloadStream.CopyToAsync(tempFileStream)
|
||||||
Catch
|
Catch
|
||||||
Finally
|
Finally
|
||||||
|
|||||||
Reference in New Issue
Block a user