コード例 #1
0
ファイル: App.xaml.cs プロジェクト: zhengpj-work/ScreenToGif
        internal void ShowException(Exception exception)
        {
            lock (_lock)
            {
                //Avoid displaying an exception that is already being displayed.
                if (_exceptionList.Any(a => a.Message == exception.Message))
                {
                    return;
                }

                //Adding to the list, so a second exception with the same name won't be displayed.
                _exceptionList.Add(exception);

                if (Global.IsHotFix4055002Installed && exception is XamlParseException && exception.InnerException is TargetInvocationException)
                {
                    ExceptionDialog.Ok(exception, "ScreenToGif", "Error while rendering visuals", exception.Message);
                }
                else
                {
                    ExceptionDialog.Ok(exception, "ScreenToGif", "Unhandled exception", exception.Message);
                }

                //By removing the exception, the same exception can be displayed later.
                _exceptionList.Remove(exception);
            }
        }
コード例 #2
0
 internal void ShowException(Exception exception)
 {
     if (Global.IsHotFix4055002Installed && exception is XamlParseException && exception.InnerException is TargetInvocationException)
     {
         ExceptionDialog.Ok(exception, "ScreenToGif", "Error while rendering visuals", exception.Message);
     }
     else
     {
         ExceptionDialog.Ok(exception, "ScreenToGif", "Unhandled exception", exception.Message);
     }
 }
コード例 #3
0
    private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
    {
        LogWriter.Log(e.Exception, "On Dispacher Unhandled Exception - Unknown");

        try
        {
            ExceptionDialog.Ok(e.Exception, "ScreenToGif - Translator", "Unhandled exception", e.Exception.Message);
        }
        catch (Exception ex)
        {
            LogWriter.Log(ex, "Error while displaying the error.");
            //Ignored.
        }

        e.Handled = true;
    }
コード例 #4
0
    private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        if (e.ExceptionObject is not Exception exception)
        {
            return;
        }

        LogWriter.Log(exception, "Current Domain Unhandled Exception - Unknown");

        try
        {
            ExceptionDialog.Ok(exception, "ScreenToGif - Translator", "Unhandled exception", exception.Message);
        }
        catch (Exception)
        {
            //Ignored.
        }
    }
コード例 #5
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Global.StartupDateTime = DateTime.Now;

            //Unhandled Exceptions.
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;

            //Increases the duration of the tooltip display.
            ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(int.MaxValue));

            #region Arguments

            try
            {
                if (e.Args.Length > 0)
                {
                    Argument.Prepare(e.Args);
                }
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Parsing arguments");

                ExceptionDialog.Ok(ex, "ScreenToGif", "Error while parsing arguments", ex.Message);
            }

            #endregion

            #region Language

            try
            {
                LocalizationHelper.SelectCulture(UserSettings.All.LanguageCode);
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Language Settings Exception");

                ExceptionDialog.Ok(ex, "ScreenToGif", "Error while detecting the app's language", ex.Message);
            }

            #endregion

            #region Net Framework

            var array  = Type.GetType("System.Array");
            var method = array?.GetMethod("Empty");

            if (array == null || method == null)
            {
                var ask = Dialog.Ask("Missing Dependency", "Net Framework 4.6.1 is not present", "In order to properly use this app, you need to download the correct version of the .Net Framework. Open the web page to download?");

                if (ask)
                {
                    Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=49981");
                    return;
                }
            }

            #endregion

            #region Net Framework HotFixes

            if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
            {
                Task.Factory.StartNew(() =>
                {
                    try
                    {
                        var search = new ManagementObjectSearcher("SELECT HotFixID FROM Win32_QuickFixEngineering WHERE HotFixID = 'KB4055002'").Get();
                        Global.IsHotFix4055002Installed = search.Count > 0;
                    }
                    catch (Exception ex)
                    {
                        LogWriter.Log(ex, "Error while trying to know if a hot fix was installed.");
                    }
                });
            }

            #endregion

            #region Tray icon and view model

            NotifyIcon = (NotifyIcon)FindResource("NotifyIcon");

            if (NotifyIcon != null)
            {
                NotifyIcon.Visibility = UserSettings.All.ShowNotificationIcon ? Visibility.Visible : Visibility.Collapsed;
            }

            MainViewModel = (ApplicationViewModel)FindResource("AppViewModel") ?? new ApplicationViewModel();

            RegisterShortcuts();

            #endregion

            //var select = new SelectFolderDialog(); select.ShowDialog(); return;
            //var select = new TestField(); select.ShowDialog(); return;
            //var select = new Encoder(); select.ShowDialog(); return;

            try
            {
                #region Startup

                if (UserSettings.All.StartUp == 4 || Argument.FileNames.Any())
                {
                    MainViewModel.OpenEditor.Execute(null);
                    return;
                }

                if (UserSettings.All.StartUp == 0)
                {
                    MainViewModel.OpenLauncher.Execute(null);
                    return;
                }

                if (UserSettings.All.StartUp == 1)
                {
                    MainViewModel.OpenRecorder.Execute(null);
                    return;
                }

                if (UserSettings.All.StartUp == 2)
                {
                    MainViewModel.OpenWebcamRecorder.Execute(null);
                    return;
                }

                if (UserSettings.All.StartUp == 3)
                {
                    MainViewModel.OpenBoardRecorder.Execute(null);
                }

                #endregion
            }
            catch (Exception ex)
            {
                LogWriter.Log(ex, "Generic Exception - Root");

                ShowException(ex);
            }
        }