-
Notifications
You must be signed in to change notification settings - Fork 22
Recursive loading of mods from nml_mods #51
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
|
@@ -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; } | ||
|
||
public int GetHashCode(AssemblyFile obj) { return obj.Assembly.GetHashCode() ^ obj.Assembly.GetHashCode(); } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this XOR a no-op? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
} |
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 | ||
|
@@ -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) | ||
{ | ||
|
@@ -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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ...Though wouldn't this throw if assembliesToLoad is never initialized...? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} | ||
|
||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. But since there's code that does deduplication later anyways, I've just removed it from this part entirely. |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
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.