void BatchCompiler_DoWork(object sender, DoWorkEventArgs e) { string[] files = (string[])e.Argument; BackgroundWorker worker = (BackgroundWorker)sender; int failed; string unused; foreach (string s in files) { if (worker.CancellationPending) { e.Cancel = true; break; } var compiler = new Compiler(); if (compiler.Compile(s, out unused, null, false)) failed = 0; else failed = 1; worker.ReportProgress(failed); } }
private bool Compile(TabInfo tab, out string msg, bool showMessages = true, bool preprocess = false) { msg = ""; if (Settings.outputDir == null) { if (showMessages) MessageBox.Show("No output path selected.\nPlease select your scripts directory before compiling", "Error"); return false; } Save(tab); if (tab.changed || tab.filepath == null) return false; if (string.Compare(Path.GetExtension(tab.filename), ".msg", true) == 0) { if (showMessages) MessageBox.Show("You cannot compile message files"); return false; } List<Error> errors = new List<Error>(); var compiler = new Compiler(); bool success = compiler.Compile(currentTab.filepath, out msg, errors, preprocess); foreach (ErrorType et in new ErrorType[] { ErrorType.Error, ErrorType.Warning, ErrorType.Message }) { foreach (Error e in errors) { if (e.type == et) dgvErrors.Rows.Add(e.type.ToString(), Path.GetFileName(e.fileName), e.line, e); } } if (!success) { tabControl2.SelectedIndex = 1; } else { parserLabel.Text = "Successfully compiled " + currentTab.filename + " at " + DateTime.Now.ToString(); } if (!success && Settings.warnOnFailedCompile) { if (showMessages) MessageBox.Show("Script " + tab.filename + " failed to compile. See the output window for details", "Error"); } return success; }