From 449bb40d4898f555af32aa571b19e42a9708f952 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:20:41 +0800 Subject: [PATCH] sing-box prioritizes the use of local srs --- .../Handler/CoreConfig/CoreConfigSingbox.cs | 39 +++++++++++++------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/v2rayN/v2rayN/Handler/CoreConfig/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfig/CoreConfigSingbox.cs index d80ddeef..1d5e6442 100644 --- a/v2rayN/v2rayN/Handler/CoreConfig/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfig/CoreConfigSingbox.cs @@ -1,4 +1,5 @@ using System.Data; +using System.IO; using System.Net; using System.Net.NetworkInformation; using v2rayN.Enums; @@ -966,27 +967,41 @@ namespace v2rayN.Handler.CoreConfig } } + //Local srs files address + var localSrss = Utils.GetBinPath("srss"); + //Add ruleset srs singboxConfig.route.rule_set = []; foreach (var item in new HashSet(ruleSets)) { if (Utils.IsNullOrEmpty(item)) { continue; } var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item)); - if (customRuleset != null) + if (customRuleset is null) { - singboxConfig.route.rule_set.Add(customRuleset); - } - else - { - 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;