public HunterConfig() { StrategyFolder = HunterUtilities.AbsolutePath("strategy\\"); PluginFolder = HunterUtilities.AbsolutePath("plugins\\"); CurrentStrategyFile = HunterUtilities.AbsolutePath("strategy\\bing.h3s"); UseProxy = false; PingTimeout = 3000; viewOption = new ViewOption(); notifyOption = new NotifyOption(); ProxyFilterKeywords = new List <String>(); UpdateHTTPRoot = "http://10.20.128.164:1204"; UpdateHTTPIndex = "/download/version.xml"; FailureCooldown = 60; FailureTimes = 10; HunterCore = Core.Default; }
public StrategyData LoadStrategy(String strategyPath) { StrategyData result = null; try { strategyPath = HunterUtilities.AbsolutePath(strategyPath); result = StrategyReader.LoadStrategy(strategyPath); WriteMessage(result.GetStrategyInformation()); mHunterConfig.CurrentStrategyFile = strategyPath; } catch { throw; } return(result); }
private void LoadStrategyList() { try { bool hasAddedSeparator = false; int addedCount = 0; DirectoryInfo d = new DirectoryInfo(HunterUtilities.AbsolutePath(mHunterConfig.StrategyFolder)); FileInfo[] files = d.GetFiles(); foreach (ToolStripMenuItem t in tsStrategies) { miStrategyList.DropDownItems.Remove(t); } foreach (FileInfo f in files) { try { StrategyData data = StrategyReader.LoadStrategy(f.FullName); //出现在列表的条件:<Title>不为空 if (data.information.Title != "") { if (!hasAddedSeparator) { ToolStripSeparator s = new ToolStripSeparator(); miStrategyList.DropDownItems.Add(s); tsStrategies.Add(s); hasAddedSeparator = true; } addedCount++; ToolStripMenuItem mi = new ToolStripMenuItem(); mi.Tag = f.FullName; mi.CheckOnClick = false; mi.Click += new EventHandler(mi_Click); mi.Text = data.information.Title; miStrategyList.DropDownItems.Add(mi); tsStrategies.Add(mi); addedCount++; if (String.Compare(f.FullName, new FileInfo(HunterUtilities.AbsolutePath(mHunterConfig.CurrentStrategyFile)).FullName, true) == 0) { mi.Checked = true; } else { mi.Checked = false; } } } catch { } } } catch (DirectoryNotFoundException ex) { mHunterConsole.WriteException(ex); mHunterConsole.WriteException(new Exception("请手动更改config.xml中的策略文件路径。")); } catch (Exception ex) { mHunterConsole.WriteException(ex); } }
private void LoadPluginList() { try { bool hasAddedSeparator = false; if (!Directory.Exists(mHunterConfig.PluginFolder)) { Directory.CreateDirectory(HunterUtilities.AbsolutePath(mHunterConfig.PluginFolder)); } DirectoryInfo d = new DirectoryInfo(mHunterConfig.PluginFolder); FileInfo[] files = d.GetFiles(); foreach (ToolStripMenuItem t in tsPlugins) { miPluginList.DropDownItems.Remove(t); } foreach (FileInfo f in files) { try { if (f.Extension != ".dll") { continue; } HunterPlugin hp = new HunterPlugin(); hp.LoadDll(f.FullName); String title = hp.GetTitle(); if (!hasAddedSeparator) { ToolStripSeparator s = new ToolStripSeparator(); miPluginList.DropDownItems.Add(s); tsPlugins.Add(s); hasAddedSeparator = true; } ToolStripMenuItem mi = new ToolStripMenuItem(); mi.Tag = hp; mi.CheckOnClick = false; mi.Click += new EventHandler((object sender, EventArgs e) => { try { new Thread(new ThreadStart(() => { HunterPlugin _hp = mi.Tag as HunterPlugin; object[] parameters = HunterPlugin.CreateArguments(_hp.GetParametersString()); if (_hp != null) { _hp.Invoke(parameters); } })).Start(); } catch { } }); mi.Text = title; miPluginList.DropDownItems.Add(mi); tsPlugins.Add(mi); } catch (Exception ex) { WriteException(ex); } } } catch (DirectoryNotFoundException ex) { mHunterConsole.WriteException(ex); mHunterConsole.WriteException(new Exception("请手动更改config.xml中的策略文件路径。")); } catch (Exception ex) { mHunterConsole.WriteException(ex); } }