diff --git a/Netch/Controllers/MainController.cs b/Netch/Controllers/MainController.cs index ec21ae45..1110c27a 100644 --- a/Netch/Controllers/MainController.cs +++ b/Netch/Controllers/MainController.cs @@ -75,7 +75,7 @@ namespace Netch.Controllers throw new MessageException(i18N.Translate("Lookup Server hostname failed")); // 添加Netch到防火墙 - _ = Task.Run(Firewall.AddNetchFwRules); + Firewall.AddNetchFwRules(); try { diff --git a/Netch/Utils/Firewall.cs b/Netch/Utils/Firewall.cs index da4254cc..e0870c69 100644 --- a/Netch/Utils/Firewall.cs +++ b/Netch/Utils/Firewall.cs @@ -9,17 +9,6 @@ namespace Netch.Utils public static class Firewall { private const string Netch = "Netch"; - private static readonly string[] ProgramPath = - { - "bin/NTT.exe", - "bin/Privoxy.exe", - "bin/Shadowsocks.exe", - "bin/ShadowsocksR.exe", - "bin/Trojan.exe", - "bin/tun2socks.exe", - "bin/xray.exe", - "Netch.exe" - }; /// /// Netch 自带程序添加防火墙 @@ -43,12 +32,8 @@ namespace Netch.Utils RemoveNetchFwRules(); } - foreach (var p in ProgramPath) - { - var path = Path.GetFullPath(p); - if (File.Exists(path)) - AddFwRule(Netch, path); - } + foreach (var path in Directory.GetFiles(Global.NetchDir, "*.exe", SearchOption.AllDirectories)) + AddFwRule(Netch, path); } catch (Exception e) { @@ -66,7 +51,8 @@ namespace Netch.Utils try { - foreach (var rule in FirewallManager.Instance.Rules.Where(r => r.ApplicationName?.StartsWith(Global.NetchDir) ?? r.Name == Netch)) + foreach (var rule in FirewallManager.Instance.Rules.Where(r + => r.ApplicationName?.StartsWith(Global.NetchDir, StringComparison.OrdinalIgnoreCase) ?? r.Name == Netch)) FirewallManager.Instance.Rules.Remove(rule); } catch (Exception e)