Beispiel #1
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public string CompileArguments()
        {
            string Result = "";

            foreach (BuildLaunchArgument Argument in Arguments)
            {
                if (BuildSettings.Evaluate(Argument.Condition, Variables))
                {
                    string Escape = BuildSettings.ExpandArguments(Argument.Value, Variables);
                    if (Result.Length > 0)
                    {
                        Result += " ";
                    }

                    Result += Escape;
                }
            }

            return(Result);
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        private bool InstallStep(string LocalFolder, ref string ResultMessage, BuildInstallStep Step)
        {
            string ExePath = BuildSettings.ExpandArguments(Step.Executable, Variables);

            if (!Path.IsPathRooted(ExePath))
            {
                ExePath = Path.Combine(LocalFolder, ExePath);
            }

            string WorkingDir = BuildSettings.ExpandArguments(Step.WorkingDirectory, Variables);

            if (WorkingDir.Length == 0)
            {
                WorkingDir = Path.GetDirectoryName(ExePath);
            }
            else
            {
                if (!Path.IsPathRooted(WorkingDir))
                {
                    WorkingDir = Path.Combine(LocalFolder, WorkingDir);
                }
            }

#if SHIPPING
            if (!File.Exists(ExePath))
            {
                ResultMessage = "Could not find executable, expected to be located at: " + ExePath;
                return(false);
            }

            if (!Directory.Exists(WorkingDir))
            {
                ResultMessage = "Could not find working directory, expected at: " + WorkingDir;
                return(false);
            }
#endif

            string Arguments = BuildSettings.ExpandArguments(Step.Arguments, Variables);

            Logger.Log(LogLevel.Info, LogCategory.Main, "Executing: {0} {1}", ExePath, Arguments);

            try
            {
                ProcessStartInfo StartInfo = new ProcessStartInfo();
                StartInfo.FileName               = ExePath;
                StartInfo.WorkingDirectory       = WorkingDir;
                StartInfo.Arguments              = Arguments;
                StartInfo.RedirectStandardOutput = true;
                StartInfo.RedirectStandardError  = true;
                StartInfo.UseShellExecute        = false;
                StartInfo.CreateNoWindow         = true;

                Process process = Process.Start(StartInfo);
                ChildProcessTracker.AddProcess(process);

                process.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { Logger.Log(LogLevel.Info, LogCategory.Main, "{0}", e.Data); };

                process.ErrorDataReceived += delegate(object sender, DataReceivedEventArgs e) { Logger.Log(LogLevel.Info, LogCategory.Main, "{0}", e.Data); };

                process.BeginErrorReadLine();
                process.BeginOutputReadLine();

                process.WaitForExit();

                if (process.ExitCode != 0 && !Step.IgnoreErrors)
                {
                    ResultMessage = "Install process exited with error code " + process.ExitCode;
                    return(false);
                }
            }
            catch (Exception Ex)
            {
                ResultMessage = "Install process exited with error: " + Ex.Message;
                return(false);
            }

            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// </summary>
        public bool Launch(string LocalFolder, ref string ResultMessage)
        {
            if (ScriptInstance != null)
            {
                CopyArgumentsToScript();
                if (!ScriptInstance.Launch(MakeScriptBuild()))
                {
                    ResultMessage = "Script failed to launch, check console output window for details.";
                    return(false);
                }
                return(true);
            }
            else
            {
                // This is now done in launch dialog or manifest downloader.

                /*if (InstallSteps.Count != 0)
                 * {
                 *  if (!Install(LocalFolder, ref ResultMessage))
                 *  {
                 *      return false;
                 *  }
                 * }*/

                string ExePath = BuildSettings.ExpandArguments(Executable, Variables);
                if (!Path.IsPathRooted(ExePath))
                {
                    ExePath = Path.Combine(LocalFolder, ExePath);
                }

                string WorkingDir = BuildSettings.ExpandArguments(WorkingDirectory, Variables);
                if (WorkingDir.Length == 0)
                {
                    WorkingDir = Path.GetDirectoryName(ExePath);
                }
                else
                {
                    if (!Path.IsPathRooted(WorkingDir))
                    {
                        WorkingDir = Path.Combine(LocalFolder, WorkingDir);
                    }
                }

#if SHIPPING
                if (!File.Exists(ExePath))
                {
                    ResultMessage = "Could not find executable, expected to be located at: " + ExePath;
                    return(false);
                }

                if (!Directory.Exists(WorkingDir))
                {
                    ResultMessage = "Could not find working directory, expected at: " + WorkingDir;
                    return(false);
                }
#endif

                string CompiledArguments = "";
                try
                {
                    CompiledArguments = CompileArguments();
                }
                catch (InvalidOperationException Ex)
                {
                    ResultMessage = "Error encountered while evaluating launch settings:\n\n" + Ex.Message;
                    return(false);
                }

                Logger.Log(LogLevel.Info, LogCategory.Main, "Executing: {0} {1}", ExePath, CompiledArguments);

                try
                {
                    ProcessStartInfo StartInfo = new ProcessStartInfo();
                    StartInfo.FileName         = ExePath;
                    StartInfo.WorkingDirectory = WorkingDir;
                    StartInfo.Arguments        = CompiledArguments;
                    //StartInfo.RedirectStandardOutput = true;
                    //StartInfo.RedirectStandardError = true;
                    StartInfo.UseShellExecute = false;
                    StartInfo.CreateNoWindow  = true;

                    Process process = Process.Start(StartInfo);
                    ChildProcessTracker.AddProcess(process);
                    //process.WaitForExit();

                    /*process.OutputDataReceived += delegate (object sender, DataReceivedEventArgs e)
                     * {
                     *  Logger.Log(LogLevel.Info, LogCategory.Main, "{0}", e.Data);
                     * };
                     *
                     * process.ErrorDataReceived += delegate (object sender, DataReceivedEventArgs e)
                     * {
                     *  Logger.Log(LogLevel.Info, LogCategory.Main, "{0}", e.Data);
                     * };
                     *
                     * process.BeginErrorReadLine();
                     * process.BeginOutputReadLine();*/
                }
                catch (Exception Ex)
                {
                    ResultMessage = "Failed to start executable with error:\n\n" + Ex.Message;
                    return(false);
                }
            }

            return(true);
        }