Refactor Utils

This commit is contained in:
2dust 2024-01-10 10:43:48 +08:00
parent 4a67e963ed
commit ea95c6de79
34 changed files with 342 additions and 384 deletions

View file

@ -2,7 +2,6 @@
using System.Windows.Threading; using System.Windows.Threading;
using v2rayN.Handler; using v2rayN.Handler;
using v2rayN.Mode; using v2rayN.Mode;
using v2rayN.Tool;
namespace v2rayN namespace v2rayN
{ {
@ -45,7 +44,7 @@ namespace v2rayN
Logging.Setup(); Logging.Setup();
Init(); Init();
Logging.LoggingEnabled(_config.guiItem.enableLog); Logging.LoggingEnabled(_config.guiItem.enableLog);
Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}"); Logging.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
Logging.ClearLogs(); Logging.ClearLogs();
Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage); Thread.CurrentThread.CurrentUICulture = new(_config.uiItem.currentLanguage);
@ -70,7 +69,7 @@ namespace v2rayN
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{ {
Utils.SaveLog("App_DispatcherUnhandledException", e.Exception); Logging.SaveLog("App_DispatcherUnhandledException", e.Exception);
e.Handled = true; e.Handled = true;
} }
@ -78,13 +77,13 @@ namespace v2rayN
{ {
if (e.ExceptionObject != null) if (e.ExceptionObject != null)
{ {
Utils.SaveLog("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject!); Logging.SaveLog("CurrentDomain_UnhandledException", (Exception)e.ExceptionObject!);
} }
} }
private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e) private void TaskScheduler_UnobservedTaskException(object? sender, UnobservedTaskExceptionEventArgs e)
{ {
Utils.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception); Logging.SaveLog("TaskScheduler_UnobservedTaskException", e.Exception);
} }
} }
} }

View file

@ -35,7 +35,7 @@ namespace v2rayN.Base
public async Task PutAsync(string url, Dictionary<string, string> headers) public async Task PutAsync(string url, Dictionary<string, string> headers)
{ {
var jsonContent = Utils.ToJson(headers); var jsonContent = JsonUtils.ToJson(headers);
var content = new StringContent(jsonContent, Encoding.UTF8, MediaTypeNames.Application.Json); var content = new StringContent(jsonContent, Encoding.UTF8, MediaTypeNames.Application.Json);
var result = await httpClient.PutAsync(url, content); var result = await httpClient.PutAsync(url, content);

View file

@ -29,13 +29,13 @@ namespace v2rayN.Handler
if (!Utils.IsNullOrEmpty(result)) if (!Utils.IsNullOrEmpty(result))
{ {
//转成Json //转成Json
config = Utils.FromJson<Config>(result); config = JsonUtils.FromJson<Config>(result);
} }
else else
{ {
if (File.Exists(Utils.GetConfigPath(configRes))) if (File.Exists(Utils.GetConfigPath(configRes)))
{ {
Utils.SaveLog("LoadConfig Exception"); Logging.SaveLog("LoadConfig Exception");
return -1; return -1;
} }
} }
@ -234,7 +234,7 @@ namespace v2rayN.Handler
//save temp file //save temp file
var resPath = Utils.GetConfigPath(configRes); var resPath = Utils.GetConfigPath(configRes);
var tempPath = $"{resPath}_temp"; var tempPath = $"{resPath}_temp";
if (Utils.ToJsonFile(config, tempPath) != 0) if (JsonUtils.ToJsonFile(config, tempPath) != 0)
{ {
return; return;
} }
@ -248,7 +248,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("ToJsonFile", ex); Logging.SaveLog("ToJsonFile", ex);
} }
} }
} }
@ -261,13 +261,13 @@ namespace v2rayN.Handler
return -1; return -1;
} }
var configOld = Utils.FromJson<ConfigOld>(result); var configOld = JsonUtils.FromJson<ConfigOld>(result);
if (configOld == null) if (configOld == null)
{ {
return -1; return -1;
} }
var subItem = Utils.FromJson<List<SubItem>>(Utils.ToJson(configOld.subItem)); var subItem = JsonUtils.FromJson<List<SubItem>>(JsonUtils.ToJson(configOld.subItem));
foreach (var it in subItem) foreach (var it in subItem)
{ {
if (Utils.IsNullOrEmpty(it.id)) if (Utils.IsNullOrEmpty(it.id))
@ -277,7 +277,7 @@ namespace v2rayN.Handler
SqliteHelper.Instance.Replace(it); SqliteHelper.Instance.Replace(it);
} }
var profileItems = Utils.FromJson<List<ProfileItem>>(Utils.ToJson(configOld.vmess)); var profileItems = JsonUtils.FromJson<List<ProfileItem>>(JsonUtils.ToJson(configOld.vmess));
foreach (var it in profileItems) foreach (var it in profileItems)
{ {
if (Utils.IsNullOrEmpty(it.indexId)) if (Utils.IsNullOrEmpty(it.indexId))
@ -293,13 +293,13 @@ namespace v2rayN.Handler
{ {
continue; continue;
} }
var routing = Utils.FromJson<RoutingItem>(Utils.ToJson(it)); var routing = JsonUtils.FromJson<RoutingItem>(JsonUtils.ToJson(it));
foreach (var it2 in it.rules) foreach (var it2 in it.rules)
{ {
it2.id = Utils.GetGUID(false); it2.id = Utils.GetGUID(false);
} }
routing.ruleNum = it.rules.Count; routing.ruleNum = it.rules.Count;
routing.ruleSet = Utils.ToJson(it.rules, false); routing.ruleSet = JsonUtils.ToJson(it.rules, false);
if (Utils.IsNullOrEmpty(routing.id)) if (Utils.IsNullOrEmpty(routing.id))
{ {
@ -308,7 +308,7 @@ namespace v2rayN.Handler
SqliteHelper.Instance.Replace(routing); SqliteHelper.Instance.Replace(routing);
} }
config = Utils.FromJson<Config>(Utils.ToJson(configOld)); config = JsonUtils.FromJson<Config>(JsonUtils.ToJson(configOld));
if (config.coreBasicItem == null) if (config.coreBasicItem == null)
{ {
@ -424,7 +424,7 @@ namespace v2rayN.Handler
continue; continue;
} }
ProfileItem profileItem = Utils.DeepCopy(item); ProfileItem profileItem = JsonUtils.DeepCopy(item);
profileItem.indexId = string.Empty; profileItem.indexId = string.Empty;
profileItem.remarks = $"{item.remarks}-clone"; profileItem.remarks = $"{item.remarks}-clone";
@ -595,7 +595,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return -1; return -1;
} }
@ -1007,7 +1007,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("Remove Item", ex); Logging.SaveLog("Remove Item", ex);
} }
return 0; return 0;
@ -1163,7 +1163,7 @@ namespace v2rayN.Handler
ProfileItem profileItem = new(); ProfileItem profileItem = new();
//Is v2ray configuration //Is v2ray configuration
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(clipboardData); V2rayConfig? v2rayConfig = JsonUtils.FromJson<V2rayConfig>(clipboardData);
if (v2rayConfig?.inbounds?.Count > 0 if (v2rayConfig?.inbounds?.Count > 0
&& v2rayConfig.outbounds?.Count > 0) && v2rayConfig.outbounds?.Count > 0)
{ {
@ -1254,10 +1254,10 @@ namespace v2rayN.Handler
} }
//SsSIP008 //SsSIP008
var lstSsServer = Utils.FromJson<List<SsServer>>(clipboardData); var lstSsServer = JsonUtils.FromJson<List<SsServer>>(clipboardData);
if (lstSsServer?.Count <= 0) if (lstSsServer?.Count <= 0)
{ {
var ssSIP008 = Utils.FromJson<SsSIP008>(clipboardData); var ssSIP008 = JsonUtils.FromJson<SsSIP008>(clipboardData);
if (ssSIP008?.servers?.Count > 0) if (ssSIP008?.servers?.Count > 0)
{ {
lstSsServer = ssSIP008.servers; lstSsServer = ssSIP008.servers;
@ -1469,7 +1469,7 @@ namespace v2rayN.Handler
return -1; return -1;
} }
var lstRules = Utils.FromJson<List<RulesItem>>(clipboardData); var lstRules = JsonUtils.FromJson<List<RulesItem>>(clipboardData);
if (lstRules == null) if (lstRules == null)
{ {
return -1; return -1;
@ -1480,7 +1480,7 @@ namespace v2rayN.Handler
item.id = Utils.GetGUID(false); item.id = Utils.GetGUID(false);
} }
routingItem.ruleNum = lstRules.Count; routingItem.ruleNum = lstRules.Count;
routingItem.ruleSet = Utils.ToJson(lstRules, false); routingItem.ruleSet = JsonUtils.ToJson(lstRules, false);
if (Utils.IsNullOrEmpty(routingItem.id)) if (Utils.IsNullOrEmpty(routingItem.id))
{ {
@ -1519,7 +1519,7 @@ namespace v2rayN.Handler
{ {
return 0; return 0;
} }
var item = Utils.DeepCopy(rules[index]); var item = JsonUtils.DeepCopy(rules[index]);
rules.RemoveAt(index); rules.RemoveAt(index);
rules.Insert(0, item); rules.Insert(0, item);
@ -1531,7 +1531,7 @@ namespace v2rayN.Handler
{ {
return 0; return 0;
} }
var item = Utils.DeepCopy(rules[index]); var item = JsonUtils.DeepCopy(rules[index]);
rules.RemoveAt(index); rules.RemoveAt(index);
rules.Insert(index - 1, item); rules.Insert(index - 1, item);
@ -1544,7 +1544,7 @@ namespace v2rayN.Handler
{ {
return 0; return 0;
} }
var item = Utils.DeepCopy(rules[index]); var item = JsonUtils.DeepCopy(rules[index]);
rules.RemoveAt(index); rules.RemoveAt(index);
rules.Insert(index + 1, item); rules.Insert(index + 1, item);
@ -1556,7 +1556,7 @@ namespace v2rayN.Handler
{ {
return 0; return 0;
} }
var item = Utils.DeepCopy(rules[index]); var item = JsonUtils.DeepCopy(rules[index]);
rules.RemoveAt(index); rules.RemoveAt(index);
rules.Add(item); rules.Add(item);
@ -1565,7 +1565,7 @@ namespace v2rayN.Handler
case EMove.Position: case EMove.Position:
{ {
var removeItem = rules[index]; var removeItem = rules[index];
var item = Utils.DeepCopy(rules[index]); var item = JsonUtils.DeepCopy(rules[index]);
rules.Insert(pos, item); rules.Insert(pos, item);
rules.Remove(removeItem); rules.Remove(removeItem);
break; break;

View file

@ -35,11 +35,11 @@ namespace v2rayN.Handler
} }
if (Utils.IsNullOrEmpty(fileName)) if (Utils.IsNullOrEmpty(fileName))
{ {
content = Utils.ToJson(singboxConfig); content = JsonUtils.ToJson(singboxConfig);
} }
else else
{ {
Utils.ToJsonFile(singboxConfig, fileName, false); JsonUtils.ToJsonFile(singboxConfig, fileName, false);
} }
} }
else else
@ -51,17 +51,17 @@ namespace v2rayN.Handler
} }
if (Utils.IsNullOrEmpty(fileName)) if (Utils.IsNullOrEmpty(fileName))
{ {
content = Utils.ToJson(v2rayConfig); content = JsonUtils.ToJson(v2rayConfig);
} }
else else
{ {
Utils.ToJsonFile(v2rayConfig, fileName, false); JsonUtils.ToJsonFile(v2rayConfig, fileName, false);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("GenerateClientConfig", ex); Logging.SaveLog("GenerateClientConfig", ex);
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
return -1; return -1;
} }
@ -143,7 +143,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("GenerateClientCustomConfig", ex); Logging.SaveLog("GenerateClientCustomConfig", ex);
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
return -1; return -1;
} }
@ -158,7 +158,7 @@ namespace v2rayN.Handler
{ {
return -1; return -1;
} }
Utils.ToJsonFile(singboxConfig, fileName, false); JsonUtils.ToJsonFile(singboxConfig, fileName, false);
} }
else else
{ {
@ -166,8 +166,7 @@ namespace v2rayN.Handler
{ {
return -1; return -1;
} }
JsonUtils.ToJsonFile(v2rayConfig, fileName, false);
Utils.ToJsonFile(v2rayConfig, fileName, false);
} }
return 0; return 0;
} }

