From e3bc5af9cb7c979c58ed87358c7afc5a6a4ade96 Mon Sep 17 00:00:00 2001 From: Scighost Date: Tue, 24 Dec 2024 11:36:08 +0800 Subject: [PATCH] use version poster as background --- src/Starward.Language/Lang.Designer.cs | 15 ++- src/Starward.Language/Lang.de-DE.resx | 34 +++--- src/Starward.Language/Lang.es-ES.resx | 34 +++--- src/Starward.Language/Lang.it-IT.resx | 34 +++--- src/Starward.Language/Lang.ja-JP.resx | 34 +++--- src/Starward.Language/Lang.ko-KR.resx | 34 +++--- src/Starward.Language/Lang.resx | 7 +- src/Starward.Language/Lang.ru-RU.resx | 34 +++--- src/Starward.Language/Lang.th-TH.resx | 34 +++--- src/Starward.Language/Lang.vi-VN.resx | 34 +++--- src/Starward.Language/Lang.zh-CN.resx | 5 +- .../Features/Background/AppBackground.xaml.cs | 2 +- .../Features/Background/BackgroundService.cs | 77 ++++++++++++- .../GameLauncher/GameBannerAndPost.xaml.cs | 2 + .../GameLauncherSettingDialog.xaml | 39 ++++++- .../GameLauncherSettingDialog.xaml.cs | 101 +++++++++++++++--- src/Starward/Frameworks/AppSetting.cs | 33 +++++- 17 files changed, 390 insertions(+), 163 deletions(-) diff --git a/src/Starward.Language/Lang.Designer.cs b/src/Starward.Language/Lang.Designer.cs index 5ed2bf34c..7a0d8e522 100644 --- a/src/Starward.Language/Lang.Designer.cs +++ b/src/Starward.Language/Lang.Designer.cs @@ -1548,11 +1548,11 @@ public static string GameLauncherPage_RemovableStorageDeviceNotConnected { } /// - /// 查找类似 Bastic Information 的本地化字符串。 + /// 查找类似 Basic Information 的本地化字符串。 /// - public static string GameLauncherSettingDialog_BasticInformation { + public static string GameLauncherSettingDialog_BasicInformation { get { - return ResourceManager.GetString("GameLauncherSettingDialog_BasticInformation", resourceCulture); + return ResourceManager.GetString("GameLauncherSettingDialog_BasicInformation", resourceCulture); } } @@ -1619,6 +1619,15 @@ public static string GameLauncherSettingDialog_StartupArguments { } } + /// + /// 查找类似 Use Version Poster 的本地化字符串。 + /// + public static string GameLauncherSettingDialog_UseVersionPoster { + get { + return ResourceManager.GetString("GameLauncherSettingDialog_UseVersionPoster", resourceCulture); + } + } + /// /// 查找类似 Diff Packages 的本地化字符串。 /// diff --git a/src/Starward.Language/Lang.de-DE.resx b/src/Starward.Language/Lang.de-DE.resx index 91c2e0ee5..1fb2286e0 100644 --- a/src/Starward.Language/Lang.de-DE.resx +++ b/src/Starward.Language/Lang.de-DE.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.es-ES.resx b/src/Starward.Language/Lang.es-ES.resx index c5537c567..3c447e024 100644 --- a/src/Starward.Language/Lang.es-ES.resx +++ b/src/Starward.Language/Lang.es-ES.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.it-IT.resx b/src/Starward.Language/Lang.it-IT.resx index a67337593..804462ba8 100644 --- a/src/Starward.Language/Lang.it-IT.resx +++ b/src/Starward.Language/Lang.it-IT.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.ja-JP.resx b/src/Starward.Language/Lang.ja-JP.resx index fc6aef517..84b959851 100644 --- a/src/Starward.Language/Lang.ja-JP.resx +++ b/src/Starward.Language/Lang.ja-JP.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.ko-KR.resx b/src/Starward.Language/Lang.ko-KR.resx index cc21c6840..a64111f8b 100644 --- a/src/Starward.Language/Lang.ko-KR.resx +++ b/src/Starward.Language/Lang.ko-KR.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.resx b/src/Starward.Language/Lang.resx index 653325d29..1b011af94 100644 --- a/src/Starward.Language/Lang.resx +++ b/src/Starward.Language/Lang.resx @@ -1624,8 +1624,8 @@ Do you accept the risk and continue to use it? Size - - Bastic Information + + Basic Information Startup Arguments @@ -1642,4 +1642,7 @@ Do you accept the risk and continue to use it? See more information about command line argument. + + Use Version Poster + \ No newline at end of file diff --git a/src/Starward.Language/Lang.ru-RU.resx b/src/Starward.Language/Lang.ru-RU.resx index 844d6c98f..b13f71b7b 100644 --- a/src/Starward.Language/Lang.ru-RU.resx +++ b/src/Starward.Language/Lang.ru-RU.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.th-TH.resx b/src/Starward.Language/Lang.th-TH.resx index d2acdb7f9..817b8d206 100644 --- a/src/Starward.Language/Lang.th-TH.resx +++ b/src/Starward.Language/Lang.th-TH.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.vi-VN.resx b/src/Starward.Language/Lang.vi-VN.resx index 51c7a3fdd..451f3ee75 100644 --- a/src/Starward.Language/Lang.vi-VN.resx +++ b/src/Starward.Language/Lang.vi-VN.resx @@ -59,46 +59,46 @@ : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> - - + + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + diff --git a/src/Starward.Language/Lang.zh-CN.resx b/src/Starward.Language/Lang.zh-CN.resx index bfdc1af02..e1e18d040 100644 --- a/src/Starward.Language/Lang.zh-CN.resx +++ b/src/Starward.Language/Lang.zh-CN.resx @@ -1624,7 +1624,7 @@ 大小 - + 基本信息 @@ -1642,4 +1642,7 @@ 查看有关命令行参数的更多信息 + + 使用版本海报 + \ No newline at end of file diff --git a/src/Starward/Features/Background/AppBackground.xaml.cs b/src/Starward/Features/Background/AppBackground.xaml.cs index e521a73ff..20582fdc5 100644 --- a/src/Starward/Features/Background/AppBackground.xaml.cs +++ b/src/Starward/Features/Background/AppBackground.xaml.cs @@ -271,7 +271,7 @@ private void StartMediaPlayer(string file) private void MediaPlayer_VideoFrameAvailable(MediaPlayer sender, object args) { - DispatcherQueue?.TryEnqueue(Microsoft.UI.Dispatching.DispatcherQueuePriority.High, () => + DispatcherQueue?.TryEnqueue(() => { try { diff --git a/src/Starward/Features/Background/BackgroundService.cs b/src/Starward/Features/Background/BackgroundService.cs index bd4350428..b18143539 100644 --- a/src/Starward/Features/Background/BackgroundService.cs +++ b/src/Starward/Features/Background/BackgroundService.cs @@ -92,6 +92,32 @@ private static bool TryGetCustomBgFilePath(GameId gameId, out string? path) + /// + /// 获取版本海报文件路径 + /// + /// + /// + /// + private static bool TryGetVersionPosterBgFilePath(GameId gameId, out string? path) + { + path = null; + if (gameId is null) + { + return false; + } + if (AppSetting.GetUseVersionPoster(gameId.GameBiz)) + { + path = Path.Join(AppSetting.UserDataFolder, "bg", AppSetting.GetVersionPoster(gameId.GameBiz)); + if (File.Exists(path)) + { + return true; + } + } + return false; + } + + + /// /// 文件是否是支持的视频格式,支持 mp4、mkv、flv、webm /// @@ -120,6 +146,10 @@ public static bool FileIsSupportedVideo(string? name) { return path; } + if (TryGetVersionPosterBgFilePath(gameId, out path)) + { + return path; + } path = GetBgFilePath(AppSetting.GetBg(gameId.GameBiz)); return File.Exists(path) ? path : null; } @@ -140,6 +170,42 @@ public static bool FileIsSupportedVideo(string? name) + /// + /// 更新版本海报 + /// + /// + /// + /// + private async Task GetVersionPosterAsync(GameId gameId, CancellationToken cancellationToken = default) + { + try + { + if (!AppSetting.GetUseVersionPoster(gameId.GameBiz)) + { + return null; + } + var info = await _hoYoPlayService.GetGameInfoAsync(gameId); + string url = info.Display.Background.Url; + string bg = Path.Combine(AppConfig.UserDataFolder, "bg"); + Directory.CreateDirectory(bg); + string name = Path.GetFileName(url); + string path = Path.Combine(bg, name); + if (!File.Exists(path)) + { + byte[] bytes = await _httpClient.GetByteArrayAsync(url, cancellationToken); + await File.WriteAllBytesAsync(path, bytes); + } + AppSetting.SetVersionPoster(gameId.GameBiz, name); + return path; + } + catch (Exception ex) + { + return null; + } + } + + + /// /// 获取背景图文件路径,最新的 /// @@ -150,14 +216,19 @@ public static bool FileIsSupportedVideo(string? name) { try { - var tokenSource = new CancellationTokenSource(10000); string? name, file; if (TryGetCustomBgFilePath(gameId, out file)) { return file; } - string? url = await GetBackgroundImageUrlAsync(gameId, tokenSource.Token); + file = await GetVersionPosterAsync(gameId, cancellationToken); + if (file is not null) + { + return file; + } + + string? url = await GetBackgroundImageUrlAsync(gameId, cancellationToken); if (string.IsNullOrWhiteSpace(url)) { _logger.LogWarning("Background of mihoyo api is null ({gameBiz})", gameId); @@ -167,7 +238,7 @@ public static bool FileIsSupportedVideo(string? name) file = GetBgFilePath(name); if (!File.Exists(file)) { - var bytes = await _httpClient.GetByteArrayAsync(url, tokenSource.Token); + var bytes = await _httpClient.GetByteArrayAsync(url, cancellationToken); Directory.CreateDirectory(Path.GetDirectoryName(file)!); await File.WriteAllBytesAsync(file, bytes); } diff --git a/src/Starward/Features/GameLauncher/GameBannerAndPost.xaml.cs b/src/Starward/Features/GameLauncher/GameBannerAndPost.xaml.cs index 75c4f9f68..b5c90b50a 100644 --- a/src/Starward/Features/GameLauncher/GameBannerAndPost.xaml.cs +++ b/src/Starward/Features/GameLauncher/GameBannerAndPost.xaml.cs @@ -84,8 +84,10 @@ private async void OnGameNoticeWindowClosed(object _, GameNoticeWindowClosedMess } + private async void OnGameAnnouncementSettingChanged(object _, GameAnnouncementSettingChangedMessage message) { + // 没有设置取消,网络不好时可能会造成状态异常,懒得写了 if (AppSetting.EnableBannerAndPost) { ShowBannerAndPost = true; diff --git a/src/Starward/Features/GameLauncher/GameLauncherSettingDialog.xaml b/src/Starward/Features/GameLauncher/GameLauncherSettingDialog.xaml index 2b79b8357..c20fd844d 100644 --- a/src/Starward/Features/GameLauncher/GameLauncherSettingDialog.xaml +++ b/src/Starward/Features/GameLauncher/GameLauncherSettingDialog.xaml @@ -124,7 +124,7 @@ - @@ -379,6 +379,42 @@ + + + + + + + +