protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); SplashScreen splash = null; MainWindow mainWindow = null; var splashVM = new SplashScreenViewModel() { Stop = new DelegateCommand(() => Shutdown()), Ignore = new DelegateCommand(() => Start()), }; splash = new SplashScreen(splashVM); this.MainWindow = splash; splash.Show(); AppConnector appConnector = null; bool canStart = true; try { XElement appSettings = XDocument.Load(@"Settings\App.xml").Element("ApplicationSettings"); if ((bool)appSettings.Element("CatchUnobservedExceptions").Attribute("Enabled")) { DispatcherUnhandledException += AppDispatcherUnhandledException; } XElement menuLayoutSources = XDocument.Load(@"Settings\MenuLayoutSources.xml").Element("MenuLayoutSources"); appConnector = new AppConnector(splashVM) { PrinterClass = (string)appSettings.Element("Printer").Attribute("Class"), PrinterName = (string)appSettings.Element("Printer").Attribute("Name"), MainMenuLayoutSourcePath = Path.GetFullPath(Path.Combine(AppDirectory, "Settings", (string)menuLayoutSources.Element("MainMenu").Attribute("Source") ?? "")), OneTouchMenuLayoutSourcePath = Path.GetFullPath(Path.Combine(AppDirectory, "Settings", (string)menuLayoutSources.Element("OneTouchMenu").Attribute("Source") ?? "")), MaintenanceMenuLayoutSourcePath = Path.GetFullPath(Path.Combine(AppDirectory, "Settings", (string)menuLayoutSources.Element("MaintenanceMenu").Attribute("Source") ?? "")), }; } catch { splashVM.Errors.Add("基本設定を正常に読み込めませんでした。設定内容に誤りが無いか確認し、解消されない場合は再インストールを検討して下さい。"); splashVM.IsErrorIgnorable = false; splashVM.IsErrorShown = true; canStart = false; } if (canStart) { MainWindowVM = new MainWindowViewModel(appConnector); mainWindow = new MainWindow(MainWindowVM); MainWindowVM.M.Loaded(); if (splashVM.Errors.Count > 0) { splashVM.Stop = new DelegateCommand(() => { MainWindowVM.M.CurrentPrinter.Dispose(); Shutdown(); }); splashVM.IsErrorIgnorable = !splashVM.Errors.Any(err => err.StartsWith("(エラー ) ")); splashVM.IsErrorShown = true; } else { Start(); } } async void Start() { MainWindowVM.M.DialogModel.ShowInformationDialog("ソフトウェアのバージョンを確認しています...", false); this.MainWindow = mainWindow; mainWindow.Show(); splash.Close(); try { using (HttpClient client = new HttpClient()) { string latestVersion = await client.GetStringAsync("https://script.google.com/macros/s/AKfycbxXOLf46ZjE9WDUC4xQYn2itPOrKA5Qr3_uPWqcpWU9AFJr7QGgkF-KQQAYlu0kRvGX/exec"); if (latestVersion == ProductVersion) { MainWindowVM.M.DialogModel.ShowInformationDialog($"ご利用のバージョンは最新です。\n\nご利用のバージョン: Version {ProductVersion}\n最新のバージョン : Version {latestVersion}"); } else { MainWindowVM.M.DialogModel.ShowInformationDialog($"新しいバージョンがリリースされています。\n\nご利用のバージョン: Version {ProductVersion}\n最新のバージョン : Version {latestVersion}"); } } } catch { MainWindowVM.M.DialogModel.ShowInformationDialog($"ご利用のバージョンが最新であるか確認出来ませんでした。\n\nご利用のバージョン: Version {ProductVersion}\n最新のバージョン : 不明"); } } }
public AppConnector(SplashScreenViewModel splashScreenVM) { splashVM = splashScreenVM; }