From e43fb5be70af34971bfc35335c33e88d0af3542d Mon Sep 17 00:00:00 2001 From: DHR60 Date: Wed, 23 Jul 2025 09:31:27 +0800 Subject: [PATCH] Regional Preset --- v2rayN/ServiceLib/Handler/ConfigHandler.cs | 51 +++++++++++++++++----- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index fd80160b..9040d70c 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -112,17 +112,10 @@ public class ConfigHandler config.ConstItem ??= new ConstItem(); - config.SimpleDNSItem ??= new SimpleDNSItem() + if (config.SimpleDNSItem == null) { - UseSystemHosts = false, - AddCommonHosts = true, - FakeIP = false, - BlockBindingQuery = true, - DirectDNS = Global.DomainDirectDNSAddress.FirstOrDefault(), - RemoteDNS = Global.DomainRemoteDNSAddress.FirstOrDefault(), - SingboxOutboundsResolveDNS = Global.DomainDirectDNSAddress.FirstOrDefault(), - SingboxFinalResolveDNS = Global.DomainPureIPDNSAddress.FirstOrDefault() - }; + InitBuiltinSimpleDNS(config); + } config.SpeedTestItem ??= new(); if (config.SpeedTestItem.SpeedTestTimeout < 10) @@ -2195,6 +2188,38 @@ public class ConfigHandler #endregion DNS + #region Simple DNS + + public static int InitBuiltinSimpleDNS(Config config) + { + config.SimpleDNSItem = new SimpleDNSItem() + { + UseSystemHosts = false, + AddCommonHosts = true, + FakeIP = false, + BlockBindingQuery = true, + DirectDNS = Global.DomainDirectDNSAddress.FirstOrDefault(), + RemoteDNS = Global.DomainRemoteDNSAddress.FirstOrDefault(), + SingboxOutboundsResolveDNS = Global.DomainDirectDNSAddress.FirstOrDefault(), + SingboxFinalResolveDNS = Global.DomainPureIPDNSAddress.FirstOrDefault() + }; + return 0; + } + + public static async Task GetExternalSimpleDNSItem(string url) + { + var downloadHandle = new DownloadService(); + var templateContent = await downloadHandle.TryDownloadString(url, true, ""); + if (templateContent.IsNullOrEmpty()) + return null; + var template = JsonUtils.Deserialize(templateContent); + if (template == null) + return null; + return template; + } + + #endregion Simple DNS + #region Regional Presets /// @@ -2216,6 +2241,8 @@ public class ConfigHandler await SQLiteHelper.Instance.DeleteAllAsync(); await InitBuiltinDNS(config); + InitBuiltinSimpleDNS(config); + return true; case EPresetType.Russia: @@ -2226,6 +2253,8 @@ public class ConfigHandler await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.Xray, Global.DNSTemplateSources[1] + "v2ray.json")); await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.sing_box, Global.DNSTemplateSources[1] + "sing_box.json")); + config.SimpleDNSItem = await GetExternalSimpleDNSItem(Global.DNSTemplateSources[1] + "simple_dns.json"); + return true; case EPresetType.Iran: @@ -2236,6 +2265,8 @@ public class ConfigHandler await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.Xray, Global.DNSTemplateSources[2] + "v2ray.json")); await SaveDNSItems(config, await GetExternalDNSItem(ECoreType.sing_box, Global.DNSTemplateSources[2] + "sing_box.json")); + config.SimpleDNSItem = await GetExternalSimpleDNSItem(Global.DNSTemplateSources[2] + "simple_dns.json"); + return true; }