From 6d8b6f79b44b6a41a630aa3aad5a3c7f16701798 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 11 Apr 2020 21:49:09 +1000 Subject: General cleanup. Try not to send strings to specify the tuple or table. Try to avoid using the Set method on tuples. Always create new tuples and add them to the section in the same line. --- .../Bind/AddCreateFoldersCommand.cs | 6 ++-- .../Bind/AssignMediaCommand.cs | 31 ++++++++---------- .../Bind/AttachPatchTransformsCommand.cs | 2 +- .../Bind/BindSummaryInfoCommand.cs | 38 +++++++++++----------- .../Bind/CreateSpecialPropertiesCommand.cs | 24 +++++++------- .../Bind/SequenceActionsCommand.cs | 2 +- .../Bind/UpdateFileFacadesCommand.cs | 20 ++++++------ 7 files changed, 59 insertions(+), 64 deletions(-) (limited to 'src/WixToolset.Core.WindowsInstaller/Bind') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs index 6cc4153f..ba844da4 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AddCreateFoldersCommand.cs @@ -26,13 +26,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind { if (!createFolderTuplesByComponentRef.Contains(componentTuple.Id.Id)) { - var createFolderTuple = new CreateFolderTuple(componentTuple.SourceLineNumbers) + this.Section.AddTuple(new CreateFolderTuple(componentTuple.SourceLineNumbers) { DirectoryRef = componentTuple.DirectoryRef, ComponentRef = componentTuple.Id.Id, - }; - - this.Section.Tuples.Add(createFolderTuple); + }); } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs index 2bfd587f..ae7e5788 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AssignMediaCommand.cs @@ -71,12 +71,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind // When building merge module, all the files go to "#MergeModule.CABinet". if (SectionType.Module == this.Section.Type) { - var mergeModuleMediaRow = new MediaTuple(); - mergeModuleMediaRow.Cabinet = "#MergeModule.CABinet"; - - this.Section.Tuples.Add(mergeModuleMediaRow); + var mergeModuleMediaTuple = this.Section.AddTuple(new MediaTuple + { + Cabinet = "#MergeModule.CABinet", + }); - filesByCabinetMedia.Add(mergeModuleMediaRow, new List(this.FileFacades)); + filesByCabinetMedia.Add(mergeModuleMediaTuple, new List(this.FileFacades)); } else if (mediaTemplateTable.Count == 0) { @@ -212,13 +212,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind // If there are uncompressed files and no MediaRow, create a default one. if (uncompressedFiles.Count > 0 && !this.Section.Tuples.OfType().Any()) { - var defaultMediaRow = new MediaTuple(null, new Identifier(AccessModifier.Private, 1)) + var defaultMediaRow = this.Section.AddTuple(new MediaTuple(null, new Identifier(AccessModifier.Private, 1)) { - DiskId = 1 - }; + DiskId = 1, + }); mediaRows.Add(1, defaultMediaRow); - this.Section.Tuples.Add(defaultMediaRow); } } @@ -298,14 +297,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// private MediaTuple AddMediaRow(WixMediaTemplateTuple mediaTemplateTuple, int cabIndex) { - var currentMediaTuple = new MediaTuple(mediaTemplateTuple.SourceLineNumbers, new Identifier(AccessModifier.Private, cabIndex)); - currentMediaTuple.DiskId = cabIndex; - currentMediaTuple.Cabinet = String.Format(CultureInfo.InvariantCulture, this.CabinetNameTemplate, cabIndex); - currentMediaTuple.CompressionLevel = mediaTemplateTuple.CompressionLevel; - - this.Section.Tuples.Add(currentMediaTuple); - - return currentMediaTuple; + return this.Section.AddTuple(new MediaTuple(mediaTemplateTuple.SourceLineNumbers, new Identifier(AccessModifier.Private, cabIndex)) + { + DiskId = cabIndex, + Cabinet = String.Format(CultureInfo.InvariantCulture, this.CabinetNameTemplate, cabIndex), + CompressionLevel = mediaTemplateTuple.CompressionLevel, + }); } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs index f4fa510f..ca6bfd2f 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/AttachPatchTransformsCommand.cs @@ -225,7 +225,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Put the summary information that was extracted back in now that it is updated. foreach (var readSummaryInfo in summaryInfo.Values.OrderBy(s => s.PropertyId)) { - section.Tuples.Add(readSummaryInfo); + section.AddTuple(readSummaryInfo); } this.SubStorages = subStorages; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs index 8aa6047f..7a9dbc69 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindSummaryInfoCommand.cs @@ -44,10 +44,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.InstallerVersion = 0; this.ModularizationGuid = null; - bool foundCreateDataTime = false; - bool foundLastSaveDataTime = false; - bool foundCreatingApplication = false; - string now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); + var foundCreateDataTime = false; + var foundLastSaveDataTime = false; + var foundCreatingApplication = false; + var now = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss", CultureInfo.InvariantCulture); foreach (var summaryInformationTuple in this.Section.Tuples.OfType()) { @@ -110,31 +110,31 @@ namespace WixToolset.Core.WindowsInstaller.Bind // add a summary information row for the create time/date property if its not already set if (!foundCreateDataTime) { - var createTimeDateRow = new SummaryInformationTuple(null); - createTimeDateRow.PropertyId = SumaryInformationType.Created; - createTimeDateRow.Value = now; - - this.Section.Tuples.Add(createTimeDateRow); + this.Section.AddTuple(new SummaryInformationTuple(null) + { + PropertyId = SumaryInformationType.Created, + Value = now, + }); } // add a summary information row for the last save time/date property if its not already set if (!foundLastSaveDataTime) { - var lastSaveTimeDateRow = new SummaryInformationTuple(null); - lastSaveTimeDateRow.PropertyId = SumaryInformationType.LastSaved; - lastSaveTimeDateRow.Value = now; - - this.Section.Tuples.Add(lastSaveTimeDateRow); + this.Section.AddTuple(new SummaryInformationTuple(null) + { + PropertyId = SumaryInformationType.LastSaved, + Value = now, + }); } // add a summary information row for the creating application property if its not already set if (!foundCreatingApplication) { - var creatingApplicationRow = new SummaryInformationTuple(null); - creatingApplicationRow.PropertyId = SumaryInformationType.CreatingApplication; - creatingApplicationRow.Value = String.Format(CultureInfo.InvariantCulture, AppCommon.GetCreatingApplicationString()); - - this.Section.Tuples.Add(creatingApplicationRow); + this.Section.AddTuple(new SummaryInformationTuple(null) + { + PropertyId = SumaryInformationType.CreatingApplication, + Value = String.Format(CultureInfo.InvariantCulture, AppCommon.GetCreatingApplicationString()), + }); } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateSpecialPropertiesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateSpecialPropertiesCommand.cs index 0d165f80..5b4fe9e5 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateSpecialPropertiesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateSpecialPropertiesCommand.cs @@ -57,26 +57,26 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (0 < adminProperties.Count) { - var tuple = new PropertyTuple(null, new Identifier(AccessModifier.Private, "AdminProperties")); - tuple.Value = String.Join(";", adminProperties); - - this.Section.Tuples.Add(tuple); + this.Section.AddTuple(new PropertyTuple(null, new Identifier(AccessModifier.Private, "AdminProperties")) + { + Value = String.Join(";", adminProperties), + }); } if (0 < secureProperties.Count) { - var tuple = new PropertyTuple(null, new Identifier(AccessModifier.Private, "SecureCustomProperties")); - tuple.Value = String.Join(";", secureProperties); - - this.Section.Tuples.Add(tuple); + this.Section.AddTuple(new PropertyTuple(null, new Identifier(AccessModifier.Private, "SecureCustomProperties")) + { + Value = String.Join(";", secureProperties), + }); } if (0 < hiddenProperties.Count) { - var tuple = new PropertyTuple(null, new Identifier(AccessModifier.Private, "MsiHiddenProperties")); - tuple.Value = String.Join(";", hiddenProperties); - - this.Section.Tuples.Add(tuple); + this.Section.AddTuple(new PropertyTuple(null, new Identifier(AccessModifier.Private, "MsiHiddenProperties")) + { + Value = String.Join(";", hiddenProperties) + }); } } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs index fe014b0b..a5055209 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/SequenceActionsCommand.cs @@ -186,7 +186,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind foreach (var action in scheduledActionTuples) { - this.Section.Tuples.Add(action); + this.Section.AddTuple(action); } } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs index 81d46b41..7ecd58d7 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs @@ -158,8 +158,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (null == facade.Hash) { - facade.Hash = new MsiFileHashTuple(facade.SourceLineNumber, facade.Identifier); - this.Section.Tuples.Add(facade.Hash); + facade.Hash = this.Section.AddTuple(new MsiFileHashTuple(facade.SourceLineNumber, facade.Identifier)); } facade.Hash.Options = 0; @@ -337,23 +336,24 @@ namespace WixToolset.Core.WindowsInstaller.Bind // override directly authored value var lookup = String.Concat(facade.ComponentRef, "/", name); - if (!assemblyNameTuples.TryGetValue(lookup, out var assemblyNameRow)) + if (!assemblyNameTuples.TryGetValue(lookup, out var assemblyNameTuple)) { - assemblyNameRow = new MsiAssemblyNameTuple(facade.SourceLineNumber); - assemblyNameRow.ComponentRef = facade.ComponentRef; - assemblyNameRow.Name = name; - assemblyNameRow.Value = value; + assemblyNameTuple = this.Section.AddTuple(new MsiAssemblyNameTuple(facade.SourceLineNumber) + { + ComponentRef = facade.ComponentRef, + Name = name, + Value = value, + }); if (null == facade.AssemblyNames) { facade.AssemblyNames = new List(); } - facade.AssemblyNames.Add(assemblyNameRow); - this.Section.Tuples.Add(assemblyNameRow); + facade.AssemblyNames.Add(assemblyNameTuple); } - assemblyNameRow.Value = value; + assemblyNameTuple.Value = value; if (this.VariableCache != null) { -- cgit v1.2.3-55-g6feb