feat: 添加自动安装更新包

fix #5290
fix #5134
This commit is contained in:
uye
2023-07-01 23:20:34 +08:00
parent 6dae845b73
commit 6843b50e17
9 changed files with 42 additions and 1 deletions

View File

@@ -137,6 +137,7 @@ namespace MaaWpfGui.Constants
public const string UpdatAutoCheck = "VersionUpdate.ScheduledUpdateCheck";
public const string UseAria2 = "VersionUpdate.UseAria2";
public const string AutoDownloadUpdatePackage = "VersionUpdate.AutoDownloadUpdatePackage";
public const string AutoInstallUpdatePackage = "VersionUpdate.AutoInstallUpdatePackage";
public const string PenguinId = "Penguin.Id";
public const string IsDrGrandet = "Penguin.IsDrGrandet";

View File

@@ -144,6 +144,7 @@
<system:String x:Key="StartupUpdateCheck">Startup Update Check</system:String>
<system:String x:Key="UpdatAutoCheck">Scheduled Update Check</system:String>
<system:String x:Key="UpdateAutoDownload">Auto Download Update</system:String>
<system:String x:Key="AutoInstallUpdatePackage">Auto Install Update</system:String>
<system:String x:Key="UpdateCheckStable">Stable Release</system:String>
<system:String x:Key="UpdateCheckBeta">Beta Release</system:String>
<system:String x:Key="UpdateCheckNightly">Nightly Release</system:String>

View File

@@ -144,6 +144,7 @@
<system:String x:Key="StartupUpdateCheck">起動時の更新チェック</system:String>
<system:String x:Key="UpdatAutoCheck">定期的な更新チェック</system:String>
<system:String x:Key="UpdateAutoDownload">自動アップデート</system:String>
<system:String x:Key="AutoInstallUpdatePackage">自動インストール更新</system:String>
<system:String x:Key="UpdateCheckStable">安定版</system:String>
<system:String x:Key="UpdateCheckBeta">ベータ版</system:String>
<system:String x:Key="UpdateCheckNightly">内部テスト版</system:String>

View File

@@ -144,6 +144,7 @@
<system:String x:Key="StartupUpdateCheck">시작시 업데이트 확인</system:String>
<system:String x:Key="UpdatAutoCheck">일정 시간마다 업데이트 확인</system:String>
<system:String x:Key="UpdateAutoDownload">자동으로 업데이트</system:String>
<system:String x:Key="AutoInstallUpdatePackage">자동 설치 업데이트 패키지</system:String>
<system:String x:Key="UpdateCheckStable">안정 버전</system:String>
<system:String x:Key="UpdateCheckBeta">베타 버전</system:String>
<system:String x:Key="UpdateCheckNightly">개발 버전</system:String>

View File

@@ -144,6 +144,7 @@
<system:String x:Key="StartupUpdateCheck">自动检查更新</system:String>
<system:String x:Key="UpdatAutoCheck">定时检查更新</system:String>
<system:String x:Key="UpdateAutoDownload">自动下载更新包</system:String>
<system:String x:Key="AutoInstallUpdatePackage">自动安装更新包</system:String>
<system:String x:Key="UpdateCheckStable">稳定版</system:String>
<system:String x:Key="UpdateCheckBeta">公测版</system:String>
<system:String x:Key="UpdateCheckNightly">内测版</system:String>

View File

@@ -144,6 +144,7 @@
<system:String x:Key="StartupUpdateCheck">啟動時檢查更新</system:String>
<system:String x:Key="UpdatAutoCheck">定時檢查更新</system:String>
<system:String x:Key="UpdateAutoDownload">自動下載更新包</system:String>
<system:String x:Key="AutoInstallUpdatePackage">自動安裝更新包</system:String>
<system:String x:Key="UpdateCheckStable">穩定版</system:String>
<system:String x:Key="UpdateCheckBeta">公測版</system:String>
<system:String x:Key="UpdateCheckNightly">內測版</system:String>

View File

@@ -1984,7 +1984,7 @@ namespace MaaWpfGui.ViewModels.UI
}
}
private bool _updateAutoCheck = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UpdatAutoCheck, bool.TrueString));
private bool _updateAutoCheck = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.UpdatAutoCheck, bool.FalseString));
/// <summary>
/// Gets or sets a value indicating whether to check update.
@@ -2043,6 +2043,21 @@ namespace MaaWpfGui.ViewModels.UI
}
}
private bool _autoInstallUpdatePackage = Convert.ToBoolean(ConfigurationHelper.GetValue(ConfigurationKeys.AutoInstallUpdatePackage, bool.FalseString));
/// <summary>
/// Gets or sets a value indicating whether to auto install update package.
/// </summary>
public bool AutoInstallUpdatePackage
{
get => _autoInstallUpdatePackage;
set
{
SetAndNotify(ref _autoInstallUpdatePackage, value);
ConfigurationHelper.SetValue(ConfigurationKeys.AutoInstallUpdatePackage, value.ToString());
}
}
/// <summary>
/// Updates manually.
/// </summary>

View File

@@ -20,6 +20,7 @@ using System.IO.Compression;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
@@ -556,6 +557,18 @@ namespace MaaWpfGui.ViewModels.UI
public void AskToRestart()
{
if (Instances.SettingsViewModel.AutoInstallUpdatePackage)
{
while (!(Instances.TaskQueueViewModel.Idle && Instances.CopilotViewModel.Idle))
{
Thread.Sleep(60000);
}
Application.Current.Shutdown();
Bootstrapper.RestartApplication();
return;
}
var result = MessageBoxHelper.Show(
LocalizationHelper.GetString("NewVersionDownloadCompletedDesc"),
LocalizationHelper.GetString("NewVersionDownloadCompletedTitle"),

View File

@@ -48,6 +48,13 @@
Content="{DynamicResource UpdateAutoDownload}"
IsChecked="{Binding AutoDownloadUpdatePackage}"
IsEnabled="{Binding UpdateCheck}" />
<CheckBox
Margin="10"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content="{DynamicResource AutoInstallUpdatePackage}"
IsChecked="{Binding AutoInstallUpdatePackage}"
IsEnabled="{Binding UpdateCheck}" />
<StackPanel VerticalAlignment="Center" Orientation="Horizontal">
<controls:TextBlock
Margin="10,10,0,10"