From 1760a92507f155c578b3a784785481041a239064 Mon Sep 17 00:00:00 2001 From: DHR60 Date: Sun, 3 May 2026 13:58:59 +0800 Subject: [PATCH] GeoPrefix move to Global --- v2rayN/ServiceLib/Global.cs | 2 ++ .../CoreConfig/Singbox/SingboxDnsService.cs | 4 ++-- .../Singbox/SingboxRoutingService.cs | 22 +++++++++---------- .../CoreConfig/V2ray/V2rayDnsService.cs | 8 +++---- v2rayN/ServiceLib/Services/UpdateService.cs | 4 ++-- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/v2rayN/ServiceLib/Global.cs b/v2rayN/ServiceLib/Global.cs index 8de3d925..4d4f541a 100644 --- a/v2rayN/ServiceLib/Global.cs +++ b/v2rayN/ServiceLib/Global.cs @@ -67,6 +67,8 @@ public class Global public const string AsIs = "AsIs"; public const string IPIfNonMatch = "IPIfNonMatch"; public const string IPOnDemand = "IPOnDemand"; + public const string GeoSitePrefix = "geosite:"; + public const string GeoIPPrefix = "geoip:"; public const string UserEMail = "t@t.tt"; public const string AutoRunRegPath = @"Software\Microsoft\Windows\CurrentVersion\Run"; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs index 3a7cb189..c7adb720 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxDnsService.cs @@ -310,9 +310,9 @@ public partial class CoreConfigSingboxService foreach (var ip in ipItems) { - if (ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase)) + if (ip.StartsWith(Global.GeoIPPrefix, StringComparison.OrdinalIgnoreCase)) { - var region = ip["geoip:".Length..]; + var region = ip[Global.GeoIPPrefix.Length..]; if (string.IsNullOrEmpty(region)) { continue; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs index 92ee56a2..c050c863 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/Singbox/SingboxRoutingService.cs @@ -406,10 +406,10 @@ public partial class CoreConfigSingboxService { return false; } - else if (domain.StartsWith("geosite:")) + else if (domain.StartsWith(Global.GeoSitePrefix)) { rule.geosite ??= []; - rule.geosite?.Add(domain.Substring(8)); + rule.geosite?.Add(domain[Global.GeoSitePrefix.Length..]); } else if (domain.StartsWith("regexp:")) { @@ -450,28 +450,28 @@ public partial class CoreConfigSingboxService { return false; } - else if (address.Equals("geoip:private")) + else if (address.Equals($"{Global.GeoIPPrefix}private")) { rule.ip_is_private = true; } - else if (address.StartsWith("geoip:")) + else if (address.StartsWith(Global.GeoIPPrefix)) { - rule.geoip ??= new(); - rule.geoip?.Add(address.Substring(6)); + rule.geoip ??= []; + rule.geoip?.Add(address[Global.GeoIPPrefix.Length..]); } - else if (address.Equals("geoip:!private")) + else if (address.Equals($"{Global.GeoIPPrefix}!private")) { rule.ip_is_private = false; } - else if (address.StartsWith("geoip:!")) + else if (address.StartsWith($"{Global.GeoIPPrefix}!")) { - rule.geoip ??= new(); - rule.geoip?.Add(address.Substring(6)); + rule.geoip ??= []; + rule.geoip?.Add(address.Substring($"{Global.GeoIPPrefix}!".Length)); rule.invert = true; } else { - rule.ip_cidr ??= new(); + rule.ip_cidr ??= []; rule.ip_cidr?.Add(address); } return true; diff --git a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs index 0bfed021..ad395009 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/V2ray/V2rayDnsService.cs @@ -161,8 +161,8 @@ public partial class CoreConfigV2rayService .ToList(); foreach (var region in from ip in expectedIPs - where ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase) - select ip["geoip:".Length..] + where ip.StartsWith(Global.GeoIPPrefix, StringComparison.OrdinalIgnoreCase) + select ip[Global.GeoIPPrefix.Length..] into region where !string.IsNullOrEmpty(region) select region) @@ -197,7 +197,7 @@ public partial class CoreConfigV2rayService if (item.OutboundTag == Global.DirectTag) { - if (normalizedDomain.StartsWith("geosite:") || normalizedDomain.StartsWith("ext:")) + if (normalizedDomain.StartsWith(Global.GeoSitePrefix) || normalizedDomain.StartsWith("ext:")) { var isExpectedDomain = !regionName.IsNullOrEmpty() || normalizedDomain.EndsWith($"-{regionName}") @@ -212,7 +212,7 @@ public partial class CoreConfigV2rayService } else if (item.OutboundTag != Global.BlockTag) { - if (normalizedDomain.StartsWith("geosite:") || normalizedDomain.StartsWith("ext:")) + if (normalizedDomain.StartsWith(Global.GeoSitePrefix) || normalizedDomain.StartsWith("ext:")) { proxyGeositeList.Add(normalizedDomain); } diff --git a/v2rayN/ServiceLib/Services/UpdateService.cs b/v2rayN/ServiceLib/Services/UpdateService.cs index 87281149..57f9d14b 100644 --- a/v2rayN/ServiceLib/Services/UpdateService.cs +++ b/v2rayN/ServiceLib/Services/UpdateService.cs @@ -375,8 +375,8 @@ public class UpdateService(Config config, Func updateFunc) var rules = JsonUtils.Deserialize>(routing.RuleSet); foreach (var item in rules ?? []) { - AddPrefixedItems(item.Ip, "geoip:", geoipFiles); - AddPrefixedItems(item.Domain, "geosite:", geoSiteFiles); + AddPrefixedItems(item.Ip, Global.GeoIPPrefix, geoipFiles); + AddPrefixedItems(item.Domain, Global.GeoSitePrefix, geoSiteFiles); } }