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);
     }
 }
Ejemplo n.º 2
0
        public TabInfo Open(string file, OpenType type, bool addToMRU = true, bool alwaysNew = false)
        {
            if (type == OpenType.File) {
                if (!Path.IsPathRooted(file)) {
                    file = Path.GetFullPath(file);
                }
                //Add this file to the recent files list
                if (addToMRU) {
                    Settings.AddRecentFile(file);
                }
                UpdateRecentList();
                //If this is an int, decompile
                if (string.Compare(Path.GetExtension(file), ".int", true) == 0) {
                    var compiler = new Compiler();
                    string decomp = compiler.Decompile(file);
                    if (decomp == null) {
                        MessageBox.Show("Decompilation of '" + file + "' was not successful", "Error");
                        return null;
                    } else {
                        file = decomp;
                        type = OpenType.Text;
                    }
                } else {
                    //Check if the file is already open
                    for (int i = 0; i < tabs.Count; i++) {
                        if (string.Compare(tabs[i].filepath, file, true) == 0) {
                            tabControl1.SelectTab(i);
                            return tabs[i];
                        }
                    }
                }
            }
            //Create the text editor and set up the tab
            ICSharpCode.TextEditor.TextEditorControl te = new ICSharpCode.TextEditor.TextEditorControl();
            te.ShowVRuler = false;
            te.Document.FoldingManager.FoldingStrategy = new CodeFolder();
            te.IndentStyle = IndentStyle.Smart;
            te.ConvertTabsToSpaces = Settings.tabsToSpaces;
            te.TabIndent = Settings.tabSize;
            te.Document.TextEditorProperties.IndentationSize = Settings.tabSize;
            if (type == OpenType.File)
                te.LoadFile(file, false, true);
            else if (type == OpenType.Text)
                te.Text = file;
            if (type == OpenType.File && string.Compare(Path.GetExtension(file), ".msg", true) == 0)
                te.SetHighlighting("msg");
            else
                te.SetHighlighting("ssl"); // Activate the highlighting, use the name from the SyntaxDefinition node.
            te.TextChanged += textChanged;
            te.ActiveTextAreaControl.TextArea.MouseDown += delegate(object a1, MouseEventArgs a2) {
                if (a2.Button == MouseButtons.Left)
                    UpdateEditorToolStripMenu();
                lbAutocomplete.Hide();
            };
            te.ActiveTextAreaControl.TextArea.KeyPress += KeyPressed;
            te.HorizontalScroll.Visible = false;

            te.ActiveTextAreaControl.TextArea.PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs a2) {
                if (lbAutocomplete.Visible) {
                    if ((a2.KeyCode == Keys.Down || a2.KeyCode == Keys.Up || a2.KeyCode == Keys.Tab)) {
                        lbAutocomplete.Focus();
                        lbAutocomplete.SelectedIndex = 0;
                    } else if (a2.KeyCode == Keys.Escape) {
                        lbAutocomplete.Hide();
                    }
                } else {
                    if (toolTipAC.Active && a2.KeyCode != Keys.Left && a2.KeyCode != Keys.Right)
                        toolTipAC.Hide(panel1);
                }
            };

            TabInfo ti = new TabInfo();
            ti.textEditor = te;
            ti.changed = false;
            if (type == OpenType.File && !alwaysNew) {
                ti.filepath = file;
                ti.filename = Path.GetFileName(file);
            } else {
                ti.filepath = null;
                ti.filename = unsaved;
            }
            ti.index = tabControl1.TabCount;
            te.ActiveTextAreaControl.TextArea.ToolTipRequest += new ToolTipRequestEventHandler(TextArea_ToolTipRequest);
            te.ContextMenuStrip = editorMenuStrip;

            tabs.Add(ti);
            TabPage tp = new TabPage(ti.filename);
            tp.Controls.Add(te);
            te.Dock = DockStyle.Fill;

            tabControl1.TabPages.Add(tp);
            if (type == OpenType.File & !alwaysNew) {
                tp.ToolTipText = ti.filepath;
                System.String ext = Path.GetExtension(file).ToLower();
                if (ext == ".ssl" || ext == ".h") {
                    ti.shouldParse = true;
                    ti.needsParse = true;
                    if (Settings.autoOpenMsgs && ti.filepath != null)
                        AssossciateMsg(ti, false);
                }
            }
            if (tabControl1.TabPages.Count > 1) {
                tabControl1.SelectTab(tp);
            } else {
                tabControl1_Selected(null, null);
            }
            return ti;
        }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 private void bwSyntaxParser_DoWork(object sender, System.ComponentModel.DoWorkEventArgs eventArgs)
 {
     WorkerArgs args = (WorkerArgs)eventArgs.Argument;
     var compiler = new Compiler();
     args.tab.parseInfo = compiler.Parse(args.text, args.tab.filepath);
     eventArgs.Result = args.tab;
     parserRunning = false;
 }