View file

@ -36,7 +36,7 @@ namespace v2rayN.Handler
return -1; return -1;
} }
singboxConfig = Utils.FromJson<SingboxConfig>(result); singboxConfig = JsonUtils.FromJson<SingboxConfig>(result);
if (singboxConfig == null) if (singboxConfig == null)
{ {
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
@ -61,7 +61,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("GenerateClientConfig4Singbox", ex); Logging.SaveLog("GenerateClientConfig4Singbox", ex);
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
return -1; return -1;
} }
@ -101,7 +101,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -178,7 +178,7 @@ namespace v2rayN.Handler
_config.tunModeItem.stack = Global.TunStacks[0]; _config.tunModeItem.stack = Global.TunStacks[0];
} }
var tunInbound = Utils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName)); var tunInbound = JsonUtils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName));
tunInbound.mtu = _config.tunModeItem.mtu; tunInbound.mtu = _config.tunModeItem.mtu;
tunInbound.strict_route = _config.tunModeItem.strictRoute; tunInbound.strict_route = _config.tunModeItem.strictRoute;
tunInbound.stack = _config.tunModeItem.stack; tunInbound.stack = _config.tunModeItem.stack;
@ -192,14 +192,14 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
private Inbound4Sbox? GetInbound(Inbound4Sbox inItem, string tag, int offset, bool bSocks) private Inbound4Sbox? GetInbound(Inbound4Sbox inItem, string tag, int offset, bool bSocks)
{ {
var inbound = Utils.DeepCopy(inItem); var inbound = JsonUtils.DeepCopy(inItem);
inbound.tag = tag; inbound.tag = tag;
inbound.listen_port = inItem.listen_port + offset; inbound.listen_port = inItem.listen_port + offset;
inbound.type = bSocks ? Global.InboundSocks : Global.InboundHttp; inbound.type = bSocks ? Global.InboundSocks : Global.InboundHttp;
@ -304,7 +304,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -329,7 +329,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -379,7 +379,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -431,7 +431,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -459,7 +459,7 @@ namespace v2rayN.Handler
if (prevNode is not null if (prevNode is not null
&& prevNode.configType != EConfigType.Custom) && prevNode.configType != EConfigType.Custom)
{ {
var prevOutbound = Utils.FromJson<Outbound4Sbox>(txtOutbound); var prevOutbound = JsonUtils.FromJson<Outbound4Sbox>(txtOutbound);
GenOutbound(prevNode, prevOutbound); GenOutbound(prevNode, prevOutbound);
prevOutbound.tag = $"{Global.ProxyTag}2"; prevOutbound.tag = $"{Global.ProxyTag}2";
singboxConfig.outbounds.Add(prevOutbound); singboxConfig.outbounds.Add(prevOutbound);
@ -472,7 +472,7 @@ namespace v2rayN.Handler
if (nextNode is not null if (nextNode is not null
&& nextNode.configType != EConfigType.Custom) && nextNode.configType != EConfigType.Custom)
{ {
var nextOutbound = Utils.FromJson<Outbound4Sbox>(txtOutbound); var nextOutbound = JsonUtils.FromJson<Outbound4Sbox>(txtOutbound);
GenOutbound(nextNode, nextOutbound); GenOutbound(nextNode, nextOutbound);
nextOutbound.tag = Global.ProxyTag; nextOutbound.tag = Global.ProxyTag;
singboxConfig.outbounds.Insert(0, nextOutbound); singboxConfig.outbounds.Insert(0, nextOutbound);
@ -483,7 +483,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
@ -497,7 +497,7 @@ namespace v2rayN.Handler
{ {
singboxConfig.route.auto_detect_interface = true; singboxConfig.route.auto_detect_interface = true;
var tunRules = Utils.FromJson<List<Rule4Sbox>>(Utils.GetEmbedText(Global.TunSingboxRulesFileName)); var tunRules = JsonUtils.FromJson<List<Rule4Sbox>>(Utils.GetEmbedText(Global.TunSingboxRulesFileName));
singboxConfig.route.rules.AddRange(tunRules); singboxConfig.route.rules.AddRange(tunRules);
GenRoutingDirectExe(out List<string> lstDnsExe, out List<string> lstDirectExe); GenRoutingDirectExe(out List<string> lstDnsExe, out List<string> lstDirectExe);
@ -520,7 +520,7 @@ namespace v2rayN.Handler
var routing = ConfigHandler.GetDefaultRouting(_config); var routing = ConfigHandler.GetDefaultRouting(_config);
if (routing != null) if (routing != null)
{ {
var rules = Utils.FromJson<List<RulesItem>>(routing.ruleSet); var rules = JsonUtils.FromJson<List<RulesItem>>(routing.ruleSet);
foreach (var item in rules!) foreach (var item in rules!)
{ {
if (item.enabled) if (item.enabled)
@ -535,7 +535,7 @@ namespace v2rayN.Handler
var lockedItem = ConfigHandler.GetLockedRoutingItem(_config); var lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
if (lockedItem != null) if (lockedItem != null)
{ {
var rules = Utils.FromJson<List<RulesItem>>(lockedItem.ruleSet); var rules = JsonUtils.FromJson<List<RulesItem>>(lockedItem.ruleSet);
foreach (var item in rules!) foreach (var item in rules!)
{ {
GenRoutingUserRule(item, singboxConfig.route.rules); GenRoutingUserRule(item, singboxConfig.route.rules);
@ -545,7 +545,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -609,8 +609,8 @@ namespace v2rayN.Handler
{ {
rule.inbound = item.inboundTag; rule.inbound = item.inboundTag;
} }
var rule2 = Utils.DeepCopy(rule); var rule2 = JsonUtils.DeepCopy(rule);
var rule3 = Utils.DeepCopy(rule); var rule3 = JsonUtils.DeepCopy(rule);
var hasDomainIp = false; var hasDomainIp = false;
if (item.domain?.Count > 0) if (item.domain?.Count > 0)
@ -647,7 +647,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -727,7 +727,7 @@ namespace v2rayN.Handler
{ {
tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName); tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName);
} }
dns4Sbox = Utils.FromJson<Dns4Sbox>(tunDNS); dns4Sbox = JsonUtils.FromJson<Dns4Sbox>(tunDNS);
} }
else else
{ {
@ -738,7 +738,7 @@ namespace v2rayN.Handler
normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}"; normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}";
} }
dns4Sbox = Utils.FromJson<Dns4Sbox>(normalDNS); dns4Sbox = JsonUtils.FromJson<Dns4Sbox>(normalDNS);
} }
if (dns4Sbox is null) if (dns4Sbox is null)
{ {
@ -765,7 +765,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -822,7 +822,7 @@ namespace v2rayN.Handler
return -1; return -1;
} }
singboxConfig = Utils.FromJson<SingboxConfig>(result); singboxConfig = JsonUtils.FromJson<SingboxConfig>(result);
if (singboxConfig == null) if (singboxConfig == null)
{ {
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
@ -838,7 +838,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
GenLog(singboxConfig); GenLog(singboxConfig);
@ -920,7 +920,7 @@ namespace v2rayN.Handler
continue; continue;
} }
var outbound = Utils.FromJson<Outbound4Sbox>(txtOutbound); var outbound = JsonUtils.FromJson<Outbound4Sbox>(txtOutbound);
GenOutbound(item, outbound); GenOutbound(item, outbound);
outbound.tag = Global.ProxyTag + inbound.listen_port.ToString(); outbound.tag = Global.ProxyTag + inbound.listen_port.ToString();
singboxConfig.outbounds.Add(outbound); singboxConfig.outbounds.Add(outbound);
@ -939,7 +939,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
return -1; return -1;
} }

View file

@ -38,7 +38,7 @@ namespace v2rayN.Handler
return -1; return -1;
} }
v2rayConfig = Utils.FromJson<V2rayConfig>(result); v2rayConfig = JsonUtils.FromJson<V2rayConfig>(result);
if (v2rayConfig == null) if (v2rayConfig == null)
{ {
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
@ -63,7 +63,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("GenerateClientConfig4V2ray", ex); Logging.SaveLog("GenerateClientConfig4V2ray", ex);
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
return -1; return -1;
} }
@ -92,7 +92,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -141,7 +141,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -154,7 +154,7 @@ namespace v2rayN.Handler
return null; return null;
} }
var inbound = Utils.FromJson<Inbounds4Ray>(result); var inbound = JsonUtils.FromJson<Inbounds4Ray>(result);
if (inbound == null) if (inbound == null)
{ {
return null; return null;
@ -187,12 +187,12 @@ namespace v2rayN.Handler
{ {
v2rayConfig.routing.domainStrategy = routing.domainStrategy; v2rayConfig.routing.domainStrategy = routing.domainStrategy;
} }
var rules = Utils.FromJson<List<RulesItem>>(routing.ruleSet); var rules = JsonUtils.FromJson<List<RulesItem>>(routing.ruleSet);
foreach (var item in rules) foreach (var item in rules)
{ {
if (item.enabled) if (item.enabled)
{ {
var item2 = Utils.FromJson<RulesItem4Ray>(Utils.ToJson(item)); var item2 = JsonUtils.FromJson<RulesItem4Ray>(JsonUtils.ToJson(item));
GenRoutingUserRule(item2, v2rayConfig); GenRoutingUserRule(item2, v2rayConfig);
} }
} }
@ -203,10 +203,10 @@ namespace v2rayN.Handler
var lockedItem = ConfigHandler.GetLockedRoutingItem(_config); var lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
if (lockedItem != null) if (lockedItem != null)
{ {
var rules = Utils.FromJson<List<RulesItem>>(lockedItem.ruleSet); var rules = JsonUtils.FromJson<List<RulesItem>>(lockedItem.ruleSet);
foreach (var item in rules) foreach (var item in rules)
{ {
var item2 = Utils.FromJson<RulesItem4Ray>(Utils.ToJson(item)); var item2 = JsonUtils.FromJson<RulesItem4Ray>(JsonUtils.ToJson(item));
GenRoutingUserRule(item2, v2rayConfig); GenRoutingUserRule(item2, v2rayConfig);
} }
} }
@ -215,7 +215,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -252,7 +252,7 @@ namespace v2rayN.Handler
var hasDomainIp = false; var hasDomainIp = false;
if (rules.domain?.Count > 0) if (rules.domain?.Count > 0)
{ {
var it = Utils.DeepCopy(rules); var it = JsonUtils.DeepCopy(rules);
it.ip = null; it.ip = null;
it.type = "field"; it.type = "field";
for (int k = it.domain.Count - 1; k >= 0; k--) for (int k = it.domain.Count - 1; k >= 0; k--)
@ -268,7 +268,7 @@ namespace v2rayN.Handler
} }
if (rules.ip?.Count > 0) if (rules.ip?.Count > 0)
{ {
var it = Utils.DeepCopy(rules); var it = JsonUtils.DeepCopy(rules);
it.domain = null; it.domain = null;
it.type = "field"; it.type = "field";
v2rayConfig.routing.rules.Add(it); v2rayConfig.routing.rules.Add(it);
@ -281,7 +281,7 @@ namespace v2rayN.Handler
|| (rules.inboundTag?.Count > 0) || (rules.inboundTag?.Count > 0)
) )
{ {
var it = Utils.DeepCopy(rules); var it = JsonUtils.DeepCopy(rules);
it.type = "field"; it.type = "field";
v2rayConfig.routing.rules.Add(it); v2rayConfig.routing.rules.Add(it);
} }
@ -289,7 +289,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -478,7 +478,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -500,7 +500,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -688,7 +688,7 @@ namespace v2rayN.Handler
pathHttp = string.Join("\",\"", arrPath); pathHttp = string.Join("\",\"", arrPath);
} }
request = request.Replace("$requestPath$", $"\"{pathHttp}\""); request = request.Replace("$requestPath$", $"\"{pathHttp}\"");
tcpSettings.header.request = Utils.FromJson<object>(request); tcpSettings.header.request = JsonUtils.FromJson<object>(request);
streamSettings.tcpSettings = tcpSettings; streamSettings.tcpSettings = tcpSettings;
} }
@ -697,7 +697,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -722,7 +722,7 @@ namespace v2rayN.Handler
outbound.settings.userLevel = 0; outbound.settings.userLevel = 0;
} }
var obj = Utils.ParseJson(normalDNS) ?? new JObject(); var obj = JsonUtils.ParseJson(normalDNS) ?? new JObject();
if (!obj.ContainsKey("servers")) if (!obj.ContainsKey("servers"))
{ {
@ -769,7 +769,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
} }
@ -849,7 +849,7 @@ namespace v2rayN.Handler
&& prevNode.configType != EConfigType.Hysteria2 && prevNode.configType != EConfigType.Hysteria2
&& prevNode.configType != EConfigType.Tuic) && prevNode.configType != EConfigType.Tuic)
{ {
var prevOutbound = Utils.FromJson<Outbounds4Ray>(txtOutbound); var prevOutbound = JsonUtils.FromJson<Outbounds4Ray>(txtOutbound);
GenOutbound(prevNode, prevOutbound); GenOutbound(prevNode, prevOutbound);
prevOutbound.tag = $"{Global.ProxyTag}2"; prevOutbound.tag = $"{Global.ProxyTag}2";
v2rayConfig.outbounds.Add(prevOutbound); v2rayConfig.outbounds.Add(prevOutbound);
@ -867,7 +867,7 @@ namespace v2rayN.Handler
&& nextNode.configType != EConfigType.Hysteria2 && nextNode.configType != EConfigType.Hysteria2
&& nextNode.configType != EConfigType.Tuic) && nextNode.configType != EConfigType.Tuic)
{ {
var nextOutbound = Utils.FromJson<Outbounds4Ray>(txtOutbound); var nextOutbound = JsonUtils.FromJson<Outbounds4Ray>(txtOutbound);
GenOutbound(nextNode, nextOutbound); GenOutbound(nextNode, nextOutbound);
nextOutbound.tag = Global.ProxyTag; nextOutbound.tag = Global.ProxyTag;
v2rayConfig.outbounds.Insert(0, nextOutbound); v2rayConfig.outbounds.Insert(0, nextOutbound);
@ -881,7 +881,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return 0; return 0;
@ -912,7 +912,7 @@ namespace v2rayN.Handler
return -1; return -1;
} }
v2rayConfig = Utils.FromJson<V2rayConfig>(result); v2rayConfig = JsonUtils.FromJson<V2rayConfig>(result);
if (v2rayConfig == null) if (v2rayConfig == null)
{ {
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
@ -928,7 +928,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
GenLog(v2rayConfig); GenLog(v2rayConfig);
@ -1009,7 +1009,7 @@ namespace v2rayN.Handler
continue; continue;
} }
var outbound = Utils.FromJson<Outbounds4Ray>(txtOutbound); var outbound = JsonUtils.FromJson<Outbounds4Ray>(txtOutbound);
GenOutbound(item, outbound); GenOutbound(item, outbound);
outbound.tag = Global.ProxyTag + inbound.port.ToString(); outbound.tag = Global.ProxyTag + inbound.port.ToString();
v2rayConfig.outbounds.Add(outbound); v2rayConfig.outbounds.Add(outbound);
@ -1029,7 +1029,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
msg = ResUI.FailedGenDefaultConfiguration; msg = ResUI.FailedGenDefaultConfiguration;
return -1; return -1;
} }

