コード例 #1
0
ファイル: heat.cs プロジェクト: naderm1991/tutorial-wix
        private void LoadExtension(string extensionType)
        {
            HeatExtension heatExtension = HeatExtension.Load(extensionType);

            heatExtension.MessageHandler = this.messageHandler;

            this.extensions.Add(heatExtension);

            foreach (HeatCommandLineOption commandLineOption in heatExtension.CommandLineTypes)
            {
                if (this.extensionsByType.Contains(commandLineOption.Option))
                {
                    this.messageHandler.Display(this, WixErrors.DuplicateCommandLineOptionInExtension(commandLineOption.Option));
                    return;
                }

                this.extensionsByType.Add(commandLineOption.Option, heatExtension);
            }

            heatExtension.Core = heatCore;
        }
コード例 #2
0
        /// <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);
        }