/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public override void Mutate(Wix.Wix wix) { this.components.Clear(); this.directoryPaths.Clear(); this.webAddresses.Clear(); this.webDirs.Clear(); this.webDirProperties.Clear(); this.webFilters.Clear(); this.webSites.Clear(); this.webVirtualDirs.Clear(); this.rootElement = null; this.IndexElement(wix); this.MutateWebAddresses(); this.MutateWebDirs(); this.MutateWebDirProperties(); this.MutateWebSites(); this.MutateWebVirtualDirs(); // this must come after the web virtual dirs in case they harvest a directory containing a web filter file this.MutateWebFilters(); // this must come after the web site identifiers are created this.MutateComponents(); }
public Wix.Wix Harvest(string argument) { if (null == argument) { throw new ArgumentNullException("argument"); } if (null == this.harvesterExtension) { throw new WixException(ErrorMessages.HarvestTypeNotFound()); } this.harvesterExtension.Core = this.Core; Wix.Fragment[] fragments = this.harvesterExtension.Harvest(argument); if (null == fragments || 0 == fragments.Length) { return(null); } Wix.Wix wix = new Wix.Wix(); foreach (Wix.Fragment fragment in fragments) { wix.AddChild(fragment); } return(wix); }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public override void Mutate(Wix.Wix wix) { this.directoryPaths.Clear(); this.filePaths.Clear(); this.webFilters.Clear(); this.webSites.Clear(); this.webVirtualDirs.Clear(); this.IndexElement(wix); this.MutateWebFilters(); this.MutateWebSites(); this.MutateWebVirtualDirs(); }
public bool Mutate(Wix.Wix wix) { bool encounteredError = false; try { foreach (IMutatorExtension mutatorExtension in this.extensions.Values) { if (null == mutatorExtension.Core) { mutatorExtension.Core = this.Core; } mutatorExtension.Mutate(wix); } } finally { encounteredError = this.Core.Messaging.EncounteredError; } // return the Wix document element only if mutation completed successfully return(!encounteredError); }
private int Harvest() { try { if (String.IsNullOrEmpty(this.ExtensionArgument)) { this.Messaging.Write(ErrorMessages.HarvestSourceNotSpecified()); } else if (String.IsNullOrEmpty(this.OutputFile)) { this.Messaging.Write(ErrorMessages.OutputTargetNotSpecified()); } // exit if there was an error parsing the core command line if (this.Messaging.EncounteredError) { return(this.Messaging.LastErrorNumber); } if (this.ShowLogo) { HelpCommand.DisplayToolHeader(); } var heatCore = new HeatCore(this.ServiceProvider, this.ExtensionArgument); // parse the extension's command line arguments var extensionOptionsArray = this.ExtensionOptions.ToArray(); foreach (var heatExtension in this.Extensions) { heatExtension.Core = heatCore; heatExtension.ParseOptions(this.ExtensionType, extensionOptionsArray); } // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.Messaging.EncounteredError) { return(this.Messaging.LastErrorNumber); } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.ExtensionArgument); if (null == wix) { return(this.Messaging.LastErrorNumber); } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return(this.Messaging.LastErrorNumber); } XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true; xmlSettings.IndentChars = new string(' ', this.Indent); xmlSettings.OmitXmlDeclaration = true; string wixString; using (StringWriter stringWriter = new StringWriter()) { using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, xmlSettings)) { wix.OutputXml(xmlWriter); } wixString = stringWriter.ToString(); } string mutatedWixString = heatCore.Mutator.Mutate(wixString); if (String.IsNullOrEmpty(mutatedWixString)) { return(this.Messaging.LastErrorNumber); } Directory.CreateDirectory(Path.GetDirectoryName(this.OutputFile)); using (StreamWriter streamWriter = new StreamWriter(this.OutputFile, false, System.Text.Encoding.UTF8)) { xmlSettings.OmitXmlDeclaration = false; xmlSettings.Encoding = System.Text.Encoding.UTF8; using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter, xmlSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.Flush(); } streamWriter.WriteLine(); streamWriter.Write(mutatedWixString); } } catch (WixException we) { this.Messaging.Write(we.Error); } catch (Exception e) { this.Messaging.Write(ErrorMessages.UnexpectedException(e)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.Messaging.LastErrorNumber); }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public virtual void Mutate(Wix.Wix wix) { }
/// <summary> /// Mutate a Wix element. /// </summary> /// <param name="wix">The Wix element to mutate.</param> private void MutateWix(Wix.Wix wix) { if (TemplateType.Fragment != this.templateType) { if (null != this.rootElement || 0 != this.features.Count) { throw new Exception("The template option cannot be used with Feature, Package, or Module elements present."); } // create a package element although it won't always be used Wix.SummaryInformation package = new Wix.SummaryInformation(); if (TemplateType.Module == this.templateType) { package.Id = this.GetGuid(); } else { package.Compressed = Wix.YesNoType.yes; } package.InstallerVersion = 200; Wix.Directory targetDir = new Wix.Directory(); targetDir.Id = "TARGETDIR"; targetDir.Name = "SourceDir"; foreach (Wix.DirectoryRef directoryRef in this.directoryRefs) { if (String.Equals(directoryRef.Id, "TARGETDIR", StringComparison.OrdinalIgnoreCase)) { Wix.IParentElement parent = directoryRef.ParentElement as Wix.IParentElement; foreach (Wix.ISchemaElement element in directoryRef.Children) { targetDir.AddChild(element); } parent.RemoveChild(directoryRef); if (null != ((Wix.ISchemaElement)parent).ParentElement) { int i = 0; foreach (Wix.ISchemaElement element in parent.Children) { i++; } if (0 == i) { Wix.IParentElement supParent = (Wix.IParentElement)((Wix.ISchemaElement)parent).ParentElement; supParent.RemoveChild((Wix.ISchemaElement)parent); } } break; } } if (TemplateType.Module == this.templateType) { Wix.Module module = new Wix.Module(); module.Id = "PUT-MODULE-NAME-HERE"; module.Language = "1033"; module.Version = "1.0.0.0"; package.Manufacturer = "PUT-COMPANY-NAME-HERE"; module.AddChild(package); module.AddChild(targetDir); wix.AddChild(module); this.rootElement = module; } else // product { Wix.Package product = new Wix.Package(); product.Id = this.GetGuid(); product.Language = "1033"; product.Manufacturer = "PUT-COMPANY-NAME-HERE"; product.Name = "PUT-PRODUCT-NAME-HERE"; product.UpgradeCode = this.GetGuid(); product.Version = "1.0.0.0"; product.AddChild(package); product.AddChild(targetDir); Wix.Media media = new Wix.Media(); media.Id = "1"; media.Cabinet = "product.cab"; media.EmbedCab = Wix.YesNoType.yes; product.AddChild(media); Wix.Feature feature = new Wix.Feature(); feature.Id = "ProductFeature"; feature.Title = "PUT-FEATURE-TITLE-HERE"; feature.Level = 1; product.AddChild(feature); this.features.Add(feature); wix.AddChild(product); this.rootElement = product; } } }
/// <summary> /// Creates a component group with a given name. /// </summary> /// <param name="wix">The Wix document element.</param> private void CreateComponentGroup(Wix.Wix wix) { Wix.ComponentGroup componentGroup = new Wix.ComponentGroup(); componentGroup.Id = this.componentGroupName; this.componentGroups.Add(componentGroup); Wix.Fragment cgFragment = new Wix.Fragment(); cgFragment.AddChild(componentGroup); wix.AddChild(cgFragment); int componentCount = 0; for (; componentCount < this.components.Count; componentCount++) { Wix.Component c = this.components[componentCount] as Wix.Component; if (this.createFragments) { if (c.ParentElement is Wix.Directory) { Wix.Directory parentDirectory = c.ParentElement as Wix.Directory; componentGroup.AddChild(c); c.Directory = parentDirectory.Id; parentDirectory.RemoveChild(c); } else if (c.ParentElement is Wix.DirectoryRef) { Wix.DirectoryRef parentDirectory = c.ParentElement as Wix.DirectoryRef; componentGroup.AddChild(c); c.Directory = parentDirectory.Id; parentDirectory.RemoveChild(c); // Remove whole fragment if moving the component to the component group just leaves an empty DirectoryRef if (0 < this.fragments.Count && parentDirectory.ParentElement is Wix.Fragment) { Wix.Fragment parentFragment = parentDirectory.ParentElement as Wix.Fragment; int childCount = 0; foreach (Wix.ISchemaElement element in parentFragment.Children) { childCount++; } // 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. if (1 == childCount && !String.IsNullOrEmpty(c.Id)) { int removeIndex = this.fragments.IndexOfKey(String.Concat("Component:", c.Id)); if (0 <= removeIndex) { this.fragments.RemoveAt(removeIndex); } } } } } else { Wix.ComponentRef componentRef = new Wix.ComponentRef(); componentRef.Id = c.Id; componentGroup.AddChild(componentRef); } } }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public override void Mutate(Wix.Wix wix) { this.components.Clear(); this.directories.Clear(); this.directoryRefs.Clear(); this.features.Clear(); this.files.Clear(); this.fragments.Clear(); this.rootElement = null; // index elements in this wix document this.IndexElement(wix); this.MutateWix(wix); this.MutateFiles(); this.MutateDirectories(); this.MutateComponents(); if (null != this.componentGroupName) { this.CreateComponentGroup(wix); } // add the components to the product feature after all the identifiers have been set if (TemplateType.Package == this.templateType) { Wix.Feature feature = (Wix.Feature) this.features[0]; foreach (Wix.ComponentGroup group in this.componentGroups) { Wix.ComponentGroupRef componentGroupRef = new Wix.ComponentGroupRef(); componentGroupRef.Id = group.Id; feature.AddChild(componentGroupRef); } } else if (TemplateType.Module == this.templateType) { foreach (Wix.ISchemaElement element in wix.Children) { if (element is Wix.Module) { foreach (Wix.ComponentGroup group in this.componentGroups) { Wix.ComponentGroupRef componentGroupRef = new Wix.ComponentGroupRef(); componentGroupRef.Id = group.Id; ((Wix.IParentElement)element).AddChild(componentGroupRef); } break; } } } //if(!this.createFragments && TemplateType.Package foreach (Wix.Fragment fragment in this.fragments.Values) { wix.AddChild(fragment); } }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public override void Mutate(Wix.Wix wix) { this.MutateElement(null, wix); }