Пример #1
0
        /// <summary>
        /// Override the startup behavior to handle files dropped on the app icon.
        /// </summary>
        /// <param name="e">
        /// The StartupEventArgs.
        /// </param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // We don't support Windows XP / 2003 / 2003 R2 / Vista / 2008
            OperatingSystem os = Environment.OSVersion;

            if (((os.Platform == PlatformID.Win32NT) && (os.Version.Major == 5)) || ((os.Platform == PlatformID.Win32NT) && (os.Version.Major == 6 && os.Version.Minor < 1)))
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsVersionWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (!Environment.Is64BitOperatingSystem)
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsBitnessWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.Equals("--reset")))
            {
                HandBrakeApp.ResetToDefaults();
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.StartsWith("--recover-queue-ids")))
            {
                string command = e.Args.FirstOrDefault(f => f.StartsWith("--recover-queue-ids"));
                if (!string.IsNullOrEmpty(command))
                {
                    command = command.Replace("--recover-queue-ids=", string.Empty);
                    List <string> processIds = command.Split(',').ToList();
                    StartupOptions.QueueRecoveryIds = processIds;
                }
            }

            if (e.Args.Any(f => f.Equals("--auto-start-queue")))
            {
                StartupOptions.AutoRestartQueue = true;
            }

            // Portable Mode
            if (Portable.IsPortable())
            {
                if (!Portable.Initialise())
                {
                    Application.Current.Shutdown();
                    return;
                }
            }

            // Setup the UI Language
            IUserSettingService userSettingService = IoC.Get <IUserSettingService>();
            string culture = userSettingService.GetUserSetting <string>(UserSettingConstants.UiLanguage);

            if (!string.IsNullOrEmpty(culture))
            {
                InterfaceLanguage language = InterfaceLanguageUtilities.FindInterfaceLanguage(culture);
                if (language != null)
                {
                    CultureInfo ci = new CultureInfo(language.Culture);
                    Thread.CurrentThread.CurrentUICulture = ci;
                }
            }

            DarkThemeMode useDarkTheme = (DarkThemeMode)userSettingService.GetUserSetting <int>(UserSettingConstants.DarkThemeMode);

            if (SystemInfo.IsWindows10())
            {
                ResourceDictionary theme = new ResourceDictionary();
                switch (useDarkTheme)
                {
                case DarkThemeMode.System:
                    if (SystemInfo.IsAppsUsingDarkTheme())
                    {
                        theme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
                        Application.Current.Resources.MergedDictionaries.Add(theme);
                    }
                    else if (!SystemParameters.HighContrast)
                    {
                        theme.Source = new Uri("Themes/Light.xaml", UriKind.Relative);
                        Application.Current.Resources.MergedDictionaries.Add(theme);
                    }
                    break;

                case DarkThemeMode.Dark:
                    theme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
                    Application.Current.Resources.MergedDictionaries.Add(theme);
                    break;

                case DarkThemeMode.Light:
                    if (!SystemParameters.HighContrast)
                    {
                        theme.Source = new Uri("Themes/Light.xaml", UriKind.Relative);
                        Application.Current.Resources.MergedDictionaries.Add(theme);
                    }

                    break;

                default:
                    break;
                }
            }

            // NO-Hardware Mode
            bool noHardware = e.Args.Any(f => f.Equals("--no-hardware")) || (Portable.IsPortable() && !Portable.IsHardwareEnabled());

            // Initialise the Engine
            HandBrakeWPF.Helpers.LogManager.Init();

            try
            {
                HandBrakeInstanceManager.Init(noHardware);
            }
            catch (Exception)
            {
                if (!noHardware)
                {
                    MessageBox.Show(HandBrakeWPF.Properties.Resources.Startup_InitFailed, HandBrakeWPF.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                throw;
            }

            // Initialise the GUI
            base.OnStartup(e);

            // If we have a file dropped on the icon, try scanning it.
            string[] args = e.Args;
            if (args.Any() && (File.Exists(args[0]) || Directory.Exists(args[0])))
            {
                IMainViewModel mvm = IoC.Get <IMainViewModel>();
                mvm.StartScan(args[0], 0);
            }
        }
Пример #2
0
        /// <summary>
        /// Override the startup behavior to handle files dropped on the app icon.
        /// </summary>
        /// <param name="e">
        /// The StartupEventArgs.
        /// </param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // We don't support Windows XP / 2003 / 2003 R2 / Vista / 2008
            OperatingSystem os = Environment.OSVersion;

            if (((os.Platform == PlatformID.Win32NT) && (os.Version.Major == 5)) || ((os.Platform == PlatformID.Win32NT) && (os.Version.Major == 6 && os.Version.Minor < 1)))
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsVersionWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (!Environment.Is64BitOperatingSystem)
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsBitnessWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.Equals("--reset")))
            {
                HandBrakeApp.ResetToDefaults();
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.StartsWith("--recover-queue-ids")))
            {
                string command = e.Args.FirstOrDefault(f => f.StartsWith("--recover-queue-ids"));
                if (!string.IsNullOrEmpty(command))
                {
                    command = command.Replace("--recover-queue-ids=", string.Empty);
                    List <string> processIds = command.Split(',').ToList();
                    StartupOptions.QueueRecoveryIds = processIds;
                }
            }

            if (e.Args.Any(f => f.Equals("--auto-start-queue")))
            {
                StartupOptions.AutoRestartQueue = true;
            }



            // Portable Mode
            if (Portable.IsPortable())
            {
                if (!Portable.Initialise())
                {
                    Application.Current.Shutdown();
                    return;
                }
            }

            // Setup the UI Language
            IUserSettingService userSettingService = IoC.Get <IUserSettingService>();
            string culture = userSettingService.GetUserSetting <string>(UserSettingConstants.UiLanguage);

            if (!string.IsNullOrEmpty(culture))
            {
                InterfaceLanguage language = InterfaceLanguageUtilities.FindInterfaceLanguage(culture);
                if (language != null)
                {
                    CultureInfo ci = new CultureInfo(language.Culture);
                    Thread.CurrentThread.CurrentUICulture = ci;
                }
            }

            int runCounter = userSettingService.GetUserSetting <int>(UserSettingConstants.RunCounter);

            if (!SystemInfo.IsWindows10() && runCounter < 2)
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OldOperatingSystem, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            // Software Rendering
            if (e.Args.Any(f => f.Equals("--force-software-rendering")) || Portable.IsForcingSoftwareRendering() || userSettingService.GetUserSetting <bool>(UserSettingConstants.ForceSoftwareRendering))
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            // Check if the user would like to check for updates AFTER the first run, but only once.
            if (runCounter == 1)
            {
                CheckForUpdateCheckPermission(userSettingService);
            }

            // Increment the counter so we can change startup behavior for the above warning and update check question.
            userSettingService.SetUserSetting(UserSettingConstants.RunCounter, runCounter + 1); // Only display once.

            // App Theme
            DarkThemeMode useDarkTheme = (DarkThemeMode)userSettingService.GetUserSetting <int>(UserSettingConstants.DarkThemeMode);

            if (SystemInfo.IsWindows10())
            {
                ResourceDictionary dark = new ResourceDictionary {
                    Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml")
                };
                ResourceDictionary light = new ResourceDictionary {
                    Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml")
                };

                ResourceDictionary theme = new ResourceDictionary();
                switch (useDarkTheme)
                {
                case DarkThemeMode.System:
                    if (SystemInfo.IsAppsUsingDarkTheme())
                    {
                        theme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
                        Application.Current.Resources.MergedDictionaries.Add(theme);
                        Application.Current.Resources.MergedDictionaries.Add(dark);
                    }
                    else if (!SystemParameters.HighContrast)
                    {
                        theme.Source = new Uri("Themes/Light.xaml", UriKind.Relative);
                        Application.Current.Resources.MergedDictionaries.Add(theme);
                        Application.Current.Resources.MergedDictionaries.Add(light);
                    }
                    break;

                case DarkThemeMode.Dark:
                    theme.Source = new Uri("Themes/Dark.xaml", UriKind.Relative);
                    Application.Current.Resources.MergedDictionaries.Add(theme);
                    Application.Current.Resources.MergedDictionaries.Add(dark);
                    break;

                case DarkThemeMode.Light:
                    if (!SystemParameters.HighContrast)
                    {
                        theme.Source = new Uri("Themes/Light.xaml", UriKind.Relative);
                        Application.Current.Resources.MergedDictionaries.Add(theme);
                        Application.Current.Resources.MergedDictionaries.Add(light);
                    }

                    break;
                }
            }

            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("Views/Styles/Styles.xaml", UriKind.Relative)
            });

            // NO-Hardware Mode
            bool noHardware = e.Args.Any(f => f.Equals("--no-hardware")) || (Portable.IsPortable() && !Portable.IsHardwareEnabled());

            // Initialise the Engine
            HandBrakeWPF.Helpers.LogManager.Init();

            try
            {
                HandBrakeInstanceManager.Init(noHardware);
            }
            catch (Exception)
            {
                if (!noHardware)
                {
                    MessageBox.Show(HandBrakeWPF.Properties.Resources.Startup_InitFailed, HandBrakeWPF.Properties.Resources.Error, MessageBoxButton.OK, MessageBoxImage.Error);
                }

                throw;
            }

            // Initialise the GUI
            base.OnStartup(e);

            // If we have a file dropped on the icon, try scanning it.
            string[] args = e.Args;
            if (args.Any() && (File.Exists(args[0]) || Directory.Exists(args[0])))
            {
                IMainViewModel mvm = IoC.Get <IMainViewModel>();
                mvm.StartScan(args[0], 0);
            }
        }
