protected override void OnStartup(StartupEventArgs e) { // -Key (Value = null) or -Key=Value CommandLineArgs = e.Args .Select(x => x.Split(new[] { '=', }, 2)) .GroupBy(xs => xs[0], (k, ys) => ys.Last()) // 重複の場合は後ろの引数を優先 .ToDictionary(xs => xs[0], xs => xs.Length == 1 ? null : xs[1], StringComparer.OrdinalIgnoreCase); #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst || CommandLineArgs.ContainsKey(RestartedArg)) #endif { if (VirtualDesktop.IsSupported) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; //var pinnedapps = WindowsDesktop.Interop.VirtualDesktopInteropHelper.GetVirtualDesktopPinnedApps(); //Debug.WriteLine($"IsPinnedWindow: {pinnedapps.IsPinnedWindow(MetroRadiance.Interop.Win32.User32.GetForegroundWindow())}"); //Debug.WriteLine($"IsPinnedApp : {pinnedapps.IsPinnedApp(MetroRadiance.Interop.Win32.User32.GetForegroundWindow())}"); DispatcherHelper.UIDispatcher = this.Dispatcher; LocalSettingsProvider.Instance.LoadAsync().Wait(); LocalSettingsProvider.Instance.AddTo(this); ThemeService.Current.Register(this, Theme.Windows, Accent.Windows); this.ShowNotifyIcon(CommandLineArgs.ContainsKey(CanOpenSettingsArg)); this.VdmHelper = VdmHelperFactory.CreateInstance().AddTo(this); this.VdmHelper.Init(); this.HookService = new HookService(this.VdmHelper).AddTo(this); this.InteropService = new UwpInteropService(this.HookService, Settings.General).AddTo(this); this.RegisterActions(); NotificationService.Instance.AddTo(this); WallpaperService.Instance.AddTo(this); base.OnStartup(e); } else { MessageBox.Show("This applications is supported only Windows 10 (build 10240).", "Not supported", MessageBoxButton.OK, MessageBoxImage.Stop); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.Shutdown(); } #endif }
protected override void OnStartup(StartupEventArgs e) { #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst) #endif { if (VirtualDesktop.IsSupported) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; DispatcherHelper.UIDispatcher = this.Dispatcher; LocalSettingsProvider.Instance.LoadAsync().Wait(); LocalSettingsProvider.Instance.AddTo(this); ThemeService.Current.Register(this, Theme.Windows, Accent.Windows); var s = e.Args.Select(x => x.ToLower()).Any(x => x == "-s"); this.ShowNotifyIcon(s); var helper = VdmHelperFactory.CreateInstance().AddTo(this); helper.Init(); this._pinService = new PinService(helper).AddTo(this); this._hookService = new HookService(helper).AddTo(this); this._hookService.PinRequested += (sender, hWnd) => this._pinService.Register(hWnd); this._hookService.UnpinRequested += (sender, hWnd) => this._pinService.Unregister(hWnd); this._interopService = new UwpInteropService(this._hookService, Settings.General).AddTo(this); this._notificationService = new NotificationService().AddTo(this); base.OnStartup(e); } else { MessageBox.Show("This applications is supported only Windows 10 (build 10240).", "Not supported", MessageBoxButton.OK, MessageBoxImage.Stop); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.Shutdown(); } #endif }
protected override void OnStartup(StartupEventArgs e) { #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst) #endif { if (VirtualDesktop.IsSupported) { this.ShutdownMode = ShutdownMode.OnExplicitShutdown; this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; DispatcherHelper.UIDispatcher = this.Dispatcher; ThemeService.Current.Initialize( this, GeneralSettings.Theme.Value ?? (VisualHelper.IsDarkTheme() ? Theme.Dark : Theme.Light), GeneralSettings.AccentColor.Value ?? Accent.Blue); this.transparentWindow = new TransparentWindow(); this.transparentWindow.Show(); if (GeneralSettings.AccentColor.Value == null) { VisualHelper.ForceChangeAccent(VisualHelper.GetWindowsAccentColor()); } this.ShowNotifyIcon(); this.hookService = new HookService().AddTo(this); this.notificationService = new NotificationService().AddTo(this); base.OnStartup(e); } else { MessageBox.Show("This applications is supported only Windows 10 (build 10240).", "Not supported", MessageBoxButton.OK, MessageBoxImage.Stop); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.Shutdown(); } #endif }
// 시작할 때의 이벤트 protected override void OnStartup(StartupEventArgs e) { this.ChangeState(ApplicationState.Startup); // 개발중에 다중 실행이 감지되어서 실행되지 않으면 불편하니 디버그 때에는 예외로 처리 #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst) #endif { // 미처리 예외 this.DispatcherUnhandledException += (sender, args) => { ReportException("Dispatcher", sender, args.Exception); args.Handled = true; }; DispatcherHelper.UIDispatcher = this.Dispatcher; SettingsHost.Load(); // 설정들 로드 this.compositeDisposable.Add(SettingsHost.Save); // Dispose될 때 설정을 저장 try { // 언어 변경 GeneralSettings.Culture .Subscribe(x => ResourceService.Current.ChangeCulture(x)) .AddTo(this); } catch (Exception ex) { ReportException("Culture", this, ex); // 무언가 오류가 발생... try { File.Delete(Providers.LocalFilePath); File.Delete(Providers.ViewerDirectoryPath); } catch (Exception ex2) { ReportException("File.Delete", this, ex2); } MessageBox.Show( "어플리케이션 기동중 문제가 발생하여 일부 설정파일을 초기화합니다.\n" + "프로그램이 종료되며, 재시작 해주시기 바랍니다.\n\n" + ex.Message + "\n" + ex.StackTrace, "제독업무도 바빠!", MessageBoxButton.OK, MessageBoxImage.Warning ); this.Shutdown(); return; } // 기존 설정 불러오기..? if (KanColleViewer.Properties.Settings.Default.UpdateSettings) { KanColleViewer.Properties.Settings.Default.Upgrade(); KanColleViewer.Properties.Settings.Default.UpdateSettings = false; KanColleViewer.Properties.Settings.Default.Save(); } // 설정들 초기화 KanColleClient.Current.Settings = new KanColleSettings(); // 테마 변경 ThemeService.Current.Register(this, Theme.Dark, Accent.Purple); // 각종 서비스 초기화 PluginService.Current.AddTo(this).Initialize(); WindowService.Current.AddTo(this).Initialize(); NotifyService.Current.AddTo(this).Initialize(); GCWorker.Current.AddTo(this).Startup(); Helper.SetMMCSSTask(); Helper.DeleteCacheIfRequested(); CefInitialize(); // WebBrowser 컨트롤 IE 버전 레지스트리 패치, MMCSS 설정 // Helper.SetRegistryFeatureBrowserEmulation(); if (GeneralSettings.MMCSSEnabled) { Helper.SetMMCSSTask(); } // 번역 여부 KanColleClient.Current.Translations.EnableTranslations = KanColleSettings.EnableTranslations; KanColleClient.Current.Translations.EnableAddUntranslated = KanColleSettings.EnableAddUntranslated; // 설정된 경우, 업데이트 통지 및 다운로드 if (KanColleClient.Current.Updater.LoadVersion(AppSettings.Default.KCVUpdateUrl.AbsoluteUri)) { // 업데이트 알림이 설정되어있고 상위 버전이 있을 경우 if (KanColleSettings.EnableUpdateNotification && KanColleClient.Current.Updater.IsOnlineVersionGreater(TranslationType.App, ProductInfo.Version.ToString())) { // 자동 업데이트 프로그램이 존재하는 경우 if (File.Exists(Path.Combine(CurrentDirectory, "AutoUpdater.exe"))) { // 자동 업데이트 프로그램을 실행 Process MyProcess = new Process(); MyProcess.StartInfo.FileName = "AutoUpdater.exe"; MyProcess.StartInfo.WorkingDirectory = CurrentDirectory; MyProcess.Start(); MyProcess.Refresh(); this.Shutdown(); } else { // 자동 업데이트 프로그램이 존재하지 않는 경우 알림만 표시 var notification = Notification.Create( "", "제독업무도 바빠! 업데이트", "어플리케이션의 새로운 버전이 릴리즈 되었습니다!" + "블로그 등의 배포처를 확인해주시기 바랍니다.", () => WindowService.Current.MainWindow.Activate() ); NotifyService.Current.Notify(notification); } } // 번역 파일 업데이트가 설정된 경우 if (KanColleSettings.EnableUpdateTransOnStart) { // 번역 파일들 업데이트 if (KanColleClient.Current.Updater.UpdateTranslations(AppSettings.Default.XMLTransUrl.AbsoluteUri, KanColleClient.Current.Translations) > 0) { var notification = Notification.Create( "", "제독업무도 바빠! 업데이트", "번역 파일의 업데이트가 완료되었습니다.", () => WindowService.Current.MainWindow.Activate() ); NotifyService.Current.Notify(notification); } } } // BootstrapProxy()에서 Views.Settings.ProxyBootstrapper.Show()가 호출되기 전에 // Application.MainWindow를 설정해둔다. (매우 중요함) // 나중에 설정하는 경우, Views.Settings.ProxyBootstrapper가 닫히면 프로그램도 같이 닫힘. this.MainWindow = WindowService.Current.GetMainWindow(); // 로컬 프록시를 시작한다. if (BootstrapProxy()) { // 종료될 때 로컬 프록시를 종료한다. this.compositeDisposable.Add(ProxyBootstrapper.Shutdown); this.MainWindow.Show(); // 브라우저 관리 클래스 var navigator = (WindowService.Current.MainWindow as KanColleWindowViewModel)?.Navigator; if (navigator != null) { navigator.Source = KanColleViewer.Properties.Settings.Default.KanColleUrl; navigator.Navigate(); } #if !DEBUG // 디버그가 아닌 경우 다중 실행과 명령줄을 처리 appInstance.CommandLineArgsReceived += (sender, args) => { // 다중 실행을 감지한 경우, 메인 윈도우를 표시 this.Dispatcher.Invoke(() => WindowService.Current.MainWindow.Activate()); this.ProcessCommandLineParameter(args.CommandLineArgs); }; #endif base.OnStartup(e); this.ChangeState(ApplicationState.Running); // 실행중임을 처리 } else { // 로컬 프록시 시작에 실패한 경우 그대로 종료 this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } } #if !DEBUG else { // 다중 실행인 경우 명령줄을 전달하고 종료 appInstance.SendCommandLineArgs(e.Args); this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } #endif }
protected override void OnStartup(StartupEventArgs e) { this.ChangeState(ApplicationState.Startup); // 開発中に多重起動検知ついてると起動できなくて鬱陶しいので // デバッグ時は外すんじゃもん #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst) #endif { this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; DispatcherHelper.UIDispatcher = this.Dispatcher; SettingsHost.Load(); this.compositeDisposable.Add(SettingsHost.Save); GeneralSettings.Culture.Subscribe(x => ResourceService.Current.ChangeCulture(x)).AddTo(this); KanColleClient.Current.Settings = new KanColleSettings(); ThemeService.Current.Register(this, Theme.Dark, Accent.Purple); PluginService.Current.AddTo(this).Initialize(); WindowService.Current.AddTo(this).Initialize(); NotifyService.Current.AddTo(this).Initialize(); Helper.SetRegistryFeatureBrowserEmulation(); Helper.SetMMCSSTask(); // BootstrapProxy() で Views.Settings.ProxyBootstrapper.Show() が呼ばれるより前に // Application.MainWindow を設定しておく。これ大事 // 後に設定した場合、Views.Settings.ProxyBootstrapper が閉じると共にアプリも終了してしまう。 this.MainWindow = WindowService.Current.GetMainWindow(); if (BootstrapProxy()) { this.compositeDisposable.Add(ProxyBootstrapper.Shutdown); this.MainWindow.Show(); var navigator = (WindowService.Current.MainWindow as KanColleWindowViewModel)?.Navigator; if (navigator != null) { navigator.Source = KanColleViewer.Properties.Settings.Default.KanColleUrl; navigator.Navigate(); } #if !DEBUG appInstance.CommandLineArgsReceived += (sender, args) => { // 多重起動を検知したら、メイン ウィンドウを最前面に出す this.Dispatcher.Invoke(() => WindowService.Current.MainWindow.Activate()); this.ProcessCommandLineParameter(args.CommandLineArgs); }; #endif base.OnStartup(e); this.ChangeState(ApplicationState.Running); } else { this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } #endif }
protected override void OnStartup(StartupEventArgs e) { this.ChangeState(ApplicationState.Startup); // 開発中に多重起動検知ついてると起動できなくて鬱陶しいので // デバッグ時は外すんじゃもん #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst) #endif { this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; DispatcherHelper.UIDispatcher = this.Dispatcher; SettingsHost.Load(); this.compositeDisposable.Add(SettingsHost.Save); GeneralSettings.Culture.Subscribe(x => ResourceService.Current.ChangeCulture(x)).AddTo(this); KanColleClient.Current.Settings = new KanColleSettings(); ThemeService.Current.Initialize(this, Theme.Dark, Accent.Purple); WindowService.Current.AddTo(this).Initialize(); PluginService.Current.AddTo(this).Initialize(); NotifyService.Current.AddTo(this).Initialize(); Helper.SetRegistryFeatureBrowserEmulation(); Helper.SetMMCSSTask(); // BootstrapProxy() で Views.Settings.ProxyBootstrapper.Show() が呼ばれるより前に // Application.MainWindow を設定しておく。これ大事 this.MainWindow = WindowService.Current.GetMainWindow(); if (BootstrapProxy()) { this.compositeDisposable.Add(ProxyBootstrapper.Shutdown); this.MainWindow.Show(); #if !DEBUG appInstance.CommandLineArgsReceived += (sender, args) => { // 多重起動を検知したら、メイン ウィンドウを最前面に出す this.Dispatcher.Invoke(() => WindowService.Current.MainWindow.Activate()); this.ProcessCommandLineParameter(args.CommandLineArgs); }; #endif base.OnStartup(e); this.ChangeState(ApplicationState.Running); } else { this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } #endif }
protected override void OnStartup(StartupEventArgs e) { this.ChangeState(ApplicationState.Startup); // 開発中に多重起動検知ついてると起動できなくて鬱陶しいので // デバッグ時は外すんじゃもん #if !DEBUG var appInstance = new MetroTrilithon.Desktop.ApplicationInstance().AddTo(this); if (appInstance.IsFirst) #endif { this.DispatcherUnhandledException += (sender, args) => { ReportException(sender, args.Exception); args.Handled = true; }; DispatcherHelper.UIDispatcher = this.Dispatcher; SettingsHost.Load(); this.compositeDisposable.Add(SettingsHost.Save); try { GeneralSettings.Culture.Subscribe(x => ResourceService.Current.ChangeCulture(x)).AddTo(this); //#1 } catch { var LocalfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "grabacr.net"); var RoamingfilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "grabacr.net"); var LocalDirs = Directory.GetDirectories(LocalfilePath).ToList(); var RoamingDirs = Directory.GetDirectories(RoamingfilePath).ToList(); for (int i = 0; i < LocalDirs.Count; i++) { if (LocalDirs[i] != "KanColleViewer") { Directory.Delete(Path.Combine(LocalfilePath, LocalDirs[i]), true); } } for (int i = 0; i < RoamingDirs.Count; i++) { if (RoamingDirs[i] != "KanColleViewer") { Directory.Delete(Path.Combine(RoamingfilePath, RoamingDirs[i]), true); } } MessageBox.Show("어플리케이션 기동중 문제가 발생하여 일부 설정파일을 초기화합니다.\n프로그램이 종료됩니다", "제독업무도 바빠!", MessageBoxButton.OK, MessageBoxImage.Warning); this.Shutdown(); } KanColleClient.Current.Settings = new KanColleSettings(); ThemeService.Current.Register(this, Theme.Dark, Accent.Purple); PluginService.Current.AddTo(this).Initialize(); WindowService.Current.AddTo(this).Initialize(); NotifyService.Current.AddTo(this).Initialize(); Helper.SetRegistryFeatureBrowserEmulation(); if (GeneralSettings.MMCSSEnabled) { Helper.SetMMCSSTask(); } KanColleClient.Current.Translations.EnableTranslations = KanColleSettings.EnableTranslations; KanColleClient.Current.Translations.EnableAddUntranslated = KanColleSettings.EnableAddUntranslated; // Update notification and download new translations (if enabled) if (KanColleClient.Current.Updater.LoadVersion(AppSettings.Default.KCVUpdateUrl.AbsoluteUri)) { //null error if (KanColleSettings.EnableUpdateNotification && KanColleClient.Current.Updater.IsOnlineVersionGreater(0, ProductInfo.Version.ToString())) { if (File.Exists(Path.Combine(MainFolder, "AutoUpdater.exe"))) { this.IsUpdate = true; Process MyProcess = new Process(); MyProcess.StartInfo.FileName = "AutoUpdater.exe"; MyProcess.StartInfo.WorkingDirectory = MainFolder; MyProcess.Start(); MyProcess.Refresh(); this.Shutdown(); } else //AutoUpdater.exe가 없는 경우 알림만 띄운다. { var notification = Notification.Create( "", "업데이트", "어플리케이션의 새로운 버전이 릴리즈 되었습니다! 블로그를 확인해주세요", () => WindowService.Current.MainWindow.Activate()); NotifyService.Current.Notify(notification); } } if (KanColleSettings.EnableUpdateTransOnStart) { if (KanColleClient.Current.Updater.UpdateTranslations(AppSettings.Default.XMLTransUrl.AbsoluteUri, KanColleClient.Current.Translations) > 0) { var notification = Notification.Create( "", "업데이트", "번역파일 업데이트가 완료되었습니다", () => WindowService.Current.MainWindow.Activate()); NotifyService.Current.Notify(notification); } } } // BootstrapProxy() で Views.Settings.ProxyBootstrapper.Show() が呼ばれるより前に // Application.MainWindow を設定しておく。これ大事 // 後に設定した場合、Views.Settings.ProxyBootstrapper が閉じると共にアプリも終了してしまう。 this.MainWindow = WindowService.Current.GetMainWindow(); if (BootstrapProxy()) { this.compositeDisposable.Add(ProxyBootstrapper.Shutdown); this.MainWindow.Show(); var navigator = (WindowService.Current.MainWindow as KanColleWindowViewModel)?.Navigator; if (navigator != null) { navigator.Source = KanColleViewer.Properties.Settings.Default.KanColleUrl; navigator.Navigate(); } #if !DEBUG appInstance.CommandLineArgsReceived += (sender, args) => { // 多重起動を検知したら、メイン ウィンドウを最前面に出す this.Dispatcher.Invoke(() => WindowService.Current.MainWindow.Activate()); this.ProcessCommandLineParameter(args.CommandLineArgs); }; #endif base.OnStartup(e); this.ChangeState(ApplicationState.Running); } else { this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } } #if !DEBUG else { appInstance.SendCommandLineArgs(e.Args); this.ChangeState(ApplicationState.Terminate); this.Shutdown(); } #endif }