aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs222
1 files changed, 118 insertions, 104 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs
index 107f3208..0dcce61b 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs
@@ -1,12 +1,15 @@
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. 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 2
3#if DELETE
4
3namespace WixToolset.Core.WindowsInstaller.Bind 5namespace WixToolset.Core.WindowsInstaller.Bind
4{ 6{
5 using System; 7 using System;
6 using System.Collections.Generic; 8 using System.Collections.Generic;
7 using System.Diagnostics; 9 using System.Diagnostics;
10 using System.IO;
11 using System.Linq;
8 using WixToolset.Core.Bind; 12 using WixToolset.Core.Bind;
9 using WixToolset.Core.Native;
10 using WixToolset.Data; 13 using WixToolset.Data;
11 using WixToolset.Data.Tuples; 14 using WixToolset.Data.Tuples;
12 using WixToolset.Data.WindowsInstaller; 15 using WixToolset.Data.WindowsInstaller;
@@ -16,15 +19,23 @@ namespace WixToolset.Core.WindowsInstaller.Bind
16 19
17 internal class CopyTransformDataCommand 20 internal class CopyTransformDataCommand
18 { 21 {
19 public bool CopyOutFileRows { private get; set; } 22 public CopyTransformDataCommand(IMessaging messaging, WindowsInstallerData output, TableDefinitionCollection tableDefinitions, bool copyOutFileRows)
23 {
24 this.Messaging = messaging;
25 this.Output = output;
26 this.TableDefinitions = tableDefinitions;
27 this.CopyOutFileRows = copyOutFileRows;
28 }
20 29
21 public IEnumerable<IFileSystemExtension> Extensions { private get; set; } 30 private bool CopyOutFileRows { get; }
22 31
23 public IMessaging Messaging { private get; set; } 32 public IEnumerable<IFileSystemExtension> Extensions { get; }
24 33
25 public WindowsInstallerData Output { private get; set; } 34 private IMessaging Messaging { get; }
26 35
27 public TableDefinitionCollection TableDefinitions { private get; set; } 36 private WindowsInstallerData Output { get; }
37
38 private TableDefinitionCollection TableDefinitions { get; }
28 39
29 public IEnumerable<FileFacade> FileFacades { get; private set; } 40 public IEnumerable<FileFacade> FileFacades { get; private set; }
30 41
@@ -32,18 +43,17 @@ namespace WixToolset.Core.WindowsInstaller.Bind
32 { 43 {
33 Debug.Assert(OutputType.Patch != this.Output.Type); 44 Debug.Assert(OutputType.Patch != this.Output.Type);
34 45
35 List<FileFacade> allFileRows = this.CopyOutFileRows ? new List<FileFacade>() : null; 46 var allFileRows = this.CopyOutFileRows ? new List<FileFacade>() : null;
36 47
37#if REVISIT_FOR_PATCHING // TODO: Fix this patching related code to work correctly with FileFacades. 48 var copyToPatch = (allFileRows != null);
38 bool copyToPatch = (allFileRows != null); 49 var copyFromPatch = !copyToPatch;
39 bool copyFromPatch = !copyToPatch;
40 50
41 RowDictionary<MediaRow> patchMediaRows = new RowDictionary<MediaRow>(); 51 var patchMediaRows = new RowDictionary<MediaRow>();
42 52
43 Dictionary<int, RowDictionary<WixFileRow>> patchMediaFileRows = new Dictionary<int, RowDictionary<WixFileRow>>(); 53 var patchMediaFileRows = new Dictionary<int, RowDictionary<WixFileRow>>();
44 54
45 Table patchActualFileTable = this.Output.EnsureTable(this.TableDefinitions["File"]); 55 var patchActualFileTable = this.Output.EnsureTable(this.TableDefinitions["File"]);
46 Table patchFileTable = this.Output.EnsureTable(this.TableDefinitions["WixFile"]); 56 var patchFileTable = this.Output.EnsureTable(this.TableDefinitions["WixFile"]);
47 57
48 if (copyFromPatch) 58 if (copyFromPatch)
49 { 59 {
@@ -51,8 +61,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
51 foreach (WixFileRow patchFileRow in patchFileTable.Rows) 61 foreach (WixFileRow patchFileRow in patchFileTable.Rows)
52 { 62 {
53 int diskId = patchFileRow.DiskId; 63 int diskId = patchFileRow.DiskId;
54 RowDictionary<WixFileRow> mediaFileRows; 64 if (!patchMediaFileRows.TryGetValue(diskId, out var mediaFileRows))
55 if (!patchMediaFileRows.TryGetValue(diskId, out mediaFileRows))
56 { 65 {
57 mediaFileRows = new RowDictionary<WixFileRow>(); 66 mediaFileRows = new RowDictionary<WixFileRow>();
58 patchMediaFileRows.Add(diskId, mediaFileRows); 67 patchMediaFileRows.Add(diskId, mediaFileRows);
@@ -61,24 +70,25 @@ namespace WixToolset.Core.WindowsInstaller.Bind
61 mediaFileRows.Add(patchFileRow); 70 mediaFileRows.Add(patchFileRow);
62 } 71 }
63 72
64 Table patchMediaTable = this.Output.EnsureTable(this.TableDefinitions["Media"]); 73 var patchMediaTable = this.Output.EnsureTable(this.TableDefinitions["Media"]);
65 patchMediaRows = new RowDictionary<MediaRow>(patchMediaTable); 74 patchMediaRows = new RowDictionary<MediaRow>(patchMediaTable);
66 } 75 }
67 76
68 // index paired transforms 77 // Index paired transforms by name without the "#" prefix.
69 Dictionary<string, Output> pairedTransforms = new Dictionary<string, Output>(); 78 var pairedTransforms = this.Output.SubStorages.Where(s => s.Name.StartsWith("#")).ToDictionary(s => s.Name.Substring(1), s => s.Data);
70 foreach (SubStorage substorage in this.Output.SubStorages) 79 //Dictionary<string, Output> pairedTransforms = new Dictionary<string, Output>();
71 { 80 //foreach (SubStorage substorage in this.Output.SubStorages)
72 if (substorage.Name.StartsWith("#")) 81 //{
73 { 82 // if (substorage.Name.StartsWith("#"))
74 pairedTransforms.Add(substorage.Name.Substring(1), substorage.Data); 83 // {
75 } 84 // pairedTransforms.Add(substorage.Name.Substring(1), substorage.Data);
76 } 85 // }
86 //}
77 87
78 try 88 try
79 { 89 {
80 // copy File bind data into substorages 90 // Copy File bind data into substorages
81 foreach (SubStorage substorage in this.Output.SubStorages) 91 foreach (var substorage in this.Output.SubStorages)
82 { 92 {
83 if (substorage.Name.StartsWith("#")) 93 if (substorage.Name.StartsWith("#"))
84 { 94 {
@@ -86,25 +96,25 @@ namespace WixToolset.Core.WindowsInstaller.Bind
86 continue; 96 continue;
87 } 97 }
88 98
89 Output mainTransform = substorage.Data; 99 var mainTransform = substorage.Data;
90 Table mainWixFileTable = mainTransform.Tables["WixFile"]; 100 var mainWixFileTable = mainTransform.Tables["WixFile"];
91 Table mainMsiFileHashTable = mainTransform.Tables["MsiFileHash"]; 101 var mainMsiFileHashTable = mainTransform.Tables["MsiFileHash"];
92 102
93 this.FileManagerCore.ActiveSubStorage = substorage; 103 this.FileManagerCore.ActiveSubStorage = substorage;
94 104
95 RowDictionary<WixFileRow> mainWixFiles = new RowDictionary<WixFileRow>(mainWixFileTable); 105 var mainWixFiles = new RowDictionary<WixFileRow>(mainWixFileTable);
96 RowDictionary<Row> mainMsiFileHashIndex = new RowDictionary<Row>(); 106 var mainMsiFileHashIndex = new RowDictionary<Row>();
97 107
98 Table mainFileTable = mainTransform.Tables["File"]; 108 var mainFileTable = mainTransform.Tables["File"];
99 Output pairedTransform = (Output)pairedTransforms[substorage.Name]; 109 var pairedTransform = pairedTransforms[substorage.Name];
100 110
101 // copy Media.LastSequence and index the MsiFileHash table if it exists. 111 // copy Media.LastSequence and index the MsiFileHash table if it exists.
102 if (copyFromPatch) 112 if (copyFromPatch)
103 { 113 {
104 Table pairedMediaTable = pairedTransform.Tables["Media"]; 114 var pairedMediaTable = pairedTransform.Tables["Media"];
105 foreach (MediaRow pairedMediaRow in pairedMediaTable.Rows) 115 foreach (MediaRow pairedMediaRow in pairedMediaTable.Rows)
106 { 116 {
107 MediaRow patchMediaRow = patchMediaRows.Get(pairedMediaRow.DiskId); 117 var patchMediaRow = patchMediaRows.Get(pairedMediaRow.DiskId);
108 pairedMediaRow.Fields[1] = patchMediaRow.Fields[1]; 118 pairedMediaRow.Fields[1] = patchMediaRow.Fields[1];
109 } 119 }
110 120
@@ -118,8 +128,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
118 } 128 }
119 129
120 // Index File table of pairedTransform 130 // Index File table of pairedTransform
121 Table pairedFileTable = pairedTransform.Tables["File"]; 131 var pairedFileTable = pairedTransform.Tables["File"];
122 RowDictionary<FileRow> pairedFileRows = new RowDictionary<FileRow>(pairedFileTable); 132 var pairedFileRows = new RowDictionary<FileRow>(pairedFileTable);
123 133
124 if (null != mainFileTable) 134 if (null != mainFileTable)
125 { 135 {
@@ -140,12 +150,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind
140 continue; 150 continue;
141 } 151 }
142 152
143 WixFileRow mainWixFileRow = mainWixFiles.Get(mainFileRow.File); 153 var mainWixFileRow = mainWixFiles.Get(mainFileRow.File);
144 154
145 if (copyToPatch) // when copying to the patch, we need compare the underlying files and include all file changes. 155 if (copyToPatch) // when copying to the patch, we need compare the underlying files and include all file changes.
146 { 156 {
147 ObjectField objectField = (ObjectField)mainWixFileRow.Fields[6]; 157 var objectField = (ObjectField)mainWixFileRow.Fields[6];
148 FileRow pairedFileRow = pairedFileRows.Get(mainFileRow.File); 158 var pairedFileRow = pairedFileRows.Get(mainFileRow.File);
149 159
150 // If the file is new, we always need to add it to the patch. 160 // If the file is new, we always need to add it to the patch.
151 if (mainFileRow.Operation != RowOperation.Add) 161 if (mainFileRow.Operation != RowOperation.Add)
@@ -169,8 +179,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
169 if (null != pairedFileRow) 179 if (null != pairedFileRow)
170 { 180 {
171 // Always patch-added, but never non-compressed. 181 // Always patch-added, but never non-compressed.
172 pairedFileRow.Attributes |= MsiInterop.MsidbFileAttributesPatchAdded; 182 pairedFileRow.Attributes |= WindowsInstallerConstants.MsidbFileAttributesPatchAdded;
173 pairedFileRow.Attributes &= ~MsiInterop.MsidbFileAttributesNoncompressed; 183 pairedFileRow.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesNoncompressed;
174 pairedFileRow.Fields[6].Modified = true; 184 pairedFileRow.Fields[6].Modified = true;
175 pairedFileRow.Operation = RowOperation.Modify; 185 pairedFileRow.Operation = RowOperation.Modify;
176 } 186 }
@@ -179,14 +189,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind
179 { 189 {
180 // The File is same. We need mark all the attributes as unchanged. 190 // The File is same. We need mark all the attributes as unchanged.
181 mainFileRow.Operation = RowOperation.None; 191 mainFileRow.Operation = RowOperation.None;
182 foreach (Field field in mainFileRow.Fields) 192 foreach (var field in mainFileRow.Fields)
183 { 193 {
184 field.Modified = false; 194 field.Modified = false;
185 } 195 }
186 196
187 if (null != pairedFileRow) 197 if (null != pairedFileRow)
188 { 198 {
189 pairedFileRow.Attributes &= ~MsiInterop.MsidbFileAttributesPatchAdded; 199 pairedFileRow.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesPatchAdded;
190 pairedFileRow.Fields[6].Modified = false; 200 pairedFileRow.Fields[6].Modified = false;
191 pairedFileRow.Operation = RowOperation.None; 201 pairedFileRow.Operation = RowOperation.None;
192 } 202 }
@@ -197,8 +207,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
197 else if (null != pairedFileRow) // RowOperation.Add 207 else if (null != pairedFileRow) // RowOperation.Add
198 { 208 {
199 // Always patch-added, but never non-compressed. 209 // Always patch-added, but never non-compressed.
200 pairedFileRow.Attributes |= MsiInterop.MsidbFileAttributesPatchAdded; 210 pairedFileRow.Attributes |= WindowsInstallerConstants.MsidbFileAttributesPatchAdded;
201 pairedFileRow.Attributes &= ~MsiInterop.MsidbFileAttributesNoncompressed; 211 pairedFileRow.Attributes &= ~WindowsInstallerConstants.MsidbFileAttributesNoncompressed;
202 pairedFileRow.Fields[6].Modified = true; 212 pairedFileRow.Fields[6].Modified = true;
203 pairedFileRow.Operation = RowOperation.Add; 213 pairedFileRow.Operation = RowOperation.Add;
204 } 214 }
@@ -207,20 +217,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind
207 // index patch files by diskId+fileId 217 // index patch files by diskId+fileId
208 int diskId = mainWixFileRow.DiskId; 218 int diskId = mainWixFileRow.DiskId;
209 219
210 RowDictionary<WixFileRow> mediaFileRows; 220 if (!patchMediaFileRows.TryGetValue(diskId, out var mediaFileRows))
211 if (!patchMediaFileRows.TryGetValue(diskId, out mediaFileRows))
212 { 221 {
213 mediaFileRows = new RowDictionary<WixFileRow>(); 222 mediaFileRows = new RowDictionary<WixFileRow>();
214 patchMediaFileRows.Add(diskId, mediaFileRows); 223 patchMediaFileRows.Add(diskId, mediaFileRows);
215 } 224 }
216 225
217 string fileId = mainFileRow.File; 226 var fileId = mainFileRow.File;
218 WixFileRow patchFileRow = mediaFileRows.Get(fileId); 227 var patchFileRow = mediaFileRows.Get(fileId);
219 if (copyToPatch) 228 if (copyToPatch)
220 { 229 {
221 if (null == patchFileRow) 230 if (null == patchFileRow)
222 { 231 {
223 FileRow patchActualFileRow = (FileRow)patchFileTable.CreateRow(mainFileRow.SourceLineNumbers); 232 var patchActualFileRow = (FileRow)patchFileTable.CreateRow(mainFileRow.SourceLineNumbers);
224 patchActualFileRow.CopyFrom(mainFileRow); 233 patchActualFileRow.CopyFrom(mainFileRow);
225 234
226 patchFileRow = (WixFileRow)patchFileTable.CreateRow(mainFileRow.SourceLineNumbers); 235 patchFileRow = (WixFileRow)patchFileTable.CreateRow(mainFileRow.SourceLineNumbers);
@@ -237,7 +246,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
237 // make sure Source is same. Otherwise we are silently ignoring a file. 246 // make sure Source is same. Otherwise we are silently ignoring a file.
238 if (0 != String.Compare(patchFileRow.Source, mainWixFileRow.Source, StringComparison.OrdinalIgnoreCase)) 247 if (0 != String.Compare(patchFileRow.Source, mainWixFileRow.Source, StringComparison.OrdinalIgnoreCase))
239 { 248 {
240 Messaging.Instance.OnMessage(WixErrors.SameFileIdDifferentSource(mainFileRow.SourceLineNumbers, fileId, patchFileRow.Source, mainWixFileRow.Source)); 249 this.Messaging.Write(ErrorMessages.SameFileIdDifferentSource(mainFileRow.SourceLineNumbers, fileId, patchFileRow.Source, mainWixFileRow.Source));
241 } 250 }
242 251
243 // capture the previous file versions (and associated data) from this targeted instance of the baseline into the current filerow. 252 // capture the previous file versions (and associated data) from this targeted instance of the baseline into the current filerow.
@@ -249,11 +258,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
249 // copy data from the patch back to the transform 258 // copy data from the patch back to the transform
250 if (null != patchFileRow) 259 if (null != patchFileRow)
251 { 260 {
252 FileRow pairedFileRow = (FileRow)pairedFileRows.Get(fileId); 261 var pairedFileRow = pairedFileRows.Get(fileId);
253 for (int i = 0; i < patchFileRow.Fields.Length; i++) 262 for (var i = 0; i < patchFileRow.Fields.Length; i++)
254 { 263 {
255 string patchValue = patchFileRow[i] == null ? "" : patchFileRow[i].ToString(); 264 var patchValue = patchFileRow[i] == null ? String.Empty : patchFileRow.FieldAsString(i);
256 string mainValue = mainFileRow[i] == null ? "" : mainFileRow[i].ToString(); 265 var mainValue = mainFileRow[i] == null ? String.Empty : mainFileRow.FieldAsString(i);
257 266
258 if (1 == i) 267 if (1 == i)
259 { 268 {
@@ -298,17 +307,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind
298 } 307 }
299 308
300 // copy MsiFileHash row for this File 309 // copy MsiFileHash row for this File
301 Row patchHashRow; 310 if (!mainMsiFileHashIndex.TryGetValue(patchFileRow.File, out var patchHashRow))
302 if (!mainMsiFileHashIndex.TryGetValue(patchFileRow.File, out patchHashRow))
303 { 311 {
304 patchHashRow = patchFileRow.Hash; 312 patchHashRow = patchFileRow.Hash;
305 } 313 }
306 314
307 if (null != patchHashRow) 315 if (null != patchHashRow)
308 { 316 {
309 Table mainHashTable = mainTransform.EnsureTable(this.TableDefinitions["MsiFileHash"]); 317 var mainHashTable = mainTransform.EnsureTable(this.TableDefinitions["MsiFileHash"]);
310 Row mainHashRow = mainHashTable.CreateRow(mainFileRow.SourceLineNumbers); 318 var mainHashRow = mainHashTable.CreateRow(mainFileRow.SourceLineNumbers);
311 for (int i = 0; i < patchHashRow.Fields.Length; i++) 319 for (var i = 0; i < patchHashRow.Fields.Length; i++)
312 { 320 {
313 mainHashRow[i] = patchHashRow[i]; 321 mainHashRow[i] = patchHashRow[i];
314 if (i > 1) 322 if (i > 1)
@@ -326,12 +334,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind
326 List<Row> patchAssemblyNameRows = patchFileRow.AssemblyNames; 334 List<Row> patchAssemblyNameRows = patchFileRow.AssemblyNames;
327 if (null != patchAssemblyNameRows) 335 if (null != patchAssemblyNameRows)
328 { 336 {
329 Table mainAssemblyNameTable = mainTransform.EnsureTable(this.TableDefinitions["MsiAssemblyName"]); 337 var mainAssemblyNameTable = mainTransform.EnsureTable(this.TableDefinitions["MsiAssemblyName"]);
330 foreach (Row patchAssemblyNameRow in patchAssemblyNameRows) 338 foreach (var patchAssemblyNameRow in patchAssemblyNameRows)
331 { 339 {
332 // Copy if there isn't an identical modified/added row already in the transform. 340 // Copy if there isn't an identical modified/added row already in the transform.
333 bool foundMatchingModifiedRow = false; 341 var foundMatchingModifiedRow = false;
334 foreach (Row mainAssemblyNameRow in mainAssemblyNameTable.Rows) 342 foreach (var mainAssemblyNameRow in mainAssemblyNameTable.Rows)
335 { 343 {
336 if (RowOperation.None != mainAssemblyNameRow.Operation && mainAssemblyNameRow.GetPrimaryKey('/').Equals(patchAssemblyNameRow.GetPrimaryKey('/'))) 344 if (RowOperation.None != mainAssemblyNameRow.Operation && mainAssemblyNameRow.GetPrimaryKey('/').Equals(patchAssemblyNameRow.GetPrimaryKey('/')))
337 { 345 {
@@ -342,8 +350,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
342 350
343 if (!foundMatchingModifiedRow) 351 if (!foundMatchingModifiedRow)
344 { 352 {
345 Row mainAssemblyNameRow = mainAssemblyNameTable.CreateRow(mainFileRow.SourceLineNumbers); 353 var mainAssemblyNameRow = mainAssemblyNameTable.CreateRow(mainFileRow.SourceLineNumbers);
346 for (int i = 0; i < patchAssemblyNameRow.Fields.Length; i++) 354 for (var i = 0; i < patchAssemblyNameRow.Fields.Length; i++)
347 { 355 {
348 mainAssemblyNameRow[i] = patchAssemblyNameRow[i]; 356 mainAssemblyNameRow[i] = patchAssemblyNameRow[i];
349 } 357 }
@@ -359,34 +367,36 @@ namespace WixToolset.Core.WindowsInstaller.Bind
359 if (null != patchFileRow.Patch) 367 if (null != patchFileRow.Patch)
360 { 368 {
361 // Add the PatchFiles action automatically to the AdminExecuteSequence and InstallExecuteSequence tables. 369 // Add the PatchFiles action automatically to the AdminExecuteSequence and InstallExecuteSequence tables.
362 AddPatchFilesActionToSequenceTable(SequenceTable.AdminExecuteSequence, mainTransform, pairedTransform, mainFileRow); 370 this.AddPatchFilesActionToSequenceTable(SequenceTable.AdminExecuteSequence, mainTransform, pairedTransform, mainFileRow);
363 AddPatchFilesActionToSequenceTable(SequenceTable.InstallExecuteSequence, mainTransform, pairedTransform, mainFileRow); 371 this.AddPatchFilesActionToSequenceTable(SequenceTable.InstallExecuteSequence, mainTransform, pairedTransform, mainFileRow);
364 372
365 // Add to Patch table 373 // Add to Patch table
366 Table patchTable = pairedTransform.EnsureTable(this.TableDefinitions["Patch"]); 374 var patchTable = pairedTransform.EnsureTable(this.TableDefinitions["Patch"]);
367 if (0 == patchTable.Rows.Count) 375 if (0 == patchTable.Rows.Count)
368 { 376 {
369 patchTable.Operation = TableOperation.Add; 377 patchTable.Operation = TableOperation.Add;
370 } 378 }
371 379
372 Row patchRow = patchTable.CreateRow(mainFileRow.SourceLineNumbers); 380 var patchRow = patchTable.CreateRow(mainFileRow.SourceLineNumbers);
373 patchRow[0] = patchFileRow.File; 381 patchRow[0] = patchFileRow.File;
374 patchRow[1] = patchFileRow.Sequence; 382 patchRow[1] = patchFileRow.Sequence;
375 383
376 FileInfo patchFile = new FileInfo(patchFileRow.Source); 384 var patchFile = new FileInfo(patchFileRow.Source);
377 patchRow[2] = (int)patchFile.Length; 385 patchRow[2] = (int)patchFile.Length;
378 patchRow[3] = 0 == (PatchAttributeType.AllowIgnoreOnError & patchFileRow.PatchAttributes) ? 0 : 1; 386 patchRow[3] = 0 == (PatchAttributeType.AllowIgnoreOnError & patchFileRow.PatchAttributes) ? 0 : 1;
379 387
380 string streamName = patchTable.Name + "." + patchRow[0] + "." + patchRow[1]; 388 var streamName = patchTable.Name + "." + patchRow[0] + "." + patchRow[1];
381 if (MsiInterop.MsiMaxStreamNameLength < streamName.Length) 389 if (Msi.MsiInterop.MsiMaxStreamNameLength < streamName.Length)
382 { 390 {
383 streamName = "_" + Guid.NewGuid().ToString("D").ToUpperInvariant().Replace('-', '_'); 391 streamName = "_" + Guid.NewGuid().ToString("D").ToUpperInvariant().Replace('-', '_');
384 Table patchHeadersTable = pairedTransform.EnsureTable(this.TableDefinitions["MsiPatchHeaders"]); 392
393 var patchHeadersTable = pairedTransform.EnsureTable(this.TableDefinitions["MsiPatchHeaders"]);
385 if (0 == patchHeadersTable.Rows.Count) 394 if (0 == patchHeadersTable.Rows.Count)
386 { 395 {
387 patchHeadersTable.Operation = TableOperation.Add; 396 patchHeadersTable.Operation = TableOperation.Add;
388 } 397 }
389 Row patchHeadersRow = patchHeadersTable.CreateRow(mainFileRow.SourceLineNumbers); 398
399 var patchHeadersRow = patchHeadersTable.CreateRow(mainFileRow.SourceLineNumbers);
390 patchHeadersRow[0] = streamName; 400 patchHeadersRow[0] = streamName;
391 patchHeadersRow[1] = patchFileRow.Patch; 401 patchHeadersRow[1] = patchFileRow.Patch;
392 patchRow[5] = streamName; 402 patchRow[5] = streamName;
@@ -420,7 +430,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
420 { 430 {
421 this.FileManagerCore.ActiveSubStorage = null; 431 this.FileManagerCore.ActiveSubStorage = null;
422 } 432 }
423#endif 433
424 this.FileFacades = allFileRows; 434 this.FileFacades = allFileRows;
425 } 435 }
426 436
@@ -509,17 +519,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind
509 foreach (var row in sequenceTable.Rows) 519 foreach (var row in sequenceTable.Rows)
510 { 520 {
511 var actionName = row.FieldAsString(0); 521 var actionName = row.FieldAsString(0);
512 if (String.Equals("PatchFiles", actionName, StringComparison.Ordinal)) 522 switch (actionName)
513 {
514 hasPatchFilesAction = true;
515 }
516 else if (String.Equals("InstallFiles", actionName, StringComparison.Ordinal))
517 { 523 {
518 installFilesSequence = row.FieldAsInteger(2); 524 case "PatchFiles":
519 } 525 hasPatchFilesAction = true;
520 else if (String.Equals("DuplicateFiles", actionName, StringComparison.Ordinal)) 526 break;
521 { 527
522 duplicateFilesSequence = row.FieldAsInteger(2); 528 case "InstallFiles":
529 installFilesSequence = row.FieldAsInteger(2);
530 break;
531
532 case "DuplicateFiles":
533 duplicateFilesSequence = row.FieldAsInteger(2);
534 break;
523 } 535 }
524 } 536 }
525 } 537 }
@@ -531,8 +543,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
531 /// <param name="output">The output to validate.</param> 543 /// <param name="output">The output to validate.</param>
532 private void ValidateFileRowChanges(WindowsInstallerData transform) 544 private void ValidateFileRowChanges(WindowsInstallerData transform)
533 { 545 {
534 Table componentTable = transform.Tables["Component"]; 546 var componentTable = transform.Tables["Component"];
535 Table fileTable = transform.Tables["File"]; 547 var fileTable = transform.Tables["File"];
536 548
537 // There's no sense validating keypaths if the transform has no component or file table 549 // There's no sense validating keypaths if the transform has no component or file table
538 if (componentTable == null || fileTable == null) 550 if (componentTable == null || fileTable == null)
@@ -540,31 +552,31 @@ namespace WixToolset.Core.WindowsInstaller.Bind
540 return; 552 return;
541 } 553 }
542 554
543 Dictionary<string, string> componentKeyPath = new Dictionary<string, string>(componentTable.Rows.Count); 555 var componentKeyPath = new Dictionary<string, string>(componentTable.Rows.Count);
544 556
545 // Index the Component table for non-directory & non-registry key paths. 557 // Index the Component table for non-directory & non-registry key paths.
546 foreach (Row row in componentTable.Rows) 558 foreach (var row in componentTable.Rows)
547 { 559 {
548 if (null != row.Fields[5].Data && 560 var keyPath = row.FieldAsString(5);
549 0 != ((int)row.Fields[3].Data & WindowsInstallerConstants.MsidbComponentAttributesRegistryKeyPath)) 561 if (keyPath != null && 0 != (row.FieldAsInteger(3) & WindowsInstallerConstants.MsidbComponentAttributesRegistryKeyPath))
550 { 562 {
551 componentKeyPath.Add(row.Fields[0].Data.ToString(), row.Fields[5].Data.ToString()); 563 componentKeyPath.Add(row.FieldAsString(0), keyPath);
552 } 564 }
553 } 565 }
554 566
555 Dictionary<string, string> componentWithChangedKeyPath = new Dictionary<string, string>(); 567 var componentWithChangedKeyPath = new Dictionary<string, string>();
556 Dictionary<string, string> componentWithNonKeyPathChanged = new Dictionary<string, string>(); 568 var componentWithNonKeyPathChanged = new Dictionary<string, string>();
557 // Verify changes in the file table, now that file diffing has occurred 569 // Verify changes in the file table, now that file diffing has occurred
558 foreach (FileRow row in fileTable.Rows) 570 foreach (FileRow row in fileTable.Rows)
559 { 571 {
560 string fileId = row.Fields[0].Data.ToString();
561 string componentId = row.Fields[1].Data.ToString();
562
563 if (RowOperation.Modify != row.Operation) 572 if (RowOperation.Modify != row.Operation)
564 { 573 {
565 continue; 574 continue;
566 } 575 }
567 576
577 var fileId = row.FieldAsString(0);
578 var componentId = row.FieldAsString(1);
579
568 // If this file is the keypath of a component 580 // If this file is the keypath of a component
569 if (componentKeyPath.ContainsValue(fileId)) 581 if (componentKeyPath.ContainsValue(fileId))
570 { 582 {
@@ -582,12 +594,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind
582 } 594 }
583 } 595 }
584 596
585 foreach (KeyValuePair<string, string> componentFile in componentWithNonKeyPathChanged) 597 foreach (var componentFile in componentWithNonKeyPathChanged)
586 { 598 {
587 // Make sure all changes to non keypath files also had a change in the keypath. 599 // Make sure all changes to non keypath files also had a change in the keypath.
588 if (!componentWithChangedKeyPath.ContainsKey(componentFile.Key) && componentKeyPath.ContainsKey(componentFile.Key)) 600 if (!componentWithChangedKeyPath.ContainsKey(componentFile.Key) && componentKeyPath.TryGetValue(componentFile.Key, out var keyPath))
589 { 601 {
590 this.Messaging.Write(WarningMessages.UpdateOfNonKeyPathFile((string)componentFile.Value, (string)componentFile.Key, (string)componentKeyPath[componentFile.Key])); 602 this.Messaging.Write(WarningMessages.UpdateOfNonKeyPathFile(componentFile.Value, componentFile.Key, keyPath));
591 } 603 }
592 } 604 }
593 } 605 }
@@ -614,3 +626,5 @@ namespace WixToolset.Core.WindowsInstaller.Bind
614 } 626 }
615 } 627 }
616} 628}
629
630#endif