/// <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(new MessageEventHandler(this.messageHandler.Display)); HarvesterCore harvesterCore = new HarvesterCore(new MessageEventHandler(this.messageHandler.Display)); 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 (this.messageHandler.EncounteredError) { return(this.messageHandler.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 (this.messageHandler.EncounteredError) { return(this.messageHandler.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 (this.messageHandler.EncounteredError) { return(this.messageHandler.LastErrorNumber); } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.extensionArgument); if (null == wix) { return(this.messageHandler.LastErrorNumber); } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return(this.messageHandler.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(this.messageHandler.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) { 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 heatCore = new HeatCore(new MessageEventHandler(this.messageHandler.Display)); try { // read the configuration file (heat.exe.config) AppCommon.ReadConfiguration(extensionList); // load any extensions foreach (string extensionType in extensionList) { HeatExtension heatExtension = HeatExtension.Load(extensionType); this.extensions.Add(heatExtension); foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes) { if (this.extensionsByType.Contains(commandLineOption.Option)) { throw new Exception(); } this.extensionsByType.Add(commandLineOption.Option, heatExtension); } heatExtension.Core = heatCore; } // parse the command line this.ParseCommandLine(args); // 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); if (heatCore.EncounteredError) { this.showHelp = true; } } // 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) { Assembly heatAssembly = Assembly.GetExecutingAssembly(); Console.WriteLine("Microsoft (R) Windows Installer XML Toolset Harvester version {0}", heatAssembly.GetName().Version.ToString()); Console.WriteLine("Copyright (C) Microsoft Corporation 2006. All rights reserved."); Console.WriteLine(); } if (this.showHelp) { Console.WriteLine(" usage: heat.exe harvestType <harvester arguments> -out sourceFile.wxs"); Console.WriteLine(); Console.WriteLine("Supported harvesting types (use \"heat.exe <type> -?\" for more info):"); // output the harvest types alphabetically SortedList harvestTypes = new SortedList(); foreach (HeatExtension heatExtension in this.extensions) { foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes) { harvestTypes.Add(commandLineOption.Option, commandLineOption); } } foreach (HeatCommandLineOption commandLineOption in harvestTypes.Values) { Console.WriteLine(" {0,-7} {1}", commandLineOption.Option, commandLineOption.Description); } Console.WriteLine(); Console.WriteLine(" -nologo skip printing heat logo information"); Console.WriteLine(" -out specify output file (default: write to current directory)"); Console.WriteLine(" -sw<N> suppress warning with specific message ID"); Console.WriteLine(" -v verbose output"); Console.WriteLine(" -? this help information"); Console.WriteLine(""); Console.WriteLine("For more information see: http://wix.sourceforge.net"); return(this.messageHandler.LastErrorNumber); } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.extensionArgument); if (null == wix) { return(this.messageHandler.LastErrorNumber); } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return(this.messageHandler.LastErrorNumber); } XmlTextWriter writer = null; try { 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(); } 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; } } 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(new MessageEventHandler(this.messageHandler.Display)); HarvesterCore harvesterCore = new HarvesterCore(new MessageEventHandler(this.messageHandler.Display)); 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 (this.messageHandler.EncounteredError) { return this.messageHandler.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 (this.messageHandler.EncounteredError) { return this.messageHandler.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 (this.messageHandler.EncounteredError) { return this.messageHandler.LastErrorNumber; } // harvest the output Wix.Wix wix = heatCore.Harvester.Harvest(this.extensionArgument); if (null == wix) { return this.messageHandler.LastErrorNumber; } // mutate the output if (!heatCore.Mutator.Mutate(wix)) { return this.messageHandler.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 this.messageHandler.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) { 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; }