mirror of
https://github.com/zs-yg/MCSJ.git
synced 2025-12-06 10:50:42 +08:00
添加日志
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using MCSJ.Tools.LogSystem;
|
||||
|
||||
namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
@@ -8,15 +9,19 @@ namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
public static void AgreeEula()
|
||||
{
|
||||
LogMain.Info("开始处理EULA同意流程");
|
||||
|
||||
// 获取服务器列表
|
||||
var servers = ServerManager.GetServerProfiles();
|
||||
if (servers.Count == 0)
|
||||
{
|
||||
LogMain.Error("没有可用的服务器存档");
|
||||
Console.WriteLine("没有可用的服务器存档");
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示服务器列表供选择
|
||||
LogMain.Info($"找到 {servers.Count} 个服务器存档");
|
||||
Console.WriteLine("可用的服务器存档:");
|
||||
for (int i = 0; i < servers.Count; i++)
|
||||
{
|
||||
@@ -26,16 +31,19 @@ namespace MCSJ.Tools.ServerManagement
|
||||
Console.Write("请选择服务器(输入编号): ");
|
||||
if (!int.TryParse(Console.ReadLine(), out int serverIndex) || serverIndex < 1 || serverIndex > servers.Count)
|
||||
{
|
||||
LogMain.Warn($"无效的服务器选择: {serverIndex}");
|
||||
Console.WriteLine("无效选择");
|
||||
return;
|
||||
}
|
||||
|
||||
string selectedServer = servers[serverIndex - 1];
|
||||
LogMain.Info($"用户选择了服务器: {selectedServer}");
|
||||
string eulaPath = Path.Combine("profiles", selectedServer, "eula.txt");
|
||||
|
||||
// 检查eula文件是否存在
|
||||
if (!File.Exists(eulaPath))
|
||||
{
|
||||
LogMain.Warn($"没有找到eula.txt文件: {eulaPath}");
|
||||
Console.WriteLine("没有找到eula.txt文件");
|
||||
return;
|
||||
}
|
||||
@@ -44,6 +52,7 @@ namespace MCSJ.Tools.ServerManagement
|
||||
string eulaContent = File.ReadAllText(eulaPath);
|
||||
if (eulaContent.Contains("eula=true"))
|
||||
{
|
||||
LogMain.Info("EULA已经同意,无需修改");
|
||||
Console.WriteLine("EULA已经同意,无需修改");
|
||||
return;
|
||||
}
|
||||
@@ -52,10 +61,12 @@ namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
eulaContent = eulaContent.Replace("eula=false", "eula=true");
|
||||
File.WriteAllText(eulaPath, eulaContent);
|
||||
LogMain.Info("已成功同意EULA");
|
||||
Console.WriteLine("已同意EULA");
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMain.Error($"无效的eula.txt格式: {eulaPath}");
|
||||
Console.WriteLine("无效的eula.txt格式");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using MCSJ.Tools.LogSystem;
|
||||
|
||||
namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
@@ -8,15 +9,19 @@ namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
public static void GenerateScript()
|
||||
{
|
||||
LogMain.Info("开始生成服务器启动脚本");
|
||||
|
||||
// 获取服务器列表
|
||||
var servers = ServerManager.GetServerProfiles();
|
||||
if (servers.Count == 0)
|
||||
{
|
||||
LogMain.Error("没有可用的服务器存档");
|
||||
Console.WriteLine("没有可用的服务器存档");
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示服务器列表供选择
|
||||
LogMain.Info($"找到 {servers.Count} 个服务器存档");
|
||||
Console.WriteLine("可用的服务器存档:");
|
||||
for (int i = 0; i < servers.Count; i++)
|
||||
{
|
||||
@@ -26,17 +31,20 @@ namespace MCSJ.Tools.ServerManagement
|
||||
Console.Write("请选择服务器(输入编号): ");
|
||||
if (!int.TryParse(Console.ReadLine(), out int serverIndex) || serverIndex < 1 || serverIndex > servers.Count)
|
||||
{
|
||||
LogMain.Error($"无效的服务器选择: {serverIndex}");
|
||||
Console.WriteLine("无效选择");
|
||||
return;
|
||||
}
|
||||
|
||||
string selectedServer = servers[serverIndex - 1];
|
||||
LogMain.Info($"用户选择了服务器: {selectedServer}");
|
||||
string serverPath = Path.Combine("profiles", selectedServer);
|
||||
|
||||
// 检查JRE配置
|
||||
string jreConfigPath = "setup/jre.toml";
|
||||
if (!File.Exists(jreConfigPath) || new FileInfo(jreConfigPath).Length == 0)
|
||||
{
|
||||
LogMain.Error("没有找到有效的JRE配置");
|
||||
Console.WriteLine("没有下载的JRE,请先下载JRE");
|
||||
return;
|
||||
}
|
||||
@@ -63,6 +71,7 @@ namespace MCSJ.Tools.ServerManagement
|
||||
|
||||
if (jreVersions.Count == 0)
|
||||
{
|
||||
LogMain.Error("JRE配置文件为空");
|
||||
Console.WriteLine("没有可用的JRE配置");
|
||||
return;
|
||||
}
|
||||
@@ -86,10 +95,12 @@ namespace MCSJ.Tools.ServerManagement
|
||||
}
|
||||
|
||||
string selectedVersion = versionList[selectedVersionIndex - 1];
|
||||
LogMain.Info($"用户选择了JRE版本: {selectedVersion}");
|
||||
var versionConfig = jreVersions[selectedVersion];
|
||||
|
||||
if (!versionConfig.ContainsKey("java_path") || !versionConfig.ContainsKey("javaw_path"))
|
||||
{
|
||||
LogMain.Error($"JRE配置不完整: {selectedVersion}");
|
||||
Console.WriteLine("JRE配置不完整");
|
||||
return;
|
||||
}
|
||||
@@ -111,6 +122,7 @@ namespace MCSJ.Tools.ServerManagement
|
||||
|
||||
string scriptPath = Path.Combine(serverPath, "start.bat");
|
||||
File.WriteAllText(scriptPath, scriptContent);
|
||||
LogMain.Info($"成功生成启动脚本: {scriptPath}");
|
||||
Console.WriteLine($"已生成启动脚本: {scriptPath}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using MCSJ.Tools.LogSystem;
|
||||
|
||||
namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
@@ -12,6 +13,7 @@ namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
LogMain.Info("显示服务器管理菜单");
|
||||
Console.WriteLine("\n=== 服务器管理 ===");
|
||||
Console.WriteLine("1. 生成启动脚本");
|
||||
Console.WriteLine("2. 启动服务器");
|
||||
@@ -23,17 +25,22 @@ namespace MCSJ.Tools.ServerManagement
|
||||
switch (choice)
|
||||
{
|
||||
case "1":
|
||||
LogMain.Info("用户选择: 生成启动脚本");
|
||||
ScriptGenerator.GenerateScript();
|
||||
break;
|
||||
case "2":
|
||||
LogMain.Info("用户选择: 启动服务器");
|
||||
ServerStarter.StartServer();
|
||||
break;
|
||||
case "3":
|
||||
LogMain.Info("用户选择: 同意eula.txt");
|
||||
EulaAgreer.AgreeEula();
|
||||
break;
|
||||
case "4":
|
||||
LogMain.Info("用户选择: 返回主菜单");
|
||||
return;
|
||||
default:
|
||||
LogMain.Warn($"无效菜单选项: {choice}");
|
||||
Console.WriteLine("无效选项");
|
||||
break;
|
||||
}
|
||||
@@ -48,11 +55,16 @@ namespace MCSJ.Tools.ServerManagement
|
||||
var profiles = new List<string>();
|
||||
if (Directory.Exists("profiles"))
|
||||
{
|
||||
LogMain.Info("获取服务器存档列表");
|
||||
foreach (var dir in Directory.GetDirectories("profiles"))
|
||||
{
|
||||
profiles.Add(Path.GetFileName(dir));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogMain.Warn("服务器存档目录不存在");
|
||||
}
|
||||
return profiles;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
using MCSJ.Tools.LogSystem;
|
||||
|
||||
namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
@@ -9,15 +10,19 @@ namespace MCSJ.Tools.ServerManagement
|
||||
{
|
||||
public static void StartServer()
|
||||
{
|
||||
LogMain.Info("开始启动服务器流程");
|
||||
|
||||
// 获取服务器列表
|
||||
var servers = ServerManager.GetServerProfiles();
|
||||
if (servers.Count == 0)
|
||||
{
|
||||
LogMain.Error("没有可用的服务器存档");
|
||||
Console.WriteLine("没有可用的服务器存档");
|
||||
return;
|
||||
}
|
||||
|
||||
// 显示服务器列表供选择
|
||||
LogMain.Info($"找到 {servers.Count} 个服务器存档");
|
||||
Console.WriteLine("可用的服务器存档:");
|
||||
for (int i = 0; i < servers.Count; i++)
|
||||
{
|
||||
@@ -27,17 +32,20 @@ namespace MCSJ.Tools.ServerManagement
|
||||
Console.Write("请选择服务器(输入编号): ");
|
||||
if (!int.TryParse(Console.ReadLine(), out int serverIndex) || serverIndex < 1 || serverIndex > servers.Count)
|
||||
{
|
||||
LogMain.Warn($"无效的服务器选择: {serverIndex}");
|
||||
Console.WriteLine("无效选择");
|
||||
return;
|
||||
}
|
||||
|
||||
string selectedServer = servers[serverIndex - 1];
|
||||
LogMain.Info($"用户选择了服务器: {selectedServer}");
|
||||
string serverPath = Path.Combine("profiles", selectedServer);
|
||||
string batPath = Path.Combine(serverPath, "start.bat");
|
||||
|
||||
// 检查启动脚本是否存在
|
||||
if (!File.Exists(batPath))
|
||||
{
|
||||
LogMain.Warn($"没有找到启动脚本: {batPath}");
|
||||
Console.WriteLine("没有找到启动脚本,请先生成脚本");
|
||||
return;
|
||||
}
|
||||
@@ -50,6 +58,7 @@ namespace MCSJ.Tools.ServerManagement
|
||||
|
||||
if (!File.Exists(fullBatPath))
|
||||
{
|
||||
LogMain.Error($"启动脚本不存在: {fullBatPath}");
|
||||
Console.WriteLine($"启动脚本不存在: {fullBatPath}");
|
||||
return;
|
||||
}
|
||||
@@ -62,14 +71,18 @@ namespace MCSJ.Tools.ServerManagement
|
||||
CreateNoWindow = false
|
||||
};
|
||||
|
||||
LogMain.Info($"启动路径: {fullBatPath}");
|
||||
LogMain.Info($"工作目录: {fullServerPath}");
|
||||
Console.WriteLine($"启动路径: {fullBatPath}");
|
||||
Console.WriteLine($"工作目录: {fullServerPath}");
|
||||
|
||||
Process.Start(startInfo);
|
||||
LogMain.Info($"成功启动服务器: {selectedServer}");
|
||||
Console.WriteLine($"已启动服务器: {selectedServer}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogMain.Error($"启动服务器失败: {ex.Message}");
|
||||
Console.WriteLine($"启动服务器失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user