Example #1
0
        /// <summary>
        /// Harvest a WiX document.
        /// </summary>
        /// <param name="argument">The argument for harvesting.</param>
        /// <returns>The harvested Fragment.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            DirectoryHarvester directoryHarvester = new DirectoryHarvester();

            directoryHarvester.Core = this.Core;
            directoryHarvester.KeepEmptyDirectories = true;

            IIsWebSiteHarvester iisWebSiteHarvester = new IIsWebSiteHarvester();

            iisWebSiteHarvester.Core = this.Core;

            IIs.WebSite webSite = iisWebSiteHarvester.HarvestWebSite(argument);

            Wix.Component component = new Wix.Component();
            component.AddChild(new Wix.CreateFolder());
            component.AddChild(webSite);

            this.Core.RootDirectory = webSite.Directory;
            Wix.Directory directory = directoryHarvester.HarvestDirectory(webSite.Directory, true);
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(new Wix.Fragment[] { fragment });
        }
        /// <summary>
        /// Harvest a reg file.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <returns>A harvested registy file.</returns>
        public Wix.Fragment HarvestRegFile(string path)
        {
            if (null == path)
            {
                throw new ArgumentNullException("path");
            }

            if (!File.Exists(path))
            {
                throw new WixException(UtilErrors.FileNotFound(path));
            }

            Wix.Directory directory = new Wix.Directory();
            directory.Id = "TARGETDIR";

            // Use absolute paths
            path = Path.GetFullPath(path);
            FileInfo file = new FileInfo(path);

            using (StreamReader sr = file.OpenText())
            {
                string line;
                this.currentLineNumber = 0;

                while (null != (line = this.GetNextLine(sr)))
                {
                    if (line.StartsWith(@"Windows Registry Editor Version 5.00"))
                    {
                        this.unicodeRegistry = true;
                    }
                    else if (line.StartsWith(@"REGEDIT4"))
                    {
                        this.unicodeRegistry = false;
                    }
                    else if (line.StartsWith(@"[HKEY_CLASSES_ROOT\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKCR, line.Substring(19, line.Length - 20));
                    }
                    else if (line.StartsWith(@"[HKEY_CURRENT_USER\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKCU, line.Substring(19, line.Length - 20));
                    }
                    else if (line.StartsWith(@"[HKEY_LOCAL_MACHINE\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKLM, line.Substring(20, line.Length - 21));
                    }
                    else if (line.StartsWith(@"[HKEY_USERS\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKU, line.Substring(12, line.Length - 13));
                    }
                }
            }

            Console.WriteLine("Processing complete");

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(fragment);
        }
Example #3
0
        /// <summary>
        /// Harvest the cab file.
        /// </summary>
        /// <param name="fragment">The property name of the bindings property.</param>
        /// <param name="argument">The path to the cab file.</param>
        /// <returns>The harvested cab binaries.</returns>
        private Wix.Fragment HarvestCab(Wix.Fragment fragment, String argument)
        {
            // crack the cab file into a temp directory.
            String cabDir = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString();

            // should this be in a try...catch?
            System.IO.Directory.CreateDirectory(cabDir);

            using (WixExtractCab extractCab = new WixExtractCab())
            {
                try
                {
                    extractCab.Extract(argument, cabDir);
                }
                catch (FileNotFoundException)
                {
                    throw new WixException(WixErrors.CabExtractionFailed(argument, cabDir));
                }
            }

            // Process the folder
            //
            DirectoryHarvester ds = new DirectoryHarvester();

            fragment = ds.Harvest(cabDir);

            return(fragment);
        }
Example #4
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 InvalidOperationException("No harvester extension was specified.");
            }

            this.harvesterExtension.Core = new HarvesterCore(this.Message);

            Wix.Fragment fragment = this.harvesterExtension.Harvest(argument);
            if (null == fragment)
            {
                return(null);
            }

            Wix.Wix wix = new Wix.Wix();
            wix.AddChild(fragment);

            return(wix);
        }
Example #5
0
        /// <summary>
        /// Gets the directory object for the provided application root path.
        /// </summary>
        /// <param name="recalculate">Flag to recalculate root directory.</param>
        /// <returns>Directory harvested from root.</returns>
        public Wix.Directory GetRootDirectory(bool recalculate)
        {
            if (null == this.source)
            {
                throw new ArgumentNullException("RootPath");
            }

            if (recalculate || null == this.rootDirectory)
            {
                DirectoryHarvester directoryHarvester = new DirectoryHarvester();
                this.rootDirectory = directoryHarvester.HarvestDirectory(this.source, true);

                Wix.Wix      wix      = new Wix.Wix();
                Wix.Fragment fragment = new Wix.Fragment();
                wix.AddChild(fragment);
                fragment.AddChild(this.rootDirectory);

                UtilMutator utilMutator = new UtilMutator();
                utilMutator.GenerateGuids        = true;
                utilMutator.SetUniqueIdentifiers = true;
                utilMutator.Mutate(wix);

                UtilFinalizeHarvesterMutator finalMutator = new UtilFinalizeHarvesterMutator();
                finalMutator.Mutate(wix);
            }

            return(this.rootDirectory);
        }
Example #6
0
        /// <summary>
        /// Harvest a file.
        /// </summary>
        /// <param name="argument">The path of the file.</param>
        /// <returns>A harvested file.</returns>
        public override Wix.Fragment Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Wix.File file = this.HarvestFile(argument);

            Wix.Component component = new Wix.Component();
            component.AddChild(file);

            string directoryPath = Path.GetDirectoryName(Path.GetFullPath(argument));

            Wix.Directory directory = new Wix.Directory();
            directory.FileSource = directoryPath;
            directory.Name       = Path.GetFileName(directoryPath);
            directory.AddChild(component);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = "TARGETDIR";
            directoryRef.AddChild(directory);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directoryRef);

            return(fragment);
        }
        /// <summary>
        /// Harvest a directory.
        /// </summary>
        /// <param name="argument">The path of the directory.</param>
        /// <returns>The harvested directory.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Wix.Directory directory = this.HarvestDirectory(argument, "SourceDir\\", true);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = this.rootedDirectoryRef;

            if (this.suppressRootDirectory)
            {
                foreach (Wix.ISchemaElement element in directory.Children)
                {
                    directoryRef.AddChild(element);
                }
            }
            else
            {
                directoryRef.AddChild(directory);
            }

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directoryRef);

            return(new Wix.Fragment[] { fragment });
        }