View file

@ -59,7 +59,7 @@ namespace v2rayN.Handler
{ {
CoreStart(node); CoreStart(node);
ShowMsg(false, "Tun mode restart the core once"); ShowMsg(false, "Tun mode restart the core once");
Utils.SaveLog("Tun mode restart the core once"); Logging.SaveLog("Tun mode restart the core once");
} }
} }
}); });
@ -120,7 +120,7 @@ namespace v2rayN.Handler
foreach (Process p in existing) foreach (Process p in existing)
{ {
string? path = p.MainModule?.FileName; string? path = p.MainModule?.FileName;
if (path == $"{Utils.GetBinPath(vName, it.coreType)}.exe") if (path == $"{Utils.GetBinPath(vName, it.coreType.ToString())}.exe")
{ {
KillProcess(p); KillProcess(p);
} }
@ -131,7 +131,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -144,7 +144,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -154,7 +154,7 @@ namespace v2rayN.Handler
foreach (string name in coreInfo.coreExes) foreach (string name in coreInfo.coreExes)
{ {
string vName = $"{name}.exe"; string vName = $"{name}.exe";
vName = Utils.GetBinPath(vName, coreInfo.coreType); vName = Utils.GetBinPath(vName, coreInfo.coreType.ToString());
if (File.Exists(vName)) if (File.Exists(vName))
{ {
fileName = vName; fileName = vName;
@ -163,8 +163,8 @@ namespace v2rayN.Handler
} }
if (Utils.IsNullOrEmpty(fileName)) if (Utils.IsNullOrEmpty(fileName))
{ {
string msg = string.Format(ResUI.NotFoundCore, Utils.GetBinPath("", coreInfo.coreType), string.Join(", ", coreInfo.coreExes.ToArray()), coreInfo.coreUrl); string msg = string.Format(ResUI.NotFoundCore, Utils.GetBinPath("", coreInfo.coreType.ToString()), string.Join(", ", coreInfo.coreExes.ToArray()), coreInfo.coreUrl);
Utils.SaveLog(msg); Logging.SaveLog(msg);
ShowMsg(false, msg); ShowMsg(false, msg);
} }
return fileName; return fileName;
@ -237,7 +237,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
string msg = ex.Message; string msg = ex.Message;
ShowMsg(false, msg); ShowMsg(false, msg);
return -1; return -1;
@ -311,7 +311,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
string msg = ex.Message; string msg = ex.Message;
update(true, msg); update(true, msg);
return null; return null;
@ -336,7 +336,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }

View file

@ -84,7 +84,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex)); Error?.Invoke(this, new ErrorEventArgs(ex));
if (ex.InnerException != null) if (ex.InnerException != null)
@ -111,7 +111,7 @@ namespace v2rayN.Handler
} }
else else
{ {
Utils.SaveLog("StatusCode error: " + url); Logging.SaveLog("StatusCode error: " + url);
return null; return null;
} }
} }
@ -128,7 +128,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex)); Error?.Invoke(this, new ErrorEventArgs(ex));
if (ex.InnerException != null) if (ex.InnerException != null)
{ {
@ -146,7 +146,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex)); Error?.Invoke(this, new ErrorEventArgs(ex));
if (ex.InnerException != null) if (ex.InnerException != null)
{ {
@ -166,7 +166,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex)); Error?.Invoke(this, new ErrorEventArgs(ex));
if (ex.InnerException != null) if (ex.InnerException != null)
{ {
@ -212,7 +212,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex)); Error?.Invoke(this, new ErrorEventArgs(ex));
if (ex.InnerException != null) if (ex.InnerException != null)
{ {
@ -243,7 +243,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex)); Error?.Invoke(this, new ErrorEventArgs(ex));
if (ex.InnerException != null) if (ex.InnerException != null)
{ {
@ -270,13 +270,13 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return -1; return -1;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return -1; return -1;
} }
} }

