private void saveMenu_Click(object sender, EventArgs e) { var name = editorTabs.SelectedTab.Text; if (!DocumentManager.HasFileName(name)) { if (DialogResult.OK == saveFileDialog.ShowDialog()) { var file = saveFileDialog.FileName; File.WriteAllText(file, editor.Text); var tabName = Path.GetFileName(file); editorTabs.SelectedTab.Text = DocumentManager.Rename(name, tabName, file); DocumentManager.UpdateSavedContent(tabName, editor.Text); saveStateTimer.Enabled = true; } } else { File.WriteAllText(DocumentManager.GetFileName(name), editor.Text); DocumentManager.UpdateSavedContent(name, editor.Text); saveStateTimer.Enabled = true; } }
public void Eval(string code, Action <Token> cb) { if (!editorTabs.SelectedTab.Text.TrimStart('*').Trim().StartsWith("new") && !IsProjectOpen) { Directory.SetCurrentDirectory(Path.GetDirectoryName(DocumentManager.GetFileName(editorTabs.SelectedTab.Text.TrimStart('*').Trim()))); } var ts = new ThreadStart(() => { Token res; var start = DateTime.Now; try { lock (ShiroLock) { res = Shiro.Eval(code); if (_showResult) { SafeWrite($"[Result] {res.ToString()}{Environment.NewLine}"); } if (_showRuntime) { SafeWrite($"[Run Duration] {DateTime.Now.Subtract(start).Milliseconds} ms"); } } cb(res); } catch (Exception ex) { SafeError(ex.Message); cb(null); } }); new Thread(ts).Start(); }
private void compileMenu_Click(object sender, EventArgs e) { //Tear down and setup the bin directory if (!IsProjectOpen) { if (editorTabs.SelectedTab.Text.TrimStart('*').Trim().StartsWith("new")) { MessageBox.Show("Please save this file before trying to compile it"); return; } else { Directory.SetCurrentDirectory(Path.GetDirectoryName(DocumentManager.GetFileName(editorTabs.SelectedTab.Text))); } } var path = Directory.GetCurrentDirectory() + "\\bin"; try { if (Directory.Exists(path)) { Directory.Delete(path, true); } Directory.CreateDirectory(path); } catch (Exception) { MessageBox.Show("Compilation failed -- it's probable that the bin directory or something in it is locked"); return; } AssemblyName[] a = Assembly.GetExecutingAssembly().GetReferencedAssemblies(); foreach (AssemblyName an in a) { if (an.FullName.ToLower().Contains("shiro")) { if (File.Exists(path + "\\Shiro.Lang.dll")) { File.Delete(path + "\\Shiro.Lang.dll"); } var shiroPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName; File.Copy(shiroPath + "\\Shiro.Lang.dll", path + "\\Shiro.Lang.dll"); } } foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory())) { if (file.EndsWith(".dll")) { File.Copy(file, file.Replace(Directory.GetCurrentDirectory(), path)); } } //Now do the compile System.CodeDom.Compiler.CompilerError ce = null; if (!IsProjectOpen) { //Single file compile, nice and easy var c = new Compiler(editorTabs.SelectedTab.Text.TrimStart('*').Trim()); c.AddShiroModule(editorTabs.SelectedTab.Text.TrimStart('*').Trim(), editor.Text); c.Compile(editorTabs.SelectedTab.Text.Split('.')[0] + ".exe", path, out ce); } else { //Project compile. Slightly trickier var pt = ProjectTree; } if (ce == null) { SafeWrite("Compile success"); } else { SafeWrite("Compile failed: " + ce.ErrorText); } }