Example #8
0
        /// <summary>
        /// Harvest a file.
        /// </summary>
        /// <param name="argument">The path of the file.</param>
        /// <returns>A harvested file.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            if (null == this.rootedDirectoryRef)
            {
                this.rootedDirectoryRef = "TARGETDIR";
            }

            string fullPath = Path.GetFullPath(argument);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = this.rootedDirectoryRef;

            Wix.File file = this.HarvestFile(fullPath);

            if (!this.suppressRootDirectory)
            {
                file.Source = String.Concat("SourceDir\\", Path.GetFileName(Path.GetDirectoryName(fullPath)), "\\", Path.GetFileName(fullPath));
            }

            Wix.Component component = new Wix.Component();
            component.AddChild(file);

            Wix.Directory directory = new Wix.Directory();

            if (this.suppressRootDirectory)
            {
                directoryRef.AddChild(component);
            }
            else
            {
                string directoryPath = Path.GetDirectoryName(Path.GetFullPath(argument));
                directory.Name = Path.GetFileName(directoryPath);

                if (this.setUniqueIdentifiers)
                {
                    directory.Id = this.Core.GenerateIdentifier(DirectoryPrefix, directoryRef.Id, directory.Name);
                }
                directory.AddChild(component);
                directoryRef.AddChild(directory);
            }

            if (this.setUniqueIdentifiers)
            {
                file.Id      = this.Core.GenerateIdentifier(FilePrefix, (this.suppressRootDirectory) ? directoryRef.Id : directory.Id, Path.GetFileName(file.Source));
                component.Id = this.Core.GenerateIdentifier(ComponentPrefix, (this.suppressRootDirectory) ? directoryRef.Id : directory.Id, file.Id);
            }

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directoryRef);

            return(new Wix.Fragment[] { fragment });
        }
Example #9
0
        /// <summary>
        /// Harvest the dll or ocx file.
        /// </summary>
        /// <param name="fragment">The property name of the bindings property.</param>
        /// <param name="argument">The dll path.</param>
        /// <returns>The harvested dll or ocx product xml.</returns>
        ///
        private Wix.Fragment HarvestDll(Wix.Fragment fragment, string argument)
        {
            // argument contains the path to the ICD dll file.

            // create the msi file
            //BUGBUG:: the dll file needs to be dealt with...
            Console.WriteLine("Exception: this currently isn't implemented.");

            return(fragment);
        }
        /// <summary>
        /// Harvest a file.
        /// </summary>
        /// <param name="argument">The path of the file.</param>
        /// <returns>A harvested file.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            // Harvest the keys from the registry file
            Wix.Fragment fragment = this.HarvestRegFile(argument);

            return(new Wix.Fragment[] { fragment });
        }
Example #11
0
        /// <summary>
        /// Harvest a directory.
        /// </summary>
        /// <param name="argument">The path of the directory.</param>
        /// <returns>The harvested directory.</returns>
        public override Wix.Fragment Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Wix.Directory directory = this.HarvestDirectory(argument, true);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(fragment);
        }
