15 Commits

Author SHA1 Message Date
zs-yg
94b2e7a196 添加papermc的下载地址 2025-11-23 11:55:53 +08:00
zs-yg
8c5d3a8219 解决警告问题 2025-11-23 09:50:39 +08:00
zs-yg
060edfb873 添加日志 2025-11-23 09:44:24 +08:00
zs-yg
397002f2e8 添加管理服务器功能 2025-11-23 09:24:49 +08:00
zs-yg
9e5e290da5 删除镜像站 2025-11-22 20:36:32 +08:00
zs-yg
59b7c84310 添加日志和修改文本输出 2025-11-22 20:03:12 +08:00
zs-yg
306a7bb309 添加查看jre 2025-11-22 19:51:40 +08:00
zs-yg
62713817e1 添加镜像仓库 2025-11-22 18:38:15 +08:00
zs-yg
1870b066fc 添加镜像仓库 2025-11-22 18:33:00 +08:00
zs-yg
7d74c603b8 添加镜像仓库 2025-11-22 18:29:18 +08:00
zs-yg
aea0742092 添加镜像仓库 2025-11-22 18:28:24 +08:00
zs-yg
295791b4f2 添加pre2和pre1 2025-11-22 18:10:37 +08:00
zs-yg
ff0cf01100 添加一键删除打包文件夹至构建脚本 2025-11-21 19:13:38 +08:00
zs-yg
b88c7507aa 添加7z一键压缩至构建脚本 2025-11-21 19:12:18 +08:00
zs-yg
969fcdff6e 修复下载jre的已知问题 2025-11-20 21:08:01 +08:00
13 changed files with 569 additions and 13 deletions

View File