View file

@ -42,7 +42,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return Properties.Resources.NotifyIcon1; return Properties.Resources.NotifyIcon1;
} }
} }
@ -112,7 +112,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return null; return null;
} }
} }
@ -163,7 +163,7 @@ namespace v2rayN.Handler
private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> update) private async Task UpdateTaskRunSubscription(Config config, Action<bool, string> update)
{ {
await Task.Delay(60000); await Task.Delay(60000);
Utils.SaveLog("UpdateTaskRunSubscription"); Logging.SaveLog("UpdateTaskRunSubscription");
var updateHandle = new UpdateHandle(); var updateHandle = new UpdateHandle();
while (true) while (true)
@ -180,7 +180,7 @@ namespace v2rayN.Handler
{ {
update(success, msg); update(success, msg);
if (success) if (success)
Utils.SaveLog("subscription" + msg); Logging.SaveLog("subscription" + msg);
}); });
item.updateTime = updateTime; item.updateTime = updateTime;
ConfigHandler.AddSubItem(config, item); ConfigHandler.AddSubItem(config, item);
@ -196,7 +196,7 @@ namespace v2rayN.Handler
var autoUpdateGeoTime = DateTime.Now; var autoUpdateGeoTime = DateTime.Now;
await Task.Delay(1000 * 120); await Task.Delay(1000 * 120);
Utils.SaveLog("UpdateTaskRunGeo"); Logging.SaveLog("UpdateTaskRunGeo");
var updateHandle = new UpdateHandle(); var updateHandle = new UpdateHandle();
while (true) while (true)

