From 9cca339473d77c7036035f949239f5231c325968 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Fri, 26 Mar 2021 12:59:03 -0700 Subject: Integrate the IntermediateSection and IntermediateSymbol mutable changes --- .../OrderPackagesAndRollbackBoundariesCommand.cs | 2 +- .../Bind/AssignMediaCommand.cs | 32 ++++------- .../Bind/AttachPatchTransformsCommand.cs | 27 ++++----- .../Bind/SequenceActionsCommand.cs | 17 ++---- src/WixToolset.Core/CompilerCore.cs | 3 +- src/WixToolset.Core/Librarian.cs | 2 +- src/WixToolset.Core/Link/WixGroupingOrdering.cs | 66 +++++++++------------- src/WixToolset.Core/Linker.cs | 13 ++++- 8 files changed, 69 insertions(+), 93 deletions(-) (limited to 'src') diff --git a/src/WixToolset.Core.Burn/Bundles/OrderPackagesAndRollbackBoundariesCommand.cs b/src/WixToolset.Core.Burn/Bundles/OrderPackagesAndRollbackBoundariesCommand.cs index f16ac707..19fd7619 100644 --- a/src/WixToolset.Core.Burn/Bundles/OrderPackagesAndRollbackBoundariesCommand.cs +++ b/src/WixToolset.Core.Burn/Bundles/OrderPackagesAndRollbackBoundariesCommand.cs @@ -65,7 +65,7 @@ namespace WixToolset.Core.Burn.Bundles // If we used the default boundary, ensure the symbol is added to the section. if (pendingRollbackBoundary.Id.Id == DefaultBoundaryId) { - this.Section.Symbols.Add(pendingRollbackBoundary); + this.Section.AddSymbol(pendingRollbackBoundary); } if (insideMsiTransaction && !warnedMsiTransaction) diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs index d7faa382..cfa84629 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs @@ -86,25 +86,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.UncompressedFileFacades = Array.Empty(); } - else if (mediaTemplateSymbols.Count == 0) - { - var filesByCabinetMedia = new Dictionary>(); - - var uncompressedFiles = new List(); - - this.ManuallyAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); - - this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable)kvp.Value); - - this.UncompressedFileFacades = uncompressedFiles; - } else { var filesByCabinetMedia = new Dictionary>(); - var uncompressedFiles = new List(); - this.AutoAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); + if (mediaTemplateSymbols.Count > 0) + { + this.AutoAssignFiles(mediaTemplateSymbols, mediaSymbols, filesByCabinetMedia, uncompressedFiles); + } + else + { + this.ManuallyAssignFiles(mediaSymbols, filesByCabinetMedia, uncompressedFiles); + } this.FileFacadesByCabinetMedia = filesByCabinetMedia.ToDictionary(kvp => kvp.Key, kvp => (IEnumerable)kvp.Value); @@ -115,7 +109,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// /// Assign files to cabinets based on MediaTemplate authoring. /// - private void AutoAssignFiles(List mediaTable, Dictionary> filesByCabinetMedia, List uncompressedFiles) + private void AutoAssignFiles(List mediaTemplateTable, List mediaSymbols, Dictionary> filesByCabinetMedia, List uncompressedFiles) { const int MaxCabIndex = 999; @@ -126,13 +120,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind MediaSymbol currentMediaRow = null; - var mediaTemplateTable = this.Section.Symbols.OfType(); - // Remove all previous media symbols since they will be replaced with // media template. - foreach (var mediaSymbol in mediaTable) + foreach (var mediaSymbol in mediaSymbols) { - this.Section.Symbols.Remove(mediaSymbol); + this.Section.RemoveSymbol(mediaSymbol); } // Auto assign files to cabinets based on maximum uncompressed media size @@ -218,7 +210,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind } // If there are uncompressed files and no MediaRow, create a default one. - if (uncompressedFiles.Count > 0 && !this.Section.Symbols.OfType().Any()) + if (uncompressedFiles.Count > 0 && mediaSymbolsByDiskId.Count == 0) { var defaultMediaRow = this.Section.AddSymbol(new MediaSymbol(null, new Identifier(AccessModifier.Section, 1)) { diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs index 6d802d98..5f8df92c 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs @@ -241,23 +241,20 @@ namespace WixToolset.Core.WindowsInstaller.Bind foreach (var section in this.Intermediate.Sections) { - for (var i = section.Symbols.Count - 1; i >= 0; i--) + // Remove all summary information from the symbols and remember those that + // are not calculated or reserved. + foreach (var patchSummaryInfo in section.Symbols.OfType().ToList()) { - if (section.Symbols[i] is SummaryInformationSymbol patchSummaryInfo) + section.RemoveSymbol(patchSummaryInfo); + + if (patchSummaryInfo.PropertyId != SummaryInformationType.PatchProductCodes && + patchSummaryInfo.PropertyId != SummaryInformationType.PatchCode && + patchSummaryInfo.PropertyId != SummaryInformationType.PatchInstallerRequirement && + patchSummaryInfo.PropertyId != SummaryInformationType.Reserved11 && + patchSummaryInfo.PropertyId != SummaryInformationType.Reserved14 && + patchSummaryInfo.PropertyId != SummaryInformationType.Reserved16) { - // Remove all summary information from the symbols and remember those that - // are not calculated or reserved. - section.Symbols.RemoveAt(i); - - if (patchSummaryInfo.PropertyId != SummaryInformationType.PatchProductCodes && - patchSummaryInfo.PropertyId != SummaryInformationType.PatchCode && - patchSummaryInfo.PropertyId != SummaryInformationType.PatchInstallerRequirement && - patchSummaryInfo.PropertyId != SummaryInformationType.Reserved11 && - patchSummaryInfo.PropertyId != SummaryInformationType.Reserved14 && - patchSummaryInfo.PropertyId != SummaryInformationType.Reserved16) - { - result.Add(patchSummaryInfo.PropertyId, patchSummaryInfo); - } + result.Add(patchSummaryInfo.PropertyId, patchSummaryInfo); } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs index 5e72ec5c..94fa0a6a 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs @@ -173,21 +173,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind } // Remove all existing WixActionSymbols from the section then add the - // scheduled actions back to the section. Note: we add the indices in - // reverse order to make it easy to remove them from the list later. - var removeIndices = new List(); - for (var i = this.Section.Symbols.Count - 1; i >= 0; --i) - { - var symbol = this.Section.Symbols[i]; - if (symbol.Definition.Type == SymbolDefinitionType.WixAction) - { - removeIndices.Add(i); - } - } + // scheduled actions back to the section. + var removeActionSymbols = this.Section.Symbols.Where(s => s.Definition.Type == SymbolDefinitionType.WixAction).ToList(); - foreach (var removeIndex in removeIndices) + foreach (var removeSymbol in removeActionSymbols) { - this.Section.Symbols.RemoveAt(removeIndex); + this.Section.RemoveSymbol(removeSymbol); } foreach (var action in scheduledActionSymbols) diff --git a/src/WixToolset.Core/CompilerCore.cs b/src/WixToolset.Core/CompilerCore.cs index d737b359..0bc63d79 100644 --- a/src/WixToolset.Core/CompilerCore.cs +++ b/src/WixToolset.Core/CompilerCore.cs @@ -1059,8 +1059,7 @@ namespace WixToolset.Core /// New section. internal IntermediateSection CreateSection(string id, SectionType type, int codepage, string compilationId) { - var section = new IntermediateSection(id, type, codepage); - section.CompilationId = compilationId; + var section = new IntermediateSection(id, type, codepage, compilationId); this.intermediate.Sections.Add(section); diff --git a/src/WixToolset.Core/Librarian.cs b/src/WixToolset.Core/Librarian.cs index 059a478b..1dd1b44d 100644 --- a/src/WixToolset.Core/Librarian.cs +++ b/src/WixToolset.Core/Librarian.cs @@ -60,7 +60,7 @@ namespace WixToolset.Core foreach (var section in sections) { - section.LibraryId = context.LibraryId; + section.AssignToLibrary(context.LibraryId); } library = new Intermediate(context.LibraryId, IntermediateLevels.Compiled, sections, localizationsByCulture); diff --git a/src/WixToolset.Core/Link/WixGroupingOrdering.cs b/src/WixToolset.Core/Link/WixGroupingOrdering.cs index a8044a0c..99220900 100644 --- a/src/WixToolset.Core/Link/WixGroupingOrdering.cs +++ b/src/WixToolset.Core/Link/WixGroupingOrdering.cs @@ -23,7 +23,7 @@ namespace WixToolset.Core.Link private List groupTypes; private List itemTypes; private ItemCollection items; - private readonly List rowsUsed; + private readonly List symbolsUsed; private bool loaded; /// @@ -36,7 +36,7 @@ namespace WixToolset.Core.Link this.EntrySection = entrySections; this.Messaging = messageHandler; - this.rowsUsed = new List(); + this.symbolsUsed = new List(); this.loaded = false; } @@ -144,16 +144,9 @@ namespace WixToolset.Core.Link /// public void RemoveUsedGroupRows() { - var sortedIndexes = this.rowsUsed.Distinct().OrderByDescending(i => i).ToList(); - - //Table wixGroupTable = this.output.Tables["WixGroup"]; - //Debug.Assert(null != wixGroupTable); - //Debug.Assert(sortedIndexes[0] < wixGroupTable.Rows.Count); - - foreach (int rowIndex in sortedIndexes) + foreach (var symbol in this.symbolsUsed) { - //wixGroupTable.Rows.RemoveAt(rowIndex); - this.EntrySection.Symbols.RemoveAt(rowIndex); + this.EntrySection.RemoveSymbol(symbol); } } @@ -236,39 +229,36 @@ namespace WixToolset.Core.Link //} // Collect all of the groups - for (int rowIndex = 0; rowIndex < this.EntrySection.Symbols.Count; ++rowIndex) + foreach (var symbol in this.EntrySection.Symbols.OfType()) { - if (this.EntrySection.Symbols[rowIndex] is WixGroupSymbol row) + var rowParentName = symbol.ParentId; + var rowParentType = symbol.ParentType.ToString(); + var rowChildName = symbol.ChildId; + var rowChildType = symbol.ChildType.ToString(); + + // If this row specifies a parent or child type that's not in our + // lists, we assume it's not a row that we're concerned about. + if (!this.groupTypes.Contains(rowParentType) || + !this.itemTypes.Contains(rowChildType)) { - var rowParentName = row.ParentId; - var rowParentType = row.ParentType.ToString(); - var rowChildName = row.ChildId; - var rowChildType = row.ChildType.ToString(); - - // If this row specifies a parent or child type that's not in our - // lists, we assume it's not a row that we're concerned about. - if (!this.groupTypes.Contains(rowParentType) || - !this.itemTypes.Contains(rowChildType)) - { - continue; - } + continue; + } - this.rowsUsed.Add(rowIndex); + this.symbolsUsed.Add(symbol); - if (!this.items.TryGetValue(rowParentType, rowParentName, out var parentItem)) - { - parentItem = new Item(row, rowParentType, rowParentName); - this.items.Add(parentItem); - } - - if (!this.items.TryGetValue(rowChildType, rowChildName, out var childItem)) - { - childItem = new Item(row, rowChildType, rowChildName); - this.items.Add(childItem); - } + if (!this.items.TryGetValue(rowParentType, rowParentName, out var parentItem)) + { + parentItem = new Item(symbol, rowParentType, rowParentName); + this.items.Add(parentItem); + } - parentItem.ChildItems.Add(childItem); + if (!this.items.TryGetValue(rowChildType, rowChildName, out var childItem)) + { + childItem = new Item(symbol, rowChildType, rowChildName); + this.items.Add(childItem); } + + parentItem.ChildItems.Add(childItem); } } diff --git a/src/WixToolset.Core/Linker.cs b/src/WixToolset.Core/Linker.cs index a6d43715..320f7d1f 100644 --- a/src/WixToolset.Core/Linker.cs +++ b/src/WixToolset.Core/Linker.cs @@ -585,13 +585,15 @@ namespace WixToolset.Core // now and after processing added back in Step 3 below. foreach (var section in sections) { + var removeSymbols = new List(); + // Count down because we'll sometimes remove items from the list. - for (var i = section.Symbols.Count - 1; i >= 0; --i) + foreach (var symbol in section.Symbols) { // Only process the "grouping parents" such as FeatureGroup, ComponentGroup, Feature, // and Module. Non-grouping complex references are simple and // resolved during normal complex reference resolutions. - if (section.Symbols[i] is WixComplexReferenceSymbol wixComplexReferenceRow && + if (symbol is WixComplexReferenceSymbol wixComplexReferenceRow && (ComplexReferenceParentType.FeatureGroup == wixComplexReferenceRow.ParentType || ComplexReferenceParentType.ComponentGroup == wixComplexReferenceRow.ParentType || ComplexReferenceParentType.Feature == wixComplexReferenceRow.ParentType || @@ -611,7 +613,7 @@ namespace WixToolset.Core } childrenComplexRefs.Add(wixComplexReferenceRow); - section.Symbols.RemoveAt(i); + removeSymbols.Add(wixComplexReferenceRow); // Remember the mapping from set of complex references with a common // parent to their section. We'll need this to add them back to the @@ -635,6 +637,11 @@ namespace WixToolset.Core } } } + + foreach (var removeSymbol in removeSymbols) + { + section.RemoveSymbol(removeSymbol); + } } Debug.Assert(parentGroups.Count == parentGroupsSections.Count); -- cgit v1.2.3-55-g6feb