Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🔥 Remove installer version detection when deploy. #369

Merged
merged 13 commits into from
May 20, 2024
Merged
13 changes: 3 additions & 10 deletions dependency/deploy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
56 changes: 48 additions & 8 deletions installer/ViewModel/DebugViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -338,20 +349,31 @@ 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)
{
Log.LogError($"未能启动API.exe, team:{team}, player: {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;
}
Expand All @@ -374,23 +396,32 @@ 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)
{
Log.LogError($"未能启动main.py, team:{team}, player: {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;
}
Expand All @@ -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
}
}
Loading