Example #12
0
        /// <summary>
        /// Creates a new melter object.
        /// </summary>
        /// <param name="decompiler">The decompiler to use during the melting process.</param>
        /// <param name="id">The Id to use for the ComponentGroup, DirectoryRef, and WixVariables. If null, defaults to the Module's Id</param>
        public Melter(Decompiler decompiler, string id)
        {
            this.core = new MelterCore(this.Message);

            this.componentGroup      = new Wix.ComponentGroup();
            this.fragment            = new Wix.Fragment();
            this.primaryDirectoryRef = new Wix.DirectoryRef();

            this.decompiler = decompiler;
            this.id         = id;

            if (null == this.decompiler)
            {
                this.core.OnMessage(WixErrors.ExpectedDecompiler("The melting process"));
            }
        }
Example #13
0
        /// <summary>
        /// Creates a new melter object.
        /// </summary>
        /// <param name="decompiler">The decompiler to use during the melting process.</param>
        /// <param name="id">The Id to use for the ComponentGroup, DirectoryRef, and WixVariables. If null, defaults to the Module's Id</param>
        public Melter(Decompiler decompiler, string id)
        {
            this.core = new MelterCore(this.Message);

            this.componentGroup = new Wix.ComponentGroup();
            this.fragment = new Wix.Fragment();
            this.primaryDirectoryRef = new Wix.DirectoryRef();

            this.decompiler = decompiler;
            this.id = id;

            if (null == this.decompiler)
            {
                this.core.OnMessage(WixErrors.ExpectedDecompiler("The melting process"));
            }
        }
Example #14
0
        /// <summary>
        /// Harvest a payload.
        /// </summary>
        /// <param name="argument">The path of the payload.</param>
        /// <returns>A harvested payload.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            string fullPath = Path.GetFullPath(argument);

            Wix.RemotePayload remotePayload = this.HarvestRemotePayload(fullPath);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(remotePayload);

            return(new Wix.Fragment[] { fragment });
        }
Example #15
0
        /// <summary>
        /// Harvest a payload.
        /// </summary>
        /// <param name="argument">The path of the payload.</param>
        /// <returns>A harvested payload.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }
            
            string fullPath = Path.GetFullPath(argument);

            Wix.RemotePayload remotePayload = this.HarvestRemotePayload(fullPath);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(remotePayload);

            return new Wix.Fragment[] { fragment };
        }
Example #16
0
        /// <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);
        }
Example #17
0
        /// <summary>
        /// Harvest a WiX document.
        /// </summary>
        /// <param name="argument">The argument for harvesting.</param>
        /// <returns>The harvested Fragment.</returns>
        public override Wix.Fragment Harvest(string argument)
        {
            Wix.Component component = new Wix.Component();
            component.AddChild(new Wix.CreateFolder());

            Wix.Fragment fragment = new Wix.Fragment();

            // Add in any CAB\DLL\OCX pre-processing here.

            // get the Internet Component Download type
            if (argument.StartsWith("ocx:") || argument.StartsWith("dll:"))
            {
                fragment = this.HarvestDll(fragment, argument.Substring(4));
            }
            else if (argument.StartsWith("cab:"))
            {
                fragment = this.HarvestCab(fragment, argument.Substring(4));
            }

            return(fragment);
        }
        /// <summary>
        /// Harvest a WiX document.
        /// </summary>
        /// <param name="argument">The argument for harvesting.</param>
        /// <returns>The harvested Fragment.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            DirectoryHarvester directoryHarvester = new DirectoryHarvester();
            directoryHarvester.Core = this.Core;
            directoryHarvester.KeepEmptyDirectories = true;

            IIsWebSiteHarvester iisWebSiteHarvester = new IIsWebSiteHarvester();
            iisWebSiteHarvester.Core = this.Core;

            IIs.WebSite webSite = iisWebSiteHarvester.HarvestWebSite(argument);

            Wix.Component component = new Wix.Component();
            component.AddChild(new Wix.CreateFolder());
            component.AddChild(webSite);

            this.Core.RootDirectory = webSite.Directory;
            Wix.Directory directory = directoryHarvester.HarvestDirectory(webSite.Directory, true);
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return new Wix.Fragment[] { fragment };
        }
Example #19
0
        /// <summary>
        /// Harvest a performance category.
        /// </summary>
        /// <param name="argument">The name of the performance category.</param>
        /// <returns>A harvested performance category.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Util.PerformanceCategory perf = this.HarvestPerformanceCategory(argument);

            Wix.Component component = new Wix.Component();
            component.Id      = CompilerCore.GetIdentifierFromName(argument);
            component.KeyPath = Wix.YesNoType.yes;
            component.AddChild(perf);

            Wix.Directory directory = new Wix.Directory();
            directory.Id = "TARGETDIR";
            //directory.Name = directory.Id;
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return(new Wix.Fragment[] { fragment });
        }
        /// <summary>
        /// Harvest a performance category.
        /// </summary>
        /// <param name="argument">The name of the performance category.</param>
        /// <returns>A harvested performance category.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Util.PerformanceCategory perf = this.HarvestPerformanceCategory(argument);

            Wix.Component component = new Wix.Component();
            component.Id = CompilerCore.GetIdentifierFromName(argument);
            component.KeyPath = Wix.YesNoType.yes;
            component.AddChild(perf);

            Wix.Directory directory = new Wix.Directory();
            directory.Id = "TARGETDIR";
            //directory.Name = directory.Id;
            directory.AddChild(component);

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return new Wix.Fragment[] { fragment };
        }
