Skip to content

Commit

Permalink
PostRunProcessor
Browse files Browse the repository at this point in the history
  • Loading branch information
Noggog committed Jul 20, 2024
1 parent f1b2b9a commit 2b5acf1
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 10 deletions.
3 changes: 0 additions & 3 deletions Mutagen.Bethesda.Synthesis/Pipeline/SynthesisPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public SynthesisState<TModSetter, TModGetter> ToState<TModSetter, TModGetter>(Ru
.Import(new BinaryReadParameters()
{
StringsParam = stringReadParams,
FileSystem = _fileSystem
FileSystem = _fileSystem,
});

// Create or import patch mod
Expand Down
3 changes: 2 additions & 1 deletion Synthesis.Bethesda.Execution/Modules/MainModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
78 changes: 78 additions & 0 deletions Synthesis.Bethesda.Execution/Running/Runner/PostRunProcessor.cs
Original file line number Diff line number Diff line change
@@ -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<FilePath> Run(
IGroupRun groupRun,
ModPath path,
IReadOnlySet<ModKey> blackListMod)
{
var lo = new LoadOrder<IModFlagsGetter>(
_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;
}
}
20 changes: 15 additions & 5 deletions Synthesis.Bethesda.Execution/Running/Runner/RunAGroup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Mutagen.Bethesda.Plugins;
using Noggog;
using Serilog;
using Synthesis.Bethesda.Execution.Groups;
Expand All @@ -16,6 +17,7 @@ Task<bool> 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; }
Expand All @@ -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;
Expand All @@ -53,17 +57,23 @@ public async Task<bool> 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;
}
}

0 comments on commit 2b5acf1

Please sign in to comment.