Esempio n. 1
0
        /// <summary>
        /// </summary>
        /// <param name="Path"></param>
        public static void WriteDummy(string Path)
        {
            BuildSettings Settings = new BuildSettings();

            BuildLaunchMode Mode = new BuildLaunchMode();

            Mode.Name             = "Launch Game";
            Mode.Executable       = @"Data\game.exe";
            Mode.WorkingDirectory = @"Data";
            Mode.Condition        = "Environment.GetEnvironmentVariable(\"PATH\") != null && Directory.Exists(\"C:\\\\\")";
            Mode.Variables.Add(new BuildLaunchVariable {
                Name = "HIDDEN_INT_TEST", FriendlyName = "Hidden Int Test", FriendlyDescription = "Should not show, condition should evaluate to false.", DataType = BuildLaunchVariableDataType.Int, Condition = "false", Value = "0", MinValue = 0, MaxValue = 100
            });
            Mode.Variables.Add(new BuildLaunchVariable {
                Name = "INT_TEST", FriendlyName = "Int Test", FriendlyDescription = "Test of integer variables.", DataType = BuildLaunchVariableDataType.Int, Condition = "true", Value = "0", MinValue = 0, MaxValue = 100
            });
            Mode.Variables.Add(new BuildLaunchVariable {
                Name = "BOOL_TEST", FriendlyName = "Bool Test", FriendlyDescription = "Test of bool variables.", DataType = BuildLaunchVariableDataType.Bool, Condition = "true", Value = "true"
            });
            Mode.Variables.Add(new BuildLaunchVariable {
                Name = "STRING_OPTIONS_TEST", FriendlyName = "String Options Test", FriendlyDescription = "Test of string options variables.", DataType = BuildLaunchVariableDataType.String, Condition = "true", Value = "main", Options = new List <string> {
                    "main", "debug", "something"
                }
            });
            Mode.Variables.Add(new BuildLaunchVariable {
                Name = "STRING_TEST", FriendlyName = "String Test", FriendlyDescription = "Test of string variables.", DataType = BuildLaunchVariableDataType.String, Condition = "true", Value = "main"
            });
            Mode.Variables.Add(new BuildLaunchVariable {
                Name = "FLOAT_TEST", FriendlyName = "Float Test", FriendlyDescription = "Test of float variables.", DataType = BuildLaunchVariableDataType.Float, Condition = "true", Value = "0.1", MinValue = 0.1f, MaxValue = 1.0f
            });
            Mode.Arguments.Add(new BuildLaunchArgument {
                Value = "-bool_test", Condition = "%BOOL_TEST%"
            });
            Mode.Arguments.Add(new BuildLaunchArgument {
                Value = "-int_test=%INT_TEST%", Condition = "%INT_TEST% > 0"
            });
            Mode.Arguments.Add(new BuildLaunchArgument {
                Value = "-float_test=%FLOAT_TEST%", Condition = "%FLOAT_TEST% > 0.1"
            });
            Mode.Arguments.Add(new BuildLaunchArgument {
                Value = "-string_test=\"%STRING_TEST%\"", Condition = "\"%STRING_TEST%\" != \"\""
            });
            Mode.Arguments.Add(new BuildLaunchArgument {
                Value = "-string_options_test=%STRING_OPTIONS_TEST%", Condition = "\"%STRING_OPTIONS_TEST%\" != \"\""
            });

            BuildInstallStep Step = new BuildInstallStep();

            Step.Executable       = "exepath";
            Step.Arguments        = "args";
            Step.WorkingDirectory = "workingdir";
            Mode.InstallSteps.Add(Step);

            Settings.Modes.Add(Mode);

            Stopwatch watch = new Stopwatch();

            watch.Start();

            List <BuildLaunchMode> CompiledModes = Settings.Compile();

            watch.Stop();
            Logger.Log(LogLevel.Info, LogCategory.Main, "Took {0}ms to compile", watch.ElapsedMilliseconds);

            foreach (BuildLaunchMode CompiledMode in CompiledModes)
            {
                watch.Restart();

                string Args = CompiledMode.CompileArguments();
                Logger.Log(LogLevel.Info, LogCategory.Main, "Arguments: {0}", Args);

                watch.Stop();
                Logger.Log(LogLevel.Info, LogCategory.Main, "Took {0}ms to compile arguments", watch.ElapsedMilliseconds);
            }

            Settings.Save(Path);
        }
Esempio n. 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);
        }