Skip to content

Commit

Permalink
Merge pull request #368 from eesast/dev
Browse files Browse the repository at this point in the history
Merge to main branch
  • Loading branch information
DreamEnderKing authored May 11, 2024
2 parents 581b906 + bb4243a commit c124f8a
Show file tree
Hide file tree
Showing 14 changed files with 504 additions and 68 deletions.
21 changes: 4 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
name: deploy
on:
push:
branches: [dev, main, master]
pull_request:
branches: [dev, main, master]
branches: [main, master]

env:
version: 1.1.0.0

jobs:
deploy-to-tencent-cos:
Expand All @@ -29,8 +25,6 @@ jobs:
mkdir D:\a\publish
- name: Copy THUAI7
run: Copy-Item -recurse D:\a\THUAI7\THUAI7\ D:\a\mirror\
- name: Test
run: tree D:\a\mirror
- name: Remove directories not needed
run: |
Remove-Item -recurse -force D:\a\mirror\.git
Expand All @@ -45,15 +39,8 @@ jobs:
- name: Build Client
run: dotnet publish "./logic/Client/Client.csproj" -o "D:\a\mirror\logic\Client" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
- name: Deploy to bucket
run: dotnet run --project "./dependency/deploy/deploy.csproj" ${{ secrets.INSTALLER_COS_SECRET_ID }} ${{ secrets.INSTALLER_COS_SECRET_KEY }}
run: dotnet run --project "./dependency/deploy/deploy.csproj" ${{ secrets.INSTALLER_COS_SECRET_ID }} ${{ secrets.INSTALLER_COS_SECRET_KEY }} "check"
- name: Get installer package(No Key contained for safety)
run: |
$version=Get-ChildItem -Path D:\a\publish | ForEach-Object { $_.name }
[Environment]::SetEnvironmentVariable("version", $version, "Machine")
dotnet publish "./installer/installer.csproj" -o "D:\a\installer" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
./dependency/7z/7za.exe a -r D:\a\publish\Installer_v${version}.zip D:\a\installer\*
- name: Upload installer package
uses: actions/upload-artifact@v4
with:
name: Installer_v${{ env.version }}.zip
path: D:\a\publish\Installer_v${{ env.version }}.zip
dotnet publish "./installer/installer.csproj" -o "D:\a\publish" -f net8.0-windows10.0.19041.0 -c Release -p:RuntimeIdentifierOverride=win10-x64 -p:WindowsPackageType=None -p:WindowsAppSDKSelfContained=true
dotnet run --project "./dependency/deploy/deploy.csproj" ${{ secrets.INSTALLER_COS_SECRET_ID }} ${{ secrets.INSTALLER_COS_SECRET_KEY }} "upload"
105 changes: 62 additions & 43 deletions dependency/deploy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using installer.Services;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO.Compression;

Logger Log = LoggerProvider.FromConsole();

Expand All @@ -17,56 +18,74 @@
d.Log.Partner.Add(Log);
// 每次更新需要更新默认值
d.CurrentVersion = new TVersion();
File.Create(Path.Combine("D:\\a\\publish", d.CurrentVersion.InstallerVersion.ToString()));

if (d.CheckUpdate())
switch (args[2])
{
foreach (var r in d.Data.MD5Update)
{
Log.LogInfo($"{r.state}, {r.name}");
}
case "check":

d.Data.SaveMD5Data();
List<Task> l = new List<Task>();
foreach (var r in d.Data.MD5Update)
{
var n = r.name.Replace('\\', '/');
n = n.TrimStart('.').TrimStart('/');
if (r.state == System.Data.DataRowState.Added || r.state == System.Data.DataRowState.Modified)
if (d.CheckUpdate())
{
l.Add(Cloud.UploadFileAsync(Path.Combine(d.Data.Config.InstallPath, r.name), n));
foreach (var r in d.Data.MD5Update)
{
Log.LogInfo($"{r.state}, {r.name}");
}

d.Data.SaveMD5Data();
List<Task> l = new List<Task>();
foreach (var r in d.Data.MD5Update)
{
var n = r.name.Replace('\\', '/');
n = n.TrimStart('.').TrimStart('/');
if (r.state == System.Data.DataRowState.Added || r.state == System.Data.DataRowState.Modified)
{
l.Add(Cloud.UploadFileAsync(Path.Combine(d.Data.Config.InstallPath, r.name), n));
}
else if (r.state == System.Data.DataRowState.Deleted)
{
l.Add(Cloud.DeleteFileAsync(n));
}
}
Task.WaitAll(l.ToArray());
}
else if (r.state == System.Data.DataRowState.Deleted)
else
{
l.Add(Cloud.DeleteFileAsync(n));
Log.LogInfo("Nothing to update");
}
}
Task.WaitAll(l.ToArray());
}
else
{
Log.LogInfo("Nothing to update");
}

