From c71a2fca1f519a1e12e1294de133c33a4f4ffebc Mon Sep 17 00:00:00 2001 From: uye <2396806385@qq.com> Date: Sun, 23 Apr 2023 01:23:06 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20LoadResource=E6=B7=BB=E5=8A=A0onlyRelo?= =?UTF-8?q?adOTA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MaaWpfGui/Main/AsstProxy.cs | 27 ++++++++++++++++++-------- src/MaaWpfGui/Services/StageManager.cs | 7 ++++--- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/MaaWpfGui/Main/AsstProxy.cs b/src/MaaWpfGui/Main/AsstProxy.cs index bd35d1fa2f..64066b3a25 100644 --- a/src/MaaWpfGui/Main/AsstProxy.cs +++ b/src/MaaWpfGui/Main/AsstProxy.cs @@ -70,7 +70,7 @@ namespace MaaWpfGui.Main [DllImport("MaaCore.dll")] private static extern unsafe bool AsstLoadResource(byte* dirname); - public static unsafe bool AsstLoadResource(string dirname) + private static unsafe bool AsstLoadResource(string dirname) { fixed (byte* ptr = EncodeNullTerminatedUTF8(dirname)) { @@ -199,10 +199,11 @@ namespace MaaWpfGui.Main /// /// 加载全局资源。 /// + /// 是否强制加载ota资源。 /// 是否成功。 - public bool LoadResource() + public bool LoadResource(bool onlyReloadOTA = false) { - if (!ForcedReloadResource && _settingsViewModel.ClientType == _curResource) + if (!ForcedReloadResource && !onlyReloadOTA && _settingsViewModel.ClientType == _curResource) { return true; } @@ -212,12 +213,15 @@ namespace MaaWpfGui.Main || _settingsViewModel.ClientType == "Official" || _settingsViewModel.ClientType == "Bilibili") { // The resources of Official and Bilibili are the same - if (!ForcedReloadResource && (_curResource == "Official" || _curResource == "Bilibili")) + if (!ForcedReloadResource && !onlyReloadOTA && (_curResource == "Official" || _curResource == "Bilibili")) { return true; } - loaded = AsstLoadResource(Directory.GetCurrentDirectory()); + if (!onlyReloadOTA) + { + loaded = AsstLoadResource(Directory.GetCurrentDirectory()); + } // Load the cached incremental resources loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache"); @@ -226,17 +230,24 @@ namespace MaaWpfGui.Main { // Load basic resources for CN client first // Then load global incremental resources - loaded = AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType); + if (!onlyReloadOTA) + { + loaded = AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType); + } // Load the cached incremental resources - loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache\\resource\\global\\" + _settingsViewModel.ClientType); + loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache") + && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache\\resource\\global\\" + _settingsViewModel.ClientType); } else { // Load basic resources for CN client first // Then load global incremental resources - loaded = AsstLoadResource(Directory.GetCurrentDirectory()) + if (!onlyReloadOTA) + { + loaded = AsstLoadResource(Directory.GetCurrentDirectory()) && AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType); + } // Load the cached incremental resources loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache") diff --git a/src/MaaWpfGui/Services/StageManager.cs b/src/MaaWpfGui/Services/StageManager.cs index d89ba79c99..b8497d6f1a 100644 --- a/src/MaaWpfGui/Services/StageManager.cs +++ b/src/MaaWpfGui/Services/StageManager.cs @@ -49,6 +49,7 @@ namespace MaaWpfGui.Services // model references private readonly TaskQueueViewModel _taskQueueViewModel; + private readonly AsstProxy _asstProxy; private readonly IMaaApiService _maaApiService; private static readonly ILogger _logger = Log.ForContext(); @@ -63,6 +64,7 @@ namespace MaaWpfGui.Services public StageManager(IContainer container) { _taskQueueViewModel = container.Get(); + _asstProxy = container.Get(); _maaApiService = container.Get(); UpdateStageLocal(); @@ -154,8 +156,6 @@ namespace MaaWpfGui.Services JObject activity = await _maaApiService.RequestMaaApiWithCache(StageApi); JObject tasksJson = await _maaApiService.RequestMaaApiWithCache(TasksApi); - AsstProxy.AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache"); - if (clientType != "Official" && tasksJson != null) { var tasksPath = "resource/global/" + clientType + '/' + TasksApi; @@ -164,9 +164,10 @@ namespace MaaWpfGui.Services // TODO: There may be an issue when the CN resource is loaded from cache (e.g. network down) while global resource is downloaded (e.g. network up again) // var tasksJsonClient = fromWeb ? WebService.RequestMaaApiWithCache(tasksPath) : WebService.RequestMaaApiWithCache(tasksPath); await _maaApiService.RequestMaaApiWithCache(tasksPath); - AsstProxy.AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache\\resource\\global\\" + clientType); } + _asstProxy.LoadResource(true); + return activity; }