static void LoadPlugins() { Log("Loading plugins..."); string path = System.IO.Path.Combine(DataDir, "plugins"); Log("Plugin Directory: " + path); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } string[] pluginFiles = System.IO.Directory.GetFiles(path, "*.dll"); foreach (string file in pluginFiles) { try { Assembly assembly = Assembly.LoadFrom(file); foreach (Type type in assembly.GetTypes()) { if (type.IsClass && type.IsPublic && !type.IsAbstract) { Type typeInterface = type.GetInterface(typeof(IiControlPlugin).ToString(), true); if (typeInterface != null) { IiControlPlugin plugin = (IiControlPlugin)Activator.CreateInstance(type); Log(String.Format("[{0}] Plugin loaded: {1} ({2}) by {3}", System.IO.Path.GetFileName(file), plugin.Name, plugin.Version, plugin.Author)); plugin.Host = pluginHost; if (plugin.Init() == true) { plugins.Add(plugin); } else { Log(String.Format("[{0}] Plugin disabled", System.IO.Path.GetFileName(file))); } } typeInterface = null; } } } catch (Exception ex) { Log(String.Format("[{0}] {1}: {2}", System.IO.Path.GetFileName(file), ex.ToString(), ex.Message)); } } Log(plugins.Count + " plugins loaded."); }
public void SetSetting(string key, object value, IiControlPlugin plugin) { Dictionary <string, object> settings = new Dictionary <string, object>(); string path = System.IO.Path.Combine((string)GetInfo("plugindir"), plugin.Name + ".config"); if (System.IO.File.Exists(path)) { settings = DeserializeJSON(path); } if (settings.ContainsKey(key)) { settings[key] = value; } else { settings.Add(key, value); } SerializeJSON(path, settings); }
public void Log(string msg, IiControlPlugin plugin) { Program.WriteLog(string.Format("[{0}] {1}", plugin.Name, msg)); }