From 2348e5962c2dd022d7008c1d9a81a099b89f1d0e Mon Sep 17 00:00:00 2001 From: DreamEnderKing Date: Sat, 11 May 2024 23:47:54 +0800 Subject: [PATCH 1/3] fix: :fire: Remove installer version detection when deploy. --- dependency/deploy/Program.cs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/dependency/deploy/Program.cs b/dependency/deploy/Program.cs index 56392ca0..9785c674 100644 --- a/dependency/deploy/Program.cs +++ b/dependency/deploy/Program.cs @@ -77,15 +77,8 @@ break; case "upload": d.UpdateMD5(); - if (d.Data.FileHashData.TVersion.InstallerVersion < d.CurrentVersion.InstallerVersion) - { - Cloud.DownloadFile(@"D:\a\publish\Secret.csv", "Secret.csv"); - ZipFile.CreateFromDirectory(@"D:\a\publish", @$"D:\a\Installer_v{d.CurrentVersion.InstallerVersion}.zip", CompressionLevel.SmallestSize, false); - Cloud.UploadFile(@$"D:\a\Installer_v{d.CurrentVersion.InstallerVersion}.zip", $"Setup/Installer_v{d.CurrentVersion.InstallerVersion}.zip"); - } - else - { - Log.LogInfo("No installer version update found."); - } + Cloud.DownloadFile(@"D:\a\publish\Secret.csv", "Secret.csv"); + ZipFile.CreateFromDirectory(@"D:\a\publish", @$"D:\a\Installer_v{d.CurrentVersion.InstallerVersion}.zip", CompressionLevel.SmallestSize, false); + Cloud.UploadFile(@$"D:\a\Installer_v{d.CurrentVersion.InstallerVersion}.zip", $"Setup/Installer_v{d.CurrentVersion.InstallerVersion}.zip"); break; } \ No newline at end of file From 57f24636355b13ad95885a7e462873e201b17952 Mon Sep 17 00:00:00 2001 From: DreamEnderKing Date: Sat, 18 May 2024 20:31:17 +0800 Subject: [PATCH 2/3] chore: :clown_face: Update logger position. --- installer/ViewModel/DebugViewModel.cs | 56 +++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 8 deletions(-) diff --git a/installer/ViewModel/DebugViewModel.cs b/installer/ViewModel/DebugViewModel.cs index fe04591b..b0a2defa 100644 --- a/installer/ViewModel/DebugViewModel.cs +++ b/installer/ViewModel/DebugViewModel.cs @@ -280,7 +280,8 @@ public bool LaunchServer() { FileName = Downloader.Data.Config.DevServerPath ?? Path.Combine(Downloader.Data.Config.InstallPath, "logic", "Server", "Server.exe"), Arguments = $"--ip 0.0.0.0 --port {Port} --teamCount {TeamCount} --shipNum {ShipCount}", - WorkingDirectory = Downloader.Data.Config.InstallPath + WorkingDirectory = Downloader.Data.Config.InstallPath, + RedirectStandardError = true, }); if (server is null) { @@ -293,6 +294,7 @@ public bool LaunchServer() OnServerExited?.Invoke(this, EventArgs.Empty); Log.LogWarning("Server已退出。"); }; + server.ErrorDataReceived += ProgramErrorReceived; Log.LogWarning("Server成功启动,请保持网络稳定。"); OnServerLaunched?.Invoke(this, EventArgs.Empty); return true; @@ -314,7 +316,8 @@ public bool LaunchClient(int team, int player, int ship) var client = Process.Start(new ProcessStartInfo() { FileName = Downloader.Data.Config.DevClientPath ?? Path.Combine(Downloader.Data.Config.InstallPath, "logic", "Client", "Client.exe"), - WorkingDirectory = Downloader.Data.Config.InstallPath + WorkingDirectory = Downloader.Data.Config.InstallPath, + RedirectStandardError = true, }); if (client is null) { @@ -329,6 +332,14 @@ public bool LaunchClient(int team, int player, int ship) File.Delete(Path.Combine(Downloader.Data.LogPath, $"lock.{team}.{player}.log")); Downloader.Data.Config.Commands.PlaybackFile = p; Log.LogInfo($"Client({team}: {player})成功启动。"); + client.EnableRaisingEvents = true; + client.ErrorDataReceived += ProgramErrorReceived; + client.BeginErrorReadLine(); + client.Exited += (_, _) => + { + Log.LogWarning($"client({team}:{player})已退出({client.ExitCode})。"); + }; + client.ErrorDataReceived += ProgramErrorReceived; children.Add(client); return true; } @@ -338,13 +349,17 @@ public bool LaunchClient(int team, int player, int ship) public bool LaunchCppAPI(int team, int player) { var exe = Downloader.Data.Config.DevCppPath ?? Path.Combine(Downloader.Data.Config.InstallPath, "CAPI", "cpp", "x64", "Debug", "API.exe"); + var logDir = Path.Combine(Downloader.Data.LogPath, $"Team{team}"); + if (!Directory.Exists(logDir)) + Directory.CreateDirectory(logDir); if (File.Exists(exe)) { var cpp = Process.Start(new ProcessStartInfo() { FileName = Downloader.Data.Config.DevCppPath ?? exe, Arguments = $"-I {IP} -P {Port} -t {team} -p {player} -o -d", - WorkingDirectory = Downloader.Data.Config.InstallPath + WorkingDirectory = logDir, + RedirectStandardError = true, }); if (cpp is null) { @@ -352,6 +367,13 @@ public bool LaunchCppAPI(int team, int player) return false; } Log.LogInfo($"API.exe启动成功, team:{team}, player: {player}!"); + cpp.EnableRaisingEvents = true; + cpp.ErrorDataReceived += ProgramErrorReceived; + cpp.BeginErrorReadLine(); + cpp.Exited += (_, _) => + { + Log.LogWarning($"API.exe({team}:{player})已退出({cpp.ExitCode})。"); + }; children.Add(cpp); return true; } @@ -374,16 +396,18 @@ public bool LaunchCppAPI(int team, int player) public bool LaunchPyAPI(int team, int player) { var p = Path.Combine(Downloader.Data.Config.InstallPath, "CAPI", "python"); + var logDir = Path.Combine(Downloader.Data.LogPath, $"Team{team}"); + if (!Directory.Exists(logDir)) + Directory.CreateDirectory(logDir); if (Directory.Exists(Path.Combine(p, "proto"))) { - var py = Process.Start(new ProcessStartInfo() { - FileName = "cmd.exe", - Arguments = "/c python " - + (Downloader.Data.Config.DevPyPath ?? Path.Combine(Downloader.Data.Config.InstallPath, "CAPI", "python", "PyAPI", "main.py")) + FileName = "python.exe", + Arguments = (Downloader.Data.Config.DevPyPath ?? Path.Combine(Downloader.Data.Config.InstallPath, "CAPI", "python", "PyAPI", "main.py")) + $" -I {IP} -P {Port} -t {team} -p {player} -o -d", - WorkingDirectory = Downloader.Data.Config.InstallPath + WorkingDirectory = logDir, + RedirectStandardError = true, }); if (py is null) { @@ -391,6 +415,13 @@ public bool LaunchPyAPI(int team, int player) return false; } Log.LogInfo($"main.py启动成功, team:{team}, player: {player}!"); + py.EnableRaisingEvents = true; + py.ErrorDataReceived += ProgramErrorReceived; + py.BeginErrorReadLine(); + py.Exited += (_, _) => + { + Log.LogWarning($"main.py({team}:{player})已退出({py.ExitCode})。"); + }; children.Add(py); return true; } @@ -409,6 +440,15 @@ public bool LaunchPyAPI(int team, int player) return false; } } + + protected virtual void ProgramErrorReceived(object sender, DataReceivedEventArgs e) + { + var program = sender as Process; + Log.LogError(string.Format("error occurs in {0}:\n {1}", + program is null ? "(anonymous)" : + (program.StartInfo.FileName + ' ' + program.StartInfo.Arguments), + e.Data ?? "Unhandled error.")); + } #endregion } } \ No newline at end of file From e9eae8f3fa0c29e1a5125cabfb7b4855a7ed743e Mon Sep 17 00:00:00 2001 From: DreamEnderKing Date: Sat, 18 May 2024 20:40:21 +0800 Subject: [PATCH 3/3] feat: :lipstick: Fix the format. --- installer/ViewModel/DebugViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/installer/ViewModel/DebugViewModel.cs b/installer/ViewModel/DebugViewModel.cs index b0a2defa..c789a3d5 100644 --- a/installer/ViewModel/DebugViewModel.cs +++ b/installer/ViewModel/DebugViewModel.cs @@ -444,8 +444,8 @@ public bool LaunchPyAPI(int team, int player) protected virtual void ProgramErrorReceived(object sender, DataReceivedEventArgs e) { var program = sender as Process; - Log.LogError(string.Format("error occurs in {0}:\n {1}", - program is null ? "(anonymous)" : + Log.LogError(string.Format("error occurs in {0}:\n {1}", + program is null ? "(anonymous)" : (program.StartInfo.FileName + ' ' + program.StartInfo.Arguments), e.Data ?? "Unhandled error.")); }