aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-06-12 12:46:48 -0700
committerRob Mensching <rob@firegiant.com>2020-06-13 09:22:27 -0700
commit86b7ea7a411813e03a2b238ca5c24fcebc947209 (patch)
tree722bdc9463a6773df4242725ec340975e6c28641 /src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs
parent404e5661ee971b9b2544185c3a28b24fafc06185 (diff)
downloadwix-86b7ea7a411813e03a2b238ca5c24fcebc947209.tar.gz
wix-86b7ea7a411813e03a2b238ca5c24fcebc947209.tar.bz2
wix-86b7ea7a411813e03a2b238ca5c24fcebc947209.zip
Move validate guids to a command and execute it earlier
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs
new file mode 100644
index 00000000..020a83fc
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/ValidateComponentGuidsCommand.cs
@@ -0,0 +1,63 @@
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
3namespace WixToolset.Core.WindowsInstaller.Bind
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using WixToolset.Data;
9 using WixToolset.Data.Tuples;
10 using WixToolset.Extensibility.Services;
11
12 /// <summary>
13 /// Validate that there are no duplicate GUIDs in the output.
14 /// </summary>
15 /// <remarks>
16 /// Duplicate GUIDs without conditions are an error condition; with conditions, it's a
17 /// warning, as the conditions might be mutually exclusive.
18 /// </remarks>
19 internal class ValidateComponentGuidsCommand
20 {
21 internal ValidateComponentGuidsCommand(IMessaging messaging, IntermediateSection section)
22 {
23 this.Messaging = messaging;
24 this.Section = section;
25 }
26
27 private IMessaging Messaging { get; }
28
29 private IntermediateSection Section { get; }
30
31 public void Execute()
32 {
33 var componentGuidConditions = new Dictionary<string, bool>();
34
35 foreach (var componentTuple in this.Section.Tuples.OfType<ComponentTuple>())
36 {
37 // We don't care about unmanaged components and if there's a * GUID remaining,
38 // there's already an error that prevented it from being replaced with a real GUID.
39 if (!String.IsNullOrEmpty(componentTuple.ComponentId) && "*" != componentTuple.ComponentId)
40 {
41 var thisComponentHasCondition = !String.IsNullOrEmpty(componentTuple.Condition);
42 var allComponentsHaveConditions = thisComponentHasCondition;
43
44 if (componentGuidConditions.TryGetValue(componentTuple.ComponentId, out var alreadyCheckedCondition))
45 {
46 allComponentsHaveConditions = thisComponentHasCondition && alreadyCheckedCondition;
47
48 if (allComponentsHaveConditions)
49 {
50 this.Messaging.Write(WarningMessages.DuplicateComponentGuidsMustHaveMutuallyExclusiveConditions(componentTuple.SourceLineNumbers, componentTuple.Id.Id, componentTuple.ComponentId));
51 }
52 else
53 {
54 this.Messaging.Write(ErrorMessages.DuplicateComponentGuids(componentTuple.SourceLineNumbers, componentTuple.Id.Id, componentTuple.ComponentId));
55 }
56 }
57
58 componentGuidConditions[componentTuple.ComponentId] = allComponentsHaveConditions;
59 }
60 }
61 }
62 }
63}