From 605c6e61a32111a3b1ff969fb238098200fc4aa8 Mon Sep 17 00:00:00 2001 From: Space Time Date: Mon, 7 Oct 2024 12:46:51 +0800 Subject: [PATCH] =?UTF-8?q?1.1.1=20->=201.1.2=20=E7=AC=AC49=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 | 62 +++++++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/Wins/MainWin.xaml.cs b/Wins/MainWin.xaml.cs index ed2f8d0..6300b6b 100644 --- a/Wins/MainWin.xaml.cs +++ b/Wins/MainWin.xaml.cs @@ -184,6 +184,7 @@ public partial class MainWin : Window { if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) return; + if (!File.Exists(MainConst.NginxConfPath)) File.Create(MainConst.NginxConfPath).Dispose(); if (!Directory.Exists(MainConst.NginxLogsPath)) @@ -300,8 +301,11 @@ public partial class MainWin : Window if (!MainPres!.IsMihomoRunning) { + if (string.IsNullOrWhiteSpace(MihomoConfs)) + throw new Exception(MainConst._ConfErrorMsg); if (MessageBox.Show(MainConst._LaunchProxyPrompt, string.Empty, MessageBoxButton.YesNo) != MessageBoxResult.Yes) return; + if (!File.Exists(MainConst.MihomoConfPath)) File.Create(MainConst.MihomoConfPath).Dispose(); @@ -576,35 +580,39 @@ public partial class MainWin : Window { if (MainConst.IsAdmin && MainPres!.IsMihomoExist) { - if (!File.Exists(MainConst.MihomoConfPath)) - File.Create(MainConst.MihomoConfPath).Dispose(); - - ExtraMihomoConfs = File.ReadAllText(MainConst.MihomoConfPath); - - Dictionary mihomoConfDict = new DeserializerBuilder() - .WithNamingConvention(HyphenatedNamingConvention.Instance) - .IgnoreUnmatchedProperties() - .Build() - .Deserialize>(ExtraMihomoConfs) ?? []; - - mihomoConfDict["mixed-port"] = 7880; - mihomoConfDict["dns"] = new + try { - enable = true, - listen = ":53", - enhancedMode = "redir-host", - nameserver = new[] { "https://doh.apad.pro/dns-query", "https://ns.net.kg/dns-query" } - }; - mihomoConfDict["tun"] = new - { - enable = true, - stack = "system", - autoRoute = true, - autoDetectInterface = true, - dnsHijack = new[] { "any:53", "tcp://any:53" } - }; + if (!File.Exists(MainConst.MihomoConfPath)) + File.Create(MainConst.MihomoConfPath).Dispose(); - MihomoConfs = new SerializerBuilder().WithNamingConvention(HyphenatedNamingConvention.Instance).Build().Serialize(mihomoConfDict); + ExtraMihomoConfs = File.ReadAllText(MainConst.MihomoConfPath); + + Dictionary mihomoConfDict = new DeserializerBuilder() + .WithNamingConvention(HyphenatedNamingConvention.Instance) + .IgnoreUnmatchedProperties() + .Build() + .Deserialize>(ExtraMihomoConfs) ?? []; + + mihomoConfDict["mixed-port"] = 7880; + mihomoConfDict["dns"] = new + { + enable = true, + listen = ":53", + enhancedMode = "redir-host", + nameserver = new[] { "https://doh.apad.pro/dns-query", "https://ns.net.kg/dns-query" } + }; + mihomoConfDict["tun"] = new + { + enable = true, + stack = "system", + autoRoute = true, + autoDetectInterface = true, + dnsHijack = new[] { "any:53", "tcp://any:53" } + }; + + MihomoConfs = new SerializerBuilder().WithNamingConvention(HyphenatedNamingConvention.Instance).Build().Serialize(mihomoConfDict); + } + catch { MihomoConfs = string.Empty; } } } private void MainWin_KeyDown(object sender, KeyEventArgs e)