/// <summary>
        /// Gets the directory object for the provided application root path.
        /// </summary>
        /// <param name="recalculate">Recalculate root directory.</param>
        /// <returns>Directory for root.</returns>
        public Wix.Directory GetRootDirectory(bool recalculate)
        {
            if (null == this.source)
            {
                throw new ArgumentNullException("Source");
            }

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

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

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

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

            return(this.rootDirectory);
        }
Example #2
0
        /// <summary>
        /// Creates a new package builder
        /// </summary>
        public PackageBuilder()
        {
            this.applicationName  = new Serialize.Name();
            this.applicationRoot  = new Serialize.Source();
            this.applicationEntry = new Serialize.EntryPoint();
            this.icon             = new Serialize.Icon();

            this.manufacturerName = new Serialize.Manufacturer();
            this.description      = new Serialize.Description();

            this.upgradeCode = Guid.Empty;

            this.directoryHarvester               = new DirectoryHarvester();
            this.utilMutator                      = new UtilMutator();
            this.utilMutator.GenerateGuids        = true;
            this.utilMutator.SetUniqueIdentifiers = true;
            this.finalMutator                     = new UtilFinalizeHarvesterMutator();
        }
Example #3
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 #4
0
        /// <summary>
        /// Parse the command line options for this extension.
        /// </summary>
        /// <param name="type">The active harvester type.</param>
        /// <param name="args">The option arguments.</param>
        public override void ParseOptions(string type, string[] args)
        {
            bool active = false;
            IHarvesterExtension harvesterExtension = null;
            bool suppressHarvestingRegistryValues  = false;
            UtilFinalizeHarvesterMutator utilFinalizeHarvesterMutator = new UtilFinalizeHarvesterMutator();
            UtilMutator utilMutator = new UtilMutator();
            List <UtilTransformMutator> transformMutators = new List <UtilTransformMutator>();
            GenerateType generateType = GenerateType.Components;

            // select the harvester
            switch (type)
            {
            case "dir":
                harvesterExtension = new DirectoryHarvester();
                active             = true;
                break;

            case "file":
                harvesterExtension = new FileHarvester();
                active             = true;
                break;

            case "exepackagepayload":
                harvesterExtension = new PayloadHarvester(this.PayloadHarvester, WixBundlePackageType.Exe);
                active             = true;
                break;

            case "msupackagepayload":
                harvesterExtension = new PayloadHarvester(this.PayloadHarvester, WixBundlePackageType.Msu);
                active             = true;
                break;

            case "perf":
                harvesterExtension = new PerformanceCategoryHarvester();
                active             = true;
                break;

            case "reg":
                harvesterExtension = new RegFileHarvester();
                active             = true;
                break;
            }

            // set default settings
            utilMutator.CreateFragments      = true;
            utilMutator.SetUniqueIdentifiers = true;

            // parse the options
            for (int i = 0; i < args.Length; i++)
            {
                string commandSwitch = args[i];

                if (null == commandSwitch || 0 == commandSwitch.Length) // skip blank arguments
                {
                    continue;
                }

                if ('-' == commandSwitch[0] || '/' == commandSwitch[0])
                {
                    string truncatedCommandSwitch = commandSwitch.Substring(1);

                    if ("ag" == truncatedCommandSwitch)
                    {
                        utilMutator.AutogenerateGuids = true;
                    }
                    else if ("cg" == truncatedCommandSwitch)
                    {
                        utilMutator.ComponentGroupName = this.GetArgumentParameter(args, i);

                        if (this.Core.Messaging.EncounteredError)
                        {
                            return;
                        }
                    }
                    else if ("dr" == truncatedCommandSwitch)
                    {
                        string dr = this.GetArgumentParameter(args, i);

                        if (this.Core.Messaging.EncounteredError)
                        {
                            return;
                        }

                        if (harvesterExtension is DirectoryHarvester)
                        {
                            ((DirectoryHarvester)harvesterExtension).RootedDirectoryRef = dr;
                        }
                        else if (harvesterExtension is FileHarvester)
                        {
                            ((FileHarvester)harvesterExtension).RootedDirectoryRef = dr;
                        }
                    }
                    else if ("gg" == truncatedCommandSwitch)
                    {
                        utilMutator.GenerateGuids = true;
                    }
                    else if ("g1" == truncatedCommandSwitch)
                    {
                        utilMutator.GuidFormat = "D";
                    }
                    else if ("ke" == truncatedCommandSwitch)
                    {
                        if (harvesterExtension is DirectoryHarvester)
                        {
                            ((DirectoryHarvester)harvesterExtension).KeepEmptyDirectories = true;
                        }
                        else if (active)
                        {
                            // TODO: error message - not applicable to file harvester
                        }
                    }
                    else if ("scom" == truncatedCommandSwitch)
                    {
                        if (active)
                        {
                            utilFinalizeHarvesterMutator.SuppressCOMElements = true;
                        }
                        else
                        {
                            // TODO: error message - not applicable
                        }
                    }
                    else if ("svb6" == truncatedCommandSwitch)
                    {
                        if (active)
                        {
                            utilFinalizeHarvesterMutator.SuppressVB6COMElements = true;
                        }
                        else
                        {
                            // TODO: error message - not applicable
                        }
                    }
                    else if ("sfrag" == truncatedCommandSwitch)
                    {
                        utilMutator.CreateFragments = false;
                    }
                    else if ("srd" == truncatedCommandSwitch)
                    {
                        if (harvesterExtension is DirectoryHarvester)
                        {
                            ((DirectoryHarvester)harvesterExtension).SuppressRootDirectory = true;
                        }
                        else if (harvesterExtension is FileHarvester)
                        {
                            ((FileHarvester)harvesterExtension).SuppressRootDirectory = true;
                        }
                    }
                    else if ("sreg" == truncatedCommandSwitch)
                    {
                        suppressHarvestingRegistryValues = true;
                    }
                    else if ("suid" == truncatedCommandSwitch)
                    {
                        utilMutator.SetUniqueIdentifiers = false;

                        if (harvesterExtension is DirectoryHarvester)
                        {
                            ((DirectoryHarvester)harvesterExtension).SetUniqueIdentifiers = false;
                        }
                        else if (harvesterExtension is FileHarvester)
                        {
                            ((FileHarvester)harvesterExtension).SetUniqueIdentifiers = false;
                        }
                    }
                    else if (truncatedCommandSwitch.StartsWith("t:", StringComparison.Ordinal) || "t" == truncatedCommandSwitch)
                    {
                        string xslFile;
                        if (truncatedCommandSwitch.StartsWith("t:", StringComparison.Ordinal))
                        {
                            this.Core.Messaging.Write(WarningMessages.DeprecatedCommandLineSwitch("t:", "t"));
                            xslFile = truncatedCommandSwitch.Substring(2);
                        }
                        else
                        {
                            xslFile = this.GetArgumentParameter(args, i, true);
                        }

                        if (0 <= xslFile.IndexOf('\"'))
                        {
                            this.Core.Messaging.Write(ErrorMessages.PathCannotContainQuote(xslFile));
                            return;
                        }

                        try
                        {
                            xslFile = Path.GetFullPath(xslFile);
                        }
                        catch (Exception e)
                        {
                            this.Core.Messaging.Write(ErrorMessages.InvalidCommandLineFileName(xslFile, e.Message));
                            return;
                        }

                        transformMutators.Add(new UtilTransformMutator(xslFile, transformMutators.Count));
                    }
                    else if (truncatedCommandSwitch.StartsWith("template:", StringComparison.Ordinal) || "template" == truncatedCommandSwitch)
                    {
                        string template;
                        if (truncatedCommandSwitch.StartsWith("template:", StringComparison.Ordinal))
                        {
                            this.Core.Messaging.Write(WarningMessages.DeprecatedCommandLineSwitch("template:", "template"));
                            template = truncatedCommandSwitch.Substring(9);
                        }
                        else
                        {
                            template = this.GetArgumentParameter(args, i);
                        }

                        switch (template)
                        {
                        case "fragment":
                            utilMutator.TemplateType = TemplateType.Fragment;
                            break;

                        case "module":
                            utilMutator.TemplateType = TemplateType.Module;
                            break;

                        case "product":
                            utilMutator.TemplateType = TemplateType.Package;
                            break;

                        default:
                            // TODO: error
                            break;
                        }
                    }
                    else if ("var" == truncatedCommandSwitch)
                    {
                        if (active)
                        {
                            utilFinalizeHarvesterMutator.PreprocessorVariable = this.GetArgumentParameter(args, i);

                            if (this.Core.Messaging.EncounteredError)
                            {
                                return;
                            }
                        }
                    }
                    else if ("generate" == truncatedCommandSwitch)
                    {
                        if (harvesterExtension is DirectoryHarvester)
                        {
                            string genType = this.GetArgumentParameter(args, i).ToUpperInvariant();
                            switch (genType)
                            {
                            case "COMPONENTS":
                                generateType = GenerateType.Components;
                                break;

                            case "PAYLOADGROUP":
                                generateType = GenerateType.PayloadGroup;
                                break;

                            default:
                                throw new WixException(HarvesterErrors.InvalidDirectoryOutputType(genType));
                            }
                        }
                        else
                        {
                            // TODO: error message - not applicable
                        }
                    }
                }
            }

            // set the appropriate harvester extension
            if (active)
            {
                this.Core.Harvester.Extension = harvesterExtension;

                if (!suppressHarvestingRegistryValues)
                {
                    this.Core.Mutator.AddExtension(new UtilHarvesterMutator());
                }

                this.Core.Mutator.AddExtension(utilFinalizeHarvesterMutator);

                if (harvesterExtension is DirectoryHarvester directoryHarvester)
                {
                    directoryHarvester.GenerateType        = generateType;
                    this.Core.Harvester.Core.RootDirectory = this.Core.Harvester.Core.ExtensionArgument;
                }
                else if (harvesterExtension is FileHarvester)
                {
                    if (((FileHarvester)harvesterExtension).SuppressRootDirectory)
                    {
                        this.Core.Harvester.Core.RootDirectory = Path.GetDirectoryName(Path.GetFullPath(this.Core.Harvester.Core.ExtensionArgument));
                    }
                    else
                    {
                        this.Core.Harvester.Core.RootDirectory = Path.GetDirectoryName(Path.GetDirectoryName(Path.GetFullPath(this.Core.Harvester.Core.ExtensionArgument)));

                        // GetDirectoryName() returns null for root paths such as "c:\", so make sure to support that as well
                        if (null == this.Core.Harvester.Core.RootDirectory)
                        {
                            this.Core.Harvester.Core.RootDirectory = Path.GetPathRoot(Path.GetDirectoryName(Path.GetFullPath(this.Core.Harvester.Core.ExtensionArgument)));
                        }
                    }
                }
            }

            // set the mutator
            this.Core.Mutator.AddExtension(utilMutator);

            // add the transforms
            foreach (UtilTransformMutator transformMutator in transformMutators)
            {
                this.Core.Mutator.AddExtension(transformMutator);
            }
        }