From 6a488f41646af34b2c4ac822010c6c745b3d1dfd Mon Sep 17 00:00:00 2001 From: DreamEnderKing Date: Fri, 10 May 2024 19:35:52 +0800 Subject: [PATCH 01/42] feat: :zap: Move proto cpp library update out of main process. --- installer/Data/MD5FileData.cs | 4 +-- installer/Model/Downloader.cs | 53 +++++++++++++++++++++++++++++----- installer/Model/Local_Data.cs | 4 +-- installer/Model/Tencent_Cos.cs | 53 ++++++++++++++++++++++++++++------ installer/installer.csproj | 9 ++++++ 5 files changed, 103 insertions(+), 20 deletions(-) diff --git a/installer/Data/MD5FileData.cs b/installer/Data/MD5FileData.cs index ef3ba870..65a63cda 100644 --- a/installer/Data/MD5FileData.cs +++ b/installer/Data/MD5FileData.cs @@ -26,13 +26,13 @@ public class TVersion { // 代码库版本 [JsonInclude] - public Version LibVersion = new Version(1, 0, 2, 2); + public Version LibVersion = new Version(1, 0, 2, 3); // 选手代码模板版本 [JsonInclude] public Version TemplateVersion = new Version(1, 0, 0, 3); // 本体版本 [JsonInclude] - public Version InstallerVersion = new Version(1, 0, 2, 0); + public Version InstallerVersion = new Version(1, 1, 0, 0); public static bool operator <(TVersion l, TVersion r) { return l.LibVersion < r.LibVersion || l.TemplateVersion < r.TemplateVersion || l.InstallerVersion < r.InstallerVersion; diff --git a/installer/Model/Downloader.cs b/installer/Model/Downloader.cs index 6b1981a6..e444d33e 100755 --- a/installer/Model/Downloader.cs +++ b/installer/Model/Downloader.cs @@ -190,28 +190,42 @@ public void Install(string? path = null) if (Log is FileLogger) ((FileLogger)Log).Path = Path.Combine(Data.Config.InstallPath, "Logs", "Installer.log"); Data.ResetInstallPath(Data.Config.InstallPath); - string zp = Path.Combine(Data.Config.InstallPath, "THUAI7.tar.gz"); Status = UpdateStatus.downloading; (CloudReport.ComCount, CloudReport.Count) = (0, 1); - Cloud.Log.LogInfo($"正在下载安装包……"); + Cloud.Log.LogInfo($"正在下载installer安装包……"); Cloud.DownloadFileAsync(zp, "THUAI7.tar.gz").Wait(); CloudReport.ComCount = 1; Status = UpdateStatus.unarchieving; - Cloud.Log.LogInfo($"安装包下载完毕,正在解压……"); + Cloud.Log.LogInfo($"installer安装包下载完毕,正在解压……"); Cloud.ArchieveUnzip(zp, Data.Config.InstallPath); - Cloud.Log.LogInfo($"解压完成"); + Cloud.Log.LogInfo($"installer解压完成"); File.Delete(zp); CurrentVersion = Data.FileHashData.TVersion; Cloud.Log.LogInfo("正在下载选手代码……"); Status = UpdateStatus.downloading; - CloudReport.Count = 3; + CloudReport.Count += 2; var tocpp = Cloud.DownloadFileAsync(Path.Combine(Data.Config.InstallPath, "CAPI", "cpp", "API", "src", "AI.cpp"), $"./Templates/t.{CurrentVersion.TemplateVersion}.cpp").ContinueWith(_ => CloudReport.ComCount++); var topy = Cloud.DownloadFileAsync(Path.Combine(Data.Config.InstallPath, "CAPI", "python", "PyAPI", "AI.py"), $"./Templates/t.{CurrentVersion.TemplateVersion}.py").ContinueWith(_ => CloudReport.ComCount++); Task.WaitAll(tocpp, topy); + + Cloud.Report.Count += 1; + zp = Path.Combine(Data.Config.InstallPath, "protoCpp.tar.gz"); + Cloud.Log.LogInfo("正在下载proto cpp库……"); + Cloud.DownloadFileAsync(zp, "Setup/proto/protoCpp.tar.gz").Wait(); + CloudReport.ComCount += 1; + Status = UpdateStatus.unarchieving; + Cloud.Log.LogInfo($"proto cpp库下载完毕,正在解压……"); + var protoCppLibPath = Path.Combine(Data.Config.InstallPath, "CAPI", "cpp", "lib"); + if (!Directory.Exists(protoCppLibPath)) + Directory.CreateDirectory(protoCppLibPath); + Cloud.ArchieveUnzip(zp, protoCppLibPath); + Cloud.Log.LogInfo($"proto cpp库解压完成"); + File.Delete(zp); + if (CloudReport.ComCount == CloudReport.Count) { Cloud.Log.LogInfo("选手代码下载成功!"); @@ -296,7 +310,7 @@ public bool CheckUpdate(bool writeMD5 = true) Status = UpdateStatus.success; if (Data.MD5Update.Count != 0 || CurrentVersion < Data.FileHashData.TVersion) { - Data.Log.LogInfo("需要更新,请点击更新按钮以更新。"); + Data.Log.LogInfo("代码库需要更新,请点击更新按钮以更新。"); if (writeMD5) { Data.SaveMD5Data(); @@ -312,6 +326,15 @@ public bool CheckUpdate(bool writeMD5 = true) } return true; } + else if (!Directory.Exists(Path.Combine(Data.Config.InstallPath, "CAPI", "cpp", "lib"))) + { + Data.Log.LogInfo("未检测到proto cpp库,请点击更新按钮以修复。"); + if (writeMD5) + { + Data.SaveMD5Data(); + } + return true; + } else { Data.Log.LogInfo("您的版本已经是最新版本!"); @@ -370,7 +393,23 @@ public int Update() return -1; } } - + // 如果缺少proto cpp库,应当立刻下载 + if (!Directory.Exists(Path.Combine(Data.Config.InstallPath, "CAPI", "cpp", "lib"))) + { + Cloud.Report.Count += 1; + string zp = Path.Combine(Data.Config.InstallPath, "protoCpp.tar.gz"); + Cloud.Log.LogInfo("正在下载proto cpp库……"); + Cloud.DownloadFileAsync(zp, "Setup/proto/protoCpp.tar.gz").Wait(); + CloudReport.ComCount += 1; + Status = UpdateStatus.unarchieving; + Cloud.Log.LogInfo($"proto cpp库下载完毕,正在解压……"); + var protoCppLibPath = Path.Combine(Data.Config.InstallPath, "CAPI", "cpp", "lib"); + if (!Directory.Exists(protoCppLibPath)) + Directory.CreateDirectory(protoCppLibPath); + Cloud.ArchieveUnzip(zp, protoCppLibPath); + Cloud.Log.LogInfo($"proto cpp库解压完成"); + File.Delete(zp); + } // 启动器本身需要更新,返回结果为16 if (CurrentVersion.InstallerVersion < Data.FileHashData.TVersion.InstallerVersion) { diff --git a/installer/Model/Local_Data.cs b/installer/Model/Local_Data.cs index 27cbed03..b89739f9 100755 --- a/installer/Model/Local_Data.cs +++ b/installer/Model/Local_Data.cs @@ -288,8 +288,8 @@ public void ScanDir(bool VersionRefresh = true) public static bool IsUserFile(string filename) { filename = filename.Replace(Path.DirectorySeparatorChar, '/'); - if (filename.Contains("/git/") || filename.Contains("bin/") || filename.Contains("/obj/") || filename.Contains("/x64/") - || filename.Contains("__pycache__")) + if (filename.Contains("/git/") || filename.Contains("/bin/") || filename.Contains("/obj/") || filename.Contains("/x64/") + || filename.Contains("__pycache__") || filename.Contains("/CAPI/cpp/lib/")) return true; if (filename.Contains("/vs/") || filename.Contains("/.vs/") || filename.Contains("/.vscode/")) return true; diff --git a/installer/Model/Tencent_Cos.cs b/installer/Model/Tencent_Cos.cs index 0bc0998f..f18b98e1 100755 --- a/installer/Model/Tencent_Cos.cs +++ b/installer/Model/Tencent_Cos.cs @@ -10,6 +10,8 @@ using System; using installer.Data; using System.Threading.Tasks; +using COSXML.Model.Bucket; +using COSXML.Model.Tag; // 禁用对没有调用异步API的异步函数的警告 #pragma warning disable CS1998 @@ -153,12 +155,14 @@ public int DownloadQueue(string basePath, IEnumerable queue) int thID = Log.StartNew(); Log.LogDebug(thID, "Batch download task started."); var array = queue.ToArray(); - Report.Count = array.Count(); - Report.ComCount = 0; - if (Report.Count == 0) - return 0; - var partitionar = Partitioner.Create(0, Report.Count, Report.Count / 4 > 0 ? Report.Count / 4 : Report.Count); - var c = 0; + var count = array.Length; + if (count == 0) + return 0; + var comCount = 0; + var comCountOld = Report.ComCount; + Report.Count += count; + + var partitionar = Partitioner.Create(0, count, count / 4 > 0 ? count / 4 : count); Parallel.ForEach(partitionar, (range, loopState) => { for (long i = range.Item1; i < range.Item2; i++) @@ -177,14 +181,14 @@ public int DownloadQueue(string basePath, IEnumerable queue) } finally { - Interlocked.Increment(ref c); - Report.ComCount = c; + Interlocked.Increment(ref comCount); + Report.ComCount = comCount + comCountOld; Log.LogInfo(thID, $"Child process: {subID} finished."); } } }); Log.LogInfo(thID, "Batch download task finished."); - Report.ComCount = Report.Count; + Report.ComCount = comCount + comCountOld; return thID; } @@ -300,6 +304,37 @@ public void DeleteFile(string remotePath) } } + public List EnumerateDir(string remotePath) + { + int thID = Log.StartNew(); + var result = new List(); + string bucket = $"{BucketName}-{Appid}"; + remotePath = remotePath.TrimStart('.').TrimStart('/'); + Log.LogInfo(thID, $"Enumerate files in {remotePath}"); + + bool truncated = false; + string marker = string.Empty; + do + { + GetBucketRequest request = new GetBucketRequest(bucket); + request.SetPrefix(remotePath); + request.SetDelimiter("/"); + if (!string.IsNullOrEmpty(marker)) + request.SetMarker(marker); + //执行请求 + GetBucketResult res = cosXml.GetBucket(request); + ListBucket info = res.listBucket; + result.AddRange(info.contentsList.Select(i => i.key).Where(i => i != remotePath)); + foreach (var dir in info.commonPrefixesList) + { + result.AddRange(EnumerateDir(dir.prefix)); + } + truncated = info.isTruncated; + marker = info.nextMarker; + } while ( truncated ); + + return result; + } #region 异步方法包装 public Task DownloadFileAsync(string savePath, string? remotePath = null) { diff --git a/installer/installer.csproj b/installer/installer.csproj index 0dcc3218..e82f1be8 100755 --- a/installer/installer.csproj +++ b/installer/installer.csproj @@ -85,6 +85,15 @@ + + + + + + + + + From 672ba267fed1b7aee4ca8e228517d613b606fd0c Mon Sep 17 00:00:00 2001 From: DreamEnderKing Date: Fri, 10 May 2024 19:46:21 +0800 Subject: [PATCH 02/42] test: :art: Merge the test workflow(diabled). --- .github/workflows/debug.yml.disabled | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/debug.yml.disabled diff --git a/.github/workflows/debug.yml.disabled b/.github/workflows/debug.yml.disabled new file mode 100644 index 00000000..4db1947b --- /dev/null +++ b/.github/workflows/debug.yml.disabled @@ -0,0 +1,13 @@ +name: CI +on: [push] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup .NET Core + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + - name: Setup tmate session + uses: mxschmitt/action-tmate@v3 \ No newline at end of file From 9f8311d9aa29d23ca13bb81fbd3fb17da8ecf5e8 Mon Sep 17 00:00:00 2001 From: DreamEnderKing Date: Fri, 10 May 2024 21:20:41 +0800 Subject: [PATCH 03/42] feat: :lipstick: Add select file button to playback screen. --- installer/MauiProgram.cs | 2 +- installer/Page/PlaybackPage.xaml | 10 +++- .../Platforms/Android/AndroidManifest.xml | 6 +-- installer/Platforms/Android/MainActivity.cs | 5 ++ installer/Platforms/iOS/Info.plist | 25 +++++++++ installer/ViewModel/DebugViewModel.cs | 8 +++ installer/ViewModel/LaunchViewModel.cs | 2 + installer/ViewModel/PlaybackViewModel.cs | 54 ++++++++++++++++++- 8 files changed, 106 insertions(+), 6 deletions(-) diff --git a/installer/MauiProgram.cs b/installer/MauiProgram.cs index 3040057e..2bf8f9ef 100755 --- a/installer/MauiProgram.cs +++ b/installer/MauiProgram.cs @@ -67,7 +67,7 @@ public static MauiApp CreateMauiApp() var c = builder.Services.AddSingleton().First(); builder.Services.AddSingleton(FolderPicker.Default); - + builder.Services.AddSingleton(FilePicker.Default); AddViewModelService(builder); AddPageService(builder); diff --git a/installer/Page/PlaybackPage.xaml b/installer/Page/PlaybackPage.xaml index 9a7315e5..c143968f 100644 --- a/installer/Page/PlaybackPage.xaml +++ b/installer/Page/PlaybackPage.xaml @@ -25,10 +25,18 @@ VerticalOptions="Center" FontSize="{Binding ConstFontSize}"/> +