chore: LoadResource添加onlyReloadOTA

This commit is contained in:
uye
2023-04-23 01:23:06 +08:00
parent f4fdf362e7
commit c71a2fca1f
2 changed files with 23 additions and 11 deletions

View File

@@ -70,7 +70,7 @@ namespace MaaWpfGui.Main
[DllImport("MaaCore.dll")] [DllImport("MaaCore.dll")]
private static extern unsafe bool AsstLoadResource(byte* dirname); 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)) fixed (byte* ptr = EncodeNullTerminatedUTF8(dirname))
{ {
@@ -199,10 +199,11 @@ namespace MaaWpfGui.Main
/// <summary> /// <summary>
/// 加载全局资源。 /// 加载全局资源。
/// </summary> /// </summary>
/// <param name="onlyReloadOTA">是否强制加载ota资源。</param>
/// <returns>是否成功。</returns> /// <returns>是否成功。</returns>
public bool LoadResource() public bool LoadResource(bool onlyReloadOTA = false)
{ {
if (!ForcedReloadResource && _settingsViewModel.ClientType == _curResource) if (!ForcedReloadResource && !onlyReloadOTA && _settingsViewModel.ClientType == _curResource)
{ {
return true; return true;
} }
@@ -212,12 +213,15 @@ namespace MaaWpfGui.Main
|| _settingsViewModel.ClientType == "Official" || _settingsViewModel.ClientType == "Bilibili") || _settingsViewModel.ClientType == "Official" || _settingsViewModel.ClientType == "Bilibili")
{ {
// The resources of Official and Bilibili are the same // The resources of Official and Bilibili are the same
if (!ForcedReloadResource && (_curResource == "Official" || _curResource == "Bilibili")) if (!ForcedReloadResource && !onlyReloadOTA && (_curResource == "Official" || _curResource == "Bilibili"))
{ {
return true; return true;
} }
loaded = AsstLoadResource(Directory.GetCurrentDirectory()); if (!onlyReloadOTA)
{
loaded = AsstLoadResource(Directory.GetCurrentDirectory());
}
// Load the cached incremental resources // Load the cached incremental resources
loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache"); loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache");
@@ -226,17 +230,24 @@ namespace MaaWpfGui.Main
{ {
// Load basic resources for CN client first // Load basic resources for CN client first
// Then load global incremental resources // 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 // 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 else
{ {
// Load basic resources for CN client first // Load basic resources for CN client first
// Then load global incremental resources // Then load global incremental resources
loaded = AsstLoadResource(Directory.GetCurrentDirectory()) if (!onlyReloadOTA)
{
loaded = AsstLoadResource(Directory.GetCurrentDirectory())
&& AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType); && AsstLoadResource(Directory.GetCurrentDirectory() + "\\resource\\global\\" + _settingsViewModel.ClientType);
}
// Load the cached incremental resources // Load the cached incremental resources
loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache") loaded = loaded && AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache")

View File

@@ -49,6 +49,7 @@ namespace MaaWpfGui.Services
// model references // model references
private readonly TaskQueueViewModel _taskQueueViewModel; private readonly TaskQueueViewModel _taskQueueViewModel;
private readonly AsstProxy _asstProxy;
private readonly IMaaApiService _maaApiService; private readonly IMaaApiService _maaApiService;
private static readonly ILogger _logger = Log.ForContext<StageManager>(); private static readonly ILogger _logger = Log.ForContext<StageManager>();
@@ -63,6 +64,7 @@ namespace MaaWpfGui.Services
public StageManager(IContainer container) public StageManager(IContainer container)
{ {
_taskQueueViewModel = container.Get<TaskQueueViewModel>(); _taskQueueViewModel = container.Get<TaskQueueViewModel>();
_asstProxy = container.Get<AsstProxy>();
_maaApiService = container.Get<IMaaApiService>(); _maaApiService = container.Get<IMaaApiService>();
UpdateStageLocal(); UpdateStageLocal();
@@ -154,8 +156,6 @@ namespace MaaWpfGui.Services
JObject activity = await _maaApiService.RequestMaaApiWithCache(StageApi); JObject activity = await _maaApiService.RequestMaaApiWithCache(StageApi);
JObject tasksJson = await _maaApiService.RequestMaaApiWithCache(TasksApi); JObject tasksJson = await _maaApiService.RequestMaaApiWithCache(TasksApi);
AsstProxy.AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache");
if (clientType != "Official" && tasksJson != null) if (clientType != "Official" && tasksJson != null)
{ {
var tasksPath = "resource/global/" + clientType + '/' + TasksApi; 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) // 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); // var tasksJsonClient = fromWeb ? WebService.RequestMaaApiWithCache(tasksPath) : WebService.RequestMaaApiWithCache(tasksPath);
await _maaApiService.RequestMaaApiWithCache(tasksPath); await _maaApiService.RequestMaaApiWithCache(tasksPath);
AsstProxy.AsstLoadResource(Directory.GetCurrentDirectory() + "\\cache\\resource\\global\\" + clientType);
} }
_asstProxy.LoadResource(true);
return activity; return activity;
} }