Skip to content

Commit

Permalink
sing-box prioritizes the use of local srs
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Jul 8, 2024
1 parent 4caf1a1 commit 449bb40
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions v2rayN/v2rayN/Handler/CoreConfig/CoreConfigSingbox.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Data;
using System.IO;
using System.Net;
using System.Net.NetworkInformation;
using v2rayN.Enums;
Expand Down Expand Up @@ -966,27 +967,41 @@ static void AddRuleSets(List<string> ruleSets, List<string>? rule_set)
}
}

//Local srs files address
var localSrss = Utils.GetBinPath("srss");

//Add ruleset srs
singboxConfig.route.rule_set = [];
foreach (var item in new HashSet<string>(ruleSets))
{
if (Utils.IsNullOrEmpty(item)) { continue; }
var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item));
if (customRuleset != null)
{
singboxConfig.route.rule_set.Add(customRuleset);
}
else
if (customRuleset is null)
{
singboxConfig.route.rule_set.Add(new()
var pathSrs = Path.Combine(localSrss, $"{item}.srs");
if (File.Exists(pathSrs))
{
type = "remote",
format = "binary",
tag = item,
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item),
download_detour = Global.ProxyTag
});
customRuleset = new()
{
type = "local",
format = "binary",
tag = item,
path = pathSrs
};
}
else
{
customRuleset = new()
{
type = "remote",
format = "binary",
tag = item,
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item),
download_detour = Global.ProxyTag
};
}
}
singboxConfig.route.rule_set.Add(customRuleset);
}

return 0;
Expand Down

0 comments on commit 449bb40

Please sign in to comment.