From e9d4d57696b13af2c9909217def71b03affc1bd3 Mon Sep 17 00:00:00 2001 From: meli <57847713+ff-meli@users.noreply.github.com> Date: Sun, 22 Mar 2020 07:17:56 -0700 Subject: [PATCH] don't even attempt to load assemblies for disabled or invalid plugins; fixes issues where starting the game with multiple versions, even disabled, could load the wrong one and block other versions --- Dalamud/Plugin/PluginManager.cs | 75 ++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/Dalamud/Plugin/PluginManager.cs b/Dalamud/Plugin/PluginManager.cs index 952c19393..64c0ddb2a 100644 --- a/Dalamud/Plugin/PluginManager.cs +++ b/Dalamud/Plugin/PluginManager.cs @@ -57,7 +57,48 @@ namespace Dalamud.Plugin } public bool LoadPluginFromAssembly(FileInfo dllFile, bool raw) { + Log.Information("Loading plugin at {0}", dllFile.Directory.FullName); + + // If this entire folder has been marked as a disabled plugin, don't even try to load anything + var disabledFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, ".disabled")); + if (disabledFile.Exists && !raw) // should raw/dev plugins really not respect this? + { + Log.Information("Plugin {0} is disabled.", dllFile.FullName); + return false; + } + + // read the plugin def if present - again, fail before actually trying to load the dll if there is a problem + var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json")); + + PluginDefinition pluginDef = null; + // load the definition if it exists, even for raw/developer plugins + if (defJsonFile.Exists) + { + Log.Information("Loading definition for plugin DLL {0}", dllFile.FullName); + + pluginDef = + JsonConvert.DeserializeObject( + File.ReadAllText(defJsonFile.FullName)); + + if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion && pluginDef.ApplicableVersion != "any") + { + Log.Information("Plugin {0} has not applicable version.", dllFile.FullName); + return false; + } + } + // but developer plugins don't require one to load + else if (!raw) + { + Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName); + return false; + } + + // TODO: given that it exists, the pluginDef's InternalName should probably be used + // as the actual assembly to load + // But plugins should also probably be loaded by directory and not by looking for every dll + Log.Information("Loading assembly at {0}", dllFile); + var assemblyName = AssemblyName.GetAssemblyName(dllFile.FullName); var pluginAssembly = Assembly.Load(assemblyName); @@ -74,38 +115,6 @@ namespace Dalamud.Plugin if (type.GetInterface(interfaceType.FullName) != null) { - var disabledFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, ".disabled")); - - if (disabledFile.Exists && !raw) { - Log.Information("Plugin {0} is disabled.", dllFile.FullName); - return false; - } - - var defJsonFile = new FileInfo(Path.Combine(dllFile.Directory.FullName, $"{Path.GetFileNameWithoutExtension(dllFile.Name)}.json")); - - PluginDefinition pluginDef = null; - // load the definition if it exists, even for raw/developer plugins - if (defJsonFile.Exists) - { - Log.Information("Loading definition for plugin DLL {0}", dllFile.FullName); - - pluginDef = - JsonConvert.DeserializeObject( - File.ReadAllText(defJsonFile.FullName)); - - if (pluginDef.ApplicableVersion != this.dalamud.StartInfo.GameVersion && pluginDef.ApplicableVersion != "any") - { - Log.Information("Plugin {0} has not applicable version.", dllFile.FullName); - return false; - } - } - // but developer plugins don't require one to load - else if (!raw) - { - Log.Information("Plugin DLL {0} has no definition.", dllFile.FullName); - return false; - } - if (this.Plugins.Any(x => x.Plugin.GetType().Assembly.GetName().Name == type.Assembly.GetName().Name)) { Log.Error("Duplicate plugin found: {0}", dllFile.FullName); return false; @@ -120,7 +129,7 @@ namespace Dalamud.Plugin { Author = "developer", Name = plugin.Name, - InternalName = "devPlugin_" + plugin.Name, + InternalName = Path.GetFileNameWithoutExtension(dllFile.Name), AssemblyVersion = plugin.GetType().Assembly.GetName().Version.ToString(), Description = "", ApplicableVersion = "any",