From bfe32ab6794894cc7390646cff493fb009cf6aad Mon Sep 17 00:00:00 2001 From: pizzaboxer Date: Sat, 29 Jul 2023 21:29:17 +0100 Subject: [PATCH] Add connectivity check on startup --- Bloxstrap/App.xaml.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 4d04507..bf137d9 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -147,6 +147,33 @@ namespace Bloxstrap } } + if (!IsMenuLaunch) + { + Logger.WriteLine(LOG_IDENT, "Performing connectivity check"); + + try + { + HttpClient.GetAsync("https://detectportal.firefox.com").Wait(); + } + catch (Exception ex) + { + Logger.WriteLine(LOG_IDENT, "Connectivity check failed!"); + Logger.WriteException(LOG_IDENT, ex); + + Controls.ShowMessageBox( + "Bloxstrap is unable to connect to the internet. Please check your network configuration and try again.\n" + + "\n" + + "More information:\n" + + ex.InnerException!.Message, + MessageBoxImage.Error, + MessageBoxButton.OK + ); + + Terminate(); + } + } + + // check if installed using (RegistryKey? registryKey = Registry.CurrentUser.OpenSubKey($@"Software\{ProjectName}")) {