Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Recursive loading of mods from nml_mods #51

Merged
merged 4 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
9 changes: 9 additions & 0 deletions NeosModLoader/AssemblyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace NeosModLoader
{
internal class AssemblyFile
{
public static readonly AssemblyFileComparer AssemblyComparer = new AssemblyFileComparer();
internal string File { get; }
internal Assembly Assembly { get; set; }
internal AssemblyFile(string file, Assembly assembly)
Expand All @@ -12,4 +13,12 @@ internal AssemblyFile(string file, Assembly assembly)
Assembly = assembly;
}
}

// compares two AssemblyFile objects, based on whether they contain identical assemblies or not.
class AssemblyFileComparer : System.Collections.Generic.IEqualityComparer<AssemblyFile>
{
public bool Equals(AssemblyFile x, AssemblyFile y) { return x.Assembly == y.Assembly; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It boggles my mind that this apparently does something, as the MS api docs don't say squat about that.


public int GetHashCode(AssemblyFile obj) { return obj.Assembly.GetHashCode() ^ obj.Assembly.GetHashCode(); }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this XOR a no-op?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That XOR does look like a no-op. Don't know what I did there.

}
}
10 changes: 8 additions & 2 deletions NeosModLoader/AssemblyLoader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;

namespace NeosModLoader
Expand All @@ -17,7 +18,10 @@ internal static class AssemblyLoader
try
{
assembliesToLoad = Directory.GetFiles(assembliesDirectory, "*.dll");
Psychpsyo marked this conversation as resolved.
Show resolved Hide resolved
Array.Sort(assembliesToLoad, (a, b) => string.CompareOrdinal(a, b));
foreach (string directory in Directory.GetDirectories(assembliesDirectory))
{
assembliesToLoad = assembliesToLoad.Concat(GetAssemblyPathsFromDir(directory)).ToArray();
}
}
catch (Exception e)
{
Expand All @@ -38,6 +42,7 @@ internal static class AssemblyLoader
Logger.ErrorInternal($"Error enumerating ${dirName} directory:\n{e}");
}
}
Array.Sort(assembliesToLoad, (a, b) => string.CompareOrdinal(a, b));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...Though wouldn't this throw if assembliesToLoad is never initialized...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would. Somehow that got moved down out of the try...catch. I moved it back in now.

return assembliesToLoad;
}

Expand Down Expand Up @@ -85,7 +90,8 @@ internal static AssemblyFile[] LoadAssembliesFromDir(string dirName)
}
}

return assemblyFiles.ToArray();
// remove duplicate assemblies and return the list
return assemblyFiles.Distinct(AssemblyFile.AssemblyComparer).ToArray();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a user has botched their assemblies enough that there are duplicates, then I think we should log it so that when the logs inevitably get sent to me to decipher I don't scratch my head for too long.

Copy link
Contributor Author

@Psychpsyo Psychpsyo Jul 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, my thought process here was that now that mod loading is recursive, someone could put a bunch of mods in a folder and call it a modpack.
If someone then puts two of those in at once, they want to load mods that are in both only once.
But yea, having that be logged probably makes more sense. (Which it will be by your deduplicator if I just take this deduplication out.)

But since there's code that does deduplication later anyways, I've just removed it from this part entirely.

}
}
}
1 change: 1 addition & 0 deletions NeosModLoader/NeosModLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<NeosPath>$(MSBuildThisFileDirectory)NeosVR/</NeosPath>
<NeosPath Condition="Exists('C:\Program Files (x86)\Steam\steamapps\common\NeosVR\')">C:\Program Files (x86)\Steam\steamapps\common\NeosVR\</NeosPath>
<NeosPath Condition="Exists('$(HOME)/.steam/steam/steamapps/common/NeosVR/')">$(HOME)/.steam/steam/steamapps/common/NeosVR/</NeosPath>
<NeosPath Condition="Exists('D:/Files/Games/Neos/app/')">D:/Files/Games/Neos/app/</NeosPath>
</PropertyGroup>

<ItemGroup>
Expand Down