protected override void OnStartup(StartupEventArgs e) { #if !DEBUG this.DispatcherUnhandledException += this.OnDispatcherUnhandledException; #endif base.OnStartup(e); OperatingSystem OS = Environment.OSVersion; if (OS.Version.Major <= 5) { MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning); this.Shutdown(); return; } #if PSEUDOLOCALIZER_ENABLED Delay.PseudoLocalizer.Enable(typeof(CommonRes)); Delay.PseudoLocalizer.Enable(typeof(MainRes)); Delay.PseudoLocalizer.Enable(typeof(EnumsRes)); Delay.PseudoLocalizer.Enable(typeof(EncodingRes)); Delay.PseudoLocalizer.Enable(typeof(OptionsRes)); Delay.PseudoLocalizer.Enable(typeof(PreviewRes)); Delay.PseudoLocalizer.Enable(typeof(LogRes)); Delay.PseudoLocalizer.Enable(typeof(SubtitleRes)); Delay.PseudoLocalizer.Enable(typeof(QueueTitlesRes)); Delay.PseudoLocalizer.Enable(typeof(ChapterMarkersRes)); Delay.PseudoLocalizer.Enable(typeof(MiscRes)); #endif // Takes about 50ms Config.Initialize(Database.Connection); if (!Config.MigratedConfigs && Directory.Exists(Utilities.LocalAppFolder)) { // Upgrade configs from previous version before migrating try { if (Settings.Default.ApplicationVersion != Utilities.CurrentVersion) { Settings.Default.Upgrade(); Settings.Default.ApplicationVersion = Utilities.CurrentVersion; if (Settings.Default.NativeLanguageCode != string.Empty) { var languageCode = Settings.Default.NativeLanguageCode; Settings.Default.NativeLanguageCode = string.Empty; if (languageCode != "und") { if (Settings.Default.DubAudio) { Settings.Default.AudioLanguageCode = languageCode; Settings.Default.AutoAudio = AutoAudioType.Language; } else { Settings.Default.SubtitleLanguageCode = languageCode; Settings.Default.AutoSubtitle = AutoSubtitleType.Language; } } } Settings.Default.Save(); } ConfigMigration.MigrateConfigSettings(); } catch (ConfigurationErrorsException) { // If we had problems loading the old config we can't recover. MessageBox.Show(MainRes.UserConfigCorrupted); Config.MigratedConfigs = true; } } var interfaceLanguageCode = Config.InterfaceLanguageCode; if (!string.IsNullOrWhiteSpace(interfaceLanguageCode)) { var cultureInfo = new CultureInfo(interfaceLanguageCode); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; } var updater = Ioc.Container.GetInstance <IUpdater>(); updater.HandlePendingUpdate(); try { // Check if we're a secondary instance IsPrimaryInstance = mutex.WaitOne(TimeSpan.Zero, true); } catch (AbandonedMutexException) { } this.GlobalInitialize(); var mainVM = new MainViewModel(); WindowManager.OpenWindow(mainVM); mainVM.OnLoaded(); if (!Utilities.IsPortable && IsPrimaryInstance) { AutomationHost.StartListening(); } }
protected override void OnStartup(StartupEventArgs e) { #if !DEBUG this.DispatcherUnhandledException += this.OnDispatcherUnhandledException; #endif base.OnStartup(e); OperatingSystem OS = Environment.OSVersion; if (OS.Version.Major <= 5) { MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning); this.Shutdown(); return; } #if PSEUDOLOCALIZER_ENABLED Delay.PseudoLocalizer.Enable(typeof(CommonRes)); Delay.PseudoLocalizer.Enable(typeof(MainRes)); Delay.PseudoLocalizer.Enable(typeof(EnumsRes)); Delay.PseudoLocalizer.Enable(typeof(EncodingRes)); Delay.PseudoLocalizer.Enable(typeof(OptionsRes)); Delay.PseudoLocalizer.Enable(typeof(PreviewRes)); Delay.PseudoLocalizer.Enable(typeof(LogRes)); Delay.PseudoLocalizer.Enable(typeof(SubtitleRes)); Delay.PseudoLocalizer.Enable(typeof(QueueTitlesRes)); Delay.PseudoLocalizer.Enable(typeof(ChapterMarkersRes)); Delay.PseudoLocalizer.Enable(typeof(MiscRes)); #endif JsonSettings.SetDefaultSerializationSettings(); // Takes about 50ms Config.EnsureInitialized(Database.Connection); var interfaceLanguageCode = Config.InterfaceLanguageCode; if (!string.IsNullOrWhiteSpace(interfaceLanguageCode)) { var cultureInfo = new CultureInfo(interfaceLanguageCode); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; CultureInfo.DefaultThreadCurrentCulture = cultureInfo; CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; } if (Config.UseCustomPreviewFolder && FileUtilities.HasWriteAccessOnFolder(Config.PreviewOutputFolder)) { Environment.SetEnvironmentVariable("TMP", Config.PreviewOutputFolder, EnvironmentVariableTarget.Process); FileUtilities.OverrideTempFolder = true; FileUtilities.TempFolderOverride = Config.PreviewOutputFolder; } var updater = Ioc.Get <IUpdater>(); updater.HandlePendingUpdate(); try { // Check if we're a secondary instance IsPrimaryInstance = mutex.WaitOne(TimeSpan.Zero, true); } catch (AbandonedMutexException) { } this.GlobalInitialize(); var mainVM = new MainViewModel(); Ioc.Get <IWindowManager>().OpenWindow(mainVM); mainVM.OnLoaded(); if (e.Args.Length > 0) { mainVM.HandlePaths(new List <string> { e.Args[0] }); } if (!Utilities.IsPortable && IsPrimaryInstance) { AutomationHost.StartListening(); } }
protected override void OnStartup(StartupEventArgs e) { if (e.Args.Contains("-ToastActivated")) { return; } if (!Debugger.IsAttached) { this.DispatcherUnhandledException += this.OnDispatcherUnhandledException; } OperatingSystem OS = Environment.OSVersion; if (OS.Version.Major <= 5) { MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning); MessageBox.Show(MiscRes.UnsupportedOSError, MiscRes.NoticeMessageTitle, MessageBoxButton.OK, MessageBoxImage.Warning); this.Shutdown(); return; } #if PSEUDOLOCALIZER_ENABLED Delay.PseudoLocalizer.Enable(typeof(CommonRes)); Delay.PseudoLocalizer.Enable(typeof(MainRes)); Delay.PseudoLocalizer.Enable(typeof(EnumsRes)); Delay.PseudoLocalizer.Enable(typeof(EncodingRes)); Delay.PseudoLocalizer.Enable(typeof(OptionsRes)); Delay.PseudoLocalizer.Enable(typeof(PreviewRes)); Delay.PseudoLocalizer.Enable(typeof(LogRes)); Delay.PseudoLocalizer.Enable(typeof(SubtitleRes)); Delay.PseudoLocalizer.Enable(typeof(QueueTitlesRes)); Delay.PseudoLocalizer.Enable(typeof(ChapterMarkersRes)); Delay.PseudoLocalizer.Enable(typeof(MiscRes)); #endif JsonSettings.SetDefaultSerializationSettings(); Ioc.SetUp(); try { Database.Initialize(); } catch (Exception) { Environment.Exit(0); } Config.EnsureInitialized(Database.Connection); var interfaceLanguageCode = Config.InterfaceLanguageCode; if (!string.IsNullOrWhiteSpace(interfaceLanguageCode)) { var cultureInfo = new CultureInfo(interfaceLanguageCode); Thread.CurrentThread.CurrentCulture = cultureInfo; Thread.CurrentThread.CurrentUICulture = cultureInfo; CultureInfo.DefaultThreadCurrentCulture = cultureInfo; CultureInfo.DefaultThreadCurrentUICulture = cultureInfo; } Stopwatch sw = Stopwatch.StartNew(); if (Config.UseCustomPreviewFolder && FileUtilities.HasWriteAccessOnFolder(Config.PreviewOutputFolder)) { Environment.SetEnvironmentVariable("TMP", Config.PreviewOutputFolder, EnvironmentVariableTarget.Process); FileUtilities.OverrideTempFolder = true; FileUtilities.TempFolderOverride = Config.PreviewOutputFolder; } var updater = StaticResolver.Resolve <IUpdater>(); sw.Stop(); System.Diagnostics.Debug.WriteLine("Startup time: " + sw.Elapsed); updater.HandlePendingUpdate(); try { // Check if we're a secondary instance IsPrimaryInstance = mutex.WaitOne(TimeSpan.Zero, true); } catch (AbandonedMutexException) { } this.GlobalInitialize(); this.appThemeService = StaticResolver.Resolve <IAppThemeService>(); this.appThemeService.AppThemeObservable.Subscribe(appTheme => { if (appTheme != this.currentTheme) { this.currentTheme = appTheme; this.ChangeTheme(new Uri($"/Themes/{appTheme}.xaml", UriKind.Relative)); bool isDark = appTheme == AppTheme.Dark; string fluentTheme = isDark ? "Dark" : "Light"; ThemeManager.ChangeTheme(this, fluentTheme + ".Cobalt"); Color ribbonTextColor = isDark ? Colors.White : Colors.Black; this.Resources["Fluent.Ribbon.Brushes.LabelTextBrush"] = new SolidColorBrush(ribbonTextColor); } }); var mainVM = new MainViewModel(); StaticResolver.Resolve <IWindowManager>().OpenWindow(mainVM); mainVM.OnLoaded(); if (e.Args.Length > 0) { mainVM.HandlePaths(new List <string> { e.Args[0] }); } if (!Utilities.IsPortable && IsPrimaryInstance) { AutomationHost.StartListening(); } base.OnStartup(e); }