feat: 软件更新中添加手动更新资源版本 (#10877)

This commit is contained in:
uye
2024-10-21 01:02:03 +08:00
committed by GitHub
parent beabba92e3
commit 5e5b18edea
9 changed files with 146 additions and 11 deletions

View File

@@ -1542,7 +1542,6 @@ namespace MaaWpfGui.Main
case "UnsupportedLevel":
Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("UnsupportedLevel") + subTaskDetails!["level"], UiLogColor.Error);
Instances.CopilotViewModel.AddLog(LocalizationHelper.GetString("ResourceUpdatePaused"));
break;
case "CustomInfrastRoomGroupsMatch":

View File

@@ -16,6 +16,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
@@ -424,5 +425,105 @@ namespace MaaWpfGui.Models
}
});
}
// 额外加一个从 github 下载完整包的方法,老的版本先留着,看看之后增量还能不能整了
public static async Task<bool> UpdateFromGithubAsync()
{
await DownloadFullPackageAsync("https://github.com/MaaAssistantArknights/MaaResource/archive/refs/heads/main.zip", "MaaResource.zip").ConfigureAwait(false);
// 解压到 MaaResource 文件夹
try
{
if (Directory.Exists("MaaResource"))
{
Directory.Delete("MaaResource", true);
}
ZipFile.ExtractToDirectory("MaaResource.zip", "MaaResource");
}
catch (Exception e)
{
_logger.Error("Failed to extract MaaResource.zip: " + e.Message);
return false;
}
// 把 \MaaResource-main 中的 cache 和 resource 文件夹复制到当前目录
try
{
string sourcePath = Path.Combine("MaaResource", "MaaResource-main");
string[] foldersToCopy = { "cache", "resource" };
foreach (var folder in foldersToCopy)
{
string sourceFolder = Path.Combine(sourcePath, folder);
string destinationFolder = Path.Combine(Directory.GetCurrentDirectory(), folder);
DirectoryMerge(sourceFolder, destinationFolder);
}
}
catch (Exception e)
{
_logger.Error("Failed to copy folders: " + e.Message);
return false;
}
// 删除 MaaResource 文件夹 和 MaaResource.zip
try
{
Directory.Delete("MaaResource", true);
File.Delete("MaaResource.zip");
}
catch (Exception e)
{
_logger.Error("Failed to delete MaaResource: " + e.Message);
}
return true;
}
private static async Task<bool> DownloadFullPackageAsync(string url, string saveTo)
{
using var response = await Instances.HttpService.GetAsync(
new Uri(url),
httpCompletionOption: HttpCompletionOption.ResponseHeadersRead);
if (response is not
{
StatusCode: System.Net.HttpStatusCode.OK
})
{
return false;
}
return await HttpResponseHelper.SaveResponseToFileAsync(response, saveTo);
}
private static void DirectoryMerge(string sourceDirName, string destDirName)
{
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
DirectoryInfo[] dirs = dir.GetDirectories();
if (!dir.Exists)
{
throw new DirectoryNotFoundException("Source directory does not exist or could not be found: " + sourceDirName);
}
if (!Directory.Exists(destDirName))
{
Directory.CreateDirectory(destDirName);
}
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string tempPath = Path.Combine(destDirName, file.Name);
file.CopyTo(tempPath, true); // 覆盖现有文件
}
foreach (DirectoryInfo subdir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryMerge(subdir.FullName, tempPath);
}
}
}
}

View File

@@ -226,6 +226,7 @@ You can cancel this popup by clicking the Settings - About Us - Issue Reporting
<system:String x:Key="DownloadWithAria2">Download via aria2</system:String>
<system:String x:Key="UpdateCheckNow">Check update</system:String>
<system:String x:Key="ShowChangelog">Changelog</system:String>
<system:String x:Key="ResourceUpdate">Resource update</system:String>
<system:String x:Key="NewVersionFoundTitle">New Version Found</system:String>
<system:String x:Key="NewVersionFoundDescDownloading">Downloading in the background……</system:String>
<system:String x:Key="NewVersionFoundDescId" xml:space="preserve">Version: </system:String>
@@ -792,8 +793,7 @@ The video aspect ratio needs to be 16:9 without interference factors such as bla
<system:String x:Key="BattleFormation">Start formation</system:String>
<system:String x:Key="BattleFormationSelected" xml:space="preserve">Selected: </system:String>
<system:String x:Key="CurrentSteps">Step: {0} {1}</system:String>
<system:String x:Key="UnsupportedLevel">Unsupported stage, please check the level name or go to「Settings - Update - Check update」and try updating the resource version!</system:String>
<system:String x:Key="ResourceUpdatePaused">Due to server resource constraints, resource version updates are temporarily suspended. Please manually import the level file or wait for a new version release</system:String>
<system:String x:Key="UnsupportedLevel">Unsupported stage, please check the level name or go to「Settings - Update - Resource update」and try updating the resource version!</system:String>
<system:String x:Key="RecruitTagsDetected" xml:space="preserve">Identification results: </system:String>
<system:String x:Key="ConnectFailed">Connection Failed</system:String>
<system:String x:Key="TryToReconnectByAdb">Attempting to reconnect</system:String>

