Skip to content
Merged
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
32 changes: 29 additions & 3 deletions Rocket/Rocket.Core/Plugins/RocketPluginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,39 @@ private Assembly OnAssemblyResolve(object sender, ResolveEventArgs args)
try
{
AssemblyName requestedName = new AssemblyName(args.Name);
var bestMatch = libraries.FirstOrDefault(lib => string.Equals(lib.Key.Name, requestedName.Name) && lib.Key.Version >= requestedName.Version);
var matchesByName = libraries.Where(lib => string.Equals(lib.Key.Name, requestedName.Name));

// Prefer exactly-matching version if possible.
var bestMatch = matchesByName.FirstOrDefault(lib => lib.Key.Version == requestedName.Version);
if (string.IsNullOrEmpty(bestMatch.Value))
{
// Otherwise, fallback to highest version.
bestMatch = matchesByName.OrderByDescending(lib => lib.Key.Version).FirstOrDefault();
}
if (!string.IsNullOrEmpty(bestMatch.Value))
{
// https://github.com/SmartlyDressedGames/Legally-Distinct-Missile/issues/84
if (requestedName.Version != null)
{
if (bestMatch.Key.Version == null)
{
Logging.Logger.LogWarning($"Rocket best match for dependency {requestedName} has no configued version: {bestMatch.Key} at {bestMatch.Value}");
}
else if (bestMatch.Key.Version < requestedName.Version)
{
Logging.Logger.LogWarning($"Rocket best match for dependency {requestedName} version is older than requested: {bestMatch.Key} at {bestMatch.Value}");
}
}

return Assembly.Load(File.ReadAllBytes(bestMatch.Value));
}
}
catch (Exception ex)
{
Logging.Logger.LogException(ex, "Caught exception resolving dependency: " + args.Name);
Logging.Logger.LogException(ex, "Rocket caught exception resolving dependency: " + args.Name);
}

Logging.Logger.LogError("Could not find dependency: " + args.Name);
Logging.Logger.LogError("Rocket could not find dependency: " + args.Name);
return null;
}

Expand Down Expand Up @@ -84,6 +105,11 @@ private void loadPlugins()
libraries.Add(pair.Key,pair.Value);
}

foreach (KeyValuePair<AssemblyName, string> pair in libraries)
{
Logging.Logger.Log($"Rocket dependency registered: {pair.Key} at {pair.Value}");
}

pluginAssemblies = LoadAssembliesFromDirectory(Environment.PluginsDirectory);
List<Type> pluginImplemenations = RocketHelper.GetTypesFromInterface(pluginAssemblies, "IRocketPlugin");
foreach (Type pluginType in pluginImplemenations)
Expand Down
Loading