convert to c#
This commit is contained in:
9
ModpackUpdater.Model/InstallAction.cs
Normal file
9
ModpackUpdater.Model/InstallAction.cs
Normal 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; }
|
||||
}
|
||||
@@ -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
|
||||
13
ModpackUpdater.Model/InstallInfos.cs
Normal file
13
ModpackUpdater.Model/InstallInfos.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
16
ModpackUpdater.Model/ModpackConfig.cs
Normal file
16
ModpackUpdater.Model/ModpackConfig.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
33
ModpackUpdater.Model/ModpackInfo.cs
Normal file
33
ModpackUpdater.Model/ModpackInfo.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
@@ -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>
|
||||
12
ModpackUpdater.Model/UpdateAction.cs
Normal file
12
ModpackUpdater.Model/UpdateAction.cs
Normal 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; }
|
||||
}
|
||||
@@ -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
|
||||
10
ModpackUpdater.Model/UpdateActionType.cs
Normal file
10
ModpackUpdater.Model/UpdateActionType.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace ModpackUpdater.Model;
|
||||
|
||||
public enum UpdateActionType
|
||||
{
|
||||
None,
|
||||
Update,
|
||||
Delete,
|
||||
Move,
|
||||
Copy
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
Public Enum UpdateActionType
|
||||
None
|
||||
Update
|
||||
Delete
|
||||
Move
|
||||
Copy
|
||||
End Enum
|
||||
11
ModpackUpdater.Model/UpdateInfo.cs
Normal file
11
ModpackUpdater.Model/UpdateInfo.cs
Normal 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; } = [];
|
||||
}
|
||||
@@ -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
|
||||
13
ModpackUpdater.Model/UpdateInfos.cs
Normal file
13
ModpackUpdater.Model/UpdateInfos.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user