View file

@ -82,7 +82,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }

View file

@ -38,7 +38,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return ""; return "";
} }
} }
@ -66,7 +66,7 @@ namespace v2rayN.Handler
fp = item.fingerprint fp = item.fingerprint
}; };
url = Utils.ToJson(vmessQRCode); url = JsonUtils.ToJson(vmessQRCode);
url = Utils.Base64Encode(url); url = Utils.Base64Encode(url);
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}"; url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
@ -431,7 +431,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
msg = ResUI.Incorrectconfiguration; msg = ResUI.Incorrectconfiguration;
return null; return null;
} }
@ -451,7 +451,7 @@ namespace v2rayN.Handler
result = Utils.Base64Decode(result); result = Utils.Base64Decode(result);
//转成Json //转成Json
VmessQRCode? vmessQRCode = Utils.FromJson<VmessQRCode>(result); VmessQRCode? vmessQRCode = JsonUtils.FromJson<VmessQRCode>(result);
if (vmessQRCode == null) if (vmessQRCode == null)
{ {
msg = ResUI.FailedConversionConfiguration; msg = ResUI.FailedConversionConfiguration;

View file

@ -107,7 +107,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -115,7 +115,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -184,7 +184,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
})); }));
} }
@ -192,7 +192,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
finally finally
{ {
@ -371,7 +371,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return responseTime; return responseTime;
} }
@ -407,7 +407,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return -1; return -1;
} }
return roundtripTime; return roundtripTime;

View file

@ -44,7 +44,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -63,7 +63,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }

View file

@ -51,7 +51,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -113,7 +113,7 @@ namespace v2rayN.Handler
up = 0; down = 0; up = 0; down = 0;
try try
{ {
var trafficItem = Utils.FromJson<TrafficItem>(source); var trafficItem = JsonUtils.FromJson<TrafficItem>(source);
if (trafficItem != null) if (trafficItem != null)
{ {
up = trafficItem.up; up = trafficItem.up;

View file

@ -35,7 +35,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
} }

View file

@ -87,7 +87,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return true; return true;
} }

View file

@ -274,8 +274,8 @@ namespace v2rayN.Handler
int ret = ConfigHandler.AddBatchServers(config, result, id, true); int ret = ConfigHandler.AddBatchServers(config, result, id, true);
if (ret <= 0) if (ret <= 0)
{ {
Utils.SaveLog("FailedImportSubscription"); Logging.SaveLog("FailedImportSubscription");
Utils.SaveLog(result); Logging.SaveLog(result);
} }
_updateFunc(false, _updateFunc(false,
ret > 0 ret > 0
@ -327,13 +327,13 @@ namespace v2rayN.Handler
} }
else else
{ {
Utils.SaveLog("StatusCode error: " + url); Logging.SaveLog("StatusCode error: " + url);
return; return;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
_updateFunc(false, ex.Message); _updateFunc(false, ex.Message);
} }
} }
@ -350,7 +350,7 @@ namespace v2rayN.Handler
foreach (string name in coreInfo.coreExes) foreach (string name in coreInfo.coreExes)
{ {
string vName = $"{name}.exe"; string vName = $"{name}.exe";
vName = Utils.GetBinPath(vName, coreInfo.coreType); vName = Utils.GetBinPath(vName, coreInfo.coreType.ToString());
if (File.Exists(vName)) if (File.Exists(vName))
{ {
filePath = vName; filePath = vName;
@ -399,7 +399,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
_updateFunc(false, ex.Message); _updateFunc(false, ex.Message);
return new SemanticVersion(""); return new SemanticVersion("");
} }
@ -409,7 +409,7 @@ namespace v2rayN.Handler
{ {
try try
{ {
var gitHubReleases = Utils.FromJson<List<GitHubRelease>>(gitHubReleaseApi); var gitHubReleases = JsonUtils.FromJson<List<GitHubRelease>>(gitHubReleaseApi);
var gitHubRelease = preRelease ? gitHubReleases!.First() : gitHubReleases!.First(r => r.Prerelease == false); var gitHubRelease = preRelease ? gitHubReleases!.First() : gitHubReleases!.First(r => r.Prerelease == false);
var version = new SemanticVersion(gitHubRelease!.TagName); var version = new SemanticVersion(gitHubRelease!.TagName);
var body = gitHubRelease!.Body; var body = gitHubRelease!.Body;
@ -524,7 +524,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
_updateFunc(false, ex.Message); _updateFunc(false, ex.Message);
} }
} }

View file

@ -15,7 +15,7 @@ namespace v2rayN.Tool
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return false; return false;
} }
@ -30,7 +30,7 @@ namespace v2rayN.Tool
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -49,7 +49,7 @@ namespace v2rayN.Tool
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
throw; throw;
} }
} }
@ -75,13 +75,13 @@ namespace v2rayN.Tool
} }
catch (IOException ex) catch (IOException ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return false; return false;
} }
return true; return true;

View file

@ -52,7 +52,7 @@ namespace v2rayN
if (!succ) if (!succ)
{ {
Utils.SaveLog("Failed to call AssignProcessToJobObject! GetLastError=" + Marshal.GetLastWin32Error()); Logging.SaveLog("Failed to call AssignProcessToJobObject! GetLastError=" + Marshal.GetLastWin32Error());
} }
return succ; return succ;

View file

