Skip to content

Commit

Permalink
Merge pull request #321 from Monitor221hz/output-fixes
Browse files Browse the repository at this point in the history
[Fix]: Engine rerun crash and other minor issues
  • Loading branch information
Monitor221hz authored Oct 18, 2024
2 parents d8227c6 + 6d5e634 commit 841e881
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 29 deletions.
31 changes: 2 additions & 29 deletions Pandora Behaviour Engine/Models/Patch/Engine/BehaviourEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ public class BehaviourEngine
{
public static readonly DirectoryInfo AssemblyDirectory = new FileInfo(System.Reflection.Assembly.GetEntryAssembly()!.Location).Directory!;
public IEngineConfiguration Configuration { get; private set; } = new SkyrimConfiguration();

private bool ClearOutputPath = false;
public bool IsExternalOutput = false;
private DirectoryInfo CurrentPath { get; } = new DirectoryInfo(Directory.GetCurrentDirectory());
public DirectoryInfo OutputPath { get; private set; } = new DirectoryInfo(Directory.GetCurrentDirectory());
public void SetOutputPath(DirectoryInfo outputPath)
{
ClearOutputPath = (outputPath != CurrentPath);
OutputPath = outputPath!;
IsExternalOutput = CurrentPath != OutputPath;
Configuration.Patcher.SetOutputPath(outputPath);
}

Expand All @@ -45,38 +44,12 @@ public async Task<bool> LaunchAsync(List<IModInfo> mods)

if (!OutputPath.Exists) OutputPath.Create();

if (ClearOutputPath)
{
ClearFolder(OutputPath);
}

var fnisESP = new FileInfo(Path.Combine(AssemblyDirectory.FullName, "FNIS.esp"));
if (fnisESP.Exists)
fnisESP.CopyTo(Path.Combine(OutputPath.FullName, "FNIS.esp"), true);

if (!await Configuration.Patcher.UpdateAsync()) { return false; }

return await Configuration.Patcher.RunAsync();
}

private void ClearFolder(DirectoryInfo dir)
{
foreach (var item in dir.GetFiles())
{
if (item.Name.Equals("ActiveMods.txt", StringComparison.InvariantCultureIgnoreCase))
continue;
else
item.Delete();
}
foreach (var item in dir.GetDirectories())
{
if (item.Name.Equals("Pandora_Engine", StringComparison.InvariantCultureIgnoreCase))
ClearFolder(item);
else
item.Delete(true);
}
}

public async Task PreloadAsync()
{
await Configuration.Patcher.PreloadAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ public async Task PreloadAsync()
public void SetOutputPath(DirectoryInfo directoryInfo)
{
exporter.ExportDirectory = directoryInfo;
if (!String.Equals(directoryInfo.FullName, BehaviourEngine.AssemblyDirectory.FullName, StringComparison.OrdinalIgnoreCase))
{
var FNISPlugin = new FileInfo(Path.Combine(BehaviourEngine.AssemblyDirectory.FullName, "FNIS.esp"));
var outputFNISPlugin = new FileInfo(Path.Combine(directoryInfo.FullName, "FNIS.esp"));

if (!outputFNISPlugin.Exists)
{
FNISPlugin.CopyTo(outputFNISPlugin.FullName);
}
}

nemesisAssembler.SetOutputPath(directoryInfo);
pandoraAssembler.SetOutputPath(directoryInfo);
}
Expand Down

0 comments on commit 841e881

Please sign in to comment.