2013-12-20 19:38:10 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2014-02-23 13:32:28 +08:00
|
|
|
|
using System.IO;
|
2013-12-20 19:38:10 +08:00
|
|
|
|
using System.Linq;
|
2013-12-21 01:20:17 +08:00
|
|
|
|
using System.Reflection;
|
2013-12-22 19:35:21 +08:00
|
|
|
|
using System.Threading;
|
2014-01-29 18:33:24 +08:00
|
|
|
|
using Wox.Helper;
|
|
|
|
|
using Wox.Plugin;
|
2014-03-29 15:52:57 +08:00
|
|
|
|
using Wox.Plugin.SystemPlugins;
|
2013-12-20 19:38:10 +08:00
|
|
|
|
|
2014-01-29 18:33:24 +08:00
|
|
|
|
namespace Wox.PluginLoader
|
2013-12-20 19:38:10 +08:00
|
|
|
|
{
|
2013-12-21 01:20:17 +08:00
|
|
|
|
public class CSharpPluginLoader : BasePluginLoader
|
2013-12-20 19:38:10 +08:00
|
|
|
|
{
|
2013-12-21 01:20:17 +08:00
|
|
|
|
public override List<PluginPair> LoadPlugin()
|
2013-12-20 19:38:10 +08:00
|
|
|
|
{
|
2013-12-21 01:20:17 +08:00
|
|
|
|
List<PluginPair> plugins = new List<PluginPair>();
|
|
|
|
|
|
|
|
|
|
List<PluginMetadata> metadatas = pluginMetadatas.Where(o => o.Language.ToUpper() == AllowedLanguage.CSharp.ToUpper()).ToList();
|
|
|
|
|
foreach (PluginMetadata metadata in metadatas)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
2014-02-23 13:32:28 +08:00
|
|
|
|
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
|
2014-01-15 22:45:02 +08:00
|
|
|
|
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList();
|
2013-12-21 01:20:17 +08:00
|
|
|
|
if (types.Count == 0)
|
|
|
|
|
{
|
2014-03-23 17:43:46 +08:00
|
|
|
|
Log.Warn(string.Format("Cound't load plugin {0}: didn't find the class who implement IPlugin",
|
2013-12-22 00:44:56 +08:00
|
|
|
|
metadata.Name));
|
2013-12-21 01:20:17 +08:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-03 23:52:36 +08:00
|
|
|
|
foreach (Type type in types)
|
2013-12-21 01:20:17 +08:00
|
|
|
|
{
|
2014-01-03 23:52:36 +08:00
|
|
|
|
PluginPair pair = new PluginPair()
|
|
|
|
|
{
|
|
|
|
|
Plugin = Activator.CreateInstance(type) as IPlugin,
|
|
|
|
|
Metadata = metadata
|
|
|
|
|
};
|
2014-03-28 22:42:28 +08:00
|
|
|
|
|
|
|
|
|
var sys = pair.Plugin as BaseSystemPlugin;
|
|
|
|
|
if (sys != null)
|
|
|
|
|
{
|
|
|
|
|
sys.PluginDirectory = metadata.PluginDirecotry;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-03 23:52:36 +08:00
|
|
|
|
plugins.Add(pair);
|
|
|
|
|
}
|
2013-12-21 01:20:17 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
Log.Error(string.Format("Cound't load plugin {0}: {1}", metadata.Name, e.Message));
|
|
|
|
|
#if (DEBUG)
|
2013-12-22 00:44:56 +08:00
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2013-12-21 01:20:17 +08:00
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-20 19:38:10 +08:00
|
|
|
|
return plugins;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|