Integrate latest Data changes for FileTuple and AssemblyTuple
Rob Mensching committed
May 23, 2019 at 15:35 UTC
5812c6c4b9d40e9ae2b5234a778ecf5aeb8423ff
2 files changed
+113
-63
src/WixToolset.Converters.Tupleizer/ConvertTuplesCommand.cs
+43
-39
@@ -23,16 +23,18 @@ namespace WixToolset.Converters.Tupleizer
23
var section = new IntermediateSection(String.Empty, OutputType3ToSectionType4(output.Type), output.Codepage);
24
25
var wixMediaByDiskId = IndexWixMediaTableByDiskId(output);
26
+ var componentsById = IndexById<Wix3.Row>(output, "Component");
27
var bindPathsById = IndexById<Wix3.Row>(output, "BindPath");
28
var fontsById = IndexById<Wix3.Row>(output, "Font");
29
var selfRegById = IndexById<Wix3.Row>(output, "SelfReg");
30
var wixDirectoryById = IndexById<Wix3.Row>(output, "WixDirectory");
31
+ var wixFileById = IndexById<Wix3.Row>(output, "WixFile");
32
33
foreach (Wix3.Table table in output.Tables)
34
{
35
foreach (Wix3.Row row in table.Rows)
36
{
35
- var tuple = GenerateTupleFromRow(row, wixMediaByDiskId, fontsById, bindPathsById, selfRegById, wixDirectoryById);
37
+ var tuple = GenerateTupleFromRow(row, wixMediaByDiskId, componentsById, fontsById, bindPathsById, selfRegById, wixFileById, wixDirectoryById);
38
if (tuple != null)
39
{
40
section.Tuples.Add(tuple);
@@ -75,7 +77,7 @@ namespace WixToolset.Converters.Tupleizer
77
return byId;
78
}
79
78
- private static IntermediateTuple GenerateTupleFromRow(Wix3.Row row, Dictionary<int, Wix3.WixMediaRow> wixMediaByDiskId, Dictionary<string, Wix3.Row> fontsById, Dictionary<string, Wix3.Row> bindPathsById, Dictionary<string, Wix3.Row> selfRegById, Dictionary<string, Wix3.Row> wixDirectoryById)
80
+ private static IntermediateTuple GenerateTupleFromRow(Wix3.Row row, Dictionary<int, Wix3.WixMediaRow> wixMediaByDiskId, Dictionary<string, Wix3.Row> componentsById, Dictionary<string, Wix3.Row> fontsById, Dictionary<string, Wix3.Row> bindPathsById, Dictionary<string, Wix3.Row> selfRegById, Dictionary<string, Wix3.Row> wixFileById, Dictionary<string, Wix3.Row> wixDirectoryById)
81
{
82
var name = row.Table.Name;
83
switch (name)
@@ -234,20 +236,15 @@ namespace WixToolset.Converters.Tupleizer
236
case "File":
237
{
238
var attributes = FieldAsNullableInt(row, 6);
237
- var readOnly = (attributes & WindowsInstallerConstants.MsidbFileAttributesReadOnly) == WindowsInstallerConstants.MsidbFileAttributesReadOnly;
238
- var hidden = (attributes & WindowsInstallerConstants.MsidbFileAttributesHidden) == WindowsInstallerConstants.MsidbFileAttributesHidden;
239
- var system = (attributes & WindowsInstallerConstants.MsidbFileAttributesSystem) == WindowsInstallerConstants.MsidbFileAttributesSystem;
240
- var vital = (attributes & WindowsInstallerConstants.MsidbFileAttributesVital) == WindowsInstallerConstants.MsidbFileAttributesVital;
241
- var checksum = (attributes & WindowsInstallerConstants.MsidbFileAttributesChecksum) == WindowsInstallerConstants.MsidbFileAttributesChecksum;
242
- bool? compressed = null;
243
- if ((attributes & WindowsInstallerConstants.MsidbFileAttributesNoncompressed) == WindowsInstallerConstants.MsidbFileAttributesNoncompressed)
244
- {
245
- compressed = false;
246
- }
247
- else if ((attributes & WindowsInstallerConstants.MsidbFileAttributesCompressed) == WindowsInstallerConstants.MsidbFileAttributesCompressed)
248
- {
249
- compressed = true;
250
- }
239
+
240
+ FileTupleAttributes tupleAttributes = 0;
241
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesReadOnly) == WindowsInstallerConstants.MsidbFileAttributesReadOnly ? FileTupleAttributes.ReadOnly : 0;
242
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesHidden) == WindowsInstallerConstants.MsidbFileAttributesHidden ? FileTupleAttributes.Hidden : 0;
243
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesSystem) == WindowsInstallerConstants.MsidbFileAttributesSystem ? FileTupleAttributes.System : 0;
244
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesVital) == WindowsInstallerConstants.MsidbFileAttributesVital ? FileTupleAttributes.Vital : 0;
245
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesChecksum) == WindowsInstallerConstants.MsidbFileAttributesChecksum ? FileTupleAttributes.Checksum : 0;
246
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesNoncompressed) == WindowsInstallerConstants.MsidbFileAttributesNoncompressed ? FileTupleAttributes.Uncompressed : 0;
247
+ tupleAttributes |= (attributes & WindowsInstallerConstants.MsidbFileAttributesCompressed) == WindowsInstallerConstants.MsidbFileAttributesCompressed ? FileTupleAttributes.Compressed : 0;
248
249
var id = FieldAsString(row, 0);
250
@@ -258,12 +255,7 @@ namespace WixToolset.Converters.Tupleizer
255
FileSize = FieldAsInt(row, 3),
256
Version = FieldAsString(row, 4),
257
Language = FieldAsString(row, 5),
261
- ReadOnly = readOnly,
262
- Hidden = hidden,
263
- System = system,
264
- Vital = vital,
265
- Checksum = checksum,
266
- Compressed = compressed,
258
+ Attributes = tupleAttributes
259
};
260
261
if (bindPathsById.TryGetValue(id, out var bindPathRow))
@@ -281,6 +273,16 @@ namespace WixToolset.Converters.Tupleizer
273
tuple.SelfRegCost = FieldAsNullableInt(selfRegRow, 1) ?? 0;
274
}
275
276
+ if (wixFileById.TryGetValue(id, out var wixFileRow))
277
+ {
278
+ tuple.DirectoryRef = FieldAsString(wixFileRow, 4);
279
+ tuple.DiskId = FieldAsNullableInt(wixFileRow, 5) ?? 0;
280
+ tuple.Source = new IntermediateFieldPathValue() { Path = FieldAsString(wixFileRow, 6) };
281
+ tuple.PatchGroup = FieldAsInt(wixFileRow, 8);
282
+ tuple.Attributes |= FieldAsInt(wixFileRow, 9) != 0 ? FileTupleAttributes.GeneratedShortFileName : 0;
283
+ tuple.PatchAttributes = (PatchAttributeType)FieldAsInt(wixFileRow, 10);
284
+ }
285
+
286
return tuple;
287
}
288
case "Font":
@@ -321,7 +323,22 @@ namespace WixToolset.Converters.Tupleizer
323
case "MoveFile":
324
return DefaultTupleFromRow(typeof(MoveFileTuple), row, columnZeroIsId: true);
325
case "MsiAssembly":
324
- return DefaultTupleFromRow(typeof(MsiAssemblyTuple), row, columnZeroIsId: false);
326
+ {
327
+ var componentId = FieldAsString(row, 0);
328
+ if (componentsById.TryGetValue(componentId, out var componentRow))
329
+ {
330
+ return new AssemblyTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(componentRow, 5)))
331
+ {
332
+ ComponentRef = componentId,
333
+ FeatureRef = FieldAsString(row, 1),
334
+ ManifestFileRef = FieldAsString(row, 2),
335
+ ApplicationFileRef = FieldAsString(row, 3),
336
+ Type = FieldAsNullableInt(row, 4) == 1 ? AssemblyType.Win32Assembly : AssemblyType.DotNetAssembly,
337
+ };
338
+ }
339
+
340
+ return null;
341
+ }
342
case "MsiLockPermissionsEx":
343
return DefaultTupleFromRow(typeof(MsiLockPermissionsExTuple), row, columnZeroIsId: true);
344
case "MsiShortcutProperty":
@@ -504,6 +521,7 @@ namespace WixToolset.Converters.Tupleizer
521
case "Verb":
522
return DefaultTupleFromRow(typeof(VerbTuple), row, columnZeroIsId: false);
523
case "WixAction":
524
+ {
525
var sequenceTable = FieldAsString(row, 0);
526
return new WixActionTuple(SourceLineNumber4(row.SourceLineNumbers))
527
{
@@ -515,6 +533,7 @@ namespace WixToolset.Converters.Tupleizer
533
After = FieldAsString(row, 5),
534
Overridable = FieldAsNullableInt(row, 6) != 0,
535
};
536
+ }
537
case "WixBootstrapperApplication":
538
return DefaultTupleFromRow(typeof(WixBootstrapperApplicationTuple), row, columnZeroIsId: true);
539
case "WixBundleContainer":
@@ -525,25 +544,10 @@ namespace WixToolset.Converters.Tupleizer
544
return DefaultTupleFromRow(typeof(WixChainItemTuple), row, columnZeroIsId: true);
545
case "WixCustomTable":
546
return DefaultTupleFromRow(typeof(WixCustomTableTuple), row, columnZeroIsId: true);
528
- case "WixDeltaPatchFile":
529
- return DefaultTupleFromRow(typeof(WixDeltaPatchFileTuple), row, columnZeroIsId: true);
547
case "WixDirectory":
548
return null;
549
case "WixFile":
533
- var assemblyAttributes3 = FieldAsNullableInt(row, 1);
534
- return new WixFileTuple(SourceLineNumber4(row.SourceLineNumbers), new Identifier(AccessModifier.Public, FieldAsString(row, 0)))
535
- {
536
- AssemblyType = assemblyAttributes3 == 0 ? FileAssemblyType.DotNetAssembly : assemblyAttributes3 == 1 ? FileAssemblyType.Win32Assembly : FileAssemblyType.NotAnAssembly,
537
- AssemblyManifestFileRef = FieldAsString(row, 2),
538
- AssemblyApplicationFileRef = FieldAsString(row, 3),
539
- DirectoryRef = FieldAsString(row, 4),
540
- DiskId = FieldAsNullableInt(row, 5) ?? 0,
541
- Source = new IntermediateFieldPathValue() { Path = FieldAsString(row, 6) },
542
- ProcessorArchitecture = FieldAsString(row, 7),
543
- PatchGroup = FieldAsInt(row, 8),
544
- Attributes = FieldAsInt(row, 9),
545
- PatchAttributes = (PatchAttributeType)FieldAsInt(row, 10),
546
- };
550
+ return null;
551
case "WixInstanceTransforms":
552
return DefaultTupleFromRow(typeof(WixInstanceTransformsTuple), row, columnZeroIsId: true);
553
case "WixMedia":
src/test/WixToolsetTest.Converters.Tupleizer/ConvertTuplesFixture.cs
+70
-24
@@ -56,8 +56,11 @@ namespace WixToolsetTest.Converters.Tupleizer
56
.ToArray();
57
58
var tuples = intermediate.Sections.SelectMany(s => s.Tuples);
59
+
60
+ var assemblyTuplesByFileId = tuples.OfType<AssemblyTuple>().ToDictionary(a => a.Id.Id);
61
+
62
var wix4Dump = tuples
60
- .SelectMany(tuple => TupleToStrings(tuple))
63
+ .SelectMany(tuple => TupleToStrings(tuple, assemblyTuplesByFileId))
64
.OrderBy(s => s)
65
.ToArray();
66
@@ -67,8 +70,11 @@ namespace WixToolsetTest.Converters.Tupleizer
70
var wix3TextDump = String.Join(Environment.NewLine, wix3Dump);
71
var wix4TextDump = String.Join(Environment.NewLine, wix4Dump);
72
70
- File.WriteAllText(Path.Combine(Path.GetTempPath(), "~3.txt"), wix3TextDump);
71
- File.WriteAllText(Path.Combine(Path.GetTempPath(), "~4.txt"), wix4TextDump);
73
+ var path3 = Path.Combine(Path.GetTempPath(), "~3.txt");
74
+ var path4 = Path.Combine(Path.GetTempPath(), "~4.txt");
75
+
76
+ File.WriteAllText(path3, wix3TextDump);
77
+ File.WriteAllText(path4, wix4TextDump);
78
79
Assert.Equal(wix3TextDump, wix4TextDump);
80
#endif
@@ -143,13 +149,19 @@ namespace WixToolsetTest.Converters.Tupleizer
149
break;
150
case "WixFile":
151
{
146
- var fieldValues = row.Fields.Take(10).Select(SafeConvertField).ToArray();
152
+ var fieldValues = row.Fields.Select(SafeConvertField).ToArray();
153
if (fieldValues[8] == null)
154
{
155
// "Somebody" sometimes writes out a null field even when the column definition says
156
// it's non-nullable. Not naming names or anything. (SWID tags.)
157
fieldValues[8] = "0";
158
}
159
+ if (fieldValues[10] == null)
160
+ {
161
+ // WixFile rows that come from merge modules will not have the attributes column set
162
+ // so initilaize with 0.
163
+ fieldValues[10] = "0";
164
+ }
165
fields = String.Join(",", fieldValues);
166
break;
167
}
@@ -166,8 +178,11 @@ namespace WixToolsetTest.Converters.Tupleizer
178
}
179
}
180
169
- private static IEnumerable<string> TupleToStrings(IntermediateTuple tuple)
181
+ private static IEnumerable<string> TupleToStrings(IntermediateTuple tuple, Dictionary<string, AssemblyTuple> assemblyTuplesByFileId)
182
{
183
+ var name = tuple.Definition.Type == TupleDefinitionType.SummaryInformation ? "_SummaryInformation" : tuple.Definition.Name;
184
+ var id = tuple.Id?.Id ?? String.Empty;
185
+
186
string fields;
187
switch (tuple.Definition.Name)
188
{
@@ -280,20 +295,53 @@ namespace WixToolsetTest.Converters.Tupleizer
295
yield return $"SelfReg:{fileTuple.Id.Id},{fileTuple.SelfRegCost}";
296
}
297
298
+ int? assemblyAttributes = null;
299
+ if (assemblyTuplesByFileId.TryGetValue(fileTuple.Id.Id, out var assemblyTuple))
300
+ {
301
+ if (assemblyTuple.Type == AssemblyType.DotNetAssembly)
302
+ {
303
+ assemblyAttributes = 0;
304
+ }
305
+ else if (assemblyTuple.Type == AssemblyType.Win32Assembly)
306
+ {
307
+ assemblyAttributes = 1;
308
+ }
309
+ }
310
+
311
+ yield return "WixFile:" + String.Join(",",
312
+ fileTuple.Id.Id,
313
+ assemblyAttributes,
314
+ assemblyTuple?.ManifestFileRef,
315
+ assemblyTuple?.ApplicationFileRef,
316
+ fileTuple.DirectoryRef,
317
+ fileTuple.DiskId,
318
+ fileTuple.Source.Path,
319
+ null, // assembly processor arch
320
+ fileTuple.PatchGroup,
321
+ (fileTuple.Attributes & FileTupleAttributes.GeneratedShortFileName) != 0 ? 1 : 0,
322
+ (int)fileTuple.PatchAttributes,
323
+ fileTuple.RetainLengths,
324
+ fileTuple.IgnoreOffsets,
325
+ fileTuple.IgnoreLengths,
326
+ fileTuple.RetainOffsets
327
+ );
328
+
329
+ var fileAttributes = 0;
330
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.ReadOnly) != 0 ? WindowsInstallerConstants.MsidbFileAttributesReadOnly : 0;
331
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.Hidden) != 0 ? WindowsInstallerConstants.MsidbFileAttributesHidden : 0;
332
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.System) != 0 ? WindowsInstallerConstants.MsidbFileAttributesSystem : 0;
333
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.Vital) != 0 ? WindowsInstallerConstants.MsidbFileAttributesVital : 0;
334
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.Checksum) != 0 ? WindowsInstallerConstants.MsidbFileAttributesChecksum : 0;
335
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.Compressed) != 0 ? WindowsInstallerConstants.MsidbFileAttributesCompressed : 0;
336
+ fileAttributes |= (fileTuple.Attributes & FileTupleAttributes.Uncompressed) != 0 ? WindowsInstallerConstants.MsidbFileAttributesNoncompressed : 0;
337
+
338
fields = String.Join(",",
339
fileTuple.ComponentRef,
340
fileTuple.Name,
341
fileTuple.FileSize.ToString(),
342
fileTuple.Version,
343
fileTuple.Language,
289
- ((fileTuple.ReadOnly ? WindowsInstallerConstants.MsidbFileAttributesReadOnly : 0)
290
- | (fileTuple.Hidden ? WindowsInstallerConstants.MsidbFileAttributesHidden : 0)
291
- | (fileTuple.System ? WindowsInstallerConstants.MsidbFileAttributesSystem : 0)
292
- | (fileTuple.Vital ? WindowsInstallerConstants.MsidbFileAttributesVital : 0)
293
- | (fileTuple.Checksum ? WindowsInstallerConstants.MsidbFileAttributesChecksum : 0)
294
- | ((fileTuple.Compressed.HasValue && fileTuple.Compressed.Value) ? WindowsInstallerConstants.MsidbFileAttributesCompressed : 0)
295
- | ((fileTuple.Compressed.HasValue && !fileTuple.Compressed.Value) ? WindowsInstallerConstants.MsidbFileAttributesNoncompressed : 0))
296
- .ToString());
344
+ fileAttributes);
345
break;
346
}
347
@@ -301,6 +349,15 @@ namespace WixToolsetTest.Converters.Tupleizer
349
fields = String.Join(",", tuple.Fields.Skip(1).Select(SafeConvertField));
350
break;
351
352
+ case "Assembly":
353
+ {
354
+ var assemblyTuple = (AssemblyTuple)tuple;
355
+
356
+ id = null;
357
+ name = "MsiAssembly";
358
+ fields = String.Join(",", assemblyTuple.ComponentRef, assemblyTuple.FeatureRef, assemblyTuple.ManifestFileRef, assemblyTuple.ApplicationFileRef, assemblyTuple.Type == AssemblyType.Win32Assembly ? 1 : 0);
359
+ break;
360
+ }
361
case "Registry":
362
{
363
var registryTuple = (RegistryTuple)tuple;
@@ -468,15 +525,6 @@ namespace WixToolsetTest.Converters.Tupleizer
525
break;
526
}
527
471
- case "WixFile":
472
- {
473
- var wixFileTuple = (WixFileTuple)tuple;
474
- fields = String.Concat(
475
- wixFileTuple.AssemblyType == FileAssemblyType.DotNetAssembly ? "0" : wixFileTuple.AssemblyType == FileAssemblyType.Win32Assembly ? "1" : String.Empty, ",",
476
- String.Join(",", tuple.Fields.Skip(1).Take(8).Select(field => (string)field)));
477
- break;
478
- }
479
-
528
case "WixProperty":
529
{
530
var wixPropertyTuple = (WixPropertyTuple)tuple;
@@ -496,8 +544,6 @@ namespace WixToolsetTest.Converters.Tupleizer
544
break;
545
}
546
499
- var name = tuple.Definition.Type == TupleDefinitionType.SummaryInformation ? "_SummaryInformation" : tuple.Definition.Name;
500
- var id = tuple.Id?.Id ?? String.Empty;
547
fields = String.IsNullOrEmpty(id) ? fields : String.IsNullOrEmpty(fields) ? id : $"{id},{fields}";
548
yield return $"{name}:{fields}";
549
}