aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2019-05-08 14:13:31 -0700
committerRob Mensching <rob@firegiant.com>2019-05-08 14:44:43 -0700
commit75fd55d5a71c492c6ea904768858c51aa97da29f (patch)
tree610047db1d5759a726ce88277bb2dfddcd01da45 /src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs
parentd1dbe29f3856d012acf5f96e8e66c43b74ab490d (diff)
downloadwix-75fd55d5a71c492c6ea904768858c51aa97da29f.tar.gz
wix-75fd55d5a71c492c6ea904768858c51aa97da29f.tar.bz2
wix-75fd55d5a71c492c6ea904768858c51aa97da29f.zip
Use new strongly typed tuples
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs39
1 files changed, 17 insertions, 22 deletions
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 @@
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
3namespace WixToolset.Core.WindowsInstaller.Bind 3namespace WixToolset.Core.WindowsInstaller.Bind
4{ 4{
@@ -37,37 +37,32 @@ namespace WixToolset.Core.WindowsInstaller.Bind
37 Dictionary<string, List<FileTuple>> filesByComponentId = null; 37 Dictionary<string, List<FileTuple>> filesByComponentId = null;
38 38
39 // Find components with generatable guids. 39 // Find components with generatable guids.
40 foreach (var componentRow in this.Section.Tuples.OfType<ComponentTuple>()) 40 foreach (var componentTuple in this.Section.Tuples.OfType<ComponentTuple>())
41 { 41 {
42 // Skip components that do not specify generate guid. 42 // Skip components that do not specify generate guid.
43 if (componentRow.ComponentId != "*") 43 if (componentTuple.ComponentId != "*")
44 { 44 {
45 continue; 45 continue;
46 } 46 }
47 47
48 var odbcDataSourceKeyPath = (componentRow.Attributes & MsiInterop.MsidbComponentAttributesODBCDataSource) != 0; 48 if (String.IsNullOrEmpty(componentTuple.KeyPath) || ComponentKeyPathType.OdbcDataSource == componentTuple.KeyPathType)
49
50 if (String.IsNullOrEmpty(componentRow.KeyPath) || odbcDataSourceKeyPath)
51 { 49 {
52 this.Messaging.Write(ErrorMessages.IllegalComponentWithAutoGeneratedGuid(componentRow.SourceLineNumbers)); 50 this.Messaging.Write(ErrorMessages.IllegalComponentWithAutoGeneratedGuid(componentTuple.SourceLineNumbers));
53 continue; 51 continue;
54 } 52 }
55 53
56 var registryKeyPath = (componentRow.Attributes & MsiInterop.MsidbComponentAttributesRegistryKeyPath) != 0; 54 if (ComponentKeyPathType.Registry == componentTuple.KeyPathType)
57
58 if (registryKeyPath)
59 { 55 {
60 if (registryKeyRows is null) 56 if (registryKeyRows is null)
61 { 57 {
62 registryKeyRows = this.Section.Tuples.OfType<RegistryTuple>().ToDictionary(t => t.Registry); 58 registryKeyRows = this.Section.Tuples.OfType<RegistryTuple>().ToDictionary(t => t.Id.Id);
63 } 59 }
64 60
65 if (registryKeyRows.TryGetValue(componentRow.KeyPath, out var foundRow)) 61 if (registryKeyRows.TryGetValue(componentTuple.KeyPath, out var foundRow))
66 { 62 {
67 var is64Bit = (componentRow.Attributes & MsiInterop.MsidbComponentAttributes64bit) != 0; 63 var bitness = componentTuple.Win64 ? "64" : String.Empty;
68 var bitness = is64Bit ? "64" : String.Empty;
69 var regkey = String.Concat(bitness, foundRow.AsString(1), "\\", foundRow.AsString(2), "\\", foundRow.AsString(3)); 64 var regkey = String.Concat(bitness, foundRow.AsString(1), "\\", foundRow.AsString(2), "\\", foundRow.AsString(3));
70 componentRow.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, regkey.ToLowerInvariant()); 65 componentTuple.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, regkey.ToLowerInvariant());
71 } 66 }
72 } 67 }
73 else // must be a File KeyPath. 68 else // must be a File KeyPath.
@@ -128,16 +123,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind
128 } 123 }
129 124
130 // validate component meets all the conditions to have a generated guid 125 // validate component meets all the conditions to have a generated guid
131 var currentComponentFiles = filesByComponentId[componentRow.Component]; 126 var currentComponentFiles = filesByComponentId[componentTuple.Component];
132 var numFilesInComponent = currentComponentFiles.Count; 127 var numFilesInComponent = currentComponentFiles.Count;
133 string path = null; 128 string path = null;
134 129
135 foreach (var fileRow in currentComponentFiles) 130 foreach (var fileRow in currentComponentFiles)
136 { 131 {
137 if (fileRow.File == componentRow.KeyPath) 132 if (fileRow.File == componentTuple.KeyPath)
138 { 133 {
139 // calculate the key file's canonical target path 134 // calculate the key file's canonical target path
140 string directoryPath = PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentRow.Directory_, true); 135 string directoryPath = PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentTuple.Directory_, true);
141 string fileName = Common.GetName(fileRow.LongFileName, false, true).ToLowerInvariant(); 136 string fileName = Common.GetName(fileRow.LongFileName, false, true).ToLowerInvariant();
142 path = Path.Combine(directoryPath, fileName); 137 path = Path.Combine(directoryPath, fileName);
143 138
@@ -149,13 +144,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind
149 path.StartsWith(@"StartMenuFolder\programs", StringComparison.Ordinal) || 144 path.StartsWith(@"StartMenuFolder\programs", StringComparison.Ordinal) ||
150 path.StartsWith(@"WindowsFolder\fonts", StringComparison.Ordinal)) 145 path.StartsWith(@"WindowsFolder\fonts", StringComparison.Ordinal))
151 { 146 {
152 this.Messaging.Write(ErrorMessages.IllegalPathForGeneratedComponentGuid(componentRow.SourceLineNumbers, fileRow.Component_, path)); 147 this.Messaging.Write(ErrorMessages.IllegalPathForGeneratedComponentGuid(componentTuple.SourceLineNumbers, fileRow.Component_, path));
153 } 148 }
154 149
155 // if component has more than one file, the key path must be versioned 150 // if component has more than one file, the key path must be versioned
156 if (1 < numFilesInComponent && String.IsNullOrEmpty(fileRow.Version)) 151 if (1 < numFilesInComponent && String.IsNullOrEmpty(fileRow.Version))
157 { 152 {
158 this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentUnversionedKeypath(componentRow.SourceLineNumbers)); 153 this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentUnversionedKeypath(componentTuple.SourceLineNumbers));
159 } 154 }
160 } 155 }
161 else 156 else
@@ -163,7 +158,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
163 // not a key path, so it must be an unversioned file if component has more than one file 158 // not a key path, so it must be an unversioned file if component has more than one file
164 if (1 < numFilesInComponent && !String.IsNullOrEmpty(fileRow.Version)) 159 if (1 < numFilesInComponent && !String.IsNullOrEmpty(fileRow.Version))
165 { 160 {
166 this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentVersionedNonkeypath(componentRow.SourceLineNumbers)); 161 this.Messaging.Write(ErrorMessages.IllegalGeneratedGuidComponentVersionedNonkeypath(componentTuple.SourceLineNumbers));
167 } 162 }
168 } 163 }
169 } 164 }
@@ -171,7 +166,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
171 // if the rules were followed, reward with a generated guid 166 // if the rules were followed, reward with a generated guid
172 if (!this.Messaging.EncounteredError) 167 if (!this.Messaging.EncounteredError)
173 { 168 {
174 componentRow.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, path); 169 componentTuple.ComponentId = this.BackendHelper.CreateGuid(BindDatabaseCommand.WixComponentGuidNamespace, path);
175 } 170 }
176 } 171 }
177 } 172 }