void pi_ErrorDataReceived(object sender, DataReceivedEventArgs e)
 {
     if (UrhoCompiler.ProcessLine(e.Data, compileErrorPublisher, errorPublisher))
     {
         pushedError = true;
     }
 }
        public void CompileFile(string file, PluginLib.ICompileHelper compileErrorPublisher, PluginLib.IErrorPublisher errorPublisher)
        {
            pushedError = false;
            this.compileErrorPublisher = compileErrorPublisher;
            this.errorPublisher = errorPublisher;
            errorsPushed = 0;
            try
            {
                string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
                path = Path.Combine(path, "bin");
                path = Path.Combine(path, "ScriptCompiler.exe");

                string parentDir = Path.GetDirectoryName(file);
                if (!Directory.Exists(parentDir))
                    return;

                List<string> compileList = new List<string>();
                foreach (string f in Directory.EnumerateFiles(parentDir))
                {
                    if (!File.Exists(f) || !Path.GetExtension(f).Equals(".as"))
                        continue;
                    compileList.Add(f);
                }
                int ct = 0;
                foreach (string f in compileList)
                {
                    // Quote spaces if necessary
                    string cmdLine = f;
                    if (cmdLine.Contains(' '))
                        cmdLine = String.Format("\"{0}\"", cmdLine);

                    // Append include directories, quoting any space containing paths
                    foreach (string s in compileErrorPublisher.GetIncludeDirs())
                        cmdLine = String.Format(file + " {1}{0}{1}", s, s.Contains(' ') ? "\"" : "");

                    ++ct;
                    compileErrorPublisher.PushOutput("────────────────────────────────────────────────────\r\n");
                    compileErrorPublisher.PushOutput(String.Format("Compiling: {0}\r\n", f, ct));
                    compileErrorPublisher.PushOutput(String.Format("{0} of {1}\r\n", ct, compileList.Count));
                    Process pi = new Process();
                    pi.StartInfo.FileName = path;
                    pi.StartInfo.Arguments = cmdLine;
                    pi.EnableRaisingEvents = true;
                    pi.StartInfo.UseShellExecute = false;
                    pi.StartInfo.CreateNoWindow = true;
                    pi.StartInfo.RedirectStandardOutput = true;
                    pi.ErrorDataReceived += pi_ErrorDataReceived;
                    pi.Start();
                    pi.WaitForExit();

                    string str = "";
                    pushedError = false;
                    while ((str = pi.StandardOutput.ReadLine()) != null)
                    {
                        if (UrhoCompiler.ProcessLine(str, compileErrorPublisher, errorPublisher))
                        {
                            pushedError = true;
                            ++errorsPushed;
                        }
                    }
                    if (pushedError) {
                        compileErrorPublisher.PushOutput(String.Format("Compiling {0} Failed\r\n", f));
                    } else {
                        compileErrorPublisher.PushOutput(String.Format("Compiling {0} Complete\r\n", f));
                    }
                }
                if (errorsPushed == 0)
                    UrhoDumpAPI.CreateDumps(compileErrorPublisher.GetProjectDirectory(), compileErrorPublisher.GetProjectSourceTree());
            }
            catch (Exception ex)
            {
                errorPublisher.PublishError(ex);
            }
        }