d.Data.SaveMD5Data();
Cloud.UploadFile(d.Data.MD5DataPath, "hash.json");
d.Data.SaveMD5Data();
Cloud.UploadFile(d.Data.MD5DataPath, "hash.json");

Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "CAPI", "cpp", "API", "src", "AI.cpp"),
$"Templates/t.{d.CurrentVersion.TemplateVersion}.cpp");
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "CAPI", "python", "PyAPI", "AI.py"),
$"Templates/t.{d.CurrentVersion.TemplateVersion}.py");
Log.LogInfo("User code uploaded.");
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "CAPI", "cpp", "API", "src", "AI.cpp"),
$"Templates/t.{d.CurrentVersion.TemplateVersion}.cpp");
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "CAPI", "python", "PyAPI", "AI.py"),
$"Templates/t.{d.CurrentVersion.TemplateVersion}.py");
Log.LogInfo("User code uploaded.");

var list = (from i in d.Data.MD5Data
select i.Key.Replace(Path.DirectorySeparatorChar, '/').TrimStart('.').TrimStart('/')).ToArray();
Log.LogInfo(list[0]);
using (FileStream s = new FileStream(Path.Combine(d.Data.Config.InstallPath, "compress.csv"), FileMode.Create, FileAccess.Write))
using (StreamWriter w = new StreamWriter(s))
{
foreach (var item in list)
{
w.WriteLine("https://thuai7-1319625962.cos.ap-beijing.myqcloud.com/" + item);
}
}
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "compress.csv"), "compress.csv");
Log.LogInfo("Compress csv generated.");
var list = (from i in d.Data.MD5Data
select i.Key.Replace(Path.DirectorySeparatorChar, '/').TrimStart('.').TrimStart('/')).ToArray();
Log.LogInfo(list[0]);
using (FileStream s = new FileStream(Path.Combine(d.Data.Config.InstallPath, "compress.csv"), FileMode.Create, FileAccess.Write))
using (StreamWriter w = new StreamWriter(s))
{
foreach (var item in list)
{
w.WriteLine("https://thuai7-1319625962.cos.ap-beijing.myqcloud.com/" + item);
}
}
Cloud.UploadFile(Path.Combine(d.Data.Config.InstallPath, "compress.csv"), "compress.csv");
Log.LogInfo("Compress csv generated.");
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.");
}
break;
}
2 changes: 1 addition & 1 deletion installer/Data/MD5FileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TVersion
public Version TemplateVersion = new Version(1, 0, 0, 3);
// 本体版本
[JsonInclude]
public Version InstallerVersion = new Version(1, 1, 0, 0);
public Version InstallerVersion = new Version(1, 1, 0, 2);
public static bool operator <(TVersion l, TVersion r)
{
return l.LibVersion < r.LibVersion || l.TemplateVersion < r.TemplateVersion || l.InstallerVersion < r.InstallerVersion;
Expand Down
10 changes: 7 additions & 3 deletions installer/ViewModel/DebugViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,14 @@ private void ServerExited(object? sender, EventArgs e)
protected Process? server;
public event EventHandler? OnServerLaunched;
public event EventHandler? OnServerExited;

public bool LaunchServer()
{
server = Process.Start(new ProcessStartInfo()
{
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
});
if (server is null)
{
Expand All @@ -296,7 +298,6 @@ public bool LaunchServer()
return true;
}


public bool LaunchClient(int team, int player, int ship)
{
Downloader.Data.Config.Commands.TeamID = team;
Expand All @@ -313,6 +314,7 @@ 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
});
if (client is null)
{
Expand Down Expand Up @@ -341,7 +343,8 @@ public bool LaunchCppAPI(int team, int player)
var cpp = Process.Start(new ProcessStartInfo()
{
FileName = Downloader.Data.Config.DevCppPath ?? exe,
Arguments = $"-I {IP} -P {Port} -t {team} -p {player} -o"
Arguments = $"-I {IP} -P {Port} -t {team} -p {player} -o -d",
WorkingDirectory = Downloader.Data.Config.InstallPath
});
if (cpp is null)
{
Expand Down Expand Up @@ -379,7 +382,8 @@ public bool LaunchPyAPI(int team, int player)
FileName = "cmd.exe",
Arguments = "/c python "
+ (Downloader.Data.Config.DevPyPath ?? Path.Combine(Downloader.Data.Config.InstallPath, "CAPI", "python", "PyAPI", "main.py"))
+ $" -I {IP} -P {Port} -t {team} -p {player} -o"
+ $" -I {IP} -P {Port} -t {team} -p {player} -o -d",
WorkingDirectory = Downloader.Data.Config.InstallPath
});
if (py is null)
{
Expand Down
8 changes: 8 additions & 0 deletions interface/interface_playback/Assets/Plugins.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions interface/interface_playback/Assets/Scripts/Playback.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

134 changes: 134 additions & 0 deletions interface/interface_playback/Assets/Scripts/Playback/MessageReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@

using Google.Protobuf;
using Protobuf;
using System;
using System.IO;
using System.IO.Compression;

namespace Playback
{
public class FileFormatNotLegalException : Exception
{
public FileFormatNotLegalException()
{

}
public override string Message => $"The file is not a legal playback file for THUAI6.";
}

public class MessageReader : IDisposable
{
private MemoryStream stream;
private CodedInputStream cos;
private GZipStream gzs;
private byte[] buffer;
public bool Finished { get; private set; } = false;

public readonly uint teamCount;
public readonly uint playerCount;

const int bufferMaxSize = 10 * 1024 * 1024; // 10M

public MessageReader(byte[] bytes)
{
stream = new MemoryStream(bytes);
var prefixLen = PlayBackConstant.Prefix.Length;
byte[] bt = new byte[prefixLen + sizeof(UInt32) * 2];
stream.Read(bt, 0, bt.Length);
for (int i = 0; i < prefixLen; ++i)
{
if (bt[i] != PlayBackConstant.Prefix[i]) throw new FileFormatNotLegalException();
}

teamCount = BitConverter.ToUInt32(bt, prefixLen);
playerCount = BitConverter.ToUInt32(bt, prefixLen + sizeof(UInt32));

gzs = new GZipStream(stream, CompressionMode.Decompress);
var tmpBuffer = new byte[bufferMaxSize];
var bufferSize = gzs.Read(tmpBuffer);
if (bufferSize == 0)
{
buffer = tmpBuffer;
Finished = true;
}
else if (bufferSize != bufferMaxSize) // 不留空位,防止 CodedInputStream 获取信息错误
{
if (bufferSize == 0)
{
Finished = true;
}
buffer = new byte[bufferSize];
Array.Copy(tmpBuffer, buffer, bufferSize);
}
else
{
buffer = tmpBuffer;
}
cos = new CodedInputStream(buffer);
}

public MessageToClient? ReadOne()
{
beginRead:
if (Finished)
return null;
var pos = cos.Position;
try
{
MessageToClient? msg = new MessageToClient();
cos.ReadMessage(msg);
return msg;
}
catch (InvalidProtocolBufferException)
{
var leftByte = buffer.Length - pos; // 上次读取剩余的字节
if (buffer.Length < bufferMaxSize / 2)
{
var newBuffer = new byte[bufferMaxSize];
for (int i = 0; i < leftByte; i++)
{
newBuffer[i] = buffer[pos + i];
}
buffer = newBuffer;
}
else
{
for (int i = 0; i < leftByte; ++i)
{
buffer[i] = buffer[pos + i];
}
}
var bufferSize = gzs.Read(buffer, (int)leftByte, (int)(buffer.Length - leftByte)) + leftByte;
if (bufferSize == leftByte)
{
Finished = true;
return null;
}
if (bufferSize != buffer.Length) // 不留空位,防止 CodedInputStream 获取信息错误
{
var tmpBuffer = new byte[bufferSize];
Array.Copy(buffer, tmpBuffer, bufferSize);
buffer = tmpBuffer;
}
cos = new CodedInputStream(buffer);
goto beginRead;
}
}

public void Dispose()
{
Finished = true;
if (stream == null)
return;
if (stream.CanRead)
{
stream.Close();
}
}

~MessageReader()
{
Dispose();
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c124f8a

Please sign in to comment.