feat: mode reference( #include <RelativePathWithoutExtesion.h> )

This commit is contained in:
ChsBuffer
2020-10-09 23:02:47 +08:00
parent bf6d3aae95
commit 36718e774c
4 changed files with 61 additions and 6 deletions

View File

@@ -62,7 +62,7 @@ namespace Netch.Controllers
}
aio_dial((int) NameList.TYPE_CLRNAME, "");
foreach (var rule in mode.Rule)
foreach (var rule in mode.FullRule)
{
aio_dial((int) NameList.TYPE_ADDNAME, rule);
}

View File

@@ -142,7 +142,7 @@ namespace Netch.Controllers
case 1:
// 代理规则
Logging.Info("代理 → 规则 IP");
_proxyIPs.AddRange(_savedMode.Rule.Select(IPNetwork.Parse));
_proxyIPs.AddRange(_savedMode.FullRule.Select(IPNetwork.Parse));
//处理 NAT 类型检测,由于协议的原因,无法仅通过域名确定需要代理的 IP自己记录解析了返回的 IP仅支持默认检测服务器
if (Global.Settings.STUN_Server == "stun.stunprotocol.org")
@@ -189,7 +189,7 @@ namespace Netch.Controllers
);
Logging.Info("绕行 → 规则 IP");
_directIPs.AddRange(_savedMode.Rule.Select(IPNetwork.Parse));
_directIPs.AddRange(_savedMode.FullRule.Select(IPNetwork.Parse));
Logging.Info("代理 → 全局");

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Netch.Utils;
namespace Netch.Models
@@ -42,6 +43,61 @@ namespace Netch.Models
/// </summary>
public readonly List<string> Rule = new List<string>();
public List<string> FullRule
{
get
{
var result = new List<string>();
foreach (var s in Rule)
{
if (string.IsNullOrWhiteSpace(s))
continue;
if (s.StartsWith("//"))
continue;
if (s.StartsWith("#include"))
{
var relativePath = new StringBuilder(s.Substring(8).Trim());
relativePath.Replace("<", "");
relativePath.Replace(">", "");
relativePath.Replace(".h", ".txt");
var mode = Global.Modes.FirstOrDefault(m => m.RelativePath.Equals(relativePath.ToString()));
if (mode == null)
{
Logging.Warning($"{relativePath} file included in {Remark} not found");
}
else
{
if (mode.Type != Type)
{
Logging.Warning($"{mode.Remark}'s mode is not as same as {Remark}'s mode");
}
else
{
if (mode.Rule.Any(rule => rule.StartsWith("#include")))
{
Logging.Warning("Cannot reference mode that reference other mode");
}
else
{
result.AddRange(mode.FullRule);
}
}
}
}
else
{
result.Add(s);
}
}
return result;
}
}
/// <summary>
/// 获取备注
/// </summary>

View File

@@ -60,7 +60,7 @@ namespace Netch.Utils
for (var i = 0; i < content.Length; i++)
{
var text = content[i];
var text = content[i].Trim();
if (i == 0)
{
@@ -83,8 +83,7 @@ namespace Netch.Utils
}
else
{
if (!text.StartsWith("#") && !string.IsNullOrWhiteSpace(text))
mode.Rule.Add(text.Trim());
mode.Rule.Add(text);
}
}