View File

@@ -226,6 +226,7 @@
<system:String x:Key="DownloadWithAria2">aria2を使う</system:String>
<system:String x:Key="UpdateCheckNow">アップデートを確認する</system:String>
<system:String x:Key="ShowChangelog">変更履歴</system:String>
<system:String x:Key="ResourceUpdate">リソース更新</system:String>
<system:String x:Key="NewVersionFoundTitle">新しいバージョンが見つかりました</system:String>
<system:String x:Key="NewVersionFoundDescDownloading">バックグラウンドでダウンロードを行います……</system:String>
<system:String x:Key="NewVersionFoundDescId" xml:space="preserve">バージョン: </system:String>
@@ -795,8 +796,7 @@ C:\\leidian\\LDPlayer9
<system:String x:Key="BattleFormation">編成開始</system:String>
<system:String x:Key="BattleFormationSelected" xml:space="preserve">オペレーターを選択: </system:String>
<system:String x:Key="CurrentSteps">現在の手順: {0} {1}</system:String>
<system:String x:Key="UnsupportedLevel">サポートされていないステージです。ステージ名を確認するか、設定に移動してソフトウェア更新をチェックし、リソースバージョンを更新してみてください!</system:String>
<system:String x:Key="ResourceUpdatePaused">サーバーリソースの制約により、リソースバージョンの更新は一時的に停止しています。レベルファイルを手動でインポートするか、新しいバージョンのリリースをお待ちください</system:String>
<system:String x:Key="UnsupportedLevel">サポートされていないステージです。ステージ名を確認するか、設定 - ソフトウェア更新 - リソース更新」に移動してリソースバージョンを更新してみてください!</system:String>
<system:String x:Key="RecruitTagsDetected" xml:space="preserve">認識結果: </system:String>
<system:String x:Key="ConnectFailed">接続失敗</system:String>
<system:String x:Key="TryToReconnectByAdb">再接続を試みています</system:String>

View File

@@ -226,6 +226,7 @@
<system:String x:Key="DownloadWithAria2">aria2로 다운로드</system:String>
<system:String x:Key="UpdateCheckNow">지금 업데이트</system:String>
<system:String x:Key="ShowChangelog">변경 내역</system:String>
<system:String x:Key="ResourceUpdate">리소스 업데이트</system:String>
<system:String x:Key="NewVersionFoundTitle">새로운 버전 확인</system:String>
<system:String x:Key="NewVersionFoundDescDownloading">백그라운드에서 다운로드 중……</system:String>
<system:String x:Key="NewVersionFoundDescId" xml:space="preserve">버전: </system:String>
@@ -795,8 +796,7 @@ C:\\leidian\\LDPlayer9
<system:String x:Key="BattleFormation">편성 시작</system:String>
<system:String x:Key="BattleFormationSelected" xml:space="preserve">오퍼레이터를 선택: </system:String>
<system:String x:Key="CurrentSteps">현재 단계: {0} {1}</system:String>
<system:String x:Key="UnsupportedLevel">지원되지 않는 스테이지입니다. 스테이지 이름을 확인하거나 설정으로 이동하여 소프트웨어 업데이트를 확인하고 리소스 버전을 업데이트해보세요!</system:String>
<system:String x:Key="ResourceUpdatePaused">서버 리소스 제약으로 인해 리소스 버전 업데이트가 일시 중지되었습니다. 리소스 파일을 수동으로 설치하거나 새 버전 출시를 기다려 주세요</system:String>
<system:String x:Key="UnsupportedLevel">지원되지 않는 스테이지입니다. 스테이지 이름을 확인하거나 설정 - 소프트웨어 업데이트 - 리소스 업데이트」로 이동하여 리소스 버전을 업데이트해 보세요!</system:String>
<system:String x:Key="RecruitTagsDetected" xml:space="preserve">인식 결과: </system:String>
<system:String x:Key="ConnectFailed">연결 실패</system:String>
<system:String x:Key="TryToReconnectByAdb">재접속을 시도하고 있습니다</system:String>

View File

