-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2175 from Nexus-Mods/feat/bg3-health-checks
BG3 Health Checks and improvements
- Loading branch information
Showing
18 changed files
with
377 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 20 additions & 10 deletions
30
src/Games/NexusMods.Games.Larian/BaldursGate3/Pipelines.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,61 @@ | ||
using System.Reactive; | ||
using System.Text; | ||
using BitFaster.Caching.Lru; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NexusMods.Abstractions.IO; | ||
using NexusMods.Abstractions.Resources; | ||
using NexusMods.Abstractions.Resources.Caching; | ||
using NexusMods.Abstractions.Resources.IO; | ||
using NexusMods.Games.Larian.BaldursGate3.Utils.LsxXmlParsing; | ||
using NexusMods.Games.Larian.BaldursGate3.Utils.PakParsing; | ||
using NexusMods.Hashing.xxHash64; | ||
using Polly; | ||
|
||
namespace NexusMods.Games.Larian.BaldursGate3; | ||
|
||
public static class Pipelines | ||
{ | ||
public const string MetadataPipelineKey = nameof(MetadataPipelineKey); | ||
|
||
public static IServiceCollection AddPipelines(this IServiceCollection serviceCollection) | ||
{ | ||
return serviceCollection.AddKeyedSingleton<IResourceLoader<Hash, LsxXmlFormat.MetaFileData>>( | ||
return serviceCollection.AddKeyedSingleton<IResourceLoader<Hash, Outcome<LsxXmlFormat.MetaFileData>>>( | ||
serviceKey: MetadataPipelineKey, | ||
implementationFactory: static (serviceProvider, _) => CreateMetadataPipeline( | ||
fileStore: serviceProvider.GetRequiredService<IFileStore>() | ||
) | ||
); | ||
} | ||
public static IResourceLoader<Hash, LsxXmlFormat.MetaFileData> GetMetadataPipeline(IServiceProvider serviceProvider) | ||
|
||
public static IResourceLoader<Hash, Outcome<LsxXmlFormat.MetaFileData>> GetMetadataPipeline(IServiceProvider serviceProvider) | ||
{ | ||
return serviceProvider.GetRequiredKeyedService<IResourceLoader<Hash, LsxXmlFormat.MetaFileData>>(serviceKey: MetadataPipelineKey); | ||
return serviceProvider.GetRequiredKeyedService<IResourceLoader<Hash, | ||
Outcome<LsxXmlFormat.MetaFileData>>>(serviceKey: MetadataPipelineKey); | ||
} | ||
|
||
private static IResourceLoader<Hash, LsxXmlFormat.MetaFileData> CreateMetadataPipeline(IFileStore fileStore) | ||
private static IResourceLoader<Hash, Outcome<LsxXmlFormat.MetaFileData>> CreateMetadataPipeline(IFileStore fileStore) | ||
{ | ||
// TODO: change pipeline to return C# 9 type unions instead of OneOf | ||
var pipeline = new FileStoreStreamLoader(fileStore) | ||
.ThenDo(Unit.Default, | ||
static (_, _, resource, _) => | ||
{ | ||
var metaFileData = PakFileParser.ParsePakMeta(resource.Data); | ||
return ValueTask.FromResult(resource.WithData(metaFileData)); | ||
try | ||
{ | ||
var metaFileData = PakFileParser.ParsePakMeta(resource.Data); | ||
return ValueTask.FromResult(resource.WithData(Outcome.FromResult(metaFileData))); | ||
} | ||
catch (InvalidDataException e) | ||
{ | ||
return ValueTask.FromResult(resource.WithData(Outcome.FromException<LsxXmlFormat.MetaFileData>(e))); | ||
} | ||
} | ||
) | ||
.UseCache( | ||
keyGenerator: static hash => hash, | ||
keyComparer: EqualityComparer<Hash>.Default, | ||
capacityPartition: new FavorWarmPartition(totalCapacity: 300) | ||
); | ||
|
||
return pipeline; | ||
} | ||
} |
Oops, something went wrong.