diff --git a/Mutagen.Bethesda.Synthesis/Pipeline/SynthesisPipeline.cs b/Mutagen.Bethesda.Synthesis/Pipeline/SynthesisPipeline.cs index b717c0c7..ab4be624 100644 --- a/Mutagen.Bethesda.Synthesis/Pipeline/SynthesisPipeline.cs +++ b/Mutagen.Bethesda.Synthesis/Pipeline/SynthesisPipeline.cs @@ -10,13 +10,10 @@ using Synthesis.Bethesda.DTO; using System.IO.Abstractions; using System.Text.Json; -using Mutagen.Bethesda.Environments; using Mutagen.Bethesda.Environments.DI; -using Mutagen.Bethesda.Installs; using Mutagen.Bethesda.Installs.DI; using Mutagen.Bethesda.Synthesis.Versioning; using SynthesisBase = Synthesis.Bethesda; -using Mutagen.Bethesda.Plugins.Binary.Parameters; using Mutagen.Bethesda.Plugins.Binary.Streams; using Mutagen.Bethesda.Plugins.Exceptions; using Mutagen.Bethesda.Plugins.Implicit.DI; diff --git a/Mutagen.Bethesda.Synthesis/States/DI/PatcherStateFactory.cs b/Mutagen.Bethesda.Synthesis/States/DI/PatcherStateFactory.cs index 12d2e56a..3bd8caf2 100644 --- a/Mutagen.Bethesda.Synthesis/States/DI/PatcherStateFactory.cs +++ b/Mutagen.Bethesda.Synthesis/States/DI/PatcherStateFactory.cs @@ -91,7 +91,7 @@ public SynthesisState ToState(Ru .Import(new BinaryReadParameters() { StringsParam = stringReadParams, - FileSystem = _fileSystem + FileSystem = _fileSystem, }); // Create or import patch mod diff --git a/Synthesis.Bethesda.Execution/Modules/MainModule.cs b/Synthesis.Bethesda.Execution/Modules/MainModule.cs index f7ef0dac..9e9e8961 100644 --- a/Synthesis.Bethesda.Execution/Modules/MainModule.cs +++ b/Synthesis.Bethesda.Execution/Modules/MainModule.cs @@ -80,7 +80,8 @@ protected override void Load(ContainerBuilder builder) .InNamespacesOf( typeof(IExecuteRun)) .InstancePerMatchingLifetimeScope(LifetimeScopes.RunNickname) - .TypicalRegistrations(); + .TypicalRegistrations() + .AsSelf(); builder.RegisterAssemblyTypes(typeof(ISynthesisSubProcessRunner).Assembly) .InNamespacesOf( diff --git a/Synthesis.Bethesda.Execution/Running/Runner/PostRunProcessor.cs b/Synthesis.Bethesda.Execution/Running/Runner/PostRunProcessor.cs new file mode 100644 index 00000000..8944d454 --- /dev/null +++ b/Synthesis.Bethesda.Execution/Running/Runner/PostRunProcessor.cs @@ -0,0 +1,78 @@ +using System.IO.Abstractions; +using Mutagen.Bethesda.Environments.DI; +using Mutagen.Bethesda.Plugins; +using Mutagen.Bethesda.Plugins.Binary.Parameters; +using Mutagen.Bethesda.Plugins.Order; +using Mutagen.Bethesda.Plugins.Records; +using Noggog; +using Synthesis.Bethesda.Execution.Groups; +using Synthesis.Bethesda.Execution.Profile; + +namespace Synthesis.Bethesda.Execution.Running.Runner; + +public class PostRunProcessor +{ + private readonly IFileSystem _fileSystem; + private readonly IGameReleaseContext _gameReleaseContext; + private readonly IDataDirectoryProvider _dataDirectoryProvider; + private readonly ILoadOrderForRunProvider _loadOrderForRunProvider; + private readonly IProfileDirectories _profileDirectories; + + public PostRunProcessor( + IFileSystem fileSystem, + IGameReleaseContext gameReleaseContext, + IDataDirectoryProvider dataDirectoryProvider, + ILoadOrderForRunProvider loadOrderForRunProvider, + IProfileDirectories profileDirectories) + { + _fileSystem = fileSystem; + _gameReleaseContext = gameReleaseContext; + _dataDirectoryProvider = dataDirectoryProvider; + _loadOrderForRunProvider = loadOrderForRunProvider; + _profileDirectories = profileDirectories; + } + + public async Task Run( + IGroupRun groupRun, + ModPath path, + IReadOnlySet blackListMod) + { + var lo = new LoadOrder( + _loadOrderForRunProvider + .Get(path.ModKey, blackListMod) + .Select(listing => + { + var modPath = new ModPath(listing.ModKey, + _dataDirectoryProvider.Path.GetFile(listing.ModKey.FileName).Path); + if (!_fileSystem.File.Exists(modPath)) return null; + using var mod = ModInstantiator.ImportGetter(modPath, _gameReleaseContext.Release, + new BinaryReadParameters() + { + FileSystem = _fileSystem + }); + return new ModFlags(mod); + }) + .NotNull()); + + var mod = ModInstantiator.ImportGetter( + path, + _gameReleaseContext.Release, + new BinaryReadParameters() + { + LoadOrder = lo + }); + + var postProcessPath = new FilePath( + Path.Combine(_profileDirectories.WorkingDirectory, groupRun.ModKey.Name, $"PostProcess", groupRun.ModKey.FileName)); + + postProcessPath.Directory?.Create(_fileSystem); + + mod.WriteToBinary(postProcessPath, new BinaryWriteParameters() + { + FileSystem = _fileSystem, + LoadOrder = lo + }); + + return postProcessPath; + } +} \ No newline at end of file diff --git a/Synthesis.Bethesda.Execution/Running/Runner/RunAGroup.cs b/Synthesis.Bethesda.Execution/Running/Runner/RunAGroup.cs index 6f83a3f4..3d139c49 100644 --- a/Synthesis.Bethesda.Execution/Running/Runner/RunAGroup.cs +++ b/Synthesis.Bethesda.Execution/Running/Runner/RunAGroup.cs @@ -1,3 +1,4 @@ +using Mutagen.Bethesda.Plugins; using Noggog; using Serilog; using Synthesis.Bethesda.Execution.Groups; @@ -16,6 +17,7 @@ Task Run( public class RunAGroup : IRunAGroup { private readonly ILogger _logger; + private readonly PostRunProcessor _postRunProcessor; public IMoveFinalResults MoveFinalResults { get; } public IGroupRunPreparer GroupRunPreparer { get; } public IRunSomePatchers RunSomePatchers { get; } @@ -24,9 +26,11 @@ public RunAGroup( ILogger logger, IGroupRunPreparer groupRunPreparer, IRunSomePatchers runSomePatchers, - IMoveFinalResults moveFinalResults) + IMoveFinalResults moveFinalResults, + PostRunProcessor postRunProcessor) { _logger = logger; + _postRunProcessor = postRunProcessor; GroupRunPreparer = groupRunPreparer; RunSomePatchers = runSomePatchers; MoveFinalResults = moveFinalResults; @@ -53,17 +57,23 @@ public async Task Run( groupRun.BlacklistedMods, runParameters).ConfigureAwait(false); - var finalPath = await RunSomePatchers.Run( + var patcherRunOutputPath = await RunSomePatchers.Run( groupRun, groupRun.Patchers, cancellation, sourcePath, runParameters).ConfigureAwait(false); - if (finalPath == null) return false; - + if (patcherRunOutputPath == null) return false; + + cancellation.ThrowIfCancellationRequested(); + var postRunPath = await _postRunProcessor.Run( + groupRun, + new ModPath(groupRun.ModKey, patcherRunOutputPath.Value), + groupRun.BlacklistedMods); + cancellation.ThrowIfCancellationRequested(); - MoveFinalResults.Move(finalPath.Value, outputDir); + MoveFinalResults.Move(postRunPath, outputDir); return true; } } \ No newline at end of file