コード例 #1
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        // NOTE: No [STAThread] here, because it could block .NET remoting callbacks
        private static int Main(string[] args)
        {
            ProgramUtils.Init();
            WindowsUtils.SetCurrentProcessAppID("ZeroInstall");
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            ErrorReportForm.SetupMonitoring(new Uri("https://0install.de/error-report/"));

            using var handler = new GuiCommandHandler();
            return((int)ProgramUtils.Run(ExeName, args, handler));
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: isabella232/0install-win
        [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();
                }
            }
        }