aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Validator.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Validator.cs (renamed from src/WixToolset.Core/Validator.cs)84
1 files changed, 34 insertions, 50 deletions
diff --git a/src/WixToolset.Core/Validator.cs b/src/WixToolset.Core.WindowsInstaller/Validator.cs
index 6420b9b7..db66f600 100644
--- a/src/WixToolset.Core/Validator.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Validator.cs
@@ -1,6 +1,6 @@
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 3namespace WixToolset.Core.WindowsInstaller
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
@@ -12,8 +12,10 @@ namespace WixToolset
12 using System.Threading; 12 using System.Threading;
13 using WixToolset.Data; 13 using WixToolset.Data;
14 using WixToolset.Extensibility; 14 using WixToolset.Extensibility;
15 using WixToolset.Msi;
16 using WixToolset.Core.Native; 15 using WixToolset.Core.Native;
16 using WixToolset.Msi;
17 using System.Linq;
18 using System.Reflection;
17 19
18 /// <summary> 20 /// <summary>
19 /// Runs internal consistency evaluators (ICEs) from cub files against a database. 21 /// Runs internal consistency evaluators (ICEs) from cub files against a database.
@@ -23,9 +25,7 @@ namespace WixToolset
23 private string actionName; 25 private string actionName;
24 private StringCollection cubeFiles; 26 private StringCollection cubeFiles;
25 private ValidatorExtension extension; 27 private ValidatorExtension extension;
26 private string[] ices;
27 private Output output; 28 private Output output;
28 private string[] suppressedICEs;
29 private InstallUIHandler validationUIHandler; 29 private InstallUIHandler validationUIHandler;
30 private bool validationSessionComplete; 30 private bool validationSessionComplete;
31 31
@@ -54,11 +54,7 @@ namespace WixToolset
54 /// </summary> 54 /// </summary>
55 /// <value>The list of ICEs.</value> 55 /// <value>The list of ICEs.</value>
56 [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] 56 [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
57 public string[] ICEs 57 public ISet<string> ICEs { get; set; }
58 {
59 get { return this.ices; }
60 set { this.ices = value; }
61 }
62 58
63 /// <summary> 59 /// <summary>
64 /// Gets or sets the output used for finding source line information. 60 /// Gets or sets the output used for finding source line information.
@@ -76,16 +72,12 @@ namespace WixToolset
76 /// </summary> 72 /// </summary>
77 /// <value>The suppressed ICEs.</value> 73 /// <value>The suppressed ICEs.</value>
78 [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] 74 [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
79 public string[] SuppressedICEs 75 public ISet<string> SuppressedICEs { get; set; }
80 {
81 get { return this.suppressedICEs; }
82 set { this.suppressedICEs = value; }
83 }
84 76
85 /// <summary> 77 /// <summary>
86 /// Sets the temporary path for the Binder. 78 /// Sets the temporary path for the Binder.
87 /// </summary> 79 /// </summary>
88 public string TempFilesLocation { private get; set; } 80 public string IntermediateFolder { private get; set; }
89 81
90 /// <summary> 82 /// <summary>
91 /// Add a cube file to the validation run. 83 /// Add a cube file to the validation run.
@@ -103,8 +95,6 @@ namespace WixToolset
103 /// <returns>true if validation succeeded; false otherwise.</returns> 95 /// <returns>true if validation succeeded; false otherwise.</returns>
104 public void Validate(string databaseFile) 96 public void Validate(string databaseFile)
105 { 97 {
106 Dictionary<string, string> indexedICEs = new Dictionary<string, string>();
107 Dictionary<string, string> indexedSuppressedICEs = new Dictionary<string, string>();
108 int previousUILevel = (int)InstallUILevels.Basic; 98 int previousUILevel = (int)InstallUILevels.Basic;
109 IntPtr previousHwnd = IntPtr.Zero; 99 IntPtr previousHwnd = IntPtr.Zero;
110 InstallUIHandler previousUIHandler = null; 100 InstallUIHandler previousUIHandler = null;
@@ -120,28 +110,10 @@ namespace WixToolset
120 this.extension.InitializeValidator(); 110 this.extension.InitializeValidator();
121 111
122 // Ensure the temporary files can be created. 112 // Ensure the temporary files can be created.
123 Directory.CreateDirectory(this.TempFilesLocation); 113 Directory.CreateDirectory(this.IntermediateFolder);
124
125 // index the ICEs
126 if (null != this.ices)
127 {
128 foreach (string ice in this.ices)
129 {
130 indexedICEs[ice] = null;
131 }
132 }
133
134 // index the suppressed ICEs
135 if (null != this.suppressedICEs)
136 {
137 foreach (string suppressedICE in this.suppressedICEs)
138 {
139 indexedSuppressedICEs[suppressedICE] = null;
140 }
141 }
142 114
143 // copy the database to a temporary location so it can be manipulated 115 // copy the database to a temporary location so it can be manipulated
144 string tempDatabaseFile = Path.Combine(this.TempFilesLocation, Path.GetFileName(databaseFile)); 116 string tempDatabaseFile = Path.Combine(this.IntermediateFolder, Path.GetFileName(databaseFile));
145 File.Copy(databaseFile, tempDatabaseFile); 117 File.Copy(databaseFile, tempDatabaseFile);
146 118
147 // remove the read-only property from the temporary database 119 // remove the read-only property from the temporary database
@@ -236,7 +208,7 @@ namespace WixToolset
236 208
237 string action = record.GetString(1); 209 string action = record.GetString(1);
238 210
239 if (!indexedSuppressedICEs.ContainsKey(action)) 211 if ((this.SuppressedICEs == null || !this.SuppressedICEs.Contains(action)) && (this.ICEs == null || this.ICEs.Contains(action)))
240 { 212 {
241 actions.Add(action); 213 actions.Add(action);
242 } 214 }
@@ -244,18 +216,6 @@ namespace WixToolset
244 } 216 }
245 } 217 }
246 218
247 if (0 != indexedICEs.Count)
248 {
249 // Walk backwards and remove those that arent in the list
250 for (int i = actions.Count - 1; 0 <= i; i--)
251 {
252 if (!indexedICEs.ContainsKey(actions[i]))
253 {
254 actions.RemoveAt(i);
255 }
256 }
257 }
258
259 // disable the internal UI handler and set an external UI handler 219 // disable the internal UI handler and set an external UI handler
260 previousUILevel = Installer.SetInternalUI((int)InstallUILevels.None, ref previousHwnd); 220 previousUILevel = Installer.SetInternalUI((int)InstallUILevels.None, ref previousHwnd);
261 previousUIHandler = Installer.SetExternalUI(this.validationUIHandler, (int)InstallLogModes.Error | (int)InstallLogModes.Warning | (int)InstallLogModes.User, IntPtr.Zero); 221 previousUIHandler = Installer.SetExternalUI(this.validationUIHandler, (int)InstallLogModes.Error | (int)InstallLogModes.Warning | (int)InstallLogModes.User, IntPtr.Zero);
@@ -370,6 +330,30 @@ namespace WixToolset
370 this.extension.OnMessage(e); 330 this.extension.OnMessage(e);
371 } 331 }
372 332
333 public static Validator CreateFromContext(IBindContext context, string cubeFilename)
334 {
335 Validator validator = null;
336
337 // Tell the binder about the validator if validation isn't suppressed
338 if (!context.SuppressValidation)
339 {
340 validator = new Validator();
341 validator.IntermediateFolder = Path.Combine(context.IntermediateFolder, "validate");
342
343 // set the default cube file
344 string thisPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
345 validator.AddCubeFile(Path.Combine(thisPath, cubeFilename));
346
347 // Set the ICEs
348 validator.ICEs = new SortedSet<string>(context.Ices);
349
350 // Set the suppressed ICEs and disable ICEs that have equivalent-or-better checks in WiX.
351 validator.SuppressedICEs = new SortedSet<string>(context.SuppressIces.Union(new[] { "ICE08", "ICE33", "ICE47", "ICE66" }));
352 }
353
354 return validator;
355 }
356
373 /// <summary> 357 /// <summary>
374 /// The validation external UI handler. 358 /// The validation external UI handler.
375 /// </summary> 359 /// </summary>