diff options
author | Rob Mensching <rob@firegiant.com> | 2022-12-06 15:54:17 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2022-12-06 17:29:07 -0800 |
commit | aa591db212c3df5a5c9f501c01fb1fbf2deadb7c (patch) | |
tree | 6e2e1e9ed3cf1b87f1cc3f05eaeb69c69d9bbf6f /src/tools | |
parent | 07fbc3561fb66dba1502305ba4aff1db905c84e4 (diff) | |
download | wix-aa591db212c3df5a5c9f501c01fb1fbf2deadb7c.tar.gz wix-aa591db212c3df5a5c9f501c01fb1fbf2deadb7c.tar.bz2 wix-aa591db212c3df5a5c9f501c01fb1fbf2deadb7c.zip |
Automated code clean up
Diffstat (limited to 'src/tools')
-rw-r--r-- | src/tools/heat/HeatCommand.cs | 27 | ||||
-rw-r--r-- | src/tools/heat/RegFileHarvester.cs | 1 | ||||
-rw-r--r-- | src/tools/heat/UtilHeatExtension.cs | 36 | ||||
-rw-r--r-- | src/tools/heat/UtilMutator.cs | 75 |
4 files changed, 66 insertions, 73 deletions
diff --git a/src/tools/heat/HeatCommand.cs b/src/tools/heat/HeatCommand.cs index d0c86401..34198011 100644 --- a/src/tools/heat/HeatCommand.cs +++ b/src/tools/heat/HeatCommand.cs | |||
@@ -68,7 +68,7 @@ namespace WixToolset.Harvesters | |||
68 | } | 68 | } |
69 | else if ('-' == arg[0] || '/' == arg[0]) | 69 | else if ('-' == arg[0] || '/' == arg[0]) |
70 | { | 70 | { |
71 | string parameter = arg.Substring(1); | 71 | var parameter = arg.Substring(1); |
72 | if ("nologo" == parameter) | 72 | if ("nologo" == parameter) |
73 | { | 73 | { |
74 | this.showLogo = false; | 74 | this.showLogo = false; |
@@ -89,7 +89,7 @@ namespace WixToolset.Harvesters | |||
89 | } | 89 | } |
90 | else if (parameter.StartsWith("sw")) | 90 | else if (parameter.StartsWith("sw")) |
91 | { | 91 | { |
92 | string paramArg = parameter.Substring(2); | 92 | var paramArg = parameter.Substring(2); |
93 | try | 93 | try |
94 | { | 94 | { |
95 | if (0 == paramArg.Length) | 95 | if (0 == paramArg.Length) |
@@ -98,7 +98,7 @@ namespace WixToolset.Harvesters | |||
98 | } | 98 | } |
99 | else | 99 | else |
100 | { | 100 | { |
101 | int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); | 101 | var suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); |
102 | if (0 >= suppressWarning) | 102 | if (0 >= suppressWarning) |
103 | { | 103 | { |
104 | this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg)); | 104 | this.Messaging.Write(ErrorMessages.IllegalSuppressWarningId(paramArg)); |
@@ -123,7 +123,7 @@ namespace WixToolset.Harvesters | |||
123 | } | 123 | } |
124 | else if (parameter.StartsWith("wx")) | 124 | else if (parameter.StartsWith("wx")) |
125 | { | 125 | { |
126 | string paramArg = parameter.Substring(2); | 126 | var paramArg = parameter.Substring(2); |
127 | try | 127 | try |
128 | { | 128 | { |
129 | if (0 == paramArg.Length) | 129 | if (0 == paramArg.Length) |
@@ -132,7 +132,7 @@ namespace WixToolset.Harvesters | |||
132 | } | 132 | } |
133 | else | 133 | else |
134 | { | 134 | { |
135 | int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); | 135 | var elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); |
136 | if (0 >= elevateWarning) | 136 | if (0 >= elevateWarning) |
137 | { | 137 | { |
138 | this.Messaging.Write(ErrorMessages.IllegalWarningIdAsError(paramArg)); | 138 | this.Messaging.Write(ErrorMessages.IllegalWarningIdAsError(paramArg)); |
@@ -212,7 +212,7 @@ namespace WixToolset.Harvesters | |||
212 | } | 212 | } |
213 | 213 | ||
214 | // harvest the output | 214 | // harvest the output |
215 | Wix.Wix wix = heatCore.Harvester.Harvest(this.ExtensionArgument); | 215 | var wix = heatCore.Harvester.Harvest(this.ExtensionArgument); |
216 | if (null == wix) | 216 | if (null == wix) |
217 | { | 217 | { |
218 | return this.Messaging.LastErrorNumber; | 218 | return this.Messaging.LastErrorNumber; |
@@ -224,15 +224,15 @@ namespace WixToolset.Harvesters | |||
224 | return this.Messaging.LastErrorNumber; | 224 | return this.Messaging.LastErrorNumber; |
225 | } | 225 | } |
226 | 226 | ||
227 | XmlWriterSettings xmlSettings = new XmlWriterSettings(); | 227 | var xmlSettings = new XmlWriterSettings(); |
228 | xmlSettings.Indent = true; | 228 | xmlSettings.Indent = true; |
229 | xmlSettings.IndentChars = new string(' ', this.Indent); | 229 | xmlSettings.IndentChars = new string(' ', this.Indent); |
230 | xmlSettings.OmitXmlDeclaration = true; | 230 | xmlSettings.OmitXmlDeclaration = true; |
231 | 231 | ||
232 | string wixString; | 232 | string wixString; |
233 | using (StringWriter stringWriter = new StringWriter()) | 233 | using (var stringWriter = new StringWriter()) |
234 | { | 234 | { |
235 | using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, xmlSettings)) | 235 | using (var xmlWriter = XmlWriter.Create(stringWriter, xmlSettings)) |
236 | { | 236 | { |
237 | wix.OutputXml(xmlWriter); | 237 | wix.OutputXml(xmlWriter); |
238 | } | 238 | } |
@@ -240,7 +240,7 @@ namespace WixToolset.Harvesters | |||
240 | wixString = stringWriter.ToString(); | 240 | wixString = stringWriter.ToString(); |
241 | } | 241 | } |
242 | 242 | ||
243 | string mutatedWixString = heatCore.Mutator.Mutate(wixString); | 243 | var mutatedWixString = heatCore.Mutator.Mutate(wixString); |
244 | if (String.IsNullOrEmpty(mutatedWixString)) | 244 | if (String.IsNullOrEmpty(mutatedWixString)) |
245 | { | 245 | { |
246 | return this.Messaging.LastErrorNumber; | 246 | return this.Messaging.LastErrorNumber; |
@@ -248,17 +248,14 @@ namespace WixToolset.Harvesters | |||
248 | 248 | ||
249 | Directory.CreateDirectory(Path.GetDirectoryName(this.OutputFile)); | 249 | Directory.CreateDirectory(Path.GetDirectoryName(this.OutputFile)); |
250 | 250 | ||
251 | using (StreamWriter streamWriter = new StreamWriter(this.OutputFile, false, System.Text.Encoding.UTF8)) | 251 | using (var streamWriter = new StreamWriter(this.OutputFile, false, System.Text.Encoding.UTF8)) |
252 | { | 252 | { |
253 | xmlSettings.OmitXmlDeclaration = false; | 253 | using (var xmlWriter = XmlWriter.Create(streamWriter, xmlSettings)) |
254 | xmlSettings.Encoding = System.Text.Encoding.UTF8; | ||
255 | using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter, xmlSettings)) | ||
256 | { | 254 | { |
257 | xmlWriter.WriteStartDocument(); | 255 | xmlWriter.WriteStartDocument(); |
258 | xmlWriter.Flush(); | 256 | xmlWriter.Flush(); |
259 | } | 257 | } |
260 | 258 | ||
261 | streamWriter.WriteLine(); | ||
262 | streamWriter.Write(mutatedWixString); | 259 | streamWriter.Write(mutatedWixString); |
263 | } | 260 | } |
264 | } | 261 | } |
diff --git a/src/tools/heat/RegFileHarvester.cs b/src/tools/heat/RegFileHarvester.cs index 3e7acaba..fcb4a9c2 100644 --- a/src/tools/heat/RegFileHarvester.cs +++ b/src/tools/heat/RegFileHarvester.cs | |||
@@ -362,7 +362,6 @@ namespace WixToolset.Harvesters | |||
362 | 362 | ||
363 | this.currentLineNumber++; | 363 | this.currentLineNumber++; |
364 | line = line.Trim(); | 364 | line = line.Trim(); |
365 | Console.Write("Processing line: {0}\r", this.currentLineNumber); | ||
366 | 365 | ||
367 | if (line.EndsWith("\\")) | 366 | if (line.EndsWith("\\")) |
368 | { | 367 | { |
diff --git a/src/tools/heat/UtilHeatExtension.cs b/src/tools/heat/UtilHeatExtension.cs index 6337340d..dd201892 100644 --- a/src/tools/heat/UtilHeatExtension.cs +++ b/src/tools/heat/UtilHeatExtension.cs | |||
@@ -60,13 +60,13 @@ namespace WixToolset.Harvesters | |||
60 | /// <param name="args">The option arguments.</param> | 60 | /// <param name="args">The option arguments.</param> |
61 | public override void ParseOptions(string type, string[] args) | 61 | public override void ParseOptions(string type, string[] args) |
62 | { | 62 | { |
63 | bool active = false; | 63 | var active = false; |
64 | IHarvesterExtension harvesterExtension = null; | 64 | IHarvesterExtension harvesterExtension = null; |
65 | bool suppressHarvestingRegistryValues = false; | 65 | var suppressHarvestingRegistryValues = false; |
66 | UtilFinalizeHarvesterMutator utilFinalizeHarvesterMutator = new UtilFinalizeHarvesterMutator(); | 66 | var utilFinalizeHarvesterMutator = new UtilFinalizeHarvesterMutator(); |
67 | UtilMutator utilMutator = new UtilMutator(); | 67 | var utilMutator = new UtilMutator(); |
68 | List<UtilTransformMutator> transformMutators = new List<UtilTransformMutator>(); | 68 | var transformMutators = new List<UtilTransformMutator>(); |
69 | GenerateType generateType = GenerateType.Components; | 69 | var generateType = GenerateType.Components; |
70 | 70 | ||
71 | // select the harvester | 71 | // select the harvester |
72 | switch (type) | 72 | switch (type) |
@@ -94,9 +94,9 @@ namespace WixToolset.Harvesters | |||
94 | utilMutator.SetUniqueIdentifiers = true; | 94 | utilMutator.SetUniqueIdentifiers = true; |
95 | 95 | ||
96 | // parse the options | 96 | // parse the options |
97 | for (int i = 0; i < args.Length; i++) | 97 | for (var i = 0; i < args.Length; i++) |
98 | { | 98 | { |
99 | string commandSwitch = args[i]; | 99 | var commandSwitch = args[i]; |
100 | 100 | ||
101 | if (null == commandSwitch || 0 == commandSwitch.Length) // skip blank arguments | 101 | if (null == commandSwitch || 0 == commandSwitch.Length) // skip blank arguments |
102 | { | 102 | { |
@@ -105,7 +105,7 @@ namespace WixToolset.Harvesters | |||
105 | 105 | ||
106 | if ('-' == commandSwitch[0] || '/' == commandSwitch[0]) | 106 | if ('-' == commandSwitch[0] || '/' == commandSwitch[0]) |
107 | { | 107 | { |
108 | string truncatedCommandSwitch = commandSwitch.Substring(1); | 108 | var truncatedCommandSwitch = commandSwitch.Substring(1); |
109 | 109 | ||
110 | if ("ag" == truncatedCommandSwitch) | 110 | if ("ag" == truncatedCommandSwitch) |
111 | { | 111 | { |
@@ -122,20 +122,20 @@ namespace WixToolset.Harvesters | |||
122 | } | 122 | } |
123 | else if ("dr" == truncatedCommandSwitch) | 123 | else if ("dr" == truncatedCommandSwitch) |
124 | { | 124 | { |
125 | string dr = this.GetArgumentParameter(args, i); | 125 | var dr = this.GetArgumentParameter(args, i); |
126 | 126 | ||
127 | if (this.Core.Messaging.EncounteredError) | 127 | if (this.Core.Messaging.EncounteredError) |
128 | { | 128 | { |
129 | return; | 129 | return; |
130 | } | 130 | } |
131 | 131 | ||
132 | if (harvesterExtension is DirectoryHarvester) | 132 | if (harvesterExtension is DirectoryHarvester directoryHarvester) |
133 | { | 133 | { |
134 | ((DirectoryHarvester)harvesterExtension).RootedDirectoryRef = dr; | 134 | directoryHarvester.RootedDirectoryRef = dr; |
135 | } | 135 | } |
136 | else if (harvesterExtension is FileHarvester) | 136 | else if (harvesterExtension is FileHarvester fileHarvester) |
137 | { | 137 | { |
138 | ((FileHarvester)harvesterExtension).RootedDirectoryRef = dr; | 138 | fileHarvester.RootedDirectoryRef = dr; |
139 | } | 139 | } |
140 | } | 140 | } |
141 | else if ("gg" == truncatedCommandSwitch) | 141 | else if ("gg" == truncatedCommandSwitch) |
@@ -288,7 +288,7 @@ namespace WixToolset.Harvesters | |||
288 | { | 288 | { |
289 | if (harvesterExtension is DirectoryHarvester) | 289 | if (harvesterExtension is DirectoryHarvester) |
290 | { | 290 | { |
291 | string genType = this.GetArgumentParameter(args, i).ToUpperInvariant(); | 291 | var genType = this.GetArgumentParameter(args, i).ToUpperInvariant(); |
292 | switch (genType) | 292 | switch (genType) |
293 | { | 293 | { |
294 | case "COMPONENTS": | 294 | case "COMPONENTS": |
@@ -349,7 +349,7 @@ namespace WixToolset.Harvesters | |||
349 | this.Core.Mutator.AddExtension(utilMutator); | 349 | this.Core.Mutator.AddExtension(utilMutator); |
350 | 350 | ||
351 | // add the transforms | 351 | // add the transforms |
352 | foreach (UtilTransformMutator transformMutator in transformMutators) | 352 | foreach (var transformMutator in transformMutators) |
353 | { | 353 | { |
354 | this.Core.Mutator.AddExtension(transformMutator); | 354 | this.Core.Mutator.AddExtension(transformMutator); |
355 | } | 355 | } |
@@ -362,8 +362,8 @@ namespace WixToolset.Harvesters | |||
362 | 362 | ||
363 | private string GetArgumentParameter(string[] args, int index, bool allowSpaces) | 363 | private string GetArgumentParameter(string[] args, int index, bool allowSpaces) |
364 | { | 364 | { |
365 | string truncatedCommandSwitch = args[index]; | 365 | var truncatedCommandSwitch = args[index]; |
366 | string commandSwitchValue = args[index + 1]; | 366 | var commandSwitchValue = args[index + 1]; |
367 | 367 | ||
368 | //increment the index to the switch value | 368 | //increment the index to the switch value |
369 | index++; | 369 | index++; |
diff --git a/src/tools/heat/UtilMutator.cs b/src/tools/heat/UtilMutator.cs index 3e084fa3..287f5f5e 100644 --- a/src/tools/heat/UtilMutator.cs +++ b/src/tools/heat/UtilMutator.cs | |||
@@ -182,11 +182,11 @@ namespace WixToolset.Harvesters | |||
182 | // add the components to the product feature after all the identifiers have been set | 182 | // add the components to the product feature after all the identifiers have been set |
183 | if (TemplateType.Package == this.templateType) | 183 | if (TemplateType.Package == this.templateType) |
184 | { | 184 | { |
185 | Wix.Feature feature = (Wix.Feature)this.features[0]; | 185 | var feature = (Wix.Feature)this.features[0]; |
186 | 186 | ||
187 | foreach (Wix.ComponentGroup group in this.componentGroups) | 187 | foreach (Wix.ComponentGroup group in this.componentGroups) |
188 | { | 188 | { |
189 | Wix.ComponentGroupRef componentGroupRef = new Wix.ComponentGroupRef(); | 189 | var componentGroupRef = new Wix.ComponentGroupRef(); |
190 | componentGroupRef.Id = group.Id; | 190 | componentGroupRef.Id = group.Id; |
191 | 191 | ||
192 | feature.AddChild(componentGroupRef); | 192 | feature.AddChild(componentGroupRef); |
@@ -200,7 +200,7 @@ namespace WixToolset.Harvesters | |||
200 | { | 200 | { |
201 | foreach (Wix.ComponentGroup group in this.componentGroups) | 201 | foreach (Wix.ComponentGroup group in this.componentGroups) |
202 | { | 202 | { |
203 | Wix.ComponentGroupRef componentGroupRef = new Wix.ComponentGroupRef(); | 203 | var componentGroupRef = new Wix.ComponentGroupRef(); |
204 | componentGroupRef.Id = group.Id; | 204 | componentGroupRef.Id = group.Id; |
205 | 205 | ||
206 | ((Wix.IParentElement)element).AddChild(componentGroupRef); | 206 | ((Wix.IParentElement)element).AddChild(componentGroupRef); |
@@ -223,24 +223,24 @@ namespace WixToolset.Harvesters | |||
223 | /// <param name="wix">The Wix document element.</param> | 223 | /// <param name="wix">The Wix document element.</param> |
224 | private void CreateComponentGroup(Wix.Wix wix) | 224 | private void CreateComponentGroup(Wix.Wix wix) |
225 | { | 225 | { |
226 | Wix.ComponentGroup componentGroup = new Wix.ComponentGroup(); | 226 | var componentGroup = new Wix.ComponentGroup(); |
227 | componentGroup.Id = this.componentGroupName; | 227 | componentGroup.Id = this.componentGroupName; |
228 | this.componentGroups.Add(componentGroup); | 228 | this.componentGroups.Add(componentGroup); |
229 | 229 | ||
230 | Wix.Fragment cgFragment = new Wix.Fragment(); | 230 | var cgFragment = new Wix.Fragment(); |
231 | cgFragment.AddChild(componentGroup); | 231 | cgFragment.AddChild(componentGroup); |
232 | wix.AddChild(cgFragment); | 232 | wix.AddChild(cgFragment); |
233 | 233 | ||
234 | int componentCount = 0; | 234 | var componentCount = 0; |
235 | for (; componentCount < this.components.Count; componentCount++) | 235 | for (; componentCount < this.components.Count; componentCount++) |
236 | { | 236 | { |
237 | Wix.Component c = this.components[componentCount] as Wix.Component; | 237 | var c = this.components[componentCount] as Wix.Component; |
238 | 238 | ||
239 | if (this.createFragments) | 239 | if (this.createFragments) |
240 | { | 240 | { |
241 | if (c.ParentElement is Wix.Directory) | 241 | if (c.ParentElement is Wix.Directory) |
242 | { | 242 | { |
243 | Wix.Directory parentDirectory = c.ParentElement as Wix.Directory; | 243 | var parentDirectory = c.ParentElement as Wix.Directory; |
244 | 244 | ||
245 | componentGroup.AddChild(c); | 245 | componentGroup.AddChild(c); |
246 | c.Directory = parentDirectory.Id; | 246 | c.Directory = parentDirectory.Id; |
@@ -248,7 +248,7 @@ namespace WixToolset.Harvesters | |||
248 | } | 248 | } |
249 | else if (c.ParentElement is Wix.DirectoryRef) | 249 | else if (c.ParentElement is Wix.DirectoryRef) |
250 | { | 250 | { |
251 | Wix.DirectoryRef parentDirectory = c.ParentElement as Wix.DirectoryRef; | 251 | var parentDirectory = c.ParentElement as Wix.DirectoryBase; |
252 | 252 | ||
253 | componentGroup.AddChild(c); | 253 | componentGroup.AddChild(c); |
254 | c.Directory = parentDirectory.Id; | 254 | c.Directory = parentDirectory.Id; |
@@ -257,8 +257,8 @@ namespace WixToolset.Harvesters | |||
257 | // Remove whole fragment if moving the component to the component group just leaves an empty DirectoryRef | 257 | // Remove whole fragment if moving the component to the component group just leaves an empty DirectoryRef |
258 | if (0 < this.fragments.Count && parentDirectory.ParentElement is Wix.Fragment) | 258 | if (0 < this.fragments.Count && parentDirectory.ParentElement is Wix.Fragment) |
259 | { | 259 | { |
260 | Wix.Fragment parentFragment = parentDirectory.ParentElement as Wix.Fragment; | 260 | var parentFragment = parentDirectory.ParentElement as Wix.Fragment; |
261 | int childCount = 0; | 261 | var childCount = 0; |
262 | foreach (Wix.ISchemaElement element in parentFragment.Children) | 262 | foreach (Wix.ISchemaElement element in parentFragment.Children) |
263 | { | 263 | { |
264 | childCount++; | 264 | childCount++; |
@@ -267,7 +267,7 @@ namespace WixToolset.Harvesters | |||
267 | // Component should always have an Id but the SortedList creation allows for null and bases the name on the fragment count which we cannot reverse engineer here. | 267 | // Component should always have an Id but the SortedList creation allows for null and bases the name on the fragment count which we cannot reverse engineer here. |
268 | if (1 == childCount && !String.IsNullOrEmpty(c.Id)) | 268 | if (1 == childCount && !String.IsNullOrEmpty(c.Id)) |
269 | { | 269 | { |
270 | int removeIndex = this.fragments.IndexOfKey(String.Concat("Component:", c.Id)); | 270 | var removeIndex = this.fragments.IndexOfKey(String.Concat("Component:", c.Id)); |
271 | if (0 <= removeIndex) | 271 | if (0 <= removeIndex) |
272 | { | 272 | { |
273 | this.fragments.RemoveAt(removeIndex); | 273 | this.fragments.RemoveAt(removeIndex); |
@@ -278,7 +278,7 @@ namespace WixToolset.Harvesters | |||
278 | } | 278 | } |
279 | else | 279 | else |
280 | { | 280 | { |
281 | Wix.ComponentRef componentRef = new Wix.ComponentRef(); | 281 | var componentRef = new Wix.ComponentRef(); |
282 | componentRef.Id = c.Id; | 282 | componentRef.Id = c.Id; |
283 | componentGroup.AddChild(componentRef); | 283 | componentGroup.AddChild(componentRef); |
284 | } | 284 | } |
@@ -322,9 +322,9 @@ namespace WixToolset.Harvesters | |||
322 | } | 322 | } |
323 | 323 | ||
324 | // index the child elements | 324 | // index the child elements |
325 | if (element is Wix.IParentElement) | 325 | if (element is Wix.IParentElement parentElement) |
326 | { | 326 | { |
327 | foreach (Wix.ISchemaElement childElement in ((Wix.IParentElement)element).Children) | 327 | foreach (Wix.ISchemaElement childElement in parentElement.Children) |
328 | { | 328 | { |
329 | this.IndexElement(childElement); | 329 | this.IndexElement(childElement); |
330 | } | 330 | } |
@@ -336,7 +336,7 @@ namespace WixToolset.Harvesters | |||
336 | /// </summary> | 336 | /// </summary> |
337 | private void MutateComponents() | 337 | private void MutateComponents() |
338 | { | 338 | { |
339 | IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component", this.Core); | 339 | var identifierGenerator = new IdentifierGenerator("Component", this.Core); |
340 | if (TemplateType.Module == this.templateType) | 340 | if (TemplateType.Module == this.templateType) |
341 | { | 341 | { |
342 | identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; | 342 | identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; |
@@ -346,7 +346,7 @@ namespace WixToolset.Harvesters | |||
346 | { | 346 | { |
347 | if (null == component.Id) | 347 | if (null == component.Id) |
348 | { | 348 | { |
349 | string firstFileId = string.Empty; | 349 | var firstFileId = String.Empty; |
350 | 350 | ||
351 | // attempt to create a possible identifier from the first file identifier in the component | 351 | // attempt to create a possible identifier from the first file identifier in the component |
352 | foreach (Wix.File file in component[typeof(Wix.File)]) | 352 | foreach (Wix.File file in component[typeof(Wix.File)]) |
@@ -355,7 +355,7 @@ namespace WixToolset.Harvesters | |||
355 | break; | 355 | break; |
356 | } | 356 | } |
357 | 357 | ||
358 | if (string.IsNullOrEmpty(firstFileId)) | 358 | if (String.IsNullOrEmpty(firstFileId)) |
359 | { | 359 | { |
360 | firstFileId = this.GetGuid(); | 360 | firstFileId = this.GetGuid(); |
361 | } | 361 | } |
@@ -375,10 +375,8 @@ namespace WixToolset.Harvesters | |||
375 | } | 375 | } |
376 | } | 376 | } |
377 | 377 | ||
378 | if (this.createFragments && component.ParentElement is Wix.Directory) | 378 | if (this.createFragments && component.ParentElement is Wix.Directory directory) |
379 | { | 379 | { |
380 | Wix.Directory directory = (Wix.Directory)component.ParentElement; | ||
381 | |||
382 | // parent directory must have an identifier to create a reference to it | 380 | // parent directory must have an identifier to create a reference to it |
383 | if (null == directory.Id) | 381 | if (null == directory.Id) |
384 | { | 382 | { |
@@ -388,14 +386,14 @@ namespace WixToolset.Harvesters | |||
388 | if (this.rootElement is Wix.Module) | 386 | if (this.rootElement is Wix.Module) |
389 | { | 387 | { |
390 | // add a ComponentRef for the Component | 388 | // add a ComponentRef for the Component |
391 | Wix.ComponentRef componentRef = new Wix.ComponentRef(); | 389 | var componentRef = new Wix.ComponentRef(); |
392 | componentRef.Id = component.Id; | 390 | componentRef.Id = component.Id; |
393 | this.rootElement.AddChild(componentRef); | 391 | this.rootElement.AddChild(componentRef); |
394 | } | 392 | } |
395 | 393 | ||
396 | // create a new Fragment | 394 | // create a new Fragment |
397 | Wix.Fragment fragment = new Wix.Fragment(); | 395 | var fragment = new Wix.Fragment(); |
398 | this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment); | 396 | this.fragments.Add(String.Concat("Component:", component.Id ?? this.fragments.Count.ToString()), fragment); |
399 | 397 | ||
400 | // create a new DirectoryRef | 398 | // create a new DirectoryRef |
401 | var directoryRef = DirectoryHelper.CreateDirectoryReference(directory.Id); | 399 | var directoryRef = DirectoryHelper.CreateDirectoryReference(directory.Id); |
@@ -416,7 +414,7 @@ namespace WixToolset.Harvesters | |||
416 | if (!this.setUniqueIdentifiers) | 414 | if (!this.setUniqueIdentifiers) |
417 | { | 415 | { |
418 | // assign all identifiers before fragmenting (because fragmenting requires them all to be present) | 416 | // assign all identifiers before fragmenting (because fragmenting requires them all to be present) |
419 | IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory", this.Core); | 417 | var identifierGenerator = new IdentifierGenerator("Directory", this.Core); |
420 | if (TemplateType.Module == this.templateType) | 418 | if (TemplateType.Module == this.templateType) |
421 | { | 419 | { |
422 | identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; | 420 | identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; |
@@ -446,7 +444,7 @@ namespace WixToolset.Harvesters | |||
446 | } | 444 | } |
447 | 445 | ||
448 | // create a new Fragment | 446 | // create a new Fragment |
449 | Wix.Fragment fragment = new Wix.Fragment(); | 447 | var fragment = new Wix.Fragment(); |
450 | this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment); | 448 | this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment); |
451 | 449 | ||
452 | // create a new DirectoryRef | 450 | // create a new DirectoryRef |
@@ -457,11 +455,10 @@ namespace WixToolset.Harvesters | |||
457 | parentDirectory.RemoveChild(directory); | 455 | parentDirectory.RemoveChild(directory); |
458 | directoryRef.AddChild(directory); | 456 | directoryRef.AddChild(directory); |
459 | } | 457 | } |
460 | else if (directory.ParentElement is Wix.Fragment) | 458 | else if (directory.ParentElement is Wix.Fragment parent) |
461 | { | 459 | { |
462 | // When creating fragments, remove any top-level Directory elements; | 460 | // When creating fragments, remove any top-level Directory elements; |
463 | // the fragments should be pulled in by their DirectoryRefs instead. | 461 | // the fragments should be pulled in by their DirectoryRefs instead. |
464 | Wix.Fragment parent = (Wix.Fragment)directory.ParentElement; | ||
465 | parent.RemoveChild(directory); | 462 | parent.RemoveChild(directory); |
466 | 463 | ||
467 | // Remove the fragment if it is empty. | 464 | // Remove the fragment if it is empty. |
@@ -473,7 +470,7 @@ namespace WixToolset.Harvesters | |||
473 | else if (directory.ParentElement == this.rootElement) | 470 | else if (directory.ParentElement == this.rootElement) |
474 | { | 471 | { |
475 | // create a new Fragment | 472 | // create a new Fragment |
476 | Wix.Fragment fragment = new Wix.Fragment(); | 473 | var fragment = new Wix.Fragment(); |
477 | this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment); | 474 | this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment); |
478 | 475 | ||
479 | // move the Directory from the root element to the Fragment | 476 | // move the Directory from the root element to the Fragment |
@@ -489,7 +486,7 @@ namespace WixToolset.Harvesters | |||
489 | /// </summary> | 486 | /// </summary> |
490 | private void MutateFiles() | 487 | private void MutateFiles() |
491 | { | 488 | { |
492 | IdentifierGenerator identifierGenerator = new IdentifierGenerator("File", this.Core); | 489 | var identifierGenerator = new IdentifierGenerator("File", this.Core); |
493 | if (TemplateType.Module == this.templateType) | 490 | if (TemplateType.Module == this.templateType) |
494 | { | 491 | { |
495 | identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; | 492 | identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength; |
@@ -518,7 +515,7 @@ namespace WixToolset.Harvesters | |||
518 | } | 515 | } |
519 | 516 | ||
520 | // create a package element although it won't always be used | 517 | // create a package element although it won't always be used |
521 | Wix.SummaryInformation package = new Wix.SummaryInformation(); | 518 | var package = new Wix.SummaryInformation(); |
522 | if (TemplateType.Module == this.templateType) | 519 | if (TemplateType.Module == this.templateType) |
523 | { | 520 | { |
524 | package.Id = this.GetGuid(); | 521 | package.Id = this.GetGuid(); |
@@ -530,7 +527,7 @@ namespace WixToolset.Harvesters | |||
530 | 527 | ||
531 | package.InstallerVersion = 200; | 528 | package.InstallerVersion = 200; |
532 | 529 | ||
533 | Wix.Directory targetDir = new Wix.Directory(); | 530 | var targetDir = new Wix.Directory(); |
534 | targetDir.Id = "TARGETDIR"; | 531 | targetDir.Id = "TARGETDIR"; |
535 | targetDir.Name = "SourceDir"; | 532 | targetDir.Name = "SourceDir"; |
536 | 533 | ||
@@ -538,7 +535,7 @@ namespace WixToolset.Harvesters | |||
538 | { | 535 | { |
539 | if (String.Equals(directoryRef.Id, "TARGETDIR", StringComparison.OrdinalIgnoreCase)) | 536 | if (String.Equals(directoryRef.Id, "TARGETDIR", StringComparison.OrdinalIgnoreCase)) |
540 | { | 537 | { |
541 | Wix.IParentElement parent = directoryRef.ParentElement as Wix.IParentElement; | 538 | var parent = directoryRef.ParentElement as Wix.IParentElement; |
542 | 539 | ||
543 | foreach (Wix.ISchemaElement element in directoryRef.Children) | 540 | foreach (Wix.ISchemaElement element in directoryRef.Children) |
544 | { | 541 | { |
@@ -549,7 +546,7 @@ namespace WixToolset.Harvesters | |||
549 | 546 | ||
550 | if (null != ((Wix.ISchemaElement)parent).ParentElement) | 547 | if (null != ((Wix.ISchemaElement)parent).ParentElement) |
551 | { | 548 | { |
552 | int i = 0; | 549 | var i = 0; |
553 | 550 | ||
554 | foreach (Wix.ISchemaElement element in parent.Children) | 551 | foreach (Wix.ISchemaElement element in parent.Children) |
555 | { | 552 | { |
@@ -558,7 +555,7 @@ namespace WixToolset.Harvesters | |||
558 | 555 | ||
559 | if (0 == i) | 556 | if (0 == i) |
560 | { | 557 | { |
561 | Wix.IParentElement supParent = (Wix.IParentElement)((Wix.ISchemaElement)parent).ParentElement; | 558 | var supParent = (Wix.IParentElement)((Wix.ISchemaElement)parent).ParentElement; |
562 | supParent.RemoveChild((Wix.ISchemaElement)parent); | 559 | supParent.RemoveChild((Wix.ISchemaElement)parent); |
563 | } | 560 | } |
564 | } | 561 | } |
@@ -569,7 +566,7 @@ namespace WixToolset.Harvesters | |||
569 | 566 | ||
570 | if (TemplateType.Module == this.templateType) | 567 | if (TemplateType.Module == this.templateType) |
571 | { | 568 | { |
572 | Wix.Module module = new Wix.Module(); | 569 | var module = new Wix.Module(); |
573 | module.Id = "PUT-MODULE-NAME-HERE"; | 570 | module.Id = "PUT-MODULE-NAME-HERE"; |
574 | module.Language = "1033"; | 571 | module.Language = "1033"; |
575 | module.Version = "1.0.0.0"; | 572 | module.Version = "1.0.0.0"; |
@@ -583,7 +580,7 @@ namespace WixToolset.Harvesters | |||
583 | } | 580 | } |
584 | else // product | 581 | else // product |
585 | { | 582 | { |
586 | Wix.Package product = new Wix.Package(); | 583 | var product = new Wix.Package(); |
587 | product.Id = this.GetGuid(); | 584 | product.Id = this.GetGuid(); |
588 | product.Language = "1033"; | 585 | product.Language = "1033"; |
589 | product.Manufacturer = "PUT-COMPANY-NAME-HERE"; | 586 | product.Manufacturer = "PUT-COMPANY-NAME-HERE"; |
@@ -593,13 +590,13 @@ namespace WixToolset.Harvesters | |||
593 | product.AddChild(package); | 590 | product.AddChild(package); |
594 | product.AddChild(targetDir); | 591 | product.AddChild(targetDir); |
595 | 592 | ||
596 | Wix.Media media = new Wix.Media(); | 593 | var media = new Wix.Media(); |
597 | media.Id = "1"; | 594 | media.Id = "1"; |
598 | media.Cabinet = "product.cab"; | 595 | media.Cabinet = "product.cab"; |
599 | media.EmbedCab = Wix.YesNoType.yes; | 596 | media.EmbedCab = Wix.YesNoType.yes; |
600 | product.AddChild(media); | 597 | product.AddChild(media); |
601 | 598 | ||
602 | Wix.Feature feature = new Wix.Feature(); | 599 | var feature = new Wix.Feature(); |
603 | feature.Id = "ProductFeature"; | 600 | feature.Id = "ProductFeature"; |
604 | feature.Title = "PUT-FEATURE-TITLE-HERE"; | 601 | feature.Title = "PUT-FEATURE-TITLE-HERE"; |
605 | feature.Level = 1; | 602 | feature.Level = 1; |