예제 #1
0
 public static T ExecuteSecure <T>(Func <T> f, bool CrashProgramm = false)
 {
     try
     {
         return(f());
     }
     catch (Win32Exception e)
     {
         Logger.Error("Win32 Error Code: " + e.NativeErrorCode + " (native) " + e.ErrorCode + " (managed)");
         Logger.LogException(e);
         if (CrashProgramm)
         {
             var errorUI = new FatalErrorUI("Win32 error", GetWin23ExeptionMessage(e));
             errorUI.ShowDialog();
             Program.Exit(ExitCode.WIN32_EXCPTION);
         }
     }
     catch (Exception e)
     {
         Logger.Error("Normal ERROR");
         Logger.LogException(e);
         if (CrashProgramm)
         {
             var errorUI = new FatalErrorUI("Normal Exception", GetExceptionMessage(e));
             errorUI.ShowDialog();
             Program.Exit(ExitCode.CLR_EXCPTION);
         }
     }
     return(default);
예제 #2
0
        static int Main(string[] args)
        {
            InitLogger();

            try
            {
                if (!CheckForOtherInstances())
                {
                    Exit(ExitCode.ALREADY_RUNNING);
                }
            }
            #region CheckForOtherInstances Error Handling
            catch (System.ComponentModel.Win32Exception e)
            {
                Logger.Error("Win32 Error Code: " + e.NativeErrorCode + " (native) " + e.ErrorCode + " (managed)");
                Logger.LogException(e);
                //MessageBox.Show(GetWin23ExeptionMessage(e), "Win32 error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                var errorUI = new FatalErrorUI("Win32 error", GetWin23ExeptionMessage(e));
                errorUI.ShowDialog();
                Exit(ExitCode.WIN32_EXCPTION);
            }
            catch (Exception e)
            {
                Logger.Error("Normal ERROR");
                Logger.LogException(e);
                //MessageBox.Show(GetExceptionMessage(e), "Normal Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                var errorUI = new FatalErrorUI("Normal Exception", GetExceptionMessage(e));
                errorUI.ShowDialog();
                Exit(ExitCode.CLR_EXCPTION);
            }
            #endregion

            if (args.Length > 0)
            {
                Logger.Message("Args: " + args.Aggregate("", (str1, str2) => str1 + " " + str2));
            }
            else
            {
                Logger.Message("No args");
            }

#if CREATE_LANGUAGE_XMLS
            WriteOutLanguageXmls();
#endif

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Settings settings = new Settings();
            if (settings.FirstBoot)
            {
                Logger.Message("First boot");
                Application.Run(new InitConfigUI());
                settings = new Settings();
                if (settings.FirstBoot)
                {
                    Logger.Error("Exit: INIT_SETUP_FAILED");
                    return((int)ExitCode.INIT_SETUP_FAILED);
                }
            }
            Form ui = null;

            LoadingScreenUI loadingUI = new LoadingScreenUI(async(progress, ct, cts) =>
            {
                try
                {
                    ui = await LoadApplication(progress, args, ct, cts);
                }
                catch (System.ComponentModel.Win32Exception e)
                {
                    Logger.Error("Win32 Error Code: " + e.NativeErrorCode + " (native) " + e.ErrorCode + " (managed)");
                    Logger.LogException(e);
                    //MessageBox.Show(GetWin23ExeptionMessage(e), "Win32 error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    var errorUI = new FatalErrorUI("Win32 error", GetWin23ExeptionMessage(e));
                    errorUI.ShowDialog(ui);
                    Exit(ExitCode.WIN32_EXCPTION);
                }
                catch (Exception e)
                {
                    Logger.Error("Normal ERROR");
                    Logger.LogException(e);
                    //MessageBox.Show(GetExceptionMessage(e), "Normal Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    var errorUI = new FatalErrorUI("Normal Exception", GetExceptionMessage(e));
                    errorUI.ShowDialog(ui);
                    Exit(ExitCode.CLR_EXCPTION);
                }
            });


            Application.Run(loadingUI);

            GC.Collect();

            if (ui == null)
            {
                return((int)ExitCode.STARTUP_FAILED);
            }

            try
            {
                //display ui and run
                Application.Run(ui);
            }
            catch (System.ComponentModel.Win32Exception e)
            {
                Logger.Error("Win32 Error Code: " + e.NativeErrorCode + " (native) " + e.ErrorCode + " (managed)");
                Logger.LogException(e);
                MessageBox.Show(GetWin23ExeptionMessage(e), "Win32 error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Exit(ExitCode.WIN32_EXCPTION);
            }
            catch (Exception e)
            {
                Logger.Error("Normal ERROR");
                Logger.LogException(e);
                MessageBox.Show(GetExceptionMessage(e), "Normal Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Exit(ExitCode.CLR_EXCPTION);
            }
            Cleanup();
            return((int)ExitCode.OK);
        }