示例#1
0
        /// <summary>
        /// </summary>
        /// <returns></returns>
        public BuildLaunchMode DeepClone()
        {
            BuildLaunchMode other = (BuildLaunchMode)MemberwiseClone();

            other.Variables = new List <BuildLaunchVariable>();
            foreach (BuildLaunchVariable variable in Variables)
            {
                other.Variables.Add(variable.ShallowClone());
            }

            other.Arguments = new List <BuildLaunchArgument>();
            foreach (BuildLaunchArgument argument in Arguments)
            {
                other.Arguments.Add(argument.ShallowClone());
            }

            other.InstallSteps = new List <BuildInstallStep>();
            foreach (BuildInstallStep argument in InstallSteps)
            {
                other.InstallSteps.Add(argument.ShallowClone());
            }

            return(other);
        }
示例#2
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);
        }
示例#3
0
        /// <summary>
        ///     Evaluates all conditions and returns a list of launch modes that are valid for execution.
        /// </summary>
        /// <returns>List of launch modes valid for execution.</returns>
        public List <BuildLaunchMode> Compile()
        {
            List <BuildLaunchMode> Result = new List <BuildLaunchMode>();

            // If we are defined by a script, compile it.
            if (ScriptSource.Length > 0)
            {
                try
                {
                    ScriptOptions Options = ScriptOptions.Default
                                            .WithImports("System", "System.Text.RegularExpressions", "System.IO", "System.Math", "System.ComponentModel", "System.ComponentModel.DataAnnotations", "BuildSync.Core.Scripting", "BuildSync.Core.Utils")
                                            .WithReferences("System", "System.Data", "System.Windows.Forms", typeof(ScriptBuild).Assembly.Location)
                                            .WithAllowUnsafe(false)
                                            .WithOptimizationLevel(OptimizationLevel.Debug);

                    Script <object> script = CSharpScript.Create(ScriptSource, Options);
                    script.Compile();
                    using (var Stream = new MemoryStream())
                    {
                        var EmitResult = script.GetCompilation().Emit(Stream);
                        if (EmitResult.Success)
                        {
                            Stream.Seek(0, SeekOrigin.Begin);
                            Assembly LoadedAssembly = Assembly.Load(Stream.ToArray());

                            foreach (Type Type in LoadedAssembly.GetTypes())
                            {
                                if (typeof(ScriptLaunchMode).IsAssignableFrom(Type))
                                {
                                    ScriptLaunchMode LaunchMode = Activator.CreateInstance(Type) as ScriptLaunchMode;
                                    if (LaunchMode.IsAvailable)
                                    {
                                        BuildLaunchMode mode = new BuildLaunchMode();
                                        mode.InitFromScript(LaunchMode);

                                        Result.Add(mode);
                                    }
                                }
                            }
                        }
                        else
                        {
                            string Errors = string.Join("\n", EmitResult.Diagnostics.Where(diagnostic => diagnostic.IsWarningAsError || diagnostic.Severity == DiagnosticSeverity.Error).Select(d => $"{d.Id}: {d.GetMessage()}"));

                            Console.WriteLine("Failed to compile build settings script file.");
                            Console.WriteLine(Errors);

                            throw new InvalidOperationException("Failed to compile script: " + Errors);
                        }
                    }
                }
                catch (CompilationErrorException e)
                {
                    string Errors = string.Join(Environment.NewLine, e.Diagnostics);

                    Console.WriteLine("Failed to compile build settings script file.");
                    Console.WriteLine(Errors);

                    throw new InvalidOperationException("Failed to compile build settings script file with errors:\n\n" + Errors);
                }
            }
            else
            {
                foreach (BuildLaunchMode Mode in Modes)
                {
                    if (Evaluate(Mode.Condition, null))
                    {
                        BuildLaunchMode NewMode = Mode.DeepClone();

                        foreach (BuildLaunchVariable Var in NewMode.Variables)
                        {
                            Var.ConditionResult = Evaluate(Var.Condition, null);
                        }

                        Result.Add(NewMode);
                    }
                }
            }

            return(Result);
        }