Fix: Remove in directory firewall rules ignore application name case

Fix: Windows Firewall Notification
Refactor: create firewall rules by searching directory exe files
This commit is contained in:
ChsBuffer
2021-02-26 13:52:29 +08:00
parent 140912bd2f
commit fde71e922f
2 changed files with 5 additions and 19 deletions

View File

@@ -75,7 +75,7 @@ namespace Netch.Controllers
throw new MessageException(i18N.Translate("Lookup Server hostname failed"));
// 添加Netch到防火墙
_ = Task.Run(Firewall.AddNetchFwRules);
Firewall.AddNetchFwRules();
try
{

View File

@@ -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"
};
/// <summary>
/// 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)