/// <summary>
        /// Split and apply command-lines for executable bindings.
        /// This is delayed until the end because environment variables that might be modified are expanded.
        /// </summary>
        private void ProcessRunEnvBindings()
        {
            foreach (var runEnv in _runEnvPendings)
            {
                var commandLine = ExpandCommandLine(runEnv.CommandLine);
                if (WindowsUtils.IsWindows)
                {
                    var split = SplitCommandLine(commandLine);
                    _startInfo.EnvironmentVariables["ZEROINSTALL_RUNENV_FILE_" + runEnv.ExeName] = split.Path;
                    _startInfo.EnvironmentVariables["ZEROINSTALL_RUNENV_ARGS_" + runEnv.ExeName] = split.Arguments;
                }
                else
                {
                    _startInfo.EnvironmentVariables["ZEROINSTALL_RUNENV_" + runEnv.ExeName] = commandLine.JoinEscapeArguments();
                }
            }
            _runEnvPendings.Clear();

            try
            {
                // Allow Linux-version of Zero Install and other tools to call back to the Fetcher
                var fetchCommand = ProcessUtils.Assembly("0install", "fetch");
                _startInfo.EnvironmentVariables["ZEROINSTALL_EXTERNAL_FETCHER"] = fetchCommand.FileName.EscapeArgument() + " " + fetchCommand.Arguments;
            }
            catch (FileNotFoundException)
            {
                // Zero Install may be embedded as a library rather than an executable
            }
        }
Beispiel #2
0
        /// <summary>
        /// Executes a "0install" command in a new background process. Returns immediately.
        /// </summary>
        /// <param name="command">The <see cref="CliCommand.Name"/> of the command to execute.</param>
        /// <param name="args">Additional arguments to pass to the command.</param>
        protected static void RunCommandBackground([NotNull] string command, [NotNull] params string[] args)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(command))
            {
                throw new ArgumentNullException("command");
            }
            #endregion

            if (ProgramUtils.GuiAssemblyName == null)
            {
                Log.Info("Skipping background command because there is no GUI subsystem available");
                return;
            }

            try
            {
                ProcessUtils.Assembly(ProgramUtils.GuiAssemblyName, args.Prepend("--background").Prepend(command)).Start();
            }
            #region Error handling
            catch (OperationCanceledException)
            {}
            catch (IOException ex)
            {
                Log.Warn(ex);
            }
            #endregion
        }
Beispiel #3
0
    /// <summary>
    /// Starts executing a command in a background process. Returns immediately.
    /// </summary>
    /// <param name="command">The name of the command to execute.</param>
    /// <param name="args">Additional arguments to pass to the command.</param>
    protected static void StartCommandBackground(string command, params string[] args)
    {
        #region Sanity checks
        if (string.IsNullOrEmpty(command))
        {
            throw new ArgumentNullException(nameof(command));
        }
        #endregion

        if (ProgramUtils.GuiAssemblyName == null)
        {
            Log.Info("Skipping background command because there is no GUI subsystem available");
            return;
        }

        try
        {
            var startInfo = ProcessUtils.Assembly(ProgramUtils.GuiAssemblyName, new[] { command, "--background" }.Concat(args).ToArray());
            startInfo.WorkingDirectory = Locations.InstallBase; // Avoid locking the user's working directory
            startInfo.Start();
        }
        #region Error handling
        catch (OperationCanceledException)
        {}
        catch (IOException ex)
        {
            Log.Warn(ex);
        }
        #endregion
    }
Beispiel #4
0
        /// <summary>
        /// Runs the application (called by main method or by embedding process).
        /// </summary>
        public static int Run(string[] args)
        {
            bool machineWide = args.Any(arg => arg == "-m" || arg == "--machine");

            if (machineWide && WindowsUtils.IsWindowsNT && !WindowsUtils.IsAdministrator)
            {
                try
                {
                    return(ProcessUtils.Assembly(ExeName, args).AsAdmin().Run());
                }
                #region Error handling
                catch (OperationCanceledException)
                {
                    return((int)ExitCode.UserCanceled);
                }
                catch (IOException ex)
                {
                    Log.Error(ex);
                    return((int)ExitCode.IOError);
                }
                #endregion
            }

            var window = new MainWindow();
            window.DeleteEvent += delegate { Application.Quit(); };
            window.Show();
            Application.Run();
            return(0);
        }