@@ -3,6 +3,8 @@ using System.Threading.Tasks;
using MCSJ.Tools; using MCSJ.Tools;
using MCSJ.Tools.LogSystem; using MCSJ.Tools.LogSystem;
using MCSJ.Tools.JreDownload; using MCSJ.Tools.JreDownload;
using MCSJ.Tools.ViewJre;
using MCSJ.Tools.ServerManagement;
namespace MCSJ namespace MCSJ
{ {
@@ -15,22 +17,25 @@ namespace MCSJ
Console.WriteLine($"日志目录: {logDir}"); Console.WriteLine($"日志目录: {logDir}");
LogMain.Debug($"日志文件: {LogCreator.GetLogFilePath()}"); LogMain.Debug($"日志文件: {LogCreator.GetLogFilePath()}");
LogMain.Info("MC服务器下载工具启动"); LogMain.Info("MC服务器启动工具启动");
var httpClient = new HttpClient { var httpClient = new HttpClient {
Timeout = TimeSpan.FromMinutes(5), Timeout = TimeSpan.FromMinutes(5),
DefaultRequestHeaders = { { "User-Agent", "MCSJ-JRE-Downloader" } } DefaultRequestHeaders = { { "User-Agent", "MCSJ-JRE-Downloader" } }
}; };
var versionManager = new VersionManager(); var versionManager = new VersionManager();
var downloadService = new DownloadService(versionManager); var downloadService = new DownloadService(versionManager);
var jreViewer = new JreViewer();
LogMain.Debug("服务初始化完成"); LogMain.Debug("服务初始化完成");
while (true) while (true)
{ {
Console.WriteLine("MC服务器下载工具"); Console.WriteLine("MC服务器启动工具");
Console.WriteLine("1. 显示所有版本"); Console.WriteLine("1. 显示所有服务器版本");
Console.WriteLine("2. 下载指定版本"); Console.WriteLine("2. 下载指定服务器版本");
Console.WriteLine("3. 下载JRE"); Console.WriteLine("3. 服务器管理");
Console.WriteLine("4. 退出"); Console.WriteLine("4. 下载JRE");
Console.WriteLine("5. 查看已安装的JRE");
Console.WriteLine("6. 退出");
Console.Write("请选择操作: "); Console.Write("请选择操作: ");
var input = Console.ReadLine(); var input = Console.ReadLine();
@@ -50,7 +55,11 @@ namespace MCSJ
LogMain.Info($"版本下载完成: {version}"); LogMain.Info($"版本下载完成: {version}");
break; break;
case "3": case "3":
Console.Write("请输入要下载的JRE版本(如jre8,jre11等): "); ServerManager.ShowMenu();
LogMain.Info("进入服务器管理");
break;
case "4":
Console.Write("请输入要下载的JRE版本(jre8,jre11,jre17/21/25): ");
var jreVersion = Console.ReadLine(); var jreVersion = Console.ReadLine();
if (string.IsNullOrWhiteSpace(jreVersion)) if (string.IsNullOrWhiteSpace(jreVersion))
{ {
@@ -62,7 +71,11 @@ namespace MCSJ
await jreDownloadService.DownloadAndSetupJre(jreVersion); await jreDownloadService.DownloadAndSetupJre(jreVersion);
LogMain.Info($"JRE下载完成: {jreVersion}"); LogMain.Info($"JRE下载完成: {jreVersion}");
break; break;
case "4": case "5":
jreViewer.DisplayInstalledJres();
LogMain.Info("显示已安装的JRE列表");
break;
case "6":
LogMain.Info("程序正常退出"); LogMain.Info("程序正常退出");
return; return;
default: default:

View File

@@ -35,7 +35,11 @@ MCSJ 是一个开源的 Minecraft 服务器管理工具,旨在为用户提供
2. 双击运行 MCSJ.exe 启动程序。 2. 双击运行 MCSJ.exe 启动程序。
3. 或者命令行输入MCSJ.exe 启动程序。可以查看是否需要安装运行时 3. 或者命令行输入MCSJ.exe 启动程序。可以查看是否需要安装运行时
## 关于作者 ## 官方镜像仓库
[gitee镜像仓库](https://gitee.com/chr_super/mcsj)
## 关于
MCSJ 项目由 [zs-yg](https://github.com/zs-yg) 开发,欢迎提交 issue 和 PR。 MCSJ 项目由 [zs-yg](https://github.com/zs-yg) 开发,欢迎提交 issue 和 PR。

View File

@@ -2,6 +2,7 @@ using System;
using System.IO; using System.IO;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools namespace MCSJ.Tools
{ {
@@ -21,6 +22,7 @@ namespace MCSJ.Tools
if (string.IsNullOrWhiteSpace(version)) if (string.IsNullOrWhiteSpace(version))
{ {
Console.WriteLine("版本名称不能为空"); Console.WriteLine("版本名称不能为空");
LogMain.Error("版本名称不能为空");
return; return;
} }
@@ -28,6 +30,7 @@ namespace MCSJ.Tools
if (string.IsNullOrEmpty(url)) if (string.IsNullOrEmpty(url))
{ {
Console.WriteLine($"版本 {version} 不存在"); Console.WriteLine($"版本 {version} 不存在");
LogMain.Error($"版本 {version} 不存在");
return; return;
} }
@@ -47,10 +50,12 @@ namespace MCSJ.Tools
if (!Directory.Exists(profilePath)) if (!Directory.Exists(profilePath))
break; break;
Console.WriteLine($"文件夹 '{targetFolder}' 已存在,请重新输入(直接回车则取消下载):"); Console.WriteLine($"文件夹 '{targetFolder}' 已存在,请重新输入(直接回车则取消下载):");
LogMain.Warn($"文件夹 '{targetFolder}' 已存在,请重新输入(直接回车则取消下载):");
} }
if (Directory.Exists(profilePath)) if (Directory.Exists(profilePath))
{ {
Console.WriteLine("下载已取消。"); Console.WriteLine("下载已取消。");
LogMain.Info("下载已取消。");
return; return;
} }
Directory.CreateDirectory(profilePath); Directory.CreateDirectory(profilePath);
@@ -59,6 +64,7 @@ namespace MCSJ.Tools
try try
{ {
Console.WriteLine($"开始下载 {version} 到 {profilePath} ..."); Console.WriteLine($"开始下载 {version} 到 {profilePath} ...");
LogMain.Info($"开始下载 {version} 到 {profilePath} ...");
var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
@@ -90,10 +96,12 @@ namespace MCSJ.Tools
} }
} }
Console.WriteLine($"\n{version} 下载完成! 文件已保存到 {jarPath}"); Console.WriteLine($"\n{version} 下载完成! 文件已保存到 {jarPath}");
LogMain.Info($"{version} 下载完成! 文件已保存到 {jarPath}");
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"下载失败: {ex.Message}"); Console.WriteLine($"下载失败: {ex.Message}");
LogMain.Error($"下载失败: {ex.Message}");
} }
} }
} }

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools namespace MCSJ.Tools
{ {
@@ -19,6 +20,7 @@ namespace MCSJ.Tools
{ {
var filePath = Path.Combine("resources", "serverlist.txt"); var filePath = Path.Combine("resources", "serverlist.txt");
Console.WriteLine($"尝试从路径加载版本列表: {Path.GetFullPath(filePath)}"); Console.WriteLine($"尝试从路径加载版本列表: {Path.GetFullPath(filePath)}");
LogMain.Info($"尝试从路径加载版本列表: {Path.GetFullPath(filePath)}");
if (!File.Exists(filePath)) if (!File.Exists(filePath))
{ {
@@ -42,7 +44,8 @@ namespace MCSJ.Tools
if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(url)) if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(url))
{ {
Console.WriteLine($"忽略无效条目: {rawLine} (版本或URL为空)"); Console.WriteLine($"忽略无效条目: {rawLine} (版本或URL为空)");
LogMain.Warn($"忽略无效条目: {rawLine} (版本或URL为空)");
continue; continue;
} }
@@ -51,6 +54,7 @@ namespace MCSJ.Tools
else else
{ {
Console.WriteLine($"忽略无效条目: {rawLine} (缺少冒号分隔或格式不正确)"); Console.WriteLine($"忽略无效条目: {rawLine} (缺少冒号分隔或格式不正确)");
LogMain.Warn($"忽略无效条目: {rawLine} (缺少冒号分隔或格式不正确)");
} }
} }
@@ -60,12 +64,15 @@ namespace MCSJ.Tools
} }
Console.WriteLine($"成功加载 {_versions.Count} 个版本"); Console.WriteLine($"成功加载 {_versions.Count} 个版本");
LogMain.Info($"成功加载 {_versions.Count} 个版本");
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"加载版本列表失败: {ex.Message}"); Console.WriteLine($"加载版本列表失败: {ex.Message}");
Console.WriteLine($"当前工作目录: {Directory.GetCurrentDirectory()}"); Console.WriteLine($"当前工作目录: {Directory.GetCurrentDirectory()}");
Console.WriteLine("请确保serverlist.txt每行格式为: 版本名:下载URL (版本名可以包含空格),支持以#开头的注释"); Console.WriteLine("请确保serverlist.txt每行格式为: 版本名:下载URL (版本名可以包含空格),支持以#开头的注释");
LogMain.Error($"加载版本列表失败: {ex.Message}");
LogMain.Error($"当前工作目录: {Directory.GetCurrentDirectory()}");
} }
} }
@@ -75,10 +82,12 @@ namespace MCSJ.Tools
if (!File.Exists(filePath)) if (!File.Exists(filePath))
{ {
Console.WriteLine("版本列表文件不存在"); Console.WriteLine("版本列表文件不存在");
LogMain.Error("版本列表文件不存在");
return; return;
} }
Console.WriteLine("可用版本列表:"); Console.WriteLine("可用版本列表:");
LogMain.Info("可用版本列表:");
foreach (var version in _versions.Keys) foreach (var version in _versions.Keys)
{ {
Console.WriteLine(version); Console.WriteLine(version);

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools.JreDownload namespace MCSJ.Tools.JreDownload
{ {
@@ -33,6 +34,7 @@ namespace MCSJ.Tools.JreDownload
if (percentage == 100) if (percentage == 100)
{ {
Console.WriteLine(); Console.WriteLine();
LogMain.Info("JRE下载完成");
} }
} }
finally finally

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.IO.Compression; using System.IO.Compression;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools.JreDownload namespace MCSJ.Tools.JreDownload
{ {
@@ -21,11 +22,20 @@ namespace MCSJ.Tools.JreDownload
public async Task DownloadAndSetupJre(string version) public async Task DownloadAndSetupJre(string version)
{ {
// 0. 检查是否已存在该版本
if (CheckJreExists(version))
{
Console.WriteLine($"JRE {version} 已存在,无需重复下载");
LogMain.Info($"JRE {version} 已存在,无需重复下载");
return;
}
// 1. 读取jrelist.txt获取下载链接 // 1. 读取jrelist.txt获取下载链接
var downloadUrl = GetDownloadUrl(version); var downloadUrl = GetDownloadUrl(version);
if (string.IsNullOrEmpty(downloadUrl)) if (string.IsNullOrEmpty(downloadUrl))
{ {
Console.WriteLine($"找不到版本 {version} 的下载链接"); Console.WriteLine($"找不到版本 {version} 的下载链接");
LogMain.Error($"找不到版本 {version} 的下载链接");
return; return;
} }
@@ -35,6 +45,7 @@ namespace MCSJ.Tools.JreDownload
if (string.IsNullOrEmpty(tempZipPath)) if (string.IsNullOrEmpty(tempZipPath))
{ {
Console.WriteLine("下载失败"); Console.WriteLine("下载失败");
LogMain.Error("下载失败");
return; return;
} }
@@ -43,6 +54,7 @@ namespace MCSJ.Tools.JreDownload
if (!ExtractJre(tempZipPath, jreFolder)) if (!ExtractJre(tempZipPath, jreFolder))
{ {
Console.WriteLine("解压失败"); Console.WriteLine("解压失败");
LogMain.Error("解压失败");
return; return;
} }
@@ -53,6 +65,7 @@ namespace MCSJ.Tools.JreDownload
if (javaExePath == null || javawExePath == null) if (javaExePath == null || javawExePath == null)
{ {
Console.WriteLine("找不到java.exe或javaw.exe"); Console.WriteLine("找不到java.exe或javaw.exe");
LogMain.Error("找不到java.exe或javaw.exe");
return; return;
} }
@@ -62,7 +75,8 @@ namespace MCSJ.Tools.JreDownload
// 6. 清理临时文件 // 6. 清理临时文件
File.Delete(tempZipPath); File.Delete(tempZipPath);
Console.WriteLine($"JRE {version} 安装完成"); Console.WriteLine($"JRE {version} 安装完成");
LogMain.Info($"JRE {version} 安装完成");
} }
private string? GetDownloadUrl(string version) private string? GetDownloadUrl(string version)
@@ -92,18 +106,22 @@ namespace MCSJ.Tools.JreDownload
if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) if (!Uri.IsWellFormedUriString(url, UriKind.Absolute))
{ {
Console.WriteLine($"无效的下载URL: {url}"); Console.WriteLine($"无效的下载URL: {url}");
LogMain.Error($"无效的下载URL: {url}");
return null; return null;
} }
Console.WriteLine($"正在准备下载 {url}..."); Console.WriteLine($"正在准备下载 {url}...");
LogMain.Info($"正在准备下载 {url}...");
var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var totalBytes = response.Content.Headers.ContentLength ?? 0; var totalBytes = response.Content.Headers.ContentLength ?? 0;
Console.WriteLine($"文件总大小: {totalBytes} 字节"); Console.WriteLine($"文件总大小: {totalBytes} 字节");
LogMain.Info($"文件总大小: {totalBytes} 字节");
long bytesRead = 0; long bytesRead = 0;
var lastReportTime = DateTime.MinValue; var lastReportTime = DateTime.MinValue;
Console.WriteLine("开始下载..."); Console.WriteLine("开始下载...");
LogMain.Info("开始下载...");
using (var stream = await response.Content.ReadAsStreamAsync()) using (var stream = await response.Content.ReadAsStreamAsync())
using (var fileStream = new FileStream(tempPath, FileMode.Create)) using (var fileStream = new FileStream(tempPath, FileMode.Create))
@@ -132,6 +150,7 @@ namespace MCSJ.Tools.JreDownload
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"下载失败: {ex.Message}"); Console.WriteLine($"下载失败: {ex.Message}");
LogMain.Error($"下载失败: {ex.Message}");
return null; return null;
} }
} }
@@ -150,6 +169,7 @@ namespace MCSJ.Tools.JreDownload
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine($"解压失败: {ex.Message}"); Console.WriteLine($"解压失败: {ex.Message}");
LogMain.Error($"解压失败: {ex.Message}");
return false; return false;
} }
} }
@@ -165,6 +185,23 @@ namespace MCSJ.Tools.JreDownload
return Directory.GetFiles(folder, exeName, SearchOption.AllDirectories).FirstOrDefault(); return Directory.GetFiles(folder, exeName, SearchOption.AllDirectories).FirstOrDefault();
} }
private bool CheckJreExists(string version)
{
var tomlPath = Path.Combine(SetupFolder, "jre.toml");
if (!File.Exists(tomlPath))
return false;
try
{
var content = File.ReadAllText(tomlPath);
return content.Contains($"[jre.{version}]");
}
catch
{
return false;
}
}
private void CreateJreToml(string version, string javaExePath, string javawExePath) private void CreateJreToml(string version, string javaExePath, string javawExePath)
{ {
if (!Directory.Exists(SetupFolder)) if (!Directory.Exists(SetupFolder))

View File

@@ -0,0 +1,74 @@
using System;
using System.IO;
using System.Collections.Generic;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools.ServerManagement
{
public static class EulaAgreer
{
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++)
{
Console.WriteLine($"{i + 1}. {servers[i]}");
}
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;
}
// 读取并修改eula文件
string eulaContent = File.ReadAllText(eulaPath);
if (eulaContent.Contains("eula=true"))
{
LogMain.Info("EULA已经同意无需修改");
Console.WriteLine("EULA已经同意无需修改");
return;
}
if (eulaContent.Contains("eula=false"))
{
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格式");
}
}
}
}

