private void LoadFirewallRules() { try { //Launcher var launcherPath = Assembly.GetEntryAssembly().Location; if (!File.Exists(launcherPath)) { GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperLauncherNotFound, DialogIcon.Error, DialogOptions.Ok); Close(); return; } var rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_outbound_tcp"); if (rule == null) { LauncherOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound; LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath || rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Outbound) { LauncherOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid; LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { LauncherOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen; LauncherOutboundStatus.Foreground = new SolidColorBrush(Colors.Green); } } var path = !string.IsNullOrWhiteSpace(LegacyBootstrapper.UserConfig?.GameFilesPath) ? LegacyBootstrapper.UserConfig?.GameFilesPath : GameScannerManager.GetGameFilesRootPath(); var spartanPath = Path.Combine(path, "Spartan.exe"); if (!File.Exists(spartanPath)) { GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperSpartanNotFound, DialogIcon.Error, DialogOptions.Ok); Close(); return; } //Spartan var rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_tcp"); var rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_udp"); if (rule1 == null || rule2 == null) { SpartanInboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound; SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath || rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Inbound || rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath || rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Inbound) { SpartanInboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid; SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { SpartanInboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen; SpartanInboundStatus.Foreground = new SolidColorBrush(Colors.Green); } } rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_tcp"); rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_udp"); if (rule1 == null || rule2 == null) { SpartanOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound; SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath || rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Outbound || rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath || rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Outbound) { SpartanOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid; SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { SpartanOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen; SpartanOutboundStatus.Foreground = new SolidColorBrush(Colors.Green); } } //Port 1000 rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_inbound_udp"); if (rule == null) { MultiplayerInboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound; MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) || rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Inbound) { MultiplayerInboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid; MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { MultiplayerInboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen; MultiplayerInboundStatus.Foreground = new SolidColorBrush(Colors.Green); } } rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_outbound_udp"); if (rule == null) { MultiplayerOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleNotFound; MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) || rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Outbound) { MultiplayerOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleInvalid; MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Red); } else { MultiplayerOutboundStatus.Content = Celeste_Launcher_Gui.Properties.Resources.WindowsFirewallHelperRuleOpen; MultiplayerOutboundStatus.Foreground = new SolidColorBrush(Colors.Green); } } } catch (Exception ex) { Logger.Error(ex, ex.Message); GenericMessageDialog.Show(Celeste_Launcher_Gui.Properties.Resources.GenericUnexpectedErrorMessage, DialogIcon.Error, DialogOptions.Ok); } }
private void RefreshForm() { try { //Launcher var launcherPath = Assembly.GetEntryAssembly().Location; if (!File.Exists(launcherPath)) { throw new FileNotFoundException("Launcher not found!", launcherPath); } var rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_inbound_tcp"); if (rule == null) { l_State_L_In.Text = @"Not Found"; l_State_L_In.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath || rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Inbound) { l_State_L_In.Text = @"Invalid"; l_State_L_In.ForeColor = Color.Red; } else { l_State_L_In.Text = @"Valid"; l_State_L_In.ForeColor = Color.Green; } } rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_launcher_outbound_tcp"); if (rule == null) { l_State_L_Out.Text = @"Not Found"; l_State_L_Out.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.TCP || rule.ApplicationName != launcherPath || rule.LocalPortType != FirewallPortType.All || rule.Direction != FirewallDirection.Outbound) { l_State_L_Out.Text = @"Invalid"; l_State_L_Out.ForeColor = Color.Red; } else { l_State_L_Out.Text = @"Valid"; l_State_L_Out.ForeColor = Color.Green; } } var path = !string.IsNullOrWhiteSpace(Program.UserConfig?.GameFilesPath) ? Program.UserConfig?.GameFilesPath : GameScannnerApi.GetGameFilesRootPath(); var spartanPath = Path.Combine(path, "Spartan.exe"); if (!File.Exists(spartanPath)) { throw new FileNotFoundException("Spartan.exe not found!", spartanPath); } //Spartan var rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_tcp"); var rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_inbound_udp"); if (rule1 == null || rule2 == null) { l_State_S_In.Text = @"Not Found"; l_State_S_In.ForeColor = Color.Red; } else { if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath || rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Inbound || rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath || rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Inbound) { l_State_S_In.Text = @"Invalid"; l_State_S_In.ForeColor = Color.Red; } else { l_State_S_In.Text = @"Valid"; l_State_S_In.ForeColor = Color.Green; } } rule1 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_tcp"); rule2 = (StandardRuleWin7)FirewallHelper.FindRule("celeste_spartan_outbound_udp"); if (rule1 == null || rule2 == null) { l_State_S_Out.Text = @"Not Found"; l_State_S_Out.ForeColor = Color.Red; } else { if (rule1.Protocol != FirewallProtocol.TCP || rule1.ApplicationName != spartanPath || rule1.LocalPortType != FirewallPortType.All || rule1.Direction != FirewallDirection.Outbound || rule2.Protocol != FirewallProtocol.UDP || rule2.ApplicationName != spartanPath || rule2.LocalPortType != FirewallPortType.All || rule2.Direction != FirewallDirection.Outbound) { l_State_S_Out.Text = @"Invalid"; l_State_S_Out.ForeColor = Color.Red; } else { l_State_S_Out.Text = @"Valid"; l_State_S_Out.ForeColor = Color.Green; } } //Port 1000 rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_inbound_udp"); if (rule == null) { l_State_MP_In.Text = @"Not Found"; l_State_MP_In.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) || rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Inbound) { l_State_MP_In.Text = @"Invalid"; l_State_MP_In.ForeColor = Color.Red; } else { l_State_MP_In.Text = @"Valid"; l_State_MP_In.ForeColor = Color.Green; } } rule = (StandardRuleWin7)FirewallHelper.FindRule("celeste_port1000_outbound_udp"); if (rule == null) { l_State_MP_Out.Text = @"Not Found"; l_State_MP_Out.ForeColor = Color.Red; } else { if (rule.Protocol != FirewallProtocol.UDP || rule.LocalPorts.All(key => key != 1000) || rule.LocalPortType != FirewallPortType.Specific || rule.Direction != FirewallDirection.Outbound) { l_State_MP_Out.Text = @"Invalid"; l_State_MP_Out.ForeColor = Color.Red; } else { l_State_MP_Out.Text = @"Valid"; l_State_MP_Out.ForeColor = Color.Green; } } } catch (Exception ex) { MsgBox.ShowMessage( $"Error: {ex.Message}", @"Celeste Fan Project", MessageBoxButtons.OK, MessageBoxIcon.Error); } }