From 1d97f6af60cc9d78c83a3e88ad259914c4631cb0 Mon Sep 17 00:00:00 2001 From: DragonAura Date: Wed, 19 Apr 2023 18:08:55 +0800 Subject: [PATCH 1/4] fix(CAPI): :bug: change async Wait to sync --- CAPI/cpp/API/include/API.h | 10 +++++----- CAPI/cpp/API/src/API.cpp | 16 ++++++---------- CAPI/cpp/API/src/DebugAPI.cpp | 16 ++++++---------- CAPI/python/PyAPI/AI.py | 6 +++--- CAPI/python/PyAPI/API.py | 12 ++++++------ CAPI/python/PyAPI/DebugAPI.py | 12 ++++++------ CAPI/python/PyAPI/Interface.py | 2 +- 7 files changed, 33 insertions(+), 41 deletions(-) diff --git a/CAPI/cpp/API/include/API.h b/CAPI/cpp/API/include/API.h index a8f3034..75824ae 100644 --- a/CAPI/cpp/API/include/API.h +++ b/CAPI/cpp/API/include/API.h @@ -118,7 +118,7 @@ public: [[nodiscard]] virtual std::pair GetMessage() = 0; // 等待下一帧 - virtual std::future Wait() = 0; + virtual bool Wait() = 0; // 获取视野内可见的学生/捣蛋鬼的信息 [[nodiscard]] virtual std::vector> GetStudents() const = 0; @@ -242,7 +242,7 @@ public: [[nodiscard]] bool HaveMessage() override; [[nodiscard]] std::pair GetMessage() override; - std::future Wait() override; + bool Wait() override; [[nodiscard]] std::vector> GetStudents() const override; [[nodiscard]] std::vector> GetTrickers() const override; @@ -330,7 +330,7 @@ public: [[nodiscard]] bool HaveMessage() override; [[nodiscard]] std::pair GetMessage() override; - std::future Wait() override; + bool Wait() override; [[nodiscard]] std::vector> GetStudents() const override; [[nodiscard]] std::vector> GetTrickers() const override; @@ -410,7 +410,7 @@ public: [[nodiscard]] bool HaveMessage() override; [[nodiscard]] std::pair GetMessage() override; - std::future Wait() override; + bool Wait() override; [[nodiscard]] std::vector> GetStudents() const override; [[nodiscard]] std::vector> GetTrickers() const override; @@ -483,7 +483,7 @@ public: [[nodiscard]] bool HaveMessage() override; [[nodiscard]] std::pair GetMessage() override; - std::future Wait() override; + bool Wait() override; [[nodiscard]] std::vector> GetStudents() const override; [[nodiscard]] std::vector> GetTrickers() const override; diff --git a/CAPI/cpp/API/src/API.cpp b/CAPI/cpp/API/src/API.cpp index ce38ae5..9b4693a 100644 --- a/CAPI/cpp/API/src/API.cpp +++ b/CAPI/cpp/API/src/API.cpp @@ -217,24 +217,20 @@ std::pair TrickerAPI::GetMessage() return logic.GetMessage(); } -std::future StudentAPI::Wait() +bool StudentAPI::Wait() { if (logic.GetCounter() == -1) - return std::async(std::launch::async, [this]() - { return false; }); + return false; else - return std::async(std::launch::async, [this]() - { return logic.WaitThread(); }); + return logic.WaitThread(); } -std::future TrickerAPI::Wait() +bool TrickerAPI::Wait() { if (logic.GetCounter() == -1) - return std::async(std::launch::async, [this]() - { return false; }); + return false; else - return std::async(std::launch::async, [this]() - { return logic.WaitThread(); }); + return logic.WaitThread(); } std::vector> StudentAPI::GetTrickers() const diff --git a/CAPI/cpp/API/src/DebugAPI.cpp b/CAPI/cpp/API/src/DebugAPI.cpp index 7861349..fdb9a5d 100644 --- a/CAPI/cpp/API/src/DebugAPI.cpp +++ b/CAPI/cpp/API/src/DebugAPI.cpp @@ -403,26 +403,22 @@ std::pair TrickerDebugAPI::GetMessage() return result; } -std::future StudentDebugAPI::Wait() +bool StudentDebugAPI::Wait() { logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint)); if (logic.GetCounter() == -1) - return std::async(std::launch::async, []() - { return false; }); + return false; else - return std::async(std::launch::async, [this]() - { return logic.WaitThread(); }); + return logic.WaitThread(); } -std::future TrickerDebugAPI::Wait() +bool TrickerDebugAPI::Wait() { logger->info("Wait: called at {}ms", Time::TimeSinceStart(startPoint)); if (logic.GetCounter() == -1) - return std::async(std::launch::async, []() - { return false; }); + return false; else - return std::async(std::launch::async, [this]() - { return logic.WaitThread(); }); + return logic.WaitThread(); } std::vector> StudentDebugAPI::GetTrickers() const diff --git a/CAPI/python/PyAPI/AI.py b/CAPI/python/PyAPI/AI.py index 5c742f6..010a3dc 100644 --- a/CAPI/python/PyAPI/AI.py +++ b/CAPI/python/PyAPI/AI.py @@ -43,7 +43,7 @@ class AI(IAI): self.__playerID = pID def StudentPlay(self, api: IStudentAPI) -> None: - #公共操作 + # 公共操作 if self.__playerID == 0: # 玩家0执行操作 return @@ -56,8 +56,8 @@ class AI(IAI): elif self.__playerID == 3: # 玩家3执行操作 return - #可以写成if self.__playerID<2之类的写法 - #公共操作 + # 可以写成if self.__playerID<2之类的写法 + # 公共操作 return def TrickerPlay(self, api: ITrickerAPI) -> None: diff --git a/CAPI/python/PyAPI/API.py b/CAPI/python/PyAPI/API.py index 2a04666..2ce4506 100644 --- a/CAPI/python/PyAPI/API.py +++ b/CAPI/python/PyAPI/API.py @@ -79,11 +79,11 @@ class StudentAPI(IStudentAPI, IGameTimer): # 等待下一帧 - def Wait(self) -> Future[bool]: + def Wait(self) -> bool: if self.__logic.GetCounter() == -1: - return self.__pool.submit(lambda: False) + return False else: - return self.__pool.submit(self.__logic.WaitThread) + return self.__logic.WaitThread() # 获取各类游戏中的消息 @@ -252,11 +252,11 @@ class TrickerAPI(ITrickerAPI, IGameTimer): # 等待下一帧 - def Wait(self) -> Future[bool]: + def Wait(self) -> bool: if self.__logic.GetCounter() == -1: - return self.__pool.submit(lambda: False) + return False else: - return self.__pool.submit(self.__logic.WaitThread) + return self.__logic.WaitThread() # 获取各类游戏中的消息 diff --git a/CAPI/python/PyAPI/DebugAPI.py b/CAPI/python/PyAPI/DebugAPI.py index d8122e1..17deaa7 100644 --- a/CAPI/python/PyAPI/DebugAPI.py +++ b/CAPI/python/PyAPI/DebugAPI.py @@ -249,13 +249,13 @@ class StudentDebugAPI(IStudentAPI, IGameTimer): # 等待下一帧 - def Wait(self) -> Future[bool]: + def Wait(self) -> bool: self.__logger.info( f"Wait: called at {self.__GetTime()}ms") if self.__logic.GetCounter() == -1: - return self.__pool.submit(lambda: False) + return False else: - return self.__pool.submit(self.__logic.WaitThread) + return self.__logic.WaitThread() # 获取各类游戏中的消息 @@ -701,13 +701,13 @@ class TrickerDebugAPI(ITrickerAPI, IGameTimer): # 等待下一帧 - def Wait(self) -> Future[bool]: + def Wait(self) -> bool: self.__logger.info( f"Wait: called at {self.__GetTime()}ms") if self.__logic.GetCounter() == -1: - return self.__pool.submit(lambda: False) + return False else: - return self.__pool.submit(self.__logic.WaitThread) + return self.__logic.WaitThread() # 获取各类游戏中的消息 diff --git a/CAPI/python/PyAPI/Interface.py b/CAPI/python/PyAPI/Interface.py index 07066f0..4d38060 100644 --- a/CAPI/python/PyAPI/Interface.py +++ b/CAPI/python/PyAPI/Interface.py @@ -245,7 +245,7 @@ class IAPI(metaclass=ABCMeta): # 等待下一帧 @abstractmethod - def Wait(self) -> Future[bool]: + def Wait(self) -> bool: pass # 获取各类游戏中的消息 From 67e21e27fae2e23acf0a2d24a1e733c07778e5fe Mon Sep 17 00:00:00 2001 From: OctaAcid Date: Wed, 19 Apr 2023 22:21:25 +0800 Subject: [PATCH 2/4] chore: use independent publishing now, self update function modified accordingly --- installer/Installer/Installer.csproj | 2 - installer/Installer/Model.cs | 52 +++++++++++++------ installer/Installer/ViewModel.cs | 9 +++- .../InstallerUpdater/InstallerUpdater.csproj | 4 +- installer/InstallerUpdater/MainWindow.xaml.cs | 1 + installer/InstallerUpdater/Program.cs | 18 +++++-- 6 files changed, 58 insertions(+), 28 deletions(-) diff --git a/installer/Installer/Installer.csproj b/installer/Installer/Installer.csproj index e63a124..53d5639 100644 --- a/installer/Installer/Installer.csproj +++ b/installer/Installer/Installer.csproj @@ -6,11 +6,9 @@ enable true true - dotNetRuntime - diff --git a/installer/Installer/Model.cs b/installer/Installer/Model.cs index d78f9be..faaa07f 100644 --- a/installer/Installer/Model.cs +++ b/installer/Installer/Model.cs @@ -458,8 +458,8 @@ namespace Downloader .Build(); // 创建 CosXmlConfig 对象 // 永久密钥访问凭证 - string secretId = "***"; //"云 API 密钥 SecretId"; - string secretKey = "***"; //"云 API 密钥 SecretKey"; + string secretId = "AKIDVpzdDcmhS0KNAj5FLG0WnpcBconY9UYN"; //"云 API 密钥 SecretId"; + string secretKey = "f2FDyVnpgNr67urZ3HF4f5KL8i2DCzY2"; //"云 API 密钥 SecretKey"; long durationSecond = 1000; // 每次请求签名有效时长,单位为秒 QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider( @@ -691,12 +691,14 @@ namespace Downloader catch (CosClientException clientEx) { // 请求失败 + MessageBox.Show("网络错误"); Console.WriteLine("CosClientException: " + clientEx.ToString() + Environment.NewLine); return; } catch (CosServerException serverEx) { // 请求失败 + MessageBox.Show("网络错误"); Console.WriteLine("CosClientException: " + serverEx.ToString() + Environment.NewLine); return; } @@ -1195,9 +1197,11 @@ namespace Downloader public static int CheckSelfVersion() { + string keyHead = "Installer/"; Tencent_cos_download downloader = new Tencent_cos_download(); string hashName = "installerHash.json"; string dir = Directory.GetCurrentDirectory(); + int result = 0; try { if (File.Exists(System.IO.Path.Combine(dir, hashName))) @@ -1213,28 +1217,42 @@ namespace Downloader json = r.ReadToEnd(); json = json.Replace("\r", string.Empty).Replace("\n", string.Empty); Dictionary jsonDict = JsonConvert.DeserializeObject>(json); + string md5 = ""; + List awaitUpdate = new List(); if (jsonDict != null) { - if (jsonDict.ContainsKey("InstallerUpdater.exe")) - { - string updaterHash = GetFileMd5Hash(System.IO.Path.Combine(dir, "InstallerUpdater.exe")); - if (updaterHash != null && !jsonDict["InstallerUpdater.exe"].Equals(updaterHash)) - downloader.download(System.IO.Path.Combine(dir, "InstallerUpdater.exe"), "InstallerUpdater.exe"); - } - else - return -1; - if (jsonDict.ContainsKey("Installer.exe")) + foreach (KeyValuePair pair in jsonDict) { - string selfHash = GetFileMd5Hash(System.IO.Path.Combine(dir, "Installer.exe")); - if (selfHash != null && !jsonDict["Installer.exe"].Equals(selfHash)) - return 1; + md5 = GetFileMd5Hash(System.IO.Path.Combine(dir, pair.Key)); + if (md5.Length == 0) // 文档不存在 + { + downloader.download(System.IO.Path.Combine(dir, pair.Key), keyHead + pair.Key); + } + else if (md5.Equals("conflict")) + { + MessageBox.Show($"检查{pair.Key}更新时遇到问题,请反馈", "读取出错", MessageBoxButton.OK, MessageBoxImage.Error); + } + else if (md5 != pair.Value) // MD5不匹配 + { + if (pair.Key.Substring(0, 12).Equals("InstallerUpd")) + { + File.Delete(System.IO.Path.Combine(dir, pair.Key)); + downloader.download(System.IO.Path.Combine(dir, pair.Key), keyHead + pair.Key); + } + else + { + result = 1; + awaitUpdate.Append(pair.Key); + } + } } - else - return -1; } else return -1; - return 0; + string Contentjson = JsonConvert.SerializeObject(awaitUpdate); + Contentjson = Contentjson.Replace("\r", String.Empty).Replace("\n", String.Empty).Replace(@"\\", "/"); + File.WriteAllText(@System.IO.Path.Combine(dir, "updateList.json"), Contentjson); + return result; } } } diff --git a/installer/Installer/ViewModel.cs b/installer/Installer/ViewModel.cs index b7b5b21..472b63f 100644 --- a/installer/Installer/ViewModel.cs +++ b/installer/Installer/ViewModel.cs @@ -33,7 +33,7 @@ namespace starter.viewmodel.settings public SettingsViewModel() { - //Program.Tencent_cos_download.UpdateHash(); + Program.Tencent_cos_download.UpdateHash(); Status = SettingsModel.Status.working; @@ -152,6 +152,13 @@ namespace starter.viewmodel.settings if (asyncUpdater.CancellationPending) { e.Cancel = true; + MessageBox.Show("下载取消"); + if (e.Argument.ToString().Equals("Manual")) + { + Status = SettingsModel.Status.menu; + } + else + Status = SettingsModel.Status.login; return; } else diff --git a/installer/InstallerUpdater/InstallerUpdater.csproj b/installer/InstallerUpdater/InstallerUpdater.csproj index 79fbb62..0dd4fb5 100644 --- a/installer/InstallerUpdater/InstallerUpdater.csproj +++ b/installer/InstallerUpdater/InstallerUpdater.csproj @@ -5,14 +5,12 @@ net6.0-windows enable true - dotNetRuntime - - true + true diff --git a/installer/InstallerUpdater/MainWindow.xaml.cs b/installer/InstallerUpdater/MainWindow.xaml.cs index 1e61b9f..80ca632 100644 --- a/installer/InstallerUpdater/MainWindow.xaml.cs +++ b/installer/InstallerUpdater/MainWindow.xaml.cs @@ -28,6 +28,7 @@ namespace InstallerUpdater public MainWindow() { InitializeComponent(); + MessageBox.Show("这是旧版"); asyncDownloader.DoWork += AsyncDownloader_DoWork; asyncDownloader.RunWorkerCompleted += AsyncDownloader_RunWorkerCompleted; if (asyncDownloader.IsBusy) diff --git a/installer/InstallerUpdater/Program.cs b/installer/InstallerUpdater/Program.cs index b274a39..5743688 100644 --- a/installer/InstallerUpdater/Program.cs +++ b/installer/InstallerUpdater/Program.cs @@ -19,14 +19,22 @@ namespace Program public static string Dir = Directory.GetCurrentDirectory(); public static string InstallerName = "Installer.exe"; public static string jsonKey = "installerHash.json"; + public static string KeyHead = "Installer/"; public static bool UpdateInstaller() { + string json; try { - download(Path.Combine(Dir, "newInstaller.exe"), InstallerName); - File.Delete(Path.Combine(Dir, InstallerName)); - File.Move(Path.Combine(Dir, "newInstaller.exe"), Path.Combine(Dir, InstallerName)); + using (StreamReader r = new StreamReader(System.IO.Path.Combine(Dir, "updateList.json"))) + json = r.ReadToEnd(); + json = json.Replace("\r", string.Empty).Replace("\n", string.Empty); + List jsonList = JsonConvert.DeserializeObject>(json); + foreach (string todo in jsonList) + { + File.Delete(Path.Combine(Dir, todo)); + download(Path.Combine(Dir, todo), KeyHead + todo); + } } catch { @@ -49,8 +57,8 @@ namespace Program .Build(); // 创建 CosXmlConfig 对象 // 永久密钥访问凭证 - string secretId = "***"; //"云 API 密钥 SecretId"; - string secretKey = "***"; //"云 API 密钥 SecretKey"; + string secretId = "AKIDVpzdDcmhS0KNAj5FLG0WnpcBconY9UYN"; //"云 API 密钥 SecretId"; + string secretKey = "f2FDyVnpgNr67urZ3HF4f5KL8i2DCzY2"; //"云 API 密钥 SecretKey"; long durationSecond = 1000; // 每次请求签名有效时长,单位为秒 QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider( From fe7930d06d8f62a4919cf025e2e8e6bc91eabd62 Mon Sep 17 00:00:00 2001 From: OctaAcid Date: Wed, 19 Apr 2023 22:22:56 +0800 Subject: [PATCH 3/4] chore: removed secretId from code --- installer/Installer/Model.cs | 4 ++-- installer/InstallerUpdater/Program.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/installer/Installer/Model.cs b/installer/Installer/Model.cs index faaa07f..adfa026 100644 --- a/installer/Installer/Model.cs +++ b/installer/Installer/Model.cs @@ -458,8 +458,8 @@ namespace Downloader .Build(); // 创建 CosXmlConfig 对象 // 永久密钥访问凭证 - string secretId = "AKIDVpzdDcmhS0KNAj5FLG0WnpcBconY9UYN"; //"云 API 密钥 SecretId"; - string secretKey = "f2FDyVnpgNr67urZ3HF4f5KL8i2DCzY2"; //"云 API 密钥 SecretKey"; + string secretId = "***"; //"云 API 密钥 SecretId"; + string secretKey = "***"; //"云 API 密钥 SecretKey"; long durationSecond = 1000; // 每次请求签名有效时长,单位为秒 QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider( diff --git a/installer/InstallerUpdater/Program.cs b/installer/InstallerUpdater/Program.cs index 5743688..1a76005 100644 --- a/installer/InstallerUpdater/Program.cs +++ b/installer/InstallerUpdater/Program.cs @@ -57,8 +57,8 @@ namespace Program .Build(); // 创建 CosXmlConfig 对象 // 永久密钥访问凭证 - string secretId = "AKIDVpzdDcmhS0KNAj5FLG0WnpcBconY9UYN"; //"云 API 密钥 SecretId"; - string secretKey = "f2FDyVnpgNr67urZ3HF4f5KL8i2DCzY2"; //"云 API 密钥 SecretKey"; + string secretId = "***"; //"云 API 密钥 SecretId"; + string secretKey = "***"; //"云 API 密钥 SecretKey"; long durationSecond = 1000; // 每次请求签名有效时长,单位为秒 QCloudCredentialProvider cosCredentialProvider = new DefaultQCloudCredentialProvider( From 5d9c142aba2927c1da980a6e3c91df403f858e19 Mon Sep 17 00:00:00 2001 From: Changli Tang <84725343+TCL606@users.noreply.github.com> Date: Wed, 19 Apr 2023 23:55:50 +0800 Subject: [PATCH 4/4] Update upload_deploy.yml --- .github/workflows/upload_deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/upload_deploy.yml b/.github/workflows/upload_deploy.yml index 4a92d96..50ea673 100644 --- a/.github/workflows/upload_deploy.yml +++ b/.github/workflows/upload_deploy.yml @@ -24,7 +24,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v4 with: - python-version: '3.9.2' + python-version: '3.9' - name: Pip Install paramiko run: pip install paramiko