/// <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; HarvesterExtension harvesterExtension = null; bool suppressHarvestingRegistryValues = false; UtilFinalizeHarvesterMutator utilFinalizeHarvesterMutator = new UtilFinalizeHarvesterMutator(); UtilMutator utilMutator = new UtilMutator(); // select the harvester switch (type) { case "dir": harvesterExtension = new DirectoryHarvester(); active = true; break; case "file": harvesterExtension = new FileHarvester(); active = true; break; } // set default settings utilMutator.CreateFragments = true; utilMutator.SetUniqueIdentifiers = true; // parse the options foreach (string arg in args) { if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("gg" == parameter) { utilMutator.GenerateGuids = true; } else if ("ke" == parameter) { if (harvesterExtension is DirectoryHarvester) { ((DirectoryHarvester)harvesterExtension).KeepEmptyDirectories = true; } else if (active) { // TODO: error message - not applicable to file harvester } } else if ("scom" == parameter) { if (active) { utilFinalizeHarvesterMutator.SuppressCOMElements = true; } else { // TODO: error message - not applicable } } else if ("sfrag" == parameter) { utilMutator.CreateFragments = false; } else if ("sreg" == parameter) { suppressHarvestingRegistryValues = true; } else if ("suid" == parameter) { utilMutator.SetUniqueIdentifiers = false; } else if (parameter.StartsWith("template:")) { switch (parameter.Substring(9)) { case "fragment": utilMutator.TemplateType = TemplateType.Fragment; break; case "module": utilMutator.TemplateType = TemplateType.Module; break; case "product": utilMutator.TemplateType = TemplateType.Product; break; default: // TODO: error break; } } } } // 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); } // set the mutator this.Core.Mutator.AddExtension(utilMutator); }
/// <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; HarvesterExtension harvesterExtension = null; bool suppressHarvestingRegistryValues = false; UtilFinalizeHarvesterMutator utilFinalizeHarvesterMutator = new UtilFinalizeHarvesterMutator(); UtilMutator utilMutator = new UtilMutator(); List<UtilTransformMutator> transformMutators = new List<UtilTransformMutator>(); // select the harvester switch (type) { case "dir": harvesterExtension = new DirectoryHarvester(); active = true; break; case "file": harvesterExtension = new FileHarvester(); active = true; break; case "payload": harvesterExtension = new PayloadHarvester(); 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.EncounteredError) { return; } } else if ("dr" == truncatedCommandSwitch) { string dr = this.GetArgumentParameter(args, i); if (this.Core.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.OnMessage(WixWarnings.DeprecatedCommandLineSwitch("t:", "t")); xslFile = truncatedCommandSwitch.Substring(2); } else { xslFile = this.GetArgumentParameter(args, i, true); } if (0 <= xslFile.IndexOf('\"')) { this.Core.OnMessage(WixErrors.PathCannotContainQuote(xslFile)); return; } try { xslFile = Path.GetFullPath(xslFile); } catch (Exception e) { this.Core.OnMessage(WixErrors.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.OnMessage(WixWarnings.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.Product; break; default: // TODO: error break; } } else if ("var" == truncatedCommandSwitch) { if (active) { utilFinalizeHarvesterMutator.PreprocessorVariable = this.GetArgumentParameter(args, i); if (this.Core.EncounteredError) { return; } } } } } // 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) { 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); } }
/// <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; HarvesterExtension harvesterExtension = null; bool suppressHarvestingRegistryValues = false; UtilFinalizeHarvesterMutator utilFinalizeHarvesterMutator = new UtilFinalizeHarvesterMutator(); UtilMutator utilMutator = new UtilMutator(); List <UtilTransformMutator> transformMutators = new List <UtilTransformMutator>(); // select the harvester switch (type) { case "dir": harvesterExtension = new DirectoryHarvester(); active = true; break; case "file": harvesterExtension = new FileHarvester(); active = true; break; case "payload": harvesterExtension = new PayloadHarvester(); 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.EncounteredError) { return; } } else if ("dr" == truncatedCommandSwitch) { string dr = this.GetArgumentParameter(args, i); if (this.Core.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.OnMessage(WixWarnings.DeprecatedCommandLineSwitch("t:", "t")); xslFile = truncatedCommandSwitch.Substring(2); } else { xslFile = this.GetArgumentParameter(args, i, true); } if (0 <= xslFile.IndexOf('\"')) { this.Core.OnMessage(WixErrors.PathCannotContainQuote(xslFile)); return; } try { xslFile = Path.GetFullPath(xslFile); } catch (Exception e) { this.Core.OnMessage(WixErrors.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.OnMessage(WixWarnings.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.Product; break; default: // TODO: error break; } } else if ("var" == truncatedCommandSwitch) { if (active) { utilFinalizeHarvesterMutator.PreprocessorVariable = this.GetArgumentParameter(args, i); if (this.Core.EncounteredError) { return; } } } } } // 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) { 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); } }
/// <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(); }