Beispiel #5
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            if (_machineWide && !WindowsUtils.IsAdministrator)
            {
                throw new NotAdminException(Resources.MustBeAdminForMachineWide);
            }

            return((ExitCode)ProcessUtils.Assembly(WindowsUtils.IsWindows ? "ZeroInstall" : "ZeroInstall-gtk").Run());
        }
Beispiel #6
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            string assembly  = WindowsUtils.IsWindows ? "ZeroInstall" : "ZeroInstall-gtk";
            var    startInfo = _machineWide
                ? ProcessUtils.Assembly(assembly, "-m").AsAdmin()
                : ProcessUtils.Assembly(assembly);

            return((ExitCode)startInfo.Run());
        }
 private static void RestartCentral(string targetDir)
 {
     if (ProgramUtils.GuiAssemblyName != null)
     {
         var startInfo = WindowsUtils.IsWindowsVista
                         // Use explorer.exe to return to standard user privileges after UAC elevation
             ? new ProcessStartInfo("explorer.exe", Path.Combine(targetDir, "ZeroInstall.exe").EscapeArgument())
             : ProcessUtils.Assembly(Path.Combine(targetDir, ProgramUtils.GuiAssemblyName), Central.Name);
         startInfo.Start();
     }
 }
Beispiel #8
0
 /// <summary>
 /// Creates a <see cref="ProcessStartInfo"/> for launching an instance of the 0install command-line interface.
 /// </summary>
 public static ProcessStartInfo?CliStartInfo(params string[] arguments)
 {
     try
     {
         return(ProcessUtils.Assembly("0install", arguments));
     }
     catch (FileNotFoundException)
     {
         return(null);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Tries to run a command in another instance of Zero Install deployed on this system.
        /// </summary>
        /// <param name="exeName">The name of the executable to call in the target instance.</param>
        /// <param name="args">The arguments to pass to the target instance.</param>
        /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param>
        /// <param name="needsMachineWide"><c>true</c> if a machine-wide install location is required; <c>false</c> if a user-specific location will also do.</param>
        /// <returns>The exit code returned by the other instance; <c>null</c> if no other instance could be found.</returns>
        /// <exception cref="IOException">There was a problem launching the target instance.</exception>
        /// <exception cref="NotAdminException">The target process requires elevation.</exception>
        private static ExitCode?TryRunOtherInstance([NotNull] string exeName, [NotNull] string[] args, [NotNull] ICommandHandler handler, bool needsMachineWide)
        {
            string installLocation = FindOtherInstance(needsMachineWide);

            if (installLocation == null)
            {
                return(null);
            }

            Log.Warn("Redirecting to instance at " + installLocation);
            handler.DisableUI();
            return((ExitCode)ProcessUtils.Assembly(Path.Combine(installLocation, exeName), args).Run());
        }
Beispiel #10
0
    /// <inheritdoc/>
    public override ExitCode Execute()
    {
        if (_machineWide && WindowsUtils.IsWindows && !WindowsUtils.IsAdministrator)
        {
            throw new NotAdminException(Resources.MustBeAdminForMachineWide);
        }

        var process = _machineWide
            ? ProcessUtils.Assembly("ZeroInstall", "--machine")
            : ProcessUtils.Assembly("ZeroInstall");

        return((ExitCode)process.Run());
    }
Beispiel #11
0
        [STAThread] // Required for WinForms
        public static int Run(string[] args)
        {
            bool machineWide = args.Any(arg => arg == "-m" || arg == "--machine");

            if (machineWide && WindowsUtils.IsWindowsNT && !WindowsUtils.IsAdministrator)
            {
                try
                {
                    return(ProcessUtils.Assembly(ExeName, args).AsAdmin().Run());
                }
                #region Error handling
                catch (OperationCanceledException)
                {
                    return((int)ExitCode.UserCanceled);
                }
                catch (IOException ex)
                {
                    Log.Error(ex);
                    return((int)ExitCode.IOError);
                }
                #endregion
            }

            try
            {
                Application.Run(new MainForm(machineWide));
            }
            #region Error handling
            catch (IOException ex)
            {
                Log.Error(ex);
                Msg.Inform(null, ex.Message, MsgSeverity.Error);
                return(-1);
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Error(ex);
                Msg.Inform(null, ex.Message, MsgSeverity.Error);
                return(-1);
            }
            catch (InvalidDataException ex)
            {
                Log.Error(ex);
                Msg.Inform(null, ex.Message + (ex.InnerException == null ? "" : "\n" + ex.InnerException.Message), MsgSeverity.Error);
                return(-1);
            }
            #endregion

            return(0);
        }
 private void buttonRunAsAdmin_Click(object sender, EventArgs e)
 {
     try
     {
         ProcessUtils.Assembly(Program.ExeName, "store", "manage").AsAdmin().Start();
         Close();
     }
     #region Error handling
     catch (OperationCanceledException)
     {}
     catch (IOException ex)
     {
         Msg.Inform(this, ex.Message, MsgSeverity.Error);
     }
     #endregion
 }
Beispiel #13
0
    /// <summary>
    /// Creates a <see cref="ProcessStartInfo"/> for launching an instance of the 0install graphical interface.
    /// </summary>
    public static ProcessStartInfo?GuiStartInfo(params string[] arguments)
    {
        if (!WindowsUtils.IsGuiSession)
        {
            return(null);
        }

        try
        {
            return(ProcessUtils.Assembly("0install-win", arguments));
        }
        catch (FileNotFoundException)
        {
            return(null);
        }
    }
Beispiel #14
0
 /// <summary>
 /// Reruns the updater using elevated permissions (as administartor).
 /// </summary>
 private void RerunElevated()
 {
     try
     {
         ProcessUtils.Assembly("0update-win", _updateProcess.Source, _updateProcess.NewVersion.ToString(), _updateProcess.Target, "--rerun").AsAdmin().Run();
     }
     #region Error handling
     catch (OperationCanceledException)
     {}
     catch (IOException ex)
     {
         Log.Warn("Rerunning elevated failed");
         Log.Warn(ex);
     }
     #endregion
 }
Beispiel #15
0
 private void labelSelfUpdateMessage_Click(object sender, EventArgs e)
 {
     try
     {
         ProcessUtils.Assembly("0install-win", SelfUpdate.Name, "--batch", "--restart-central").Start();
         Application.Exit();
     }
     #region Error handling
     catch (OperationCanceledException)
     {}
     catch (IOException ex)
     {
         Msg.Inform(this, ex.Message, MsgSeverity.Error);
     }
     #endregion
 }
Beispiel #16
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            try
            {
                ProcessUtils.Assembly("0install-win", GetArgs().ToArray()).Start();
            }
            #region Error handling
            catch (OperationCanceledException)
            {}
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            #endregion

            Close();
        }
 private void buttonRunAsAdmin_Click(object sender, EventArgs e)
 {
     try
     {
         ProcessUtils.Assembly(Program.ExeName, StoreMan.Name, "manage").AsAdmin().Start();
     }
     catch (PlatformNotSupportedException ex)
     {
         Msg.Inform(this, ex.Message, MsgSeverity.Error);
         return;
     }
     catch (OperationCanceledException)
     {
         return;
     }
     Close();
 }
Beispiel #18
0
        private void buttonRun_Click(object sender, EventArgs e)
        {
            if (dataGrid.CurrentRow == null)
            {
                return;
            }
            var result = _results[dataGrid.CurrentRow.Index];

            try
            {
                ProcessUtils.Assembly(Program.ExeName, "run", "--no-wait", result.Uri.ToStringRfc()).Start();
            }
            #region Error handling
            catch (OperationCanceledException)
            {}
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            #endregion
        }
Beispiel #19
0
        private ProcessStartInfo GetExistingInstance()
        {
            if (!WindowsUtils.IsWindows)
            {
                return(null);
            }

            string existingInstall = RegistryUtils.GetSoftwareString("Zero Install", "InstallLocation");

            if (!string.IsNullOrEmpty(existingInstall))
            {
                string launchAssembly = _gui
                    ? "0install-win" //(WindowsUtils.IsWindows ? "0install-win" : "0install-gtk")
                    : "0install";

                if (File.Exists(Path.Combine(existingInstall, launchAssembly + ".exe")))
                {
                    return(ProcessUtils.Assembly(Path.Combine(existingInstall, launchAssembly), _targetArgs.ToArray()));
                }
            }
            return(null);
        }
Beispiel #20
0
            /// <summary>
            /// Deploys a portable copy of Zero Install to a temp directory and delegates the actual removal of the current instance to this copy.
            /// </summary>
            private void DelegateToTempCopy()
            {
                string tempDir = FileUtils.GetTempDirectory("0install-remove");

                using (var manager = new SelfManager(tempDir, Handler, machineWide: false, portable: true))
                    manager.Deploy();

                string assembly = Path.Combine(tempDir, ProgramUtils.GuiAssemblyName ?? "0install");

                var args = new[] { Self.Name, RemoveHelper.Name, Locations.InstallBase };

                if (Handler.Verbosity == Verbosity.Batch)
                {
                    args = args.Append("--batch");
                }
                if (Handler.Background)
                {
                    args = args.Append("--background");
                }

                ProcessUtils.Assembly(assembly, args).Start();
            }
Beispiel #21
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            // Differentiate between entry point describing a command and a direct command
            var    entryPoint = comboBoxCommand.SelectedItem as EntryPointWrapper;
            string command    = (entryPoint == null) ? comboBoxCommand.Text : entryPoint.GetCommand();

            try
            {
                // Cannot use in-process method here because the "args" string needs to be parsed by the operating system
                ProcessUtils.Assembly(Commands.WinForms.Program.ExeName,
                                      "run", "--no-wait", "--command", command, _target.Uri.ToStringRfc(), textBoxArgs.Text).Start();
            }
            #region Error handling
            catch (OperationCanceledException)
            {}
            catch (IOException ex)
            {
                Msg.Inform(this, ex.Message, MsgSeverity.Error);
            }
            #endregion

            Close();
        }