View File

@@ -0,0 +1,133 @@
using System;
using System.IO;
using System.Collections.Generic;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools.ServerManagement
{
public static class ScriptGenerator
{
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++)
{
Console.WriteLine($"{i + 1}. {servers[i]}");
}
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;
}
// 解析JRE配置
var jreVersions = new Dictionary<string, Dictionary<string, string>>();
string currentVersion = string.Empty;
foreach (var line in File.ReadAllLines(jreConfigPath))
{
if (line.StartsWith("[") && line.EndsWith("]"))
{
var version = line.Trim('[', ']');
currentVersion = version ?? string.Empty;
if (currentVersion != null!)
{
jreVersions[currentVersion] = new Dictionary<string, string>();
}
}
else if (line.Contains("=") && currentVersion != null)
{
var parts = line.Split('=');
string key = parts[0].Trim();
string value = parts[1].Trim().Trim('\'');
jreVersions[currentVersion][key] = value;
}
}
if (jreVersions.Count == 0)
{
LogMain.Error("JRE配置文件为空");
Console.WriteLine("没有可用的JRE配置");
return;
}
// 选择JRE版本
Console.WriteLine("可用的JRE版本:");
int versionIndex = 1;
var versionList = new List<string>(jreVersions.Keys);
foreach (var version in versionList)
{
Console.WriteLine($"{versionIndex}. {version}");
versionIndex++;
}
Console.Write("请选择JRE版本(输入编号): ");
if (!int.TryParse(Console.ReadLine(), out int selectedVersionIndex) ||
selectedVersionIndex < 1 || selectedVersionIndex > versionList.Count)
{
Console.WriteLine("无效选择");
return;
}
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;
}
// 选择java执行方式
Console.WriteLine("选择Java执行方式:");
Console.WriteLine("1. java.exe (控制台模式)");
Console.WriteLine("2. javaw.exe (无控制台模式)");
Console.Write("请选择: ");
string javaPath = Console.ReadLine() == "1"
? Path.GetFullPath(versionConfig["java_path"])
: Path.GetFullPath(versionConfig["javaw_path"]);
// 生成启动脚本(统一使用反斜杠)
string scriptContent = $"@echo off\r\n" +
$"cd /D \"{Path.GetFullPath(serverPath).Replace('/', '\\')}\"\r\n" +
$"\"{javaPath.Replace('/', '\\')}\" -jar server.jar\r\n" +
"pause";
string scriptPath = Path.Combine(serverPath, "start.bat");
File.WriteAllText(scriptPath, scriptContent);
LogMain.Info($"成功生成启动脚本: {scriptPath}");
Console.WriteLine($"已生成启动脚本: {scriptPath}");
}
}
}

