aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.BuildTasks/Torch.cs
blob: e18ed315efe2097ea51793c8f934342a49fedf55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// 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.BuildTasks
{
    using System;
    using System.Diagnostics;
    using System.Globalization;
    using System.IO;
    using System.Text;

    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;

    /// <summary>
    /// An MSBuild task to run the WiX transform generator.
    /// </summary>
    public sealed class Torch : WixToolTask
    {
        private const string TorchToolName = "Torch.exe";

        private bool adminImage;
        private ITaskItem baselineFile;
        private string binaryExtractionPath;
        private bool inputIsXml;
        private bool leaveTemporaryFiles;
        private bool outputAsXml;
        private ITaskItem outputFile;
        private bool preserveUnmodifiedContent;
        private string suppressTransformErrorFlags;
        private string transformValidationFlags;
        private string transformValidationType;
        private ITaskItem updateFile;

        public bool AdminImage
        {
            get { return this.adminImage; }
            set { this.adminImage = value; }
        }


        [Required]
        public ITaskItem BaselineFile
        {
            get { return this.baselineFile; }
            set { this.baselineFile = value; }
        }

        public string BinaryExtractionPath
        {
            get { return this.binaryExtractionPath; }
            set { this.binaryExtractionPath = value; }
        }

        public bool LeaveTemporaryFiles
        {
            get { return this.leaveTemporaryFiles; }
            set { this.leaveTemporaryFiles = value; }
        }

        public bool InputIsXml
        {
            get { return this.inputIsXml; }
            set { this.inputIsXml = value; }
        }

        public bool OutputAsXml
        {
            get { return this.outputAsXml; }
            set { this.outputAsXml = value; }
        }

        public bool PreserveUnmodifiedContent
        {
            get { return this.preserveUnmodifiedContent; }
            set { this.preserveUnmodifiedContent = value; }
        }

        [Required]
        [Output]
        public ITaskItem OutputFile
        {
            get { return this.outputFile; }
            set { this.outputFile = value; }
        }

        public string SuppressTransformErrorFlags
        {
            get { return this.suppressTransformErrorFlags; }
            set { this.suppressTransformErrorFlags = value; }
        }

        public string TransformValidationType
        {
            get { return this.transformValidationType; }
            set { this.transformValidationType = value; }
        }

        public string TransformValidationFlags
        {
            get { return this.transformValidationFlags; }
            set { this.transformValidationFlags = value; }
        }

        [Required]
        public ITaskItem UpdateFile
        {
            get { return this.updateFile; }
            set { this.updateFile = value; }
        }

        /// <summary>
        /// Get the name of the executable.
        /// </summary>
        /// <remarks>The ToolName is used with the ToolPath to get the location of torch.exe.</remarks>
        /// <value>The name of the executable.</value>
        protected override string ToolName
        {
            get { return TorchToolName; }
        }

        /// <summary>
        /// Get the path to the executable. 
        /// </summary>
        /// <remarks>GetFullPathToTool is only called when the ToolPath property is not set (see the ToolName remarks above).</remarks>
        /// <returns>The full path to the executable or simply torch.exe if it's expected to be in the system path.</returns>
        protected override string GenerateFullPathToTool()
        {
            // If there's not a ToolPath specified, it has to be in the system path.
            if (String.IsNullOrEmpty(this.ToolPath))
            {
                return TorchToolName;
            }

            return Path.Combine(Path.GetFullPath(this.ToolPath), TorchToolName);
        }

        /// <summary>
        /// Builds a command line from options in this task.
        /// </summary>
        protected override void BuildCommandLine(WixCommandLineBuilder commandLineBuilder)
        {
            base.BuildCommandLine(commandLineBuilder);

            commandLineBuilder.AppendIfTrue("-notidy", this.LeaveTemporaryFiles);
            commandLineBuilder.AppendIfTrue("-xo", this.OutputAsXml);
            commandLineBuilder.AppendIfTrue("-xi", this.InputIsXml);
            commandLineBuilder.AppendIfTrue("-p", this.PreserveUnmodifiedContent);
            commandLineBuilder.AppendTextIfNotNull(this.AdditionalOptions);
            commandLineBuilder.AppendFileNameIfNotNull(this.BaselineFile);
            commandLineBuilder.AppendFileNameIfNotNull(this.UpdateFile);
            commandLineBuilder.AppendSwitchIfNotNull("-out ", this.OutputFile);
            commandLineBuilder.AppendIfTrue("-a", this.adminImage);
            commandLineBuilder.AppendSwitchIfNotNull("-x ", this.BinaryExtractionPath);
            commandLineBuilder.AppendSwitchIfNotNull("-serr ", this.SuppressTransformErrorFlags);
            commandLineBuilder.AppendSwitchIfNotNull("-t ", this.TransformValidationType);
            commandLineBuilder.AppendSwitchIfNotNull("-val ", this.TransformValidationFlags);
        }
    }
}