@joebigelow / wix-1 / commits / f662e0ed

Modernize PSCompiler.

Sean Hall committed Apr 10, 2020 at 09:33 UTC f662e0ed63b1a22b7a9aed9093076a7b3bf808c6
1 file changed +32 -31
src/wixext/PSCompiler.cs
+32 -31
@@ -32,8 +32,8 @@ namespace WixToolset.PowerShell
32 switch (parentElement.Name.LocalName)
33 {
34 case "File":
35 - string fileId = context["FileId"];
36 - string componentId = context["ComponentId"];
35 + var fileId = context["FileId"];
36 + var componentId = context["ComponentId"];
37
38 switch (element.Name.LocalName)
39 {
@@ -69,18 +69,17 @@ namespace WixToolset.PowerShell
69 /// <param name="componentId">Identifier for parent component.</param>
70 private void ParseSnapInElement(Intermediate intermediate, IntermediateSection section, XElement node, string fileId, string componentId)
71 {
72 - SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
72 + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
73 string id = null;
74 - string assemblyName = null;
74 string customSnapInType = null;
75 string description = null;
76 string descriptionIndirect = null;
78 - Version requiredPowerShellVersion = CompilerConstants.IllegalVersion;
77 + var requiredPowerShellVersion = CompilerConstants.IllegalVersion;
78 string vendor = null;
79 string vendorIndirect = null;
80 string version = null;
81
83 - foreach (XAttribute attrib in node.Attributes())
82 + foreach (var attrib in node.Attributes())
83 {
84 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
85 {
@@ -103,7 +102,7 @@ namespace WixToolset.PowerShell
102 break;
103
104 case "RequiredPowerShellVersion":
106 - string ver = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib);
105 + var ver = this.ParseHelper.GetAttributeVersionValue(sourceLineNumbers, attrib);
106 requiredPowerShellVersion = new Version(ver);
107 break;
108
@@ -148,7 +147,7 @@ namespace WixToolset.PowerShell
147 version = String.Format("!(bind.assemblyVersion.{0})", fileId);
148 }
149
151 - foreach (XElement child in node.Elements())
150 + foreach (var child in node.Elements())
151 {
152 if (this.Namespace == child.Name.Namespace)
153 {
@@ -174,56 +173,58 @@ namespace WixToolset.PowerShell
173 // Get the major part of the required PowerShell version which is
174 // needed for the registry key, and put that into a WiX variable
175 // for use in Formats and Types files. PowerShell v2 still uses 1.
177 - int major = (2 == requiredPowerShellVersion.Major) ? 1 : requiredPowerShellVersion.Major;
176 + var major = (2 == requiredPowerShellVersion.Major) ? 1 : requiredPowerShellVersion.Major;
177
178 var variableId = new Identifier(AccessModifier.Public, String.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id));
180 - var wixVariableRow = (WixVariableTuple)this.ParseHelper.CreateRow(section, sourceLineNumbers, "WixVariable", variableId);
181 - wixVariableRow.Value = major.ToString(CultureInfo.InvariantCulture);
182 - wixVariableRow.Overridable = false;
179 + section.AddTuple(new WixVariableTuple(sourceLineNumbers, variableId)
180 + {
181 + Value = major.ToString(CultureInfo.InvariantCulture),
182 + Overridable = false,
183 + });
184
184 - RegistryRootType registryRoot = RegistryRootType.LocalMachine; // HKLM
185 - string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, major, id);
185 + var registryRoot = RegistryRootType.LocalMachine; // HKLM
186 + var registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, major, id);
187
187 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", String.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false);
188 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", String.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false);
189
190 // set the assembly name automatically when binding.
191 // processorArchitecture is not handled correctly by PowerShell v1.0
192 // so format the assembly name explicitly.
192 - assemblyName = String.Format(CultureInfo.InvariantCulture, "!(bind.assemblyName.{0}), Version=!(bind.assemblyVersion.{0}), Culture=!(bind.assemblyCulture.{0}), PublicKeyToken=!(bind.assemblyPublicKeyToken.{0})", fileId);
193 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false);
193 + var assemblyName = String.Format(CultureInfo.InvariantCulture, "!(bind.assemblyName.{0}), Version=!(bind.assemblyVersion.{0}), Culture=!(bind.assemblyCulture.{0}), PublicKeyToken=!(bind.assemblyPublicKeyToken.{0})", fileId);
194 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false);
195
196 if (null != customSnapInType)
197 {
197 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, componentId, false);
198 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, componentId, false);
199 }
200
201 if (null != description)
202 {
202 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false);
203 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false);
204 }
205
206 if (null != descriptionIndirect)
207 {
207 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false);
208 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false);
209 }
210
210 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "ModuleName", String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false);
211 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "ModuleName", String.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false);
212
212 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false);
213 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false);
214
215 if (null != vendor)
216 {
216 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false);
217 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false);
218 }
219
220 if (null != vendorIndirect)
221 {
221 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false);
222 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false);
223 }
224
225 if (null != version)
226 {
226 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, "Version", version, componentId, false);
227 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, "Version", version, componentId, false);
228 }
229 }
230
@@ -236,11 +237,11 @@ namespace WixToolset.PowerShell
237 /// <param name="componentId">Identifier for parent component.</param>
238 private void ParseExtensionsFile(Intermediate intermediate, IntermediateSection section, XElement node, string valueName, string id, string componentId)
239 {
239 - SourceLineNumber sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
240 + var sourceLineNumbers = this.ParseHelper.GetSourceLineNumbers(node);
241 string fileId = null;
242 string snapIn = null;
243
243 - foreach (XAttribute attrib in node.Attributes())
244 + foreach (var attrib in node.Attributes())
245 {
246 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
247 {
@@ -274,11 +275,11 @@ namespace WixToolset.PowerShell
275
276 this.ParseHelper.ParseForExtensionElements(this.Context.Extensions, intermediate, section, node);
277
277 - RegistryRootType registryRoot = RegistryRootType.LocalMachine; // HKLM
278 - string registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, String.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn);
278 + var registryRoot = RegistryRootType.LocalMachine; // HKLM
279 + var registryKey = String.Format(CultureInfo.InvariantCulture, KeyFormat, String.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn);
280
280 - this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, "File", fileId);
281 - this.ParseHelper.CreateRegistryRow(section, sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false);
281 + this.ParseHelper.CreateSimpleReference(section, sourceLineNumbers, TupleDefinitions.File, fileId);
282 + this.ParseHelper.CreateRegistryTuple(section, sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false);
283 }
284 }
285 }