Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]: Engine rerun crash and other minor issues #321

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading