mirror of https://github.com/2dust/v2rayN
Refactor
parent
3c4703ad85
commit
02225ad0b8
|
@ -35,7 +35,7 @@ namespace v2rayN
|
||||||
|
|
||||||
public async Task PutAsync(string url, Dictionary<string, string> headers)
|
public async Task PutAsync(string url, Dictionary<string, string> headers)
|
||||||
{
|
{
|
||||||
var jsonContent = JsonUtils.ToJson(headers);
|
var jsonContent = JsonUtils.Serialize(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);
|
||||||
|
|
|
@ -14,7 +14,7 @@ namespace v2rayN
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T DeepCopy<T>(T obj)
|
public static T DeepCopy<T>(T obj)
|
||||||
{
|
{
|
||||||
return FromJson<T>(ToJson(obj, false))!;
|
return Deserialize<T>(Serialize(obj, false))!;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -23,7 +23,7 @@ namespace v2rayN
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
/// <param name="strJson"></param>
|
/// <param name="strJson"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static T? FromJson<T>(string? strJson)
|
public static T? Deserialize<T>(string? strJson)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -68,7 +68,7 @@ namespace v2rayN
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <param name="indented"></param>
|
/// <param name="indented"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ToJson(object? obj, bool indented = true)
|
public static string Serialize(object? obj, bool indented = true)
|
||||||
{
|
{
|
||||||
string result = string.Empty;
|
string result = string.Empty;
|
||||||
try
|
try
|
||||||
|
@ -95,7 +95,7 @@ namespace v2rayN
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <param name="nullValue"></param>
|
/// <param name="nullValue"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int ToJsonFile(object? obj, string filePath, bool nullValue = true)
|
public static int ToFile(object? obj, string filePath, bool nullValue = true)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
try
|
try
|
||||||
|
|
|
@ -27,7 +27,7 @@ namespace v2rayN.Handler
|
||||||
if (!Utils.IsNullOrEmpty(result))
|
if (!Utils.IsNullOrEmpty(result))
|
||||||
{
|
{
|
||||||
//转成Json
|
//转成Json
|
||||||
config = JsonUtils.FromJson<Config>(result);
|
config = JsonUtils.Deserialize<Config>(result);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -232,7 +232,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 (JsonUtils.ToJsonFile(config, tempPath) != 0)
|
if (JsonUtils.ToFile(config, tempPath) != 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -259,13 +259,13 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var configOld = JsonUtils.FromJson<ConfigOld>(result);
|
var configOld = JsonUtils.Deserialize<ConfigOld>(result);
|
||||||
if (configOld == null)
|
if (configOld == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var subItem = JsonUtils.FromJson<List<SubItem>>(JsonUtils.ToJson(configOld.subItem));
|
var subItem = JsonUtils.Deserialize<List<SubItem>>(JsonUtils.Serialize(configOld.subItem));
|
||||||
foreach (var it in subItem)
|
foreach (var it in subItem)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(it.id))
|
if (Utils.IsNullOrEmpty(it.id))
|
||||||
|
@ -275,7 +275,7 @@ namespace v2rayN.Handler
|
||||||
SqliteHelper.Instance.Replace(it);
|
SqliteHelper.Instance.Replace(it);
|
||||||
}
|
}
|
||||||
|
|
||||||
var profileItems = JsonUtils.FromJson<List<ProfileItem>>(JsonUtils.ToJson(configOld.vmess));
|
var profileItems = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(configOld.vmess));
|
||||||
foreach (var it in profileItems)
|
foreach (var it in profileItems)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(it.indexId))
|
if (Utils.IsNullOrEmpty(it.indexId))
|
||||||
|
@ -291,13 +291,13 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
var routing = JsonUtils.FromJson<RoutingItem>(JsonUtils.ToJson(it));
|
var routing = JsonUtils.Deserialize<RoutingItem>(JsonUtils.Serialize(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 = JsonUtils.ToJson(it.rules, false);
|
routing.ruleSet = JsonUtils.Serialize(it.rules, false);
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(routing.id))
|
if (Utils.IsNullOrEmpty(routing.id))
|
||||||
{
|
{
|
||||||
|
@ -306,7 +306,7 @@ namespace v2rayN.Handler
|
||||||
SqliteHelper.Instance.Replace(routing);
|
SqliteHelper.Instance.Replace(routing);
|
||||||
}
|
}
|
||||||
|
|
||||||
config = JsonUtils.FromJson<Config>(JsonUtils.ToJson(configOld));
|
config = JsonUtils.Deserialize<Config>(JsonUtils.Serialize(configOld));
|
||||||
|
|
||||||
if (config.coreBasicItem == null)
|
if (config.coreBasicItem == null)
|
||||||
{
|
{
|
||||||
|
@ -1161,7 +1161,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
ProfileItem profileItem = new();
|
ProfileItem profileItem = new();
|
||||||
//Is v2ray configuration
|
//Is v2ray configuration
|
||||||
V2rayConfig? v2rayConfig = JsonUtils.FromJson<V2rayConfig>(clipboardData);
|
V2rayConfig? v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(clipboardData);
|
||||||
if (v2rayConfig?.inbounds?.Count > 0
|
if (v2rayConfig?.inbounds?.Count > 0
|
||||||
&& v2rayConfig.outbounds?.Count > 0)
|
&& v2rayConfig.outbounds?.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -1252,10 +1252,10 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
//SsSIP008
|
//SsSIP008
|
||||||
var lstSsServer = JsonUtils.FromJson<List<SsServer>>(clipboardData);
|
var lstSsServer = JsonUtils.Deserialize<List<SsServer>>(clipboardData);
|
||||||
if (lstSsServer?.Count <= 0)
|
if (lstSsServer?.Count <= 0)
|
||||||
{
|
{
|
||||||
var ssSIP008 = JsonUtils.FromJson<SsSIP008>(clipboardData);
|
var ssSIP008 = JsonUtils.Deserialize<SsSIP008>(clipboardData);
|
||||||
if (ssSIP008?.servers?.Count > 0)
|
if (ssSIP008?.servers?.Count > 0)
|
||||||
{
|
{
|
||||||
lstSsServer = ssSIP008.servers;
|
lstSsServer = ssSIP008.servers;
|
||||||
|
@ -1467,7 +1467,7 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
var lstRules = JsonUtils.FromJson<List<RulesItem>>(clipboardData);
|
var lstRules = JsonUtils.Deserialize<List<RulesItem>>(clipboardData);
|
||||||
if (lstRules == null)
|
if (lstRules == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1478,7 +1478,7 @@ namespace v2rayN.Handler
|
||||||
item.id = Utils.GetGUID(false);
|
item.id = Utils.GetGUID(false);
|
||||||
}
|
}
|
||||||
routingItem.ruleNum = lstRules.Count;
|
routingItem.ruleNum = lstRules.Count;
|
||||||
routingItem.ruleSet = JsonUtils.ToJson(lstRules, false);
|
routingItem.ruleSet = JsonUtils.Serialize(lstRules, false);
|
||||||
|
|
||||||
if (Utils.IsNullOrEmpty(routingItem.id))
|
if (Utils.IsNullOrEmpty(routingItem.id))
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,11 +35,11 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (Utils.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
content = JsonUtils.ToJson(singboxConfig);
|
content = JsonUtils.Serialize(singboxConfig);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JsonUtils.ToJsonFile(singboxConfig, fileName, false);
|
JsonUtils.ToFile(singboxConfig, fileName, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -51,11 +51,11 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
if (Utils.IsNullOrEmpty(fileName))
|
if (Utils.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
content = JsonUtils.ToJson(v2rayConfig);
|
content = JsonUtils.Serialize(v2rayConfig);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
JsonUtils.ToJsonFile(v2rayConfig, fileName, false);
|
JsonUtils.ToFile(v2rayConfig, fileName, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
JsonUtils.ToJsonFile(singboxConfig, fileName, false);
|
JsonUtils.ToFile(singboxConfig, fileName, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -166,7 +166,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
JsonUtils.ToJsonFile(v2rayConfig, fileName, false);
|
JsonUtils.ToFile(v2rayConfig, fileName, false);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
singboxConfig = JsonUtils.FromJson<SingboxConfig>(result);
|
singboxConfig = JsonUtils.Deserialize<SingboxConfig>(result);
|
||||||
if (singboxConfig == null)
|
if (singboxConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
@ -177,7 +177,7 @@ namespace v2rayN.Handler
|
||||||
_config.tunModeItem.stack = Global.TunStacks[0];
|
_config.tunModeItem.stack = Global.TunStacks[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
var tunInbound = JsonUtils.FromJson<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName)) ?? new Inbound4Sbox { };
|
var tunInbound = JsonUtils.Deserialize<Inbound4Sbox>(Utils.GetEmbedText(Global.TunSingboxInboundFileName)) ?? new Inbound4Sbox { };
|
||||||
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;
|
||||||
|
@ -458,7 +458,7 @@ namespace v2rayN.Handler
|
||||||
if (prevNode is not null
|
if (prevNode is not null
|
||||||
&& prevNode.configType != EConfigType.Custom)
|
&& prevNode.configType != EConfigType.Custom)
|
||||||
{
|
{
|
||||||
var prevOutbound = JsonUtils.FromJson<Outbound4Sbox>(txtOutbound);
|
var prevOutbound = JsonUtils.Deserialize<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);
|
||||||
|
@ -471,7 +471,7 @@ namespace v2rayN.Handler
|
||||||
if (nextNode is not null
|
if (nextNode is not null
|
||||||
&& nextNode.configType != EConfigType.Custom)
|
&& nextNode.configType != EConfigType.Custom)
|
||||||
{
|
{
|
||||||
var nextOutbound = JsonUtils.FromJson<Outbound4Sbox>(txtOutbound);
|
var nextOutbound = JsonUtils.Deserialize<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);
|
||||||
|
@ -496,7 +496,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
singboxConfig.route.auto_detect_interface = true;
|
singboxConfig.route.auto_detect_interface = true;
|
||||||
|
|
||||||
var tunRules = JsonUtils.FromJson<List<Rule4Sbox>>(Utils.GetEmbedText(Global.TunSingboxRulesFileName));
|
var tunRules = JsonUtils.Deserialize<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);
|
||||||
|
@ -519,7 +519,7 @@ namespace v2rayN.Handler
|
||||||
var routing = ConfigHandler.GetDefaultRouting(_config);
|
var routing = ConfigHandler.GetDefaultRouting(_config);
|
||||||
if (routing != null)
|
if (routing != null)
|
||||||
{
|
{
|
||||||
var rules = JsonUtils.FromJson<List<RulesItem>>(routing.ruleSet);
|
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.ruleSet);
|
||||||
foreach (var item in rules!)
|
foreach (var item in rules!)
|
||||||
{
|
{
|
||||||
if (item.enabled)
|
if (item.enabled)
|
||||||
|
@ -534,7 +534,7 @@ namespace v2rayN.Handler
|
||||||
var lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
|
var lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
|
||||||
if (lockedItem != null)
|
if (lockedItem != null)
|
||||||
{
|
{
|
||||||
var rules = JsonUtils.FromJson<List<RulesItem>>(lockedItem.ruleSet);
|
var rules = JsonUtils.Deserialize<List<RulesItem>>(lockedItem.ruleSet);
|
||||||
foreach (var item in rules!)
|
foreach (var item in rules!)
|
||||||
{
|
{
|
||||||
GenRoutingUserRule(item, singboxConfig.route.rules);
|
GenRoutingUserRule(item, singboxConfig.route.rules);
|
||||||
|
@ -726,7 +726,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName);
|
tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName);
|
||||||
}
|
}
|
||||||
dns4Sbox = JsonUtils.FromJson<Dns4Sbox>(tunDNS);
|
dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(tunDNS);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -737,7 +737,7 @@ namespace v2rayN.Handler
|
||||||
normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}";
|
normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}";
|
||||||
}
|
}
|
||||||
|
|
||||||
dns4Sbox = JsonUtils.FromJson<Dns4Sbox>(normalDNS);
|
dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(normalDNS);
|
||||||
}
|
}
|
||||||
if (dns4Sbox is null)
|
if (dns4Sbox is null)
|
||||||
{
|
{
|
||||||
|
@ -821,7 +821,7 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
singboxConfig = JsonUtils.FromJson<SingboxConfig>(result);
|
singboxConfig = JsonUtils.Deserialize<SingboxConfig>(result);
|
||||||
if (singboxConfig == null)
|
if (singboxConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
@ -919,7 +919,7 @@ namespace v2rayN.Handler
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var outbound = JsonUtils.FromJson<Outbound4Sbox>(txtOutbound);
|
var outbound = JsonUtils.Deserialize<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);
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
v2rayConfig = JsonUtils.FromJson<V2rayConfig>(result);
|
v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
@ -153,7 +153,7 @@ namespace v2rayN.Handler
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
var inbound = JsonUtils.FromJson<Inbounds4Ray>(result);
|
var inbound = JsonUtils.Deserialize<Inbounds4Ray>(result);
|
||||||
if (inbound == null)
|
if (inbound == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
@ -186,12 +186,12 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
v2rayConfig.routing.domainStrategy = routing.domainStrategy;
|
v2rayConfig.routing.domainStrategy = routing.domainStrategy;
|
||||||
}
|
}
|
||||||
var rules = JsonUtils.FromJson<List<RulesItem>>(routing.ruleSet);
|
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.ruleSet);
|
||||||
foreach (var item in rules)
|
foreach (var item in rules)
|
||||||
{
|
{
|
||||||
if (item.enabled)
|
if (item.enabled)
|
||||||
{
|
{
|
||||||
var item2 = JsonUtils.FromJson<RulesItem4Ray>(JsonUtils.ToJson(item));
|
var item2 = JsonUtils.Deserialize<RulesItem4Ray>(JsonUtils.Serialize(item));
|
||||||
GenRoutingUserRule(item2, v2rayConfig);
|
GenRoutingUserRule(item2, v2rayConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -202,10 +202,10 @@ namespace v2rayN.Handler
|
||||||
var lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
|
var lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
|
||||||
if (lockedItem != null)
|
if (lockedItem != null)
|
||||||
{
|
{
|
||||||
var rules = JsonUtils.FromJson<List<RulesItem>>(lockedItem.ruleSet);
|
var rules = JsonUtils.Deserialize<List<RulesItem>>(lockedItem.ruleSet);
|
||||||
foreach (var item in rules)
|
foreach (var item in rules)
|
||||||
{
|
{
|
||||||
var item2 = JsonUtils.FromJson<RulesItem4Ray>(JsonUtils.ToJson(item));
|
var item2 = JsonUtils.Deserialize<RulesItem4Ray>(JsonUtils.Serialize(item));
|
||||||
GenRoutingUserRule(item2, v2rayConfig);
|
GenRoutingUserRule(item2, v2rayConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -687,7 +687,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 = JsonUtils.FromJson<object>(request);
|
tcpSettings.header.request = JsonUtils.Deserialize<object>(request);
|
||||||
|
|
||||||
streamSettings.tcpSettings = tcpSettings;
|
streamSettings.tcpSettings = tcpSettings;
|
||||||
}
|
}
|
||||||
|
@ -848,7 +848,7 @@ namespace v2rayN.Handler
|
||||||
&& prevNode.configType != EConfigType.Hysteria2
|
&& prevNode.configType != EConfigType.Hysteria2
|
||||||
&& prevNode.configType != EConfigType.Tuic)
|
&& prevNode.configType != EConfigType.Tuic)
|
||||||
{
|
{
|
||||||
var prevOutbound = JsonUtils.FromJson<Outbounds4Ray>(txtOutbound);
|
var prevOutbound = JsonUtils.Deserialize<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);
|
||||||
|
@ -866,7 +866,7 @@ namespace v2rayN.Handler
|
||||||
&& nextNode.configType != EConfigType.Hysteria2
|
&& nextNode.configType != EConfigType.Hysteria2
|
||||||
&& nextNode.configType != EConfigType.Tuic)
|
&& nextNode.configType != EConfigType.Tuic)
|
||||||
{
|
{
|
||||||
var nextOutbound = JsonUtils.FromJson<Outbounds4Ray>(txtOutbound);
|
var nextOutbound = JsonUtils.Deserialize<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);
|
||||||
|
@ -911,7 +911,7 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
v2rayConfig = JsonUtils.FromJson<V2rayConfig>(result);
|
v2rayConfig = JsonUtils.Deserialize<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
@ -1008,7 +1008,7 @@ namespace v2rayN.Handler
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var outbound = JsonUtils.FromJson<Outbounds4Ray>(txtOutbound);
|
var outbound = JsonUtils.Deserialize<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);
|
||||||
|
|
|
@ -320,27 +320,5 @@ namespace v2rayN.Handler
|
||||||
ref int lpcEntries // Number of entries written to the buffer
|
ref int lpcEntries // Number of entries written to the buffer
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断是否使用代理
|
|
||||||
public static bool UsedProxy()
|
|
||||||
{
|
|
||||||
using RegistryKey? rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
|
|
||||||
if (rk?.GetValue("ProxyEnable")?.ToString() == "1")
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//获得代理的IP和端口
|
|
||||||
public static string? GetProxyProxyServer()
|
|
||||||
{
|
|
||||||
using RegistryKey? rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
|
|
||||||
string ProxyServer = rk.GetValue("ProxyServer").ToString();
|
|
||||||
return ProxyServer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -65,7 +65,7 @@ namespace v2rayN.Handler
|
||||||
fp = item.fingerprint
|
fp = item.fingerprint
|
||||||
};
|
};
|
||||||
|
|
||||||
url = JsonUtils.ToJson(vmessQRCode);
|
url = JsonUtils.Serialize(vmessQRCode);
|
||||||
url = Utils.Base64Encode(url);
|
url = Utils.Base64Encode(url);
|
||||||
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
url = $"{Global.ProtocolShares[EConfigType.VMess]}{url}";
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ namespace v2rayN.Handler
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
|
|
||||||
//转成Json
|
//转成Json
|
||||||
VmessQRCode? vmessQRCode = JsonUtils.FromJson<VmessQRCode>(result);
|
VmessQRCode? vmessQRCode = JsonUtils.Deserialize<VmessQRCode>(result);
|
||||||
if (vmessQRCode == null)
|
if (vmessQRCode == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedConversionConfiguration;
|
msg = ResUI.FailedConversionConfiguration;
|
||||||
|
|
|
@ -113,7 +113,7 @@ namespace v2rayN.Handler
|
||||||
up = 0; down = 0;
|
up = 0; down = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var trafficItem = JsonUtils.FromJson<TrafficItem>(source);
|
var trafficItem = JsonUtils.Deserialize<TrafficItem>(source);
|
||||||
if (trafficItem != null)
|
if (trafficItem != null)
|
||||||
{
|
{
|
||||||
up = trafficItem.up;
|
up = trafficItem.up;
|
||||||
|
|
|
@ -407,7 +407,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var gitHubReleases = JsonUtils.FromJson<List<GitHubRelease>>(gitHubReleaseApi);
|
var gitHubReleases = JsonUtils.Deserialize<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;
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace v2rayN.ViewModels
|
||||||
}
|
}
|
||||||
if (!Utils.IsNullOrEmpty(normalDNS2))
|
if (!Utils.IsNullOrEmpty(normalDNS2))
|
||||||
{
|
{
|
||||||
var obj2 = JsonUtils.FromJson<Dns4Sbox>(normalDNS2);
|
var obj2 = JsonUtils.Deserialize<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 = JsonUtils.FromJson<Dns4Sbox>(tunDNS2);
|
var obj2 = JsonUtils.Deserialize<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 = JsonUtils.ToJson(JsonUtils.ParseJson(normalDNS2));
|
item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));
|
||||||
item2.tunDNS = JsonUtils.ToJson(JsonUtils.ParseJson(tunDNS2));
|
item2.tunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2));
|
||||||
ConfigHandler.SaveDNSItems(_config, item2);
|
ConfigHandler.SaveDNSItems(_config, item2);
|
||||||
|
|
||||||
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
_noticeHandler?.Enqueue(ResUI.OperationSuccess);
|
||||||
|
|
|
@ -832,7 +832,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 = JsonUtils.FromJson<List<ProfileItem>>(JsonUtils.ToJson(lstModel));
|
_lstProfile = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(lstModel));
|
||||||
|
|
||||||
Application.Current.Dispatcher.Invoke((Action)(() =>
|
Application.Current.Dispatcher.Invoke((Action)(() =>
|
||||||
{
|
{
|
||||||
|
@ -938,7 +938,7 @@ namespace v2rayN.ViewModels
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
lstSelecteds = JsonUtils.FromJson<List<ProfileItem>>(JsonUtils.ToJson(orderProfiles));
|
lstSelecteds = JsonUtils.Deserialize<List<ProfileItem>>(JsonUtils.Serialize(orderProfiles));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -58,7 +58,7 @@ namespace v2rayN.ViewModels
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SelectedRouting = routingItem;
|
SelectedRouting = routingItem;
|
||||||
_rules = JsonUtils.FromJson<List<RulesItem>>(SelectedRouting.ruleSet);
|
_rules = JsonUtils.Deserialize<List<RulesItem>>(SelectedRouting.ruleSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
RefreshRulesItems();
|
RefreshRulesItems();
|
||||||
|
@ -207,7 +207,7 @@ namespace v2rayN.ViewModels
|
||||||
}
|
}
|
||||||
if (lst.Count > 0)
|
if (lst.Count > 0)
|
||||||
{
|
{
|
||||||
Utils.SetClipboardData(JsonUtils.ToJson(lst));
|
Utils.SetClipboardData(JsonUtils.Serialize(lst));
|
||||||
//UI.Show(ResUI.OperationSuccess"));
|
//UI.Show(ResUI.OperationSuccess"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,7 @@ namespace v2rayN.ViewModels
|
||||||
it.id = Utils.GetGUID(false);
|
it.id = Utils.GetGUID(false);
|
||||||
}
|
}
|
||||||
item.ruleNum = _rules.Count;
|
item.ruleNum = _rules.Count;
|
||||||
item.ruleSet = JsonUtils.ToJson(_rules, false);
|
item.ruleSet = JsonUtils.Serialize(_rules, false);
|
||||||
|
|
||||||
if (ConfigHandler.SaveRoutingItem(_config, item) == 0)
|
if (ConfigHandler.SaveRoutingItem(_config, item) == 0)
|
||||||
{
|
{
|
||||||
|
@ -328,7 +328,7 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
var lstRules = JsonUtils.FromJson<List<RulesItem>>(clipboardData);
|
var lstRules = JsonUtils.Deserialize<List<RulesItem>>(clipboardData);
|
||||||
if (lstRules == null)
|
if (lstRules == null)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace v2rayN.ViewModels
|
||||||
_lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
|
_lockedItem = ConfigHandler.GetLockedRoutingItem(_config);
|
||||||
if (_lockedItem != null)
|
if (_lockedItem != null)
|
||||||
{
|
{
|
||||||
_lockedRules = JsonUtils.FromJson<List<RulesItem>>(_lockedItem.ruleSet);
|
_lockedRules = JsonUtils.Deserialize<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);
|
||||||
|
|
||||||
|
@ -161,7 +161,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 = JsonUtils.ToJson(_lockedRules, false);
|
_lockedItem.ruleSet = JsonUtils.Serialize(_lockedRules, false);
|
||||||
|
|
||||||
ConfigHandler.SaveRoutingItem(_config, _lockedItem);
|
ConfigHandler.SaveRoutingItem(_config, _lockedItem);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue