convert to c#

This commit is contained in:
2024-06-18 10:56:32 +02:00
parent f07fad0a80
commit deb14caf24
49 changed files with 1622 additions and 1534 deletions

View File

@@ -0,0 +1,9 @@
namespace ModpackUpdater.Model;
public class InstallAction
{
public bool IsZip { get; set; }
public string ZipPath { get; set; }
public string DestPath { get; set; }
public string DownloadUrl { get; set; }
}

View File

@@ -1,8 +0,0 @@
Public Class InstallAction
Public Property IsZip As Boolean
Public Property ZipPath As String
Public Property DestPath As String
Public Property DownloadUrl As String
End Class

View File

@@ -0,0 +1,13 @@
using Newtonsoft.Json;
namespace ModpackUpdater.Model;
public class InstallInfos
{
public List<InstallAction> Actions { get; private set; } = [];
public static InstallInfos Parse(string content)
{
return JsonConvert.DeserializeObject<InstallInfos>(content);
}
}

View File

@@ -1,11 +0,0 @@
Imports Newtonsoft.Json
Public Class InstallInfos
Public ReadOnly Property Actions As New List(Of InstallAction)
Public Shared Function Parse(content As String) As InstallInfos
Return JsonConvert.DeserializeObject(Of InstallInfos)(content)
End Function
End Class

View File

@@ -0,0 +1,16 @@
using Newtonsoft.Json;
namespace ModpackUpdater.Model;
public class ModpackConfig
{
public string Name { get; set; }
public string UpdateUrl { get; set; }
public string InstallUrl { get; set; }
public static object LoadFromUrl(string url)
{
string result = new HttpClient().GetStringAsync(url).Result;
return JsonConvert.DeserializeObject<ModpackConfig>(result);
}
}

View File

@@ -1,16 +0,0 @@
Imports System.Net.Http
Imports Newtonsoft.Json
Public Class ModpackConfig
Public Property Name As String
Public Property UpdateUrl As String
Public Property InstallUrl As String
Public Shared Function LoadFromUrl(url As String)
Dim result As String = New HttpClient().GetStringAsync(url).Result
Return JsonConvert.DeserializeObject(Of ModpackConfig)(result)
End Function
End Class

View File

@@ -0,0 +1,33 @@
using Microsoft.VisualBasic.CompilerServices;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ModpackUpdater.Model;
public class ModpackInfo
{
private const string FILENAME_MODPACKINFO = "modpack-info.json";
[JsonConverter(typeof(VersionConverter))]
public Version Version { get; set; }
public void Save(string mcRoot)
{
File.WriteAllText(Conversions.ToString(GetFilePath(mcRoot)), JsonConvert.SerializeObject(this));
}
public static ModpackInfo Load(string mcRoot)
{
return JsonConvert.DeserializeObject<ModpackInfo>(File.ReadAllText(Conversions.ToString(GetFilePath(mcRoot))));
}
public static bool HasModpackInfo(string mcRoot)
{
return File.Exists(Conversions.ToString(GetFilePath(mcRoot)));
}
private static object GetFilePath(string mcRoot)
{
return Path.Combine(mcRoot, FILENAME_MODPACKINFO);
}
}

View File

@@ -1,29 +0,0 @@
Imports System.IO
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Public Class ModpackInfo
Private Const FILENAME_MODPACKINFO = "modpack-info.json"
<JsonConverter(GetType(VersionConverter))>
Public Property Version As Version
Public Sub Save(mcRoot As String)
File.WriteAllText(GetFilePath(mcRoot), JsonConvert.SerializeObject(Me))
End Sub
Public Shared Function Load(mcRoot As String) As ModpackInfo
Return JsonConvert.DeserializeObject(Of ModpackInfo)(File.ReadAllText(GetFilePath(mcRoot)))
End Function
Public Shared Function HasModpackInfo(mcRoot As String) As Boolean
Return File.Exists(GetFilePath(mcRoot))
End Function
Private Shared Function GetFilePath(mcRoot As String)
Return Path.Combine(mcRoot, FILENAME_MODPACKINFO)
End Function
End Class

View File

@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>ModpackUpdater.Model</RootNamespace>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>true</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pilz.Cryptography" Version="2.0.1" />
</ItemGroup>
</Project>
</Project>

View File

@@ -0,0 +1,12 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ModpackUpdater.Model;
public class UpdateAction : InstallAction
{
[JsonConverter(typeof(StringEnumConverter))]
public UpdateActionType Type { get; set; }
public string SrcPath { get; set; }
public bool IsDirectory { get; set; }
}

View File

@@ -1,12 +0,0 @@
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Public Class UpdateAction
Inherits InstallAction
<JsonConverter(GetType(StringEnumConverter))>
Public Property Type As UpdateActionType
Public Property SrcPath As String
Public Property IsDirectory As Boolean
End Class

View File

@@ -0,0 +1,10 @@
namespace ModpackUpdater.Model;
public enum UpdateActionType
{
None,
Update,
Delete,
Move,
Copy
}

View File

@@ -1,7 +0,0 @@
Public Enum UpdateActionType
None
Update
Delete
Move
Copy
End Enum

View File

@@ -0,0 +1,11 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace ModpackUpdater.Model;
public class UpdateInfo
{
[JsonConverter(typeof(VersionConverter))]
public Version Version { get; set; }
public List<UpdateAction> Actions { get; private set; } = [];
}

View File

@@ -1,10 +0,0 @@
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Converters
Public Class UpdateInfo
<JsonConverter(GetType(VersionConverter))>
Public Property Version As Version
Public ReadOnly Property Actions As New List(Of UpdateAction)
End Class

View File

@@ -0,0 +1,13 @@
using Newtonsoft.Json;
namespace ModpackUpdater.Model;
public class UpdateInfos
{
public List<UpdateInfo> Updates { get; private set; } = [];
public static UpdateInfos Parse(string content)
{
return JsonConvert.DeserializeObject<UpdateInfos>(content);
}
}

View File

@@ -1,11 +0,0 @@
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 JsonConvert.DeserializeObject(Of UpdateInfos)(content)
End Function
End Class