Skip to content

Commit

Permalink
game path hot path
Browse files Browse the repository at this point in the history
  • Loading branch information
Lightczx committed Dec 9, 2024
1 parent 754b5b6 commit 52b9ac3
Showing 1 changed file with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,26 @@ internal sealed partial class GamePathService : IGamePathService

public async ValueTask<ValueResult<bool, string>> SilentGetGamePathAsync()
{
// Cannot find in setting
if (string.IsNullOrEmpty(launchOptions.GamePath))
// Found in setting
if (!string.IsNullOrEmpty(launchOptions.GamePath))
{
// Try to locate by unity log
if (await gameLocatorFactory.LocateAsync(GameLocationSource.UnityLog).ConfigureAwait(false) is (true, { } path1))
{
launchOptions.UpdateGamePath(path1);
return new(true, launchOptions.GamePath);
}
return new(true, launchOptions.GamePath);
}

// Try to locate by registry
if (await gameLocatorFactory.LocateAsync(GameLocationSource.Registry).ConfigureAwait(false) is (true, { } path2))
{
launchOptions.UpdateGamePath(path2);
return new(true, launchOptions.GamePath);
}
// Try to locate by unity log
if (await gameLocatorFactory.LocateAsync(GameLocationSource.UnityLog).ConfigureAwait(false) is (true, { } path1))
{
launchOptions.UpdateGamePath(path1);
return new(true, launchOptions.GamePath);
}

// If it's still null or empty
if (string.IsNullOrEmpty(launchOptions.GamePath))
{
return new(false, SH.ServiceGamePathLocateFailed);
}
// Try to locate by registry
if (await gameLocatorFactory.LocateAsync(GameLocationSource.Registry).ConfigureAwait(false) is (true, { } path2))
{
launchOptions.UpdateGamePath(path2);
return new(true, launchOptions.GamePath);
}

return new(true, launchOptions.GamePath);
return new(false, SH.ServiceGamePathLocateFailed);
}
}

0 comments on commit 52b9ac3

Please sign in to comment.