mirror of
https://github.com/2dust/v2rayN.git
synced 2025-04-19 21:52:25 +00:00
AI-optimized code
This commit is contained in:
parent
c3439c5abe
commit
7e8b405555
3 changed files with 19 additions and 22 deletions
|
@ -44,7 +44,7 @@ namespace ServiceLib.Services.CoreConfig
|
|||
File.Delete(fileName);
|
||||
}
|
||||
|
||||
string addressFileName = node.Address;
|
||||
var addressFileName = node.Address;
|
||||
if (addressFileName.IsNullOrEmpty())
|
||||
{
|
||||
ret.Msg = ResUI.FailedGetDefaultConfiguration;
|
||||
|
@ -60,9 +60,9 @@ namespace ServiceLib.Services.CoreConfig
|
|||
return ret;
|
||||
}
|
||||
|
||||
string tagYamlStr1 = "!<str>";
|
||||
string tagYamlStr2 = "__strn__";
|
||||
string tagYamlStr3 = "!!str";
|
||||
var tagYamlStr1 = "!<str>";
|
||||
var tagYamlStr2 = "__strn__";
|
||||
var tagYamlStr3 = "!!str";
|
||||
var txtFile = File.ReadAllText(addressFileName);
|
||||
txtFile = txtFile.Replace(tagYamlStr1, tagYamlStr2);
|
||||
|
||||
|
@ -121,9 +121,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
{
|
||||
var tunContent = YamlUtils.FromYaml<Dictionary<string, object>>(tun);
|
||||
if (tunContent != null)
|
||||
{
|
||||
fileContent["tun"] = tunContent["tun"];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Mixin
|
||||
try
|
||||
|
@ -202,8 +204,8 @@ namespace ServiceLib.Services.CoreConfig
|
|||
|
||||
private void ModifyContentMerge(Dictionary<string, object> fileContent, string key, object value)
|
||||
{
|
||||
bool blPrepend = false;
|
||||
bool blRemoved = false;
|
||||
var blPrepend = false;
|
||||
var blRemoved = false;
|
||||
if (key.StartsWith("prepend-"))
|
||||
{
|
||||
blPrepend = true;
|
||||
|
@ -244,17 +246,11 @@ namespace ServiceLib.Services.CoreConfig
|
|||
if (blPrepend)
|
||||
{
|
||||
lstValue.Reverse();
|
||||
foreach (var item in lstValue)
|
||||
{
|
||||
lstOri.Insert(0, item);
|
||||
}
|
||||
lstValue.ForEach(item => lstOri.Insert(0, item));
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in lstValue)
|
||||
{
|
||||
lstOri.Add(item);
|
||||
}
|
||||
lstValue.ForEach(item => lstOri.Add(item));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace ServiceLib.Services.Statistics
|
|||
{
|
||||
public class StatisticsSingboxService
|
||||
{
|
||||
private Config _config;
|
||||
private readonly Config _config;
|
||||
private bool _exitFlag;
|
||||
private ClientWebSocket? webSocket;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
|
@ -18,7 +18,7 @@ namespace ServiceLib.Services.Statistics
|
|||
_updateFunc = updateFunc;
|
||||
_exitFlag = false;
|
||||
|
||||
Task.Run(Run);
|
||||
_ = Task.Run(Run);
|
||||
}
|
||||
|
||||
private async Task Init()
|
||||
|
@ -68,8 +68,7 @@ namespace ServiceLib.Services.Statistics
|
|||
}
|
||||
if (webSocket != null)
|
||||
{
|
||||
if (webSocket.State == WebSocketState.Aborted
|
||||
|| webSocket.State == WebSocketState.Closed)
|
||||
if (webSocket.State is WebSocketState.Aborted or WebSocketState.Closed)
|
||||
{
|
||||
webSocket.Abort();
|
||||
webSocket = null;
|
||||
|
@ -89,7 +88,7 @@ namespace ServiceLib.Services.Statistics
|
|||
var result = Encoding.UTF8.GetString(buffer, 0, res.Count);
|
||||
if (result.IsNotEmpty())
|
||||
{
|
||||
ParseOutput(result, out ulong up, out ulong down);
|
||||
ParseOutput(result, out var up, out var down);
|
||||
|
||||
_updateFunc?.Invoke(new ServerSpeedItem()
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@ namespace ServiceLib.Services.Statistics
|
|||
{
|
||||
private const long linkBase = 1024;
|
||||
private ServerSpeedItem _serverSpeedItem = new();
|
||||
private Config _config;
|
||||
private readonly Config _config;
|
||||
private bool _exitFlag;
|
||||
private Action<ServerSpeedItem>? _updateFunc;
|
||||
private string Url => $"{Global.HttpProtocol}{Global.Loopback}:{AppHandler.Instance.StatePort}/debug/vars";
|
||||
|
@ -15,7 +15,7 @@ namespace ServiceLib.Services.Statistics
|
|||
_updateFunc = updateFunc;
|
||||
_exitFlag = false;
|
||||
|
||||
Task.Run(Run);
|
||||
_ = Task.Run(Run);
|
||||
}
|
||||
|
||||
public void Close()
|
||||
|
@ -60,11 +60,13 @@ namespace ServiceLib.Services.Statistics
|
|||
}
|
||||
|
||||
ServerSpeedItem server = new();
|
||||
foreach (string key in source.stats.outbound.Keys)
|
||||
foreach (var key in source.stats.outbound.Keys.Cast<string>())
|
||||
{
|
||||
var value = source.stats.outbound[key];
|
||||
if (value == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var state = JsonUtils.Deserialize<V2rayMetricsVarsLink>(value.ToString());
|
||||
|
||||
if (key.StartsWith(Global.ProxyTag))
|
||||
|
|
Loading…
Reference in a new issue