Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MP1-5191: Fixed bug MPEMaker fails to save plugindependencies: remove handler when done #256

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
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