View File

@@ -0,0 +1,71 @@
using System;
using System.IO;
using System.Collections.Generic;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools.ServerManagement
{
public class ServerManager
{
private const int SERVER_MANAGEMENT_OPTION = 3;
public static void ShowMenu()
{
while (true)
{
LogMain.Info("显示服务器管理菜单");
Console.WriteLine("\n=== 服务器管理 ===");
Console.WriteLine("1. 生成启动脚本");
Console.WriteLine("2. 启动服务器");
Console.WriteLine("3. 同意eula.txt");
Console.WriteLine("4. 返回主菜单");
Console.Write("请选择: ");
var choice = Console.ReadLine();
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;
}
Console.WriteLine("\n按任意键继续...");
Console.ReadKey();
}
}
public static List<string> GetServerProfiles()
{
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;
}
}
}

View File

@@ -0,0 +1,90 @@
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using MCSJ.Tools.LogSystem;
namespace MCSJ.Tools.ServerManagement
{
public static class ServerStarter
{
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++)
{
Console.WriteLine($"{i + 1}. {servers[i]}");
}
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;
}
// 启动服务器
try
{
string fullBatPath = Path.GetFullPath(batPath);
string fullServerPath = Path.GetFullPath(serverPath);
if (!File.Exists(fullBatPath))
{
LogMain.Error($"启动脚本不存在: {fullBatPath}");
Console.WriteLine($"启动脚本不存在: {fullBatPath}");
return;
}
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = fullBatPath,
WorkingDirectory = fullServerPath,
UseShellExecute = true,
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}");
}
}
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Linq;
using MCSJ.Tools.LogSystem;
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");
LogMain.Info("没有安装任何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");
LogMain.Info("没有安装任何JRE");
return;
}
Console.WriteLine("已安装的JRE版本:");
LogMain.Info("已安装的JRE版本:");
foreach (var version in versions)
{
Console.WriteLine(version); // 直接输出版本号,不带前缀
}
}
catch (Exception ex)
{
Console.WriteLine($"读取JRE列表失败: {ex.Message}");
LogMain.Error($"读取JRE列表失败: {ex.Message}");
}
}
}
}

