private static IDictionary <string, string> GatherPreprocessorVariables(IEnumerable <string> defineConstants) { var variables = new Dictionary <string, string>(); foreach (var pair in defineConstants) { string[] value = pair.Split(new[] { '=' }, 2); if (variables.ContainsKey(value[0])) { Messaging.Instance.OnMessage(WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], variables[value[0]])); continue; } variables.Add(value[0], (1 == value.Length) ? String.Empty : value[1]); } return(variables); }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> private void ParseCommandLine(string[] args) { for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (null == arg || 0 == arg.Length) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { this.sourceFiles.AddRange(AppCommon.GetFiles(arg, "Source")); continue; } if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ("allowPerSourceOutputSpecification" == parameter) { // This is a *long* parameter name; but we want it to be painful because it's // non-standard and we don't really want to have it at all. this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("allowPerSourceOutputSpecification")); this.allowPerSourceOutputSpecification = true; } else if ('d' == parameter[0]) { if (1 >= parameter.Length || '=' == parameter[1]) { this.messageHandler.Display(this, WixErrors.InvalidVariableDefinition(arg)); return; } parameter = arg.Substring(2); string[] value = parameter.Split("=".ToCharArray(), 2); if (this.parameters.ContainsKey(value[0])) { this.messageHandler.Display(this, WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], (string)this.parameters[value[0]])); return; } if (1 == value.Length) { this.parameters.Add(value[0], String.Empty); } else { this.parameters.Add(value[0], value[1]); } } else if ("fips" == parameter) { this.fipsCompliant = true; } else if ('I' == parameter[0]) { this.includeSearchPaths.Add(parameter.Substring(1)); } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.TypeSpecificationForExtensionRequired("-ext")); return; } else { this.extensionList.Add(args[i]); } } else if ("nologo" == parameter) { this.showLogo = false; } else if ("o" == parameter || "out" == parameter) { string path = CommandLine.GetFileOrDirectory(parameter, this.messageHandler, args, ++i); if (!String.IsNullOrEmpty(path)) { if (path.EndsWith("\\", StringComparison.Ordinal) || path.EndsWith("/", StringComparison.Ordinal)) { this.outputDirectory = path; } else { this.outputFile = path; } } else { return; } } else if ("pedantic" == parameter) { this.showPedanticMessages = true; } else if ("platform" == parameter || "arch" == parameter) { if ("platform" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("platform", "arch")); } if (!CommandLine.IsValidArg(args, ++i)) { this.messageHandler.Display(this, WixErrors.InvalidPlatformParameter(parameter, String.Empty)); return; } if (String.Equals(args[i], "intel", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "x86", StringComparison.OrdinalIgnoreCase)) { this.platform = Platform.X86; } else if (String.Equals(args[i], "x64", StringComparison.OrdinalIgnoreCase)) { this.platform = Platform.X64; } else if (String.Equals(args[i], "intel64", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "ia64", StringComparison.OrdinalIgnoreCase)) { this.platform = Platform.IA64; } else { this.messageHandler.Display(this, WixErrors.InvalidPlatformParameter(parameter, args[i])); } } else if ('p' == parameter[0]) { String file = arg.Substring(2); this.preprocessFile = file; this.preprocessToStdout = (0 == file.Length); } else if ("sfdvital" == parameter) { this.suppressFilesVitalByDefault = true; } else if ("ss" == parameter) { this.suppressSchema = true; } else if ("swall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("swall", "sw")); this.messageHandler.SuppressAllWarnings = true; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } this.messageHandler.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalSuppressWarningId(paramArg)); } } else if ("wxall" == parameter) { this.messageHandler.Display(this, WixWarnings.DeprecatedCommandLineSwitch("wxall", "wx")); this.messageHandler.WarningAsError = true; } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { this.messageHandler.WarningAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } this.messageHandler.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { this.messageHandler.Display(this, WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("trace" == parameter) { this.messageHandler.SourceTrace = true; } else if ("v" == parameter) { this.messageHandler.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.showHelp = true; return; } else { this.invalidArgs.Add(parameter); } } else if ('@' == arg[0]) { this.ParseCommandLine(CommandLineResponseFile.Parse(arg.Substring(1))); } else { string sourceArg = arg; string targetArg = null; if (this.allowPerSourceOutputSpecification) { string[] parts = arg.Split(Candle.sourceOutputSeparator, 2); if (2 == parts.Length) { sourceArg = parts[0]; targetArg = parts[1]; } } string[] files = AppCommon.GetFiles(sourceArg, "Source"); if (this.allowPerSourceOutputSpecification && null != targetArg) { // files should contain only one item! if (1 < files.Length) { string sourceList = CompilerCore.CreateValueList(ValueListKind.None, files); this.messageHandler.Display(this, WixErrors.MultipleFilesMatchedWithOutputSpecification(arg, sourceList)); } else { this.sourceFiles.Add(string.Concat(files[0], Candle.sourceOutputSeparator[0], targetArg)); } } else { this.sourceFiles.AddRange(files); } } } return; }
/// <summary> /// Parse the commandline arguments. /// </summary> /// <param name="args">Commandline arguments.</param> public string[] Parse(string[] args) { List <string> unprocessed = new List <string>(); for (int i = 0; i < args.Length; ++i) { string arg = args[i]; if (String.IsNullOrEmpty(arg)) // skip blank arguments { continue; } if (1 == arg.Length) // treat '-' and '@' as filenames when by themselves. { unprocessed.Add(arg); } else if ('-' == arg[0] || '/' == arg[0]) { string parameter = arg.Substring(1); if ('d' == parameter[0]) { if (1 >= parameter.Length || '=' == parameter[1]) { Messaging.Instance.OnMessage(WixErrors.InvalidVariableDefinition(arg)); break; } parameter = arg.Substring(2); string[] value = parameter.Split("=".ToCharArray(), 2); if (this.PreprocessorVariables.ContainsKey(value[0])) { Messaging.Instance.OnMessage(WixErrors.DuplicateVariableDefinition(value[0], (1 == value.Length) ? String.Empty : value[1], this.PreprocessorVariables[value[0]])); break; } if (1 == value.Length) { this.PreprocessorVariables.Add(value[0], String.Empty); } else { this.PreprocessorVariables.Add(value[0], value[1]); } } else if ('I' == parameter[0]) { this.IncludeSearchPaths.Add(parameter.Substring(1)); } else if ("ext" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.TypeSpecificationForExtensionRequired("-ext")); break; } else { this.Extensions.Add(args[i]); } } else if ("nologo" == parameter) { this.ShowLogo = false; } else if ("o" == parameter || "out" == parameter) { string path = CommandLine.GetFileOrDirectory(parameter, args, ++i); if (!String.IsNullOrEmpty(path)) { if (path.EndsWith("\\", StringComparison.Ordinal) || path.EndsWith("/", StringComparison.Ordinal)) { this.OutputFolder = path; } else { this.OutputFile = path; } } else { break; } } else if ("pedantic" == parameter) { this.ShowPedanticMessages = true; } else if ("arch" == parameter) { if (!CommandLine.IsValidArg(args, ++i)) { Messaging.Instance.OnMessage(WixErrors.InvalidPlatformParameter(parameter, String.Empty)); break; } if (String.Equals(args[i], "intel", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "x86", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.X86; } else if (String.Equals(args[i], "x64", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.X64; } else if (String.Equals(args[i], "intel64", StringComparison.OrdinalIgnoreCase) || String.Equals(args[i], "ia64", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.IA64; } else if (String.Equals(args[i], "arm", StringComparison.OrdinalIgnoreCase)) { this.Platform = Platform.ARM; } else { Messaging.Instance.OnMessage(WixErrors.InvalidPlatformParameter(parameter, args[i])); } } else if ('p' == parameter[0]) { string file = parameter.Substring(1); this.PreprocessFile = String.IsNullOrEmpty(file) ? "con:" : file; } else if (parameter.StartsWith("sw", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { Messaging.Instance.SuppressAllWarnings = true; } else { int suppressWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= suppressWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } Messaging.Instance.SuppressWarningMessage(suppressWarning); } } catch (FormatException) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } catch (OverflowException) { Messaging.Instance.OnMessage(WixErrors.IllegalSuppressWarningId(paramArg)); } } else if (parameter.StartsWith("wx", StringComparison.Ordinal)) { string paramArg = parameter.Substring(2); try { if (0 == paramArg.Length) { Messaging.Instance.WarningsAsError = true; } else { int elevateWarning = Convert.ToInt32(paramArg, CultureInfo.InvariantCulture.NumberFormat); if (0 >= elevateWarning) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } Messaging.Instance.ElevateWarningMessage(elevateWarning); } } catch (FormatException) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } catch (OverflowException) { Messaging.Instance.OnMessage(WixErrors.IllegalWarningIdAsError(paramArg)); } } else if ("v" == parameter) { Messaging.Instance.ShowVerboseMessages = true; } else if ("?" == parameter || "help" == parameter) { this.ShowHelp = true; break; } else { unprocessed.Add(arg); } } else if ('@' == arg[0]) { string[] parsedArgs = CommandLineResponseFile.Parse(arg.Substring(1)); string[] unparsedArgs = this.Parse(parsedArgs); unprocessed.AddRange(unparsedArgs); } else { unprocessed.Add(arg); } } return(unprocessed.ToArray()); }