Пример #3
0
        /// <summary>
        /// Override the startup behavior to handle files dropped on the app icon.
        /// </summary>
        /// <param name="e">
        /// The StartupEventArgs.
        /// </param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // We don't support Windows XP / 2003 / 2003 R2 / Vista / 2008
            OperatingSystem os = Environment.OSVersion;

            if (((os.Platform == PlatformID.Win32NT) && (os.Version.Major == 5)) || ((os.Platform == PlatformID.Win32NT) && (os.Version.Major == 6 && os.Version.Minor < 1)))
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsVersionWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (!Environment.Is64BitOperatingSystem)
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsBitnessWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.Equals("--reset")))
            {
                HandBrakeApp.ResetToDefaults();
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.StartsWith("--recover-queue-ids")))
            {
                string command = e.Args.FirstOrDefault(f => f.StartsWith("--recover-queue-ids"));
                if (!string.IsNullOrEmpty(command))
                {
                    command = command.Replace("--recover-queue-ids=", string.Empty);
                    List <string> processIds = command.Split(',').ToList();
                    StartupOptions.QueueRecoveryIds = processIds;
                }
            }

            if (e.Args.Any(f => f.Equals("--auto-start-queue")))
            {
                StartupOptions.AutoRestartQueue = true;
            }

            // Portable Mode
            if (Portable.IsPortable())
            {
                Portable.Initialise();
            }

            // Setup the UI Language

            IUserSettingService userSettingService = IoC.Get <IUserSettingService>();
            string culture = userSettingService.GetUserSetting <string>(UserSettingConstants.UiLanguage);

            if (!string.IsNullOrEmpty(culture) && !"en".Equals(culture))
            {
                InterfaceLanguage language = InterfaceLanguageUtilities.FindInterfaceLanguage(culture);
                if (language != null)
                {
                    CultureInfo ci = new CultureInfo(language.Culture);
                    Thread.CurrentThread.CurrentCulture   = ci;
                    Thread.CurrentThread.CurrentUICulture = ci;
                }
            }

            base.OnStartup(e);

            // If we have a file dropped on the icon, try scanning it.
            string[] args = e.Args;
            if (args.Any() && (File.Exists(args[0]) || Directory.Exists(args[0])))
            {
                IMainViewModel mvm = IoC.Get <IMainViewModel>();
                mvm.StartScan(args[0], 0);
            }
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShellView"/> class.
        /// </summary>
        public ShellView()
        {
            this.InitializeComponent();

            IUserSettingService userSettingService = IoC.Get <IUserSettingService>();
            bool minimiseToTray = userSettingService.GetUserSetting <bool>(UserSettingConstants.MainWindowMinimize);

            if (minimiseToTray)
            {
                INotifyIconService notifyIconService = IoC.Get <INotifyIconService>();
                this.notifyIcon = new NotifyIcon();
                notifyIconService.RegisterNotifyIcon(this.notifyIcon);

                StreamResourceInfo streamResourceInfo = Application.GetResourceStream(new Uri("pack://application:,,,/handbrakepineapple.ico"));
                if (streamResourceInfo != null)
                {
                    Stream iconStream = streamResourceInfo.Stream;
                    this.notifyIcon.Icon = new Icon(iconStream);
                }

                this.notifyIcon.Click += this.NotifyIconClick;
                this.StateChanged     += this.ShellViewStateChanged;
            }

            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.E, ModifierKeys.Control)), new KeyGesture(Key.E, ModifierKeys.Control)));                                           // Start Encode
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.K, ModifierKeys.Control)), new KeyGesture(Key.K, ModifierKeys.Control)));                                           // Stop Encode
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.L, ModifierKeys.Control)), new KeyGesture(Key.L, ModifierKeys.Control)));                                           // Open Log Window
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.Q, ModifierKeys.Control)), new KeyGesture(Key.Q, ModifierKeys.Control)));                                           // Open Queue Window
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Control)), new KeyGesture(Key.A, ModifierKeys.Control)));                                           // Add to Queue
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Alt)), new KeyGesture(Key.A, ModifierKeys.Alt)));                                                   // Add all to Queue
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift)), new KeyGesture(Key.A, ModifierKeys.Control | ModifierKeys.Shift))); // Add selection to Queue

            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.O, ModifierKeys.Control)), new KeyGesture(Key.O, ModifierKeys.Control)));                                           // File Scan
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.O, ModifierKeys.Alt)), new KeyGesture(Key.O, ModifierKeys.Alt)));                                                   // Scan Window
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Shift)), new KeyGesture(Key.O, ModifierKeys.Control | ModifierKeys.Shift))); // Scan a Folder
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Shift)), new KeyGesture(Key.G, ModifierKeys.Control | ModifierKeys.Shift))); // Garbage Collection
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.F1, ModifierKeys.None)), new KeyGesture(Key.F1, ModifierKeys.None)));                                               // Help
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.S, ModifierKeys.Control)), new KeyGesture(Key.S, ModifierKeys.Control)));                                           // Browse Destination

            // Tabs Switching
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D1, ModifierKeys.Control)), new KeyGesture(Key.D1, ModifierKeys.Control)));
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D2, ModifierKeys.Control)), new KeyGesture(Key.D2, ModifierKeys.Control)));
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D3, ModifierKeys.Control)), new KeyGesture(Key.D3, ModifierKeys.Control)));
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D4, ModifierKeys.Control)), new KeyGesture(Key.D4, ModifierKeys.Control)));
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D5, ModifierKeys.Control)), new KeyGesture(Key.D5, ModifierKeys.Control)));
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D6, ModifierKeys.Control)), new KeyGesture(Key.D6, ModifierKeys.Control)));
            this.InputBindings.Add(new InputBinding(new ProcessShortcutCommand(new KeyGesture(Key.D7, ModifierKeys.Control)), new KeyGesture(Key.D7, ModifierKeys.Control)));

            // Enable Windows 7 Taskbar progress indication.
            if (this.TaskbarItemInfo == null)
            {
                this.TaskbarItemInfo = Win7.WindowsTaskbar;
            }

            // Setup the UI Language
            string culture = userSettingService.GetUserSetting <string>(UserSettingConstants.UiLanguage);

            if (!string.IsNullOrEmpty(culture))
            {
                InterfaceLanguage language = InterfaceLanguageUtilities.FindInterfaceLanguage(culture);
                if (language != null)
                {
                    if (language.RightToLeft)
                    {
                        if (Application.Current.MainWindow != null)
                        {
                            Application.Current.MainWindow.FlowDirection = FlowDirection.RightToLeft;
                        }
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Override the startup behavior to handle files dropped on the app icon.
        /// </summary>
        /// <param name="e">
        /// The StartupEventArgs.
        /// </param>
        protected override void OnStartup(StartupEventArgs e)
        {
            // We don't support Windows earlier than 10.
            if (!SystemInfo.IsWindows10OrLater())
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsVersionWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (!Environment.Is64BitOperatingSystem)
            {
                MessageBox.Show(HandBrakeWPF.Properties.Resources.OsBitnessWarning, HandBrakeWPF.Properties.Resources.Warning, MessageBoxButton.OK, MessageBoxImage.Warning);
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.Equals("--reset")))
            {
                HandBrakeApp.ResetToDefaults();
                Application.Current.Shutdown();
                return;
            }

            if (e.Args.Any(f => f.StartsWith("--recover-queue-ids")))
            {
                string command = e.Args.FirstOrDefault(f => f.StartsWith("--recover-queue-ids"));
                if (!string.IsNullOrEmpty(command))
                {
                    command = command.Replace("--recover-queue-ids=", string.Empty);
                    List <string> processIds = command.Split(',').ToList();
                    StartupOptions.QueueRecoveryIds = processIds;
                }
            }

            if (e.Args.Any(f => f.Equals("--auto-start-queue")))
            {
                StartupOptions.AutoRestartQueue = true;
            }

            // Portable Mode
            if (Portable.IsPortable())
            {
                int portableInit = Portable.Initialise();
                if (portableInit != 0)
                {
                    switch (portableInit)
                    {
                    case -1:
                        MessageBox.Show(
                            HandBrakeWPF.Properties.Resources.Portable_IniFileError,
                            HandBrakeWPF.Properties.Resources.Error,
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        break;

                    case -2:
                        MessageBox.Show(
                            HandBrakeWPF.Properties.Resources.Portable_TmpNotWritable,
                            HandBrakeWPF.Properties.Resources.Error,
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        break;

                    case -3:
                        MessageBox.Show(
                            HandBrakeWPF.Properties.Resources.Portable_StorageNotWritable,
                            HandBrakeWPF.Properties.Resources.Error,
                            MessageBoxButton.OK,
                            MessageBoxImage.Error);
                        break;
                    }

                    Application.Current.Shutdown();
                    return;
                }
            }

            // Setup the UI Language
            IUserSettingService userSettingService = IoC.Get <IUserSettingService>();
            string culture = userSettingService.GetUserSetting <string>(UserSettingConstants.UiLanguage);

            if (!string.IsNullOrEmpty(culture))
            {
                InterfaceLanguage language = InterfaceLanguageUtilities.FindInterfaceLanguage(culture);
                if (language != null)
                {
                    CultureInfo ci = new CultureInfo(language.Culture);
                    Thread.CurrentThread.CurrentUICulture = ci;
                }
            }

            int runCounter = userSettingService.GetUserSetting <int>(UserSettingConstants.RunCounter);

            // Software Rendering
            if (e.Args.Any(f => f.Equals("--force-software-rendering")) || Portable.IsForcingSoftwareRendering() || userSettingService.GetUserSetting <bool>(UserSettingConstants.ForceSoftwareRendering))
            {
                RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly;
            }

            // Check if the user would like to check for updates AFTER the first run, but only once.
            if (runCounter == 1)
            {
                CheckForUpdateCheckPermission(userSettingService);
            }

            // Increment the counter so we can change startup behavior for the above warning and update check question.
            userSettingService.SetUserSetting(UserSettingConstants.RunCounter, runCounter + 1); // Only display once.

            // App Theme
            DarkThemeMode      useDarkTheme = (DarkThemeMode)userSettingService.GetUserSetting <int>(UserSettingConstants.DarkThemeMode);
            ResourceDictionary dark         = new ResourceDictionary {
                Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Blue.xaml")
            };
            ResourceDictionary light = new ResourceDictionary {
                Source = new Uri("pack://application:,,,/MahApps.Metro;component/Styles/Themes/Light.Blue.xaml")
            };

            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("Themes/Generic.xaml", UriKind.Relative)
            });
            bool themed = false;

            if (SystemParameters.HighContrast)
            {
                Application.Current.Resources["Ui.Light"]         = new SolidColorBrush(SystemColors.HighlightTextColor);
                Application.Current.Resources["Ui.ContrastLight"] = new SolidColorBrush(SystemColors.ActiveBorderBrush.Color);
                useDarkTheme = DarkThemeMode.None;
            }

            switch (useDarkTheme)
            {
            case DarkThemeMode.System:
                if (SystemInfo.IsAppsUsingDarkTheme())
                {
                    Application.Current.Resources.MergedDictionaries.Add(dark);
                    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                        Source = new Uri("Themes/Dark.xaml", UriKind.Relative)
                    });
                }
                else
                {
                    Application.Current.Resources.MergedDictionaries.Add(light);
                    Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                        Source = new Uri("Themes/Light.xaml", UriKind.Relative)
                    });
                }

                themed = true;
                break;

            case DarkThemeMode.Dark:
                Application.Current.Resources.MergedDictionaries.Add(dark);
                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("Themes/Dark.xaml", UriKind.Relative)
                });
                themed = true;
                break;

            case DarkThemeMode.Light:
                Application.Current.Resources.MergedDictionaries.Add(light);
                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("Themes/Light.xaml", UriKind.Relative)
                });
                themed = true;
                break;

            case DarkThemeMode.None:
                Application.Current.Resources["Ui.Light"]         = new SolidColorBrush(SystemColors.HighlightTextColor);
                Application.Current.Resources["Ui.ContrastLight"] = new SolidColorBrush(SystemColors.ActiveBorderBrush.Color);
                themed = false;
                break;
            }

            Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                Source = new Uri("Views/Styles/Styles.xaml", UriKind.Relative)
            });

            if (themed)
            {
                Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("Views/Styles/ThemedStyles.xaml", UriKind.Relative)
                });
            }

            // NO-Hardware Mode
            bool noHardware = e.Args.Any(f => f.Equals("--no-hardware")) || (Portable.IsPortable() && !Portable.IsHardwareEnabled());

            // Initialise the Engine
            Services.Logging.GlobalLoggingManager.Init();
            HandBrakeInstanceManager.Init(noHardware, userSettingService);

            // Initialise the GUI
            base.OnStartup(e);

            // If we have a file dropped on the icon, try scanning it.
            string[] args = e.Args;
            if (args.Any() && (File.Exists(args[0]) || Directory.Exists(args[0])))
            {
                IMainViewModel mvm = IoC.Get <IMainViewModel>();
                mvm.StartScan(args[0], 0);
            }
        }