From c43bc49feb5ba38a785e7aa8790f5a9d821e6c77 Mon Sep 17 00:00:00 2001 From: racpast Date: Mon, 13 Jan 2025 04:17:27 +0800 Subject: [PATCH] Correct and optimize the code --- Wins/MainWin.xaml.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index a027634..4fd8be5 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -204,6 +204,8 @@ public partial class MainWin : Window { HoldButtonTimer?.Stop(); + NginxConfWatcher_Changed(null!, null!); + if (!MainPres.IsConginxRunning && !MainPres.IsNginxRunning) { if (NginxCleaner.IsNginxCleaningSemaphore.CurrentCount == 0 || !await IsNginxLaunchingSemaphore.WaitAsync(0)) @@ -772,13 +774,9 @@ public partial class MainWin : Window NginxHttpPort = 80; NginxHttpsPort = 443; - foreach (IPEndPoint activeTcpListener in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners()) - if (activeTcpListener.Port == NginxHttpPort) - NginxHttpPort++; - else if (activeTcpListener.Port == NginxHttpsPort) - NginxHttpsPort++; - else if (activeTcpListener.Port > NginxHttpsPort) - break; + HashSet activePorts = new(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners().Select(listener => listener.Port)); + while (activePorts.Contains(NginxHttpPort)) NginxHttpPort++; + while (activePorts.Contains(NginxHttpsPort)) NginxHttpsPort++; await using FileStream nginxConfStream = new(MainConst.NginxConfPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete); NginxConfig extraNginxConfig = NginxConfig.Load(ExtraNginxConfs = new StreamReader(nginxConfStream).ReadToEnd());