改为可空类型

pull/3309/head
小仙女 2023-02-19 12:18:08 +08:00
parent d44f311ba1
commit b84bad4e1a
15 changed files with 161 additions and 177 deletions

View File

@ -205,7 +205,7 @@ namespace v2rayN.Handler
}
LazyConfig.Instance.SetConfig(ref config);
LazyConfig.Instance.SetConfig(config);
return 0;
}
/// <summary>
@ -438,7 +438,7 @@ namespace v2rayN.Handler
/// <param name="config"></param>
/// <param name="item"></param>
/// <returns></returns>
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<V2rayConfig>(clipboardData);
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(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<ProfileItem> lstOriSub = null;
List<ProfileItem>? lstOriSub = null;
if (isSub && !Utils.IsNullOrEmpty(subid))
{
lstOriSub = LazyConfig.Instance.ProfileItems(subid);

View File

@ -25,7 +25,7 @@ namespace v2rayN.Handler
/// <param name="msg"></param>
/// <param name="content"></param>
/// <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;
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>();
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<V2rayConfig>(result);
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(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<V2rayConfig>(result);
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(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<V2rayConfig>(result);
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(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<V2rayConfig>(result);
V2rayConfig? v2rayConfig = Utils.FromJson<V2rayConfig>(result);
if (v2rayConfig == null)
{
msg = ResUI.FailedGenDefaultConfiguration;
@ -1523,7 +1523,7 @@ namespace v2rayN.Handler
v2rayConfig.inbounds.Add(inbound);
//outbound
V2rayConfig v2rayConfigCopy = Utils.FromJson<V2rayConfig>(result);
V2rayConfig? v2rayConfigCopy = Utils.FromJson<V2rayConfig>(result);
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
if (item is null)
{

View File

@ -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<bool, string> _updateFunc;
public CoreHandler(Action<bool, string> 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);

View File

@ -16,7 +16,7 @@ namespace v2rayN.Handler
{
public event EventHandler<ResultEventArgs> UpdateCompleted;
public event ErrorEventHandler Error;
public event ErrorEventHandler? Error;
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);
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<string> TryDownloadString(string url, bool blProxy, string userAgent)
public async Task<string?> 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
/// </summary>
/// <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
{
@ -234,7 +232,7 @@ namespace v2rayN.Handler
/// DownloadString
/// </summary>
/// <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
{
@ -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);

View File

@ -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<ProfileItemModel>(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<CoreInfo> GetCoreInfos()
public List<CoreInfo>? GetCoreInfos()
{
if (coreInfos == null)
{

View File

@ -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;
}

View File

@ -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;

View File

@ -9,7 +9,7 @@ namespace v2rayN.Handler
/// </summary>
public class QRCodeHelper
{
public static DrawingImage GetQRCode(string strContent)
public static DrawingImage? GetQRCode(string strContent)
{
try
{

View File

@ -17,7 +17,7 @@ namespace v2rayN.Handler
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
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<string, string> dicQuery)
private static int GetStdTransport(ProfileItem item, string? securityDef, ref Dictionary<string, string> dicQuery)
{
if (!Utils.IsNullOrEmpty(item.flow))
{
@ -270,7 +270,7 @@ namespace v2rayN.Handler
/// </summary>
/// <param name="msg"></param>
/// <returns></returns>
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<VmessQRCode>(result);
VmessQRCode? vmessQRCode = Utils.FromJson<VmessQRCode>(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://(?<base64>[A-Za-z0-9+-/=_]+)(?:#(?<tag>\S+))?", RegexOptions.IgnoreCase);
private static readonly Regex DetailsParser = new Regex(@"^((?<method>.+?):(?<password>.*)@(?<hostname>.+?):(?<port>\d+?))$", 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 | 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(
@"^(?<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
{
@ -675,7 +675,7 @@ namespace v2rayN.Handler
return profileItem;
}
private static ProfileItem ResolveSocksNew(string result)
private static ProfileItem? ResolveSocksNew(string result)
{
Uri parsedUrl;
try

View File

@ -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<ServerStatItem> _lstServerStat;
public List<ServerStatItem> 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 });

View File

@ -20,7 +20,7 @@ namespace v2rayN.Handler
// <proxy-server><CR-LF>
// <bypass-list><CR-LF>
// <pac-url>
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) =>
{

View File

@ -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;

View File

@ -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);
}

View File

@ -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
/// <typeparam name="T"></typeparam>
/// <param name="strJson"></param>
/// <returns></returns>
public static T FromJson<T>(string strJson)
public static T? FromJson<T>(string strJson)
{
try
{
@ -98,8 +99,7 @@ namespace v2rayN
{
return default;
}
T obj = JsonConvert.DeserializeObject<T>(strJson);
return obj;
return JsonConvert.DeserializeObject<T>(strJson);
}
catch
{
@ -112,7 +112,7 @@ namespace v2rayN
/// </summary>
/// <param name="obj"></param>
/// <returns></returns>
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
/// <param name="obj"></param>
/// <param name="filePath"></param>
/// <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;
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
/// 获取剪贴板数
/// </summary>
/// <returns></returns>
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()

View File

@ -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)