diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-11-11 01:45:59 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-11-11 01:45:59 -0800 |
| commit | 9f8cb5374481b6c8a06eb2739858332350f72666 (patch) | |
| tree | 4b09b90d8a516cb5e7d8203759bd2489b6a5d20c /src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs | |
| parent | 2bb37beda887d120a0ddabf874ad25357101faa1 (diff) | |
| download | wix-9f8cb5374481b6c8a06eb2739858332350f72666.tar.gz wix-9f8cb5374481b6c8a06eb2739858332350f72666.tar.bz2 wix-9f8cb5374481b6c8a06eb2739858332350f72666.zip | |
Additional IR updates
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs new file mode 100644 index 00000000..85b3b25a --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs | |||
| @@ -0,0 +1,230 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.Core.WindowsInstaller.Bind | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Linq; | ||
| 7 | using WixToolset.Core.Native; | ||
| 8 | using WixToolset.Data; | ||
| 9 | using WixToolset.Data.Rows; | ||
| 10 | using WixToolset.Data.Tuples; | ||
| 11 | |||
| 12 | internal class CreateOutputFromIRCommand | ||
| 13 | { | ||
| 14 | public CreateOutputFromIRCommand(IntermediateSection section, TableDefinitionCollection tableDefinitions) | ||
| 15 | { | ||
| 16 | this.Section = section; | ||
| 17 | this.TableDefinitions = tableDefinitions; | ||
| 18 | } | ||
| 19 | |||
| 20 | private TableDefinitionCollection TableDefinitions { get; } | ||
| 21 | |||
| 22 | private IntermediateSection Section { get; } | ||
| 23 | |||
| 24 | public Output Output { get; private set; } | ||
| 25 | |||
| 26 | public void Execute() | ||
| 27 | { | ||
| 28 | var output = new Output(this.Section.Tuples.First().SourceLineNumbers); | ||
| 29 | output.Codepage = this.Section.Codepage; | ||
| 30 | output.Type = SectionTypeToOutputType(this.Section.Type); | ||
| 31 | |||
| 32 | this.AddSectionToOutput(this.Section, output); | ||
| 33 | |||
| 34 | this.Output = output; | ||
| 35 | } | ||
| 36 | |||
| 37 | private void AddSectionToOutput(IntermediateSection section, Output output) | ||
| 38 | { | ||
| 39 | foreach (var tuple in section.Tuples) | ||
| 40 | { | ||
| 41 | switch (tuple.Definition.Type) | ||
| 42 | { | ||
| 43 | case TupleDefinitionType.File: | ||
| 44 | this.AddFileTuple((FileTuple)tuple, output); | ||
| 45 | break; | ||
| 46 | |||
| 47 | case TupleDefinitionType.WixAction: | ||
| 48 | this.AddWixActionTuple((WixActionTuple)tuple, output); | ||
| 49 | break; | ||
| 50 | |||
| 51 | default: | ||
| 52 | this.AddTupleDefaultly(tuple, output); | ||
| 53 | break; | ||
| 54 | } | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | private void AddFileTuple(FileTuple tuple, Output output) | ||
| 59 | { | ||
| 60 | var table = output.EnsureTable(this.TableDefinitions["File"]); | ||
| 61 | var row = (FileRow)table.CreateRow(tuple.SourceLineNumbers); | ||
| 62 | row.File = tuple.File; | ||
| 63 | row.Component = tuple.Component_; | ||
| 64 | row.FileName = GetMsiFilenameValue(tuple.ShortFileName, tuple.LongFileName); | ||
| 65 | row.FileSize = tuple.FileSize; | ||
| 66 | row.Version = tuple.Version; | ||
| 67 | row.Language = tuple.Language; | ||
| 68 | |||
| 69 | var attributes = tuple.Checksum ? MsiInterop.MsidbFileAttributesChecksum : 0; | ||
| 70 | attributes |= (tuple.Compressed.HasValue && tuple.Compressed.Value) ? MsiInterop.MsidbFileAttributesCompressed : 0; | ||
| 71 | attributes |= (tuple.Compressed.HasValue && !tuple.Compressed.Value) ? MsiInterop.MsidbFileAttributesNoncompressed : 0; | ||
| 72 | attributes |= tuple.Hidden ? MsiInterop.MsidbFileAttributesHidden : 0; | ||
| 73 | attributes |= tuple.ReadOnly ? MsiInterop.MsidbFileAttributesReadOnly : 0; | ||
| 74 | attributes |= tuple.System ? MsiInterop.MsidbFileAttributesSystem : 0; | ||
| 75 | attributes |= tuple.Vital ? MsiInterop.MsidbFileAttributesVital : 0; | ||
| 76 | row.Attributes = attributes; | ||
| 77 | } | ||
| 78 | |||
| 79 | private void AddWixActionTuple(WixActionTuple actionRow, Output output) | ||
| 80 | { | ||
| 81 | // Get the table definition for the action (and ensure the proper table exists for a module). | ||
| 82 | TableDefinition sequenceTableDefinition = null; | ||
| 83 | switch (actionRow.SequenceTable) | ||
| 84 | { | ||
| 85 | case SequenceTable.AdminExecuteSequence: | ||
| 86 | if (OutputType.Module == output.Type) | ||
| 87 | { | ||
| 88 | output.EnsureTable(this.TableDefinitions["AdminExecuteSequence"]); | ||
| 89 | sequenceTableDefinition = this.TableDefinitions["ModuleAdminExecuteSequence"]; | ||
| 90 | } | ||
| 91 | else | ||
| 92 | { | ||
| 93 | sequenceTableDefinition = this.TableDefinitions["AdminExecuteSequence"]; | ||
| 94 | } | ||
| 95 | break; | ||
| 96 | case SequenceTable.AdminUISequence: | ||
| 97 | if (OutputType.Module == output.Type) | ||
| 98 | { | ||
| 99 | output.EnsureTable(this.TableDefinitions["AdminUISequence"]); | ||
| 100 | sequenceTableDefinition = this.TableDefinitions["ModuleAdminUISequence"]; | ||
| 101 | } | ||
| 102 | else | ||
| 103 | { | ||
| 104 | sequenceTableDefinition = this.TableDefinitions["AdminUISequence"]; | ||
| 105 | } | ||
| 106 | break; | ||
| 107 | case SequenceTable.AdvtExecuteSequence: | ||
| 108 | if (OutputType.Module == output.Type) | ||
| 109 | { | ||
| 110 | output.EnsureTable(this.TableDefinitions["AdvtExecuteSequence"]); | ||
| 111 | sequenceTableDefinition = this.TableDefinitions["ModuleAdvtExecuteSequence"]; | ||
| 112 | } | ||
| 113 | else | ||
| 114 | { | ||
| 115 | sequenceTableDefinition = this.TableDefinitions["AdvtExecuteSequence"]; | ||
| 116 | } | ||
| 117 | break; | ||
| 118 | case SequenceTable.InstallExecuteSequence: | ||
| 119 | if (OutputType.Module == output.Type) | ||
| 120 | { | ||
| 121 | output.EnsureTable(this.TableDefinitions["InstallExecuteSequence"]); | ||
| 122 | sequenceTableDefinition = this.TableDefinitions["ModuleInstallExecuteSequence"]; | ||
| 123 | } | ||
| 124 | else | ||
| 125 | { | ||
| 126 | sequenceTableDefinition = this.TableDefinitions["InstallExecuteSequence"]; | ||
| 127 | } | ||
| 128 | break; | ||
| 129 | case SequenceTable.InstallUISequence: | ||
| 130 | if (OutputType.Module == output.Type) | ||
| 131 | { | ||
| 132 | output.EnsureTable(this.TableDefinitions["InstallUISequence"]); | ||
| 133 | sequenceTableDefinition = this.TableDefinitions["ModuleInstallUISequence"]; | ||
| 134 | } | ||
| 135 | else | ||
| 136 | { | ||
| 137 | sequenceTableDefinition = this.TableDefinitions["InstallUISequence"]; | ||
| 138 | } | ||
| 139 | break; | ||
| 140 | } | ||
| 141 | |||
| 142 | // create the action sequence row in the output | ||
| 143 | var sequenceTable = output.EnsureTable(sequenceTableDefinition); | ||
| 144 | var row = sequenceTable.CreateRow(actionRow.SourceLineNumbers); | ||
| 145 | |||
| 146 | if (SectionType.Module == this.Section.Type) | ||
| 147 | { | ||
| 148 | row[0] = actionRow.Action; | ||
| 149 | if (0 != actionRow.Sequence) | ||
| 150 | { | ||
| 151 | row[1] = actionRow.Sequence; | ||
| 152 | } | ||
| 153 | else | ||
| 154 | { | ||
| 155 | bool after = (null == actionRow.Before); | ||
| 156 | row[2] = after ? actionRow.After : actionRow.Before; | ||
| 157 | row[3] = after ? 1 : 0; | ||
| 158 | } | ||
| 159 | row[4] = actionRow.Condition; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 | row[0] = actionRow.Action; | ||
| 164 | row[1] = actionRow.Condition; | ||
| 165 | row[2] = actionRow.Sequence; | ||
| 166 | } | ||
| 167 | } | ||
| 168 | |||
| 169 | private void AddTupleDefaultly(IntermediateTuple tuple, Output output) | ||
| 170 | { | ||
| 171 | if (!this.TableDefinitions.TryGet(tuple.Definition.Name, out var tableDefinition)) | ||
| 172 | { | ||
| 173 | return; | ||
| 174 | } | ||
| 175 | |||
| 176 | var table = output.EnsureTable(tableDefinition); | ||
| 177 | var row = table.CreateRow(tuple.SourceLineNumbers); | ||
| 178 | for (var i = 0; i < tuple.Fields.Length; ++i) | ||
| 179 | { | ||
| 180 | if (i < tableDefinition.Columns.Count) | ||
| 181 | { | ||
| 182 | var column = tableDefinition.Columns[i]; | ||
| 183 | |||
| 184 | switch (column.Type) | ||
| 185 | { | ||
| 186 | case ColumnType.Number: | ||
| 187 | row[i] = tuple.AsNumber(i); | ||
| 188 | break; | ||
| 189 | |||
| 190 | default: | ||
| 191 | row[i] = tuple.AsString(i); | ||
| 192 | break; | ||
| 193 | } | ||
| 194 | } | ||
| 195 | } | ||
| 196 | } | ||
| 197 | |||
| 198 | private static OutputType SectionTypeToOutputType(SectionType type) | ||
| 199 | { | ||
| 200 | switch (type) | ||
| 201 | { | ||
| 202 | case SectionType.Bundle: | ||
| 203 | return OutputType.Bundle; | ||
| 204 | case SectionType.Module: | ||
| 205 | return OutputType.Module; | ||
| 206 | case SectionType.Product: | ||
| 207 | return OutputType.Product; | ||
| 208 | case SectionType.PatchCreation: | ||
| 209 | return OutputType.PatchCreation; | ||
| 210 | case SectionType.Patch: | ||
| 211 | return OutputType.Patch; | ||
| 212 | |||
| 213 | default: | ||
| 214 | throw new ArgumentOutOfRangeException(nameof(type)); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | |||
| 218 | private static string GetMsiFilenameValue(string shortName, string longName) | ||
| 219 | { | ||
| 220 | if (String.IsNullOrEmpty(shortName)) | ||
| 221 | { | ||
| 222 | return longName; | ||
| 223 | } | ||
| 224 | else | ||
| 225 | { | ||
| 226 | return shortName + "|" + longName; | ||
| 227 | } | ||
| 228 | } | ||
| 229 | } | ||
| 230 | } | ||
