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