// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. namespace WixToolset.Core { using System; using System.Collections.Generic; using System.IO; using System.Linq; using WixToolset.Data; internal class BuildCommand : ICommand { public BuildCommand(IEnumerable sources, IDictionary preprocessorVariables, IEnumerable locFiles, string outputPath, IEnumerable cultures, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) { this.LocFiles = locFiles; this.PreprocessorVariables = preprocessorVariables; this.SourceFiles = sources; this.OutputPath = outputPath; this.Cultures = cultures; this.ContentsFile = contentsFile; this.OutputsFile = outputsFile; this.BuiltOutputsFile = builtOutputsFile; this.WixProjectFile = wixProjectFile; } public IEnumerable LocFiles { get; } private IEnumerable SourceFiles { get; } private IDictionary PreprocessorVariables { get; } private string OutputPath { get; } public IEnumerable Cultures { get; } public string ContentsFile { get; } public string OutputsFile { get; } public string BuiltOutputsFile { get; } public string WixProjectFile { get; } public int Execute() { var intermediates = CompilePhase(); var sections = intermediates.SelectMany(i => i.Sections).ToList(); var linker = new Linker(); var output = linker.Link(sections, OutputType.Product); var localizer = new Localizer(); var binder = new Binder(); binder.TempFilesLocation = Path.GetTempPath(); binder.WixVariableResolver = new WixVariableResolver(); binder.WixVariableResolver.Localizer = localizer; binder.AddExtension(new BinderFileManager()); binder.SuppressValidation = true; binder.ContentsFile = this.ContentsFile; binder.OutputsFile = this.OutputsFile; binder.BuiltOutputsFile = this.BuiltOutputsFile; binder.WixprojectFile = this.WixProjectFile; foreach (var loc in this.LocFiles) { var localization = Localizer.ParseLocalizationFile(loc, linker.TableDefinitions); binder.WixVariableResolver.Localizer.AddLocalization(localization); } binder.Bind(output, this.OutputPath); return 0; } private IEnumerable CompilePhase() { var intermediates = new List(); var preprocessor = new Preprocessor(); var compiler = new Compiler(); foreach (var sourceFile in this.SourceFiles) { var document = preprocessor.Process(sourceFile.SourcePath, this.PreprocessorVariables); var intermediate = compiler.Compile(document); intermediates.Add(intermediate); } return intermediates; } } }