From 59b7c843104b1bcb259a6599f567b34e45bf38ad Mon Sep 17 00:00:00 2001 From: zs-yg <3972006562@qq.com> Date: Sat, 22 Nov 2025 20:03:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=E5=92=8C?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=87=E6=9C=AC=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Program.cs | 8 ++++---- Tools/DownloadService.cs | 8 ++++++++ Tools/VersionManager.cs | 13 +++++++++++-- Tools/jredownload/JreDownloadProgress.cs | 2 ++ Tools/jredownload/JreDownloadService.cs | 15 ++++++++++++++- Tools/viewjre/JreViewer.cs | 9 +++++++-- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/Program.cs b/Program.cs index dbad13f..d2f3e1c 100644 --- a/Program.cs +++ b/Program.cs @@ -16,7 +16,7 @@ namespace MCSJ Console.WriteLine($"日志目录: {logDir}"); LogMain.Debug($"日志文件: {LogCreator.GetLogFilePath()}"); - LogMain.Info("MC服务器下载工具启动"); + LogMain.Info("MC服务器启动工具启动"); var httpClient = new HttpClient { Timeout = TimeSpan.FromMinutes(5), DefaultRequestHeaders = { { "User-Agent", "MCSJ-JRE-Downloader" } } @@ -28,9 +28,9 @@ namespace MCSJ while (true) { - Console.WriteLine("MC服务器下载工具"); - Console.WriteLine("1. 显示所有版本"); - Console.WriteLine("2. 下载指定版本"); + Console.WriteLine("MC服务器启动工具"); + Console.WriteLine("1. 显示所有服务器版本"); + Console.WriteLine("2. 下载指定服务器版本"); Console.WriteLine("3. 下载JRE"); Console.WriteLine("4. 查看已安装的JRE"); Console.WriteLine("5. 退出"); diff --git a/Tools/DownloadService.cs b/Tools/DownloadService.cs index 10210e2..6982415 100644 --- a/Tools/DownloadService.cs +++ b/Tools/DownloadService.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Net.Http; using System.Threading.Tasks; +using MCSJ.Tools.LogSystem; namespace MCSJ.Tools { @@ -21,6 +22,7 @@ namespace MCSJ.Tools if (string.IsNullOrWhiteSpace(version)) { Console.WriteLine("版本名称不能为空"); + LogMain.Error("版本名称不能为空"); return; } @@ -28,6 +30,7 @@ namespace MCSJ.Tools if (string.IsNullOrEmpty(url)) { Console.WriteLine($"版本 {version} 不存在"); + LogMain.Error($"版本 {version} 不存在"); return; } @@ -47,10 +50,12 @@ namespace MCSJ.Tools if (!Directory.Exists(profilePath)) break; Console.WriteLine($"文件夹 '{targetFolder}' 已存在,请重新输入(直接回车则取消下载):"); + LogMain.Warn($"文件夹 '{targetFolder}' 已存在,请重新输入(直接回车则取消下载):"); } if (Directory.Exists(profilePath)) { Console.WriteLine("下载已取消。"); + LogMain.Info("下载已取消。"); return; } Directory.CreateDirectory(profilePath); @@ -59,6 +64,7 @@ namespace MCSJ.Tools try { Console.WriteLine($"开始下载 {version} 到 {profilePath} ..."); + LogMain.Info($"开始下载 {version} 到 {profilePath} ..."); var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); response.EnsureSuccessStatusCode(); @@ -90,10 +96,12 @@ namespace MCSJ.Tools } } Console.WriteLine($"\n{version} 下载完成! 文件已保存到 {jarPath}"); + LogMain.Info($"{version} 下载完成! 文件已保存到 {jarPath}"); } catch (Exception ex) { Console.WriteLine($"下载失败: {ex.Message}"); + LogMain.Error($"下载失败: {ex.Message}"); } } } diff --git a/Tools/VersionManager.cs b/Tools/VersionManager.cs index 0f8514b..e8aa313 100644 --- a/Tools/VersionManager.cs +++ b/Tools/VersionManager.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using MCSJ.Tools.LogSystem; namespace MCSJ.Tools { @@ -19,6 +20,7 @@ namespace MCSJ.Tools { var filePath = Path.Combine("resources", "serverlist.txt"); Console.WriteLine($"尝试从路径加载版本列表: {Path.GetFullPath(filePath)}"); + LogMain.Info($"尝试从路径加载版本列表: {Path.GetFullPath(filePath)}"); if (!File.Exists(filePath)) { @@ -42,7 +44,8 @@ namespace MCSJ.Tools if (string.IsNullOrEmpty(version) || string.IsNullOrEmpty(url)) { - Console.WriteLine($"忽略无效条目: {rawLine} (版本或URL为空)"); + Console.WriteLine($"忽略无效条目: {rawLine} (版本或URL为空)"); + LogMain.Warn($"忽略无效条目: {rawLine} (版本或URL为空)"); continue; } @@ -51,6 +54,7 @@ namespace MCSJ.Tools else { Console.WriteLine($"忽略无效条目: {rawLine} (缺少冒号分隔或格式不正确)"); + LogMain.Warn($"忽略无效条目: {rawLine} (缺少冒号分隔或格式不正确)"); } } @@ -60,12 +64,15 @@ namespace MCSJ.Tools } Console.WriteLine($"成功加载 {_versions.Count} 个版本"); + LogMain.Info($"成功加载 {_versions.Count} 个版本"); } catch (Exception ex) { Console.WriteLine($"加载版本列表失败: {ex.Message}"); Console.WriteLine($"当前工作目录: {Directory.GetCurrentDirectory()}"); Console.WriteLine("请确保serverlist.txt每行格式为: 版本名:下载URL (版本名可以包含空格),支持以#开头的注释"); + LogMain.Error($"加载版本列表失败: {ex.Message}"); + LogMain.Error($"当前工作目录: {Directory.GetCurrentDirectory()}"); } } @@ -75,10 +82,12 @@ namespace MCSJ.Tools if (!File.Exists(filePath)) { Console.WriteLine("版本列表文件不存在"); + LogMain.Error("版本列表文件不存在"); return; } - Console.WriteLine("可用版本列表:"); + Console.WriteLine("可用版本列表:"); + LogMain.Info("可用版本列表:"); foreach (var version in _versions.Keys) { Console.WriteLine(version); diff --git a/Tools/jredownload/JreDownloadProgress.cs b/Tools/jredownload/JreDownloadProgress.cs index 9a31785..93f44e1 100644 --- a/Tools/jredownload/JreDownloadProgress.cs +++ b/Tools/jredownload/JreDownloadProgress.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using MCSJ.Tools.LogSystem; namespace MCSJ.Tools.JreDownload { @@ -33,6 +34,7 @@ namespace MCSJ.Tools.JreDownload if (percentage == 100) { Console.WriteLine(); + LogMain.Info("JRE下载完成"); } } finally diff --git a/Tools/jredownload/JreDownloadService.cs b/Tools/jredownload/JreDownloadService.cs index 92a5a40..8f11f97 100644 --- a/Tools/jredownload/JreDownloadService.cs +++ b/Tools/jredownload/JreDownloadService.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net.Http; using System.Threading.Tasks; using System.IO.Compression; +using MCSJ.Tools.LogSystem; namespace MCSJ.Tools.JreDownload { @@ -25,6 +26,7 @@ namespace MCSJ.Tools.JreDownload if (CheckJreExists(version)) { Console.WriteLine($"JRE {version} 已存在,无需重复下载"); + LogMain.Info($"JRE {version} 已存在,无需重复下载"); return; } @@ -33,6 +35,7 @@ namespace MCSJ.Tools.JreDownload if (string.IsNullOrEmpty(downloadUrl)) { Console.WriteLine($"找不到版本 {version} 的下载链接"); + LogMain.Error($"找不到版本 {version} 的下载链接"); return; } @@ -42,6 +45,7 @@ namespace MCSJ.Tools.JreDownload if (string.IsNullOrEmpty(tempZipPath)) { Console.WriteLine("下载失败"); + LogMain.Error("下载失败"); return; } @@ -50,6 +54,7 @@ namespace MCSJ.Tools.JreDownload if (!ExtractJre(tempZipPath, jreFolder)) { Console.WriteLine("解压失败"); + LogMain.Error("解压失败"); return; } @@ -60,6 +65,7 @@ namespace MCSJ.Tools.JreDownload if (javaExePath == null || javawExePath == null) { Console.WriteLine("找不到java.exe或javaw.exe"); + LogMain.Error("找不到java.exe或javaw.exe"); return; } @@ -69,7 +75,8 @@ namespace MCSJ.Tools.JreDownload // 6. 清理临时文件 File.Delete(tempZipPath); - Console.WriteLine($"JRE {version} 安装完成"); + Console.WriteLine($"JRE {version} 安装完成"); + LogMain.Info($"JRE {version} 安装完成"); } private string? GetDownloadUrl(string version) @@ -99,18 +106,22 @@ namespace MCSJ.Tools.JreDownload if (!Uri.IsWellFormedUriString(url, UriKind.Absolute)) { Console.WriteLine($"无效的下载URL: {url}"); + LogMain.Error($"无效的下载URL: {url}"); return null; } Console.WriteLine($"正在准备下载 {url}..."); + LogMain.Info($"正在准备下载 {url}..."); var response = await _httpClient.GetAsync(url, HttpCompletionOption.ResponseHeadersRead); response.EnsureSuccessStatusCode(); var totalBytes = response.Content.Headers.ContentLength ?? 0; Console.WriteLine($"文件总大小: {totalBytes} 字节"); + LogMain.Info($"文件总大小: {totalBytes} 字节"); long bytesRead = 0; var lastReportTime = DateTime.MinValue; Console.WriteLine("开始下载..."); + LogMain.Info("开始下载..."); using (var stream = await response.Content.ReadAsStreamAsync()) using (var fileStream = new FileStream(tempPath, FileMode.Create)) @@ -139,6 +150,7 @@ namespace MCSJ.Tools.JreDownload catch (Exception ex) { Console.WriteLine($"下载失败: {ex.Message}"); + LogMain.Error($"下载失败: {ex.Message}"); return null; } } @@ -157,6 +169,7 @@ namespace MCSJ.Tools.JreDownload catch (Exception ex) { Console.WriteLine($"解压失败: {ex.Message}"); + LogMain.Error($"解压失败: {ex.Message}"); return false; } } diff --git a/Tools/viewjre/JreViewer.cs b/Tools/viewjre/JreViewer.cs index 13bcb64..ed31135 100644 --- a/Tools/viewjre/JreViewer.cs +++ b/Tools/viewjre/JreViewer.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using MCSJ.Tools.LogSystem; namespace MCSJ.Tools.ViewJre { @@ -16,6 +17,7 @@ namespace MCSJ.Tools.ViewJre if (!File.Exists(tomlPath)) { Console.WriteLine("没有安装任何JRE"); + LogMain.Info("没有安装任何JRE"); return; } @@ -29,11 +31,13 @@ namespace MCSJ.Tools.ViewJre if (versions.Count == 0) { - Console.WriteLine("没有安装任何JRE"); - return; + Console.WriteLine("没有安装任何JRE"); + LogMain.Info("没有安装任何JRE"); + return; } Console.WriteLine("已安装的JRE版本:"); + LogMain.Info("已安装的JRE版本:"); foreach (var version in versions) { Console.WriteLine(version); // 直接输出版本号,不带前缀 @@ -42,6 +46,7 @@ namespace MCSJ.Tools.ViewJre catch (Exception ex) { Console.WriteLine($"读取JRE列表失败: {ex.Message}"); + LogMain.Error($"读取JRE列表失败: {ex.Message}"); } } }