public static void GetPlugins() { if (Directory.Exists(Manage.PluginsPath)) { //获取所有文件 string[] listFiles = Directory.GetFiles(Manage.PluginsPath); //遍历 foreach (string s in listFiles) { //找到类库 if (s.ToUpper().EndsWith(".DLL")) { //加载 Assembly asm = Assembly.LoadFrom(s); if (asm != null) { //获取类型名集合 Type[] types = asm.GetTypes(); foreach (Type t in types) { //找到类型名内含有入口方法的类型 if (t.GetMethod("AnythingPluginMain") != null) { //创建对象 object obj = asm.CreateInstance(t.FullName); //添加到集合 plugins.Add(obj); //创建对应的菜单项 MenuItem menuitem = new MenuItem(); //写菜单项名称 menuitem.Header = t.GetProperty("MdlName").GetValue(obj, null).ToString(); //检查是否要接管内部操作 if (t.GetProperty("ManageOperation").GetValue(obj, null).ToString() != "") { //接管网络浏览器 if (t.GetProperty("ManageOperation").GetValue(obj, null).ToString() == "Web") { Manage.MOWeb.IsUsed = true; Manage.MOWeb.MdlName = t.GetProperty("MdlName").GetValue(obj, null).ToString(); } //接管文件夹浏览 else if (t.GetProperty("ManageOperation").GetValue(obj, null).ToString() == "Folder") { Manage.MOFolder.IsUsed = true; Manage.MOFolder.MdlName = t.GetProperty("MdlName").GetValue(obj, null).ToString(); } } //检查插件是否申请了快捷键 if ((bool)t.GetProperty("ApplyForHotKey").GetValue(obj, null)) { string KeyGot = t.GetProperty("HotKey").GetValue(obj, null).ToString(); if (!string.IsNullOrEmpty(KeyGot)) { HotKeyVisualItem HKVI = new HotKeyVisualItem(); HKVI.HotKeysString = KeyGot; if (HKVI.Available) { Manage.CheckAndRegisterHotKey(HKVI, menuitem.Header.ToString()); } } } //菜单项添加事件 menuitem.Click += Menuitem_Click; //添加菜单项 Manage.WindowMain.Plugins.Items.Add(menuitem); } } } } } } }
/// <summary> /// 从数据文件路径初始化内部数据 /// </summary> /// <param name="path"></param> /// <returns></returns> private int ConnectDB() { if (objDB != null) { this.data.Name = objDB.ReadFirstByName("Name") as string; this.data.ID = objDB.ReadFirstByName("ID") as string; int Count = Convert.ToInt32(objDB.ReadFirstByName("Icon")); try { using (BinaryReader br = new BinaryReader(new FileStream(Manage.IconPath + data.ID + ".ib", FileMode.Open))) { data.Icon = br.ReadBytes(Count); } } catch { } this.data.Path = objDB.ReadFirstByName("Path") as string; this.data.Arguments = objDB.ReadFirstByName("Arguments") as string; this.data.RunAs = Convert.ToInt32(objDB.ReadFirstByName("Runas")); this.data.AutoRun = Convert.ToInt32(objDB.ReadFirstByName("Autorun")); this.data.Levels = Convert.ToInt32(objDB.ReadFirstByName("Levels")); this.data.WorkingDirectory = objDB.ReadFirstByName("WorkingDirectory"); this.data.tagName = objDB.ReadFirstByName("TagName"); string strHKI = objDB.ReadFirstByName("HotKey"); if (strHKI != null) { if (!string.IsNullOrEmpty(strHKI.Replace(",", "").Replace(" ", ""))) { string[] HKISplit; try { HKISplit = strHKI.Split(','); } catch { HKISplit = new string[] { }; } if (HKISplit.Length >= 3) { System.Windows.Forms.KeysConverter keyCvt = new System.Windows.Forms.KeysConverter(); this.data.HotKey = new HotKeyItem(this, (System.Windows.Forms.Keys)keyCvt.ConvertFromString(HKISplit[0]), Convert.ToUInt32(HKISplit[1]), Convert.ToInt32(HKISplit[2]), HotKeyItem.HotKeyParentType.Item); if (Manage.CheckAndRegisterHotKey(data.HotKey)) { Class.HotKey.CurrentID++; data.EnableHotKey = true; } } else { this.data.HotKey = new HotKeyItem(null, System.Windows.Forms.Keys.None, 0, 0, HotKeyItem.HotKeyParentType.Item); } } else { data.HotKey = new HotKeyItem(this, System.Windows.Forms.Keys.None, 0, 0, HotKeyItem.HotKeyParentType.Item); } } return(0); } return(-1); }