Example #21
0
        /// <summary>
        /// Harvest a file.
        /// </summary>
        /// <param name="argument">The path of the file.</param>
        /// <returns>A harvested file.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            if (null == this.rootedDirectoryRef)
            {
                this.rootedDirectoryRef = "TARGETDIR";
            }

            string fullPath = Path.GetFullPath(argument);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = this.rootedDirectoryRef;

            Wix.File file = this.HarvestFile(fullPath);

            if (!this.suppressRootDirectory)
            {
                file.Source = String.Concat("SourceDir\\", Path.GetFileName(Path.GetDirectoryName(fullPath)), "\\", Path.GetFileName(fullPath));
            }

            Wix.Component component = new Wix.Component();
            component.AddChild(file);

            Wix.Directory directory = new Wix.Directory();

            if (this.suppressRootDirectory)
            {
                directoryRef.AddChild(component);
            }
            else
            {
                string directoryPath = Path.GetDirectoryName(Path.GetFullPath(argument));
                directory.Name = Path.GetFileName(directoryPath);

                if (this.setUniqueIdentifiers)
                {
                    directory.Id = this.Core.GenerateIdentifier(DirectoryPrefix, directoryRef.Id, directory.Name);
                }
                directory.AddChild(component);
                directoryRef.AddChild(directory);
            }

            if (this.setUniqueIdentifiers)
            {
                file.Id = this.Core.GenerateIdentifier(FilePrefix, (this.suppressRootDirectory) ? directoryRef.Id : directory.Id, Path.GetFileName(file.Source));
                component.Id = this.Core.GenerateIdentifier(ComponentPrefix, (this.suppressRootDirectory) ? directoryRef.Id : directory.Id, file.Id);
            }

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directoryRef);

            return new Wix.Fragment[] { fragment };
        }
