From 75fd55d5a71c492c6ea904768858c51aa97da29f Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 8 May 2019 14:13:31 -0700 Subject: Use new strongly typed tuples --- .../Bind/CalculateComponentGuids.cs | 39 ++++++++++------------ 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs index b8f1b2f3..a773519a 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs @@ -1,4 +1,4 @@ -// 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. +// 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. namespace WixToolset.Core.WindowsInstaller.Bind { @@ -37,37 +37,32 @@ namespace WixToolset.Core.WindowsInstaller.Bind Dictionary> filesByComponentId = null; // Find components with generatable guids. - foreach (var componentRow in this.Section.Tuples.OfType()) + foreach (var componentTuple in this.Section.Tuples.OfType()) { // Skip components that do not specify generate guid. - if (componentRow.ComponentId != "*") + if (componentTuple.ComponentId != "*") { continue; } - var odbcDataSourceKeyPath = (componentRow.Attributes & MsiInterop.MsidbComponentAttributesODBCDataSource) != 0; - - if (String.IsNullOrEmpty(componentRow.KeyPath) || odbcDataSourceKeyPath) + if (String.IsNullOrEmpty(componentTuple.KeyPath) || ComponentKeyPathType.OdbcDataSource == componentTuple.KeyPathType) { - this.Messaging.Write(ErrorMessages.IllegalComponentWithAutoGeneratedGuid(componentRow.SourceLineNumbers)); + this.Messaging.Write(ErrorMessages.IllegalComponentWithAutoGeneratedGuid(componentTuple.SourceLineNumbers)); continue; } - var registryKeyPath = (componentRow.Attributes & MsiInterop.MsidbComponentAttributesRegistryKeyPath) != 0; - - if (registryKeyPath) + if (ComponentKeyPathType.Registry == componentTuple.KeyPathType) { if (registryKeyRows is null) { - registryKeyRows = this.Section.Tuples.OfType().ToDictionary(t => t.Registry); + registryKeyRows = this.Section.Tuples.OfType().ToDictionary(t => t.Id.Id); } - if (registryKeyRows.TryGetValue(componentRow.KeyPath, out var foundRow)) + if (registryKeyRows.TryGetValue(componentTuple.KeyPath, out var foundRow)) { - var is64Bit = (componentRow.Attributes & MsiInterop.MsidbComponentAttributes64bit) != 0; - var bitness = is64Bit ? "64" : String.Empty; + var bitness = componentTuple.Win64 ? "64" : String.Empty; var regkey = String.Concat(bitness, foundRow.AsString(1), "\\", foundRow.AsString(2), "\\", foundRow.AsString(3)); - componentRow.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, regkey.ToLowerInvariant()); + componentTuple.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, regkey.ToLowerInvariant()); } } else // must be a File KeyPath. @@ -128,16 +123,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind } // validate component meets all the conditions to have a generated guid - var currentComponentFiles = filesByComponentId[componentRow.Component]; + var currentComponentFiles = filesByComponentId[componentTuple.Component]; var numFilesInComponent = currentComponentFiles.Count; string path = null; foreach (var fileRow in currentComponentFiles) { - if (fileRow.File == componentRow.KeyPath) + if (fileRow.File == componentTuple.KeyPath) { // calculate the key file's canonical target path - string directoryPath = PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentRow.Directory_, true); + string directoryPath = PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentTuple.Directory_, true); string fileName = Common.GetName(fileRow.LongFileName, false, true).ToLowerInvariant(); path = Path.Combine(directoryPath, fileName); @@ -149,13 +144,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind path.StartsWith(@"StartMenuFolder\programs", StringComparison.Ordinal) || path.StartsWith(@"WindowsFolder\fonts", StringComparison.Ordinal)) { - this.Messaging.Write(ErrorMessages.IllegalPathForGeneratedComponentGuid(componentRow.SourceLineNumbers, fileRow.Component_, path)); + this.Messaging.Write(ErrorMessages.IllegalPathForGeneratedComponentGuid(componentTuple.SourceLineNumbers, fileRow.Component_, path)); } // if component has more than one file, the key path must be versioned if (1 < numFilesInComponent && String.IsNullOrEmpty(fileRow.Version)) { - this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentUnversionedKeypath(componentRow.SourceLineNumbers)); + this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentUnversionedKeypath(componentTuple.SourceLineNumbers)); } } else @@ -163,7 +158,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // not a key path, so it must be an unversioned file if component has more than one file if (1 < numFilesInComponent && !String.IsNullOrEmpty(fileRow.Version)) { - this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentVersionedNonkeypath(componentRow.SourceLineNumbers)); + this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentVersionedNonkeypath(componentTuple.SourceLineNumbers)); } } } @@ -171,7 +166,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // if the rules were followed, reward with a generated guid if (!this.Messaging.EncounteredError) { - componentRow.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, path); + componentTuple.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, path); } } } -- cgit v1.2.3-55-g6feb