diff --git a/v2rayN/v2rayN/Handler/ConfigHandler.cs b/v2rayN/v2rayN/Handler/ConfigHandler.cs
index b99f507f..59e1bc5e 100644
--- a/v2rayN/v2rayN/Handler/ConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/ConfigHandler.cs
@@ -205,7 +205,7 @@ namespace v2rayN.Handler
}
- LazyConfig.Instance.SetConfig(ref config);
+ LazyConfig.Instance.SetConfig(config);
return 0;
}
///
@@ -438,7 +438,7 @@ namespace v2rayN.Handler
///
///
///
- public static int SetDefaultServerIndex(ref Config config, string indexId)
+ public static int SetDefaultServerIndex(ref Config config, string? indexId)
{
if (Utils.IsNullOrEmpty(indexId))
{
@@ -460,7 +460,7 @@ namespace v2rayN.Handler
return 0;
}
var allItems = LazyConfig.Instance.ProfileItemIndexs("");
- if (allItems.Where(t => t == config.indexId).Count() > 0)
+ if (allItems.Where(t => t == config.indexId).Any())
{
return 0;
}
@@ -468,13 +468,13 @@ namespace v2rayN.Handler
{
return SetDefaultServerIndex(ref config, lstProfile[0].indexId);
}
- if (allItems.Count() > 0)
+ if (allItems.Count > 0)
{
return SetDefaultServerIndex(ref config, allItems.FirstOrDefault());
}
return -1;
}
- public static ProfileItem GetDefaultServer(ref Config config)
+ public static ProfileItem? GetDefaultServer(ref Config config)
{
var item = LazyConfig.Instance.GetProfileItem(config.indexId);
if (item is null)
@@ -1041,7 +1041,7 @@ namespace v2rayN.Handler
ProfileItem profileItem = new();
//Is v2ray configuration
- V2rayConfig v2rayConfig = Utils.FromJson(clipboardData);
+ V2rayConfig? v2rayConfig = Utils.FromJson(clipboardData);
if (v2rayConfig != null
&& v2rayConfig.inbounds != null
&& v2rayConfig.inbounds.Count > 0
@@ -1176,7 +1176,7 @@ namespace v2rayN.Handler
public static int AddBatchServers(ref Config config, string clipboardData, string subid, bool isSub)
{
- List lstOriSub = null;
+ List? lstOriSub = null;
if (isSub && !Utils.IsNullOrEmpty(subid))
{
lstOriSub = LazyConfig.Instance.ProfileItems(subid);
diff --git a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs
index be92a35b..1dc417fd 100644
--- a/v2rayN/v2rayN/Handler/CoreConfigHandler.cs
+++ b/v2rayN/v2rayN/Handler/CoreConfigHandler.cs
@@ -25,7 +25,7 @@ namespace v2rayN.Handler
///
///
///
- 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;
try
@@ -43,7 +43,7 @@ namespace v2rayN.Handler
}
else
{
- V2rayConfig v2rayConfig = null;
+ V2rayConfig? v2rayConfig = null;
if (GenerateClientConfigContent(node, false, ref v2rayConfig, out msg) != 0)
{
return -1;
@@ -114,11 +114,11 @@ namespace v2rayN.Handler
{
v2rayConfig.inbounds = new List();
- Inbounds inbound = GetInbound(config.inbound[0], Global.InboundSocks, 0, true);
+ Inbounds? inbound = GetInbound(config.inbound[0], Global.InboundSocks, 0, true);
v2rayConfig.inbounds.Add(inbound);
//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);
if (config.inbound[0].allowLANConn)
@@ -157,7 +157,7 @@ namespace v2rayN.Handler
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);
if (Utils.IsNullOrEmpty(result))
@@ -957,7 +957,7 @@ namespace v2rayN.Handler
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
{
@@ -1034,7 +1034,7 @@ namespace v2rayN.Handler
return -1;
}
- V2rayConfig v2rayConfig = Utils.FromJson(result);
+ V2rayConfig? v2rayConfig = Utils.FromJson(result);
if (v2rayConfig == null)
{
msg = ResUI.FailedGenDefaultConfiguration;
@@ -1123,7 +1123,7 @@ namespace v2rayN.Handler
#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;
ProfileItem profileItem = new ProfileItem();
@@ -1137,7 +1137,7 @@ namespace v2rayN.Handler
return null;
}
- V2rayConfig v2rayConfig = Utils.FromJson(result);
+ V2rayConfig? v2rayConfig = Utils.FromJson(result);
if (v2rayConfig == null)
{
msg = ResUI.FailedConversionConfiguration;
@@ -1262,7 +1262,7 @@ namespace v2rayN.Handler
return profileItem;
}
- public static ProfileItem ImportFromServerConfig(string fileName, out string msg)
+ public static ProfileItem? ImportFromServerConfig(string fileName, out string msg)
{
msg = string.Empty;
ProfileItem profileItem = new ProfileItem();
@@ -1276,7 +1276,7 @@ namespace v2rayN.Handler
return null;
}
- V2rayConfig v2rayConfig = Utils.FromJson(result);
+ V2rayConfig? v2rayConfig = Utils.FromJson(result);
if (v2rayConfig == null)
{
msg = ResUI.FailedConversionConfiguration;
@@ -1401,7 +1401,7 @@ namespace v2rayN.Handler
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)
{
return -1;
@@ -1440,7 +1440,7 @@ namespace v2rayN.Handler
return "";
}
- V2rayConfig v2rayConfig = Utils.FromJson(result);
+ V2rayConfig? v2rayConfig = Utils.FromJson(result);
if (v2rayConfig == null)
{
msg = ResUI.FailedGenDefaultConfiguration;
@@ -1523,7 +1523,7 @@ namespace v2rayN.Handler
v2rayConfig.inbounds.Add(inbound);
//outbound
- V2rayConfig v2rayConfigCopy = Utils.FromJson(result);
+ V2rayConfig? v2rayConfigCopy = Utils.FromJson(result);
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
if (item is null)
{
diff --git a/v2rayN/v2rayN/Handler/CoreHandler.cs b/v2rayN/v2rayN/Handler/CoreHandler.cs
index f5ac0957..87d7f063 100644
--- a/v2rayN/v2rayN/Handler/CoreHandler.cs
+++ b/v2rayN/v2rayN/Handler/CoreHandler.cs
@@ -12,9 +12,9 @@ namespace v2rayN.Handler
class CoreHandler
{
private static string _coreCConfigRes = Global.coreConfigFileName;
- private CoreInfo _coreInfo;
+ private CoreInfo? _coreInfo;
private int _processId = 0;
- private Process _process;
+ private Process? _process;
Action _updateFunc;
public CoreHandler(Action update)
@@ -108,7 +108,7 @@ namespace v2rayN.Handler
Process[] existing = Process.GetProcessesByName(vName);
foreach (Process p in existing)
{
- string path = p.MainModule.FileName;
+ string? path = p.MainModule?.FileName;
if (path == $"{Utils.GetBinPath(vName, _coreInfo.coreType)}.exe")
{
KillProcess(p);
@@ -193,7 +193,7 @@ namespace v2rayN.Handler
{
p.OutputDataReceived += (sender, e) =>
{
- if (!String.IsNullOrEmpty(e.Data))
+ if (!string.IsNullOrEmpty(e.Data))
{
string msg = e.Data + Environment.NewLine;
ShowMsg(false, msg);
diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs
index caa463ea..66fb7316 100644
--- a/v2rayN/v2rayN/Handler/DownloadHandle.cs
+++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs
@@ -16,7 +16,7 @@ namespace v2rayN.Handler
{
public event EventHandler UpdateCompleted;
- public event ErrorEventHandler Error;
+ public event ErrorEventHandler? Error;
public class ResultEventArgs : EventArgs
@@ -99,7 +99,7 @@ namespace v2rayN.Handler
}
}
- public async Task UrlRedirectAsync(string url, bool blProxy)
+ public async Task UrlRedirectAsync(string url, bool blProxy)
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().guiItem.enableSecurityProtocolTls13);
var webRequestHandler = new SocketsHttpHandler
@@ -112,7 +112,7 @@ namespace v2rayN.Handler
HttpResponseMessage response = await client.GetAsync(url);
if (response.StatusCode.ToString() == "Redirect")
{
- return response.Headers.Location.ToString();
+ return response.Headers.Location?.ToString();
}
else
{
@@ -121,7 +121,7 @@ namespace v2rayN.Handler
}
}
- public async Task TryDownloadString(string url, bool blProxy, string userAgent)
+ public async Task TryDownloadString(string url, bool blProxy, string userAgent)
{
try
{
@@ -161,14 +161,12 @@ namespace v2rayN.Handler
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);
- var result3 = await wc.DownloadStringTaskAsync(url);
- if (!Utils.IsNullOrEmpty(result3))
- {
- return result3;
- }
+ return result3;
}
}
catch (Exception ex)
@@ -189,7 +187,7 @@ namespace v2rayN.Handler
/// DownloadString
///
///
- public async Task DownloadStringAsync(string url, bool blProxy, string userAgent)
+ public async Task DownloadStringAsync(string url, bool blProxy, string userAgent)
{
try
{
@@ -234,7 +232,7 @@ namespace v2rayN.Handler
/// DownloadString
///
///
- public async Task DownloadStringViaDownloader(string url, bool blProxy, string userAgent)
+ public async Task DownloadStringViaDownloader(string url, bool blProxy, string userAgent)
{
try
{
@@ -262,7 +260,7 @@ namespace v2rayN.Handler
}
- public int RunAvailabilityCheck(WebProxy webProxy)
+ public int RunAvailabilityCheck(WebProxy? webProxy)
{
try
{
@@ -324,7 +322,7 @@ namespace v2rayN.Handler
return msg;
}
- private WebProxy GetWebProxy(bool blProxy)
+ private WebProxy? GetWebProxy(bool blProxy)
{
if (!blProxy)
{
@@ -341,7 +339,7 @@ namespace v2rayN.Handler
private bool SocketCheck(string ip, int port)
{
- Socket sock = null;
+ Socket? sock = null;
try
{
IPAddress ipa = IPAddress.Parse(ip);
diff --git a/v2rayN/v2rayN/Handler/LazyConfig.cs b/v2rayN/v2rayN/Handler/LazyConfig.cs
index f1fe5093..f0947dbf 100644
--- a/v2rayN/v2rayN/Handler/LazyConfig.cs
+++ b/v2rayN/v2rayN/Handler/LazyConfig.cs
@@ -22,7 +22,7 @@ namespace v2rayN.Handler
#region Config
- public void SetConfig(ref Config config)
+ public void SetConfig(Config config)
{
_config = config;
}
@@ -118,7 +118,7 @@ namespace v2rayN.Handler
return SqliteHelper.Instance.Query(sql).ToList();
}
- public ProfileItem GetProfileItem(string indexId)
+ public ProfileItem? GetProfileItem(string indexId)
{
if (Utils.IsNullOrEmpty(indexId))
{
@@ -173,7 +173,7 @@ namespace v2rayN.Handler
return item.coreType;
}
- public CoreInfo GetCoreInfo(ECoreType coreType)
+ public CoreInfo? GetCoreInfo(ECoreType coreType)
{
if (coreInfos == null)
{
@@ -182,7 +182,7 @@ namespace v2rayN.Handler
return coreInfos.Where(t => t.coreType == coreType).FirstOrDefault();
}
- public List GetCoreInfos()
+ public List? GetCoreInfos()
{
if (coreInfos == null)
{
diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs
index 96c15478..9c942757 100644
--- a/v2rayN/v2rayN/Handler/MainFormHandler.cs
+++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs
@@ -82,7 +82,7 @@ namespace v2rayN.Handler
return BitmapFrame.Create(new Uri($"pack://application:,,,/Resources/NotifyIcon{index}.ico", UriKind.RelativeOrAbsolute));
}
- private Icon GetNotifyIcon4Routing(Config config)
+ private Icon? GetNotifyIcon4Routing(Config config)
{
try
{
@@ -286,7 +286,7 @@ namespace v2rayN.Handler
BackupGuiNConfig(config, true);
config = resConfig;
- LazyConfig.Instance.SetConfig(ref config);
+ LazyConfig.Instance.SetConfig(config);
return true;
}
diff --git a/v2rayN/v2rayN/Handler/ProxySetting.cs b/v2rayN/v2rayN/Handler/ProxySetting.cs
index 045f6039..446b1caa 100644
--- a/v2rayN/v2rayN/Handler/ProxySetting.cs
+++ b/v2rayN/v2rayN/Handler/ProxySetting.cs
@@ -10,7 +10,7 @@ namespace v2rayN.Handler
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();
@@ -189,8 +189,8 @@ namespace v2rayN.Handler
//判断是否使用代理
public static bool UsedProxy()
{
- using RegistryKey rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
- if (rk.GetValue("ProxyEnable").ToString() == "1")
+ using RegistryKey? rk = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true);
+ if (rk?.GetValue("ProxyEnable")?.ToString() == "1")
{
return true;
}
@@ -202,7 +202,7 @@ namespace v2rayN.Handler
//获得代理的IP和端口
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();
return ProxyServer;
diff --git a/v2rayN/v2rayN/Handler/QRCodeHelper.cs b/v2rayN/v2rayN/Handler/QRCodeHelper.cs
index 643b7e7e..ff5528d2 100644
--- a/v2rayN/v2rayN/Handler/QRCodeHelper.cs
+++ b/v2rayN/v2rayN/Handler/QRCodeHelper.cs
@@ -9,7 +9,7 @@ namespace v2rayN.Handler
///
public class QRCodeHelper
{
- public static DrawingImage GetQRCode(string strContent)
+ public static DrawingImage? GetQRCode(string strContent)
{
try
{
diff --git a/v2rayN/v2rayN/Handler/ShareHandler.cs b/v2rayN/v2rayN/Handler/ShareHandler.cs
index ed93607b..d76b201b 100644
--- a/v2rayN/v2rayN/Handler/ShareHandler.cs
+++ b/v2rayN/v2rayN/Handler/ShareHandler.cs
@@ -17,7 +17,7 @@ namespace v2rayN.Handler
///
///
///
- public static string GetShareUrl(ProfileItem item)
+ public static string? GetShareUrl(ProfileItem item)
{
try
{
@@ -167,7 +167,7 @@ namespace v2rayN.Handler
return Utils.IsIpv6(address) ? $"[{address}]" : address;
}
- private static int GetStdTransport(ProfileItem item, string securityDef, ref Dictionary dicQuery)
+ private static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary dicQuery)
{
if (!Utils.IsNullOrEmpty(item.flow))
{
@@ -270,7 +270,7 @@ namespace v2rayN.Handler
///
///
///
- public static ProfileItem ImportFromClipboardConfig(string clipboardData, out string msg)
+ public static ProfileItem? ImportFromClipboardConfig(string clipboardData, out string msg)
{
msg = string.Empty;
ProfileItem profileItem = new ProfileItem();
@@ -357,7 +357,7 @@ namespace v2rayN.Handler
return profileItem;
}
- private static ProfileItem ResolveVmess(string result, out string msg)
+ private static ProfileItem? ResolveVmess(string result, out string msg)
{
msg = string.Empty;
var profileItem = new ProfileItem
@@ -369,7 +369,7 @@ namespace v2rayN.Handler
result = Utils.Base64Decode(result);
//转成Json
- VmessQRCode vmessQRCode = Utils.FromJson(result);
+ VmessQRCode? vmessQRCode = Utils.FromJson(result);
if (vmessQRCode == null)
{
msg = ResUI.FailedConversionConfiguration;
@@ -407,17 +407,17 @@ namespace v2rayN.Handler
return profileItem;
}
- private static ProfileItem ResolveVmess4Kitsunebi(string result)
+ private static ProfileItem? ResolveVmess4Kitsunebi(string result)
{
ProfileItem profileItem = new ProfileItem
{
configType = EConfigType.VMess
};
- result = result.Substring(Global.vmessProtocol.Length);
+ result = result[Global.vmessProtocol.Length..];
int indexSplit = result.IndexOf("?");
if (indexSplit > 0)
{
- result = result.Substring(0, indexSplit);
+ result = result[..indexSplit];
}
result = Utils.Base64Decode(result);
@@ -445,7 +445,7 @@ namespace v2rayN.Handler
return profileItem;
}
- private static ProfileItem ResolveStdVmess(string result)
+ private static ProfileItem? ResolveStdVmess(string result)
{
ProfileItem i = new ProfileItem
{
@@ -526,7 +526,7 @@ namespace v2rayN.Handler
return i;
}
- private static ProfileItem ResolveSip002(string result)
+ private static ProfileItem? ResolveSip002(string result)
{
Uri parsedUrl;
try
@@ -545,7 +545,7 @@ namespace v2rayN.Handler
};
string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.UriEscaped);
//2022-blake3
- if (rawUserInfo.Contains(":"))
+ if (rawUserInfo.Contains(':'))
{
string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2);
if (userInfoParts.Length != 2)
@@ -589,10 +589,10 @@ namespace v2rayN.Handler
return server;
}
- private static readonly Regex UrlFinder = new Regex(@"ss://(?[A-Za-z0-9+-/=_]+)(?:#(?\S+))?", RegexOptions.IgnoreCase);
- private static readonly Regex DetailsParser = new Regex(@"^((?.+?):(?.*)@(?.+?):(?\d+?))$", RegexOptions.IgnoreCase);
+ private static readonly Regex UrlFinder = new Regex(@"ss://(?[A-Za-z0-9+-/=_]+)(?:#(?\S+))?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
+ private static readonly Regex DetailsParser = new Regex(@"^((?.+?):(?.*)@(?.+?):(?\d+?))$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
- private static ProfileItem ResolveSSLegacy(string result)
+ private static ProfileItem? ResolveSSLegacy(string result)
{
var match = UrlFinder.Match(result);
if (!match.Success)
@@ -627,7 +627,7 @@ namespace v2rayN.Handler
private static readonly Regex StdVmessUserInfo = new Regex(
@"^(?[a-z]+)(\+(?[a-z]+))?:(?[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
{
@@ -675,7 +675,7 @@ namespace v2rayN.Handler
return profileItem;
}
- private static ProfileItem ResolveSocksNew(string result)
+ private static ProfileItem? ResolveSocksNew(string result)
{
Uri parsedUrl;
try
diff --git a/v2rayN/v2rayN/Handler/StatisticsHandler.cs b/v2rayN/v2rayN/Handler/StatisticsHandler.cs
index cb747f46..1421f239 100644
--- a/v2rayN/v2rayN/Handler/StatisticsHandler.cs
+++ b/v2rayN/v2rayN/Handler/StatisticsHandler.cs
@@ -13,7 +13,7 @@ namespace v2rayN.Handler
private Channel channel_;
private StatsService.StatsServiceClient client_;
private bool exitFlag_;
- private ServerStatItem _serverStatItem;
+ private ServerStatItem? _serverStatItem;
private List _lstServerStat;
public List ServerStat => _lstServerStat;
@@ -70,7 +70,7 @@ namespace v2rayN.Handler
{
if (Enable && channel_.State == ChannelState.Ready)
{
- QueryStatsResponse res = null;
+ QueryStatsResponse? res = null;
try
{
res = client_.QueryStats(new QueryStatsRequest() { Pattern = "", Reset = true });
diff --git a/v2rayN/v2rayN/Handler/SysProxyHandle.cs b/v2rayN/v2rayN/Handler/SysProxyHandle.cs
index c0dd4f8d..1c979b8e 100644
--- a/v2rayN/v2rayN/Handler/SysProxyHandle.cs
+++ b/v2rayN/v2rayN/Handler/SysProxyHandle.cs
@@ -20,7 +20,7 @@ namespace v2rayN.Handler
//
//
//
- private static SysproxyConfig _userSettings = null;
+ private static SysproxyConfig? _userSettings = null;
enum RET_ERRORS : int
{
@@ -174,8 +174,8 @@ namespace v2rayN.Handler
process.StartInfo.CreateNoWindow = true;
- StringBuilder output = new StringBuilder();
- StringBuilder error = new StringBuilder();
+ StringBuilder output = new StringBuilder(1024);
+ StringBuilder error = new StringBuilder(1024);
process.OutputDataReceived += (sender, e) =>
{
diff --git a/v2rayN/v2rayN/Handler/TunHandler.cs b/v2rayN/v2rayN/Handler/TunHandler.cs
index ef0e99ff..04c0075b 100644
--- a/v2rayN/v2rayN/Handler/TunHandler.cs
+++ b/v2rayN/v2rayN/Handler/TunHandler.cs
@@ -13,7 +13,7 @@ namespace v2rayN.Base
private string _tunConfigName = "tunConfig.json";
private static Config _config;
private CoreInfo coreInfo;
- private Process _process;
+ private Process? _process;
private static int _socksPort;
private static bool _needRestart = true;
private static bool _isRunning = false;
diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs
index a3ba3777..0172fe5e 100644
--- a/v2rayN/v2rayN/Handler/UpdateHandle.cs
+++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs
@@ -35,51 +35,46 @@ namespace v2rayN.Handler
_updateFunc = update;
var url = string.Empty;
- DownloadHandle downloadHandle = null;
- if (downloadHandle == null)
+ DownloadHandle downloadHandle = new DownloadHandle();
+ downloadHandle.UpdateCompleted += (sender2, args) =>
{
- downloadHandle = new DownloadHandle();
-
- downloadHandle.UpdateCompleted += (sender2, args) =>
+ if (args.Success)
{
- 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));
- fileName = Utils.UrlEncode(fileName);
- Process process = new Process
+ StartInfo = new ProcessStartInfo
{
- StartInfo = new ProcessStartInfo
- {
- FileName = "v2rayUpgrade.exe",
- Arguments = $"\"{fileName}\"",
- WorkingDirectory = Utils.StartupPath()
- }
- };
- process.Start();
- if (process.Id > 0)
- {
- _updateFunc(true, "");
+ FileName = "v2rayUpgrade.exe",
+ Arguments = $"\"{fileName}\"",
+ WorkingDirectory = Utils.StartupPath()
}
- }
- 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) =>
{
if (args.Success)
@@ -106,36 +101,32 @@ namespace v2rayN.Handler
_updateFunc = update;
var url = string.Empty;
- DownloadHandle downloadHandle = null;
- if (downloadHandle == null)
+ DownloadHandle downloadHandle = new DownloadHandle();
+ downloadHandle.UpdateCompleted += (sender2, args) =>
{
- downloadHandle = new DownloadHandle();
- downloadHandle.UpdateCompleted += (sender2, args) =>
+ if (args.Success)
{
- if (args.Success)
- {
- _updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
- _updateFunc(false, ResUI.MsgUnpacking);
+ _updateFunc(false, ResUI.MsgDownloadV2rayCoreSuccessfully);
+ _updateFunc(false, ResUI.MsgUnpacking);
- try
- {
- _updateFunc(true, url);
- }
- catch (Exception ex)
- {
- _updateFunc(false, ex.Message);
- }
- }
- else
+ try
{
- _updateFunc(false, args.Msg);
+ _updateFunc(true, url);
}
- };
- downloadHandle.Error += (sender2, args) =>
+ catch (Exception ex)
+ {
+ _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) =>
{
@@ -226,7 +217,7 @@ namespace v2rayN.Handler
else
{
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
- if (result.Length < 99)
+ if (result!.Length < 99)
{
_updateFunc(false, $"{hashCode}{result}");
}
@@ -262,49 +253,44 @@ namespace v2rayN.Handler
_updateFunc = update;
var url = string.Format(Global.geoUrl, geoName);
- DownloadHandle downloadHandle = null;
- if (downloadHandle == null)
+ DownloadHandle downloadHandle = new DownloadHandle();
+ downloadHandle.UpdateCompleted += (sender2, args) =>
{
- downloadHandle = new DownloadHandle();
-
- downloadHandle.UpdateCompleted += (sender2, args) =>
+ if (args.Success)
{
- if (args.Success)
+ _updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
+
+ try
{
- _updateFunc(false, string.Format(ResUI.MsgDownloadGeoFileSuccessfully, geoName));
-
- try
+ string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
+ if (File.Exists(fileName))
{
- string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
- if (File.Exists(fileName))
- {
- //Global.coreTypes.ForEach(it =>
- //{
- // string targetPath = Utils.GetBinPath($"{geoName}.dat", (ECoreType)Enum.Parse(typeof(ECoreType), it));
- // File.Copy(fileName, targetPath, true);
- //});
- string targetPath = Utils.GetBinPath($"{geoName}.dat");
- File.Copy(fileName, targetPath, true);
+ //Global.coreTypes.ForEach(it =>
+ //{
+ // string targetPath = Utils.GetBinPath($"{geoName}.dat", (ECoreType)Enum.Parse(typeof(ECoreType), it));
+ // File.Copy(fileName, targetPath, true);
+ //});
+ string targetPath = Utils.GetBinPath($"{geoName}.dat");
+ File.Copy(fileName, targetPath, true);
- File.Delete(fileName);
- //_updateFunc(true, "");
- }
- }
- catch (Exception ex)
- {
- _updateFunc(false, ex.Message);
+ File.Delete(fileName);
+ //_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);
+ };
askToDownload(downloadHandle, url, false);
}
diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs
index 43359be6..6f4e5e69 100644
--- a/v2rayN/v2rayN/Tool/Utils.cs
+++ b/v2rayN/v2rayN/Tool/Utils.cs
@@ -48,7 +48,8 @@ namespace v2rayN
try
{
Assembly assembly = Assembly.GetExecutingAssembly();
- using Stream stream = assembly.GetManifestResourceStream(res);
+ using Stream? stream = assembly.GetManifestResourceStream(res);
+ ArgumentNullException.ThrowIfNull(stream);
using StreamReader reader = new(stream);
result = reader.ReadToEnd();
}
@@ -90,7 +91,7 @@ namespace v2rayN
///
///
///
- public static T FromJson(string strJson)
+ public static T? FromJson(string strJson)
{
try
{
@@ -98,8 +99,7 @@ namespace v2rayN
{
return default;
}
- T obj = JsonConvert.DeserializeObject(strJson);
- return obj;
+ return JsonConvert.DeserializeObject(strJson);
}
catch
{
@@ -112,7 +112,7 @@ namespace v2rayN
///
///
///
- public static string ToJson(object obj, bool indented = true)
+ public static string ToJson(object? obj, bool indented = true)
{
string result = string.Empty;
try
@@ -141,7 +141,7 @@ namespace v2rayN
///
///
///
- public static int ToJsonFile(object obj, string filePath, bool nullValue = true)
+ public static int ToJsonFile(object? obj, string filePath, bool nullValue = true)
{
int result;
try
@@ -168,7 +168,7 @@ namespace v2rayN
return result;
}
- public static JObject ParseJson(string strJson)
+ public static JObject? ParseJson(string strJson)
{
try
{
@@ -676,7 +676,7 @@ namespace v2rayN
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;
try
@@ -737,7 +737,7 @@ namespace v2rayN
public static bool CheckForDotNetVersion(int release = 528040)
{
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)
{
return (int)ndpKey.GetValue("Release") >= release ? true : false;
@@ -908,7 +908,7 @@ namespace v2rayN
/// 获取剪贴板数
///
///
- public static string GetClipboardData()
+ public static string? GetClipboardData()
{
string strData = string.Empty;
try
@@ -995,7 +995,7 @@ namespace v2rayN
return fileName;
}
- public static IPAddress GetDefaultGateway()
+ public static IPAddress? GetDefaultGateway()
{
return NetworkInterface
.GetAllNetworkInterfaces()
diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
index e8a687ad..9dd0ccb2 100644
--- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
+++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs
@@ -532,7 +532,7 @@ namespace v2rayN.ViewModels
{
_noticeHandler?.SendMessage(msg);
}
- private async void UpdateTaskHandler(bool success, string msg)
+ private void UpdateTaskHandler(bool success, string msg)
{
_noticeHandler?.SendMessage(msg);
if (success)