public void CompileFile(string file, PluginLib.ICompileHelper compileErrorPublisher, PluginLib.IErrorPublisher errorPublisher) { pushedError = false; this.compileErrorPublisher = compileErrorPublisher; this.errorPublisher = errorPublisher; try { string path = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location); path = Path.Combine(path, "bin"); path = Path.Combine(path, "ScriptCompiler.exe"); // Check for spaces in paths and quote any paths that need to be quoted if (file.Contains(' ')) { file = String.Format("\"{0}\"", file); } foreach (string s in compileErrorPublisher.GetIncludeDirs()) { file = String.Format(file + " {1}{0}{1}", s, s.Contains(' ') ? "\"" : ""); } Process pi = new Process(); pi.StartInfo.FileName = path; pi.StartInfo.Arguments = file; pi.EnableRaisingEvents = true; pi.StartInfo.WorkingDirectory = compileErrorPublisher.GetProjectDirectory(); pi.StartInfo.UseShellExecute = false; pi.StartInfo.CreateNoWindow = true; pi.ErrorDataReceived += pi_ErrorDataReceived; pi.OutputDataReceived += pi_OutputDataReceived; pi.StartInfo.RedirectStandardError = true; pi.StartInfo.RedirectStandardOutput = true; pi.Start(); pi.BeginOutputReadLine(); pi.BeginErrorReadLine(); pi.WaitForExit(); if (pushedError) { compileErrorPublisher.PushOutput(String.Format("Compiling {0} Failed\r\n", file)); } else { compileErrorPublisher.PushOutput(String.Format("Compiling {0} Complete\r\n", file)); UrhoDumpAPI.CreateDumps(compileErrorPublisher.GetProjectDirectory(), compileErrorPublisher.GetProjectSourceTree()); } } catch (Exception ex) { errorPublisher.PublishError(ex); } }
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); } }