Exemplo n.º 1
0
 private void btnClose_Click(object sender, EventArgs e)
 {
     //Disregard user random Id setting if reports are disabled
     CurrentSettings.UseRandomId = cbRandom.Checked && !cbStopReporting.Checked;
     //User disabled reports
     if (!CurrentSettings.DisableUsageReport && cbStopReporting.Checked)
     {
         FeatureReport.Used(FeatureReport.Feature.DisableReport);
         FeatureReport.Report();
         CurrentSettings.ReportId = FeatureReport.Id = Guid.Empty;
     }
     else if (CurrentSettings.ReportId == Guid.Empty && !cbStopReporting.Checked)
     {
         //Generate a new Id if reports are enabled and no Id is present
         CurrentSettings.ReportId = FeatureReport.Id = Guid.NewGuid();
     }
     Close();
 }
Exemplo n.º 2
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            FeatureReport.Used(FeatureReport.Feature.TerminateByError);
            FeatureReport.Report();
            if (e.ExceptionObject is Exception)
            {
                Log.Write("{0}: Unhandled exception", nameof(ErrorHandler));
                Log.Write((Exception)e.ExceptionObject);
            }
            else
            {
                Log.Write("{0}: Unhandled Exception: {1}", nameof(ErrorHandler), e.ExceptionObject == null ? "<no data given>" : e.ExceptionObject.ToString());
            }
            using (var f = new frmErrorHandler((Exception)e.ExceptionObject, this))
            {
                f.ShowDialog();
            }
            Log.Write("{0}: Application terminating abnormally", nameof(ErrorHandler));
            Log.Close();
            Process P = Process.GetCurrentProcess();

            P.Kill();
            P.WaitForExit();
        }
Exemplo n.º 3
0
        static int Main(string[] args)
        {
            Log.Write("Application version {0} start", Tools.CurrentVersion);
            FeatureReport.Id = Guid.Empty;
            //Set "NOFORM" to better experiment
#if !NOFORM
#if !DEBUG
            var ReleaseModeErrorHandler = new ErrorHandler();
            ReleaseModeErrorHandler.ErrorReport += delegate(Exception ex, ErrorHandlerEventArgs e)
            {
                Log.Write("Sending error report");
                var    Msg         = ErrorHandler.generateReport(ex);
                var    MainForm    = Tools.GetForm <frmMain>();
                byte[] CurrentFile = null;
                if (MainForm != null && MainForm.HasFileOpen)
                {
                    var F = MainForm.CurrentFile;
                    using (var MS = new MemoryStream())
                    {
                        F.Export(MS);
                        MS.Position = 0;
                        CurrentFile = Compression.CompressData(MS.ToArray());
                    }
                }
                //Send report
                e.Handled = ReleaseModeErrorHandler.UploadReport(Msg, CurrentFile == null ? new byte[0] : CurrentFile);
            };
#endif
            //Perform update automatically if it's pending
            if (!DEBUG && args.Length == 0 && File.Exists(UpdateHandler.DefaultUpdateExecutable))
            {
                if (UpdateHandler.PerformUpdate())
                {
                    Log.Write("Application version {0} end (Update success)", Tools.CurrentVersion);
                    Log.Close();
                    return(RET.SUCCESS);
                }
            }
            //Only run main application part if no update was performed
            if (DEBUG || !UpdateHandler.Update())
            {
#if DEBUG
                FeatureReport.Used(FeatureReport.Feature.DebugMode);
#endif
                int Status = HandleArguments(args);
                if (Status == RET.UI)
                {
                    //Remove console handle to not block any scripts.
                    Tools.FreeConsole();
                    QuickPlay.CheckQuickPlay();
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new frmMain(args.FirstOrDefault()));
                }
                else if (DEBUG)
                {
                    return(Exit(RET.SUCCESS));
                }
                //Send Report
                FeatureReport.Report();
            }
            Log.Write("Application version {0} end", Tools.CurrentVersion);
            Log.Close();
            return(RET.SUCCESS);
#else
            Log.Write("Running in test mode");
            //Allocate console or the Console.ReadKey() will crash
            Tools.AllocConsole();

            Console.Error.WriteLine("Arguments: {0}", string.Join("\r\n", args));

            Test();
            return(Exit(RET.SUCCESS));
#endif
        }