Beispiel #1
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)
        {
            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);
        }
Beispiel #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)
        {
            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;
                }
            }

            return inscribed ? 1 : this.messageHandler.LastErrorNumber;
        }