private static ExecutionCommand CreateExecutionCommand(NMEProject project, NMEProjectConfiguration configuration)
        {
            string exe  = "haxelib";
            string args = "run nme run \"" + project.TargetNMMLFile + "\" " + configuration.Platform.ToLower();

            if (configuration.DebugMode)
            {
                args += " -debug";
            }

            if (project.AdditionalArguments != "")
            {
                args += " " + project.AdditionalArguments;
            }

            if (configuration.AdditionalArguments != "")
            {
                args += " " + configuration.AdditionalArguments;
            }

            NativeExecutionCommand cmd = new NativeExecutionCommand(exe);

            cmd.Arguments        = args;
            cmd.WorkingDirectory = project.BaseDirectory.FullPath;

            return(cmd);
        }
        static void ParserOutputFile(NMEProject project, BuildResult result, StringBuilder output, string filename)
        {
            StreamReader reader = File.OpenText(filename);

            string line;

            while ((line = reader.ReadLine()) != null)
            {
                output.AppendLine(line);

                line = line.Trim();
                if (line.Length == 0 || line.StartsWith("\t"))
                {
                    continue;
                }

                BuildError error = CreateErrorFromString(project, line);
                if (error != null)
                {
                    result.Append(error);
                }
            }

            reader.Close();
        }
        public static string GetHXMLData(NMEProject project, NMEProjectConfiguration configuration)
        {
            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName               = "haxelib";
            info.Arguments              = "run nme update \"" + project.TargetNMMLFile + "\" " + configuration.Platform.ToLower() + " " + project.AdditionalArguments + " " + configuration.AdditionalArguments;
            info.UseShellExecute        = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            info.WorkingDirectory       = project.BaseDirectory;
            //info.WindowStyle = ProcessWindowStyle.Hidden;
            info.CreateNoWindow = true;

            using (Process process = Process.Start(info))
            {
                process.WaitForExit();
            }

            info.Arguments = "run nme display \"" + project.TargetNMMLFile + "\" " + configuration.Platform.ToLower() + " " + project.AdditionalArguments + " " + configuration.AdditionalArguments;

            using (Process process = Process.Start(info))
            {
                string data = process.StandardOutput.ReadToEnd();
                process.WaitForExit();
                return(data.Replace(Environment.NewLine, " "));
            }
        }
        public void Load(NMEProject project)
        {
            mProject = project;

            TargetNMMLFileEntry.Text      = mProject.TargetNMMLFile;
            AdditionalArgumentsEntry.Text = mProject.AdditionalArguments;
        }
		public void Load (NMEProject project)
		{
			mProject = project;
			
			TargetNMMLFileEntry.Text = mProject.TargetNMMLFile;
			AdditionalArgumentsEntry.Text = mProject.AdditionalArguments;
		}
        public static bool CanRun(NMEProject project, NMEProjectConfiguration configuration, ExecutionContext context)
        {
            ExecutionCommand cmd = CreateExecutionCommand(project, configuration);

            if (cmd == null)
            {
                return(false);
            }
            return(context.ExecutionHandler.CanExecute(cmd));
        }
        static BuildResult ParseOutput(NMEProject project, string stderr)
        {
            BuildResult result = new BuildResult();

            StringBuilder output = new StringBuilder();

            ParserOutputFile(project, result, output, stderr);

            result.CompilerOutput = output.ToString();

            return(result);
        }
        public static BuildResult Compile(NMEProject project, NMEProjectConfiguration configuration, IProgressMonitor monitor)
        {
            string args = "run nme build \"" + project.TargetNMMLFile + "\" " + configuration.Platform.ToLower();

            if (configuration.DebugMode)
            {
                args += " -debug";
            }

            if (project.AdditionalArguments != "")
            {
                args += " " + project.AdditionalArguments;
            }

            if (configuration.AdditionalArguments != "")
            {
                args += " " + configuration.AdditionalArguments;
            }

            string error    = "";
            int    exitCode = DoCompilation("haxelib", args, project.BaseDirectory, monitor, ref error);

            BuildResult result = ParseOutput(project, error);

            if (result.CompilerOutput.Trim().Length != 0)
            {
                monitor.Log.WriteLine(result.CompilerOutput);
            }

            if (result.ErrorCount == 0 && exitCode != 0)
            {
                string errorMessage = File.ReadAllText(error);
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    result.AddError(errorMessage);
                }
                else
                {
                    result.AddError("Build failed. Go to \"Build Output\" for more information");
                }
            }

            FileService.DeleteFile(error);
            return(result);
        }
        public static void Clean(NMEProject project, NMEProjectConfiguration configuration, IProgressMonitor monitor)
        {
            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName               = "haxelib";
            info.Arguments              = "run nme clean \"" + project.TargetNMMLFile + "\" " + configuration.Platform.ToLower() + " " + project.AdditionalArguments + " " + configuration.AdditionalArguments;
            info.UseShellExecute        = false;
            info.RedirectStandardOutput = true;
            info.RedirectStandardError  = true;
            info.WorkingDirectory       = project.BaseDirectory;
            //info.WindowStyle = ProcessWindowStyle.Hidden;
            info.CreateNoWindow = true;

            using (Process process = Process.Start(info))
            {
                process.WaitForExit();
            }
        }
        public static void Run(NMEProject project, NMEProjectConfiguration configuration, IProgressMonitor monitor, ExecutionContext context)
        {
            ExecutionCommand cmd = CreateExecutionCommand(project, configuration);

            IConsole console;

            if (configuration.ExternalConsole)
            {
                console = context.ExternalConsoleFactory.CreateConsole(false);
            }
            else
            {
                console = context.ConsoleFactory.CreateConsole(false);
            }

            AggregatedOperationMonitor operationMonitor = new AggregatedOperationMonitor(monitor);

            try
            {
                if (!context.ExecutionHandler.CanExecute(cmd))
                {
                    monitor.ReportError(String.Format("Cannot execute '{0}'.", cmd.CommandString), null);
                    return;
                }

                IProcessAsyncOperation operation = context.ExecutionHandler.Execute(cmd, console);

                operationMonitor.AddOperation(operation);
                operation.WaitForCompleted();

                monitor.Log.WriteLine("Player exited with code {0}.", operation.ExitCode);
            }
            catch (Exception)
            {
                monitor.ReportError(String.Format("Error while executing '{0}'.", cmd.CommandString), null);
            }
            finally
            {
                operationMonitor.Dispose();
                console.Dispose();
            }
        }
        private static BuildError CreateErrorFromString(NMEProject project, string text)
        {
            Match match = mErrorIgnore.Match(text);

            if (match.Success)
            {
                return(null);
            }

            match = mErrorFull.Match(text);
            if (!match.Success)
            {
                match = mErrorCmdLine.Match(text);
            }
            if (!match.Success)
            {
                match = mErrorFileChar.Match(text);
            }
            if (!match.Success)
            {
                match = mErrorFileChars.Match(text);
            }
            if (!match.Success)
            {
                match = mErrorFile.Match(text);
            }

            if (!match.Success)
            {
                match = mErrorSimple.Match(text);
            }
            if (!match.Success)
            {
                return(null);
            }

            int n;

            BuildError error = new BuildError();

            error.FileName  = match.Result("${file}") ?? "";
            error.IsWarning = match.Result("${level}").ToLower() == "warning";
            error.ErrorText = match.Result("${message}");

            if (error.FileName == "${file}")
            {
                error.FileName = "";
            }
            else
            {
                if (!File.Exists(error.FileName))
                {
                    if (File.Exists(Path.GetFullPath(error.FileName)))
                    {
                        error.FileName = Path.GetFullPath(error.FileName);
                    }
                    else
                    {
                        error.FileName = Path.Combine(project.BaseDirectory, error.FileName);
                    }
                }
            }

            if (Int32.TryParse(match.Result("${line}"), out n))
            {
                error.Line = n;
            }
            else
            {
                error.Line = 0;
            }

            if (Int32.TryParse(match.Result("${column}"), out n))
            {
                error.Column = n + 1;               //haxe counts zero based
            }
            else
            {
                error.Column = -1;
            }

            return(error);
        }