chore: 提取 ResourceReload 方法

This commit is contained in:
uye
2025-03-07 23:26:31 +08:00
parent c0ff1ddbe9
commit bfd0ce283e
5 changed files with 26 additions and 27 deletions

View File

@@ -1612,14 +1612,7 @@ namespace MaaWpfGui.Main
return;
}
var ret = await ResourceUpdater.CheckAndDownloadResourceUpdate();
if (ret == VersionUpdateViewModel.CheckUpdateRetT.OnlyGameResourceUpdated)
{
Instances.AsstProxy.LoadResource();
DataHelper.Reload();
SettingsViewModel.VersionUpdateSettings.ResourceInfoUpdate();
ToastNotification.ShowDirect(LocalizationHelper.GetString("GameResourceUpdated"));
}
await ResourceUpdater.ResourceUpdateAndReloadAsync();
});
break;

View File

@@ -291,6 +291,28 @@ namespace MaaWpfGui.Models
return ret;
}
public static async Task ResourceUpdateAndReloadAsync()
{
if (SettingsViewModel.VersionUpdateSettings.IsCheckingForUpdates)
{
return;
}
var ret = await CheckAndDownloadResourceUpdate();
if (ret == CheckUpdateRetT.OnlyGameResourceUpdated)
{
ResourceReload();
}
}
public static void ResourceReload()
{
Instances.AsstProxy.LoadResource();
DataHelper.Reload();
SettingsViewModel.VersionUpdateSettings.ResourceInfoUpdate();
ToastNotification.ShowDirect(LocalizationHelper.GetString("GameResourceUpdated"));
}
private static async Task<bool> DownloadFullPackageAsync(string url, string saveTo)
{
using var response = await Instances.HttpService.GetAsync(new Uri(url));

View File

@@ -474,13 +474,7 @@ namespace MaaWpfGui.ViewModels.UI
_ = Instances.VersionUpdateViewModel.AskToRestart();
}
if (await ResourceUpdater.CheckAndDownloadResourceUpdate() == VersionUpdateViewModel.CheckUpdateRetT.OnlyGameResourceUpdated)
{
Instances.AsstProxy.LoadResource();
DataHelper.Reload();
SettingsViewModel.VersionUpdateSettings.ResourceInfoUpdate();
ToastNotification.ShowDirect(LocalizationHelper.GetString("GameResourceUpdated"));
}
await ResourceUpdater.ResourceUpdateAndReloadAsync();
_isCheckingForUpdates = false;
});

View File

@@ -488,14 +488,7 @@ public class VersionUpdateViewModel : Screen
_ = AskToRestart();
}
var ret2 = await ResourceUpdater.CheckAndDownloadResourceUpdate();
if (ret2 == CheckUpdateRetT.OnlyGameResourceUpdated)
{
Instances.AsstProxy.LoadResource();
DataHelper.Reload();
SettingsViewModel.VersionUpdateSettings.ResourceInfoUpdate();
ToastNotification.ShowDirect(LocalizationHelper.GetString("GameResourceUpdated"));
}
await ResourceUpdater.ResourceUpdateAndReloadAsync();
}
else
{

View File

@@ -462,10 +462,7 @@ public class VersionUpdateSettingsUserControlModel : PropertyChangedBase
if (success)
{
Instances.AsstProxy.LoadResource();
DataHelper.Reload();
SettingsViewModel.VersionUpdateSettings.ResourceInfoUpdate();
ToastNotification.ShowDirect(LocalizationHelper.GetString("GameResourceUpdated"));
ResourceUpdater.ResourceReload();
}
IsCheckingForUpdates = false;