Example #22
0
        /// <summary>
        /// Mutate the directories.
        /// </summary>
        private void MutateDirectories()
        {
            // assign all identifiers before fragmenting (because fragmenting requires them all to be present)
            if (this.setUniqueIdentifiers)
            {
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory");

                // index all the existing identifiers and names
                foreach (Wix.Directory directory in this.directories)
                {
                    if (null != directory.Id)
                    {
                        identifierGenerator.IndexExistingIdentifier(directory.Id);
                    }
                    else
                    {
                        identifierGenerator.IndexName(directory.Name);
                    }
                }

                foreach (Wix.Directory directory in this.directories)
                {
                    if (null == directory.Id)
                    {
                        directory.Id = identifierGenerator.GetIdentifier(directory.Name);
                    }
                }
            }

            foreach (Wix.Directory directory in this.directories)
            {
                if (this.createFragments)
                {
                    if (directory.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement;

                        // parent directory must have an identifier to create a reference to it
                        if (null == parentDirectory.Id)
                        {
                            return;
                        }

                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // create a new DirectoryRef
                        Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                        directoryRef.Id = parentDirectory.Id;
                        fragment.AddChild(directoryRef);

                        // move the Directory from the parent Directory to DirectoryRef
                        parentDirectory.RemoveChild(directory);
                        directoryRef.AddChild(directory);
                    }
                    else if (directory.ParentElement == this.rootElement)
                    {
                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // move the Directory from the root element to the Fragment
                        this.rootElement.RemoveChild(directory);
                        fragment.AddChild(directory);
                    }
                }
            }
        }
        /// <summary>
        /// Harvest a reg file.
        /// </summary>
        /// <param name="path">The path of the file.</param>
        /// <returns>A harvested registy file.</returns>
        public Wix.Fragment HarvestRegFile(string path)
        {
            if (null == path)
            {
                throw new ArgumentNullException("path");
            }

            if (!File.Exists(path))
            {
                throw new WixException(UtilErrors.FileNotFound(path));
            }

            Wix.Directory directory = new Wix.Directory();
            directory.Id = "TARGETDIR";

            // Use absolute paths
            path = Path.GetFullPath(path);
            FileInfo file = new FileInfo(path);

            using (StreamReader sr = file.OpenText())
            {
                string line;
                this.currentLineNumber = 0;

                while (null != (line = this.GetNextLine(sr)))
                {
                    if (line.StartsWith(@"Windows Registry Editor Version 5.00"))
                    {
                        this.unicodeRegistry = true;
                    }
                    else if (line.StartsWith(@"REGEDIT4"))
                    {
                        this.unicodeRegistry = false;
                    }
                    else if (line.StartsWith(@"[HKEY_CLASSES_ROOT\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKCR, line.Substring(19, line.Length - 20));
                    }
                    else if (line.StartsWith(@"[HKEY_CURRENT_USER\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKCU, line.Substring(19, line.Length - 20));
                    }
                    else if (line.StartsWith(@"[HKEY_LOCAL_MACHINE\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKLM, line.Substring(20, line.Length - 21));
                    }
                    else if (line.StartsWith(@"[HKEY_USERS\"))
                    {
                        this.ConvertKey(sr, ref directory, Wix.RegistryRootType.HKU, line.Substring(12, line.Length - 13));
                    }
                }
            }

            Console.WriteLine("Processing complete");

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directory);

            return fragment;
        }
Example #24
0
        /// <summary>
        /// Mutate the components.
        /// </summary>
        private void MutateComponents()
        {
            IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component");

            if (TemplateType.Module == this.templateType)
            {
                identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
            }

            foreach (Wix.Component component in this.components)
            {
                if (null == component.Id)
                {
                    string firstFileId = string.Empty;

                    // attempt to create a possible identifier from the first file identifier in the component
                    foreach (Wix.File file in component[typeof(Wix.File)])
                    {
                        firstFileId = file.Id;
                        break;
                    }

                    if (string.IsNullOrEmpty(firstFileId))
                    {
                        firstFileId = GetGuid();
                    }

                    component.Id = identifierGenerator.GetIdentifier(firstFileId);
                }

                if (null == component.Guid)
                {
                    if (this.AutogenerateGuids)
                    {
                        component.Guid = "*";
                    }
                    else
                    {
                        component.Guid = this.GetGuid();
                    }
                }

                if (this.createFragments && component.ParentElement is Wix.Directory)
                {
                    Wix.Directory directory = (Wix.Directory)component.ParentElement;

                    // parent directory must have an identifier to create a reference to it
                    if (null == directory.Id)
                    {
                        break;
                    }

                    if (this.rootElement is Wix.Module)
                    {
                        // add a ComponentRef for the Component
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        this.rootElement.AddChild(componentRef);
                    }

                    // create a new Fragment
                    Wix.Fragment fragment = new Wix.Fragment();
                    this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment);

                    // create a new DirectoryRef
                    Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                    directoryRef.Id = directory.Id;
                    fragment.AddChild(directoryRef);

                    // move the Component from the the Directory to the DirectoryRef
                    directory.RemoveChild(component);
                    directoryRef.AddChild(component);
                }
            }
        }
Example #25
0
        /// <summary>
        /// Mutate the components.
        /// </summary>
        private void MutateComponents()
        {
            IdentifierGenerator identifierGenerator = null;

            if (this.setUniqueIdentifiers)
            {
                identifierGenerator = new IdentifierGenerator("Component");

                // index all the existing identifiers and names
                foreach (Wix.Component component in this.components)
                {
                    if (null != component.Id)
                    {
                        identifierGenerator.IndexExistingIdentifier(component.Id);
                    }
                    else
                    {
                        string firstFileId = string.Empty;

                        // attempt to create a possible identifier from the first file identifier in the component
                        foreach (Wix.File file in component[typeof(Wix.File)])
                        {
                            firstFileId = file.Id;
                            break;
                        }

                        identifierGenerator.IndexName(firstFileId);
                    }
                }
            }

            foreach (Wix.Component component in this.components)
            {
                if (this.setUniqueIdentifiers && null == component.Id)
                {
                    string firstFileId = string.Empty;

                    // attempt to create a possible identifier from the first file identifier in the component
                    foreach (Wix.File file in component[typeof(Wix.File)])
                    {
                        firstFileId = file.Id;
                        break;
                    }

                    component.Id = identifierGenerator.GetIdentifier(firstFileId);
                }

                if (null == component.Guid)
                {
                    component.Guid = this.GetGuid();
                }

                if (this.createFragments && component.ParentElement is Wix.Directory)
                {
                    Wix.Directory directory = (Wix.Directory)component.ParentElement;

                    // parent directory must have an identifier to create a reference to it
                    if (null == directory.Id)
                    {
                        break;
                    }

                    if (this.rootElement is Wix.Module)
                    {
                        // add a ComponentRef for the Component
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        this.rootElement.AddChild(componentRef);
                    }

                    // create a new Fragment
                    Wix.Fragment fragment = new Wix.Fragment();
                    this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment);

                    // create a new DirectoryRef
                    Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                    directoryRef.Id = directory.Id;
                    fragment.AddChild(directoryRef);

                    // move the Component from the the Directory to the DirectoryRef
                    directory.RemoveChild(component);
                    directoryRef.AddChild(component);
                }
            }
        }
Example #26
0
        /// <summary>
        /// Gets the directory object for the provided application root path.
        /// </summary>
        /// <param name="recalculate">Flag to recalculate root directory.</param>
        /// <returns>Directory harvested from root.</returns>
        public Wix.Directory GetRootDirectory(bool recalculate)
        {
            if (null == this.source)
            {
                throw new ArgumentNullException("RootPath");
            }

            if (recalculate || null == this.rootDirectory)
            {
                DirectoryHarvester directoryHarvester = new DirectoryHarvester();
                this.rootDirectory = directoryHarvester.HarvestDirectory(this.source, true);

                Wix.Wix wix = new Wix.Wix();
                Wix.Fragment fragment = new Wix.Fragment();
                wix.AddChild(fragment);
                fragment.AddChild(this.rootDirectory);

                UtilMutator utilMutator = new UtilMutator();
                utilMutator.GenerateGuids = true;
                utilMutator.SetUniqueIdentifiers = true;
                utilMutator.Mutate(wix);

                UtilFinalizeHarvesterMutator finalMutator = new UtilFinalizeHarvesterMutator();
                finalMutator.Mutate(wix);
            }

            return this.rootDirectory;
        }
Example #27
0
        /// <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;
        }
Example #28
0
        /// <summary>
        /// Harvest a directory.
        /// </summary>
        /// <param name="argument">The path of the directory.</param>
        /// <returns>The harvested directory.</returns>
        public override Wix.Fragment[] Harvest(string argument)
        {
            if (null == argument)
            {
                throw new ArgumentNullException("argument");
            }

            Wix.Directory directory = this.HarvestDirectory(argument, "SourceDir\\", true);

            Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
            directoryRef.Id = this.rootedDirectoryRef;

            if (this.suppressRootDirectory)
            {
                foreach (Wix.ISchemaElement element in directory.Children)
                {
                    directoryRef.AddChild(element);
                }
            }
            else
            {
                directoryRef.AddChild(directory);
            }

            Wix.Fragment fragment = new Wix.Fragment();
            fragment.AddChild(directoryRef);

            return new Wix.Fragment[] { fragment };
        }
Example #29
0
        /// <summary>
        /// Creates WiX fragments for files in one output group.
        /// </summary>
        /// <param name="projectFile">VS MSBuild project file.</param>
        /// <param name="buildOutputs">Dictionary of build outputs retrieved from an MSBuild run on the project file.</param>
        /// <param name="pog">Project output group parameters.</param>
        /// <param name="fragmentList">List to which generated fragments will be added.</param>
        /// <returns>Count of harvested files.</returns>
        private int HarvestProjectOutputGroup(string projectFile, IDictionary buildOutputs, ProjectOutputGroup pog, IList fragmentList)
        {
            string projectName = Path.GetFileNameWithoutExtension(projectFile);
            string projectBaseDir = null;

            if (this.ProjectName != null)
            {
                projectName = this.ProjectName;
            }

            string sanitizedProjectName = HarvesterCore.GetIdentifierFromName(projectName);

            Wix.IParentElement harvestParent;

            if (this.GenerateType == GenerateType.Container)
            {
                Wix.Container container = new Wix.Container();
                harvestParent = container;

                container.Name = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
            }
            else if (this.GenerateType == GenerateType.PayloadGroup)
            {
                Wix.PayloadGroup container = new Wix.PayloadGroup();
                harvestParent = container;

                container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
            }
            else if (this.GenerateType == GenerateType.PackageGroup)
            {
                Wix.PackageGroup container = new Wix.PackageGroup();
                harvestParent = container;

                container.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
            }
            else
            {
                Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                harvestParent = directoryRef;

                if (!String.IsNullOrEmpty(this.directoryIds))
                {
                    directoryRef.Id = this.directoryIds;
                }
                else if (this.setUniqueIdentifiers)
                {
                    directoryRef.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
                }
                else
                {
                    directoryRef.Id = HarvesterCore.GetIdentifierFromName(String.Format(CultureInfo.InvariantCulture, VSProjectHarvester.DirectoryIdFormat, sanitizedProjectName, pog.Name));
                }

                this.directoryRefSeed = this.Core.GenerateIdentifier(DirectoryPrefix, this.projectGUID, pog.Name);
            }

            IEnumerable pogFiles = buildOutputs[pog.BuildOutputGroup] as IEnumerable;
            if (pogFiles == null)
            {
                throw new WixException(VSErrors.MissingProjectOutputGroup(
                    projectFile, pog.BuildOutputGroup));
            }

            if (pog.FileSource == "ProjectDir")
            {
                projectBaseDir = Path.GetDirectoryName(projectFile) + "\\";
            }

            int harvestCount = this.HarvestProjectOutputGroupFiles(projectBaseDir, projectName, pog.Name, pog.FileSource, pogFiles, harvestParent);

            if (this.GenerateType == GenerateType.Container)
            {
                // harvestParent must be a Container at this point
                Wix.Container container = harvestParent as Wix.Container;

                Wix.Fragment fragment = new Wix.Fragment();
                fragment.AddChild(container);
                fragmentList.Add(fragment);
            }
            else if (this.GenerateType == GenerateType.PackageGroup)
            {
                // harvestParent must be a PackageGroup at this point
                Wix.PackageGroup packageGroup = harvestParent as Wix.PackageGroup;

                Wix.Fragment fragment = new Wix.Fragment();
                fragment.AddChild(packageGroup);
                fragmentList.Add(fragment);
            }
            else if (this.GenerateType == GenerateType.PayloadGroup)
            {
                // harvestParent must be a Container at this point
                Wix.PayloadGroup payloadGroup = harvestParent as Wix.PayloadGroup;

                Wix.Fragment fragment = new Wix.Fragment();
                fragment.AddChild(payloadGroup);
                fragmentList.Add(fragment);
            }
            else
            {
                // harvestParent must be a DirectoryRef at this point
                Wix.DirectoryRef directoryRef = harvestParent as Wix.DirectoryRef;

                if (harvestCount > 0)
                {
                    Wix.Fragment drf = new Wix.Fragment();
                    drf.AddChild(directoryRef);
                    fragmentList.Add(drf);
                }

                Wix.ComponentGroup cg = new Wix.ComponentGroup();

                if (this.setUniqueIdentifiers || !String.IsNullOrEmpty(this.directoryIds))
                {
                    cg.Id = String.Format(CultureInfo.InvariantCulture, DirectoryIdFormat, sanitizedProjectName, pog.Name);
                }
                else
                {
                    cg.Id = directoryRef.Id;
                }

                if (harvestCount > 0)
                {
                    this.AddComponentsToComponentGroup(directoryRef, cg);
                }

                Wix.Fragment cgf = new Wix.Fragment();
                cgf.AddChild(cg);
                fragmentList.Add(cgf);
            }

            return harvestCount;
        }
Example #30
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);
                }
            }
        }
