public ThemeImageConverter()
        {
            this.userSettingService = IoC.Get <IUserSettingService>();
            DarkThemeMode mode = (DarkThemeMode)this.userSettingService.GetUserSetting <int>(UserSettingConstants.DarkThemeMode);

            if (mode == DarkThemeMode.Dark || (mode == DarkThemeMode.System && Utilities.SystemInfo.IsAppsUsingDarkTheme()))
            {
                this.isDarkTheme = true;
            }
        }
Ejemplo n.º 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;
                }
            }

            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);
            }
        }
Ejemplo n.º 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())
            {
                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);
            }
        }
Ejemplo n.º 4
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);
            }
        }