Exemplo n.º 1
0
        /// <summary>
        /// Walks a directory structure obtaining Component Id's and Standard Directory Id's.
        /// </summary>
        /// <param name="directory">The Directory to walk.</param>
        /// <returns>true if the directory is TARGETDIR.</returns>
        private bool WalkDirectory(Wix.Directory directory)
        {
            bool isTargetDir = false;

            if ("TARGETDIR" == directory.Id)
            {
                isTargetDir = true;
            }

            string standardDirectoryId = null;

            if (Melter.StartsWithStandardDirectoryId(directory.Id, out standardDirectoryId) && !isTargetDir)
            {
                this.AddSetPropertyCustomAction(directory.Id, String.Format(CultureInfo.InvariantCulture, "[{0}]", standardDirectoryId));
            }

            foreach (Wix.ISchemaElement child in directory.Children)
            {
                Wix.Directory childDir = child as Wix.Directory;
                if (null != childDir)
                {
                    if (isTargetDir)
                    {
                        this.primaryDirectoryRef.AddChild(child);
                    }
                    this.WalkDirectory(childDir);
                }
                else
                {
                    Wix.Component childComponent = child as Wix.Component;
                    if (null != childComponent)
                    {
                        if (isTargetDir)
                        {
                            this.primaryDirectoryRef.AddChild(child);
                        }
                        this.AddComponentRef(childComponent);
                    }
                }
            }

            return(isTargetDir);
        }
Exemplo n.º 2
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);
        }