Skip to content

Commit

Permalink
Merge pull request #256 from MediaPortal/MP1-5191_MPEMaker_fails_to_s…
Browse files Browse the repository at this point in the history
…ave_plugindependencies

MP1-5191: Fixed bug MPEMaker fails to save plugindependencies: remove handler when done
  • Loading branch information
andrewjswan authored Jan 22, 2024
2 parents 6c6ff83 + 74633e9 commit a42d890
Showing 1 changed file with 48 additions and 38 deletions.
86 changes: 48 additions & 38 deletions mediaportal/MPE/MpeCore/Classes/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ public static bool IsPlugin(string pluginFile)
return false;
}
Assembly pluginAssembly = null;
var pluginDllLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins", "Windows");
ResolveEventHandler handler = new ResolveEventHandler(delegate (object sender, ResolveEventArgs args)
{
int idx = args.Name.IndexOf(',');
string pluginFullPath = Path.Combine(pluginDllLocation, (idx > 0 ? args.Name.Substring(0, idx) : args.Name) + ".dll");
return Assembly.LoadFrom(pluginFullPath);
});

AppDomain.CurrentDomain.AssemblyResolve += handler;
try
{
var pluginDllLocation = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "plugins", "Windows");
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(delegate (object sender, ResolveEventArgs args)
{
var dllName = Path.Combine(pluginDllLocation, args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll");
return Assembly.LoadFrom(dllName);
});
pluginAssembly = Assembly.LoadFrom(pluginFile);
}
catch (BadImageFormatException)
Expand All @@ -119,45 +122,52 @@ public static bool IsPlugin(string pluginFile)
MessageBox.Show(string.Format("Error adding plugin depdendency for {0}.\nException message: {1}", pluginFile, ex.Message));
return false;
}
if (pluginAssembly != null)
try
{
try
if (pluginAssembly != null)
{
Type[] exportedTypes = pluginAssembly.GetExportedTypes();

foreach (Type type in exportedTypes)
try
{
if (type.IsAbstract)
{
continue;
}
if (type.GetInterface("MediaPortal.GUI.Library.ISetupForm") != null)
{
return true;
}
if (type.GetInterface("MediaPortal.GUI.Library.IPlugin") != null)
{
return true;
}
if (type.GetInterface("MediaPortal.GUI.Library.IWakeable") != null)
{
return true;
}
if (type.GetInterface("TvEngine.ITvServerPlugin") != null)
{
return true;
}
if (type.IsClass && type.IsSubclassOf(typeof(GUIWindow)))
Type[] exportedTypes = pluginAssembly.GetExportedTypes();

foreach (Type type in exportedTypes)
{
return true;
if (type.IsAbstract)
{
continue;
}
if (type.GetInterface("MediaPortal.GUI.Library.ISetupForm") != null)
{
return true;
}
if (type.GetInterface("MediaPortal.GUI.Library.IPlugin") != null)
{
return true;
}
if (type.GetInterface("MediaPortal.GUI.Library.IWakeable") != null)
{
return true;
}
if (type.GetInterface("TvEngine.ITvServerPlugin") != null)
{
return true;
}
if (type.IsClass && type.IsSubclassOf(typeof(GUIWindow)))
{
return true;
}
}
}
catch (Exception e)
{
MessageBox.Show("Exception " + e.Message);
return false;
}
}
catch (Exception e)
{
MessageBox.Show("Exception " + e.Message);
return false;
}
}
finally
{
AppDomain.CurrentDomain.AssemblyResolve -= handler;
}
return false;
}
Expand Down

0 comments on commit a42d890

Please sign in to comment.