Example #31
0
        /// <summary>
        /// Mutate the components.
        /// </summary>
        private void MutateComponents()
        {
            IdentifierGenerator identifierGenerator = new IdentifierGenerator("Component");
            if (TemplateType.Module == this.templateType)
            {
                identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
            }

            foreach (Wix.Component component in this.components)
            {
                if (null == component.Id)
                {
                    string firstFileId = string.Empty;

                    // attempt to create a possible identifier from the first file identifier in the component
                    foreach (Wix.File file in component[typeof(Wix.File)])
                    {
                        firstFileId = file.Id;
                        break;
                    }

                    if (string.IsNullOrEmpty(firstFileId))
                    {
                        firstFileId = GetGuid();
                    }

                    component.Id = identifierGenerator.GetIdentifier(firstFileId);
                }

                if (null == component.Guid)
                {
                    if (this.AutogenerateGuids)
                    {
                        component.Guid = "*";
                    }
                    else
                    {
                        component.Guid = this.GetGuid();
                    }
                }

                if (this.createFragments && component.ParentElement is Wix.Directory)
                {
                    Wix.Directory directory = (Wix.Directory)component.ParentElement;

                    // parent directory must have an identifier to create a reference to it
                    if (null == directory.Id)
                    {
                        break;
                    }

                    if (this.rootElement is Wix.Module)
                    {
                        // add a ComponentRef for the Component
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        this.rootElement.AddChild(componentRef);
                    }

                    // create a new Fragment
                    Wix.Fragment fragment = new Wix.Fragment();
                    this.fragments.Add(String.Concat("Component:", (null != component.Id ? component.Id : this.fragments.Count.ToString())), fragment);

                    // create a new DirectoryRef
                    Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                    directoryRef.Id = directory.Id;
                    fragment.AddChild(directoryRef);

                    // move the Component from the the Directory to the DirectoryRef
                    directory.RemoveChild(component);
                    directoryRef.AddChild(component);
                }
            }
        }