Beispiel #22
0
        /// <summary>
        /// Runs the application (called by main method or by embedding process).
        /// </summary>
        public static ExitCode Run(string[] args)
        {
            var handler = new CliCommandHandler();

            try
            {
                var command = new StoreMan(handler);
                command.Parse(args);
                return(command.Execute());
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                return(ExitCode.UserCanceled);
            }
            catch (NeedGuiException ex)
            {
                if (ProgramUtils.GuiAssemblyName == null)
                {
                    Log.Error(ex);
                    return(ExitCode.InvalidArguments);
                }
                else
                {
                    Log.Info("Switching to GUI");
                    try
                    {
                        return((ExitCode)ProcessUtils.Assembly(ProgramUtils.GuiAssemblyName, args.Prepend(StoreMan.Name)).Run());
                    }
                    #region Error handling
                    catch (OperationCanceledException)
                    {
                        return(ExitCode.UserCanceled);
                    }
                    catch (IOException ex2)
                    {
                        Log.Error(ex2);
                        return(ExitCode.IOError);
                    }
                    #endregion
                }
            }
            catch (NotAdminException ex)
            {
                if (WindowsUtils.IsWindowsNT)
                {
                    try
                    {
                        return((ExitCode)ProcessUtils.Assembly(ProgramUtils.GuiAssemblyName ?? "0install", args.Prepend(StoreMan.Name)).AsAdmin().Run());
                    }
                    #region Error handling
                    catch (OperationCanceledException)
                    {
                        return(ExitCode.UserCanceled);
                    }
                    catch (IOException ex2)
                    {
                        Log.Error(ex2);
                        return(ExitCode.IOError);
                    }
                    #endregion
                }
                else
                {
                    Log.Error(ex);
                    return(ExitCode.AccessDenied);
                }
            }
            catch (OptionException ex)
            {
                var builder = new StringBuilder(ex.Message);
                if (ex.InnerException != null)
                {
                    builder.Append("\n" + ex.InnerException.Message);
                }
                builder.Append("\n" + string.Format(Resources.TryHelp, ExeName));
                Log.Error(builder.ToString());
                return(ExitCode.InvalidArguments);
            }
            catch (FormatException ex)
            {
                Log.Error(ex);
                return(ExitCode.InvalidArguments);
            }
            catch (WebException ex)
            {
                Log.Error(ex);
                return(ExitCode.WebError);
            }
            catch (NotSupportedException ex)
            {
                Log.Error(ex);
                return(ExitCode.NotSupported);
            }
            catch (IOException ex)
            {
                Log.Error(ex);
                return(ExitCode.IOError);
            }
            catch (UnauthorizedAccessException ex)
            {
                Log.Error(ex);
                return(ExitCode.AccessDenied);
            }
            catch (InvalidDataException ex)
            {
                Log.Error(ex);
                return(ExitCode.InvalidData);
            }
            catch (SignatureException ex)
            {
                Log.Error(ex);
                return(ExitCode.InvalidSignature);
            }
            catch (DigestMismatchException ex)
            {
                Log.Error(ex);
                return(ExitCode.DigestMismatch);
            }
            #endregion

            finally
            {
                handler.CloseUI();
            }
        }
