diff --git a/v2rayN/ServiceLib/Handler/AppHandler.cs b/v2rayN/ServiceLib/Handler/AppHandler.cs index 496173f3..43302636 100644 --- a/v2rayN/ServiceLib/Handler/AppHandler.cs +++ b/v2rayN/ServiceLib/Handler/AppHandler.cs @@ -63,7 +63,6 @@ public sealed class AppHandler SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); SQLiteHelper.Instance.CreateTable(); - SQLiteHelper.Instance.CreateTable(); return true; } diff --git a/v2rayN/ServiceLib/Handler/ConfigHandler.cs b/v2rayN/ServiceLib/Handler/ConfigHandler.cs index 3667d7d2..78d8aa81 100644 --- a/v2rayN/ServiceLib/Handler/ConfigHandler.cs +++ b/v2rayN/ServiceLib/Handler/ConfigHandler.cs @@ -112,7 +112,7 @@ public class ConfigHandler config.ConstItem ??= new ConstItem(); - config.DNSItem ??= new DNSItem() + config.SimpleDNSItem ??= new SimpleDNSItem() { UseSystemHosts = false, AddCommonHosts = true, @@ -2118,7 +2118,7 @@ public class ConfigHandler config.ConstItem.SrsSourceUrl = ""; config.ConstItem.RouteRulesTemplateSourceUrl = ""; - await SQLiteHelper.Instance.DeleteAllAsync(); + //await SQLiteHelper.Instance.DeleteAllAsync(); return true; diff --git a/v2rayN/ServiceLib/Models/Config.cs b/v2rayN/ServiceLib/Models/Config.cs index ca032c2e..91b49b29 100644 --- a/v2rayN/ServiceLib/Models/Config.cs +++ b/v2rayN/ServiceLib/Models/Config.cs @@ -48,7 +48,7 @@ public class Config public List Inbound { get; set; } public List GlobalHotkeys { get; set; } public List CoreTypeItem { get; set; } - public DNSItem DNSItem { get; set; } + public SimpleDNSItem SimpleDNSItem { get; set; } #endregion other entities } diff --git a/v2rayN/ServiceLib/Models/ConfigItems.cs b/v2rayN/ServiceLib/Models/ConfigItems.cs index ea73ffe2..998b49f1 100644 --- a/v2rayN/ServiceLib/Models/ConfigItems.cs +++ b/v2rayN/ServiceLib/Models/ConfigItems.cs @@ -255,7 +255,7 @@ public class WindowSizeItem } [Serializable] -public class DNSItem +public class SimpleDNSItem { public bool? UseSystemHosts { get; set; } public bool? AddCommonHosts { get; set; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs index 7a16dd8f..576bdd3d 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigSingboxService.cs @@ -245,7 +245,7 @@ public class CoreConfigSingboxService singboxConfig.route.rules.Add(rule); } - await GenDnsDomains(singboxConfig, _config.DNSItem); + await GenDnsDomains(singboxConfig, _config.SimpleDNSItem); //var dnsServer = singboxConfig.dns?.servers.FirstOrDefault(); //if (dnsServer != null) //{ @@ -317,7 +317,7 @@ public class CoreConfigSingboxService await GenOutbound(node, singboxConfig.outbounds.First()); } await GenMoreOutbounds(node, singboxConfig); - await GenDnsDomains(singboxConfig, _config.DNSItem); + await GenDnsDomains(singboxConfig, _config.SimpleDNSItem); singboxConfig.route.rules.Clear(); singboxConfig.inbounds.Clear(); @@ -1225,7 +1225,7 @@ public class CoreConfigSingboxService try { singboxConfig.route.final = Global.ProxyTag; - var item = _config.DNSItem; + var item = _config.SimpleDNSItem; singboxConfig.route.default_domain_resolver = new() { server = "outbound_resolver", @@ -1575,9 +1575,9 @@ public class CoreConfigSingboxService { try { - var dNSItem = _config.DNSItem; - await GenDnsServers(singboxConfig, dNSItem); - await GenDnsRules(singboxConfig, dNSItem); + var simpleDNSItem = _config.SimpleDNSItem; + await GenDnsServers(singboxConfig, simpleDNSItem); + await GenDnsRules(singboxConfig, simpleDNSItem); singboxConfig.dns ??= new Dns4Sbox(); singboxConfig.dns.independent_cache = true; @@ -1590,20 +1590,20 @@ public class CoreConfigSingboxService return 0; } - private async Task GenDnsServers(SingboxConfig singboxConfig, DNSItem dNSItem) + private async Task GenDnsServers(SingboxConfig singboxConfig, SimpleDNSItem simpleDNSItem) { - var finalDns = await GenDnsDomains(singboxConfig, dNSItem); + var finalDns = await GenDnsDomains(singboxConfig, simpleDNSItem); - var directDns = ParseDnsAddress(dNSItem.DirectDNS); + var directDns = ParseDnsAddress(simpleDNSItem.DirectDNS); directDns.tag = "dns_direct"; directDns.domain_resolver = "final_resolver"; - var remoteDns = ParseDnsAddress(dNSItem.RemoteDNS); + var remoteDns = ParseDnsAddress(simpleDNSItem.RemoteDNS); remoteDns.tag = "dns_remote"; remoteDns.detour = Global.ProxyTag; remoteDns.domain_resolver = "final_resolver"; - var resolverDns = ParseDnsAddress(dNSItem.SingboxOutboundsResolveDNS); + var resolverDns = ParseDnsAddress(simpleDNSItem.SingboxOutboundsResolveDNS); resolverDns.tag = "outbound_resolver"; resolverDns.domain_resolver = "final_resolver"; @@ -1612,11 +1612,11 @@ public class CoreConfigSingboxService tag = "dns_hosts", type = "hosts", }; - if (dNSItem.AddCommonHosts == true) + if (simpleDNSItem.AddCommonHosts == true) { hostsDns.predefined = Global.PredefinedHosts; } - var userHostsMap = dNSItem.Hosts? + var userHostsMap = simpleDNSItem.Hosts? .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) .Where(line => !string.IsNullOrWhiteSpace(line)) .Where(line => line.Contains(' ')) @@ -1670,7 +1670,7 @@ public class CoreConfigSingboxService singboxConfig.dns.servers.Add(hostsDns); // fake ip - if (dNSItem.FakeIP == true) + if (simpleDNSItem.FakeIP == true) { var fakeip = new Server4Sbox { @@ -1685,9 +1685,9 @@ public class CoreConfigSingboxService return await Task.FromResult(0); } - private async Task GenDnsDomains(SingboxConfig singboxConfig, DNSItem? dNSItem) + private async Task GenDnsDomains(SingboxConfig singboxConfig, SimpleDNSItem? simpleDNSItem) { - var finalDns = ParseDnsAddress(dNSItem.SingboxFinalResolveDNS); + var finalDns = ParseDnsAddress(simpleDNSItem.SingboxFinalResolveDNS); finalDns.tag = "final_resolver"; singboxConfig.dns ??= new Dns4Sbox(); singboxConfig.dns.servers ??= new List(); @@ -1695,7 +1695,7 @@ public class CoreConfigSingboxService return await Task.FromResult(finalDns); } - private async Task GenDnsRules(SingboxConfig singboxConfig, DNSItem dNSItem) + private async Task GenDnsRules(SingboxConfig singboxConfig, SimpleDNSItem simpleDNSItem) { singboxConfig.dns ??= new Dns4Sbox(); singboxConfig.dns.rules ??= new List(); @@ -1706,13 +1706,13 @@ public class CoreConfigSingboxService new Rule4Sbox { server = "dns_remote", - strategy = string.IsNullOrEmpty(dNSItem.SingboxStrategy4Proxy) ? null : dNSItem.SingboxStrategy4Proxy, + strategy = simpleDNSItem.SingboxStrategy4Proxy.IsNullOrEmpty() ? null : simpleDNSItem.SingboxStrategy4Proxy, clash_mode = ERuleMode.Global.ToString() }, new Rule4Sbox { server = "dns_direct", - strategy = string.IsNullOrEmpty(dNSItem.SingboxStrategy4Direct) ? null : dNSItem.SingboxStrategy4Direct, + strategy = simpleDNSItem.SingboxStrategy4Direct.IsNullOrEmpty() ? null : simpleDNSItem.SingboxStrategy4Direct, clash_mode = ERuleMode.Direct.ToString() }, new Rule4Sbox @@ -1732,9 +1732,9 @@ public class CoreConfigSingboxService var expectedIPsRegions = new List(); var regionNames = new HashSet(); - if (!string.IsNullOrEmpty(dNSItem?.DirectExpectedIPs)) + if (!string.IsNullOrEmpty(simpleDNSItem?.DirectExpectedIPs)) { - var ipItems = dNSItem.DirectExpectedIPs + var ipItems = simpleDNSItem.DirectExpectedIPs .Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Where(s => !string.IsNullOrEmpty(s)) @@ -1777,7 +1777,7 @@ public class CoreConfigSingboxService if (item.OutboundTag == Global.DirectTag) { rule.server = "dns_direct"; - rule.strategy = string.IsNullOrEmpty(dNSItem.SingboxStrategy4Direct) ? null : dNSItem.SingboxStrategy4Direct; + rule.strategy = string.IsNullOrEmpty(simpleDNSItem.SingboxStrategy4Direct) ? null : simpleDNSItem.SingboxStrategy4Direct; if (expectedIPsRegions.Count > 0 && rule.geosite?.Count > 0) { @@ -1797,14 +1797,14 @@ public class CoreConfigSingboxService } else if (item.OutboundTag == Global.ProxyTag) { - if (dNSItem.FakeIP == true) + if (simpleDNSItem.FakeIP == true) { var rule4Fake = JsonUtils.DeepCopy(rule); rule4Fake.server = "dns-fake"; singboxConfig.dns.rules.Add(rule4Fake); } rule.server = "dns_remote"; - rule.strategy = string.IsNullOrEmpty(dNSItem.SingboxStrategy4Proxy) ? null : dNSItem.SingboxStrategy4Proxy; + rule.strategy = string.IsNullOrEmpty(simpleDNSItem.SingboxStrategy4Proxy) ? null : simpleDNSItem.SingboxStrategy4Proxy; } else if (item.OutboundTag == Global.BlockTag) { @@ -1929,7 +1929,7 @@ public class CoreConfigSingboxService { enabled = true, path = Utils.GetBinPath("cache.db"), - store_fakeip = _config.DNSItem.FakeIP == true + store_fakeip = _config.SimpleDNSItem.FakeIP == true }; } diff --git a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs index 742b1eed..cdc90e4b 100644 --- a/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs +++ b/v2rayN/ServiceLib/Services/CoreConfig/CoreConfigV2rayService.cs @@ -1137,7 +1137,7 @@ public class CoreConfigV2rayService { try { - var dNSItem = _config.DNSItem; + var dNSItem = _config.SimpleDNSItem; var domainStrategy4Freedom = dNSItem?.RayStrategy4Freedom; //Outbound Freedom domainStrategy @@ -1164,7 +1164,7 @@ public class CoreConfigV2rayService return 0; } - private async Task GenDnsServers(ProfileItem? node, V2rayConfig v2rayConfig, DNSItem dNSItem) + private async Task GenDnsServers(ProfileItem? node, V2rayConfig v2rayConfig, SimpleDNSItem simpleDNSItem) { static List ParseDnsAddresses(string? dnsInput, string defaultAddress) { @@ -1192,8 +1192,8 @@ public class CoreConfigV2rayService }); } - var directDNSAddress = ParseDnsAddresses(dNSItem?.DirectDNS, Global.DomainDirectDNSAddress.FirstOrDefault()); - var remoteDNSAddress = ParseDnsAddresses(dNSItem?.RemoteDNS, Global.DomainRemoteDNSAddress.FirstOrDefault()); + var directDNSAddress = ParseDnsAddresses(simpleDNSItem?.DirectDNS, Global.DomainDirectDNSAddress.FirstOrDefault()); + var remoteDNSAddress = ParseDnsAddresses(simpleDNSItem?.RemoteDNS, Global.DomainRemoteDNSAddress.FirstOrDefault()); var directDomainList = new List(); var directGeositeList = new List(); @@ -1203,9 +1203,9 @@ public class CoreConfigV2rayService var expectedIPs = new List(); var regionNames = new HashSet(); - if (!string.IsNullOrEmpty(dNSItem?.DirectExpectedIPs)) + if (!string.IsNullOrEmpty(simpleDNSItem?.DirectExpectedIPs)) { - expectedIPs = dNSItem.DirectExpectedIPs + expectedIPs = simpleDNSItem.DirectExpectedIPs .Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .Where(s => !string.IsNullOrEmpty(s)) @@ -1317,20 +1317,20 @@ public class CoreConfigV2rayService return 0; } - private async Task GenDnsHosts(V2rayConfig v2rayConfig, DNSItem dNSItem) + private async Task GenDnsHosts(V2rayConfig v2rayConfig, SimpleDNSItem simpleDNSItem) { - if (dNSItem.AddCommonHosts == false && dNSItem.UseSystemHosts == false && dNSItem.Hosts.IsNullOrEmpty()) + if (simpleDNSItem.AddCommonHosts == false && simpleDNSItem.UseSystemHosts == false && simpleDNSItem.Hosts.IsNullOrEmpty()) { return await Task.FromResult(0); } v2rayConfig.dns ??= new Dns4Ray(); v2rayConfig.dns.hosts ??= new Dictionary>(); - if (dNSItem.AddCommonHosts == true) + if (simpleDNSItem.AddCommonHosts == true) { v2rayConfig.dns.hosts = Global.PredefinedHosts; } - if (dNSItem.UseSystemHosts == true) + if (simpleDNSItem.UseSystemHosts == true) { var systemHosts = Utils.GetSystemHosts(); if (systemHosts.Count > 0) @@ -1350,7 +1350,7 @@ public class CoreConfigV2rayService } } - var userHostsMap = dNSItem.Hosts? + var userHostsMap = simpleDNSItem.Hosts? .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) .Where(line => !string.IsNullOrWhiteSpace(line)) .Where(line => line.Contains(' ')) diff --git a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs index ff6620d6..b2cea774 100644 --- a/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/DNSSettingViewModel.cs @@ -49,7 +49,7 @@ public class DNSSettingViewModel : MyReactiveObject private async Task Init() { _config = AppHandler.Instance.Config; - var item = _config.DNSItem; + var item = _config.SimpleDNSItem; UseSystemHosts = item.UseSystemHosts; AddCommonHosts = item.AddCommonHosts; FakeIP = item.FakeIP; @@ -67,19 +67,19 @@ public class DNSSettingViewModel : MyReactiveObject private async Task SaveSettingAsync() { - _config.DNSItem.UseSystemHosts = UseSystemHosts; - _config.DNSItem.AddCommonHosts = AddCommonHosts; - _config.DNSItem.FakeIP = FakeIP; - _config.DNSItem.BlockBindingQuery = BlockBindingQuery; - _config.DNSItem.DirectDNS = DirectDNS; - _config.DNSItem.RemoteDNS = RemoteDNS; - _config.DNSItem.RayStrategy4Freedom = RayStrategy4Freedom; - _config.DNSItem.SingboxOutboundsResolveDNS = SingboxOutboundsResolveDNS; - _config.DNSItem.SingboxFinalResolveDNS = SingboxFinalResolveDNS; - _config.DNSItem.SingboxStrategy4Direct = SingboxStrategy4Direct; - _config.DNSItem.SingboxStrategy4Proxy = SingboxStrategy4Proxy; - _config.DNSItem.Hosts = Hosts; - _config.DNSItem.DirectExpectedIPs = DirectExpectedIPs; + _config.SimpleDNSItem.UseSystemHosts = UseSystemHosts; + _config.SimpleDNSItem.AddCommonHosts = AddCommonHosts; + _config.SimpleDNSItem.FakeIP = FakeIP; + _config.SimpleDNSItem.BlockBindingQuery = BlockBindingQuery; + _config.SimpleDNSItem.DirectDNS = DirectDNS; + _config.SimpleDNSItem.RemoteDNS = RemoteDNS; + _config.SimpleDNSItem.RayStrategy4Freedom = RayStrategy4Freedom; + _config.SimpleDNSItem.SingboxOutboundsResolveDNS = SingboxOutboundsResolveDNS; + _config.SimpleDNSItem.SingboxFinalResolveDNS = SingboxFinalResolveDNS; + _config.SimpleDNSItem.SingboxStrategy4Direct = SingboxStrategy4Direct; + _config.SimpleDNSItem.SingboxStrategy4Proxy = SingboxStrategy4Proxy; + _config.SimpleDNSItem.Hosts = Hosts; + _config.SimpleDNSItem.DirectExpectedIPs = DirectExpectedIPs; await ConfigHandler.SaveConfig(_config); if (_updateView != null) {