Beispiel #1
0
 private void DelAIBtn_Click(object sender, EventArgs e)
 {
     if (listViewAI.SelectedItems.Count == 0)
     {
         MessageBox.Show("请在左边选择一个要删除的条目!", "提示窗口",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
         return;
     }
     foreach (AssetItem aa in AIlist.list)
     {
         foreach (NameAndTypeName bb in aa.names)
         {
             foreach (ListViewItem listitem in listViewAI.SelectedItems)
             {
                 this.Text += bb.name;
                 if (aa.DLLName == listitem.SubItems[0].Text && bb.name == listitem.SubItems[1].Text &&
                     bb.typeNames == listitem.SubItems[2].Text)
                 {
                     AIlist.list.Remove(aa);
                     File.Delete(AIListPath);
                     AssetList.Save(File.Open(AIListPath, FileMode.OpenOrCreate), AIlist);
                     InitialAIList();
                     return;
                 }
             }
         }
     }
 }
Beispiel #2
0
        private void OpenRuleDLLFileDialog_FileOk(object sender, CancelEventArgs e)
        {
            List <AssetItem> rulesList = new List <AssetItem>();

            List <string> vaildDLL = new List <string>();

            int countVaildClass = 0;

            foreach (string fileName in OpenRuleDLLFileDialog.FileNames)
            {
                Assembly assembly = DIHelper.GetAssembly(fileName);

                AssetItem curItem;
                bool      findGameRule = false;
                curItem         = new AssetItem();
                curItem.DLLName = assembly.FullName;// Path.GetFileName( fileName );
                List <NameAndTypeName> names = new List <NameAndTypeName>();
                try
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        foreach (Type infer in type.GetInterfaces())
                        {
                            if (infer.Name == "IGameRule")
                            {
                                object[] attributes = type.GetCustomAttributes(typeof(RuleAttribute), false);
                                foreach (object attri in attributes)
                                {
                                    if (attri is RuleAttribute)
                                    {
                                        findGameRule = true;
                                        string ruleName = ((RuleAttribute)attri).Name;
                                        names.Add(new NameAndTypeName(ruleName, type.FullName));
                                        countVaildClass++;
                                        break;
                                    }
                                }
                                if (findGameRule)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    findGameRule = false;
                }
                if (findGameRule)
                {
                    curItem.names = names.ToArray();
                    rulesList.Add(curItem);
                    vaildDLL.Add(fileName);
                }
            }

            if (rulesList.Count != 0)
            {
                Directory.SetCurrentDirectory(Application.StartupPath);
                if (!Directory.Exists(rulesPath))
                {
                    Directory.CreateDirectory(rulesPath);
                }
                AssetList list = AssetList.Load(File.Open(rulesListPath, FileMode.OpenOrCreate));
                if (list == null)
                {
                    list = new AssetList();
                }


                foreach (AssetItem item in rulesList)
                {
                    int index = list.IndexOf(item.DLLName);
                    if (index != -1)
                    {
                        list.list[index] = item;
                    }
                    else
                    {
                        list.list.Add(item);
                    }
                }
                AssetList.Save(File.Open(rulesListPath, FileMode.OpenOrCreate), list);

                foreach (string DLLPath in vaildDLL)
                {
                    string copyPath = Path.Combine(rulesPath, Path.GetFileName(DLLPath));
                    if (!Path.GetFullPath(copyPath).Equals(DLLPath))
                    {
                        if (File.Exists(copyPath))
                        {
                            DialogResult result = MessageBox.Show(Path.GetFileName(DLLPath) + "已存在于" + rulesPath + "中。是否覆盖?", "文件已存在", MessageBoxButtons.YesNo);
                            if (result == DialogResult.Yes)
                            {
                                File.Copy(DLLPath, copyPath, true);
                            }
                        }
                        else
                        {
                            File.Copy(DLLPath, copyPath);
                        }
                    }
                }
                MessageBox.Show("添加规则程序集成功!共添加" + vaildDLL.Count + "个有效程序集," + countVaildClass + "个有效规则类", "成功");
            }
            else
            {
                MessageBox.Show("未找到有效规则程序集!", "失败");
            }

            InitialRuleList();
        }