Skip to content

Commit b3ba87e

Browse files
committed
修正JRE和JDK判断问题:有javac的才是jdk
1 parent 8f49314 commit b3ba87e

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

PCL2.Neo/Models/Minecraft/Java/JavaData.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public bool IsJre
8484
return _isJre.Value;
8585
}
8686

87-
var result = File.Exists(System.IO.Path.Combine(Path,
87+
var hasJavac = File.Exists(System.IO.Path.Combine(Path,
8888
RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? "javac.exe" : "javac"));
89-
_isJre = result;
90-
return result;
89+
_isJre = !hasJavac;
90+
return _isJre.Value;
9191
}
9292
}
9393

PCL2.Neo/Views/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
Name="TestLoading"
232232
Width="150" />
233233
<pc:MyButton Height="50" Margin="10" />
234-
<pc:MyButton Height="50" Margin="10" />
234+
<pc:MyButton Height="50" Margin="10" Text="搜索 Java" Click="Search_Java_Button"/>
235235
<pc:MyCard Margin="10" />
236236
</StackPanel>
237237
</ScrollViewer>

PCL2.Neo/Views/MainWindow.axaml.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
using PCL2.Neo.Animations.Easings;
88
using PCL2.Neo.Controls;
99
using PCL2.Neo.Helpers;
10+
using PCL2.Neo.Models.Minecraft.Java;
1011
using System;
12+
using System.Linq;
1113
using System.Threading.Tasks;
1214

1315
namespace PCL2.Neo.Views;
@@ -77,4 +79,27 @@ private void Button2_OnClick(object? sender, RoutedEventArgs e)
7779
{
7880
this.TestLoading.State = MyLoading.LoadingState.Error;
7981
}
82+
83+
private async void Search_Java_Button(object? sender, RoutedEventArgs e)
84+
{
85+
try
86+
{
87+
var javas = await Java.SearchJava();
88+
Console.WriteLine($"找到 {javas.Count()} 个Java环境:");
89+
90+
foreach (var java in javas)
91+
{
92+
Console.WriteLine("----------------------");
93+
Console.WriteLine($"路径: {java.Path}");
94+
Console.WriteLine($"版本: Java {java.Version}");
95+
Console.WriteLine($"位数: {(java.Is64Bit ? "64位" : "32位")}");
96+
Console.WriteLine($"类型: {(java.IsJre ? "JRE" : "JDK")}");
97+
Console.WriteLine($"可用: {java.IsUsable}");
98+
}
99+
}
100+
catch (Exception ex)
101+
{
102+
Console.WriteLine($"搜索失败: {ex.Message}");
103+
}
104+
}
80105
}

0 commit comments

Comments
 (0)