add function to mixin, support append and prepend
This commit is contained in:
@@ -123,7 +123,14 @@ namespace clashN.Handler
|
||||
}
|
||||
|
||||
//Mixin
|
||||
MixinContent(fileContent, config, node);
|
||||
try
|
||||
{
|
||||
MixinContent(fileContent, config, node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog("GenerateClientCustomConfig-Mixin", ex);
|
||||
}
|
||||
|
||||
File.WriteAllText(fileName, Utils.ToYaml(fileContent));
|
||||
//check again
|
||||
@@ -174,7 +181,14 @@ namespace clashN.Handler
|
||||
continue;
|
||||
}
|
||||
|
||||
ModifyContent(fileContent, item.Key, item.Value);
|
||||
if (item.Key.StartsWith("prepend-") || item.Key.StartsWith("append-"))
|
||||
{
|
||||
ModifyContentMerge(fileContent, item.Key, item.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModifyContent(fileContent, item.Key, item.Value);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -190,5 +204,45 @@ namespace clashN.Handler
|
||||
fileContent.Add(key, value);
|
||||
}
|
||||
}
|
||||
private static void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
||||
{
|
||||
bool blPrepend = false;
|
||||
if (key.StartsWith("prepend-"))
|
||||
{
|
||||
blPrepend = true;
|
||||
key = key.Replace("prepend-", "");
|
||||
}
|
||||
else if (key.StartsWith("append-"))
|
||||
{
|
||||
blPrepend = false;
|
||||
key = key.Replace("append-", "");
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!fileContent.ContainsKey(key))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var lstOri = (List<object>)fileContent[key];
|
||||
var lstValue = (List<object>)value;
|
||||
|
||||
if (blPrepend)
|
||||
{
|
||||
lstValue.Reverse();
|
||||
foreach (var item in lstValue)
|
||||
{
|
||||
lstOri.Insert(0, item);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in lstValue)
|
||||
{
|
||||
lstOri.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,16 @@
|
||||
#
|
||||
# 注意下面缩进,请用支持yaml显示的编辑器打开
|
||||
#
|
||||
# 使用clash配置文件关键字则覆盖原配置
|
||||
#
|
||||
# append-rules 数组合并至原配置rules数组后
|
||||
# prepend-rules 数组合并至原配置rules数组前
|
||||
# append-proxies 数组合并至原配置proxies数组后
|
||||
# prepend-proxies 数组合并至原配置proxies数组前
|
||||
# append-proxy-groups 数组合并至原配置proxy-groups数组后
|
||||
# prepend-proxy-groups 数组合并至原配置proxy-groups数组前
|
||||
#
|
||||
|
||||
dns:
|
||||
enable: true
|
||||
enhanced-mode: fake-ip
|
||||
|
||||
Reference in New Issue
Block a user