code style

This commit is contained in:
Lightczx
2024-04-08 14:06:04 +08:00
parent 311941bb89
commit 27ce55f3f7
4 changed files with 40 additions and 36 deletions

View File

@@ -19,10 +19,10 @@ internal sealed partial class LaunchGameConfigurationFixDialog : ContentDialog
taskContext = serviceProvider.GetRequiredService<ITaskContext>();
}
public async ValueTask<ValueResult<bool, LaunchScheme?>> GetLaunchSchemeAsync()
public async ValueTask<ValueResult<bool, LaunchScheme>> GetLaunchSchemeAsync()
{
await taskContext.SwitchToMainThreadAsync();
ContentDialogResult result = await ShowAsync();
return new(result == ContentDialogResult.Primary, SelectedScheme);
return new(result is ContentDialogResult.Primary, SelectedScheme);
}
}

View File

@@ -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<LaunchGameConfigurationFixDialog>().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]

View File

@@ -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<IdentifyMonitorWindow> windows = [];
IReadOnlyList<DisplayArea> 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<IdentifyMonitorWindow> windows = [];
IReadOnlyList<DisplayArea> 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();
}
}
}

View File

@@ -48,7 +48,7 @@ internal sealed partial class LaunchGameViewModelSlim : Abstraction.ViewModelSli
/// <inheritdoc/>
protected override async Task OpenUIAsync()
{
LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(gameService, infoBarService);
LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile();
ObservableCollection<GameAccount> accounts = gameService.GameAccountCollection;
try
@@ -77,7 +77,7 @@ internal sealed partial class LaunchGameViewModelSlim : Abstraction.ViewModelSli
private async Task LaunchAsync()
{
IInfoBarService infoBarService = ServiceProvider.GetRequiredService<IInfoBarService>();
LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile(gameService, infoBarService);
LaunchScheme? scheme = launchGameShared.GetCurrentLaunchSchemeFromConfigFile();
try
{