diff --git a/MinecraftLaunch.csproj b/MinecraftLaunch.csproj index a9d92b9..adb81a5 100644 --- a/MinecraftLaunch.csproj +++ b/MinecraftLaunch.csproj @@ -1,6 +1,6 @@ - 2.0.0 + 2.0.1 net7.0;net6.0 enable enable diff --git a/Modules/Enum/OpenJdkType.cs b/Modules/Enum/OpenJdkType.cs index 2588e0e..cff4ed8 100644 --- a/Modules/Enum/OpenJdkType.cs +++ b/Modules/Enum/OpenJdkType.cs @@ -1,9 +1,14 @@ +using System.ComponentModel; + namespace MinecraftLaunch.Modules.Enum; -public enum OpenJdkType -{ - OpenJdk8, - OpenJdk11, - OpenJdk17, - OpenJdk18 +public enum JavaVersion { + [Description("8")] + Java8, + + [Description("16")] + Java16, + + [Description("17")] + Java17, } diff --git a/Modules/Installer/JavaInstaller.cs b/Modules/Installer/JavaInstaller.cs index 86c046b..c10649c 100644 --- a/Modules/Installer/JavaInstaller.cs +++ b/Modules/Installer/JavaInstaller.cs @@ -36,7 +36,7 @@ public JavaInstaller(string path, DownloadJavaInfo javaInfo) { JavaInfo = javaInfo; } - public static async IAsyncEnumerable GetJavasByVersionAsync(int javaVersion) { + public static async IAsyncEnumerable GetJavasByVersionAsync(JavaVersion javaVersion) { string api = $"{(APIManager.Current == APIManager.Mojang ? "https://piston-meta.mojang.com" : APIManager.Current.Host)}" + $"/v1/products/java-runtime/2ec0cc96c44e5a76b9c8b7c39df7210883d12871/all.json"; @@ -58,11 +58,12 @@ public static async IAsyncEnumerable GetJavasByVersionAsync(in ? Convert.ToInt32(version.Split('.', 2)[0]) : Convert.ToInt32(version[0].ToString()); - if (firstVersion == javaVersion) { + if (firstVersion == Convert.ToInt32(javaVersion.AsDescription())) { var manifest = info["manifest"]; yield return new DownloadJavaInfo { - Type = java.Key, + OsType = java.Key, + JavaType = item.Key, Version = firstVersion, DetailVersion = version, Url = manifest["url"].GetValue(), @@ -157,9 +158,9 @@ public record DownloadJavaInfo { public int Version { get; set; } - public string Type { get; set; } + public string OsType { get; set; } - public string JavaPath { get; set; } + public string JavaType { get; set; } public string DetailVersion { get; set; } } diff --git a/Modules/Utilities/ExtendUtil.cs b/Modules/Utilities/ExtendUtil.cs index 01fcd15..17b9853 100644 --- a/Modules/Utilities/ExtendUtil.cs +++ b/Modules/Utilities/ExtendUtil.cs @@ -9,6 +9,9 @@ using System.IO.Compression; using System.Security.Cryptography; using System.IO; +using System.ComponentModel; +using System.Reflection; +using DateTimeConverter = MinecraftLaunch.Modules.Models.Download.DateTimeConverter; namespace MinecraftLaunch.Modules.Utilities; @@ -85,27 +88,6 @@ public static T ToJsonEntity(this string json) { return JsonSerializer.Deserialize(json)!; } - public static string ToFullJavaPath(this OpenJdkType open, string Save) { - string javapath = null; - switch (open) { - case OpenJdkType.OpenJdk8: - javapath += "OpenJDK 8"; - break; - case OpenJdkType.OpenJdk11: - javapath += "OpenJDK 11"; - break; - case OpenJdkType.OpenJdk17: - javapath += "OpenJDK 17"; - break; - case OpenJdkType.OpenJdk18: - javapath += "OpenJDK 18"; - break; - } - string obj = (Save.EndsWith('\\') ? (Save + javapath) : (Save.EndsWith("/") ? (Save + javapath) : (Save + "\\" + javapath))); - Directory.CreateDirectory(obj); - return obj; - } - public static List GetModInfoToVersion(this List ms, string version) { string version2 = version; List result = new List(); @@ -231,4 +213,12 @@ public static FileInfo Find(this DirectoryInfo directory, string file) { return null; } + + public static string? AsDescription(this System.Enum t) { + var type = t.GetType(); + var field = type.GetField(t.ToString()); + var description = field?.GetCustomAttribute(); + + return description?.Description; + } }