private static string LoadFromFile(string filename, bool wait, bool loop, bool run, bool autostart) { string status = "Loaded"; string classname = Path.GetFileNameWithoutExtension(filename); string fullpath = Path.Combine(Assistant.Engine.RootPath, "Scripts", filename); string text = null; if (File.Exists(fullpath)) { text = File.ReadAllText(fullpath); } else { return("ERROR: file not found"); } Scripts.EnhancedScript script = new Scripts.EnhancedScript(filename, text, wait, loop, run, autostart); string result = script.Create(null); if (result == "Created") { Scripts.EnhancedScripts.TryAdd(filename, script); } else { status = "ERROR: " + result; } return(status); }
private void buttonScriptRefresh_Click(object sender, EventArgs e) { if (scriptTable != null && scriptTable.Rows.Count > 0 && scriptlistView.SelectedItems.Count == 1) { DataRow row = scriptTable.Rows[scriptlistView.SelectedItems[0].Index]; string scriptname = row[0].ToString(); Scripts.EnhancedScript script = Scripts.Search(scriptname); if (script != null) { string fullpath = Path.Combine(Assistant.Engine.RootPath, "Scripts", scriptname); if (File.Exists(fullpath) && Scripts.EnhancedScripts.ContainsKey(scriptname)) { string text = File.ReadAllText(fullpath); bool loop = script.Loop; bool wait = script.Wait; bool run = script.Run; bool autostart = script.AutoStart; bool isRunning = script.IsRunning; if (isRunning) { script.Stop(); } Scripts.EnhancedScript reloaded = new Scripts.EnhancedScript(scriptname, text, wait, loop, run, autostart); reloaded.Create(null); Scripts.EnhancedScripts[scriptname] = reloaded; if (isRunning) { reloaded.Start(); } } } } }