From c0fb1e3904cc70bada06f046425fe1390eb13ede Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Sun, 21 Apr 2024 11:40:49 +0200 Subject: [PATCH] minor code improvements --- ModpackUpdater.Model/ModpackInfo.vb | 5 ++--- ModpackUpdater.Model/UpdateConfig.vb | 8 ++++---- ModpackUpdater.Model/UpdateInfos.vb | 4 ++-- ModpackUpdater/AppUpdater.vb | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ModpackUpdater.Model/ModpackInfo.vb b/ModpackUpdater.Model/ModpackInfo.vb index f27e4aa..35fd3ac 100644 --- a/ModpackUpdater.Model/ModpackInfo.vb +++ b/ModpackUpdater.Model/ModpackInfo.vb @@ -2,7 +2,6 @@ Imports Newtonsoft.Json Imports Newtonsoft.Json.Converters -Imports Newtonsoft.Json.Linq Public Class ModpackInfo @@ -12,11 +11,11 @@ Public Class ModpackInfo Public Property Version As Version Public Sub Save(mcRoot As String) - File.WriteAllText(GetFilePath(mcRoot), JObject.FromObject(Me).ToString) + File.WriteAllText(GetFilePath(mcRoot), JsonConvert.SerializeObject(Me)) End Sub Public Shared Function Load(mcRoot As String) As ModpackInfo - Return JObject.Parse(File.ReadAllText(GetFilePath(mcRoot))).ToObject(Of ModpackInfo) + Return JsonConvert.DeserializeObject(Of ModpackInfo)(File.ReadAllText(GetFilePath(mcRoot))) End Function Public Shared Function HasModpackInfo(mcRoot As String) As Boolean diff --git a/ModpackUpdater.Model/UpdateConfig.vb b/ModpackUpdater.Model/UpdateConfig.vb index eca5ebb..11e27f1 100644 --- a/ModpackUpdater.Model/UpdateConfig.vb +++ b/ModpackUpdater.Model/UpdateConfig.vb @@ -1,6 +1,6 @@ Imports System.IO -Imports Newtonsoft.Json.Linq +Imports Newtonsoft.Json Imports Pilz.Cryptography @@ -11,12 +11,12 @@ Public Class UpdateConfig Public Property WebdavUsername As SecureString Public Property WebdavPassword As SecureString - Public Sub SaveToFile(filePath As string) - File.WriteAllText(filePath, JObject.FromObject(Me).ToString) + Public Sub SaveToFile(filePath As String) + File.WriteAllText(filePath, JsonConvert.SerializeObject(Me)) End Sub Public Shared Function LoadFromFile(filePath As String) As UpdateConfig - Return JObject.Parse(File.ReadAllText(filePath)).ToObject(Of UpdateConfig) + Return JsonConvert.DeserializeObject(Of UpdateConfig)(File.ReadAllText(filePath)) End Function End Class diff --git a/ModpackUpdater.Model/UpdateInfos.vb b/ModpackUpdater.Model/UpdateInfos.vb index de53cd5..04e4256 100644 --- a/ModpackUpdater.Model/UpdateInfos.vb +++ b/ModpackUpdater.Model/UpdateInfos.vb @@ -1,11 +1,11 @@ -Imports Newtonsoft.Json.Linq +Imports Newtonsoft.Json Public Class UpdateInfos Public ReadOnly Property Updates As New List(Of UpdateInfo) Public Shared Function Parse(content As String) As UpdateInfos - Return JObject.Parse(content).ToObject(Of UpdateInfos) + Return JsonConvert.DeserializeObject(Of UpdateInfos)(content) End Function End Class diff --git a/ModpackUpdater/AppUpdater.vb b/ModpackUpdater/AppUpdater.vb index 9dfb84c..adb2e11 100644 --- a/ModpackUpdater/AppUpdater.vb +++ b/ModpackUpdater/AppUpdater.vb @@ -22,7 +22,7 @@ Public Class AppUpdater Using client As New WebDavClient(params) Dim result = Await client.Propfind(String.Empty) - If result.IsSuccessful AndAlso result.Resources.Any Then + If result.IsSuccessful AndAlso result.Resources.Count <> 0 Then Dim resource = result.Resources(0) Dim appModificationDate = File.GetLastWriteTimeUtc(appFileName) Dim remoteModificationDate = resource.LastModifiedDate?.ToUniversalTime