@ -0,0 +1,120 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.IO;
namespace v2rayN
{
internal class JsonUtils
{
/// <summary>
/// DeepCopy
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static T DeepCopy<T>(T obj)
{
return FromJson<T>(ToJson(obj, false))!;
}
/// <summary>
/// Deserialize to object
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="strJson"></param>
/// <returns></returns>
public static T? FromJson<T>(string? strJson)
{
try
{
if (string.IsNullOrEmpty(strJson))
{
return default;
}
return JsonConvert.DeserializeObject<T>(strJson);
}
catch
{
return default;
}
}
/// <summary>
/// parse
/// </summary>
/// <param name="strJson"></param>
/// <returns></returns>
public static JObject? ParseJson(string strJson)
{
try
{
if (string.IsNullOrEmpty(strJson))
{
return null;
}
return JObject.Parse(strJson);
}
catch
{
//SaveLog(ex.Message, ex);
return null;
}
}
/// <summary>
/// Serialize Object to Json string
/// </summary>
/// <param name="obj"></param>
/// <param name="indented"></param>
/// <returns></returns>
public static string ToJson(object? obj, bool indented = true)
{
string result = string.Empty;
try
{
if (obj == null)
{
return result;
}
result = JsonConvert.SerializeObject(obj,
indented ? Formatting.Indented : Formatting.None,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
}
return result;
}
/// <summary>
/// Save as json file
/// </summary>
/// <param name="obj"></param>
/// <param name="filePath"></param>
/// <param name="nullValue"></param>
/// <returns></returns>
public static int ToJsonFile(object? obj, string filePath, bool nullValue = true)
{
int result;
try
{
using StreamWriter file = File.CreateText(filePath);
var serializer = new JsonSerializer()
{
Formatting = Formatting.Indented,
NullValueHandling = nullValue ? NullValueHandling.Include : NullValueHandling.Ignore
};
serializer.Serialize(file, obj);
result = 0;
}
catch (Exception ex)
{
Logging.SaveLog(ex.Message, ex);
result = -1;
}
return result;
}
}
}

View file

@ -3,7 +3,7 @@ using NLog.Config;
using NLog.Targets; using NLog.Targets;
using System.IO; using System.IO;
namespace v2rayN.Tool namespace v2rayN
{ {
public class Logging public class Logging
{ {
@ -51,5 +51,28 @@ namespace v2rayN.Tool
catch { } catch { }
}); });
} }
public static void SaveLog(string strContent)
{
if (LogManager.IsLoggingEnabled())
{
var logger = LogManager.GetLogger("Log1");
logger.Info(strContent);
}
}
public static void SaveLog(string strTitle, Exception ex)
{
if (LogManager.IsLoggingEnabled())
{
var logger = LogManager.GetLogger("Log2");
logger.Debug($"{strTitle},{ex.Message}");
logger.Debug(ex.StackTrace);
if (ex?.InnerException != null)
{
logger.Error(ex.InnerException);
}
}
}
} }
} }

View file

@ -1,8 +1,5 @@
using Microsoft.Win32; using Microsoft.Win32;
using Microsoft.Win32.TaskScheduler; using Microsoft.Win32.TaskScheduler;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
@ -21,8 +18,6 @@ using System.Windows;
using System.Windows.Interop; using System.Windows.Interop;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using v2rayN.Base;
using v2rayN.Mode;
using ZXing; using ZXing;
using ZXing.Common; using ZXing.Common;
using ZXing.QrCode; using ZXing.QrCode;
@ -53,7 +48,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return result; return result;
} }
@ -71,111 +66,11 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return null; return null;
} }
/// <summary>
/// 反序列化成对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="strJson"></param>
/// <returns></returns>
public static T? FromJson<T>(string? strJson)
{
try
{
if (string.IsNullOrEmpty(strJson))
{
return default;
}
return JsonConvert.DeserializeObject<T>(strJson);
}
catch
{
return default;
}
}
/// <summary>
/// 序列化成Json
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
public static string ToJson(object? obj, bool indented = true)
{
string result = string.Empty;
try
{
if (obj == null)
{
return result;
}
if (indented)
{
result = JsonConvert.SerializeObject(obj,
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
else
{
result = JsonConvert.SerializeObject(obj, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
}
}
catch (Exception ex)
{
SaveLog(ex.Message, ex);
}
return result;
}
/// <summary>
/// 保存成json文件
/// </summary>
/// <param name="obj"></param>
/// <param name="filePath"></param>
/// <returns></returns>
public static int ToJsonFile(object? obj, string filePath, bool nullValue = true)
{
int result;
try
{
using StreamWriter file = File.CreateText(filePath);
JsonSerializer serializer;
if (nullValue)
{
serializer = new JsonSerializer() { Formatting = Formatting.Indented };
}
else
{
serializer = new JsonSerializer() { Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore };
}
serializer.Serialize(file, obj);
result = 0;
}
catch (Exception ex)
{
SaveLog(ex.Message, ex);
result = -1;
}
return result;
}
public static JObject? ParseJson(string strJson)
{
try
{
return JObject.Parse(strJson);
}
catch (Exception ex)
{
//SaveLog(ex.Message, ex);
return null;
}
}
#endregion Json操作 #endregion Json操作
#region #region
@ -204,7 +99,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return string.Empty; return string.Empty;
} }
} }
@ -223,7 +118,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return new List<string>(); return new List<string>();
} }
} }
@ -244,7 +139,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return new List<string>(); return new List<string>();
} }
} }
@ -263,7 +158,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog("Base64Encode", ex); Logging.SaveLog("Base64Encode", ex);
return string.Empty; return string.Empty;
} }
} }
@ -277,7 +172,7 @@ namespace v2rayN
{ {
try try
{ {
plainText = plainText.TrimEx() plainText = plainText.Trim()
.Replace(Environment.NewLine, "") .Replace(Environment.NewLine, "")
.Replace("\n", "") .Replace("\n", "")
.Replace("\r", "") .Replace("\r", "")
@ -295,7 +190,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog("Base64Decode", ex); Logging.SaveLog("Base64Decode", ex);
return string.Empty; return string.Empty;
} }
} }
@ -492,7 +387,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return false; return false;
} }
} }
@ -598,14 +493,14 @@ namespace v2rayN
/// </summary> /// </summary>
/// <param name="run"></param> /// <param name="run"></param>
/// <returns></returns> /// <returns></returns>
public static void SetAutoRun(bool run) public static void SetAutoRun(string AutoRunRegPath, string AutoRunName, bool run)
{ {
try try
{ {
var autoRunName = $"{Global.AutoRunName}_{GetMD5(StartupPath())}"; var autoRunName = $"{AutoRunName}_{GetMD5(StartupPath())}";
//delete first //delete first
RegWriteValue(Global.AutoRunRegPath, autoRunName, ""); RegWriteValue(AutoRunRegPath, autoRunName, "");
if (IsAdministrator()) if (IsAdministrator())
{ {
AutoStart(autoRunName, "", ""); AutoStart(autoRunName, "", "");
@ -620,43 +515,16 @@ namespace v2rayN
} }
else else
{ {
RegWriteValue(Global.AutoRunRegPath, autoRunName, exePath); RegWriteValue(AutoRunRegPath, autoRunName, exePath);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
/// <summary>
/// 是否已经设置开机自动启动
/// </summary>
/// <returns></returns>
public static bool IsAutoRun()
{
try
{
//clear
if (!RegReadValue(Global.AutoRunRegPath, Global.AutoRunName, "").IsNullOrEmpty())
{
RegWriteValue(Global.AutoRunRegPath, Global.AutoRunName, "");
}
string value = RegReadValue(Global.AutoRunRegPath, Global.AutoRunName, "");
string exePath = GetExePath();
if (value == exePath || value == $"\"{exePath}\"")
{
return true;
}
}
catch (Exception ex)
{
SaveLog(ex.Message, ex);
}
return false;
}
/// <summary> /// <summary>
/// 获取启动了应用程序的可执行文件的路径 /// 获取启动了应用程序的可执行文件的路径
@ -704,7 +572,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
finally finally
{ {
@ -730,7 +598,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
finally finally
{ {
@ -859,7 +727,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return inUse; return inUse;
} }
@ -891,34 +759,11 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return string.Empty; return string.Empty;
} }
} }
/// <summary>
/// DeepCopy
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="obj"></param>
/// <returns></returns>
public static T DeepCopy<T>(T obj)
{
return FromJson<T>(ToJson(obj, false))!;
// object retval;
// MemoryStream ms = new();
//#pragma warning disable SYSLIB0011 // 类型或成员已过时
// BinaryFormatter bf = new();
//#pragma warning restore SYSLIB0011 // 类型或成员已过时
// //序列化成流
// bf.Serialize(ms, obj);
// ms.Seek(0, SeekOrigin.Begin);
// //反序列化成对象
// retval = bf.Deserialize(ms);
// return (T)retval;
}
/// <summary> /// <summary>
/// 获取剪贴板数 /// 获取剪贴板数
/// </summary> /// </summary>
@ -937,7 +782,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return strData; return strData;
} }
@ -976,7 +821,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return string.Empty; return string.Empty;
} }
@ -996,7 +841,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return false; return false;
} }
} }
@ -1036,7 +881,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -1115,7 +960,7 @@ namespace v2rayN
} }
} }
public static string GetBinPath(string filename, ECoreType? coreType = null) public static string GetBinPath(string filename, string? coreType = null)
{ {
string _tempPath = Path.Combine(StartupPath(), "bin"); string _tempPath = Path.Combine(StartupPath(), "bin");
if (!Directory.Exists(_tempPath)) if (!Directory.Exists(_tempPath))
@ -1176,33 +1021,6 @@ namespace v2rayN
#endregion TempPath #endregion TempPath
#region Log
public static void SaveLog(string strContent)
{
if (LogManager.IsLoggingEnabled())
{
var logger = LogManager.GetLogger("Log1");
logger.Info(strContent);
}
}
public static void SaveLog(string strTitle, Exception ex)
{
if (LogManager.IsLoggingEnabled())
{
var logger = LogManager.GetLogger("Log2");
logger.Debug($"{strTitle},{ex.Message}");
logger.Debug(ex.StackTrace);
if (ex?.InnerException != null)
{
logger.Error(ex.InnerException);
}
}
}
#endregion Log
#region scan screen #region scan screen
public static string ScanScreen(float dpiX, float dpiY) public static string ScanScreen(float dpiX, float dpiY)
@ -1248,7 +1066,7 @@ namespace v2rayN
} }
catch (Exception ex) catch (Exception ex)
{ {
SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
return string.Empty; return string.Empty;
} }

