Exemplo n.º 1
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);
 }
Exemplo n.º 2
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(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();
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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;
                }
            }
        }