Example #32
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);
                }
            }
        }
Example #33
0
        /// <summary>
        /// Mutate the directories.
        /// </summary>
        private void MutateDirectories()
        {
            if (!this.setUniqueIdentifiers)
            {
                // assign all identifiers before fragmenting (because fragmenting requires them all to be present)
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory");
                if (TemplateType.Module == this.templateType)
                {
                    identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
                }

                foreach (Wix.Directory directory in this.directories)
                {
                    if (null == directory.Id)
                    {
                        directory.Id = identifierGenerator.GetIdentifier(directory.Name);
                    }
                }
            }

            if (this.createFragments)
            {
                foreach (Wix.Directory directory in this.directories)
                {
                    if (directory.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement;

                        // parent directory must have an identifier to create a reference to it
                        if (null == parentDirectory.Id)
                        {
                            return;
                        }

                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // create a new DirectoryRef
                        Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                        directoryRef.Id = parentDirectory.Id;
                        fragment.AddChild(directoryRef);

                        // move the Directory from the parent Directory to DirectoryRef
                        parentDirectory.RemoveChild(directory);
                        directoryRef.AddChild(directory);
                    }
                    else if (directory.ParentElement is Wix.Fragment)
                    {
                        // When creating fragments, remove any top-level Directory elements;
                        // the fragments should be pulled in by their DirectoryRefs instead.
                        Wix.Fragment parent = (Wix.Fragment)directory.ParentElement;
                        parent.RemoveChild(directory);

                        // Remove the fragment if it is empty.
                        if (parent.Children.GetEnumerator().Current == null && parent.ParentElement != null)
                        {
                            ((Wix.IParentElement)parent.ParentElement).RemoveChild(parent);
                        }
                    }
                    else if (directory.ParentElement == this.rootElement)
                    {
                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // move the Directory from the root element to the Fragment
                        this.rootElement.RemoveChild(directory);
                        fragment.AddChild(directory);
                    }
                }
            }
        }
