From e962850d05772603f7b40d904223e9711adbe823 Mon Sep 17 00:00:00 2001 From: Space Time Date: Thu, 19 Dec 2024 11:19:58 +0800 Subject: [PATCH] =?UTF-8?q?1.1.3=20->=201.1.4=20=E7=AC=AC81=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wins/MainWin.xaml.cs | 118 +++++++++++++++++++++++++------------------ 1 file changed, 68 insertions(+), 50 deletions(-) diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index ff83921..9e97dec 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -91,7 +91,15 @@ public partial class MainWin : Window UpdateUpstreamHostButton_Click(null!, null!); }); } - private void MainWin_Closing(object sender, CancelEventArgs e) => Application.Current.Shutdown(); + private void MainWin_Closing(object sender, CancelEventArgs e) + { + if (MainPres.IsNginxIniting) + File.WriteAllText(MainConst.NginxConfPath, ExtraNginxConfs); + if (MainPres.IsMihomoIniting) + File.WriteAllText(MainConst.MihomoConfPath, ExtraMihomoConfs); + + Application.Current.Shutdown(); + } private void MainWin_DragEnter(object sender, DragEventArgs e) { @@ -263,41 +271,46 @@ public partial class MainWin : Window File.AppendAllText(MainConst.HostsConfPath, hostsConfAppendContent); #endregion Child Cert & Hosts - MainPres.IsNginxIniting = true; - NginxConfWatcher.EnableRaisingEvents = false; - NginxConfs!.Save(MainConst.NginxConfPath); - - await Task.Run(() => + try { - new NginxProc().Run(Path.GetDirectoryName(MainConst.NginxPath), @$"-c ""{Path.GetRelativePath(Path.GetDirectoryName(MainConst.NginxPath)!, MainConst.NginxConfPath)}"""); - }); + MainPres.IsNginxIniting = true; + NginxConfWatcher.EnableRaisingEvents = false; + NginxConfs!.Save(MainConst.NginxConfPath); - while (true) - { - try + await Task.Run(() => { - await Http.GetAsync($"https://localhost:{NginxHttpsPort}", MainClient); + new NginxProc().Run(Path.GetDirectoryName(MainConst.NginxPath), @$"-c ""{Path.GetRelativePath(Path.GetDirectoryName(MainConst.NginxPath)!, MainConst.NginxConfPath)}"""); + }); - break; - } - catch (HttpRequestException ex) + while (true) { - if (ex.InnerException is SocketException innerEx && innerEx.SocketErrorCode != SocketError.ConnectionRefused) + try + { + await Http.GetAsync($"https://localhost:{NginxHttpsPort}", MainClient); + break; - } + } + catch (HttpRequestException ex) + { + if (ex.InnerException is SocketException innerEx && innerEx.SocketErrorCode != SocketError.ConnectionRefused) + break; + } - if (!MainPres.IsNginxRunning) - { - if (MessageBox.Show(MainConst._LaunchNginxErrorPrompt, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) - Process.Start(new ProcessStartInfo(MainConst.NginxErrorLogsPath) { UseShellExecute = true }); + if (!MainPres.IsNginxRunning) + { + if (MessageBox.Show(MainConst._LaunchNginxErrorPrompt, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.Yes) + Process.Start(new ProcessStartInfo(MainConst.NginxErrorLogsPath) { UseShellExecute = true }); - break; + break; + } } } - - File.WriteAllText(MainConst.NginxConfPath, ExtraNginxConfs); - NginxConfWatcher.EnableRaisingEvents = true; - MainPres.IsNginxIniting = false; + finally + { + File.WriteAllText(MainConst.NginxConfPath, ExtraNginxConfs); + NginxConfWatcher.EnableRaisingEvents = true; + MainPres.IsNginxIniting = false; + } } else { @@ -339,40 +352,45 @@ public partial class MainWin : Window if (!File.Exists(MainConst.MihomoConfPath)) File.Create(MainConst.MihomoConfPath).Dispose(); - MainPres.IsMihomoIniting = true; - MihomoConfWatcher.EnableRaisingEvents = false; - File.WriteAllText(MainConst.MihomoConfPath, MihomoConfs); - - await Task.Run(() => + try { - new MihomoProc().Run(Path.GetDirectoryName(MainConst.MihomoPath), @$"-d ""{Path.GetDirectoryName(MainConst.MihomoConfPath)}"""); - }); + MainPres.IsMihomoIniting = true; + MihomoConfWatcher.EnableRaisingEvents = false; + File.WriteAllText(MainConst.MihomoConfPath, MihomoConfs); - while (true) - { - try + await Task.Run(() => { - await Http.GetAsync($"http://localhost:{MihomoMixedPort}", MainClient); + new MihomoProc().Run(Path.GetDirectoryName(MainConst.MihomoPath), @$"-d ""{Path.GetDirectoryName(MainConst.MihomoConfPath)}"""); + }); - break; - } - catch (HttpRequestException ex) + while (true) { - if (ex.InnerException is SocketException innerEx && innerEx.SocketErrorCode != SocketError.ConnectionRefused) + try + { + await Http.GetAsync($"http://localhost:{MihomoMixedPort}", MainClient); + break; - } + } + catch (HttpRequestException ex) + { + if (ex.InnerException is SocketException innerEx && innerEx.SocketErrorCode != SocketError.ConnectionRefused) + break; + } - if (!MainPres.IsMihomoRunning) - { - MessageBox.Show(MainConst._LaunchMihomoErrorMsg); + if (!MainPres.IsMihomoRunning) + { + MessageBox.Show(MainConst._LaunchMihomoErrorMsg); - break; + break; + } } } - - File.WriteAllText(MainConst.MihomoConfPath, ExtraMihomoConfs); - MihomoConfWatcher.EnableRaisingEvents = true; - MainPres.IsMihomoIniting = false; + finally + { + File.WriteAllText(MainConst.MihomoConfPath, ExtraMihomoConfs); + MihomoConfWatcher.EnableRaisingEvents = true; + MainPres.IsMihomoIniting = false; + } } else {