mirror of
https://github.com/2dust/v2rayN.git
synced 2026-11-04 03:25:00 +03:00
Code clean (#9482)
This commit is contained in:
@@ -153,7 +153,7 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||
{
|
||||
listen = Global.Loopback,
|
||||
listen_port = port,
|
||||
type = EInboundProtocol.mixed.ToString(),
|
||||
type = nameof(EInboundProtocol.mixed),
|
||||
};
|
||||
inbound.tag = inbound.type + inbound.listen_port.ToString();
|
||||
_coreConfig.inbounds.Add(inbound);
|
||||
@@ -229,7 +229,7 @@ public partial class CoreConfigSingboxService(CoreConfigContext context)
|
||||
tag = $"{EInboundProtocol.mixed}{port}",
|
||||
listen = Global.Loopback,
|
||||
listen_port = port,
|
||||
type = EInboundProtocol.mixed.ToString(),
|
||||
type = nameof(EInboundProtocol.mixed),
|
||||
});
|
||||
ApplyOutboundBindInterface();
|
||||
ApplyOutboundSendThrough();
|
||||
|
||||
@@ -23,7 +23,7 @@ public partial class CoreConfigSingboxService
|
||||
}
|
||||
|
||||
// Process outbounds
|
||||
var customOutboundsNode = fullConfigTemplateNode["outbounds"] is JsonArray outbounds ? outbounds : [];
|
||||
var customOutboundsNode = fullConfigTemplateNode["outbounds"] as JsonArray ?? [];
|
||||
foreach (var outbound in _coreConfig.outbounds)
|
||||
{
|
||||
if (outbound.type.ToLower() is "direct" or "block")
|
||||
@@ -42,9 +42,9 @@ public partial class CoreConfigSingboxService
|
||||
fullConfigTemplateNode["outbounds"] = customOutboundsNode;
|
||||
|
||||
// Process endpoints
|
||||
if (_coreConfig.endpoints != null && _coreConfig.endpoints.Count > 0)
|
||||
if (_coreConfig.endpoints is { Count: > 0 })
|
||||
{
|
||||
var customEndpointsNode = fullConfigTemplateNode["endpoints"] is JsonArray endpoints ? endpoints : [];
|
||||
var customEndpointsNode = fullConfigTemplateNode["endpoints"] as JsonArray ?? [];
|
||||
foreach (var endpoint in _coreConfig.endpoints)
|
||||
{
|
||||
if (endpoint.detour.IsNullOrEmpty() && !fullConfigTemplate.ProxyDetour.IsNullOrEmpty())
|
||||
|
||||
@@ -26,7 +26,7 @@ public partial class CoreConfigSingboxService
|
||||
{
|
||||
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet) ?? [];
|
||||
|
||||
if (rules?.LastOrDefault() is { } lastRule && lastRule.OutboundTag == Global.DirectTag)
|
||||
if (rules?.LastOrDefault() is { OutboundTag: Global.DirectTag } lastRule)
|
||||
{
|
||||
var noDomain = lastRule.Domain == null || lastRule.Domain.Count == 0;
|
||||
var noProcess = lastRule.Process == null || lastRule.Process.Count == 0;
|
||||
@@ -82,7 +82,7 @@ public partial class CoreConfigSingboxService
|
||||
if (simpleDnsItem.UseSystemHosts == true)
|
||||
{
|
||||
var systemHosts = Utils.GetSystemHosts();
|
||||
if (systemHosts != null && systemHosts.Count > 0)
|
||||
if (systemHosts is { Count: > 0 })
|
||||
{
|
||||
foreach (var host in systemHosts)
|
||||
{
|
||||
@@ -182,13 +182,13 @@ public partial class CoreConfigSingboxService
|
||||
{
|
||||
server = Global.SingboxRemoteDNSTag,
|
||||
strategy = Utils.DomainStrategy4Sbox(simpleDnsItem.Strategy4Proxy),
|
||||
clash_mode = ERuleMode.Global.ToString()
|
||||
clash_mode = nameof(ERuleMode.Global)
|
||||
},
|
||||
new Rule4Sbox
|
||||
{
|
||||
server = Global.SingboxDirectDNSTag,
|
||||
strategy = Utils.DomainStrategy4Sbox(simpleDnsItem.Strategy4Freedom),
|
||||
clash_mode = ERuleMode.Direct.ToString()
|
||||
clash_mode = nameof(ERuleMode.Direct)
|
||||
}
|
||||
});
|
||||
|
||||
@@ -454,12 +454,12 @@ public partial class CoreConfigSingboxService
|
||||
dns4Sbox.rules.Insert(0, new()
|
||||
{
|
||||
server = tag,
|
||||
clash_mode = ERuleMode.Direct.ToString()
|
||||
clash_mode = nameof(ERuleMode.Direct)
|
||||
});
|
||||
dns4Sbox.rules.Insert(0, new()
|
||||
{
|
||||
server = dns4Sbox.servers.Where(t => t.detour == Global.ProxyTag).Select(t => t.tag).FirstOrDefault() ?? "remote",
|
||||
clash_mode = ERuleMode.Global.ToString()
|
||||
clash_mode = nameof(ERuleMode.Global)
|
||||
});
|
||||
|
||||
var finalDnsAddress = string.IsNullOrEmpty(dnsItem?.DomainDNSAddress) ? Global.DomainPureIPDNSAddress.FirstOrDefault() : dnsItem?.DomainDNSAddress;
|
||||
|
||||
@@ -15,8 +15,8 @@ public partial class CoreConfigSingboxService
|
||||
{
|
||||
var inbound = new Inbound4Sbox()
|
||||
{
|
||||
type = EInboundProtocol.mixed.ToString(),
|
||||
tag = EInboundProtocol.socks.ToString(),
|
||||
type = nameof(EInboundProtocol.mixed),
|
||||
tag = nameof(EInboundProtocol.socks),
|
||||
listen = Global.Loopback,
|
||||
};
|
||||
_coreConfig.inbounds.Add(inbound);
|
||||
@@ -87,7 +87,7 @@ public partial class CoreConfigSingboxService
|
||||
var inbound = JsonUtils.DeepCopy(inItem);
|
||||
inbound.tag = protocol.ToString();
|
||||
inbound.listen_port = inItem.listen_port + (int)protocol;
|
||||
inbound.type = EInboundProtocol.mixed.ToString();
|
||||
inbound.type = nameof(EInboundProtocol.mixed);
|
||||
return inbound;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -730,8 +730,8 @@ public partial class CoreConfigSingboxService
|
||||
{
|
||||
return;
|
||||
}
|
||||
var outbounds = servers.Where(s => s is Outbound4Sbox).Cast<Outbound4Sbox>().ToList();
|
||||
var endpoints = servers.Where(s => s is Endpoints4Sbox).Cast<Endpoints4Sbox>().ToList();
|
||||
var outbounds = servers.OfType<Outbound4Sbox>().ToList();
|
||||
var endpoints = servers.OfType<Endpoints4Sbox>().ToList();
|
||||
singboxConfig.endpoints ??= [];
|
||||
if (prepend)
|
||||
{
|
||||
|
||||
@@ -193,12 +193,12 @@ public partial class CoreConfigSingboxService
|
||||
_coreConfig.route.rules.Add(new()
|
||||
{
|
||||
outbound = Global.DirectTag,
|
||||
clash_mode = ERuleMode.Direct.ToString()
|
||||
clash_mode = nameof(ERuleMode.Direct)
|
||||
});
|
||||
_coreConfig.route.rules.Add(new()
|
||||
{
|
||||
outbound = Global.ProxyTag,
|
||||
clash_mode = ERuleMode.Global.ToString()
|
||||
clash_mode = nameof(ERuleMode.Global)
|
||||
});
|
||||
|
||||
var domainStrategy = _config.RoutingBasicItem.DomainStrategy4Singbox.NullIfEmpty();
|
||||
|
||||
@@ -18,15 +18,15 @@ public partial class CoreConfigSingboxService
|
||||
//convert route geosite & geoip to ruleset
|
||||
foreach (var rule in _coreConfig.route.rules.Where(t => t.geosite?.Count > 0).ToList() ?? [])
|
||||
{
|
||||
rule.rule_set ??= new List<string>();
|
||||
rule.rule_set.AddRange(rule?.geosite?.Select(t => $"{geosite}-{t}").ToList());
|
||||
rule.rule_set ??= [];
|
||||
rule.rule_set.AddRange(rule?.geosite?.Select(t => $"{geosite}-{t}").ToList() ?? []);
|
||||
rule.geosite = null;
|
||||
AddRuleSets(ruleSets, rule.rule_set);
|
||||
}
|
||||
foreach (var rule in _coreConfig.route.rules.Where(t => t.geoip?.Count > 0).ToList() ?? [])
|
||||
{
|
||||
rule.rule_set ??= new List<string>();
|
||||
rule.rule_set.AddRange(rule?.geoip?.Select(t => $"{geoip}-{t}").ToList());
|
||||
rule.rule_set ??= [];
|
||||
rule.rule_set.AddRange(rule?.geoip?.Select(t => $"{geoip}-{t}").ToList() ?? []);
|
||||
rule.geoip = null;
|
||||
AddRuleSets(ruleSets, rule.rule_set);
|
||||
}
|
||||
@@ -34,14 +34,14 @@ public partial class CoreConfigSingboxService
|
||||
//convert dns geosite & geoip to ruleset
|
||||
foreach (var rule in _coreConfig.dns?.rules.Where(t => t.geosite?.Count > 0).ToList() ?? [])
|
||||
{
|
||||
rule.rule_set ??= new List<string>();
|
||||
rule.rule_set.AddRange(rule?.geosite?.Select(t => $"{geosite}-{t}").ToList());
|
||||
rule.rule_set ??= [];
|
||||
rule.rule_set.AddRange(rule?.geosite?.Select(t => $"{geosite}-{t}").ToList() ?? []);
|
||||
rule.geosite = null;
|
||||
}
|
||||
foreach (var rule in _coreConfig.dns?.rules.Where(t => t.geoip?.Count > 0).ToList() ?? [])
|
||||
{
|
||||
rule.rule_set ??= new List<string>();
|
||||
rule.rule_set.AddRange(rule?.geoip?.Select(t => $"{geoip}-{t}").ToList());
|
||||
rule.rule_set ??= [];
|
||||
rule.rule_set.AddRange(rule?.geoip?.Select(t => $"{geoip}-{t}").ToList() ?? []);
|
||||
rule.geoip = null;
|
||||
}
|
||||
foreach (var dnsRule in _coreConfig.dns?.rules.Where(t => t.rule_set?.Count > 0).ToList() ?? [])
|
||||
|
||||
Reference in New Issue
Block a user