BetterExplorer.App.OnStartup C# (CSharp) Метод

OnStartup() защищенный Метод

On app start
protected OnStartup ( System.Windows.StartupEventArgs e ) : void
e System.Windows.StartupEventArgs Startup EventArgs
Результат void
    protected override void OnStartup(StartupEventArgs e) {
      Process process = Process.GetCurrentProcess();
      process.PriorityClass = ProcessPriorityClass.Normal;

      // Set the current thread to run at 'Highest' Priority
      Thread thread = Thread.CurrentThread;
      thread.Priority = ThreadPriority.Highest;

      String locale = string.Empty;
      Boolean dmi = true;
      System.Windows.Forms.Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
      Current.DispatcherUnhandledException += this.Current_DispatcherUnhandledException;
      AppDomain.CurrentDomain.UnhandledException += this.CurrentDomain_UnhandledException;
      System.Windows.Forms.Application.ThreadException += this.Application_ThreadException;

      if (!File.Exists(Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer\Settings.sqlite"))) {
        var beAppDataPath = Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer");
        if (!Directory.Exists(beAppDataPath)) {
          Directory.CreateDirectory(beAppDataPath);
        }
        File.Copy(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Settings.sqlite"), Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer\Settings.sqlite"));
      }

      RegistryKey rk = Registry.CurrentUser, rks = rk.OpenSubKey(@"Software\BExplorer", true);
      if (rks == null) {
        rk.CreateSubKey(@"Software\BExplorer");
        rks = rk.OpenSubKey(@"Software\BExplorer", true);
      }

      //// loads current Ribbon color theme
      try {
        var color = Convert.ToString(rks?.GetValue("CurrentTheme", "Blue"));
        var owner = Current.MainWindow;
        if (owner != null) {
          owner.Resources.BeginInit();

          if (owner.Resources.MergedDictionaries.Count > 0) {
            owner.Resources.MergedDictionaries.RemoveAt(0);
          }

          if (string.IsNullOrEmpty(color) == false) {
            owner.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = new Uri(color) });
          }

          owner.Resources.EndInit();
        }

        Current.Resources.BeginInit();

        Current.Resources.MergedDictionaries.RemoveAt(1);

        switch (color) {
          case "Blue":
          case "Silver":
          case "Black":
          case "Green":
            Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{color}.xaml") });
            break;
          case "Metro":
            Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri("pack://application:,,,/Fluent;component/Themes/Office2013/Generic.xaml") });
            break;
          default:
            Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary() { Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{color}.xaml") });
            break;
        }

        Current.Resources.EndInit();
      } catch (Exception ex) {
        // MessageBox.Show(String.Format("An error occurred while trying to load the theme data from the Registry. \n\r \n\r{0}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/", ex.Message), "RibbonTheme Error - " + ex.ToString());
        MessageBox.Show(
          $"An error occurred while trying to load the theme data from the Registry. \n\r \n\rRibbonTheme Error - {ex}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/",
          ex.Message);
      } finally {
        rks?.Close();
      }

      rk.Close();

      if (e.Args.Any()) {
        dmi = e.Args.Length >= 1;
        IsStartWithStartupTab = e.Args.Contains("/norestore");

        if (e.Args[0] != "-minimized") {
          this.Properties["cmd"] = e.Args[0];
        } else {
          IsStartMinimized = true;
        }
      }

      if (!ApplicationInstanceManager.CreateSingleInstance(Assembly.GetExecutingAssembly().GetName().Name, this.SingleInstanceCallback) && dmi) {
        return; // exit, if same app. is running
      }

      base.OnStartup(e);

      try {
        var regLocale = Utilities.GetRegistryValue("Locale", string.Empty).ToString();
        locale = string.IsNullOrEmpty(regLocale) ? CultureInfo.CurrentUICulture.Name : regLocale;
        this.SelectCulture(locale);
      } catch {
        // MessageBox.Show(String.Format("A problem occurred while loading the locale from the Registry. This was the value in the Registry: \r\n \r\n {0}\r\n \r\nPlease report this issue at http://bugtracker.better-explorer.com/.", Locale));
        MessageBox.Show($"A problem occurred while loading the locale from the Registry. This was the value in the Registry: \r\n \r\n {locale}\r\n \r\nPlease report this issue at http://bugtracker.better-explorer.com/.");

        this.Shutdown();
      }
    }