/// <summary> /// Harvest wix authoring. /// </summary> /// <param name="argument">The argument for harvesting.</param> /// <returns>The harvested wix authoring.</returns> public Wix.Wix Harvest(string argument) { if (null == argument) { throw new ArgumentNullException("argument"); } if (null == this.harvesterExtension) { throw new InvalidOperationException("No harvester extension was specified."); } this.harvesterExtension.Core = new HarvesterCore(this.Message); Wix.Fragment fragment = this.harvesterExtension.Harvest(argument); if (null == fragment) { return(null); } Wix.Wix wix = new Wix.Wix(); wix.AddChild(fragment); return(wix); }
/// <summary> /// Harvest wix authoring. /// </summary> /// <param name="argument">The argument for harvesting.</param> /// <returns>The harvested wix authoring.</returns> public Wix.Wix Harvest(string argument) { if (null == argument) { throw new ArgumentNullException("argument"); } if (null == this.harvesterExtension) { throw new WixException(WixErrors.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> /// Converts a Module wixout into a ComponentGroup. /// </summary> /// <param name="wixout">The output object representing the unbound merge module to melt.</param> /// <returns>The converted Module as a ComponentGroup.</returns> public Wix.Wix Melt(Output wixout) { this.moduleId = GetModuleId(wixout); // Assign the default componentGroupId if none was specified if (null == this.id) { this.id = this.moduleId; } this.componentGroup.Id = this.id; this.primaryDirectoryRef.Id = this.id; PreDecompile(wixout); wixout.Type = OutputType.Product; this.decompiler.TreatProductAsModule = true; Wix.Wix wix = this.decompiler.Decompile(wixout); if (null == wix) { return(wix); } ConvertModule(wix); return(wix); }
/// <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(); }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> /// <returns>true if mutation was successful</returns> public bool Mutate(Wix.Wix wix) { bool encounteredError = false; try { // create a new core this.core = new MutatorCore(this.Message); foreach (MutatorExtension mutatorExtension in this.extensions.Values) { mutatorExtension.Mutate(wix); } } finally { encounteredError = this.core.EncounteredError; this.core = null; foreach (MutatorExtension mutatorExtension in this.extensions.Values) { mutatorExtension.Core = null; } } // return the Wix document element only if mutation completed successfully return(!encounteredError); }
/// <summary> /// Harvest a WiX document. /// </summary> /// <param name="argument">The argument for harvesting.</param> /// <returns>The harvested Fragment.</returns> public override void Mutate(Wix.Wix wix) { //Add in the product information from the main dll //Get the Product Component - update the following String MainBinFileName = harvesterMutator.MainBinFilePath; String MainBinGuid = harvesterMutator.MainComponentGuid; if (MainBinFileName != null) { FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(MainBinFileName); foreach (Wix.ISchemaElement ise in wix.Children) { if (ise is Wix.Product) { foreach (Wix.ISchemaElement fts in ((Wix.IParentElement)ise).Children) { if (fts is Wix.Feature) { ((Wix.Feature)fts).Title = "ActiveXControl"; } } Wix.Product productelement = (Wix.Product)ise; productelement.Id = MainBinGuid; productelement.Manufacturer = fileVersionInfo.CompanyName; productelement.Name = fileVersionInfo.ProductName; productelement.UpgradeCode = Guid.NewGuid().ToString("B").ToUpper(); productelement.Version = fileVersionInfo.FileVersion.Trim(" "); break; } } } }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public override void Mutate(Wix.Wix wix) { //Remove the inf file from the package Wix.Component InfComponent = this.GetComponentWithFileFromWix(null, wix, ".inf", true); String InfPath = GetFilePathFromComponent(InfComponent, ".inf", true); if (InfPath != null) { ((Wix.IParentElement)((Wix.ISchemaElement)InfComponent).ParentElement).RemoveChild(InfComponent); } //Process the inf for the package if (InfPath != null) { InfParser infp = new InfIntrepretor.InfParser(InfPath); infp.ParseIntoSections(); infp.InterpretInfToOpTree(); ProcessInfFile(infp.InfFiles, wix); Wix.Component BinComponent = this.GetComponentWithFileFromWix(null, wix, infp.MainBinFileName, false); this.mainBinFilePath = GetFilePathFromComponent(BinComponent, infp.MainBinFileName, false); } else { //go through and register every file //BUGBUGAddRegistrationInformation(wix); } }
/// <summary> /// Converts a Module wixout into a ComponentGroup. /// </summary> /// <param name="wixout">The output object representing the unbound merge module to melt.</param> /// <returns>The converted Module as a ComponentGroup.</returns> public Wix.Wix Melt(Output wixout) { string moduleId = GetModuleId(wixout); // Assign the default componentGroupId if none was specified if (null == this.id) { this.id = moduleId; } this.componentGroup.Id = this.id; this.primaryDirectoryRef.Id = this.id; PreDecompile(wixout); Wix.Wix wix = decompiler.Decompile(wixout); if (null == wix) { return(wix); } ConvertModule(wix); return(wix); }
/// <summary> /// Harvest wix authoring. /// </summary> /// <param name="argument">The argument for harvesting.</param> /// <returns>The harvested wix authoring.</returns> public Wix.Wix Harvest(string argument) { if (null == argument) { throw new ArgumentNullException("argument"); } if (null == this.harvesterExtension) { throw new WixException(WixErrors.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> /// Converts a Module to a ComponentGroup and adds all of its relevant elements to the main fragment. /// </summary> /// <param name="wix">The output object representing an unbound merge module.</param> private void ConvertModule(Wix.Wix wix) { Wix.Module module = GetModule(wix); foreach (Wix.ISchemaElement child in module.Children) { if (child is Wix.Directory) { bool isTargetDir = WalkDirectory((Wix.Directory)child); if (isTargetDir) { continue; } } else if (child is Wix.Dependency) { AddPropertyRef(((Wix.Dependency)child).RequiredId); continue; } else if (child is Wix.Package) { continue; } this.fragment.AddChild(child); } AddProperty(module.Id, this.id); wix.RemoveChild(module); wix.AddChild(this.fragment); this.fragment.AddChild(this.componentGroup); this.fragment.AddChild(this.primaryDirectoryRef); }
/// <summary> /// Gets the directory object for the provided application root path. /// </summary> /// <param name="recalculate">Flag to recalculate root directory.</param> /// <returns>Directory harvested from root.</returns> public Wix.Directory GetRootDirectory(bool recalculate) { if (null == this.source) { throw new ArgumentNullException("RootPath"); } if (recalculate || null == this.rootDirectory) { DirectoryHarvester directoryHarvester = new DirectoryHarvester(); this.rootDirectory = directoryHarvester.HarvestDirectory(this.source, true); Wix.Wix wix = new Wix.Wix(); Wix.Fragment fragment = new Wix.Fragment(); wix.AddChild(fragment); fragment.AddChild(this.rootDirectory); UtilMutator utilMutator = new UtilMutator(); utilMutator.GenerateGuids = true; utilMutator.SetUniqueIdentifiers = true; utilMutator.Mutate(wix); UtilFinalizeHarvesterMutator finalMutator = new UtilFinalizeHarvesterMutator(); finalMutator.Mutate(wix); } return(this.rootDirectory); }
/// <summary> /// Gets the module from the Wix object. /// </summary> /// <param name="wix">The Wix object.</param> /// <returns>The Module in the Wix object, null if no Module was found</returns> private Wix.Module GetModule(Wix.Wix wix) { foreach (Wix.ISchemaElement element in wix.Children) { if (element is Wix.Module) { return((Wix.Module)element); } } return(null); }
/// <summary> /// Gets the module from the Wix object. /// </summary> /// <param name="wix">The Wix object.</param> /// <returns>The Module in the Wix object, null if no Module was found</returns> private static Wix.Product GetProduct(Wix.Wix wix) { foreach (Wix.ISchemaElement element in wix.Children) { Wix.Product productElement = element as Wix.Product; if (null != productElement) { return(productElement); } } return(null); }
/// <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(); }
/// <summary> /// Gets the directory object for the ApplicationRoot. /// </summary> public Wix.Directory GetApplicationRootDirectory() { if (null != this.applicationRoot && null == this.applicationRootDirectory) { this.applicationRootDirectory = this.directoryHarvester.HarvestDirectory(this.applicationRoot.Content, true); Wix.Wix wix = new Wix.Wix(); Wix.Fragment fragment = new Wix.Fragment(); wix.AddChild(fragment); fragment.AddChild(this.applicationRootDirectory); this.utilMutator.Mutate(wix); this.finalMutator.Mutate(wix); } return(this.applicationRootDirectory); }
/// <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.directoryPaths.Clear(); this.filePaths.Clear(); this.files.Clear(); this.registryValues.Clear(); // index elements in this wix document this.IndexElement(wix); this.MutateDirectories(); this.MutateFiles(); this.MutateRegistryValues(); // must occur after all the registry values have been formatted this.MutateComponents(); }
/// <summary> /// Generates a WiX serialization object tree for a product that consumes the /// given unit tests. /// </summary> /// <param name="unitTestIds">List of unit test ids.</param> private void GenerateTestSource(IEnumerable <string> unitTestIds) { Wix.Product product = new Wix.Product(); product.Id = "*"; product.Language = "1033"; product.Manufacturer = "Lux"; product.Name = Path.GetFileNameWithoutExtension(this.outputFile) + " Lux test project"; product.Version = "1.0"; product.UpgradeCode = "{FBBDFC60-6EFF-427E-8B6B-7696A3C7066B}"; Wix.Package package = new Wix.Package(); package.Compressed = Wix.YesNoType.yes; package.InstallScope = Wix.Package.InstallScopeType.perUser; product.AddChild(package); foreach (string unitTestId in unitTestIds) { WixLux.UnitTestRef unitTestRef = new WixLux.UnitTestRef(); unitTestRef.Id = unitTestId; product.AddChild(unitTestRef); } Wix.Wix wix = new Wix.Wix(); wix.AddChild(product); // now write to the file XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; this.OnMessage(LuxBuildVerboses.GeneratingConsumer(this.outputFile, unitTestIds.Count())); using (XmlWriter writer = XmlWriter.Create(this.outputFile, settings)) { writer.WriteStartDocument(); wix.OutputXml(writer); writer.WriteEndDocument(); } }
private void ProcessInfFile(List <InfFileInstructions> InfFiles, Wix.Wix wix) { foreach (InfFileInstructions ifi in InfFiles) { Wix.Component FileComponent = this.GetComponentWithFileFromWix(null, wix, ifi.FileName, false); if (null == FileComponent) { Console.WriteLine("Exception: this file wasn't found in the current component..."); } if (mainComponentGuid == null) { mainComponentGuid = Guid.NewGuid().ToString("B").ToUpper(); FileComponent.Guid = mainComponentGuid; } else { FileComponent.Guid = Guid.NewGuid().ToString("B").ToUpper(); } String FilePath = GetFilePathFromComponent(FileComponent, ifi.FileName, false); if (ifi.RegisterServer == "yes") { DllHarvester dh = new DllHarvester(); Wix.RegistryValue[] axregvals = dh.HarvestRegistryValues(FilePath); foreach (Wix.RegistryValue r in axregvals) { FileComponent.AddChild(r); } } } }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> /// <returns>true if mutation was successful</returns> public bool Mutate(Wix.Wix wix) { bool encounteredError = false; try { foreach (MutatorExtension mutatorExtension in this.extensions.Values) { if (null == mutatorExtension.Core) { mutatorExtension.Core = this.core; } mutatorExtension.Mutate(wix); } } finally { encounteredError = this.core.EncounteredError; } // return the Wix document element only if mutation completed successfully return(!encounteredError); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { StringCollection extensionList = new StringCollection(); HeatCore heatCore = new HeatCore(new MessageEventHandler(this.messageHandler.Display)); try { // read the configuration file (heat.exe.config) AppCommon.ReadConfiguration(extensionList); // load any extensions foreach (string extensionType in extensionList) { HeatExtension heatExtension = HeatExtension.Load(extensionType); this.extensions.Add(heatExtension); foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes) { if (this.extensionsByType.Contains(commandLineOption.Option)) { throw new Exception(); } this.extensionsByType.Add(commandLineOption.Option, heatExtension); } heatExtension.Core = heatCore; } // parse the command line this.ParseCommandLine(args); // parse the extension's command line arguments string[] extensionOptionsArray = new string[this.extensionOptions.Count]; this.extensionOptions.CopyTo(extensionOptionsArray, 0); foreach (HeatExtension heatExtension in this.extensions) { heatExtension.ParseOptions(this.extensionType, extensionOptionsArray); if (heatCore.EncounteredError) { this.showHelp = true; } } // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (this.showLogo) { Assembly heatAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer XML Toolset Harvester version {0}", heatAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2006. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: heat.exe harvestType <harvester arguments> -out sourceFile.wxs"); Console.WriteLine(); Console.WriteLine("Supported harvesting types (use \"heat.exe <type> -?\" for more info):"); // output the harvest types alphabetically SortedList harvestTypes = new SortedList(); foreach (HeatExtension heatExtension in this.extensions) { foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes) { harvestTypes.Add(commandLineOption.Option, commandLineOption); } } foreach (HeatCommandLineOption commandLineOption in harvestTypes.Values) { Console.WriteLine(" {0,-7} {1}", commandLineOption.Option, commandLineOption.Description); } Console.WriteLine(); Console.WriteLine(" -nologo skip printing heat logo information"); Console.WriteLine(" -out specify output file (default: write to current directory)"); Console.WriteLine(" -sw<N> suppress warning with specific message ID"); Console.WriteLine(" -v verbose output"); Console.WriteLine(" -? this help information"); Console.WriteLine(""); Console.WriteLine("For more information see: http://wix.sourceforge.net"); return(this.messageHandler.LastErrorNumber); } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.extensionArgument); if (null == wix) { return(this.messageHandler.LastErrorNumber); } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return(this.messageHandler.LastErrorNumber); } XmlTextWriter writer = null; try { writer = new XmlTextWriter(this.outputFile, System.Text.Encoding.UTF8); writer.Indentation = 4; writer.IndentChar = ' '; writer.QuoteChar = '"'; writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); wix.OutputXml(writer); writer.WriteEndDocument(); } finally { if (null != writer) { writer.Close(); } } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Gets the directory object for the ApplicationRoot. /// </summary> public Wix.Directory GetApplicationRootDirectory() { if (null != this.applicationRoot && null == this.applicationRootDirectory) { this.applicationRootDirectory = this.directoryHarvester.HarvestDirectory(this.applicationRoot.Content, true); Wix.Wix wix = new Wix.Wix(); Wix.Fragment fragment = new Wix.Fragment(); wix.AddChild(fragment); fragment.AddChild(this.applicationRootDirectory); this.utilMutator.Mutate(wix); this.finalMutator.Mutate(wix); } return this.applicationRootDirectory; }
/// <summary> /// Mutate a WiX document. /// </summary> /// <param name="wix">The Wix document element.</param> public override void Mutate(Wix.Wix wix) { // delegate to contained instance. utilMutator.Mutate(wix); }
public Wix.Wix Decompile(Output output) { if (null == output) { throw new ArgumentNullException("output"); } this.codepage = output.Codepage; this.outputType = output.Type; // collect the table definitions from the output this.tableDefinitions.Clear(); foreach (Table table in output.Tables) { this.tableDefinitions.Add(table.Definition); } // add any missing standard and wix-specific table definitions foreach (TableDefinition tableDefinition in Installer.GetTableDefinitions()) { if (!this.tableDefinitions.Contains(tableDefinition.Name)) { this.tableDefinitions.Add(tableDefinition); } } // add any missing extension table definitions foreach (WixExtension extension in this.extensions) { if (null != extension.TableDefinitions) { foreach (TableDefinition tableDefinition in extension.TableDefinitions) { if (!this.tableDefinitions.Contains(tableDefinition.Name)) { this.tableDefinitions.Add(tableDefinition); } } } } // if we don't have the temporary files object yet, get one if (null == this.tempFiles) { this.TempFilesLocation = null; } Directory.CreateDirectory(this.tempFiles.BasePath); // ensure the base path is there bool encounteredError = false; Wix.IParentElement rootElement; Wix.Wix wixElement = new Wix.Wix(); switch (this.outputType) { case OutputType.Module: rootElement = new Wix.Module(); break; case OutputType.PatchCreation: rootElement = new Wix.PatchCreation(); break; case OutputType.Product: rootElement = new Wix.Product(); break; default: throw new InvalidOperationException(WixStrings.EXP_UnknownOutputType); } wixElement.AddChild((Wix.ISchemaElement)rootElement); // try to decompile the database file try { this.core = new DecompilerCore(rootElement, this.Message); this.core.ShowPedanticMessages = this.showPedanticMessages; // stop processing if an error previously occurred if (this.core.EncounteredError) { return null; } // initialize the decompiler and its extensions foreach (WixExtension extension in this.extensions) { if (null != extension.DecompilerExtension) { extension.DecompilerExtension.Core = this.core; extension.DecompilerExtension.InitializeDecompile(output.Tables); } } this.InitializeDecompile(output.Tables); // stop processing if an error previously occurred if (this.core.EncounteredError) { return null; } // decompile the tables this.DecompileTables(output); // finalize the decompiler and its extensions this.FinalizeDecompile(output.Tables); foreach (WixExtension extension in this.extensions) { if (null != extension.DecompilerExtension) { extension.DecompilerExtension.FinalizeDecompile(output.Tables); } } } finally { encounteredError = this.core.EncounteredError; this.core = null; foreach (WixExtension extension in this.extensions) { if (null != extension.DecompilerExtension) { extension.DecompilerExtension.Core = null; } } } // return the root element only if decompilation completed successfully return (encounteredError ? null : wixElement); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { StringCollection extensionList = new StringCollection(); heatCore = new HeatCore(new MessageEventHandler(this.messageHandler.Display)); HarvesterCore harvesterCore = new HarvesterCore(new MessageEventHandler(this.messageHandler.Display)); heatCore.Harvester.Core = harvesterCore; heatCore.Mutator.Core = harvesterCore; try { // read the configuration file (heat.exe.config) AppCommon.ReadConfiguration(extensionList); // load any extensions foreach (string extensionType in extensionList) { this.LoadExtension(extensionType); } // exit if there was an error loading an extension if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // parse the command line this.ParseCommandLine(args); if (this.showHelp) { return(this.DisplayHelp()); } // exit if there was an error parsing the core command line if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } // set the extension argument for use by all extensions harvesterCore.ExtensionArgument = this.extensionArgument; // parse the extension's command line arguments string[] extensionOptionsArray = new string[this.extensionOptions.Count]; this.extensionOptions.CopyTo(extensionOptionsArray, 0); foreach (HeatExtension heatExtension in this.extensions) { heatExtension.ParseOptions(this.extensionType, extensionOptionsArray); } // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.extensionArgument); if (null == wix) { return(this.messageHandler.LastErrorNumber); } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return(this.messageHandler.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.messageHandler.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.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <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, Product, or Module elements present."); } // create a package element although it won't always be used Wix.Package package = new Wix.Package(); 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.Product product = new Wix.Product(); 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> /// Extracts files from a merge module and creates corresponding ComponentGroup WiX authoring. /// </summary> private void MeltModule() { Decompiler decompiler = null; Unbinder unbinder = null; Melter melter = null; try { // create the decompiler, unbinder, and melter decompiler = new Decompiler(); unbinder = new Unbinder(); melter = new Melter(decompiler, id); // read the configuration file (melt.exe.config) AppCommon.ReadConfiguration(this.extensionList); // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); decompiler.AddExtension(wixExtension); unbinder.AddExtension(wixExtension); } // set options decompiler.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); unbinder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); unbinder.SuppressDemodularization = true; decompiler.Message += new MessageEventHandler(this.messageHandler.Display); unbinder.Message += new MessageEventHandler(this.messageHandler.Display); melter.Message += new MessageEventHandler(this.messageHandler.Display); // print friendly message saying what file is being decompiled Console.WriteLine(Path.GetFileName(this.inputFile)); // unbind Output output = unbinder.Unbind(this.inputFile, this.outputType, this.exportBasePath); if (null != output) { Wix.Wix wix = melter.Melt(output); if (null != wix) { XmlTextWriter writer = null; try { writer = new XmlTextWriter(this.outputFile, System.Text.Encoding.UTF8); writer.Indentation = 4; writer.IndentChar = ' '; writer.QuoteChar = '"'; writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); wix.OutputXml(writer); writer.WriteEndDocument(); } finally { if (null != writer) { writer.Close(); } } } } } finally { if (null != decompiler) { if (this.tidy) { if (!decompiler.DeleteTempFiles()) { Console.WriteLine(MeltStrings.WAR_FailedToDeleteTempDir, decompiler.TempFilesLocation); } } else { Console.WriteLine(MeltStrings.INF_TempDirLocatedAt, decompiler.TempFilesLocation); } } if (null != unbinder) { if (this.tidy) { if (!unbinder.DeleteTempFiles()) { Console.WriteLine(MeltStrings.WAR_FailedToDeleteTempDir, unbinder.TempFilesLocation); } } else { Console.WriteLine(MeltStrings.INF_TempDirLocatedAt, unbinder.TempFilesLocation); } } } }
/// <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 document. /// </summary> /// <param name="wix">The Wix document element.</param> public abstract void Mutate(Wix.Wix wix);
/// <summary> /// Gets the directory object for the provided application root path. /// </summary> /// <param name="recalculate">Flag to recalculate root directory.</param> /// <returns>Directory harvested from root.</returns> public Wix.Directory GetRootDirectory(bool recalculate) { if (null == this.source) { throw new ArgumentNullException("RootPath"); } if (recalculate || null == this.rootDirectory) { DirectoryHarvester directoryHarvester = new DirectoryHarvester(); this.rootDirectory = directoryHarvester.HarvestDirectory(this.source, true); Wix.Wix wix = new Wix.Wix(); Wix.Fragment fragment = new Wix.Fragment(); wix.AddChild(fragment); fragment.AddChild(this.rootDirectory); UtilMutator utilMutator = new UtilMutator(); utilMutator.GenerateGuids = true; utilMutator.SetUniqueIdentifiers = true; utilMutator.Mutate(wix); UtilFinalizeHarvesterMutator finalMutator = new UtilFinalizeHarvesterMutator(); finalMutator.Mutate(wix); } return this.rootDirectory; }
/// <summary> /// Converts a Module to a ComponentGroup and adds all of its relevant elements to the main fragment. /// </summary> /// <param name="wix">The output object representing an unbound merge module.</param> private void ConvertModule(Wix.Wix wix) { Wix.Product product = Melter.GetProduct(wix); List <string> customActionsRemoved = new List <string>(); Dictionary <Wix.Custom, Wix.InstallExecuteSequence> customsToRemove = new Dictionary <Wix.Custom, Wix.InstallExecuteSequence>(); foreach (Wix.ISchemaElement child in product.Children) { Wix.Directory childDir = child as Wix.Directory; if (null != childDir) { bool isTargetDir = this.WalkDirectory(childDir); if (isTargetDir) { continue; } } else { Wix.Dependency childDep = child as Wix.Dependency; if (null != childDep) { this.AddPropertyRef(childDep.RequiredId); continue; } else if (child is Wix.Package) { continue; } else if (child is Wix.CustomAction) { Wix.CustomAction customAction = child as Wix.CustomAction; string directoryId; if (StartsWithStandardDirectoryId(customAction.Id, out directoryId) && customAction.Property == customAction.Id) { customActionsRemoved.Add(customAction.Id); continue; } } else if (child is Wix.InstallExecuteSequence) { Wix.InstallExecuteSequence installExecuteSequence = child as Wix.InstallExecuteSequence; foreach (Wix.ISchemaElement sequenceChild in installExecuteSequence.Children) { Wix.Custom custom = sequenceChild as Wix.Custom; string directoryId; if (custom != null && StartsWithStandardDirectoryId(custom.Action, out directoryId)) { customsToRemove.Add(custom, installExecuteSequence); } } } } this.fragment.AddChild(child); } // For any customaction that we removed, also remove the scheduling of that action. foreach (Wix.Custom custom in customsToRemove.Keys) { if (customActionsRemoved.Contains(custom.Action)) { ((Wix.InstallExecuteSequence)customsToRemove[custom]).RemoveChild(custom); } } AddProperty(this.moduleId, this.id); wix.RemoveChild(product); wix.AddChild(this.fragment); this.fragment.AddChild(this.componentGroup); this.fragment.AddChild(this.primaryDirectoryRef); }
/// <summary> /// Generates the .wxs file for the application. /// </summary> /// <returns>XmlDocument containing the .wxs file for the application.</returns> private XmlDocument GenerateSourceFile() { XmlDocument sourceDoc = null; // Ensure the root application directory has been calculated and the // new PackageCode is generated. this.GetRootDirectory(false); if (this.productCode == Guid.Empty) { this.productCode = Guid.NewGuid(); } // Build up the product information. Wix.Wix wix = new Wix.Wix(); Wix.Product product = new Wix.Product(); product.Id = this.productCode.ToString(); product.Language = this.language; product.Manufacturer = this.manufacturer; product.Name = this.name; product.UpgradeCode = this.upgradeCode.ToString(); product.Version = this.version.ToString(); wix.AddChild(product); Wix.Package package = new Wix.Package(); package.Compressed = Wix.YesNoType.yes; if (null != this.description) { package.Description = this.description; } package.InstallerVersion = 200; product.AddChild(package); Wix.WixVariable variable = new Wix.WixVariable(); variable = new Wix.WixVariable(); variable.Id = "ProductName"; variable.Value = product.Name; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ProductCode"; variable.Value = product.Id; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ProductVersion"; variable.Value = product.Version; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ShimPath"; variable.Value = this.shimPath; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ShimClsid"; variable.Value = this.ShimClsid.ToString("B"); product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ShimProgId"; variable.Value = this.shimProgid; product.AddChild(variable); // Upgrade logic. Wix.Upgrade upgrade = new Wix.Upgrade(); upgrade.Id = product.UpgradeCode; product.AddChild(upgrade); Wix.UpgradeVersion minUpgrade = new Wix.UpgradeVersion(); minUpgrade.Minimum = product.Version; minUpgrade.OnlyDetect = Wix.YesNoType.yes; minUpgrade.Property = "NEWERVERSIONDETECTED"; upgrade.AddChild(minUpgrade); Wix.UpgradeVersion maxUpgrade = new Wix.UpgradeVersion(); maxUpgrade.Maximum = product.Version; maxUpgrade.IncludeMaximum = Wix.YesNoType.no; maxUpgrade.Property = "OLDERVERSIONBEINGUPGRADED"; upgrade.AddChild(maxUpgrade); // Update feed property. Wix.Property property = new Wix.Property(); property.Id = "ARPURLUPDATEINFO"; property.Value = this.updateUrl.AbsoluteUri; product.AddChild(property); // Root the application's directory tree in the applications folder. Wix.DirectoryRef applicationsFolderRef = new Wix.DirectoryRef(); applicationsFolderRef.Id = "ApplicationsFolder"; product.AddChild(applicationsFolderRef); this.rootDirectory.Name = String.Concat(product.Id, "v", product.Version); applicationsFolderRef.AddChild(this.rootDirectory); // Add the shim to the root directory. Wix.Component shimComponent = this.GenerateShimComponent(); this.rootDirectory.AddChild(shimComponent); // Add all of the Components to the Feature tree. Wix.FeatureRef applicationFeatureRef = new Wix.FeatureRef(); applicationFeatureRef.Id = "ApplicationFeature"; product.AddChild(applicationFeatureRef); Wix.ComponentRef[] componentRefs = this.GetComponentRefs(this.rootDirectory); foreach (Wix.ComponentRef componentRef in componentRefs) { applicationFeatureRef.AddChild(componentRef); } // Serialize product information to an xml string. string xml; using (StringWriter sw = new StringWriter()) { XmlTextWriter writer = null; try { writer = new XmlTextWriter(sw); wix.OutputXml(writer); xml = sw.ToString(); } finally { if (writer != null) { writer.Close(); } } } // Load the xml into a document. sourceDoc = new XmlDocument(); sourceDoc.LoadXml(xml); return sourceDoc; }
/// <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.Product == 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.Product foreach (Wix.Fragment fragment in this.fragments.Values) { wix.AddChild(fragment); } }
/// <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 < 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 = fragments.IndexOfKey(String.Concat("Component:", c.Id)); if (0 <= removeIndex) { fragments.RemoveAt(removeIndex); } } } } } else { Wix.ComponentRef componentRef = new Wix.ComponentRef(); componentRef.Id = c.Id; componentGroup.AddChild(componentRef); } } }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { Decompiler decompiler = null; Mutator mutator = null; Unbinder unbinder = null; try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.inputFile) { this.showHelp = true; } else if (null == this.outputFile) { if (null == this.outputDirectory) { this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFile), ".wxs"); } else { this.outputFile = Path.Combine(this.outputDirectory, Path.ChangeExtension(Path.GetFileName(this.inputFile), ".wxs")); } } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(DarkStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // create the decompiler and mutator decompiler = new Decompiler(); mutator = new Mutator(); mutator.Core = new HarvesterCore(new MessageEventHandler(this.messageHandler.Display)); unbinder = new Unbinder(); // read the configuration file (dark.exe.config) AppCommon.ReadConfiguration(this.extensionList); // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); decompiler.AddExtension(wixExtension); unbinder.AddExtension(wixExtension); } // set options decompiler.SuppressCustomTables = this.suppressCustomTables; decompiler.SuppressDroppingEmptyTables = this.suppressDroppingEmptyTables; decompiler.SuppressRelativeActionSequencing = this.suppressRelativeActionSequencing; decompiler.SuppressUI = this.suppressUI; decompiler.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); if (!String.IsNullOrEmpty(this.exportBasePath)) { decompiler.ExportFilePath = this.exportBasePath; } unbinder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); decompiler.Message += new MessageEventHandler(this.messageHandler.Display); unbinder.Message += new MessageEventHandler(this.messageHandler.Display); // print friendly message saying what file is being decompiled Console.WriteLine(Path.GetFileName(this.inputFile)); // unbind // TODO: passing a bundle to the decompiler without the /x parameter specified stumbles here // as the exportBasePath will be null. Need a design decision whether to throw an // message below or throw a message here Output output = unbinder.Unbind(this.inputFile, this.outputType, this.exportBasePath); if (null != output) { if (OutputType.Patch == this.outputType || OutputType.Transform == this.outputType || this.outputXml) { output.Save(this.outputFile, null, new WixVariableResolver(), null); } else // decompile { Wix.Wix wix = decompiler.Decompile(output); // output if (null != wix) { XmlTextWriter writer = null; // mutate the Wix document if (!mutator.Mutate(wix)) { return(this.messageHandler.LastErrorNumber); } try { Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(this.outputFile))); writer = new XmlTextWriter(this.outputFile, System.Text.Encoding.UTF8); writer.Indentation = 4; writer.IndentChar = ' '; writer.QuoteChar = '"'; writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); wix.OutputXml(writer); writer.WriteEndDocument(); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.FileWriteError(this.outputFile, e.Message)); return(this.messageHandler.LastErrorNumber); } finally { if (null != writer) { writer.Close(); } } } } } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != decompiler) { if (this.tidy) { if (!decompiler.DeleteTempFiles()) { Console.WriteLine(DarkStrings.WAR_FailedToDeleteTempDir, decompiler.TempFilesLocation); } } else { Console.WriteLine(DarkStrings.INF_TempDirLocatedAt, decompiler.TempFilesLocation); } } if (null != unbinder) { if (this.tidy) { if (!unbinder.DeleteTempFiles()) { Console.WriteLine(DarkStrings.WAR_FailedToDeleteTempDir, unbinder.TempFilesLocation); } } else { Console.WriteLine(DarkStrings.INF_TempDirLocatedAt, unbinder.TempFilesLocation); } } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Generates a WiX serialization object tree for a product that consumes the /// given unit tests. /// </summary> /// <param name="unitTestIds">List of unit test ids.</param> private void GenerateTestSource(List<string> unitTestIds) { Wix.Product product = new Wix.Product(); product.Id = "*"; product.Language = "1033"; product.Manufacturer = "Lux"; product.Name = Path.GetFileNameWithoutExtension(this.outputFile) + " Lux test project"; product.Version = "1.0"; product.UpgradeCode = "{FBBDFC60-6EFF-427E-8B6B-7696A3C7066B}"; Wix.Package package = new Wix.Package(); package.Compressed = Wix.YesNoType.yes; package.InstallScope = Wix.Package.InstallScopeType.perUser; product.AddChild(package); foreach (string unitTestId in unitTestIds) { WixLux.UnitTestRef unitTestRef = new WixLux.UnitTestRef(); unitTestRef.Id = unitTestId; product.AddChild(unitTestRef); } Wix.Wix wix = new Wix.Wix(); wix.AddChild(product); // now write to the file XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; this.OnMessage(LuxBuildVerboses.GeneratingConsumer(this.outputFile, unitTestIds.Count)); using (XmlWriter writer = XmlWriter.Create(this.outputFile, settings)) { writer.WriteStartDocument(); wix.OutputXml(writer); writer.WriteEndDocument(); } }
/// <summary> /// Generates the .wxs file for the application. /// </summary> /// <returns>XmlDocument containing the .wxs file for the application.</returns> private XmlDocument GenerateSourceFile() { XmlDocument sourceDoc = null; // Ensure the root application directory has been calculated and the // new PackageCode is generated. this.GetRootDirectory(false); if (this.productCode == Guid.Empty) { this.productCode = Guid.NewGuid(); } // Build up the product information. Wix.Wix wix = new Wix.Wix(); Wix.Product product = new Wix.Product(); product.Id = this.productCode.ToString(); product.Language = this.language; product.Manufacturer = this.manufacturer; product.Name = this.name; product.UpgradeCode = this.upgradeCode.ToString(); product.Version = this.version.ToString(); wix.AddChild(product); Wix.Package package = new Wix.Package(); package.Compressed = Wix.YesNoType.yes; if (null != this.description) { package.Description = this.description; } package.InstallerVersion = 200; product.AddChild(package); Wix.WixVariable variable = new Wix.WixVariable(); variable = new Wix.WixVariable(); variable.Id = "ProductName"; variable.Value = product.Name; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ProductCode"; variable.Value = product.Id; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ProductVersion"; variable.Value = product.Version; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ShimPath"; variable.Value = this.shimPath; product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ShimClsid"; variable.Value = this.ShimClsid.ToString("B"); product.AddChild(variable); variable = new Wix.WixVariable(); variable.Id = "ShimProgId"; variable.Value = this.shimProgid; product.AddChild(variable); // Upgrade logic. Wix.Upgrade upgrade = new Wix.Upgrade(); upgrade.Id = product.UpgradeCode; product.AddChild(upgrade); Wix.UpgradeVersion minUpgrade = new Wix.UpgradeVersion(); minUpgrade.Minimum = product.Version; minUpgrade.OnlyDetect = Wix.YesNoType.yes; minUpgrade.Property = "NEWERVERSIONDETECTED"; upgrade.AddChild(minUpgrade); Wix.UpgradeVersion maxUpgrade = new Wix.UpgradeVersion(); maxUpgrade.Maximum = product.Version; maxUpgrade.IncludeMaximum = Wix.YesNoType.no; maxUpgrade.Property = "OLDERVERSIONBEINGUPGRADED"; upgrade.AddChild(maxUpgrade); // Update feed property. Wix.Property property = new Wix.Property(); property.Id = "ARPURLUPDATEINFO"; property.Value = this.updateUrl.AbsoluteUri; product.AddChild(property); // Root the application's directory tree in the applications folder. Wix.DirectoryRef applicationsFolderRef = new Wix.DirectoryRef(); applicationsFolderRef.Id = "ApplicationsFolder"; product.AddChild(applicationsFolderRef); this.rootDirectory.Name = String.Concat(product.Id, "v", product.Version); applicationsFolderRef.AddChild(this.rootDirectory); // Add the shim to the root directory. Wix.Component shimComponent = this.GenerateShimComponent(); this.rootDirectory.AddChild(shimComponent); // Add all of the Components to the Feature tree. Wix.FeatureRef applicationFeatureRef = new Wix.FeatureRef(); applicationFeatureRef.Id = "ApplicationFeature"; product.AddChild(applicationFeatureRef); Wix.ComponentRef[] componentRefs = this.GetComponentRefs(this.rootDirectory); foreach (Wix.ComponentRef componentRef in componentRefs) { applicationFeatureRef.AddChild(componentRef); } // Serialize product information to an xml string. string xml; using (StringWriter sw = new StringWriter()) { XmlTextWriter writer = null; try { writer = new XmlTextWriter(sw); wix.OutputXml(writer); xml = sw.ToString(); } finally { if (writer != null) { writer.Close(); } } } // Load the xml into a document. sourceDoc = new XmlDocument(); sourceDoc.LoadXml(xml); return(sourceDoc); }