mirror of
https://github.com/2dust/v2rayN.git
synced 2025-05-14 04:08:07 +00:00
改为可空类型
This commit is contained in:
parent
d44f311ba1
commit
b84bad4e1a
15 changed files with 161 additions and 177 deletions
|
@ -205,7 +205,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LazyConfig.Instance.SetConfig(ref config);
|
LazyConfig.Instance.SetConfig(config);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -438,7 +438,7 @@ namespace v2rayN.Handler
|
||||||
/// <param name="config"></param>
|
/// <param name="config"></param>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int SetDefaultServerIndex(ref Config config, string indexId)
|
public static int SetDefaultServerIndex(ref Config config, string? indexId)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(indexId))
|
if (Utils.IsNullOrEmpty(indexId))
|
||||||
{
|
{
|
||||||
|
@ -460,7 +460,7 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
var allItems = LazyConfig.Instance.ProfileItemIndexs("");
|
var allItems = LazyConfig.Instance.ProfileItemIndexs("");
|
||||||
if (allItems.Where(t => t == config.indexId).Count() > 0)
|
if (allItems.Where(t => t == config.indexId).Any())
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -468,13 +468,13 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return SetDefaultServerIndex(ref config, lstProfile[0].indexId);
|
return SetDefaultServerIndex(ref config, lstProfile[0].indexId);
|
||||||
}
|
}
|
||||||
if (allItems.Count() > 0)
|
if (allItems.Count > 0)
|
||||||
{
|
{
|
||||||
return SetDefaultServerIndex(ref config, allItems.FirstOrDefault());
|
return SetDefaultServerIndex(ref config, allItems.FirstOrDefault());
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
public static ProfileItem GetDefaultServer(ref Config config)
|
public static ProfileItem? GetDefaultServer(ref Config config)
|
||||||
{
|
{
|
||||||
var item = LazyConfig.Instance.GetProfileItem(config.indexId);
|
var item = LazyConfig.Instance.GetProfileItem(config.indexId);
|
||||||
if (item is null)
|
if (item is null)
|
||||||
|
@ -1041,7 +1041,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
ProfileItem profileItem = new();
|
ProfileItem profileItem = new();
|
||||||
//Is v2ray configuration
|
//Is v2ray configuration
|
||||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(clipboardData);
|
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(clipboardData);
|
||||||
if (v2rayConfig != null
|
if (v2rayConfig != null
|
||||||
&& v2rayConfig.inbounds != null
|
&& v2rayConfig.inbounds != null
|
||||||
&& v2rayConfig.inbounds.Count > 0
|
&& v2rayConfig.inbounds.Count > 0
|
||||||
|
@ -1176,7 +1176,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public static int AddBatchServers(ref Config config, string clipboardData, string subid, bool isSub)
|
public static int AddBatchServers(ref Config config, string clipboardData, string subid, bool isSub)
|
||||||
{
|
{
|
||||||
List<ProfileItem> lstOriSub = null;
|
List<ProfileItem>? lstOriSub = null;
|
||||||
if (isSub && !Utils.IsNullOrEmpty(subid))
|
if (isSub && !Utils.IsNullOrEmpty(subid))
|
||||||
{
|
{
|
||||||
lstOriSub = LazyConfig.Instance.ProfileItems(subid);
|
lstOriSub = LazyConfig.Instance.ProfileItems(subid);
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace v2rayN.Handler
|
||||||
/// <param name="msg"></param>
|
/// <param name="msg"></param>
|
||||||
/// <param name="content"></param>
|
/// <param name="content"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int GenerateClientConfig(ProfileItem node, string fileName, out string msg, out string content)
|
public static int GenerateClientConfig(ProfileItem node, string? fileName, out string msg, out string content)
|
||||||
{
|
{
|
||||||
content = string.Empty;
|
content = string.Empty;
|
||||||
try
|
try
|
||||||
|
@ -43,7 +43,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
V2rayConfig v2rayConfig = null;
|
V2rayConfig? v2rayConfig = null;
|
||||||
if (GenerateClientConfigContent(node, false, ref v2rayConfig, out msg) != 0)
|
if (GenerateClientConfigContent(node, false, ref v2rayConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -114,11 +114,11 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
v2rayConfig.inbounds = new List<Inbounds>();
|
v2rayConfig.inbounds = new List<Inbounds>();
|
||||||
|
|
||||||
Inbounds inbound = GetInbound(config.inbound[0], Global.InboundSocks, 0, true);
|
Inbounds? inbound = GetInbound(config.inbound[0], Global.InboundSocks, 0, true);
|
||||||
v2rayConfig.inbounds.Add(inbound);
|
v2rayConfig.inbounds.Add(inbound);
|
||||||
|
|
||||||
//http
|
//http
|
||||||
Inbounds inbound2 = GetInbound(config.inbound[0], Global.InboundHttp, 1, false);
|
Inbounds? inbound2 = GetInbound(config.inbound[0], Global.InboundHttp, 1, false);
|
||||||
v2rayConfig.inbounds.Add(inbound2);
|
v2rayConfig.inbounds.Add(inbound2);
|
||||||
|
|
||||||
if (config.inbound[0].allowLANConn)
|
if (config.inbound[0].allowLANConn)
|
||||||
|
@ -157,7 +157,7 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Inbounds GetInbound(InItem inItem, string tag, int offset, bool bSocks)
|
private static Inbounds? GetInbound(InItem inItem, string tag, int offset, bool bSocks)
|
||||||
{
|
{
|
||||||
string result = Utils.GetEmbedText(Global.v2raySampleInbound);
|
string result = Utils.GetEmbedText(Global.v2raySampleInbound);
|
||||||
if (Utils.IsNullOrEmpty(result))
|
if (Utils.IsNullOrEmpty(result))
|
||||||
|
@ -957,7 +957,7 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GenerateClientConfigContent(ProfileItem node, bool blExport, ref V2rayConfig v2rayConfig, out string msg)
|
public static int GenerateClientConfigContent(ProfileItem node, bool blExport, ref V2rayConfig? v2rayConfig, out string msg)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1034,7 +1034,7 @@ namespace v2rayN.Handler
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
@ -1123,7 +1123,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
#region Import (export) client/server configuration
|
#region Import (export) client/server configuration
|
||||||
|
|
||||||
public static ProfileItem ImportFromClientConfig(string fileName, out string msg)
|
public static ProfileItem? ImportFromClientConfig(string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = string.Empty;
|
||||||
ProfileItem profileItem = new ProfileItem();
|
ProfileItem profileItem = new ProfileItem();
|
||||||
|
@ -1137,7 +1137,7 @@ namespace v2rayN.Handler
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedConversionConfiguration;
|
msg = ResUI.FailedConversionConfiguration;
|
||||||
|
@ -1262,7 +1262,7 @@ namespace v2rayN.Handler
|
||||||
return profileItem;
|
return profileItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ProfileItem ImportFromServerConfig(string fileName, out string msg)
|
public static ProfileItem? ImportFromServerConfig(string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = string.Empty;
|
||||||
ProfileItem profileItem = new ProfileItem();
|
ProfileItem profileItem = new ProfileItem();
|
||||||
|
@ -1276,7 +1276,7 @@ namespace v2rayN.Handler
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedConversionConfiguration;
|
msg = ResUI.FailedConversionConfiguration;
|
||||||
|
@ -1401,7 +1401,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public static int Export2ClientConfig(ProfileItem node, string fileName, out string msg)
|
public static int Export2ClientConfig(ProfileItem node, string fileName, out string msg)
|
||||||
{
|
{
|
||||||
V2rayConfig v2rayConfig = null;
|
V2rayConfig? v2rayConfig = null;
|
||||||
if (GenerateClientConfigContent(node, true, ref v2rayConfig, out msg) != 0)
|
if (GenerateClientConfigContent(node, true, ref v2rayConfig, out msg) != 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -1440,7 +1440,7 @@ namespace v2rayN.Handler
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(result);
|
||||||
if (v2rayConfig == null)
|
if (v2rayConfig == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
|
@ -1523,7 +1523,7 @@ namespace v2rayN.Handler
|
||||||
v2rayConfig.inbounds.Add(inbound);
|
v2rayConfig.inbounds.Add(inbound);
|
||||||
|
|
||||||
//outbound
|
//outbound
|
||||||
V2rayConfig v2rayConfigCopy = Utils.FromJson<V2rayConfig>(result);
|
V2rayConfig? v2rayConfigCopy = Utils.FromJson<V2rayConfig>(result);
|
||||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||||
if (item is null)
|
if (item is null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,9 +12,9 @@ namespace v2rayN.Handler
|
||||||
class CoreHandler
|
class CoreHandler
|
||||||
{
|
{
|
||||||
private static string _coreCConfigRes = Global.coreConfigFileName;
|
private static string _coreCConfigRes = Global.coreConfigFileName;
|
||||||
private CoreInfo _coreInfo;
|
private CoreInfo? _coreInfo;
|
||||||
private int _processId = 0;
|
private int _processId = 0;
|
||||||
private Process _process;
|
private Process? _process;
|
||||||
Action<bool, string> _updateFunc;
|
Action<bool, string> _updateFunc;
|
||||||
|
|
||||||
public CoreHandler(Action<bool, string> update)
|
public CoreHandler(Action<bool, string> update)
|
||||||
|
@ -108,7 +108,7 @@ namespace v2rayN.Handler
|
||||||
Process[] existing = Process.GetProcessesByName(vName);
|
Process[] existing = Process.GetProcessesByName(vName);
|
||||||
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, _coreInfo.coreType)}.exe")
|
if (path == $"{Utils.GetBinPath(vName, _coreInfo.coreType)}.exe")
|
||||||
{
|
{
|
||||||
KillProcess(p);
|
KillProcess(p);
|
||||||
|
@ -193,7 +193,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
p.OutputDataReceived += (sender, e) =>
|
p.OutputDataReceived += (sender, e) =>
|
||||||
{
|
{
|
||||||
if (!String.IsNullOrEmpty(e.Data))
|
if (!string.IsNullOrEmpty(e.Data))
|
||||||
{
|
{
|
||||||
string msg = e.Data + Environment.NewLine;
|
string msg = e.Data + Environment.NewLine;
|
||||||
ShowMsg(false, msg);
|
ShowMsg(false, msg);
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
public event EventHandler<ResultEventArgs> UpdateCompleted;
|
public event EventHandler<ResultEventArgs> UpdateCompleted;
|
||||||
|
|
||||||
public event ErrorEventHandler Error;
|
public event ErrorEventHandler? Error;
|
||||||
|
|
||||||
|
|
||||||
public class ResultEventArgs : EventArgs
|
public class ResultEventArgs : EventArgs
|
||||||
|
@ -99,7 +99,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> UrlRedirectAsync(string url, bool blProxy)
|
public async Task<string?> UrlRedirectAsync(string url, bool blProxy)
|
||||||
{
|
{
|
||||||
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
|
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
|
||||||
var webRequestHandler = new SocketsHttpHandler
|
var webRequestHandler = new SocketsHttpHandler
|
||||||
|
@ -112,7 +112,7 @@ namespace v2rayN.Handler
|
||||||
HttpResponseMessage response = await client.GetAsync(url);
|
HttpResponseMessage response = await client.GetAsync(url);
|
||||||
if (response.StatusCode.ToString() == "Redirect")
|
if (response.StatusCode.ToString() == "Redirect")
|
||||||
{
|
{
|
||||||
return response.Headers.Location.ToString();
|
return response.Headers.Location?.ToString();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -121,7 +121,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string> TryDownloadString(string url, bool blProxy, string userAgent)
|
public async Task<string?> TryDownloadString(string url, bool blProxy, string userAgent)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -161,14 +161,12 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var wc = new WebClient())
|
using var wc = new WebClient();
|
||||||
|
wc.Proxy = GetWebProxy(blProxy);
|
||||||
|
var result3 = await wc.DownloadStringTaskAsync(url);
|
||||||
|
if (!Utils.IsNullOrEmpty(result3))
|
||||||
{
|
{
|
||||||
wc.Proxy = GetWebProxy(blProxy);
|
return result3;
|
||||||
var result3 = await wc.DownloadStringTaskAsync(url);
|
|
||||||
if (!Utils.IsNullOrEmpty(result3))
|
|
||||||
{
|
|
||||||
return result3;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -189,7 +187,7 @@ namespace v2rayN.Handler
|
||||||
/// DownloadString
|
/// DownloadString
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public async Task<string> DownloadStringAsync(string url, bool blProxy, string userAgent)
|
public async Task<string?> DownloadStringAsync(string url, bool blProxy, string userAgent)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -234,7 +232,7 @@ namespace v2rayN.Handler
|
||||||
/// DownloadString
|
/// DownloadString
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="url"></param>
|
/// <param name="url"></param>
|
||||||
public async Task<string> DownloadStringViaDownloader(string url, bool blProxy, string userAgent)
|
public async Task<string?> DownloadStringViaDownloader(string url, bool blProxy, string userAgent)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -262,7 +260,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int RunAvailabilityCheck(WebProxy webProxy)
|
public int RunAvailabilityCheck(WebProxy? webProxy)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -324,7 +322,7 @@ namespace v2rayN.Handler
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebProxy GetWebProxy(bool blProxy)
|
private WebProxy? GetWebProxy(bool blProxy)
|
||||||
{
|
{
|
||||||
if (!blProxy)
|
if (!blProxy)
|
||||||
{
|
{
|
||||||
|
@ -341,7 +339,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
private bool SocketCheck(string ip, int port)
|
private bool SocketCheck(string ip, int port)
|
||||||
{
|
{
|
||||||
Socket sock = null;
|
Socket? sock = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IPAddress ipa = IPAddress.Parse(ip);
|
IPAddress ipa = IPAddress.Parse(ip);
|
||||||
|
|
|
@ -22,7 +22,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
#region Config
|
#region Config
|
||||||
|
|
||||||
public void SetConfig(ref Config config)
|
public void SetConfig(Config config)
|
||||||
{
|
{
|
||||||
_config = config;
|
_config = config;
|
||||||
}
|
}
|
||||||
|
@ -118,7 +118,7 @@ namespace v2rayN.Handler
|
||||||
return SqliteHelper.Instance.Query<ProfileItemModel>(sql).ToList();
|
return SqliteHelper.Instance.Query<ProfileItemModel>(sql).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProfileItem GetProfileItem(string indexId)
|
public ProfileItem? GetProfileItem(string indexId)
|
||||||
{
|
{
|
||||||
if (Utils.IsNullOrEmpty(indexId))
|
if (Utils.IsNullOrEmpty(indexId))
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ namespace v2rayN.Handler
|
||||||
return item.coreType;
|
return item.coreType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CoreInfo GetCoreInfo(ECoreType coreType)
|
public CoreInfo? GetCoreInfo(ECoreType coreType)
|
||||||
{
|
{
|
||||||
if (coreInfos == null)
|
if (coreInfos == null)
|
||||||
{
|
{
|
||||||
|
@ -182,7 +182,7 @@ namespace v2rayN.Handler
|
||||||
return coreInfos.Where(t => t.coreType == coreType).FirstOrDefault();
|
return coreInfos.Where(t => t.coreType == coreType).FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CoreInfo> GetCoreInfos()
|
public List<CoreInfo>? GetCoreInfos()
|
||||||
{
|
{
|
||||||
if (coreInfos == null)
|
if (coreInfos == null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,7 +82,7 @@ namespace v2rayN.Handler
|
||||||
return BitmapFrame.Create(new Uri($"pack://application:,,,/Resources/NotifyIcon{index}.ico", UriKind.RelativeOrAbsolute));
|
return BitmapFrame.Create(new Uri($"pack://application:,,,/Resources/NotifyIcon{index}.ico", UriKind.RelativeOrAbsolute));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Icon GetNotifyIcon4Routing(Config config)
|
private Icon? GetNotifyIcon4Routing(Config config)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -286,7 +286,7 @@ namespace v2rayN.Handler
|
||||||
BackupGuiNConfig(config, true);
|
BackupGuiNConfig(config, true);
|
||||||
|
|
||||||
config = resConfig;
|
config = resConfig;
|
||||||
LazyConfig.Instance.SetConfig(ref config);
|
LazyConfig.Instance.SetConfig(config);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ namespace v2rayN.Handler
|
||||||
return SetProxy(null, null, 1);
|
return SetProxy(null, null, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool SetProxy(string strProxy, string exceptions, int type)
|
public static bool SetProxy(string? strProxy, string? exceptions, int type)
|
||||||
{
|
{
|
||||||
InternetPerConnOptionList list = new InternetPerConnOptionList();
|
InternetPerConnOptionList list = new InternetPerConnOptionList();
|
||||||
|
|
||||||
|
@ -189,8 +189,8 @@ namespace v2rayN.Handler
|
||||||
//判断是否使用代理
|
//判断是否使用代理
|
||||||
public static bool UsedProxy()
|
public static bool UsedProxy()
|
||||||
{
|
{
|
||||||
using RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
|
using RegistryKey? rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
|
||||||
if (rk.GetValue("ProxyEnable").ToString() == "1")
|
if (rk?.GetValue("ProxyEnable")?.ToString() == "1")
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -202,7 +202,7 @@ namespace v2rayN.Handler
|
||||||
//获得代理的IP和端口
|
//获得代理的IP和端口
|
||||||
public static string GetProxyProxyServer()
|
public static string GetProxyProxyServer()
|
||||||
{
|
{
|
||||||
using RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
|
using RegistryKey? rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
|
||||||
string ProxyServer = rk.GetValue("ProxyServer").ToString();
|
string ProxyServer = rk.GetValue("ProxyServer").ToString();
|
||||||
return ProxyServer;
|
return ProxyServer;
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ namespace v2rayN.Handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class QRCodeHelper
|
public class QRCodeHelper
|
||||||
{
|
{
|
||||||
public static DrawingImage GetQRCode(string strContent)
|
public static DrawingImage? GetQRCode(string strContent)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace v2rayN.Handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item"></param>
|
/// <param name="item"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetShareUrl(ProfileItem item)
|
public static string? GetShareUrl(ProfileItem item)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -167,7 +167,7 @@ namespace v2rayN.Handler
|
||||||
return Utils.IsIpv6(address) ? $"[{address}]" : address;
|
return Utils.IsIpv6(address) ? $"[{address}]" : address;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int GetStdTransport(ProfileItem item, string securityDef, ref Dictionary<string, string> dicQuery)
|
private static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
|
||||||
{
|
{
|
||||||
if (!Utils.IsNullOrEmpty(item.flow))
|
if (!Utils.IsNullOrEmpty(item.flow))
|
||||||
{
|
{
|
||||||
|
@ -270,7 +270,7 @@ namespace v2rayN.Handler
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="msg"></param>
|
/// <param name="msg"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static ProfileItem ImportFromClipboardConfig(string clipboardData, out string msg)
|
public static ProfileItem? ImportFromClipboardConfig(string clipboardData, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = string.Empty;
|
||||||
ProfileItem profileItem = new ProfileItem();
|
ProfileItem profileItem = new ProfileItem();
|
||||||
|
@ -357,7 +357,7 @@ namespace v2rayN.Handler
|
||||||
return profileItem;
|
return profileItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileItem ResolveVmess(string result, out string msg)
|
private static ProfileItem? ResolveVmess(string result, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = string.Empty;
|
||||||
var profileItem = new ProfileItem
|
var profileItem = new ProfileItem
|
||||||
|
@ -369,7 +369,7 @@ namespace v2rayN.Handler
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
|
|
||||||
//转成Json
|
//转成Json
|
||||||
VmessQRCode vmessQRCode = Utils.FromJson<VmessQRCode>(result);
|
VmessQRCode? vmessQRCode = Utils.FromJson<VmessQRCode>(result);
|
||||||
if (vmessQRCode == null)
|
if (vmessQRCode == null)
|
||||||
{
|
{
|
||||||
msg = ResUI.FailedConversionConfiguration;
|
msg = ResUI.FailedConversionConfiguration;
|
||||||
|
@ -407,17 +407,17 @@ namespace v2rayN.Handler
|
||||||
return profileItem;
|
return profileItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileItem ResolveVmess4Kitsunebi(string result)
|
private static ProfileItem? ResolveVmess4Kitsunebi(string result)
|
||||||
{
|
{
|
||||||
ProfileItem profileItem = new ProfileItem
|
ProfileItem profileItem = new ProfileItem
|
||||||
{
|
{
|
||||||
configType = EConfigType.VMess
|
configType = EConfigType.VMess
|
||||||
};
|
};
|
||||||
result = result.Substring(Global.vmessProtocol.Length);
|
result = result[Global.vmessProtocol.Length..];
|
||||||
int indexSplit = result.IndexOf("?");
|
int indexSplit = result.IndexOf("?");
|
||||||
if (indexSplit > 0)
|
if (indexSplit > 0)
|
||||||
{
|
{
|
||||||
result = result.Substring(0, indexSplit);
|
result = result[..indexSplit];
|
||||||
}
|
}
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
|
|
||||||
|
@ -445,7 +445,7 @@ namespace v2rayN.Handler
|
||||||
return profileItem;
|
return profileItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileItem ResolveStdVmess(string result)
|
private static ProfileItem? ResolveStdVmess(string result)
|
||||||
{
|
{
|
||||||
ProfileItem i = new ProfileItem
|
ProfileItem i = new ProfileItem
|
||||||
{
|
{
|
||||||
|
@ -526,7 +526,7 @@ namespace v2rayN.Handler
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileItem ResolveSip002(string result)
|
private static ProfileItem? ResolveSip002(string result)
|
||||||
{
|
{
|
||||||
Uri parsedUrl;
|
Uri parsedUrl;
|
||||||
try
|
try
|
||||||
|
@ -545,7 +545,7 @@ namespace v2rayN.Handler
|
||||||
};
|
};
|
||||||
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.UriEscaped);
|
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.UriEscaped);
|
||||||
//2022-blake3
|
//2022-blake3
|
||||||
if (rawUserInfo.Contains(":"))
|
if (rawUserInfo.Contains(':'))
|
||||||
{
|
{
|
||||||
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
|
||||||
if (userInfoParts.Length != 2)
|
if (userInfoParts.Length != 2)
|
||||||
|
@ -589,10 +589,10 @@ namespace v2rayN.Handler
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Regex UrlFinder = new Regex(@"ss://(?<base64>[A-Za-z0-9+-/=_]+)(?:#(?<tag>\S+))?", RegexOptions.IgnoreCase);
|
private static readonly Regex UrlFinder = new Regex(@"ss://(?<base64>[A-Za-z0-9+-/=_]+)(?:#(?<tag>\S+))?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
private static readonly Regex DetailsParser = new Regex(@"^((?<method>.+?):(?<password>.*)@(?<hostname>.+?):(?<port>\d+?))$", RegexOptions.IgnoreCase);
|
private static readonly Regex DetailsParser = new Regex(@"^((?<method>.+?):(?<password>.*)@(?<hostname>.+?):(?<port>\d+?))$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
private static ProfileItem ResolveSSLegacy(string result)
|
private static ProfileItem? ResolveSSLegacy(string result)
|
||||||
{
|
{
|
||||||
var match = UrlFinder.Match(result);
|
var match = UrlFinder.Match(result);
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
|
@ -627,7 +627,7 @@ namespace v2rayN.Handler
|
||||||
private static readonly Regex StdVmessUserInfo = new Regex(
|
private static readonly Regex StdVmessUserInfo = new Regex(
|
||||||
@"^(?<network>[a-z]+)(\+(?<streamSecurity>[a-z]+))?:(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$", RegexOptions.Compiled);
|
@"^(?<network>[a-z]+)(\+(?<streamSecurity>[a-z]+))?:(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$", RegexOptions.Compiled);
|
||||||
|
|
||||||
private static ProfileItem ResolveSocks(string result)
|
private static ProfileItem? ResolveSocks(string result)
|
||||||
{
|
{
|
||||||
ProfileItem profileItem = new ProfileItem
|
ProfileItem profileItem = new ProfileItem
|
||||||
{
|
{
|
||||||
|
@ -675,7 +675,7 @@ namespace v2rayN.Handler
|
||||||
return profileItem;
|
return profileItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProfileItem ResolveSocksNew(string result)
|
private static ProfileItem? ResolveSocksNew(string result)
|
||||||
{
|
{
|
||||||
Uri parsedUrl;
|
Uri parsedUrl;
|
||||||
try
|
try
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace v2rayN.Handler
|
||||||
private Channel channel_;
|
private Channel channel_;
|
||||||
private StatsService.StatsServiceClient client_;
|
private StatsService.StatsServiceClient client_;
|
||||||
private bool exitFlag_;
|
private bool exitFlag_;
|
||||||
private ServerStatItem _serverStatItem;
|
private ServerStatItem? _serverStatItem;
|
||||||
private List<ServerStatItem> _lstServerStat;
|
private List<ServerStatItem> _lstServerStat;
|
||||||
public List<ServerStatItem> ServerStat => _lstServerStat;
|
public List<ServerStatItem> ServerStat => _lstServerStat;
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
if (Enable && channel_.State == ChannelState.Ready)
|
if (Enable && channel_.State == ChannelState.Ready)
|
||||||
{
|
{
|
||||||
QueryStatsResponse res = null;
|
QueryStatsResponse? res = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
res = client_.QueryStats(new QueryStatsRequest() { Pattern = "", Reset = true });
|
res = client_.QueryStats(new QueryStatsRequest() { Pattern = "", Reset = true });
|
||||||
|
|
|
@ -20,7 +20,7 @@ namespace v2rayN.Handler
|
||||||
// <proxy-server><CR-LF>
|
// <proxy-server><CR-LF>
|
||||||
// <bypass-list><CR-LF>
|
// <bypass-list><CR-LF>
|
||||||
// <pac-url>
|
// <pac-url>
|
||||||
private static SysproxyConfig _userSettings = null;
|
private static SysproxyConfig? _userSettings = null;
|
||||||
|
|
||||||
enum RET_ERRORS : int
|
enum RET_ERRORS : int
|
||||||
{
|
{
|
||||||
|
@ -174,8 +174,8 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
process.StartInfo.CreateNoWindow = true;
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
StringBuilder output = new StringBuilder();
|
StringBuilder output = new StringBuilder(1024);
|
||||||
StringBuilder error = new StringBuilder();
|
StringBuilder error = new StringBuilder(1024);
|
||||||
|
|
||||||
process.OutputDataReceived += (sender, e) =>
|
process.OutputDataReceived += (sender, e) =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace v2rayN.Base
|
||||||
private string _tunConfigName = "tunConfig.json";
|
private string _tunConfigName = "tunConfig.json";
|
||||||
private static Config _config;
|
private static Config _config;
|
||||||
private CoreInfo coreInfo;
|
private CoreInfo coreInfo;
|
||||||
private Process _process;
|
private Process? _process;
|
||||||
private static int _socksPort;
|
private static int _socksPort;
|
||||||
private static bool _needRestart = true;
|
private static bool _needRestart = true;
|
||||||
private static bool _isRunning = false;
|
private static bool _isRunning = false;
|
||||||
|
|
|
@ -35,51 +35,46 @@ namespace v2rayN.Handler
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
var url = string.Empty;
|
var url = string.Empty;
|
||||||
|
|
||||||
DownloadHandle downloadHandle = null;
|
DownloadHandle downloadHandle = new DownloadHandle();
|
||||||
if (downloadHandle == null)
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
downloadHandle = new DownloadHandle();
|
if (args.Success)
|
||||||
|
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
|
||||||
{
|
{
|
||||||
if (args.Success)
|
_updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
|
||||||
{
|
|
||||||
_updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
|
{
|
||||||
|
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
||||||
|
fileName = Utils.UrlEncode(fileName);
|
||||||
|
Process process = new Process
|
||||||
{
|
{
|
||||||
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
StartInfo = new ProcessStartInfo
|
||||||
fileName = Utils.UrlEncode(fileName);
|
|
||||||
Process process = new Process
|
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
FileName = "v2rayUpgrade.exe",
|
||||||
{
|
Arguments = $"\"{fileName}\"",
|
||||||
FileName = "v2rayUpgrade.exe",
|
WorkingDirectory = Utils.StartupPath()
|
||||||
Arguments = $"\"{fileName}\"",
|
|
||||||
WorkingDirectory = Utils.StartupPath()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
process.Start();
|
|
||||||
if (process.Id > 0)
|
|
||||||
{
|
|
||||||
_updateFunc(true, "");
|
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
catch (Exception ex)
|
process.Start();
|
||||||
|
if (process.Id > 0)
|
||||||
{
|
{
|
||||||
_updateFunc(false, ex.Message);
|
_updateFunc(true, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_updateFunc(false, args.Msg);
|
_updateFunc(false, ex.Message);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
downloadHandle.Error += (sender2, args) =>
|
else
|
||||||
{
|
{
|
||||||
_updateFunc(false, args.GetException().Message);
|
_updateFunc(false, args.Msg);
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
downloadHandle.Error += (sender2, args) =>
|
||||||
|
{
|
||||||
|
_updateFunc(false, args.GetException().Message);
|
||||||
|
};
|
||||||
AbsoluteCompleted += (sender2, args) =>
|
AbsoluteCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
||||||
|
@ -106,36 +101,32 @@ namespace v2rayN.Handler
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
var url = string.Empty;
|
var url = string.Empty;
|
||||||
|
|
||||||
DownloadHandle downloadHandle = null;
|
DownloadHandle downloadHandle = new DownloadHandle();
|
||||||
if (downloadHandle == null)
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
downloadHandle = new DownloadHandle();
|
if (args.Success)
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
|
||||||
{
|
{
|
||||||
if (args.Success)
|
_updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
|
||||||
{
|
_updateFunc(false, ResUI.MsgUnpacking);
|
||||||
_updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
|
|
||||||
_updateFunc(false, ResUI.MsgUnpacking);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
|
||||||
_updateFunc(true, url);
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_updateFunc(false, ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_updateFunc(false, args.Msg);
|
_updateFunc(true, url);
|
||||||
}
|
}
|
||||||
};
|
catch (Exception ex)
|
||||||
downloadHandle.Error += (sender2, args) =>
|
{
|
||||||
|
_updateFunc(false, ex.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
_updateFunc(true, args.GetException().Message);
|
_updateFunc(false, args.Msg);
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
downloadHandle.Error += (sender2, args) =>
|
||||||
|
{
|
||||||
|
_updateFunc(true, args.GetException().Message);
|
||||||
|
};
|
||||||
|
|
||||||
AbsoluteCompleted += (sender2, args) =>
|
AbsoluteCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
|
@ -226,7 +217,7 @@ namespace v2rayN.Handler
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
|
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
|
||||||
if (result.Length < 99)
|
if (result!.Length < 99)
|
||||||
{
|
{
|
||||||
_updateFunc(false, $"{hashCode}{result}");
|
_updateFunc(false, $"{hashCode}{result}");
|
||||||
}
|
}
|
||||||
|
@ -262,49 +253,44 @@ namespace v2rayN.Handler
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
var url = string.Format(Global.geoUrl, geoName);
|
var url = string.Format(Global.geoUrl, geoName);
|
||||||
|
|
||||||
DownloadHandle downloadHandle = null;
|
DownloadHandle downloadHandle = new DownloadHandle();
|
||||||
if (downloadHandle == null)
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
downloadHandle = new DownloadHandle();
|
if (args.Success)
|
||||||
|
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
|
||||||
{
|
{
|
||||||
if (args.Success)
|
_updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
_updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
|
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
||||||
|
if (File.Exists(fileName))
|
||||||
try
|
|
||||||
{
|
{
|
||||||
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
//Global.coreTypes.ForEach(it =>
|
||||||
if (File.Exists(fileName))
|
//{
|
||||||
{
|
// string targetPath = Utils.GetBinPath($"{geoName}.dat", (ECoreType)Enum.Parse(typeof(ECoreType), it));
|
||||||
//Global.coreTypes.ForEach(it =>
|
// File.Copy(fileName, targetPath, true);
|
||||||
//{
|
//});
|
||||||
// string targetPath = Utils.GetBinPath($"{geoName}.dat", (ECoreType)Enum.Parse(typeof(ECoreType), it));
|
string targetPath = Utils.GetBinPath($"{geoName}.dat");
|
||||||
// File.Copy(fileName, targetPath, true);
|
File.Copy(fileName, targetPath, true);
|
||||||
//});
|
|
||||||
string targetPath = Utils.GetBinPath($"{geoName}.dat");
|
|
||||||
File.Copy(fileName, targetPath, true);
|
|
||||||
|
|
||||||
File.Delete(fileName);
|
File.Delete(fileName);
|
||||||
//_updateFunc(true, "");
|
//_updateFunc(true, "");
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_updateFunc(false, ex.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_updateFunc(false, args.Msg);
|
_updateFunc(false, ex.Message);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
downloadHandle.Error += (sender2, args) =>
|
else
|
||||||
{
|
{
|
||||||
_updateFunc(false, args.GetException().Message);
|
_updateFunc(false, args.Msg);
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
downloadHandle.Error += (sender2, args) =>
|
||||||
|
{
|
||||||
|
_updateFunc(false, args.GetException().Message);
|
||||||
|
};
|
||||||
askToDownload(downloadHandle, url, false);
|
askToDownload(downloadHandle, url, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,8 @@ namespace v2rayN
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||||
using Stream stream = assembly.GetManifestResourceStream(res);
|
using Stream? stream = assembly.GetManifestResourceStream(res);
|
||||||
|
ArgumentNullException.ThrowIfNull(stream);
|
||||||
using StreamReader reader = new(stream);
|
using StreamReader reader = new(stream);
|
||||||
result = reader.ReadToEnd();
|
result = reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
@ -90,7 +91,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? FromJson<T>(string strJson)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -98,8 +99,7 @@ namespace v2rayN
|
||||||
{
|
{
|
||||||
return default;
|
return default;
|
||||||
}
|
}
|
||||||
T obj = JsonConvert.DeserializeObject<T>(strJson);
|
return JsonConvert.DeserializeObject<T>(strJson);
|
||||||
return obj;
|
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -112,7 +112,7 @@ namespace v2rayN
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string ToJson(object obj, bool indented = true)
|
public static string ToJson(object? obj, bool indented = true)
|
||||||
{
|
{
|
||||||
string result = string.Empty;
|
string result = string.Empty;
|
||||||
try
|
try
|
||||||
|
@ -141,7 +141,7 @@ namespace v2rayN
|
||||||
/// <param name="obj"></param>
|
/// <param name="obj"></param>
|
||||||
/// <param name="filePath"></param>
|
/// <param name="filePath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static int ToJsonFile(object obj, string filePath, bool nullValue = true)
|
public static int ToJsonFile(object? obj, string filePath, bool nullValue = true)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
try
|
try
|
||||||
|
@ -168,7 +168,7 @@ namespace v2rayN
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JObject ParseJson(string strJson)
|
public static JObject? ParseJson(string strJson)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -676,7 +676,7 @@ namespace v2rayN
|
||||||
return Application.StartupPath;
|
return Application.StartupPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string RegReadValue(string path, string name, string def)
|
public static string? RegReadValue(string path, string name, string def)
|
||||||
{
|
{
|
||||||
RegistryKey? regKey = null;
|
RegistryKey? regKey = null;
|
||||||
try
|
try
|
||||||
|
@ -737,7 +737,7 @@ namespace v2rayN
|
||||||
public static bool CheckForDotNetVersion(int release = 528040)
|
public static bool CheckForDotNetVersion(int release = 528040)
|
||||||
{
|
{
|
||||||
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
|
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
|
||||||
using RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey);
|
using RegistryKey? ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey);
|
||||||
if (ndpKey != null && ndpKey.GetValue("Release") != null)
|
if (ndpKey != null && ndpKey.GetValue("Release") != null)
|
||||||
{
|
{
|
||||||
return (int)ndpKey.GetValue("Release") >= release ? true : false;
|
return (int)ndpKey.GetValue("Release") >= release ? true : false;
|
||||||
|
@ -908,7 +908,7 @@ namespace v2rayN
|
||||||
/// 获取剪贴板数
|
/// 获取剪贴板数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static string GetClipboardData()
|
public static string? GetClipboardData()
|
||||||
{
|
{
|
||||||
string strData = string.Empty;
|
string strData = string.Empty;
|
||||||
try
|
try
|
||||||
|
@ -995,7 +995,7 @@ namespace v2rayN
|
||||||
return fileName;
|
return fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IPAddress GetDefaultGateway()
|
public static IPAddress? GetDefaultGateway()
|
||||||
{
|
{
|
||||||
return NetworkInterface
|
return NetworkInterface
|
||||||
.GetAllNetworkInterfaces()
|
.GetAllNetworkInterfaces()
|
||||||
|
|
|
@ -532,7 +532,7 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
_noticeHandler?.SendMessage(msg);
|
_noticeHandler?.SendMessage(msg);
|
||||||
}
|
}
|
||||||
private async void UpdateTaskHandler(bool success, string msg)
|
private void UpdateTaskHandler(bool success, string msg)
|
||||||
{
|
{
|
||||||
_noticeHandler?.SendMessage(msg);
|
_noticeHandler?.SendMessage(msg);
|
||||||
if (success)
|
if (success)
|
||||||
|
|
Loading…
Reference in a new issue