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/heat/UtilMutator.cs | |
parent | 07fbc3561fb66dba1502305ba4aff1db905c84e4 (diff) | |
download | wix-aa591db212c3df5a5c9f501c01fb1fbf2deadb7c.tar.gz wix-aa591db212c3df5a5c9f501c01fb1fbf2deadb7c.tar.bz2 wix-aa591db212c3df5a5c9f501c01fb1fbf2deadb7c.zip |
Automated code clean up
Diffstat (limited to 'src/tools/heat/UtilMutator.cs')
-rw-r--r-- | src/tools/heat/UtilMutator.cs | 75 |
1 files changed, 36 insertions, 39 deletions
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; |