public ICommandLineCommand ParseWixCopCommandLine() { this.Parse(); if (this.showLogo) { AppCommon.DisplayToolHeader(); Console.WriteLine(); } if (this.showHelp) { return(new HelpCommand()); } return(new ConvertCommand( this.serviceProvider, this.showLogo, this.fixErrors, this.indentationAmount, this.searchPatterns, this.subDirectories, this.settingsFile1, this.settingsFile2)); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (Messaging.Instance.EncounteredError) { return(Messaging.Instance.LastErrorNumber); } if (!(String.IsNullOrEmpty(this.inputFile) ^ String.IsNullOrEmpty(this.outputFile))) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(RetinaStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(Messaging.Instance.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; if (!String.IsNullOrEmpty(this.inputFile)) { this.ExtractBinaryWixlibFiles(); } else { this.RebuildWixlib(); } } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); } catch (Exception e) { Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(Messaging.Instance.LastErrorNumber); }
/// <summary> /// Shows the help screen. /// </summary> /// <returns>Returns the last error found in the message handler.</returns> private int DisplayHelp() { AppCommon.DisplayToolHeader(); Console.WriteLine(HeatStrings.HelpMessageBegin); // output the harvest types alphabetically SortedList harvestOptions = new SortedList(); foreach (HeatExtension heatExtension in this.extensions) { foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes) { harvestOptions.Add(commandLineOption.Option, commandLineOption); } } harvestOptions.Add("-ext", new HeatCommandLineOption("-ext", HeatStrings.HelpMessageExtension)); harvestOptions.Add("-nologo", new HeatCommandLineOption("-nologo", HeatStrings.HelpMessageNoLogo)); harvestOptions.Add("-indent <N>", new HeatCommandLineOption("-indent <N>", HeatStrings.HelpMessageIndentation)); harvestOptions.Add("-o[ut]", new HeatCommandLineOption("-out", HeatStrings.HelpMessageOut)); harvestOptions.Add("-sw<N>", new HeatCommandLineOption("-sw<N>", HeatStrings.HelpMessageSuppressWarning)); harvestOptions.Add("-swall", new HeatCommandLineOption("-swall", HeatStrings.HelpMessageSuppressAllWarnings)); harvestOptions.Add("-v", new HeatCommandLineOption("-v", HeatStrings.HelpMessageVerbose)); harvestOptions.Add("-wx[N]", new HeatCommandLineOption("-wx[N]", HeatStrings.HelpMessageTreatWarningAsError)); harvestOptions.Add("-wxall", new HeatCommandLineOption("-wxall", HeatStrings.HelpMessageTreatAllWarningsAsErrors)); foreach (HeatCommandLineOption commandLineOption in harvestOptions.Values) { if (!commandLineOption.Option.StartsWith("-")) { Console.WriteLine(HeatStrings.HelpMessageOptionFormat, commandLineOption.Option, commandLineOption.Description); } } Console.WriteLine(); Console.WriteLine(HeatStrings.HelpMessageOptionHeading); foreach (HeatCommandLineOption commandLineOption in harvestOptions.Values) { if (commandLineOption.Option.StartsWith("-")) { Console.WriteLine(HeatStrings.HelpMessageOptionFormat, commandLineOption.Option, commandLineOption.Description); } } Console.WriteLine(HeatStrings.HelpMessageOptionFormat, "-? | -help", HeatStrings.HelpMessageThisHelpInfo); AppCommon.DisplayToolFooter(); return(Messaging.Instance.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> public int Run(IServiceProvider serviceProvider, IMessageListener listener, string[] args) { var messaging = serviceProvider.GetService <IMessaging>(); messaging.SetListener(listener); try { var unparsed = this.ParseCommandLineAndLoadExtensions(serviceProvider, messaging, args); if (!messaging.EncounteredError) { if (this.commandLine.ShowLogo) { AppCommon.DisplayToolHeader(); } if (this.commandLine.ShowHelp) { PrintHelp(); AppCommon.DisplayToolFooter(); } else { foreach (string arg in unparsed) { messaging.Write(WarningMessages.UnsupportedCommandLineArgument(arg)); } this.Bind(serviceProvider, messaging); } } } catch (WixException we) { messaging.Write(we.Error); } catch (Exception e) { messaging.Write(ErrorMessages.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(messaging.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Command-line arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { this.commandLine = new ThmGenCommandLine(); string[] unprocessed = commandLine.Parse(args); if (!Messaging.Instance.EncounteredError) { if (this.commandLine.ShowLogo) { AppCommon.DisplayToolHeader(); } if (this.commandLine.ShowHelp) { Console.WriteLine(ThmGenStrings.HelpMessage); AppCommon.DisplayToolFooter(); } else { foreach (string arg in unprocessed) { Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(arg)); } this.GenerateThemeHelpers(); } } } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); } catch (Exception e) { Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(Messaging.Instance.LastErrorNumber); }
public ICommandLineCommand ParseStandardCommandLine() { var context = this.ServiceProvider.GetService <ICommandLineContext>(); context.ExtensionManager = this.ExtensionManager ?? this.ServiceProvider.GetService <IExtensionManager>(); context.Arguments = this.Arguments; var command = this.Parse(context); if (command.ShowLogo) { AppCommon.DisplayToolHeader(); } return(command); //switch (commandType) //{ //case CommandTypes.Build: //{ // var sourceFiles = GatherSourceFiles(files, outputFolder); // var variables = this.GatherPreprocessorVariables(defines); // var bindPathList = this.GatherBindPaths(bindPaths); // var filterCultures = CalculateFilterCultures(cultures); // var type = CalculateOutputType(outputType, outputFile); // var platform = CalculatePlatform(platformType); // return new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, platform, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile); //} //case CommandTypes.Compile: //{ // var sourceFiles = GatherSourceFiles(files, outputFolder); // var variables = this.GatherPreprocessorVariables(defines); // var platform = CalculatePlatform(platformType); // return new CompileCommand(this.ServiceProvider, sourceFiles, variables, platform); //} //case CommandTypes.Decompile: //{ // var sourceFiles = GatherSourceFiles(files, outputFolder); // return new DecompileCommand(this.ServiceProvider, sourceFiles, outputFile); //} //} //return null; }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Execute(string[] args) { try { string[] unparsed = this.ParseCommandLineAndLoadExtensions(args); if (!Messaging.Instance.EncounteredError) { if (this.commandLine.ShowLogo) { AppCommon.DisplayToolHeader(); } if (this.commandLine.ShowHelp) { this.PrintHelp(); AppCommon.DisplayToolFooter(); } else { foreach (string arg in unparsed) { Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(arg)); } this.Run(); } } } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); } catch (Exception e) { Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(Messaging.Instance.LastErrorNumber); }
public static void Main(string[] args) { AppCommon.PrepareConsoleForLocalization(); CommandLine cmdLine = CommandLine.Parse(args); if (cmdLine.ShowLogo) { AppCommon.DisplayToolHeader(); } if (cmdLine.ShowHelp) { Shine.ShowHelp(); AppCommon.DisplayToolFooter(); return; } // Execute the scan and display the results. Scanner scanner = new Scanner(); scanner.RecurseProjects = cmdLine.RecurseProjects; ScanResult result = scanner.Scan(cmdLine.Paths, null, null); // If there is anything to filter, do so. if (cmdLine.IncludeSymbols.Count > 0 || cmdLine.ExcludeSymbols.Count > 0) { result.FilterSymbols(cmdLine.IncludeSymbols, cmdLine.ExcludeSymbols); } if (String.IsNullOrEmpty(cmdLine.Dgml)) { Console.WriteLine("Displaying graph to console is not supported yet. Use the -dgml switch."); } else { Shine.SaveDgml(result, cmdLine.Group, cmdLine.Show, cmdLine.DgmlTemplate, cmdLine.Dgml); } }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { Linker linker = null; Localizer localizer = null; SectionCollection sections = new SectionCollection(); ArrayList transforms = new ArrayList(); try { // parse the command line this.ParseCommandLine(args); // load any extensions List <WixExtension> loadedExtensionList = new List <WixExtension>(); foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); loadedExtensionList.Add(wixExtension); // If the extension provides a binder, use that now if it // matches the class from the command line. if (null != wixExtension.CustomBinder && null != this.binderClass && wixExtension.CustomBinder.GetType().Name.Equals(this.binderClass, StringComparison.Ordinal)) { this.binder = wixExtension.CustomBinder; } } // If a binder was specified, but not found then show an error. if (!String.IsNullOrEmpty(this.binderClass) && null == this.binder) { throw new WixException(WixErrors.SpecifiedBinderNotFound(this.binderClass)); } // create the linker, binder, and validator linker = new Linker(); if (null == this.binder) { this.binder = new Microsoft.Tools.WindowsInstallerXml.Binder(); } // have the binder parse the command line arguments light did not recognize string[] unparsedArgsArray = new string[this.unparsedArgs.Count]; this.unparsedArgs.CopyTo(unparsedArgsArray, 0); StringCollection remainingArgs = this.binder.ParseCommandLine(unparsedArgsArray, this.messageHandler); // Loop through the extensions to give them a shot at processing the remaining command-line args. foreach (WixExtension wixExtension in loadedExtensionList) { if (0 == remainingArgs.Count) { break; } remainingArgs = wixExtension.ParseCommandLine(remainingArgs, this.messageHandler); } this.ParseCommandLinePassTwo(remainingArgs); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (0 == this.inputFiles.Count) { this.showHelp = true; } else if (null == this.outputFile) { if (1 < this.inputFiles.Count) { throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput()); } this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wix"); // we'll let the linker change the extension later } this.binder.OutputFile = this.outputFile; this.binder.PostParseCommandLine(); if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { this.PrintHelp(); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } linker.AllowIdenticalRows = this.allowIdenticalRows; linker.AllowUnresolvedReferences = this.allowUnresolvedReferences; linker.Cultures = this.cultures; linker.UnreferencedSymbolsFile = this.unreferencedSymbolsFile; linker.ShowPedanticMessages = this.showPedanticMessages; linker.DropUnrealTables = this.dropUnrealTables; linker.SuppressLocalization = this.suppressLocalization; linker.SuppressMsiAssemblyTable = this.suppressMsiAssemblyTable; linker.WixVariableResolver = this.wixVariableResolver; // set the sequence suppression options linker.SuppressAdminSequence = this.suppressAdminSequence; linker.SuppressAdvertiseSequence = this.suppressAdvertiseSequence; linker.SuppressUISequence = this.suppressUISequence; linker.SectionIdOnRows = this.sectionIdOnRows; this.binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); this.binder.WixVariableResolver = this.wixVariableResolver; if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.sourcePaths.Add(bindPath); } } } // instantiate the localizer and load any localization files if (!this.suppressLocalization || 0 < this.localizationFiles.Count || null != this.cultures || !this.outputXml) { List <Localization> localizations = new List <Localization>(); localizer = new Localizer(); localizer.Message += new MessageEventHandler(this.messageHandler.Display); // load each localization file foreach (string localizationFile in this.localizationFiles) { Localization localization = Localization.Load(localizationFile, linker.TableDefinitions, this.suppressSchema); localizations.Add(localization); } if (null != this.cultures) { // add localizations in order specified in cultures foreach (string culture in this.cultures) { foreach (Localization localization in localizations) { if (culture.Equals(localization.Culture, StringComparison.OrdinalIgnoreCase)) { localizer.AddLocalization(localization); } } } } else { bool neutralFound = false; foreach (Localization localization in localizations) { if (0 == localization.Culture.Length) { // if a neutral wxl was provided use it localizer.AddLocalization(localization); neutralFound = true; } } if (!neutralFound) { // cultures wasn't specified and no neutral wxl are available, include all of the files foreach (Localization localization in localizations) { localizer.AddLocalization(localization); } } } // immediately stop processing if any errors were found if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // tell all of the objects about the localizer linker.Localizer = localizer; this.binder.Localizer = localizer; this.wixVariableResolver.Localizer = localizer; } // process loaded extensions foreach (WixExtension wixExtension in loadedExtensionList) { linker.AddExtension(wixExtension); this.binder.AddExtension(wixExtension); // load the extension's localizations Library library = wixExtension.GetLibrary(linker.TableDefinitions); if (null != library) { // load the extension's default culture if it provides one and we don't specify any cultures string[] extensionCultures = this.cultures; if (null == extensionCultures && null != wixExtension.DefaultCulture) { extensionCultures = new string[] { wixExtension.DefaultCulture }; } library.GetLocalizations(extensionCultures, localizer); } } this.binder.ProcessExtensions(loadedExtensionList.ToArray()); // set the message handlers linker.Message += new MessageEventHandler(this.messageHandler.Display); this.binder.AddMessageEventHandler(new MessageEventHandler(this.messageHandler.Display)); Output output = null; // loop through all the believed object files foreach (string inputFile in this.inputFiles) { string dirName = Path.GetDirectoryName(inputFile); string inputFileFullPath = Path.GetFullPath(inputFile); if (!this.sourcePaths.Contains(dirName)) { this.sourcePaths.Add(dirName); } // try loading as an object file try { Intermediate intermediate = Intermediate.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(intermediate.Sections); continue; // next file } catch (WixNotIntermediateException) { // try another format } // try loading as a library file try { Library library = Library.Load(inputFileFullPath, linker.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); library.GetLocalizations(this.cultures, localizer); sections.AddRange(library.Sections); continue; // next file } catch (WixNotLibraryException) { // try another format } // try loading as an output file output = Output.Load(inputFileFullPath, this.suppressVersionCheck, this.suppressSchema); } // immediately stop processing if any errors were found if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // set the binder file manager information foreach (string bindPath in this.bindPaths) { //Checking as IndexOf will return 0 if the string value is String.Empty. if (String.IsNullOrEmpty(bindPath)) { continue; } if (-1 == bindPath.IndexOf('=')) { this.binder.FileManager.BindPaths.Add(bindPath); } else { string[] namedPair = bindPath.Split('='); //It is ok to have duplicate key. this.binder.FileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]); } } foreach (string sourcePath in this.sourcePaths) { this.binder.FileManager.SourcePaths.Add(sourcePath); } // and now for the fun part if (null == output) { OutputType expectedOutputType = OutputType.Unknown; if (this.outputFile != null) { expectedOutputType = Output.GetOutputType(Path.GetExtension(this.outputFile)); } output = linker.Link(sections, transforms, expectedOutputType); // if an error occurred during linking, stop processing if (null == output) { return(this.messageHandler.LastErrorNumber); } } else if (0 != sections.Count) { throw new InvalidOperationException(LightStrings.EXP_CannotLinkObjFilesWithOutpuFile); } // Now that the output object is either linked or loaded, tell the binder file manager about it. this.binder.FileManager.Output = output; // only output the xml if its a patch build or user specfied to only output wixout if (this.outputXml || OutputType.Patch == output.Type) { string outputExtension = Path.GetExtension(this.outputFile); if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension) { if (OutputType.Patch == output.Type) { this.outputFile = Path.ChangeExtension(this.outputFile, ".wixmsp"); } else { this.outputFile = Path.ChangeExtension(this.outputFile, ".wixout"); } } output.Save(this.outputFile, (this.bindFiles ? this.binder.FileManager : null), this.wixVariableResolver, this.binder.TempFilesLocation); } else // finish creating the MSI/MSM { string outputExtension = Path.GetExtension(this.outputFile); if (null == outputExtension || 0 == outputExtension.Length || ".wix" == outputExtension) { outputExtension = Output.GetExtension(output.Type); this.outputFile = Path.ChangeExtension(this.outputFile, outputExtension); } this.binder.Bind(output, this.outputFile); } } catch (WixException we) { if (we is WixInvalidIdtException) { // make sure the IDT files stay around this.tidy = false; } this.messageHandler.Display(this, we.Error); } catch (Exception e) { // make sure the files stay around for debugging this.tidy = false; this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != binder) { this.binder.Cleanup(this.tidy); } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { StringCollection extensionList = new StringCollection(); ClickThroughConsoleExtension extension = null; try { // parse the command line this.ParseCommandLine(args); // load the extension if (null != this.extensionType) { extension = ClickThroughConsoleExtension.Load(this.extensionType); extension.Fabricator.Message += new MessageEventHandler(this.messageHandler.Display); // parse the extension's command line arguments string[] extensionOptionsArray = new string[this.extensionOptions.Count]; this.extensionOptions.CopyTo(extensionOptionsArray, 0); extension.ParseOptions(extensionOptionsArray); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(CTStrings.HelpMessage1); // output the builder types alphabetically if (null != extension) { SortedList builderTypes = new SortedList(); foreach (CommandLineOption commandLineOption in extension.CommandLineTypes) { builderTypes.Add(commandLineOption.Option, commandLineOption); } foreach (CommandLineOption commandLineOption in builderTypes.Values) { Console.WriteLine(String.Format(CultureInfo.CurrentUICulture, CTStrings.OptionFormat, commandLineOption.Option, commandLineOption.Description)); } } Console.WriteLine(CTStrings.HelpMessage2); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } // build the output if (!extension.Fabricator.Fabricate(this.outputFile)) { return(this.messageHandler.LastErrorNumber); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { bool inscribed = false; try { Inscriber inscriber = null; // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (String.IsNullOrEmpty(this.msiPath) && String.IsNullOrEmpty(this.bundlePath)) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(InsigniaStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // Calculate the output path. string inputPath = String.IsNullOrEmpty(this.msiPath) ? Path.GetFullPath(this.bundlePath) : Path.GetFullPath(this.msiPath); if (String.IsNullOrEmpty(this.outputPath)) { this.outputPath = inputPath; } else if (this.outputPath.EndsWith("\\")) { this.outputPath = Path.GetFullPath(Path.Combine(this.outputPath, Path.GetFileName(inputPath))); } inscriber = new Inscriber(); inscriber.MessageHandler += new MessageEventHandler(this.messageHandler.Display); // Set the temp directory - if it's null, we'll default appropriately inscriber.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); if (!String.IsNullOrEmpty(this.msiPath)) { try { inscribed = inscriber.InscribeDatabase(inputPath, this.outputPath, this.tidy); } catch (UnauthorizedAccessException) { this.messageHandler.Display(this, WixErrors.UnauthorizedAccess(inputPath)); } } else if (!String.IsNullOrEmpty(this.bundleWithAttachedContainerPath)) { inscribed = inscriber.InscribeBundle(this.bundleWithAttachedContainerPath, this.bundlePath, this.outputPath); } else { inscribed = inscriber.InscribeBundleEngine(this.bundlePath, this.outputPath); } if (this.tidy) { inscriber.DeleteTempFiles(); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } // On success but nothing inscribed then return -1. Otherwise, return whatever last error number // was (which could be zero if successfully inscribed). return((0 == this.messageHandler.LastErrorNumber && !inscribed) ? -1 : this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { Librarian librarian = null; SectionCollection sections = new SectionCollection(); // parse the command line this.ParseCommandLine(args); // load any extensions List <WixExtension> loadedExtensionList = new List <WixExtension>(); foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); loadedExtensionList.Add(wixExtension); // Have the binder extension parse the command line arguments lit did not recognized. if (0 < this.unparsedArgs.Count) { this.unparsedArgs = wixExtension.ParseCommandLine(this.unparsedArgs, this.messageHandler); } } this.ParseCommandLinePassTwo(this.unparsedArgs); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (0 == this.inputFiles.Count) { this.showHelp = true; } else if (null == this.outputFile) { if (1 < this.inputFiles.Count) { throw new WixException(WixErrors.MustSpecifyOutputWithMoreThanOneInput()); } this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFiles[0]), ".wixlib"); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(LitStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // create the librarian librarian = new Librarian(); librarian.Message += new MessageEventHandler(this.messageHandler.Display); librarian.ShowPedanticMessages = this.showPedanticMessages; if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.sourcePaths.Add(bindPath); } } } foreach (WixExtension wixExtension in loadedExtensionList) { librarian.AddExtension(wixExtension); // load the binder file manager regardless of whether it will be used in case there is a collision if (null != wixExtension.BinderFileManager) { if (null != this.binderFileManager) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, LitStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), this.binderFileManager.GetType().ToString()), "ext"); } this.binderFileManager = wixExtension.BinderFileManager; } } // add the sections to the librarian foreach (string inputFile in this.inputFiles) { string inputFileFullPath = Path.GetFullPath(inputFile); string dirName = Path.GetDirectoryName(inputFileFullPath); if (!this.sourcePaths.Contains(dirName)) { this.sourcePaths.Add(dirName); } // try loading as an object file try { Intermediate intermediate = Intermediate.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(intermediate.Sections); continue; // next file } catch (WixNotIntermediateException) { // try another format } // try loading as a library file Library loadedLibrary = Library.Load(inputFileFullPath, librarian.TableDefinitions, this.suppressVersionCheck, this.suppressSchema); sections.AddRange(loadedLibrary.Sections); } // and now for the fun part Library library = librarian.Combine(sections); // save the library output if an error did not occur if (null != library) { if (this.bindFiles) { // if the binder file manager has not been loaded yet use the built-in binder extension if (null == this.binderFileManager) { this.binderFileManager = new BinderFileManager(); } if (null != this.bindPaths) { foreach (string bindPath in this.bindPaths) { if (-1 == bindPath.IndexOf('=')) { this.binderFileManager.BindPaths.Add(bindPath); } else { string[] namedPair = bindPath.Split('='); //It is ok to have duplicate key. this.binderFileManager.NamedBindPaths.Add(namedPair[0], namedPair[1]); } } } foreach (string sourcePath in this.sourcePaths) { this.binderFileManager.SourcePaths.Add(sourcePath); } } else { this.binderFileManager = null; } foreach (string localizationFile in this.localizationFiles) { Localization localization = Localization.Load(localizationFile, librarian.TableDefinitions, this.suppressSchema); library.AddLocalization(localization); } WixVariableResolver wixVariableResolver = new WixVariableResolver(); wixVariableResolver.Message += new MessageEventHandler(this.messageHandler.Display); library.Save(this.outputFile, this.binderFileManager, wixVariableResolver); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); this.messageHandler.ShowVerboseMessages = true; // always verbose, to show passed tests // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(NitStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // gotta have something to do if (0 == this.inputFiles.Count) { Console.WriteLine(NitStrings.HelpMessage); this.messageHandler.Display(this, NitErrors.MalfunctionNeedInput()); return(this.messageHandler.LastErrorNumber); } // run tests and report results TestRunner runner = new TestRunner(); runner.InputFiles = this.inputFiles; runner.Message += this.messageHandler.Display; int failures = 0; int passes = 0; runner.RunTests(out passes, out failures); if (0 < failures) { this.messageHandler.Display(this, NitErrors.TotalTestFailures(failures, passes)); return(this.messageHandler.LastErrorNumber); } else { this.messageHandler.Display(this, NitVerboses.OneHundredPercent(passes)); } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (Messaging.Instance.EncounteredError) { return(Messaging.Instance.LastErrorNumber); } if (String.IsNullOrEmpty(this.inputFile) || String.IsNullOrEmpty(this.outputFile) || (OutputType.Product == this.outputType && String.IsNullOrEmpty(this.inputPdbFile))) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(MeltStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(Messaging.Instance.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { Messaging.Instance.OnMessage(WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; if (null == this.exportBasePath) { this.exportBasePath = System.IO.Path.GetDirectoryName(this.outputFile); } if (OutputType.Module == this.outputType) { MeltModule(); } else if (OutputType.Product == this.outputType) { MeltProduct(); } } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); } catch (Exception e) { Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(Messaging.Instance.LastErrorNumber); }
private ICommandLineCommand ParseStandardCommandLine(ICommandLineContext context, string[] args) { var next = String.Empty; var command = Commands.Unknown; var showLogo = true; var showVersion = false; var outputFolder = String.Empty; var outputFile = String.Empty; var outputType = String.Empty; var verbose = false; var files = new List <string>(); var defines = new List <string>(); var includePaths = new List <string>(); var locFiles = new List <string>(); var libraryFiles = new List <string>(); var suppressedWarnings = new List <int>(); var bindFiles = false; var bindPaths = new List <string>(); var intermediateFolder = String.Empty; var cabCachePath = String.Empty; var cultures = new List <string>(); var contentsFile = String.Empty; var outputsFile = String.Empty; var builtOutputsFile = String.Empty; this.Parse(context, args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => { if (cmdline.IsSwitch(arg)) { var parameter = arg.Substring(1); switch (parameter.ToLowerInvariant()) { case "?": case "h": case "help": cmdline.ShowHelp = true; return(true); case "bindfiles": bindFiles = true; return(true); case "bindpath": cmdline.GetNextArgumentOrError(bindPaths); return(true); case "cc": cmdline.GetNextArgumentOrError(ref cabCachePath); return(true); case "culture": cmdline.GetNextArgumentOrError(cultures); return(true); case "contentsfile": cmdline.GetNextArgumentOrError(ref contentsFile); return(true); case "outputsfile": cmdline.GetNextArgumentOrError(ref outputsFile); return(true); case "builtoutputsfile": cmdline.GetNextArgumentOrError(ref builtOutputsFile); return(true); case "d": case "define": cmdline.GetNextArgumentOrError(defines); return(true); case "i": case "includepath": cmdline.GetNextArgumentOrError(includePaths); return(true); case "intermediatefolder": cmdline.GetNextArgumentOrError(ref intermediateFolder); return(true); case "loc": cmdline.GetNextArgumentAsFilePathOrError(locFiles, "localization files"); return(true); case "lib": cmdline.GetNextArgumentAsFilePathOrError(libraryFiles, "library files"); return(true); case "o": case "out": cmdline.GetNextArgumentOrError(ref outputFile); return(true); case "outputtype": cmdline.GetNextArgumentOrError(ref outputType); return(true); case "nologo": showLogo = false; return(true); case "v": case "verbose": verbose = true; return(true); case "version": case "-version": showVersion = true; return(true); case "sval": // todo: implement return(true); } return(false); } else { files.AddRange(CommandLineHelper.GetFiles(arg, "source code")); return(true); } }); this.Messaging.ShowVerboseMessages = verbose; if (showVersion) { return(new VersionCommand()); } if (showLogo) { AppCommon.DisplayToolHeader(); } if (this.ShowHelp) { return(new HelpCommand(command)); } switch (command) { case Commands.Build: { var sourceFiles = GatherSourceFiles(files, outputFolder); var variables = this.GatherPreprocessorVariables(defines); var bindPathList = this.GatherBindPaths(bindPaths); var filterCultures = CalculateFilterCultures(cultures); var type = CalculateOutputType(outputType, outputFile); return(new BuildCommand(this.ServiceProvider, sourceFiles, variables, locFiles, libraryFiles, filterCultures, outputFile, type, cabCachePath, bindFiles, bindPathList, includePaths, intermediateFolder, contentsFile, outputsFile, builtOutputsFile)); } case Commands.Compile: { var sourceFiles = GatherSourceFiles(files, outputFolder); var variables = GatherPreprocessorVariables(defines); return(new CompileCommand(this.ServiceProvider, sourceFiles, variables)); } } return(null); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.inputFile || null == this.outputFile) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(PyroStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } // Load in transforms ArrayList transforms = new ArrayList(); foreach (string inputTransform in inputTransformsOrdered) { PatchTransform patchTransform = new PatchTransform(inputTransform, inputTransforms[inputTransform]); patchTransform.Message += new MessageEventHandler(this.messageHandler.Display); transforms.Add(patchTransform); } // Create and configure the patch Patch patch = new Patch(); patch.Message += new MessageEventHandler(this.messageHandler.Display); // Create and configure the binder binder = new Microsoft.Tools.WindowsInstallerXml.Binder(); binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); binder.WixVariableResolver = this.wixVariableResolver; binder.Message += new MessageEventHandler(this.messageHandler.Display); binder.SuppressAssemblies = this.suppressAssemblies; binder.SuppressFileHashAndInfo = this.suppressFileHashAndInfo; binder.SetMsiAssemblyNameFileVersion = this.setAssemblyFileVersions; // have the binder parse the command line arguments light did not recognize string[] unparsedArgsArray = new string[this.unparsedArgs.Count]; this.unparsedArgs.CopyTo(unparsedArgsArray, 0); StringCollection remainingArgs = this.binder.ParseCommandLine(unparsedArgsArray, this.messageHandler); // Load the extensions bool binderFileManagerLoaded = false; foreach (String extension in this.extensions) { WixExtension wixExtension = WixExtension.Load(extension); binder.AddExtension(wixExtension); patch.AddExtension(wixExtension); if (0 < remainingArgs.Count) { remainingArgs = wixExtension.ParseCommandLine(remainingArgs, this.messageHandler); } if (null != wixExtension.BinderFileManager) { if (binderFileManagerLoaded) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, PyroStrings.EXP_CannotLoadBinderFileManager, wixExtension.BinderFileManager.GetType().ToString(), binder.FileManager.ToString()), "ext"); } binder.FileManager = wixExtension.BinderFileManager; binderFileManagerLoaded = true; } } foreach (string parameter in remainingArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // since the binder is now ready, let's plug dynamic bindpath into file manager this.PrepareDataForFileManager(); // Load the patch patch.Load(this.inputFile); // Copy transforms into output if (0 < transforms.Count) { patch.AttachTransforms(transforms); } if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.pdbFile && null != this.outputFile) { this.pdbFile = Path.ChangeExtension(this.outputFile, ".wixpdb"); } binder.PdbFile = suppressWixPdb ? null : this.pdbFile; if (this.suppressFiles) { binder.SuppressAssemblies = true; binder.SuppressFileHashAndInfo = true; } if (null != this.cabCachePath || this.reuseCabinets) { // ensure the cabinet cache path exists if we are going to use it if (null != this.cabCachePath && !Directory.Exists(this.cabCachePath)) { Directory.CreateDirectory(this.cabCachePath); } } binder.AllowEmptyTransforms = this.allowEmptyTransforms; binder.FileManager.ReuseCabinets = this.reuseCabinets; binder.FileManager.CabCachePath = this.cabCachePath; binder.FileManager.Output = patch.PatchOutput; binder.FileManager.DeltaBinaryPatch = this.delta; // Bind the patch to an msp. binder.Bind(patch.PatchOutput, this.outputFile); } catch (WixException we) { this.OnMessage(we.Error); } catch (Exception e) { this.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != binder) { if (this.tidy) { if (!binder.DeleteTempFiles()) { Console.WriteLine(PyroStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(PyroStrings.INF_TempDirLocatedAt, binder.TempFilesLocation); } } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (!this.fipsCompliant) { try { System.Security.Cryptography.MD5.Create(); } catch (TargetInvocationException) { this.messageHandler.Display(this, WixErrors.UseFipsArgument()); return(this.messageHandler.LastErrorNumber); } } if (0 == this.sourceFiles.Count) { this.showHelp = true; } else if (1 < this.sourceFiles.Count && null != this.outputFile) { throw new ArgumentException(CandleStrings.CannotSpecifyMoreThanOneSourceFileForSingleTargetFile, "-out"); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(CandleStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // create the preprocessor and compiler Preprocessor preprocessor = new Preprocessor(); preprocessor.Message += new MessageEventHandler(this.messageHandler.Display); for (int i = 0; i < this.includeSearchPaths.Count; ++i) { preprocessor.IncludeSearchPaths.Add(this.includeSearchPaths[i]); } preprocessor.CurrentPlatform = this.platform; Compiler compiler = new Compiler(); compiler.Message += new MessageEventHandler(this.messageHandler.Display); compiler.SuppressFilesVitalByDefault = this.suppressFilesVitalByDefault; compiler.ShowPedanticMessages = this.showPedanticMessages; compiler.SuppressValidate = this.suppressSchema; compiler.CurrentPlatform = this.platform; compiler.FipsCompliant = this.fipsCompliant; // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); preprocessor.AddExtension(wixExtension); compiler.AddExtension(wixExtension); } // preprocess then compile each source file Dictionary <string, List <string> > sourcesForOutput = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase); foreach (string sourceFileOrig in this.sourceFiles) { string sourceFile = sourceFileOrig; string targetFile = null; if (this.allowPerSourceOutputSpecification) { string[] parts = sourceFileOrig.Split(Candle.sourceOutputSeparator, 2); if (2 == parts.Length) { sourceFile = parts[0]; targetFile = parts[1]; } } string sourceFilePath = Path.GetFullPath(sourceFile); string sourceFileName = Path.GetFileName(sourceFile); if (null == targetFile) { if (null != this.outputFile) { targetFile = this.outputFile; } else if (null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, Path.ChangeExtension(sourceFileName, ".wixobj")); } else { targetFile = Path.ChangeExtension(sourceFileName, ".wixobj"); } } else if (!Path.IsPathRooted(targetFile) && null != this.outputDirectory) { targetFile = Path.Combine(this.outputDirectory, targetFile); } // print friendly message saying what file is being compiled Console.WriteLine(sourceFileName); // preprocess the source XmlDocument sourceDocument; try { if (this.preprocessToStdout) { preprocessor.PreprocessOut = Console.Out; } else if (null != this.preprocessFile) { preprocessor.PreprocessOut = new StreamWriter(this.preprocessFile); } sourceDocument = preprocessor.Process(sourceFilePath, this.parameters); } finally { if (null != preprocessor.PreprocessOut && Console.Out != preprocessor.PreprocessOut) { preprocessor.PreprocessOut.Close(); } } // if we're not actually going to compile anything, move on to the next file if (null == sourceDocument || this.preprocessToStdout || null != this.preprocessFile) { continue; } // and now we do what we came here to do... Intermediate intermediate = compiler.Compile(sourceDocument); // save the intermediate to disk if no errors were found for this source file if (null != intermediate) { intermediate.Save(targetFile); } // Track which source files result in a given output file, to ensure we aren't // overwriting the output. List <string> sources = null; string targetPath = Path.GetFullPath(targetFile); if (!sourcesForOutput.TryGetValue(targetPath, out sources)) { sources = new List <string>(); sourcesForOutput.Add(targetPath, sources); } sources.Add(sourceFile); } // Show an error for every output file that had more than 1 source file. foreach (KeyValuePair <string, List <string> > outputSources in sourcesForOutput) { if (1 < outputSources.Value.Count) { string sourceFiles = CompilerCore.CreateValueList(ValueListKind.None, outputSources.Value); this.messageHandler.Display(this, WixErrors.DuplicateSourcesForOutput(sourceFiles, outputSources.Key)); } } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(LuxStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // gotta have something to do if (0 == this.inputFiles.Count || String.IsNullOrEmpty(this.outputFile)) { Console.WriteLine(LuxStrings.HelpMessage); this.messageHandler.Display(this, LuxBuildErrors.MalfunctionNeedInput()); return(this.messageHandler.LastErrorNumber); } if (String.IsNullOrEmpty(Path.GetExtension(this.outputFile))) { this.outputFile = Path.ChangeExtension(this.outputFile, ".wxs"); } // get extensions from lux.exe.config AppCommon.ReadConfiguration(this.extensionList); List <string> inputFragments = new List <string>(); Generator.Generate(this.extensionList, this.inputFiles, this.outputFile, this.messageHandler.Display, out inputFragments); } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { StringCollection extensionList = new StringCollection(); heatCore = new HeatCore(); HarvesterCore harvesterCore = new HarvesterCore(); heatCore.Harvester.Core = harvesterCore; heatCore.Mutator.Core = harvesterCore; try { // read the configuration file (heat.exe.config) AppCommon.ReadConfiguration(extensionList); // load any extensions foreach (string extensionType in extensionList) { this.LoadExtension(extensionType); } // exit if there was an error loading an extension if (Messaging.Instance.EncounteredError) { return(Messaging.Instance.LastErrorNumber); } // parse the command line this.ParseCommandLine(args); if (this.showHelp) { return(this.DisplayHelp()); } // exit if there was an error parsing the core command line if (Messaging.Instance.EncounteredError) { return(Messaging.Instance.LastErrorNumber); } if (this.showLogo) { AppCommon.DisplayToolHeader(); } // set the extension argument for use by all extensions harvesterCore.ExtensionArgument = this.extensionArgument; // parse the extension's command line arguments string[] extensionOptionsArray = new string[this.extensionOptions.Count]; this.extensionOptions.CopyTo(extensionOptionsArray, 0); foreach (HeatExtension heatExtension in this.extensions) { heatExtension.ParseOptions(this.extensionType, extensionOptionsArray); } // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (Messaging.Instance.EncounteredError) { return(Messaging.Instance.LastErrorNumber); } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.extensionArgument); if (null == wix) { return(Messaging.Instance.LastErrorNumber); } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return(Messaging.Instance.LastErrorNumber); } XmlWriterSettings xmlSettings = new XmlWriterSettings(); xmlSettings.Indent = true; xmlSettings.IndentChars = new string(' ', this.indent); xmlSettings.OmitXmlDeclaration = true; string wixString; using (StringWriter stringWriter = new StringWriter()) { using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter, xmlSettings)) { wix.OutputXml(xmlWriter); } wixString = stringWriter.ToString(); } string mutatedWixString = heatCore.Mutator.Mutate(wixString); if (String.IsNullOrEmpty(mutatedWixString)) { return(Messaging.Instance.LastErrorNumber); } Directory.CreateDirectory(Path.GetDirectoryName(this.outputFile)); using (StreamWriter streamWriter = new StreamWriter(this.outputFile, false, System.Text.Encoding.UTF8)) { xmlSettings.OmitXmlDeclaration = false; xmlSettings.Encoding = System.Text.Encoding.UTF8; using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter, xmlSettings)) { xmlWriter.WriteStartDocument(); xmlWriter.Flush(); } streamWriter.WriteLine(); streamWriter.Write(mutatedWixString); } } catch (WixException we) { Messaging.Instance.OnMessage(we.Error); } catch (Exception e) { Messaging.Instance.OnMessage(WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(Messaging.Instance.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { Decompiler decompiler = null; Mutator mutator = null; Unbinder unbinder = null; try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.inputFile) { this.showHelp = true; } else if (null == this.outputFile) { if (null == this.outputDirectory) { this.outputFile = Path.ChangeExtension(Path.GetFileName(this.inputFile), ".wxs"); } else { this.outputFile = Path.Combine(this.outputDirectory, Path.ChangeExtension(Path.GetFileName(this.inputFile), ".wxs")); } } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(DarkStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; // create the decompiler and mutator decompiler = new Decompiler(); mutator = new Mutator(); mutator.Core = new HarvesterCore(new MessageEventHandler(this.messageHandler.Display)); unbinder = new Unbinder(); // read the configuration file (dark.exe.config) AppCommon.ReadConfiguration(this.extensionList); // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); decompiler.AddExtension(wixExtension); unbinder.AddExtension(wixExtension); } // set options decompiler.SuppressCustomTables = this.suppressCustomTables; decompiler.SuppressDroppingEmptyTables = this.suppressDroppingEmptyTables; decompiler.SuppressRelativeActionSequencing = this.suppressRelativeActionSequencing; decompiler.SuppressUI = this.suppressUI; decompiler.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); if (!String.IsNullOrEmpty(this.exportBasePath)) { decompiler.ExportFilePath = this.exportBasePath; } unbinder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); decompiler.Message += new MessageEventHandler(this.messageHandler.Display); unbinder.Message += new MessageEventHandler(this.messageHandler.Display); // print friendly message saying what file is being decompiled Console.WriteLine(Path.GetFileName(this.inputFile)); // unbind // TODO: passing a bundle to the decompiler without the /x parameter specified stumbles here // as the exportBasePath will be null. Need a design decision whether to throw an // message below or throw a message here Output output = unbinder.Unbind(this.inputFile, this.outputType, this.exportBasePath); if (null != output) { if (OutputType.Patch == this.outputType || OutputType.Transform == this.outputType || this.outputXml) { output.Save(this.outputFile, null, new WixVariableResolver(), null); } else // decompile { Wix.Wix wix = decompiler.Decompile(output); // output if (null != wix) { XmlTextWriter writer = null; // mutate the Wix document if (!mutator.Mutate(wix)) { return(this.messageHandler.LastErrorNumber); } try { Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(this.outputFile))); writer = new XmlTextWriter(this.outputFile, System.Text.Encoding.UTF8); writer.Indentation = 4; writer.IndentChar = ' '; writer.QuoteChar = '"'; writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); wix.OutputXml(writer); writer.WriteEndDocument(); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.FileWriteError(this.outputFile, e.Message)); return(this.messageHandler.LastErrorNumber); } finally { if (null != writer) { writer.Close(); } } } } } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != decompiler) { if (this.tidy) { if (!decompiler.DeleteTempFiles()) { Console.WriteLine(DarkStrings.WAR_FailedToDeleteTempDir, decompiler.TempFilesLocation); } } else { Console.WriteLine(DarkStrings.INF_TempDirLocatedAt, decompiler.TempFilesLocation); } } if (null != unbinder) { if (this.tidy) { if (!unbinder.DeleteTempFiles()) { Console.WriteLine(DarkStrings.WAR_FailedToDeleteTempDir, unbinder.TempFilesLocation); } } else { Console.WriteLine(DarkStrings.INF_TempDirLocatedAt, unbinder.TempFilesLocation); } } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { Microsoft.Tools.WindowsInstallerXml.Binder binder = null; Differ differ = null; Unbinder unbinder = null; TempFileCollection tempFileCollection = null; try { // parse the command line this.ParseCommandLine(args); // validate the inputs if (this.xmlInputs && this.adminImage) { this.messageHandler.Display(this, WixErrors.IllegalCommandlineArgumentCombination("a", "xi")); this.showHelp = true; } string[] allValidExtensions = new string[] { wixMstExtension, wixOutExtension, wixPdbExtension, msiExtension }; string[] expectedSingleInputExtensions = new string[] { wixMstExtension, wixOutExtension }; string[] expectedDoubleInputXmlExtensions = new string[] { wixOutExtension, wixPdbExtension }; string[] expectedDoubleInputMsiExtensions = new string[] { msiExtension }; // Validate that all inputs have the correct extension and we dont have too many inputs. if (1 == this.inputFiles.Count) { string inputFile = this.inputFiles[0]; bool hasValidExtension = false; foreach (string extension in expectedSingleInputExtensions) { if (String.Equals(Path.GetExtension(inputFile), extension, StringComparison.OrdinalIgnoreCase)) { hasValidExtension = true; break; } } if (!hasValidExtension) { bool missingInput = false; // Check if its using an extension that could be valid in other scenarios. foreach (string validExtension in allValidExtensions) { if (String.Equals(Path.GetExtension(inputFile), validExtension, StringComparison.OrdinalIgnoreCase)) { this.messageHandler.Display(this, WixErrors.WrongFileExtensionForNumberOfInputs(Path.GetExtension(inputFile), inputFile)); missingInput = true; break; } } if (!missingInput) { this.messageHandler.Display(this, WixErrors.UnexpectedFileExtension(inputFile, String.Join(", ", expectedSingleInputExtensions))); } } } else if (2 == this.inputFiles.Count) { foreach (string inputFile in inputFiles) { bool hasValidExtension = false; string[] expectedExtensions = allValidExtensions; if (this.xmlInputs) { foreach (string extension in expectedDoubleInputXmlExtensions) { if (String.Equals(Path.GetExtension(inputFile), extension, StringComparison.OrdinalIgnoreCase)) { hasValidExtension = true; expectedExtensions = expectedDoubleInputXmlExtensions; break; } } } else { foreach (string extension in expectedDoubleInputMsiExtensions) { if (String.Equals(Path.GetExtension(inputFile), extension, StringComparison.OrdinalIgnoreCase)) { hasValidExtension = true; expectedExtensions = expectedDoubleInputMsiExtensions; break; } } } if (!hasValidExtension) { this.messageHandler.Display(this, WixErrors.UnexpectedFileExtension(inputFile, String.Join(", ", expectedExtensions))); } } } else { this.showHelp = true; } // exit if there was an error parsing the command line or with a file extension (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (null == this.outputFile) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(TorchStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; binder = new Microsoft.Tools.WindowsInstallerXml.Binder(); differ = new Differ(); unbinder = new Unbinder(); // load any extensions foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); unbinder.AddExtension(wixExtension); binder.AddExtension(wixExtension); differ.AddExtension(wixExtension); } binder.Message += new MessageEventHandler(this.messageHandler.Display); differ.Message += new MessageEventHandler(this.messageHandler.Display); unbinder.Message += new MessageEventHandler(this.messageHandler.Display); binder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); unbinder.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); tempFileCollection = new TempFileCollection(Environment.GetEnvironmentVariable("WIX_TEMP")); binder.WixVariableResolver = new WixVariableResolver(); differ.PreserveUnchangedRows = this.preserveUnchangedRows; differ.ShowPedanticMessages = this.showPedanticMessages; unbinder.SuppressExtractCabinets = true; unbinder.IsAdminImage = this.adminImage; if (null == this.exportBasePath) { this.exportBasePath = tempFileCollection.BasePath; } // load and process the inputs Output transform; if (1 == this.inputFiles.Count) { transform = Output.Load(this.inputFiles[0], false, false); if (OutputType.Transform != transform.Type) { this.messageHandler.Display(this, WixErrors.InvalidWixTransform(this.inputFiles[0])); return(this.messageHandler.LastErrorNumber); } } else // 2 inputs { Output targetOutput; Output updatedOutput; if (this.xmlInputs) { // load the target database if (String.Equals(Path.GetExtension(inputFiles[0]), wixPdbExtension, StringComparison.OrdinalIgnoreCase)) { Pdb targetPdb = Pdb.Load(this.inputFiles[0], false, false); targetOutput = targetPdb.Output; } else { targetOutput = Output.Load(this.inputFiles[0], false, false); } // load the updated database if (String.Equals(Path.GetExtension(inputFiles[1]), wixPdbExtension, StringComparison.OrdinalIgnoreCase)) { Pdb updatedPdb = Pdb.Load(this.inputFiles[1], false, false); updatedOutput = updatedPdb.Output; } else { updatedOutput = Output.Load(this.inputFiles[1], false, false); } this.xmlOutput = true; } else { // load the target database targetOutput = unbinder.Unbind(this.inputFiles[0], OutputType.Product, Path.Combine(this.exportBasePath, "targetBinaries")); // load the updated database updatedOutput = unbinder.Unbind(this.inputFiles[1], OutputType.Product, Path.Combine(this.exportBasePath, "updatedBinaries")); } // diff the target and updated databases transform = differ.Diff(targetOutput, updatedOutput, this.validationFlags); if (null == transform.Tables || 0 >= transform.Tables.Count) { throw new WixException(WixErrors.NoDifferencesInTransform(transform.SourceLineNumbers)); } } // output the transform if (null != transform) { // If either the user selected xml output or gave xml input, save as xml output. // With xml inputs, many funtions of the binder have not been performed on the inputs (ie. file sequencing). This results in bad IDT files which cannot be put in a transform. if (this.xmlOutput) { transform.Save(this.outputFile, null, null, tempFileCollection.BasePath); } else { binder.Bind(transform, this.outputFile); } } } catch (WixException we) { if (we is WixInvalidIdtException) { // make sure the IDT files stay around this.tidy = false; } this.messageHandler.Display(this, we.Error); } catch (Exception e) { // make sure the files stay around for debugging this.tidy = false; this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } finally { if (null != binder) { if (this.tidy) { if (!binder.DeleteTempFiles()) { Console.WriteLine(TorchStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(TorchStrings.INF_BinderTempDirLocatedAt, binder.TempFilesLocation); } } if (null != unbinder) { if (this.tidy) { if (!unbinder.DeleteTempFiles()) { Console.WriteLine(TorchStrings.WAR_FailedToDeleteTempDir, binder.TempFilesLocation); } } else { Console.WriteLine(TorchStrings.INF_UnbinderTempDirLocatedAt, binder.TempFilesLocation); } } if (null != tempFileCollection) { if (this.tidy) { try { Directory.Delete(tempFileCollection.BasePath, true); } catch (DirectoryNotFoundException) { // if the path doesn't exist, then there is nothing for us to worry about } catch { Console.WriteLine(TorchStrings.WAR_FailedToDeleteTempDir, tempFileCollection.BasePath); } } else { Console.WriteLine(TorchStrings.INF_TorchTempDirLocatedAt, tempFileCollection.BasePath); } } } return(this.messageHandler.LastErrorNumber); }
/// <summary> /// Main running method for the application. /// </summary> /// <param name="args">Commandline arguments to the application.</param> /// <returns>Returns the application error code.</returns> private int Run(string[] args) { try { // parse the command line this.ParseCommandLine(args); // exit if there was an error parsing the command line (otherwise the logo appears after error messages) if (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } if (0 == this.inputFiles.Count) { this.showHelp = true; } if (this.showLogo) { AppCommon.DisplayToolHeader(); } if (this.showHelp) { Console.WriteLine(SmokeStrings.HelpMessage); AppCommon.DisplayToolFooter(); return(this.messageHandler.LastErrorNumber); } foreach (string parameter in this.invalidArgs) { this.messageHandler.Display(this, WixWarnings.UnsupportedCommandLineArgument(parameter)); } this.invalidArgs = null; validator.TempFilesLocation = Environment.GetEnvironmentVariable("WIX_TEMP"); // load any extensions bool validatorExtensionLoaded = false; foreach (string extension in this.extensionList) { WixExtension wixExtension = WixExtension.Load(extension); ValidatorExtension validatorExtension = wixExtension.ValidatorExtension; if (null != validatorExtension) { if (validatorExtensionLoaded) { throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, SmokeStrings.EXP_CannotLoadLinkerExtension, validatorExtension.GetType().ToString(), validator.Extension.ToString()), "ext"); } validator.Extension = validatorExtension; validatorExtensionLoaded = true; } } // set the message handlers validator.Extension.Message += new MessageEventHandler(this.messageHandler.Display); // disable ICE33 and ICE66 by default this.suppressICEs.Add("ICE33"); this.suppressICEs.Add("ICE66"); // set the ICEs string[] iceArray = new string[this.ices.Count]; this.ices.CopyTo(iceArray, 0); validator.ICEs = iceArray; // set the suppressed ICEs string[] suppressICEArray = new string[this.suppressICEs.Count]; this.suppressICEs.CopyTo(suppressICEArray, 0); validator.SuppressedICEs = suppressICEArray; // Load the pdb and assign the Output to the validator if (null != pdbPath) { string pdbFullPath = Path.GetFullPath(pdbPath); Pdb pdb = Pdb.Load(pdbFullPath, false, false); this.validator.Output = pdb.Output; } foreach (string inputFile in this.inputFiles) { // set the default cube file Assembly assembly = Assembly.GetExecutingAssembly(); string appDirectory = Path.GetDirectoryName(assembly.Location); if (this.addDefault) { switch (Path.GetExtension(inputFile).ToLower(CultureInfo.InvariantCulture)) { case msm: validator.AddCubeFile(Path.Combine(appDirectory, "mergemod.cub")); break; case msi: validator.AddCubeFile(Path.Combine(appDirectory, "darice.cub")); break; default: throw new WixException(WixErrors.UnexpectedFileExtension(inputFile, ".msi, .msm")); } } // print friendly message saying what file is being validated Console.WriteLine(Path.GetFileName(inputFile)); Stopwatch stopwatch = Stopwatch.StartNew(); try { validator.Validate(Path.GetFullPath(inputFile)); } catch (UnauthorizedAccessException) { this.messageHandler.Display(this, WixErrors.UnauthorizedAccess(Path.GetFullPath(inputFile))); } finally { stopwatch.Stop(); this.messageHandler.Display(this, WixVerboses.ValidatedDatabase(stopwatch.ElapsedMilliseconds)); if (this.tidy) { if (!validator.DeleteTempFiles()) { Console.WriteLine(SmokeStrings.WAR_FailedToDeleteTempDir, validator.TempFilesLocation); } } else { Console.WriteLine(SmokeStrings.INF_TempDirLocatedAt, validator.TempFilesLocation); } } } } catch (WixException we) { this.messageHandler.Display(this, we.Error); } catch (Exception e) { this.messageHandler.Display(this, WixErrors.UnexpectedException(e.Message, e.GetType().ToString(), e.StackTrace)); if (e is NullReferenceException || e is SEHException) { throw; } } return(this.messageHandler.LastErrorNumber); }