Beispiel #23
0
                : null; //(UnixUtils.HasGui ? "0install-gtk" : null);

        /// <summary>
        /// Parses command-line arguments and performs the indicated action. Performs error handling.
        /// </summary>
        /// <param name="exeName">The name of the executable to use as a reference in help messages and self-invokation.</param>
        /// <param name="args">The arguments to be processed.</param>
        /// <param name="handler">A callback object used when the the user needs to be asked questions or informed about download and IO tasks.</param>
        /// <returns>The exit status code to end the process with. Cast to <see cref="int"/> to return from a Main method.</returns>
        public static ExitCode Run([NotNull] string exeName, [NotNull] string[] args, [NotNull] ICommandHandler handler)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(exeName))
            {
                throw new ArgumentNullException(nameof(exeName));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            try
            {
                var command = CommandFactory.CreateAndParse(args, handler);
                return(command.Execute());
            }
            #region Error handling
            catch (OperationCanceledException)
            {
                return(ExitCode.UserCanceled);
            }
            catch (NeedGuiException ex)
            {
                if (GuiAssemblyName != null)
                {
                    Log.Info("Switching to GUI");
                    handler.DisableUI();
                    try
                    {
                        return((ExitCode)ProcessUtils.Assembly(GuiAssemblyName, args).Run());
                    }
                    catch (IOException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.IOError);
                    }
                    catch (NotAdminException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.AccessDenied);
                    }
                }
                else
                {
                    handler.Error(ex);
                    return(ExitCode.NotSupported);
                }
            }
            catch (NotAdminException ex)
            {
                if (WindowsUtils.HasUac)
                {
                    Log.Info("Elevating to admin");
                    handler.DisableUI();
                    try
                    {
                        return((ExitCode)ProcessUtils.Assembly(GuiAssemblyName ?? exeName, args).AsAdmin().Run());
                    }
                    catch (PlatformNotSupportedException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.NotSupported);
                    }
                    catch (IOException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.IOError);
                    }
                    catch (NotAdminException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.AccessDenied);
                    }
                    catch (OperationCanceledException)
                    {
                        return(ExitCode.UserCanceled);
                    }
                }
                else
                {
                    handler.Error(ex);
                    return(ExitCode.AccessDenied);
                }
            }
            catch (UnsuitableInstallBaseException ex)
            {
                if (WindowsUtils.IsWindows)
                {
                    try
                    {
                        var result = TryRunOtherInstance(exeName, args, handler, ex.NeedsMachineWide);
                        if (result.HasValue)
                        {
                            return(result.Value);
                        }
                        else if (handler.Ask(Resources.AskDeployZeroInstall + Environment.NewLine + ex.Message,
                                             defaultAnswer: false, alternateMessage: ex.Message))
                        {
                            var deployArgs = new[] { MaintenanceMan.Name, MaintenanceMan.Deploy.Name, "--batch" };
                            if (ex.NeedsMachineWide)
                            {
                                deployArgs = deployArgs.Append("--machine");
                            }
                            var deployResult = Run(exeName, deployArgs, handler);
                            if (deployResult == ExitCode.OK)
                            {
                                result = TryRunOtherInstance(exeName, args, handler, ex.NeedsMachineWide);
                                if (result.HasValue)
                                {
                                    return(result.Value);
                                }
                                else
                                {
                                    throw new IOException("Unable to find newly installed instance.");
                                }
                            }
                            else
                            {
                                return(deployResult);
                            }
                        }
                    }
                    catch (IOException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.IOError);
                    }
                    catch (NotAdminException ex2)
                    {
                        handler.Error(ex2);
                        return(ExitCode.AccessDenied);
                    }
                }
                else
                {
                    handler.Error(ex);
                }

                return(ExitCode.NotSupported);
            }
            catch (OptionException ex)
            {
                handler.Error(new OptionException(ex.Message + Environment.NewLine + string.Format(Resources.TryHelp, exeName), ex.OptionName));
                return(ExitCode.InvalidArguments);
            }
            catch (FormatException ex)
            {
                handler.Error(ex);
                return(ExitCode.InvalidArguments);
            }
            catch (WebException ex)
            {
                handler.Error(ex);
                return(ExitCode.WebError);
            }
            catch (NotSupportedException ex)
            {
                handler.Error(ex);
                return(ExitCode.NotSupported);
            }
            catch (IOException ex)
            {
                handler.Error(ex);
                return(ExitCode.IOError);
            }
            catch (UnauthorizedAccessException ex)
            {
                handler.Error(ex);
                return(ExitCode.AccessDenied);
            }
            catch (InvalidDataException ex)
            {
                handler.Error(ex);
                return(ExitCode.InvalidData);
            }
            catch (SignatureException ex)
            {
                handler.Error(ex);
                return(ExitCode.InvalidSignature);
            }
            catch (DigestMismatchException ex)
            {
                handler.Error(ex);
                return(ExitCode.DigestMismatch);
            }
            catch (SolverException ex)
            {
                handler.Error(ex);
                return(ExitCode.SolverError);
            }
            catch (ExecutorException ex)
            {
                handler.Error(ex);
                return(ExitCode.ExecutorError);
            }
            catch (ConflictException ex)
            {
                handler.Error(ex);
                return(ExitCode.Conflict);
            }
            #endregion

            finally
            {
                handler.CloseUI();
            }
        }
