Skip to content

Commit

Permalink
StrongInject usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Jan 1, 2025
1 parent feb706c commit 8143330
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 296 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<PackageVersion Include="Simple.Wpf.Terminal">
<Version>2.3.57</Version>
</PackageVersion>
<PackageVersion Include="StrongInject" Version="1.4.4" PrivateAssets="All" />
<PackageVersion Include="System.Collections.Immutable" Version="9.0.0" />
<PackageVersion Include="System.IO.Compression" Version="4.3.0" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
Expand Down
97 changes: 60 additions & 37 deletions Mutagen.Bethesda.Core/Archives/Archive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,57 @@
using Mutagen.Bethesda.Installs.DI;
using Mutagen.Bethesda.Plugins.Order;
using Mutagen.Bethesda.Plugins.Order.DI;
using StrongInject;
using Stream = System.IO.Stream;

namespace Mutagen.Bethesda.Archives;

[Register(typeof(IniPathLookup), typeof(IIniPathLookup))]
[Register(typeof(IniPathProvider), typeof(IIniPathProvider))]
[Register(typeof(GetArchiveIniListings), typeof(IGetArchiveIniListings))]
[Register(typeof(CachedArchiveListingDetailsProvider), typeof(IArchiveListingDetailsProvider))]
[Register(typeof(ArchiveExtensionProvider), typeof(IArchiveExtensionProvider))]
[Register(typeof(CheckArchiveApplicability), typeof(ICheckArchiveApplicability))]
[Register(typeof(GetApplicableArchivePaths))]
partial class ArchiveContainer : IContainer<GetApplicableArchivePaths>
{
[Instance] private readonly IFileSystem _fileSystem;
[Instance] private readonly IGameReleaseContext _gameReleaseContext;
[Instance] private readonly ILoadOrderListingsProvider _loadOrderListingsProvider;
[Instance] private readonly IDataDirectoryProvider _dataDirectoryProvider;
[Instance] private readonly IGameDirectoryLookup _gameDirectoryLookup = GameLocatorLookupCache.Instance;

public ArchiveContainer(
IFileSystem fileSystem,
IGameReleaseContext GameReleaseContext,
ILoadOrderListingsProvider LoadOrderListingsProvider,
IDataDirectoryProvider DataDirectoryProvider)
{
_fileSystem = fileSystem;
_gameReleaseContext = GameReleaseContext;
_loadOrderListingsProvider = LoadOrderListingsProvider;
_dataDirectoryProvider = DataDirectoryProvider;
}
}

[Register(typeof(IniPathLookup), typeof(IIniPathLookup))]
[Register(typeof(IniPathProvider), typeof(IIniPathProvider))]
[Register(typeof(GetArchiveIniListings))]
partial class GetArchiveIniListingsContainer : IContainer<GetArchiveIniListings>
{
[Instance] private readonly IFileSystem _fileSystem;
[Instance] private readonly IGameReleaseContext _gameReleaseContext;
[Instance] private readonly IGameDirectoryLookup _gameDirectoryLookup = GameLocatorLookupCache.Instance;

public GetArchiveIniListingsContainer(
IFileSystem? fileSystem,
GameRelease release)
{
_fileSystem = fileSystem.GetOrDefault();
_gameReleaseContext = new GameReleaseInjection(release);
}
}

public static class Archive
{
private static GetApplicableArchivePaths GetApplicableArchivePathsDi(
Expand All @@ -19,25 +66,13 @@ private static GetApplicableArchivePaths GetApplicableArchivePathsDi(
IEnumerable<ModKey>? modOrdering,
IFileSystem? fileSystem)
{
fileSystem ??= fileSystem.GetOrDefault();
var gameReleaseInjection = new GameReleaseInjection(release);
var ext = new ArchiveExtensionProvider(gameReleaseInjection);
var lo = new LoadOrderListingsInjection(
modOrdering.EmptyIfNull().Select(x => new LoadOrderListing(x, enabled: true)));
return new GetApplicableArchivePaths(
fileSystem,
new CheckArchiveApplicability(
ext),
new DataDirectoryInjection(dataFolderPath),
ext,
new CachedArchiveListingDetailsProvider(
lo,
new GetArchiveIniListings(
fileSystem,
new IniPathProvider(
new GameReleaseInjection(release),
new IniPathLookup(
GameLocatorLookupCache.Instance)))));
var cont = new ArchiveContainer(
fileSystem: fileSystem.GetOrDefault(),
new GameReleaseInjection(release),
new LoadOrderListingsInjection(
modOrdering.EmptyIfNull().Select(x => new LoadOrderListing(x, enabled: true))),
new DataDirectoryInjection(dataFolderPath));
return cont.Resolve().Value;
}

/// <summary>
Expand Down Expand Up @@ -182,12 +217,8 @@ public static bool IsApplicable(GameRelease release, ModKey modKey, FileName arc
/// <returns>Any Archive ordering info retrieved from the ini definition</returns>
public static IEnumerable<FileName> GetIniListings(GameRelease release, IFileSystem? fileSystem = null)
{
return new GetArchiveIniListings(
fileSystem.GetOrDefault(),
new IniPathProvider(
new GameReleaseInjection(release),
new IniPathLookup(
GameLocatorLookupCache.Instance)))
return new GetArchiveIniListingsContainer(fileSystem, release)
.Resolve().Value
.Get();
}

Expand All @@ -200,12 +231,8 @@ public static IEnumerable<FileName> GetIniListings(GameRelease release, IFileSys
/// <returns>Any Archive ordering info retrieved from the ini definition</returns>
public static IEnumerable<FileName> GetIniListings(GameRelease release, FilePath path, IFileSystem? fileSystem = null)
{
return new GetArchiveIniListings(
fileSystem.GetOrDefault(),
new IniPathProvider(
new GameReleaseInjection(release),
new IniPathLookup(
GameLocatorLookupCache.Instance)))
return new GetArchiveIniListingsContainer(fileSystem, release)
.Resolve().Value
.Get(path);
}

Expand All @@ -218,12 +245,8 @@ public static IEnumerable<FileName> GetIniListings(GameRelease release, FilePath
/// <returns>Any Archive ordering info retrieved from the ini definition</returns>
public static IEnumerable<FileName> GetIniListings(GameRelease release, Stream iniStream, IFileSystem? fileSystem = null)
{
return new GetArchiveIniListings(
fileSystem.GetOrDefault(),
new IniPathProvider(
new GameReleaseInjection(release),
new IniPathLookup(
GameLocatorLookupCache.Instance)))
return new GetArchiveIniListingsContainer(fileSystem, release)
.Resolve().Value
.Get(iniStream);
}
}
Loading

0 comments on commit 8143330

Please sign in to comment.