From 27ce55f3f79a42f50f93125ab81259ea10db44d3 Mon Sep 17 00:00:00 2001 From: Lightczx <1686188646@qq.com> Date: Mon, 8 Apr 2024 14:06:04 +0800 Subject: [PATCH] code style --- .../LaunchGameConfigurationFixDialog.xaml.cs | 4 +- .../ViewModel/Game/LaunchGameShared.cs | 18 ++++--- .../ViewModel/Game/LaunchGameViewModel.cs | 50 +++++++++---------- .../ViewModel/Game/LaunchGameViewModelSlim.cs | 4 +- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Snap.Hutao/Snap.Hutao/View/Dialog/LaunchGameConfigurationFixDialog.xaml.cs b/src/Snap.Hutao/Snap.Hutao/View/Dialog/LaunchGameConfigurationFixDialog.xaml.cs index fe1822a0..335d2b55 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Dialog/LaunchGameConfigurationFixDialog.xaml.cs +++ b/src/Snap.Hutao/Snap.Hutao/View/Dialog/LaunchGameConfigurationFixDialog.xaml.cs @@ -19,10 +19,10 @@ internal sealed partial class LaunchGameConfigurationFixDialog : ContentDialog taskContext = serviceProvider.GetRequiredService(); } - public async ValueTask> GetLaunchSchemeAsync() + public async ValueTask> GetLaunchSchemeAsync() { await taskContext.SwitchToMainThreadAsync(); ContentDialogResult result = await ShowAsync(); - return new(result == ContentDialogResult.Primary, SelectedScheme); + return new(result is ContentDialogResult.Primary, SelectedScheme); } } diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs index 61160078..16ca9bf8 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameShared.cs @@ -25,7 +25,7 @@ internal sealed partial class LaunchGameShared private readonly LaunchOptions launchOptions; private readonly ITaskContext taskContext; - public LaunchScheme? GetCurrentLaunchSchemeFromConfigFile(IGameServiceFacade gameService, IInfoBarService infoBarService) + public LaunchScheme? GetCurrentLaunchSchemeFromConfigFile() { ChannelOptions options = gameService.GetChannelOptions(); @@ -58,23 +58,27 @@ internal sealed partial class LaunchGameShared } [Command("HandleConfigurationFileNotFoundCommand")] - private async ValueTask HandleConfigurationFileNotFoundAsync() + private async Task HandleConfigurationFileNotFoundAsync() { - launchOptions.TryGetGameFileSystem(out GameFileSystem? gameFileSystem); - ArgumentNullException.ThrowIfNull(gameFileSystem); + if (!launchOptions.TryGetGameFileSystem(out GameFileSystem? gameFileSystem)) + { + return; + } + bool isOversea = LaunchScheme.ExecutableIsOversea(gameFileSystem.GameFileName); - string version = await File.ReadAllTextAsync(Path.Combine(gameFileSystem.GameDirectory, isOversea ? GameConstants.GenshinImpactData : GameConstants.YuanShenData, "Persistent", "ScriptVersion")).ConfigureAwait(false); + string dataFolder = isOversea ? GameConstants.GenshinImpactData : GameConstants.YuanShenData; + string persistentScriptVersionFile = Path.Combine(gameFileSystem.GameDirectory, dataFolder, "Persistent", "ScriptVersion"); + string version = await File.ReadAllTextAsync(persistentScriptVersionFile).ConfigureAwait(false); LaunchGameConfigurationFixDialog dialog = await contentDialogFactory.CreateInstanceAsync().ConfigureAwait(false); await taskContext.SwitchToMainThreadAsync(); dialog.KnownSchemes = KnownLaunchSchemes.Get().Where(scheme => scheme.IsOversea == isOversea); dialog.SelectedScheme = dialog.KnownSchemes.First(scheme => scheme.IsNotCompatOnly); - (bool isOk, LaunchScheme? launchScheme) = await dialog.GetLaunchSchemeAsync().ConfigureAwait(false); + (bool isOk, LaunchScheme launchScheme) = await dialog.GetLaunchSchemeAsync().ConfigureAwait(false); if (isOk) { - ArgumentNullException.ThrowIfNull(launchScheme); string gameBiz = launchScheme.IsOversea ? "hk4e_global" : "hk4e_cn"; string content = $""" [General] diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs index 00328f2a..e3795711 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModel.cs @@ -100,7 +100,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView { using (await EnterCriticalExecutionAsync().ConfigureAwait(false)) { - LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(gameService, infoBarService); + LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(); await taskContext.SwitchToMainThreadAsync(); await SetSelectedSchemeAsync(scheme).ConfigureAwait(true); @@ -181,6 +181,30 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView return ValueTask.FromResult(true); } + [Command("IdentifyMonitorsCommand")] + private static async Task IdentifyMonitorsAsync() + { + List windows = []; + + IReadOnlyList displayAreas = DisplayArea.FindAll(); + for (int i = 0; i < displayAreas.Count; i++) + { + windows.Add(new IdentifyMonitorWindow(displayAreas[i], i + 1)); + } + + foreach (IdentifyMonitorWindow window in windows) + { + window.Activate(); + } + + await Delay.FromSeconds(3).ConfigureAwait(true); + + foreach (IdentifyMonitorWindow window in windows) + { + window.Close(); + } + } + [Command("SetGamePathCommand")] private async Task SetGamePathAsync() { @@ -341,28 +365,4 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView }; } } - - [Command("IdentifyMonitorsCommand")] - private async Task IdentifyMonitorsAsync() - { - List windows = []; - - IReadOnlyList displayAreas = DisplayArea.FindAll(); - for (int i = 0; i < displayAreas.Count; i++) - { - windows.Add(new IdentifyMonitorWindow(displayAreas[i], i + 1)); - } - - foreach (IdentifyMonitorWindow window in windows) - { - window.Activate(); - } - - await Delay.FromSeconds(3).ConfigureAwait(true); - - foreach (IdentifyMonitorWindow window in windows) - { - window.Close(); - } - } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModelSlim.cs b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModelSlim.cs index ef2083ef..d37ddd7d 100644 --- a/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModelSlim.cs +++ b/src/Snap.Hutao/Snap.Hutao/ViewModel/Game/LaunchGameViewModelSlim.cs @@ -48,7 +48,7 @@ internal sealed partial class LaunchGameViewModelSlim : Abstraction.ViewModelSli /// protected override async Task OpenUIAsync() { - LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(gameService, infoBarService); + LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(); ObservableCollection accounts = gameService.GameAccountCollection; try @@ -77,7 +77,7 @@ internal sealed partial class LaunchGameViewModelSlim : Abstraction.ViewModelSli private async Task LaunchAsync() { IInfoBarService infoBarService = ServiceProvider.GetRequiredService(); - LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(gameService, infoBarService); + LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(); try {