View File

@@ -5,5 +5,11 @@ ren win-x64 MCSJ-x64
ren win-x86 MCSJ-x86 ren win-x86 MCSJ-x86
rmdir /s /q MCSJ-x64\publish rmdir /s /q MCSJ-x64\publish
rmdir /s /q MCSJ-x86\publish rmdir /s /q MCSJ-x86\publish
7z a -t7z MCSJ-x64.7z MCSJ-x64
7z a -t7z MCSJ-x86.7z MCSJ-x86
7z a -tzip MCSJ-x64.zip MCSJ-x64 7z a -tzip MCSJ-x64.zip MCSJ-x64
7z a -tzip MCSJ-x86.zip MCSJ-x86 7z a -tzip MCSJ-x86.zip MCSJ-x86
7z a -ttar MCSJ-x64.tar MCSJ-x64
7z a -ttar MCSJ-x86.tar MCSJ-x86
rmdir /s /q MCSJ-x64
rmdir /s /q MCSJ-x86

View File

@@ -1,3 +1,5 @@
1.21.11-pre2:https://piston-data.mojang.com/v1/objects/7f997b55094aa7754f25173aafef657449f02bec/server.jar
1.21.11-pre1:https://piston-data.mojang.com/v1/objects/1087f90b4d73209318d87aa8deecfaae24861004/server.jar
25w46a:https://piston-data.mojang.com/v1/objects/e61a72ec98fae895ef3e80b05269ae343c42fc0b/server.jar 25w46a:https://piston-data.mojang.com/v1/objects/e61a72ec98fae895ef3e80b05269ae343c42fc0b/server.jar
25w45a:https://piston-data.mojang.com/v1/objects/4c0fe96ca002d7049226a740194c8d7114bd5059/server.jar 25w45a:https://piston-data.mojang.com/v1/objects/4c0fe96ca002d7049226a740194c8d7114bd5059/server.jar
25w44a:https://piston-data.mojang.com/v1/objects/1ade1ebd6affbfed6dbfb2ce8864cf19efed07ba/server.jar 25w44a:https://piston-data.mojang.com/v1/objects/1ade1ebd6affbfed6dbfb2ce8864cf19efed07ba/server.jar
@@ -780,3 +782,57 @@
1.3.1:https://launcher.mojang.com/v1/objects/82563ce498bfc1fc8a2cb5bf236f7da86a390646/server.jar 1.3.1:https://launcher.mojang.com/v1/objects/82563ce498bfc1fc8a2cb5bf236f7da86a390646/server.jar
1.3:https://launcher.mojang.com/v1/objects/cb21a9aaaf599c94dd7fa1b777b2f0cc37a776c7/server.jar 1.3:https://launcher.mojang.com/v1/objects/cb21a9aaaf599c94dd7fa1b777b2f0cc37a776c7/server.jar
1.2.5:https://launcher.mojang.com/v1/objects/d8321edc9470e56b8ad5c67bbd16beba25843336/server.jar 1.2.5:https://launcher.mojang.com/v1/objects/d8321edc9470e56b8ad5c67bbd16beba25843336/server.jar
paper-1.21.9-pre4:https://api.papermc.io/v2/projects/paper/versions/1.21.9-pre4/builds/22/downloads/paper-1.21.9-pre4-22.jar
paper-1.21.9-pre3:https://api.papermc.io/v2/projects/paper/versions/1.21.9-pre3/builds/12/downloads/paper-1.21.9-pre3-12.jar
paper-1.21.9-pre2:https://api.papermc.io/v2/projects/paper/versions/1.21.9-pre2/builds/7/downloads/paper-1.21.9-pre2-7.jar
paper-1.21.9:https://api.papermc.io/v2/projects/paper/versions/1.21.9/builds/59/downloads/paper-1.21.9-59.jar
paper-1.21.8:https://api.papermc.io/v2/projects/paper/versions/1.21.8/builds/60/downloads/paper-1.21.8-60.jar
paper-1.21.7:https://api.papermc.io/v2/projects/paper/versions/1.21.7/builds/32/downloads/paper-1.21.7-32.jar
paper-1.21.6:https://api.papermc.io/v2/projects/paper/versions/1.21.6/builds/48/downloads/paper-1.21.6-48.jar
paper-1.21.5:https://api.papermc.io/v2/projects/paper/versions/1.21.5/builds/114/downloads/paper-1.21.5-114.jar
paper-1.21.4:https://api.papermc.io/v2/projects/paper/versions/1.21.4/builds/232/downloads/paper-1.21.4-232.jar
paper-1.21.3:https://api.papermc.io/v2/projects/paper/versions/1.21.3/builds/83/downloads/paper-1.21.3-83.jar
paper-1.21.10:https://api.papermc.io/v2/projects/paper/versions/1.21.10/builds/115/downloads/paper-1.21.10-115.jar
paper-1.21.1:https://api.papermc.io/v2/projects/paper/versions/1.21.1/builds/133/downloads/paper-1.21.1-133.jar
paper-1.21:https://api.papermc.io/v2/projects/paper/versions/1.21/builds/130/downloads/paper-1.21-130.jar
paper-1.20.6:https://api.papermc.io/v2/projects/paper/versions/1.20.6/builds/151/downloads/paper-1.20.6-151.jar
paper-1.20.5:https://api.papermc.io/v2/projects/paper/versions/1.20.5/builds/22/downloads/paper-1.20.5-22.jar
paper-1.20.4:https://api.papermc.io/v2/projects/paper/versions/1.20.4/builds/499/downloads/paper-1.20.4-499.jar
paper-1.20.2:https://api.papermc.io/v2/projects/paper/versions/1.20.2/builds/318/downloads/paper-1.20.2-318.jar
paper-1.20.1:https://api.papermc.io/v2/projects/paper/versions/1.20.1/builds/196/downloads/paper-1.20.1-196.jar
paper-1.20:https://api.papermc.io/v2/projects/paper/versions/1.20/builds/17/downloads/paper-1.20-17.jar
paper-1.19.4:https://api.papermc.io/v2/projects/paper/versions/1.19.4/builds/550/downloads/paper-1.19.4-550.jar
paper-1.19.3:https://api.papermc.io/v2/projects/paper/versions/1.19.3/builds/448/downloads/paper-1.19.3-448.jar
paper-1.19.2:https://api.papermc.io/v2/projects/paper/versions/1.19.2/builds/307/downloads/paper-1.19.2-307.jar
paper-1.19.1:https://api.papermc.io/v2/projects/paper/versions/1.19.1/builds/111/downloads/paper-1.19.1-111.jar
paper-1.19:https://api.papermc.io/v2/projects/paper/versions/1.19/builds/81/downloads/paper-1.19-81.jar
paper-1.18.2:https://api.papermc.io/v2/projects/paper/versions/1.18.2/builds/388/downloads/paper-1.18.2-388.jar
paper-1.18.1:https://api.papermc.io/v2/projects/paper/versions/1.18.1/builds/216/downloads/paper-1.18.1-216.jar
paper-1.18:https://api.papermc.io/v2/projects/paper/versions/1.18/builds/66/downloads/paper-1.18-66.jar
paper-1.17.1:https://api.papermc.io/v2/projects/paper/versions/1.17.1/builds/411/downloads/paper-1.17.1-411.jar
paper-1.17:https://api.papermc.io/v2/projects/paper/versions/1.17/builds/79/downloads/paper-1.17-79.jar
paper-1.16.5:https://api.papermc.io/v2/projects/paper/versions/1.16.5/builds/794/downloads/paper-1.16.5-794.jar
paper-1.16.4:https://api.papermc.io/v2/projects/paper/versions/1.16.4/builds/416/downloads/paper-1.16.4-416.jar
paper-1.16.3:https://api.papermc.io/v2/projects/paper/versions/1.16.3/builds/253/downloads/paper-1.16.3-253.jar
paper-1.16.2:https://api.papermc.io/v2/projects/paper/versions/1.16.2/builds/189/downloads/paper-1.16.2-189.jar
paper-1.16.1:https://api.papermc.io/v2/projects/paper/versions/1.16.1/builds/138/downloads/paper-1.16.1-138.jar
paper-1.15.2:https://api.papermc.io/v2/projects/paper/versions/1.15.2/builds/393/downloads/paper-1.15.2-393.jar
paper-1.15.1:https://api.papermc.io/v2/projects/paper/versions/1.15.1/builds/62/downloads/paper-1.15.1-62.jar
paper-1.15:https://api.papermc.io/v2/projects/paper/versions/1.15/builds/21/downloads/paper-1.15-21.jar
paper-1.14.4:https://api.papermc.io/v2/projects/paper/versions/1.14.4/builds/245/downloads/paper-1.14.4-245.jar
paper-1.14.3:https://api.papermc.io/v2/projects/paper/versions/1.14.3/builds/134/downloads/paper-1.14.3-134.jar
paper-1.14.2:https://api.papermc.io/v2/projects/paper/versions/1.14.2/builds/107/downloads/paper-1.14.2-107.jar
paper-1.14.1:https://api.papermc.io/v2/projects/paper/versions/1.14.1/builds/50/downloads/paper-1.14.1-50.jar
paper-1.14:https://api.papermc.io/v2/projects/paper/versions/1.14/builds/17/downloads/paper-1.14-17.jar
paper-1.13.2:https://api.papermc.io/v2/projects/paper/versions/1.13.2/builds/657/downloads/paper-1.13.2-657.jar
paper-1.13.1:https://api.papermc.io/v2/projects/paper/versions/1.13.1/builds/386/downloads/paper-1.13.1-386.jar
paper-1.13-pre7:https://api.papermc.io/v2/projects/paper/versions/1.13-pre7/builds/12/downloads/paper-1.13-pre7-12.jar
paper-1.13:https://api.papermc.io/v2/projects/paper/versions/1.13/builds/173/downloads/paper-1.13-173.jar
paper-1.12.2:https://api.papermc.io/v2/projects/paper/versions/1.12.2/builds/1620/downloads/paper-1.12.2-1620.jar
paper-1.12.1:https://api.papermc.io/v2/projects/paper/versions/1.12.1/builds/1204/downloads/paper-1.12.1-1204.jar
paper-1.12:https://api.papermc.io/v2/projects/paper/versions/1.12/builds/1169/downloads/paper-1.12-1169.jar
paper-1.11.2:https://api.papermc.io/v2/projects/paper/versions/1.11.2/builds/1106/downloads/paper-1.11.2-1106.jar
paper-1.10.2:https://api.papermc.io/v2/projects/paper/versions/1.10.2/builds/918/downloads/paper-1.10.2-918.jar
paper-1.9.4:https://api.papermc.io/v2/projects/paper/versions/1.9.4/builds/775/downloads/paper-1.9.4-775.jar
paper-1.8.8:https://api.papermc.io/v2/projects/paper/versions/1.8.8/builds/445/downloads/paper-1.8.8-445.jar
paper-1.7.10:https://api.papermc.io/v2/projects/paper/versions/1.7.10/builds/2025/downloads/paper-1.7.10-2025.jar