Beispiel #1
0
        /// <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>
        /// 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>
        /// Gets the directory object for the provided application root path.
        /// </summary>
        /// <param name="recalculate">Recalculate root directory.</param>
        /// <returns>Directory for root.</returns>
        public Wix.Directory GetRootDirectory(bool recalculate)
        {
            if (null == this.source)
            {
                throw new ArgumentNullException("Source");
            }

            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);
        }
Beispiel #4
0
        /// <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);
        }
Beispiel #5
0
 /// <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);
 }
Beispiel #6
0
        /// <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);
        }
Beispiel #8
0
        /// <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();
            }
        }
Beispiel #9
0
        /// <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);
        }
Beispiel #10
0
        /// <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>
        /// 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);

            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;
            package.InstallPrivileges = Wix.Package.InstallPrivilegesType.limited;
            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);

            // Find the entry File/@Id for the Shortcut to point at.
            Wix.File entryFile = this.GetFile(this.rootDirectory, this.entryFileRelativePath);
            variable       = new Wix.WixVariable();
            variable.Id    = "ShortcutFileId";
            variable.Value = entryFile.Id;
            product.AddChild(variable);

            // Set the target Component's GUID to be the same as the ProductCode for easy
            // lookup by the update.exe.
            Wix.Component targetComponent = (Wix.Component)entryFile.ParentElement;
            targetComponent.Guid = product.Id;

            variable       = new Wix.WixVariable();
            variable.Id    = "TargetComponentId";
            variable.Value = targetComponent.Guid;
            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 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.MutateElement(null, wix);
 }
Beispiel #13
0
        /// <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);
        }
Beispiel #14
0
 /// <summary>
 /// Mutate a WiX document.
 /// </summary>
 /// <param name="wix">The Wix document element.</param>
 public virtual void Mutate(Wix.Wix wix)
 {
 }
Beispiel #15
0
        /// <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 (Messaging.Instance.EncounteredError)
                {
                    return(Messaging.Instance.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(Messaging.Instance.LastErrorNumber);
                }

                foreach (string parameter in this.invalidArgs)
                {
                    Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(parameter));
                }
                this.invalidArgs = null;

                // create the decompiler and mutator
                decompiler   = new Decompiler();
                mutator      = new Mutator();
                mutator.Core = new HarvesterCore();
                unbinder     = new Unbinder();

                // read the configuration file (dark.exe.config)
                AppCommon.ReadConfiguration(this.extensionList);

                // load all extensions
                ExtensionManager extensionManager = new ExtensionManager();
                foreach (string extension in this.extensionList)
                {
                    extensionManager.Load(extension);
                }

                foreach (IDecompilerExtension extension in extensionManager.Create <IDecompilerExtension>())
                {
                    decompiler.AddExtension(extension);
                }

                foreach (IUnbinderExtension extension in extensionManager.Create <IUnbinderExtension>())
                {
                    unbinder.AddExtension(extension);
                }

                // 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");

                // 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(Messaging.Instance.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)
                            {
                                Messaging.Instance.OnMessage(WixErrors.FileWriteError(this.outputFile, e.Message));
                                return(Messaging.Instance.LastErrorNumber);
                            }
                            finally
                            {
                                if (null != writer)
                                {
                                    writer.Close();
                                }
                            }
                        }
                    }
                }
            }
            catch (WixException we)
            {
                Messaging.Instance.OnMessage(we.Error);
            }
            catch (Exception e)
            {
                Messaging.Instance.OnMessage(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(Messaging.Instance.LastErrorNumber);
        }
Beispiel #16
0
        /// <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);
                }
            }
        }
Beispiel #17
0
        /// <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);
        }
Beispiel #18
0
        /// <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;
                }
            }
        }
Beispiel #19
0
        /// <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 all extensions
                ExtensionManager extensionManager = new ExtensionManager();
                foreach (string extension in this.extensionList)
                {
                    extensionManager.Load(extension);
                }

                foreach (IDecompilerExtension extension in extensionManager.Create <IDecompilerExtension>())
                {
                    decompiler.AddExtension(extension);
                }

                foreach (IUnbinderExtension extension in extensionManager.Create <IUnbinderExtension>())
                {
                    unbinder.AddExtension(extension);
                }

                // set options
                decompiler.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP");

                unbinder.TempFilesLocation        = Environment.GetEnvironmentVariable("WIX_TEMP");
                unbinder.SuppressDemodularization = true;

                // 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);
                    }
                }
            }
        }