View file

@ -38,7 +38,7 @@ namespace v2rayN.ViewModels
} }
else else
{ {
SelectedSource = Utils.DeepCopy(profileItem); SelectedSource = JsonUtils.DeepCopy(profileItem);
} }
_view = view; _view = view;
@ -127,7 +127,7 @@ namespace v2rayN.ViewModels
_noticeHandler?.Enqueue(ResUI.SuccessfullyImportedCustomServer); _noticeHandler?.Enqueue(ResUI.SuccessfullyImportedCustomServer);
if (!Utils.IsNullOrEmpty(item.indexId)) if (!Utils.IsNullOrEmpty(item.indexId))
{ {
SelectedSource = Utils.DeepCopy(item); SelectedSource = JsonUtils.DeepCopy(item);
} }
IsModified = true; IsModified = true;
} }

View file

@ -37,7 +37,7 @@ namespace v2rayN.ViewModels
} }
else else
{ {
SelectedSource = Utils.DeepCopy(profileItem); SelectedSource = JsonUtils.DeepCopy(profileItem);
} }
SaveCmd = ReactiveCommand.Create(() => SaveCmd = ReactiveCommand.Create(() =>

View file

@ -63,7 +63,7 @@ namespace v2rayN.ViewModels
{ {
if (!Utils.IsNullOrEmpty(normalDNS)) if (!Utils.IsNullOrEmpty(normalDNS))
{ {
var obj = Utils.ParseJson(normalDNS); var obj = JsonUtils.ParseJson(normalDNS);
if (obj != null && obj.ContainsKey("servers") == true) if (obj != null && obj.ContainsKey("servers") == true)
{ {
} }
@ -78,7 +78,7 @@ namespace v2rayN.ViewModels
} }
if (!Utils.IsNullOrEmpty(normalDNS2)) if (!Utils.IsNullOrEmpty(normalDNS2))
{ {
var obj2 = Utils.FromJson<Dns4Sbox>(normalDNS2); var obj2 = JsonUtils.FromJson<Dns4Sbox>(normalDNS2);
if (obj2 == null) if (obj2 == null)
{ {
UI.Show(ResUI.FillCorrectDNSText); UI.Show(ResUI.FillCorrectDNSText);
@ -87,7 +87,7 @@ namespace v2rayN.ViewModels
} }
if (!Utils.IsNullOrEmpty(tunDNS2)) if (!Utils.IsNullOrEmpty(tunDNS2))
{ {
var obj2 = Utils.FromJson<Dns4Sbox>(tunDNS2); var obj2 = JsonUtils.FromJson<Dns4Sbox>(tunDNS2);
if (obj2 == null) if (obj2 == null)
{ {
UI.Show(ResUI.FillCorrectDNSText); UI.Show(ResUI.FillCorrectDNSText);
@ -102,8 +102,8 @@ namespace v2rayN.ViewModels
ConfigHandler.SaveDNSItems(_config, item); ConfigHandler.SaveDNSItems(_config, item);
var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
item2.normalDNS = Utils.ToJson(Utils.ParseJson(normalDNS2)); item2.normalDNS = JsonUtils.ToJson(JsonUtils.ParseJson(normalDNS2));
item2.tunDNS = Utils.ToJson(Utils.ParseJson(tunDNS2)); item2.tunDNS = JsonUtils.ToJson(JsonUtils.ParseJson(tunDNS2));
ConfigHandler.SaveDNSItems(_config, item2); ConfigHandler.SaveDNSItems(_config, item2);
_noticeHandler?.Enqueue(ResUI.OperationSuccess); _noticeHandler?.Enqueue(ResUI.OperationSuccess);

View file

@ -652,13 +652,13 @@ namespace v2rayN.ViewModels
if (SelectedProfile?.indexId == item.indexId) if (SelectedProfile?.indexId == item.indexId)
{ {
var temp = Utils.DeepCopy(item); var temp = JsonUtils.DeepCopy(item);
_profileItems.Replace(item, temp); _profileItems.Replace(item, temp);
SelectedProfile = temp; SelectedProfile = temp;
} }
else else
{ {
_profileItems.Replace(item, Utils.DeepCopy(item)); _profileItems.Replace(item, JsonUtils.DeepCopy(item));
} }
} }
} }
@ -667,7 +667,7 @@ namespace v2rayN.ViewModels
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
} }
} }
@ -700,7 +700,7 @@ namespace v2rayN.ViewModels
{ {
item.speedVal = $"{speed} {Global.SpeedUnit}"; item.speedVal = $"{speed} {Global.SpeedUnit}";
} }
_profileItems.Replace(item, Utils.DeepCopy(item)); _profileItems.Replace(item, JsonUtils.DeepCopy(item));
} }
} }
@ -734,7 +734,7 @@ namespace v2rayN.ViewModels
{ {
try try
{ {
Utils.SaveLog("MyAppExit Begin"); Logging.SaveLog("MyAppExit Begin");
StorageUI(); StorageUI();
ConfigHandler.SaveConfig(_config); ConfigHandler.SaveConfig(_config);
@ -755,7 +755,7 @@ namespace v2rayN.ViewModels
_statistics?.Close(); _statistics?.Close();
_coreHandler.CoreStop(); _coreHandler.CoreStop();
Utils.SaveLog("MyAppExit End"); Logging.SaveLog("MyAppExit End");
} }
catch { } catch { }
finally finally
@ -835,7 +835,7 @@ namespace v2rayN.ViewModels
totalDown = t22 == null ? "" : Utils.HumanFy(t22.totalDown), totalDown = t22 == null ? "" : Utils.HumanFy(t22.totalDown),
totalUp = t22 == null ? "" : Utils.HumanFy(t22.totalUp) totalUp = t22 == null ? "" : Utils.HumanFy(t22.totalUp)
}).OrderBy(t => t.sort).ToList(); }).OrderBy(t => t.sort).ToList();
_lstProfile = Utils.FromJson<List<ProfileItem>>(Utils.ToJson(lstModel)); _lstProfile = JsonUtils.FromJson<List<ProfileItem>>(JsonUtils.ToJson(lstModel));
Application.Current.Dispatcher.Invoke((Action)(() => Application.Current.Dispatcher.Invoke((Action)(() =>
{ {
@ -941,7 +941,7 @@ namespace v2rayN.ViewModels
} }
else else
{ {
lstSelecteds = Utils.FromJson<List<ProfileItem>>(Utils.ToJson(orderProfiles)); lstSelecteds = JsonUtils.FromJson<List<ProfileItem>>(JsonUtils.ToJson(orderProfiles));
} }
return 0; return 0;
@ -1456,7 +1456,7 @@ namespace v2rayN.ViewModels
CloseV2ray(); CloseV2ray();
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg)); string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(msg));
string toPath = Utils.GetBinPath("", type); string toPath = Utils.GetBinPath("", type.ToString());
FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : ""); FileManager.ZipExtractToFile(fileName, toPath, _config.guiItem.ignoreGeoUpdateCore ? "geo" : "");

