Skip to content

Commit

Permalink
Added NVSEInstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
MistaOmega committed Oct 4, 2024
1 parent 70b8d8f commit 063882a
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using NexusMods.Games.FOMOD;
using NexusMods.Games.Generic.Installers;
using NexusMods.Games.Obsidian.FalloutNewVegas.Emitters;
using NexusMods.Games.Obsidian.FalloutNewVegas.Installers;
using NexusMods.Paths;
using NexusMods.Paths.Utilities;

Expand Down Expand Up @@ -80,6 +81,7 @@ public override GamePath GetPrimaryFile(GameStore store)

public override ILibraryItemInstaller[] LibraryItemInstallers =>
[
new NVSEInstaller(_serviceProvider),
new GenericPatternMatchInstaller(_serviceProvider)
{
InstallFolderTargets =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Library.Installers;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
using NexusMods.MnemonicDB.Abstractions;
using NexusMods.Paths;
using NexusMods.Paths.Trees;
using NexusMods.Paths.Trees.Traits;

namespace NexusMods.Games.Obsidian.FalloutNewVegas.Installers;

public class NVSEInstaller(IServiceProvider serviceProvider) : ALibraryArchiveInstaller(serviceProvider, serviceProvider.GetRequiredService<ILogger<NVSEInstaller>>())
{
public override ValueTask<InstallerResult> ExecuteAsync(
LibraryArchive.ReadOnly libraryArchive,
LoadoutItemGroup.New loadoutGroup,
ITransaction transaction,
Loadout.ReadOnly loadout,
CancellationToken cancellationToken)
{
var tree = libraryArchive.GetTree();
var keys = new[] { "nvse_1_4.dll", "nvse_editor_1_4.dll", "nvse_loader.exe", "nvse_steam_loader.dll" };


List<LoadoutFile.New> results = [];
foreach (var fileNode in tree.EnumerateFilesBfs())
{
var relativePath = new RelativePath(fileNode.Value.Item.Path.Name);
if (!keys.Contains(relativePath.Name.ToString()))
{
continue;
};

var loadoutFile = new LoadoutFile.New(transaction, out var id)
{
LoadoutItemWithTargetPath = new LoadoutItemWithTargetPath.New(transaction, id)
{
TargetPath = (loadout.Id, LocationId.Game, relativePath),
LoadoutItem = new LoadoutItem.New(transaction, id)
{
Name = relativePath.Name,
LoadoutId = loadout.Id,
ParentId = loadoutGroup.Id,
},
},
Hash = fileNode.Value.Item.LibraryFile.Value.Hash,
Size = fileNode.Value.Item.LibraryFile.Value.Size,
};
results.Add(loadoutFile);
}

return results.Count > 0
? ValueTask.FromResult<InstallerResult>(new Success())
: ValueTask.FromResult<InstallerResult>(new NotSupported());
}
}

0 comments on commit 063882a

Please sign in to comment.