private void LoadPlugin(string name) { Logger.LogDebug(string.Format("{0} Loading plugin {1}.", brktname, name)); if (plugins.ContainsKey(name)) { Logger.LogError(string.Format("{0} {1} plugin is already loaded.", brktname, name)); return; //throw new InvalidOperationException(string.Format("{0} {1} plugin is already loaded.", brktname, name)); } try { string text = GetPluginScriptText(name); string[] lines = text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); DirectoryInfo dir = new DirectoryInfo(Path.Combine(pluginDirectory.FullName, name)); JintPlugin plugin = new JintPlugin(dir, name, text); plugin.InstallHooks(); plugin.Invoke("On_PluginInit"); string cmdname = null; bool b = false, d = false, f = false; foreach (string line in lines) { if (line.Contains("On_Command")) { string[] spl = line.Split(Convert.ToChar(",")); cmdname = spl[1].Trim(); b = true; if (plugin.CommandList.Count == 0) { f = true; } continue; } if (cmdname != null) { if (!b) { break; } if (line.Contains("function")) { b = false; continue; } string n = line.Trim(); string l = n.ToLower(); if ((n.Contains(cmdname) && n.Contains("==")) || n.Contains("case")) { if (l.Contains("getsetting") || l.Contains("datastore")) { if (!d && f) { Logger.LogDebug("I detected the usage of custom commands in " + plugin.Name); Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList"); Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))"); Logger.LogDebug("If you have questions go to www.fougerite.com !"); d = true; } continue; } IEnumerable <string> s = null; IEnumerable <string> s2 = null; if (n.Contains("'")) { s = getBetween(l, "'", "'"); } else if (n.Contains('"'.ToString())) { s2 = getBetween(l, '"'.ToString(), '"'.ToString()); } else { if (!d && f) { Logger.LogDebug("I detected the usage of custom commands in: " + plugin.Name); Logger.LogDebug("Make sure you add the commands manually to: Plugin.CommandList"); Logger.LogDebug("Example: Plugin.CommandList.Add(ini.GetSetting(...))"); Logger.LogDebug("If you have questions go to www.fougerite.com !"); d = true; } continue; } if (s != null) { foreach (var cmd in s) { plugin.CommandList.Add(cmd); } } if (s2 != null) { foreach (var cmd in s2) { plugin.CommandList.Add(cmd); } } } } } if (d) { plugin.CommandList.Clear(); } plugins[name] = plugin; GlobalPluginCollector.GetPluginCollector().AddPlugin(name, plugin, "JavaScript2"); Logger.Log(string.Format("{0} {1} plugin by {2} V{3} was loaded successfully.", brktname, name, plugin.Author, plugin.Version)); if (!string.IsNullOrEmpty(plugin.About) && plugin.About != "undefined") { Logger.LogError(string.Format("{0} Description: {1}", brktname, plugin.About)); } } catch (Exception ex) { Logger.LogError(string.Format("{0} {1} plugin could not be loaded.", brktname, name)); Logger.LogException(ex); } }
public AdvancedTimer(JintPlugin pl) { Plugin = pl; Timers = new Dictionary <string, JintTE>(); ParallelTimers = new List <JintTE>(); }