Beispiel #24
0
        [STAThread] // Required for WinForms
        public static ExitCode Run(string[] args)
        {
            Log.Debug("Zero Install Command WinForms GUI started with: " + args.JoinEscapeArguments());

            using (var handler = new GuiCommandHandler())
            {
                try
                {
                    var command = CommandFactory.CreateAndParse(args, handler);
                    return(command.Execute());
                }
                #region Error handling
                catch (OperationCanceledException)
                {
                    return(ExitCode.UserCanceled);
                }
                catch (NotAdminException ex)
                {
                    handler.DisableUI();
                    if (WindowsUtils.IsWindowsNT)
                    {
                        try
                        {
                            return((ExitCode)ProcessUtils.Assembly(ExeName, args).AsAdmin().Run());
                        }
                        #region Error handling
                        catch (OperationCanceledException)
                        {
                            return(ExitCode.UserCanceled);
                        }
                        catch (IOException ex2)
                        {
                            Log.Error(ex2);
                            return(ExitCode.IOError);
                        }
                        #endregion
                    }
                    else
                    {
                        Log.Error(ex);
                        Msg.Inform(null, ex.Message, MsgSeverity.Warn);
                        return(ExitCode.AccessDenied);
                    }
                }
                catch (OptionException ex)
                {
                    var builder = new StringBuilder(ex.Message);
                    if (ex.InnerException != null)
                    {
                        builder.Append("\n" + ex.InnerException.Message);
                    }
                    builder.Append("\n" + string.Format(Resources.TryHelp, ExeName));
                    Msg.Inform(null, builder.ToString(), MsgSeverity.Warn);
                    return(ExitCode.InvalidArguments);
                }
                catch (FormatException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.InvalidArguments);
                }
                catch (WebException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.WebError);
                }
                catch (NotSupportedException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.NotSupported);
                }
                catch (IOException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.IOError);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.AccessDenied);
                }
                catch (InvalidDataException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.InvalidData);
                }
                catch (SignatureException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.InvalidSignature);
                }
                catch (DigestMismatchException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, Resources.DownloadDamaged, handler.ErrorLog);
                    return(ExitCode.DigestMismatch);
                }
                catch (SolverException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message.GetLeftPartAtFirstOccurrence(Environment.NewLine), handler.ErrorLog);
                    return(ExitCode.SolverError);
                }
                catch (ExecutorException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.ExecutorError);
                }
                catch (ConflictException ex)
                {
                    Log.Error(ex);
                    handler.DisableUI();
                    ErrorBox.Show(null, ex.Message, handler.ErrorLog);
                    return(ExitCode.Conflict);
                }
                #endregion

                finally
                {
                    handler.CloseUI();
                }
            }
        }