View file

@ -296,7 +296,7 @@ namespace v2rayN.ViewModels
//_config.kcpItem.congestion = Kcpcongestion; //_config.kcpItem.congestion = Kcpcongestion;
//UI //UI
Utils.SetAutoRun(AutoRun); Utils.SetAutoRun(Global.AutoRunRegPath, Global.AutoRunName, AutoRun);
_config.guiItem.autoRun = AutoRun; _config.guiItem.autoRun = AutoRun;
_config.guiItem.enableStatistics = EnableStatistics; _config.guiItem.enableStatistics = EnableStatistics;
_config.guiItem.keepOlderDedupl = KeepOlderDedupl; _config.guiItem.keepOlderDedupl = KeepOlderDedupl;

View file

@ -60,7 +60,7 @@ namespace v2rayN.ViewModels
else else
{ {
SelectedRouting = routingItem; SelectedRouting = routingItem;
_rules = Utils.FromJson<List<RulesItem>>(SelectedRouting.ruleSet); _rules = JsonUtils.FromJson<List<RulesItem>>(SelectedRouting.ruleSet);
} }
RefreshRulesItems(); RefreshRulesItems();
@ -209,7 +209,7 @@ namespace v2rayN.ViewModels
} }
if (lst.Count > 0) if (lst.Count > 0)
{ {
Utils.SetClipboardData(Utils.ToJson(lst)); Utils.SetClipboardData(JsonUtils.ToJson(lst));
//UI.Show(ResUI.OperationSuccess")); //UI.Show(ResUI.OperationSuccess"));
} }
} }
@ -248,7 +248,7 @@ namespace v2rayN.ViewModels
it.id = Utils.GetGUID(false); it.id = Utils.GetGUID(false);
} }
item.ruleNum = _rules.Count; item.ruleNum = _rules.Count;
item.ruleSet = Utils.ToJson(_rules, false); item.ruleSet = JsonUtils.ToJson(_rules, false);
if (ConfigHandler.SaveRoutingItem(_config, item) == 0) if (ConfigHandler.SaveRoutingItem(_config, item) == 0)
{ {
@ -334,7 +334,7 @@ namespace v2rayN.ViewModels
{ {
return -1; return -1;
} }
var lstRules = Utils.FromJson<List<RulesItem>>(clipboardData); var lstRules = JsonUtils.FromJson<List<RulesItem>>(clipboardData);
if (lstRules == null) if (lstRules == null)
{ {
return -1; return -1;

View file

@ -137,7 +137,7 @@ namespace v2rayN.ViewModels
_lockedItem = ConfigHandler.GetLockedRoutingItem(_config); _lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
if (_lockedItem != null) if (_lockedItem != null)
{ {
_lockedRules = Utils.FromJson<List<RulesItem>>(_lockedItem.ruleSet); _lockedRules = JsonUtils.FromJson<List<RulesItem>>(_lockedItem.ruleSet);
ProxyDomain = Utils.List2String(_lockedRules[0].domain, true); ProxyDomain = Utils.List2String(_lockedRules[0].domain, true);
ProxyIP = Utils.List2String(_lockedRules[0].ip, true); ProxyIP = Utils.List2String(_lockedRules[0].ip, true);
@ -162,7 +162,7 @@ namespace v2rayN.ViewModels
_lockedRules[2].domain = Utils.String2List(Utils.Convert2Comma(BlockDomain.TrimEx())); _lockedRules[2].domain = Utils.String2List(Utils.Convert2Comma(BlockDomain.TrimEx()));
_lockedRules[2].ip = Utils.String2List(Utils.Convert2Comma(BlockIP.TrimEx())); _lockedRules[2].ip = Utils.String2List(Utils.Convert2Comma(BlockIP.TrimEx()));
_lockedItem.ruleSet = Utils.ToJson(_lockedRules, false); _lockedItem.ruleSet = JsonUtils.ToJson(_lockedRules, false);
ConfigHandler.SaveRoutingItem(_config, _lockedItem); ConfigHandler.SaveRoutingItem(_config, _lockedItem);
} }

View file

@ -33,7 +33,7 @@ namespace v2rayN.ViewModels
} }
else else
{ {
SelectedSource = Utils.DeepCopy(subItem); SelectedSource = JsonUtils.DeepCopy(subItem);
} }
SaveCmd = ReactiveCommand.Create(() => SaveCmd = ReactiveCommand.Create(() =>

View file

@ -70,7 +70,7 @@ namespace v2rayN.Views
private KeyEventItem GetKeyEventItemByEGlobalHotkey(List<KeyEventItem> KELsit, EGlobalHotkey eg) private KeyEventItem GetKeyEventItemByEGlobalHotkey(List<KeyEventItem> KELsit, EGlobalHotkey eg)
{ {
return Utils.DeepCopy(KELsit.Find((it) => it.eGlobalHotkey == eg) ?? new() return JsonUtils.DeepCopy(KELsit.Find((it) => it.eGlobalHotkey == eg) ?? new()
{ {
eGlobalHotkey = eg, eGlobalHotkey = eg,
Control = false, Control = false,

View file

@ -276,7 +276,7 @@ namespace v2rayN.Views
private void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e) private void Current_SessionEnding(object sender, SessionEndingCancelEventArgs e)
{ {
Utils.SaveLog("Current_SessionEnding"); Logging.SaveLog("Current_SessionEnding");
StorageUI(); StorageUI();
ViewModel?.MyAppExit(true); ViewModel?.MyAppExit(true);
} }

View file

@ -128,7 +128,7 @@ namespace v2rayN.Views
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog("fill fonts error", ex); Logging.SaveLog("fill fonts error", ex);
} }
cmbcurrentFontFamily.Items.Add(string.Empty); cmbcurrentFontFamily.Items.Add(string.Empty);

View file

@ -20,7 +20,6 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="QRCoder.Xaml" Version="1.4.3" /> <PackageReference Include="QRCoder.Xaml" Version="1.4.3" />
<PackageReference Include="sqlite-net-pcl" Version="1.8.116" /> <PackageReference Include="sqlite-net-pcl" Version="1.8.116" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="TaskScheduler" Version="2.10.1" /> <PackageReference Include="TaskScheduler" Version="2.10.1" />
<PackageReference Include="ZXing.Net.Bindings.Windows.Compatibility" Version="0.16.12" /> <PackageReference Include="ZXing.Net.Bindings.Windows.Compatibility" Version="0.16.12" />
<PackageReference Include="ReactiveUI.Fody" Version="19.5.39" /> <PackageReference Include="ReactiveUI.Fody" Version="19.5.39" />