mirror of
https://github.com/zs-yg/MCSJ.git
synced 2025-12-06 10:50:42 +08:00
添加查看jre
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Threading.Tasks;
|
||||
using MCSJ.Tools;
|
||||
using MCSJ.Tools.LogSystem;
|
||||
using MCSJ.Tools.JreDownload;
|
||||
using MCSJ.Tools.ViewJre;
|
||||
|
||||
namespace MCSJ
|
||||
{
|
||||
@@ -22,6 +23,7 @@ namespace MCSJ
|
||||
};
|
||||
var versionManager = new VersionManager();
|
||||
var downloadService = new DownloadService(versionManager);
|
||||
var jreViewer = new JreViewer();
|
||||
LogMain.Debug("服务初始化完成");
|
||||
|
||||
while (true)
|
||||
@@ -30,7 +32,8 @@ namespace MCSJ
|
||||
Console.WriteLine("1. 显示所有版本");
|
||||
Console.WriteLine("2. 下载指定版本");
|
||||
Console.WriteLine("3. 下载JRE");
|
||||
Console.WriteLine("4. 退出");
|
||||
Console.WriteLine("4. 查看已安装的JRE");
|
||||
Console.WriteLine("5. 退出");
|
||||
Console.Write("请选择操作: ");
|
||||
|
||||
var input = Console.ReadLine();
|
||||
@@ -63,6 +66,10 @@ namespace MCSJ
|
||||
LogMain.Info($"JRE下载完成: {jreVersion}");
|
||||
break;
|
||||
case "4":
|
||||
jreViewer.DisplayInstalledJres();
|
||||
LogMain.Info("显示已安装的JRE列表");
|
||||
break;
|
||||
case "5":
|
||||
LogMain.Info("程序正常退出");
|
||||
return;
|
||||
default:
|
||||
|
||||
48
Tools/viewjre/JreViewer.cs
Normal file
48
Tools/viewjre/JreViewer.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace MCSJ.Tools.ViewJre
|
||||
{
|
||||
public class JreViewer
|
||||
{
|
||||
private const string SetupFolder = "setup";
|
||||
private const string JreTomlFile = "jre.toml";
|
||||
|
||||
public void DisplayInstalledJres()
|
||||
{
|
||||
var tomlPath = Path.Combine(SetupFolder, JreTomlFile);
|
||||
|
||||
if (!File.Exists(tomlPath))
|
||||
{
|
||||
Console.WriteLine("没有安装任何JRE");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var content = File.ReadAllText(tomlPath);
|
||||
var versions = content.Split('\n')
|
||||
.Where(line => line.StartsWith("[jre."))
|
||||
.Select(line => line.Split('.')[1].Split(']')[0].Trim()) // 精确提取版本号
|
||||
.ToList();
|
||||
|
||||
if (versions.Count == 0)
|
||||
{
|
||||
Console.WriteLine("没有安装任何JRE");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine("已安装的JRE版本:");
|
||||
foreach (var version in versions)
|
||||
{
|
||||
Console.WriteLine(version); // 直接输出版本号,不带前缀
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"读取JRE列表失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user