@@ -226,6 +226,7 @@
<system:String x:Key="DownloadWithAria2">使用 aria2 进行下载</system:String>
<system:String x:Key="UpdateCheckNow">检查更新</system:String>
<system:String x:Key="ShowChangelog">更新日志</system:String>
<system:String x:Key="ResourceUpdate">资源更新</system:String>
<system:String x:Key="NewVersionFoundTitle">检测到新版本</system:String>
<system:String x:Key="NewVersionFoundDescDownloading">正在后台下载……</system:String>
<system:String x:Key="NewVersionFoundDescId" xml:space="preserve">版本号: </system:String>
@@ -794,8 +795,7 @@ C:\\leidian\\LDPlayer9。\n
<system:String x:Key="BattleFormation">开始编队</system:String>
<system:String x:Key="BattleFormationSelected" xml:space="preserve">选择干员: </system:String>
<system:String x:Key="CurrentSteps">当前步骤: {0} {1}</system:String>
<system:String x:Key="UnsupportedLevel">不支持的关卡,请检查关卡名或前往「设置 - 软件更新 - 检查更新」尝试更新资源版本!</system:String>
<system:String x:Key="ResourceUpdatePaused">由于服务器资源紧张,暂时停止提供资源版本更新。请手动导入关卡文件或等待新的版本发布</system:String>
<system:String x:Key="UnsupportedLevel">不支持的关卡,请检查关卡名或前往「设置 - 软件更新 - 资源更新」尝试更新资源版本!</system:String>
<system:String x:Key="RecruitTagsDetected" xml:space="preserve">识别结果: </system:String>
<system:String x:Key="ConnectFailed">连接失败</system:String>
<system:String x:Key="TryToReconnectByAdb">正在尝试重连</system:String>

View File

@@ -226,6 +226,7 @@
<system:String x:Key="DownloadWithAria2">使用 aria2 進行下載</system:String>
<system:String x:Key="UpdateCheckNow">檢查更新</system:String>
<system:String x:Key="ShowChangelog">更新日誌</system:String>
<system:String x:Key="ResourceUpdate">資源更新</system:String>
<system:String x:Key="NewVersionFoundTitle">檢測到新版本</system:String>
<system:String x:Key="NewVersionFoundDescDownloading">正在後臺下載……</system:String>
<system:String x:Key="NewVersionFoundDescId" xml:space="preserve">版本號: </system:String>
@@ -794,8 +795,7 @@ C:\\leidian\\LDPlayer9。\n
<system:String x:Key="BattleFormation">開始編隊</system:String>
<system:String x:Key="BattleFormationSelected" xml:space="preserve">選擇幹員: </system:String>
<system:String x:Key="CurrentSteps">當前步驟: {0} {1}</system:String>
<system:String x:Key="UnsupportedLevel">不支援的關卡,請檢查關卡名稱或前往「設置 - 軟體更新 - 檢查更新」,嘗試更新資源版本!</system:String>
<system:String x:Key="ResourceUpdatePaused">由於伺服器資源緊張,暫時停止提供資源版本更新。請手動導入關卡文件或等待新的版本發佈</system:String>
<system:String x:Key="UnsupportedLevel">不支援的關卡,請檢查關卡名稱或前往「設置 - 軟體更新 - 資源更新」,嘗試更新資源版本!</system:String>
<system:String x:Key="RecruitTagsDetected" xml:space="preserve">辨識結果: </system:String>
<system:String x:Key="ConnectFailed">連接失敗</system:String>
<system:String x:Key="TryToReconnectByAdb">正在嘗試重连</system:String>

View File

@@ -3962,6 +3962,34 @@ namespace MaaWpfGui.ViewModels.UI
}
}
public async Task ManualUpdateResource()
{
IsCheckingForUpdates = true;
if (await ResourceUpdater.UpdateFromGithubAsync())
{
if (Instances.SettingsViewModel.AutoInstallUpdatePackage)
{
await Bootstrapper.RestartAfterIdleAsync();
}
else
{
var result = MessageBoxHelper.Show(
LocalizationHelper.GetString("GameResourceUpdated"),
LocalizationHelper.GetString("Tip"),
MessageBoxButton.OKCancel,
MessageBoxImage.Question,
ok: LocalizationHelper.GetString("Ok"),
cancel: LocalizationHelper.GetString("ManualRestart"));
if (result == MessageBoxResult.OK)
{
Bootstrapper.ShutdownAndRestartWithoutArgs();
}
}
}
IsCheckingForUpdates = false;
}
// UI 绑定的方法
// ReSharper disable once UnusedMember.Global
public void ShowChangelog()

View File

@@ -82,6 +82,7 @@
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<ComboBox
@@ -331,6 +332,12 @@
Content="{DynamicResource ShowChangelog}"
IsEnabled="{c:Binding !IsCheckingForUpdates}" />
</StackPanel>
<Button
Grid.Row="4"
Margin="5"
Command="{s:Action ManualUpdateResource}"
Content="{DynamicResource ResourceUpdate}"
IsEnabled="{c:Binding !IsCheckingForUpdates}" />
</Grid>
</StackPanel>
</Grid>