Example #34
0
        /// <summary>
        /// Mutate the directories.
        /// </summary>
        private void MutateDirectories()
        {
            if (!this.setUniqueIdentifiers)
            {
                // assign all identifiers before fragmenting (because fragmenting requires them all to be present)
                IdentifierGenerator identifierGenerator = new IdentifierGenerator("Directory");
                if (TemplateType.Module == this.templateType)
                {
                    identifierGenerator.MaxIdentifierLength = IdentifierGenerator.MaxModuleIdentifierLength;
                }

                foreach (Wix.Directory directory in this.directories)
                {
                    if (null == directory.Id)
                    {
                        directory.Id = identifierGenerator.GetIdentifier(directory.Name);
                    }
                }
            }

            if (this.createFragments)
            {
                foreach (Wix.Directory directory in this.directories)
                {
                    if (directory.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = (Wix.Directory)directory.ParentElement;

                        // parent directory must have an identifier to create a reference to it
                        if (null == parentDirectory.Id)
                        {
                            return;
                        }

                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // create a new DirectoryRef
                        Wix.DirectoryRef directoryRef = new Wix.DirectoryRef();
                        directoryRef.Id = parentDirectory.Id;
                        fragment.AddChild(directoryRef);

                        // move the Directory from the parent Directory to DirectoryRef
                        parentDirectory.RemoveChild(directory);
                        directoryRef.AddChild(directory);
                    }
                    else if (directory.ParentElement is Wix.Fragment)
                    {
                        // When creating fragments, remove any top-level Directory elements;
                        // the fragments should be pulled in by their DirectoryRefs instead.
                        Wix.Fragment parent = (Wix.Fragment)directory.ParentElement;
                        parent.RemoveChild(directory);

                        // Remove the fragment if it is empty.
                        if (parent.Children.GetEnumerator().Current == null && parent.ParentElement != null)
                        {
                            ((Wix.IParentElement)parent.ParentElement).RemoveChild(parent);
                        }
                    }
                    else if (directory.ParentElement == this.rootElement)
                    {
                        // create a new Fragment
                        Wix.Fragment fragment = new Wix.Fragment();
                        this.fragments.Add(String.Concat("Directory:", ("TARGETDIR" == directory.Id ? null : (null != directory.Id ? directory.Id : this.fragments.Count.ToString()))), fragment);

                        // move the Directory from the root element to the Fragment
                        this.rootElement.RemoveChild(directory);
                        fragment.AddChild(directory);
                    }
                }
            }
        }
Example #35
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();

            // 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.Component component in this.components)
                {
                    if (null != component.Id)
                    {
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        feature.AddChild(componentRef);
                    }
                }
            }
            // create a ComponentGroup with all the components
            else if (TemplateType.Fragment == this.templateType && !this.createFragments)
            {
                Wix.ComponentGroup componentGroup = new Wix.ComponentGroup();
                componentGroup.Id = "ComponentGroup1";

                foreach (Wix.Component component in this.components)
                {
                    if (null != component.Id)
                    {
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        componentGroup.AddChild(componentRef);
                    }
                }

                Wix.Fragment fragment = new Wix.Fragment();
                this.fragments.Add("ComponentGroup:1", fragment);
                fragment.AddChild(componentGroup);
            }

            foreach (Wix.Fragment fragment in this.fragments.Values)
            {
                wix.AddChild(fragment);
            }
        }