From 548784eea037a53e46ce19a67fa92a85a2d44855 Mon Sep 17 00:00:00 2001 From: YangSpring114 Date: Sun, 17 Dec 2023 13:02:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=87=AA=E5=8A=A8=E6=90=9C?= =?UTF-8?q?=E5=AF=BB=E5=90=88=E9=80=82=E7=9A=84Java=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MinecraftLaunch/Classes/Models/Game/GameEntry.cs | 2 ++ MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs | 3 +++ MinecraftLaunch/Components/Resolver/GameResolver.cs | 3 ++- MinecraftLaunch/MinecraftLaunch.csproj | 11 +++++------ MinecraftLaunch/Utilities/JavaUtil.cs | 12 ++++++++++++ 5 files changed, 24 insertions(+), 7 deletions(-) diff --git a/MinecraftLaunch/Classes/Models/Game/GameEntry.cs b/MinecraftLaunch/Classes/Models/Game/GameEntry.cs index e6b2a1a..b7cdb71 100644 --- a/MinecraftLaunch/Classes/Models/Game/GameEntry.cs +++ b/MinecraftLaunch/Classes/Models/Game/GameEntry.cs @@ -8,6 +8,8 @@ public record GameEntry { public string Type { get; set; } + public int JavaVersion { get; set; } + public LoaderType MainLoaderType { get; set; } public bool IsVanilla { get; set; } diff --git a/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs b/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs index 5a764ed..2aacede 100644 --- a/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs +++ b/MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs @@ -22,6 +22,9 @@ public record GameJsonEntry { [JsonPropertyName("assets")] public string Assets { get; set; } + [JsonPropertyName("javaVersion")] + public JsonNode JavaVersion { get; set; } + [JsonPropertyName("arguments")] public ArgumentsJsonEntry Arguments { get; set; } diff --git a/MinecraftLaunch/Components/Resolver/GameResolver.cs b/MinecraftLaunch/Components/Resolver/GameResolver.cs index 64feacf..6dcaf44 100644 --- a/MinecraftLaunch/Components/Resolver/GameResolver.cs +++ b/MinecraftLaunch/Components/Resolver/GameResolver.cs @@ -31,7 +31,8 @@ public GameEntry GetGameEntity(string id) { GameFolderPath = root, IsInheritedFrom = false, MainClass = entity.MainClass, - MainLoaderType = entity.GetGameLoaderType() + MainLoaderType = entity.GetGameLoaderType(), + JavaVersion = entity.JavaVersion.GetInt32("majorVersion"), }; var assetsIndexFile = Path.Combine(root, "assets", "indexes", $"{entity.AssetIndex?.Id}.json"); diff --git a/MinecraftLaunch/MinecraftLaunch.csproj b/MinecraftLaunch/MinecraftLaunch.csproj index 8de8574..e63339c 100644 --- a/MinecraftLaunch/MinecraftLaunch.csproj +++ b/MinecraftLaunch/MinecraftLaunch.csproj @@ -16,15 +16,14 @@ MinecraftLaunch disable - + - + + + - - True - - + diff --git a/MinecraftLaunch/Utilities/JavaUtil.cs b/MinecraftLaunch/Utilities/JavaUtil.cs index d784af8..107d52f 100644 --- a/MinecraftLaunch/Utilities/JavaUtil.cs +++ b/MinecraftLaunch/Utilities/JavaUtil.cs @@ -63,6 +63,18 @@ public static JavaEntry GetJavaInfo(string path) { } } + public static JavaEntry GetCurrentJava(IReadOnlyList javaEntries, GameEntry entry) { + var result = javaEntries.FirstOrDefault(x => x.Is64Bit && x.JavaSlugVersion == entry.JavaVersion) + ?? javaEntries.FirstOrDefault(x => x.JavaSlugVersion == entry.JavaVersion); + + if (result == null) { + throw new InvalidOperationException("No suitable Java found"); + } + + return result; + } + + [SupportedOSPlatform(nameof(OSPlatform.Windows))] private static bool GetIs64Bit(string path) { ushort architecture = 0;