mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-14 20:54:16 +01:00
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
This commit is contained in:
parent
1370b767a8
commit
e9d4d57696
1 changed files with 42 additions and 33 deletions
|
|
@ -57,7 +57,48 @@ namespace Dalamud.Plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool LoadPluginFromAssembly(FileInfo dllFile, bool raw) {
|
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<PluginDefinition>(
|
||||||
|
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);
|
Log.Information("Loading assembly at {0}", dllFile);
|
||||||
|
|
||||||
var assemblyName = AssemblyName.GetAssemblyName(dllFile.FullName);
|
var assemblyName = AssemblyName.GetAssemblyName(dllFile.FullName);
|
||||||
var pluginAssembly = Assembly.Load(assemblyName);
|
var pluginAssembly = Assembly.Load(assemblyName);
|
||||||
|
|
||||||
|
|
@ -74,38 +115,6 @@ namespace Dalamud.Plugin
|
||||||
|
|
||||||
if (type.GetInterface(interfaceType.FullName) != null)
|
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<PluginDefinition>(
|
|
||||||
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)) {
|
if (this.Plugins.Any(x => x.Plugin.GetType().Assembly.GetName().Name == type.Assembly.GetName().Name)) {
|
||||||
Log.Error("Duplicate plugin found: {0}", dllFile.FullName);
|
Log.Error("Duplicate plugin found: {0}", dllFile.FullName);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -120,7 +129,7 @@ namespace Dalamud.Plugin
|
||||||
{
|
{
|
||||||
Author = "developer",
|
Author = "developer",
|
||||||
Name = plugin.Name,
|
Name = plugin.Name,
|
||||||
InternalName = "devPlugin_" + plugin.Name,
|
InternalName = Path.GetFileNameWithoutExtension(dllFile.Name),
|
||||||
AssemblyVersion = plugin.GetType().Assembly.GetName().Version.ToString(),
|
AssemblyVersion = plugin.GetType().Assembly.GetName().Version.ToString(),
|
||||||
Description = "",
|
Description = "",
|
||||||
ApplicableVersion = "any",
|
ApplicableVersion = "any",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue