Skip to content

Commit

Permalink
添加自动搜寻合适的Java的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
YangSpring114 committed Dec 17, 2023
1 parent 79cdc4e commit 548784e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions MinecraftLaunch/Classes/Models/Game/GameEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 3 additions & 0 deletions MinecraftLaunch/Classes/Models/Game/GameJsonEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
3 changes: 2 additions & 1 deletion MinecraftLaunch/Components/Resolver/GameResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
11 changes: 5 additions & 6 deletions MinecraftLaunch/MinecraftLaunch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
<Title>MinecraftLaunch</Title>
<Nullable>disable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Flurl.Http" Version="4.0.0-pre7" />
<Compile Remove=".nuget\**" />
<None Remove=".nuget\**" />
<EmbeddedResource Remove=".nuget\**" />
</ItemGroup>

<ItemGroup>
<None Include=".nuget\logo.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
<PackageReference Include="Flurl.Http" Version="4.0.0-pre7" />
</ItemGroup>
</Project>
12 changes: 12 additions & 0 deletions MinecraftLaunch/Utilities/JavaUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@ public static JavaEntry GetJavaInfo(string path) {
}
}

public static JavaEntry GetCurrentJava(IReadOnlyList<JavaEntry> 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;
Expand Down

0 comments on commit 548784e

Please sign in to comment.