diff options
author | Rob Mensching <rob@firegiant.com> | 2017-10-14 16:12:07 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2017-10-14 16:12:07 -0700 |
commit | dbde9e7104b907bbbaea17e21247d8cafc8b3a4c (patch) | |
tree | 0f5fbbb6fe12c6b2e5e622a0e18ce4c5b4eb2b96 /src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs | |
parent | fbf986eb97f68396797a89fc7d40dec07b775440 (diff) | |
download | wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.gz wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.bz2 wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.zip |
Massive refactoring to introduce the concept of IBackend
Diffstat (limited to 'src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs')
-rw-r--r-- | src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs | 241 |
1 files changed, 241 insertions, 0 deletions
diff --git a/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs b/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs new file mode 100644 index 00000000..58814efc --- /dev/null +++ b/src/WixToolset.Core.Burn/Bundles/CreateBootstrapperApplicationManifestCommand.cs | |||
@@ -0,0 +1,241 @@ | |||
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.Burn.Bundles | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.Diagnostics; | ||
8 | using System.Globalization; | ||
9 | using System.IO; | ||
10 | using System.Text; | ||
11 | using System.Xml; | ||
12 | using WixToolset.Data; | ||
13 | using WixToolset.Data.Rows; | ||
14 | |||
15 | internal class CreateBootstrapperApplicationManifestCommand | ||
16 | { | ||
17 | public WixBundleRow BundleRow { private get; set; } | ||
18 | |||
19 | public IEnumerable<PackageFacade> ChainPackages { private get; set; } | ||
20 | |||
21 | public int LastUXPayloadIndex { private get; set; } | ||
22 | |||
23 | public IEnumerable<WixBundleMsiFeatureRow> MsiFeatures { private get; set; } | ||
24 | |||
25 | public Output Output { private get; set; } | ||
26 | |||
27 | public RowDictionary<WixBundlePayloadRow> Payloads { private get; set; } | ||
28 | |||
29 | public TableDefinitionCollection TableDefinitions { private get; set; } | ||
30 | |||
31 | public string TempFilesLocation { private get; set; } | ||
32 | |||
33 | public WixBundlePayloadRow BootstrapperApplicationManifestPayloadRow { get; private set; } | ||
34 | |||
35 | public void Execute() | ||
36 | { | ||
37 | this.GenerateBAManifestBundleTables(); | ||
38 | |||
39 | this.GenerateBAManifestMsiFeatureTables(); | ||
40 | |||
41 | this.GenerateBAManifestPackageTables(); | ||
42 | |||
43 | this.GenerateBAManifestPayloadTables(); | ||
44 | |||
45 | string baManifestPath = Path.Combine(this.TempFilesLocation, "wix-badata.xml"); | ||
46 | |||
47 | this.CreateBootstrapperApplicationManifest(baManifestPath); | ||
48 | |||
49 | this.BootstrapperApplicationManifestPayloadRow = this.CreateBootstrapperApplicationManifestPayloadRow(baManifestPath); | ||
50 | } | ||
51 | |||
52 | private void GenerateBAManifestBundleTables() | ||
53 | { | ||
54 | Table wixBundlePropertiesTable = this.Output.EnsureTable(this.TableDefinitions["WixBundleProperties"]); | ||
55 | |||
56 | Row row = wixBundlePropertiesTable.CreateRow(this.BundleRow.SourceLineNumbers); | ||
57 | row[0] = this.BundleRow.Name; | ||
58 | row[1] = this.BundleRow.LogPathVariable; | ||
59 | row[2] = (YesNoDefaultType.Yes == this.BundleRow.Compressed) ? "yes" : "no"; | ||
60 | row[3] = this.BundleRow.BundleId.ToString("B"); | ||
61 | row[4] = this.BundleRow.UpgradeCode; | ||
62 | row[5] = this.BundleRow.PerMachine ? "yes" : "no"; | ||
63 | } | ||
64 | |||
65 | private void GenerateBAManifestPackageTables() | ||
66 | { | ||
67 | Table wixPackagePropertiesTable = this.Output.EnsureTable(this.TableDefinitions["WixPackageProperties"]); | ||
68 | |||
69 | foreach (PackageFacade package in this.ChainPackages) | ||
70 | { | ||
71 | WixBundlePayloadRow packagePayload = this.Payloads[package.Package.PackagePayload]; | ||
72 | |||
73 | Row row = wixPackagePropertiesTable.CreateRow(package.Package.SourceLineNumbers); | ||
74 | row[0] = package.Package.WixChainItemId; | ||
75 | row[1] = (YesNoType.Yes == package.Package.Vital) ? "yes" : "no"; | ||
76 | row[2] = package.Package.DisplayName; | ||
77 | row[3] = package.Package.Description; | ||
78 | row[4] = package.Package.Size.ToString(CultureInfo.InvariantCulture); // TODO: DownloadSize (compressed) (what does this mean when it's embedded?) | ||
79 | row[5] = package.Package.Size.ToString(CultureInfo.InvariantCulture); // Package.Size (uncompressed) | ||
80 | row[6] = package.Package.InstallSize.Value.ToString(CultureInfo.InvariantCulture); // InstallSize (required disk space) | ||
81 | row[7] = package.Package.Type.ToString(); | ||
82 | row[8] = package.Package.Permanent ? "yes" : "no"; | ||
83 | row[9] = package.Package.LogPathVariable; | ||
84 | row[10] = package.Package.RollbackLogPathVariable; | ||
85 | row[11] = (PackagingType.Embedded == packagePayload.Packaging) ? "yes" : "no"; | ||
86 | |||
87 | if (WixBundlePackageType.Msi == package.Package.Type) | ||
88 | { | ||
89 | row[12] = package.MsiPackage.DisplayInternalUI ? "yes" : "no"; | ||
90 | |||
91 | if (!String.IsNullOrEmpty(package.MsiPackage.ProductCode)) | ||
92 | { | ||
93 | row[13] = package.MsiPackage.ProductCode; | ||
94 | } | ||
95 | |||
96 | if (!String.IsNullOrEmpty(package.MsiPackage.UpgradeCode)) | ||
97 | { | ||
98 | row[14] = package.MsiPackage.UpgradeCode; | ||
99 | } | ||
100 | } | ||
101 | else if (WixBundlePackageType.Msp == package.Package.Type) | ||
102 | { | ||
103 | row[12] = package.MspPackage.DisplayInternalUI ? "yes" : "no"; | ||
104 | |||
105 | if (!String.IsNullOrEmpty(package.MspPackage.PatchCode)) | ||
106 | { | ||
107 | row[13] = package.MspPackage.PatchCode; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | if (!String.IsNullOrEmpty(package.Package.Version)) | ||
112 | { | ||
113 | row[15] = package.Package.Version; | ||
114 | } | ||
115 | |||
116 | if (!String.IsNullOrEmpty(package.Package.InstallCondition)) | ||
117 | { | ||
118 | row[16] = package.Package.InstallCondition; | ||
119 | } | ||
120 | |||
121 | switch (package.Package.Cache) | ||
122 | { | ||
123 | case YesNoAlwaysType.No: | ||
124 | row[17] = "no"; | ||
125 | break; | ||
126 | case YesNoAlwaysType.Yes: | ||
127 | row[17] = "yes"; | ||
128 | break; | ||
129 | case YesNoAlwaysType.Always: | ||
130 | row[17] = "always"; | ||
131 | break; | ||
132 | } | ||
133 | } | ||
134 | } | ||
135 | |||
136 | private void GenerateBAManifestMsiFeatureTables() | ||
137 | { | ||
138 | Table wixPackageFeatureInfoTable = this.Output.EnsureTable(this.TableDefinitions["WixPackageFeatureInfo"]); | ||
139 | |||
140 | foreach (WixBundleMsiFeatureRow feature in this.MsiFeatures) | ||
141 | { | ||
142 | Row row = wixPackageFeatureInfoTable.CreateRow(feature.SourceLineNumbers); | ||
143 | row[0] = feature.ChainPackageId; | ||
144 | row[1] = feature.Name; | ||
145 | row[2] = Convert.ToString(feature.Size, CultureInfo.InvariantCulture); | ||
146 | row[3] = feature.Parent; | ||
147 | row[4] = feature.Title; | ||
148 | row[5] = feature.Description; | ||
149 | row[6] = Convert.ToString(feature.Display, CultureInfo.InvariantCulture); | ||
150 | row[7] = Convert.ToString(feature.Level, CultureInfo.InvariantCulture); | ||
151 | row[8] = feature.Directory; | ||
152 | row[9] = Convert.ToString(feature.Attributes, CultureInfo.InvariantCulture); | ||
153 | } | ||
154 | |||
155 | } | ||
156 | |||
157 | private void GenerateBAManifestPayloadTables() | ||
158 | { | ||
159 | Table wixPayloadPropertiesTable = this.Output.EnsureTable(this.TableDefinitions["WixPayloadProperties"]); | ||
160 | |||
161 | foreach (WixBundlePayloadRow payload in this.Payloads.Values) | ||
162 | { | ||
163 | WixPayloadPropertiesRow row = (WixPayloadPropertiesRow)wixPayloadPropertiesTable.CreateRow(payload.SourceLineNumbers); | ||
164 | row.Id = payload.Id; | ||
165 | row.Package = payload.Package; | ||
166 | row.Container = payload.Container; | ||
167 | row.Name = payload.Name; | ||
168 | row.Size = payload.FileSize.ToString(); | ||
169 | row.DownloadUrl = payload.DownloadUrl; | ||
170 | row.LayoutOnly = payload.LayoutOnly ? "yes" : "no"; | ||
171 | } | ||
172 | } | ||
173 | |||
174 | private void CreateBootstrapperApplicationManifest(string path) | ||
175 | { | ||
176 | using (XmlTextWriter writer = new XmlTextWriter(path, Encoding.Unicode)) | ||
177 | { | ||
178 | writer.Formatting = Formatting.Indented; | ||
179 | writer.WriteStartDocument(); | ||
180 | writer.WriteStartElement("BootstrapperApplicationData", "http://wixtoolset.org/schemas/v4/2010/BootstrapperApplicationData"); | ||
181 | |||
182 | foreach (Table table in this.Output.Tables) | ||
183 | { | ||
184 | if (table.Definition.BootstrapperApplicationData) | ||
185 | { | ||
186 | // We simply assert that the table (and field) name is valid, because | ||
187 | // this is up to the extension developer to get right. An author will | ||
188 | // only affect the attribute value, and that will get properly escaped. | ||
189 | #if DEBUG | ||
190 | Debug.Assert(Common.IsIdentifier(table.Name)); | ||
191 | foreach (ColumnDefinition column in table.Definition.Columns) | ||
192 | { | ||
193 | Debug.Assert(Common.IsIdentifier(column.Name)); | ||
194 | } | ||
195 | #endif // DEBUG | ||
196 | |||
197 | foreach (Row row in table.Rows) | ||
198 | { | ||
199 | writer.WriteStartElement(table.Name); | ||
200 | |||
201 | foreach (Field field in row.Fields) | ||
202 | { | ||
203 | if (null != field.Data) | ||
204 | { | ||
205 | writer.WriteAttributeString(field.Column.Name, field.Data.ToString()); | ||
206 | } | ||
207 | } | ||
208 | |||
209 | writer.WriteEndElement(); | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | writer.WriteEndElement(); | ||
215 | writer.WriteEndDocument(); | ||
216 | } | ||
217 | } | ||
218 | |||
219 | private WixBundlePayloadRow CreateBootstrapperApplicationManifestPayloadRow(string baManifestPath) | ||
220 | { | ||
221 | Table payloadTable = this.Output.EnsureTable(this.TableDefinitions["WixBundlePayload"]); | ||
222 | WixBundlePayloadRow row = (WixBundlePayloadRow)payloadTable.CreateRow(this.BundleRow.SourceLineNumbers); | ||
223 | row.Id = Common.GenerateIdentifier("ux", "BootstrapperApplicationData.xml"); | ||
224 | row.Name = "BootstrapperApplicationData.xml"; | ||
225 | row.SourceFile = baManifestPath; | ||
226 | row.Compressed = YesNoDefaultType.Yes; | ||
227 | row.UnresolvedSourceFile = baManifestPath; | ||
228 | row.Container = Compiler.BurnUXContainerId; | ||
229 | row.EmbeddedId = String.Format(CultureInfo.InvariantCulture, BurnCommon.BurnUXContainerEmbeddedIdFormat, this.LastUXPayloadIndex); | ||
230 | row.Packaging = PackagingType.Embedded; | ||
231 | |||
232 | FileInfo fileInfo = new FileInfo(row.SourceFile); | ||
233 | |||
234 | row.FileSize = (int)fileInfo.Length; | ||
235 | |||
236 | row.Hash = Common.GetFileHash(fileInfo.FullName); | ||
237 | |||
238 | return row; | ||
239 | } | ||
240 | } | ||
241 | } | ||