Skip to content
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
1 change: 1 addition & 0 deletions src/Core/API/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ public class ModInstallConfig : ModInstaller.IConfig
public IEnumerable<string> DirsAtRoot { get; set; } = Array.Empty<string>();
public IEnumerable<string> ExcludedFromInstall { get; set; } = Array.Empty<string>();
public IEnumerable<string> ExcludedFromConfig { get; set; } = Array.Empty<string>();
public bool GenerateModDetails { get; set; } = true;
}
12 changes: 11 additions & 1 deletion src/Core/Mods/Installation/Installers/ModInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Core.Games;
using Core.Packages.Installation.Backup;
using Core.Packages.Installation.Installers;
using Core.Utils;
using Microsoft.Extensions.FileSystemGlobbing;
Expand All @@ -17,14 +16,21 @@ IEnumerable<string> ExcludedFromConfig
{
get;
}

bool GenerateModDetails
{
get;
}
}

private readonly Matcher filesToConfigureMatcher;
private readonly bool generateModDetails;

internal ModInstaller(IInstaller inner, IGame game, ITempDir tempDir, IConfig config) :
base(inner, game, tempDir, config)
{
filesToConfigureMatcher = Matchers.ExcludingPatterns(config.ExcludedFromConfig);
generateModDetails = config.GenerateModDetails;
}

protected override void Install(Action innerInstall)
Expand Down Expand Up @@ -65,6 +71,10 @@ private void WriteModConfigFiles(ConfigEntries modConfig)
AddToInstalledFiles(PostProcessor.AppendCrdFileEntries(modConfigDirPath, modConfig.CrdFileEntries));
AddToInstalledFiles(PostProcessor.AppendTrdFileEntries(modConfigDirPath, modConfig.TrdFileEntries));
AddToInstalledFiles(PostProcessor.AppendDrivelineRecords(modConfigDirPath, modConfig.DrivelineRecords));
if (generateModDetails && (modConfig.CrdFileEntries.Any() || modConfig.DrivelineRecords.Any()))
{
AddToInstalledFiles(PostProcessor.GenerateModDetails(modConfigDirPath, Inner));
}
}

private List<string> CrdFileEntries() =>
Expand Down
25 changes: 24 additions & 1 deletion src/Core/Mods/Installation/Installers/PostProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Core.Utils;
using Core.Packages.Installation;
using Core.Utils;

namespace Core.Mods.Installation.Installers;

Expand Down Expand Up @@ -108,4 +109,26 @@ private static string DrivelineFileContents(RootedPath driveLineFilePath, string
}

private static string IdentityProcessor(string block) => block;

public static RootedPath GenerateModDetails(RootedPath destDirPath, IInstallation installation)
{
var modName = Path.GetFileName(destDirPath.Full);
var filePath = destDirPath.SubPath($"{modName}.xml");
var contents = @$"<?xml version=""1.0""?>
<Reflection>
<class name=""BRTTIRefCount"" base=""root class"" />
<class name=""BPersistent"" base=""BRTTIRefCount"">
<prop name=""Name"" type=""String"" />
</class>
<class name=""ModDetails"" base=""BPersistent"">
<prop name=""DisplayName"" type=""String"" />
</class>
<data class=""ModDetails"" id=""0x{installation.PackageFsHash:x08}"">
<prop name=""Name"" data=""{modName}"" />
<prop name=""DisplayName"" data=""{installation.PackageName}"" />
</data>
</Reflection>";
File.WriteAllText(filePath.Full, contents);
return filePath;
}
}
23 changes: 17 additions & 6 deletions tests/Core.Tests/API/ModManagerIntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public void Install_PerformsBackups()
}

[Fact]
public void Install_OldVehiclesRequireBootfiles()
public void Install_OldVehiclesDoNotRequireBootfiles()
{
var drivelineRecord = $"RECORD foo";
modRepositoryMock.Setup(_ => _.ListEnabled()).Returns([
Expand All @@ -463,9 +463,14 @@ public void Install_OldVehiclesRequireBootfiles()

modManager.InstallEnabledMods(eventHandlerMock.Object);

persistedState.Should().HaveInstalled(["Package100", "__bootfiles900"]);
File.ReadAllText(GamePath(VehicleListRelativePath).Full).Should().Contain("Vehicle.crd");
File.ReadAllText(GamePath(DrivelineRelativePath).Full).Should().Contain(drivelineRecord);
persistedState.Should().HaveInstalled(["Package100"]);
var generatedConfigDir = $"Package100_{100:x}";
File.ReadAllText(GamePath(PostProcessor.GameSupportedModDirectory, generatedConfigDir,
PostProcessor.VehicleListFileName).Full).Should().Contain("Vehicle.crd");
File.ReadAllText(GamePath(PostProcessor.GameSupportedModDirectory, generatedConfigDir,
PostProcessor.DrivelineFileName).Full).Should().Contain(drivelineRecord);
File.Exists(GamePath(PostProcessor.GameSupportedModDirectory, generatedConfigDir, $"{generatedConfigDir}.xml")
.Full).Should().BeTrue();
}

[Fact]
Expand Down Expand Up @@ -495,14 +500,20 @@ public void Install_AllTracksRequireBootfiles()
modManager.InstallEnabledMods(eventHandlerMock.Object);

persistedState.Should().HaveInstalled(["Package100", "__bootfiles900"]);
var generatedConfigDir = $"Package100_{100:x}";
File.ReadAllText(GamePath(PostProcessor.GameSupportedModDirectory, generatedConfigDir,
PostProcessor.TrackListFileName).Full).Should().Contain("Track.trd");
File.Exists(GamePath(PostProcessor.GameSupportedModDirectory, generatedConfigDir, $"{generatedConfigDir}.xml")
.Full).Should().BeFalse();

File.ReadAllText(GamePath(TrackListRelativePath).Full).Should().Contain("Track.trd");
}

[Fact]
public void Install_ExtractsBootfilesFromGameByDefault()
{
modRepositoryMock.Setup(_ => _.ListEnabled()).Returns([
CreateModArchive(100, [Path.Combine(DirAtRoot, "Foo.crd")])
CreateModArchive(100, [Path.Combine(DirAtRoot, "Foo.trd")])
]);

// Unfortunately, there is no easy way to create pak files!
Expand All @@ -520,7 +531,7 @@ public void Install_ExtractsBootfilesFromGameByDefault()
public void Install_ChoosesLastOfMultipleCustomBootfiles()
{
modRepositoryMock.Setup(_ => _.ListEnabled()).Returns([
CreateModArchive(100, [Path.Combine(DirAtRoot, "Foo.crd")]),
CreateModArchive(100, [Path.Combine(DirAtRoot, "Foo.trd")]),
CreateCustomBootfiles(900),
CreateCustomBootfiles(901)
]);
Expand Down