Exemplo n.º 1
0
 private Microsoft.Tools.WindowsInstallerXml.Serialize.Package CreatePackage(bool isWin64)
 {
     Microsoft.Tools.WindowsInstallerXml.Serialize.Package package = new Microsoft.Tools.WindowsInstallerXml.Serialize.Package();
     package.Id           = m_guid.ToString("D");
     package.Manufacturer = m_manufacturer;
     if (isWin64)
     {
         package.Platforms = "x64";
     }
     return(package);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new Application object.
 /// </summary>
 public Application()
 {
     this.wixRoot = new Wix();
     this.product = new Product();
     this.wixRoot.AddChild(this.product);
     this.package = new Package();
     this.package.Id = "????????-????-????-????-????????????";
     this.package.Compressed = Microsoft.Tools.WindowsInstallerXml.Serialize.YesNoType.yes;
     this.package.InstallerVersion = 200;
     this.product.AddChild(this.package);
 }
Exemplo n.º 3
0
        public void Load(bool isWin64, Catalogue catalogue)
        {
            // Get the root folder path.

            string rootFolderPath;

            if (string.IsNullOrEmpty(catalogue.RootFolder))
            {
                rootFolderPath = Path.GetDirectoryName(catalogue.FullPath);
            }
            else
            {
                rootFolderPath = FilePath.GetAbsolutePath(catalogue.RootFolder, Path.GetDirectoryName(catalogue.FullPath));
            }

            // Create the module element.

            Module module = CreateModule();

            Wix.AddChild(module);

            // Create the package element.

            Microsoft.Tools.WindowsInstallerXml.Serialize.Package package = CreatePackage(isWin64);
            module.AddChild(package);

            // Create a target directory element.

            Directory directory = CreateDirectory(Constants.Wix.Xml.Directory.Target.Id, Constants.Wix.Xml.Directory.Target.Name);

            module.AddChild(directory);

            // Load the artifacts in the catalogue.

            foreach (Artifact artifact in catalogue.Artifacts)
            {
                Load(isWin64, artifact, rootFolderPath, directory);
            }

            // Add the catalogue file itself.

            Artifact catalogueArtifact = new Artifact(FilePath.GetRelativePath(catalogue.FullPath, rootFolderPath));

            catalogueArtifact.SetMetadata(Constants.Catalogue.Artifact.Guid, catalogue.Guid);
            Load(isWin64, catalogueArtifact, rootFolderPath, directory);

            // Resolve all elements.

            Resolve(directory);
        }
Exemplo n.º 4
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.º 5
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();
            }
        }
