fix game account attach uid crash

This commit is contained in:
DismissedLight
2024-07-06 10:09:07 +08:00
parent d3fbf35f34
commit 1cd6aad518
7 changed files with 23 additions and 15 deletions

View File

@@ -88,10 +88,13 @@ internal sealed partial class GameAccountService : IGameAccountService
return RegistryInterop.Set(account);
}
public void AttachGameAccountToUid(GameAccount gameAccount, string uid)
public async ValueTask AttachGameAccountToUidAsync(GameAccount gameAccount, string uid)
{
gameAccount.UpdateAttachUid(uid);
await taskContext.SwitchToBackgroundAsync();
gameDbService.UpdateGameAccount(gameAccount);
await taskContext.SwitchToMainThreadAsync();
gameAccount.UpdateAttachUid(uid);
}
public async ValueTask ModifyGameAccountAsync(GameAccount gameAccount)

View File

@@ -11,7 +11,7 @@ internal interface IGameAccountService
{
ObservableReorderableDbCollection<GameAccount> GameAccountCollection { get; }
void AttachGameAccountToUid(GameAccount gameAccount, string uid);
ValueTask AttachGameAccountToUidAsync(GameAccount gameAccount, string uid);
GameAccount? DetectCurrentGameAccount(SchemeType schemeType);

View File

@@ -27,15 +27,19 @@ internal sealed partial class GameConfigurationFileService : IGameConfigurationF
string serverCacheFolder = runtimeOptions.GetDataFolderServerCacheFolder();
string source = Path.Combine(serverCacheFolder, ConfigurationFileName);
if (File.Exists(source))
if (!File.Exists(source))
{
string? directory = Path.GetDirectoryName(destination);
if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory))
{
return;
}
File.Copy(source, destination, true);
return;
}
// If target directory does not exist, do not copy the file
// This often means user has moved the game folder away.
string? directory = Path.GetDirectoryName(destination);
if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory))
{
return;
}
File.Copy(source, destination, true);
}
}

View File

@@ -54,9 +54,9 @@ internal sealed partial class GameServiceFacade : IGameServiceFacade
}
/// <inheritdoc/>
public void AttachGameAccountToUid(GameAccount gameAccount, string uid)
public ValueTask AttachGameAccountToUidAsync(GameAccount gameAccount, string uid)
{
gameAccountService.AttachGameAccountToUid(gameAccount, uid);
return gameAccountService.AttachGameAccountToUidAsync(gameAccount, uid);
}
/// <inheritdoc/>

View File

@@ -25,7 +25,7 @@ internal interface IGameServiceFacade
/// </summary>
/// <param name="gameAccount">游戏内账号</param>
/// <param name="uid">uid</param>
void AttachGameAccountToUid(GameAccount gameAccount, string uid);
ValueTask AttachGameAccountToUidAsync(GameAccount gameAccount, string uid);
ValueTask<GameAccount?> DetectGameAccountAsync(SchemeType scheme);

View File

@@ -60,6 +60,7 @@
Command="{Binding NavigateCommand}"
Content="{StaticResource FontIconContentSetting}"
FontFamily="{StaticResource SymbolThemeFontFamily}"
Style="{ThemeResource ButtonRevealStyle}"
ToolTipService.ToolTip="{shuxm:ResourceString Name=ViewPageHomeLaunchGameSettingAction}"/>
<StackPanel
Grid.Row="2"

View File

@@ -249,7 +249,7 @@ internal sealed partial class LaunchGameViewModel : Abstraction.ViewModel, IView
if (await userService.GetCurrentUidAsync().ConfigureAwait(false) is { } uid)
{
gameService.AttachGameAccountToUid(gameAccount, uid);
await gameService.AttachGameAccountToUidAsync(gameAccount, uid).ConfigureAwait(false);
}
else
{