Skip to content

Commit

Permalink
Fix Installers
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeeWanderer committed Sep 5, 2024
1 parent 050c709 commit d88811e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 114 deletions.
225 changes: 112 additions & 113 deletions src/Games/NexusMods.Games.UnrealEngine/Installers/SmartUEInstaller.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Microsoft.Extensions.Logging;
using NexusMods.Abstractions.FileStore.Trees;
using NexusMods.Abstractions.GameLocators;
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.Library.Installers;
using NexusMods.Abstractions.Library.Models;
using NexusMods.Abstractions.Loadouts;
Expand Down Expand Up @@ -40,129 +39,129 @@ public SmartUEInstaller(ILogger<SmartUEInstaller> logger, IConnection connection
];

// This is here for reference, to be removed when loadout items reach parity with this implementation
public async ValueTask<IEnumerable<ModInstallerResult>> GetModsAsync(
ModInstallerInfo info,
CancellationToken cancellationToken = default)
{
var gameFolderPath = info.Locations[LocationId.Game];
var gameMainUEFolderPath = info.Locations[Constants.GameMainUE];
//public async ValueTask<IEnumerable<ModInstallerResult>> GetModsAsync(
// ModInstallerInfo info,
// CancellationToken cancellationToken = default)
//{
// var gameFolderPath = info.Locations[LocationId.Game];
// var gameMainUEFolderPath = info.Locations[Constants.GameMainUE];

var achiveFiles = info.ArchiveFiles.GetFiles();
// var achiveFiles = info.ArchiveFiles.GetFiles();

if (achiveFiles.Length == 0)
{
Logger.LogError("Archive contains 0 files");
return [];
}
// if (achiveFiles.Length == 0)
// {
// Logger.LogError("Archive contains 0 files");
// return [];
// }

var loadout = Loadout.All(_connection.Db)
.First(x => x.Installation.Path == gameFolderPath.ToString());
// var loadout = Loadout.All(_connection.Db)
// .First(x => x.Installation.Path == gameFolderPath.ToString());

var gameFilesLookup = loadout.Mods
.First(mod => mod.Category == ModCategory.GameFiles).Files
.Select(file => file.To).ToLookup(x => x.Path.FileName);
// var gameFilesLookup = loadout.Mods
// .First(mod => mod.Category == ModCategory.GameFiles).Files
// .Select(file => file.To).ToLookup(x => x.Path.FileName);

var modFiles = achiveFiles.Select(kv =>
{
switch (kv.Path().Extension)
{
case Extension ext when Constants.ContentExts.Contains(ext):
{
var matchesGameContentFles = gameFilesLookup[kv.FileName()];
if (matchesGameContentFles.Any()) // if Content file exists in game dir replace it
{
var matchedContentFIle = matchesGameContentFles.First();
return kv.ToStoredFile(
matchedContentFIle
);
}
else
return kv.ToStoredFile(
Constants.ContentModsPath.Join(kv.FileName())
);
}
case Extension ext when ext == Constants.DLLExt:
{
var matchesGameDlls = gameFilesLookup[kv.FileName()];
if (matchesGameDlls.Any()) // if DLL exists in game dir replace it
{
var matchedDll = matchesGameDlls.First();
return kv.ToStoredFile(
matchedDll
);
}
else
return kv.ToStoredFile(
Constants.InjectorModsPath.Join(kv.FileName())
);
}
default:
{
var matchesGameFles = gameFilesLookup[kv.FileName()];
if (matchesGameFles.Any()) // if File exists in game dir replace it
{
var matchedFile = matchesGameFles.First();
return kv.ToStoredFile(
matchedFile
);
}
else
{
Logger.LogWarning("File {} is of unrecognized type {}, skipping", kv.Path().FileName, kv.Path().Extension);
return null;
}
}
}
}).OfType<TempEntity>().ToArray();
// var modFiles = achiveFiles.Select(kv =>
// {
// switch (kv.Path().Extension)
// {
// case Extension ext when Constants.ContentExts.Contains(ext):
// {
// var matchesGameContentFles = gameFilesLookup[kv.FileName()];
// if (matchesGameContentFles.Any()) // if Content file exists in game dir replace it
// {
// var matchedContentFIle = matchesGameContentFles.First();
// return kv.ToStoredFile(
// matchedContentFIle
// );
// }
// else
// return kv.ToStoredFile(
// Constants.ContentModsPath.Join(kv.FileName())
// );
// }
// case Extension ext when ext == Constants.DLLExt:
// {
// var matchesGameDlls = gameFilesLookup[kv.FileName()];
// if (matchesGameDlls.Any()) // if DLL exists in game dir replace it
// {
// var matchedDll = matchesGameDlls.First();
// return kv.ToStoredFile(
// matchedDll
// );
// }
// else
// return kv.ToStoredFile(
// Constants.InjectorModsPath.Join(kv.FileName())
// );
// }
// default:
// {
// var matchesGameFles = gameFilesLookup[kv.FileName()];
// if (matchesGameFles.Any()) // if File exists in game dir replace it
// {
// var matchedFile = matchesGameFles.First();
// return kv.ToStoredFile(
// matchedFile
// );
// }
// else
// {
// Logger.LogWarning("File {} is of unrecognized type {}, skipping", kv.Path().FileName, kv.Path().Extension);
// return null;
// }
// }
// }
// }).OfType<TempEntity>().ToArray();

if (modFiles.Length == 0)
{
Logger.LogError("0 files were processed");
return [];
}
else if (modFiles.Length != achiveFiles.Length)
{
Logger.LogWarning("Of {} files in archive only {} were processed", achiveFiles.Length, modFiles.Length);
}
// if (modFiles.Length == 0)
// {
// Logger.LogError("0 files were processed");
// return [];
// }
// else if (modFiles.Length != achiveFiles.Length)
// {
// Logger.LogWarning("Of {} files in archive only {} were processed", achiveFiles.Length, modFiles.Length);
// }

var Name = info.ModName;
var Id = info.BaseModId;
string? Version = null;
// var Name = info.ModName;
// var Id = info.BaseModId;
// string? Version = null;

// If ModName ends with archive extension try to parse name and version out of the archive name
if (info.ModName != null && Constants.ArchiveExts.Contains(info.ModName.ToRelativePath().Extension))
{
foreach (var regex in ModArchiveNameRegexes)
{
var match = regex.Match(info.ModName);
if (match.Success)
{
if (match.Groups.ContainsKey("modName"))
{
Name = match.Groups["modName"].Value
.Replace('_', ' ')
.Trim();
}
// // If ModName ends with archive extension try to parse name and version out of the archive name
// if (info.ModName != null && Constants.ArchiveExts.Contains(info.ModName.ToRelativePath().Extension))
// {
// foreach (var regex in ModArchiveNameRegexes)
// {
// var match = regex.Match(info.ModName);
// if (match.Success)
// {
// if (match.Groups.ContainsKey("modName"))
// {
// Name = match.Groups["modName"].Value
// .Replace('_', ' ')
// .Trim();
// }

if (match.Groups.ContainsKey("version"))
{
Version = match.Groups["version"].Value
.Replace('-', '.');
}
// if (match.Groups.ContainsKey("version"))
// {
// Version = match.Groups["version"].Value
// .Replace('-', '.');
// }

break;
}
}
}
// break;
// }
// }
// }

return [ new ModInstallerResult
{
Id = Id,
Files = modFiles,
Name = Name,
Version = Version,
}];
}
// return [ new ModInstallerResult
// {
// Id = Id,
// Files = modFiles,
// Name = Name,
// Version = Version,
// }];
//}

public override async ValueTask<InstallerResult> ExecuteAsync(
LibraryArchive.ReadOnly libraryArchive,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using NexusMods.Abstractions.GameLocators.Stores.Steam;
using NexusMods.Abstractions.Games;
using NexusMods.Abstractions.Games.DTO;
using NexusMods.Abstractions.Installers;
using NexusMods.Abstractions.IO;
using NexusMods.Abstractions.IO.StreamFactories;
using NexusMods.Abstractions.Loadouts.Synchronizers;
Expand Down

0 comments on commit d88811e

Please sign in to comment.