Exemplo n.º 6
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;
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Decompile the _SummaryInformation table.
        /// </summary>
        /// <param name="table">The table to decompile.</param>
        private void Decompile_SummaryInformationTable(Table table)
        {
            if (OutputType.Module == this.outputType || OutputType.Product == this.outputType)
            {
                Wix.Package package = new Wix.Package();

                foreach (Row row in table.Rows)
                {
                    string value = Convert.ToString(row[1]);

                    if (null != value && 0 < value.Length)
                    {
                        switch (Convert.ToInt32(row[0]))
                        {
                            case 1:
                                if ("1252" != value)
                                {
                                    package.SummaryCodepage = value;
                                }
                                break;
                            case 3:
                                package.Description = value;
                                break;
                            case 4:
                                package.Manufacturer = value;
                                break;
                            case 5:
                                if ("Installer" != value)
                                {
                                    package.Keywords = value;
                                }
                                break;
                            case 6:
                                package.Comments = value;
                                break;
                            case 7:
                                string[] template = value.Split(';');
                                if (0 < template.Length && 0 < template[template.Length - 1].Length)
                                {
                                    package.Languages = template[template.Length - 1];
                                }

                                if (1 < template.Length && null != template[0] && 0 < template[0].Length)
                                {
                                    switch (template[0])
                                    {
                                        case "Intel":
                                            package.Platform = Microsoft.Tools.WindowsInstallerXml.Serialize.Package.PlatformType.x86;
                                            break;
                                        case "Intel64":
                                            package.Platform = Microsoft.Tools.WindowsInstallerXml.Serialize.Package.PlatformType.ia64;
                                            break;
                                        case "x64":
                                            package.Platform = Microsoft.Tools.WindowsInstallerXml.Serialize.Package.PlatformType.x64;
                                            break;
                                    }
                                }
                                break;
                            case 9:
                                if (OutputType.Module == this.outputType)
                                {
                                    this.modularizationGuid = value;
                                    package.Id = value;
                                }
                                break;
                            case 14:
                                package.InstallerVersion = Convert.ToInt32(row[1], CultureInfo.InvariantCulture);
                                break;
                            case 15:
                                int wordCount = Convert.ToInt32(row[1], CultureInfo.InvariantCulture);
                                if (0x1 == (wordCount & 0x1))
                                {
                                    this.shortNames = true;
                                    package.ShortNames = Wix.YesNoType.yes;
                                }

                                if (0x2 == (wordCount & 0x2))
                                {
                                    this.compressed = true;

                                    if (OutputType.Product == this.outputType)
                                    {
                                        package.Compressed = Wix.YesNoType.yes;
                                    }
                                }

                                if (0x4 == (wordCount & 0x4))
                                {
                                    package.AdminImage = Wix.YesNoType.yes;
                                }

                                if (0x8 == (wordCount & 0x8))
                                {
                                    package.InstallPrivileges = Wix.Package.InstallPrivilegesType.limited;
                                }

                                break;
                            case 19:
                                int security = Convert.ToInt32(row[1], CultureInfo.InvariantCulture);
                                switch (security)
                                {
                                    case 0:
                                        package.ReadOnly = Wix.YesNoDefaultType.no;
                                        break;
                                    case 4:
                                        package.ReadOnly = Wix.YesNoDefaultType.yes;
                                        break;
                                }
                                break;
                        }
                    }
                }

                this.core.RootElement.AddChild(package);
            }
            else
            {
                Wix.PatchInformation patchInformation = new Wix.PatchInformation();

                foreach (Row row in table.Rows)
                {
                    int propertyId = Convert.ToInt32(row[0]);
                    string value = Convert.ToString(row[1]);

                    if (null != row[1] && 0 < value.Length)
                    {
                        switch (propertyId)
                        {
                            case 1:
                                if ("1252" != value)
                                {
                                    patchInformation.SummaryCodepage = value;
                                }
                                break;
                            case 3:
                                patchInformation.Description = value;
                                break;
                            case 4:
                                patchInformation.Manufacturer = value;
                                break;
                            case 5:
                                if ("Installer,Patching,PCP,Database" != value)
                                {
                                    patchInformation.Keywords = value;
                                }
                                break;
                            case 6:
                                patchInformation.Comments = value;
                                break;
                            case 7:
                                string[] template = value.Split(';');
                                if (0 < template.Length && 0 < template[template.Length - 1].Length)
                                {
                                    patchInformation.Languages = template[template.Length - 1];
                                }

                                if (1 < template.Length && null != template[0] && 0 < template[0].Length)
                                {
                                    patchInformation.Platforms = template[0];
                                }
                                break;
                            case 15:
                                int wordCount = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                                if (0x1 == (wordCount & 0x1))
                                {
                                    patchInformation.ShortNames = Wix.YesNoType.yes;
                                }

                                if (0x2 == (wordCount & 0x2))
                                {
                                    patchInformation.Compressed = Wix.YesNoType.yes;
                                }

                                if (0x4 == (wordCount & 0x4))
                                {
                                    patchInformation.AdminImage = Wix.YesNoType.yes;
                                }
                                break;
                            case 19:
                                int security = Convert.ToInt32(value, CultureInfo.InvariantCulture);
                                switch (security)
                                {
                                    case 0:
                                        patchInformation.ReadOnly = Wix.YesNoDefaultType.no;
                                        break;
                                    case 4:
                                        patchInformation.ReadOnly = Wix.YesNoDefaultType.yes;
                                        break;
                                }
                                break;
                        }
                    }
                }

                this.core.RootElement.AddChild(patchInformation);
            }
        }
Exemplo n.º 8
0
        /// <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);
        }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
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;
                }
            }
        }
Exemplo n.º 11
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();
                }
                package.Compressed       = Wix.YesNoType.yes;
                package.InstallerVersion = 200;

                // create the root directory
                Wix.Directory targetDir = new Wix.Directory();
                targetDir.Id   = "TARGETDIR";
                targetDir.Name = "SourceDir";

                // add all previous root directories to the root directory
                foreach (Wix.Directory directory in this.directories)
                {
                    if (!(directory.ParentElement is Wix.Directory || directory.ParentElement is Wix.DirectoryRef))
                    {
                        ((Wix.IParentElement)directory.ParentElement).RemoveChild(directory);
                        targetDir.AddChild(directory);
                    }
                }

                // add children of DirectoryRef/@Id="TARGETROOT" elements to the root directory
                foreach (Wix.DirectoryRef directoryRef in this.directoryRefs)
                {
                    if ("TARGETDIR" == directoryRef.Id)
                    {
                        foreach (Wix.ISchemaElement element in directoryRef.Children)
                        {
                            targetDir.AddChild(element);
                        }
                        ((Wix.IParentElement)directoryRef.ParentElement).RemoveChild(directoryRef);
                    }
                }

                this.directories.Add(targetDir);

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

                    // add the authoring from the fragments directly into the module
                    foreach (Wix.Fragment fragment in wix.Children)
                    {
                        foreach (Wix.ISchemaElement element in fragment.Children)
                        {
                            module.AddChild(element);
                        }
                    }

                    foreach (Wix.Fragment fragment in wix.Children)
                    {
                        wix.RemoveChild(fragment);
                    }

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

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

                    // add the authoring from the fragments directly into the product
                    foreach (Wix.Fragment fragment in wix.Children)
                    {
                        foreach (Wix.ISchemaElement element in fragment.Children)
                        {
                            product.AddChild(element);
                        }
                    }

                    foreach (Wix.Fragment fragment in wix.Children)
                    {
                        wix.RemoveChild(fragment);
                    }

                    product.AddChild(targetDir);

                    wix.AddChild(product);
                    this.rootElement = product;
                }
            }
        }