mirror of https://github.com/2dust/v2rayN
commit
b0bee3ca1a
|
@ -6,14 +6,10 @@ namespace v2rayN.Base
|
|||
{
|
||||
internal class DownloaderHelper
|
||||
{
|
||||
private static readonly Lazy<DownloaderHelper> _instance = new Lazy<DownloaderHelper>(() => new());
|
||||
private static readonly Lazy<DownloaderHelper> _instance = new(() => new());
|
||||
public static DownloaderHelper Instance => _instance.Value;
|
||||
|
||||
public DownloaderHelper()
|
||||
{
|
||||
}
|
||||
|
||||
public async Task<string> DownloadStringAsync(IWebProxy webProxy, string url, string? userAgent, int timeout)
|
||||
public async Task<string?> DownloadStringAsync(IWebProxy webProxy, string url, string? userAgent, int timeout)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
|
@ -23,7 +19,7 @@ namespace v2rayN.Base
|
|||
var cancellationToken = new CancellationTokenSource();
|
||||
cancellationToken.CancelAfter(timeout * 1000);
|
||||
|
||||
Uri uri = new Uri(url);
|
||||
Uri uri = new(url);
|
||||
//Authorization Header
|
||||
var headers = new WebHeaderCollection();
|
||||
if (!Utils.IsNullOrEmpty(uri.UserInfo))
|
||||
|
@ -44,9 +40,7 @@ namespace v2rayN.Base
|
|||
}
|
||||
};
|
||||
|
||||
string text = string.Empty;
|
||||
using (var downloader = new DownloadService(downloadOpt))
|
||||
{
|
||||
using var downloader = new DownloadService(downloadOpt);
|
||||
downloader.DownloadFileCompleted += (sender, value) =>
|
||||
{
|
||||
if (value.Error != null)
|
||||
|
@ -54,18 +48,12 @@ namespace v2rayN.Base
|
|||
throw new Exception(string.Format("{0}", value.Error.Message));
|
||||
}
|
||||
};
|
||||
using (var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token))
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
text = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
using var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
downloadOpt = null;
|
||||
|
||||
return text;
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
|
||||
|
@ -73,7 +61,7 @@ namespace v2rayN.Base
|
|||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException("url");
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
|
||||
var cancellationToken = new CancellationTokenSource();
|
||||
|
@ -94,8 +82,7 @@ namespace v2rayN.Base
|
|||
int totalSecond = 0;
|
||||
var hasValue = false;
|
||||
double maxSpeed = 0;
|
||||
using (var downloader = new DownloadService(downloadOpt))
|
||||
{
|
||||
using var downloader = new DownloadService(downloadOpt);
|
||||
//downloader.DownloadStarted += (sender, value) =>
|
||||
//{
|
||||
// if (progress != null)
|
||||
|
@ -131,7 +118,6 @@ namespace v2rayN.Base
|
|||
progress.Report("......");
|
||||
|
||||
await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
|
||||
}
|
||||
|
||||
downloadOpt = null;
|
||||
}
|
||||
|
@ -140,11 +126,11 @@ namespace v2rayN.Base
|
|||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException("url");
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
throw new ArgumentNullException("fileName");
|
||||
throw new ArgumentNullException(nameof(fileName));
|
||||
}
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
|
@ -167,14 +153,10 @@ namespace v2rayN.Base
|
|||
|
||||
var progressPercentage = 0;
|
||||
var hasValue = false;
|
||||
using (var downloader = new DownloadService(downloadOpt))
|
||||
{
|
||||
using var downloader = new DownloadService(downloadOpt);
|
||||
downloader.DownloadStarted += (sender, value) =>
|
||||
{
|
||||
if (progress != null)
|
||||
{
|
||||
progress.Report(0);
|
||||
}
|
||||
progress?.Report(0);
|
||||
};
|
||||
downloader.DownloadProgressChanged += (sender, value) =>
|
||||
{
|
||||
|
@ -198,7 +180,6 @@ namespace v2rayN.Base
|
|||
};
|
||||
|
||||
await downloader.DownloadFileTaskAsync(url, fileName, cancellationToken: cancellationToken.Token);
|
||||
}
|
||||
|
||||
downloadOpt = null;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace v2rayN.Base
|
|||
return httpClientHelper;
|
||||
}
|
||||
}
|
||||
public async Task<string> GetAsync(string url)
|
||||
public async Task<string?> GetAsync(string url)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
|
@ -43,7 +43,7 @@ namespace v2rayN.Base
|
|||
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
public async Task<string> GetAsync(HttpClient client, string url, CancellationToken token)
|
||||
public async Task<string?> GetAsync(HttpClient client, string url, CancellationToken token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ namespace v2rayN.Base
|
|||
{
|
||||
throw new Exception(string.Format("{0}", response.StatusCode));
|
||||
}
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
return await response.Content.ReadAsStringAsync(token);
|
||||
}
|
||||
|
||||
public async Task PutAsync(string url, Dictionary<string, string> headers)
|
||||
|
@ -92,10 +92,8 @@ namespace v2rayN.Base
|
|||
var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
|
||||
var canReportProgress = total != -1 && progress != null;
|
||||
|
||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
{
|
||||
using (var file = File.Create(fileName))
|
||||
{
|
||||
using var stream = await response.Content.ReadAsStreamAsync();
|
||||
using var file = File.Create(fileName);
|
||||
var totalRead = 0L;
|
||||
var buffer = new byte[1024 * 1024];
|
||||
var isMoreToRead = true;
|
||||
|
@ -132,21 +130,18 @@ namespace v2rayN.Base
|
|||
}
|
||||
}
|
||||
} while (isMoreToRead);
|
||||
file.Close();
|
||||
if (canReportProgress)
|
||||
{
|
||||
progress.Report(101);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress<string> progress, CancellationToken token)
|
||||
{
|
||||
if (string.IsNullOrEmpty(url))
|
||||
{
|
||||
throw new ArgumentNullException("url");
|
||||
throw new ArgumentNullException(nameof(url));
|
||||
}
|
||||
|
||||
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
|
||||
|
@ -159,8 +154,7 @@ namespace v2rayN.Base
|
|||
//var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
|
||||
//var canReportProgress = total != -1 && progress != null;
|
||||
|
||||
using (var stream = await response.Content.ReadAsStreamAsync())
|
||||
{
|
||||
using var stream = await response.Content.ReadAsStreamAsync(token);
|
||||
var totalRead = 0L;
|
||||
var buffer = new byte[1024 * 64];
|
||||
var isMoreToRead = true;
|
||||
|
@ -210,7 +204,6 @@ namespace v2rayN.Base
|
|||
}
|
||||
} while (isMoreToRead);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace v2rayN.Base
|
|||
|
||||
public static IEnumerable<string> NonWhiteSpaceLines(this TextReader reader)
|
||||
{
|
||||
string line;
|
||||
string? line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
if (line.IsWhiteSpace()) continue;
|
||||
|
|
|
@ -1021,7 +1021,17 @@ namespace v2rayN.Handler
|
|||
return -1;
|
||||
}
|
||||
|
||||
ProfileItem profileItem = new ProfileItem();
|
||||
//判断str是否包含s的任意一个字符串
|
||||
static bool Containss(string str, params string[] s)
|
||||
{
|
||||
foreach (var item in s)
|
||||
{
|
||||
if (str.Contains(item, StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ProfileItem profileItem = new();
|
||||
//Is v2ray configuration
|
||||
V2rayConfig v2rayConfig = Utils.FromJson<V2rayConfig>(clipboardData);
|
||||
if (v2rayConfig != null
|
||||
|
@ -1038,9 +1048,7 @@ namespace v2rayN.Handler
|
|||
profileItem.remarks = "v2ray_custom";
|
||||
}
|
||||
//Is Clash configuration
|
||||
else if (clipboardData.IndexOf("port") >= 0
|
||||
&& clipboardData.IndexOf("socks-port") >= 0
|
||||
&& clipboardData.IndexOf("proxies") >= 0)
|
||||
else if (Containss(clipboardData, "port", "socks-port", "proxies"))
|
||||
{
|
||||
var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.yaml");
|
||||
File.WriteAllText(fileName, clipboardData);
|
||||
|
@ -1050,12 +1058,7 @@ namespace v2rayN.Handler
|
|||
profileItem.remarks = "clash_custom";
|
||||
}
|
||||
//Is hysteria configuration
|
||||
else if (clipboardData.IndexOf("server") >= 0
|
||||
&& clipboardData.IndexOf("up") >= 0
|
||||
&& clipboardData.IndexOf("down") >= 0
|
||||
&& clipboardData.IndexOf("listen") >= 0
|
||||
&& clipboardData.IndexOf("<html>") < 0
|
||||
&& clipboardData.IndexOf("<body>") < 0)
|
||||
else if (Containss(clipboardData, "server", "up", "down", "listen", "<html>", "<body>"))
|
||||
{
|
||||
var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.json");
|
||||
File.WriteAllText(fileName, clipboardData);
|
||||
|
@ -1065,10 +1068,7 @@ namespace v2rayN.Handler
|
|||
profileItem.remarks = "hysteria_custom";
|
||||
}
|
||||
//Is naiveproxy configuration
|
||||
else if (clipboardData.IndexOf("listen") >= 0
|
||||
&& clipboardData.IndexOf("proxy") >= 0
|
||||
&& clipboardData.IndexOf("<html>") < 0
|
||||
&& clipboardData.IndexOf("<body>") < 0)
|
||||
else if (Containss(clipboardData, "listen", "proxy", "<html>", "<body>"))
|
||||
{
|
||||
var fileName = Utils.GetTempPath($"{Utils.GetGUID(false)}.json");
|
||||
File.WriteAllText(fileName, clipboardData);
|
||||
|
|
|
@ -189,24 +189,21 @@ namespace v2rayN.Handler
|
|||
//判断是否使用代理
|
||||
public static bool UsedProxy()
|
||||
{
|
||||
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")
|
||||
{
|
||||
rk.Close();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
rk.Close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
//获得代理的IP和端口
|
||||
public static string GetProxyProxyServer()
|
||||
{
|
||||
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();
|
||||
rk.Close();
|
||||
return ProxyServer;
|
||||
|
||||
}
|
||||
|
|
|
@ -21,28 +21,18 @@ namespace v2rayN.Handler
|
|||
{
|
||||
try
|
||||
{
|
||||
string url = string.Empty;
|
||||
string? url = string.Empty;
|
||||
|
||||
switch (item.configType)
|
||||
url = item.configType switch
|
||||
{
|
||||
case EConfigType.VMess:
|
||||
url = ShareVmess(item);
|
||||
break;
|
||||
case EConfigType.Shadowsocks:
|
||||
url = ShareShadowsocks(item);
|
||||
break;
|
||||
case EConfigType.Socks:
|
||||
url = ShareSocks(item);
|
||||
break;
|
||||
case EConfigType.Trojan:
|
||||
url = ShareTrojan(item);
|
||||
break;
|
||||
case EConfigType.VLESS:
|
||||
url = ShareVLESS(item);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
EConfigType.VMess => ShareVmess(item),
|
||||
EConfigType.Shadowsocks => ShareShadowsocks(item),
|
||||
EConfigType.Socks => ShareSocks(item),
|
||||
EConfigType.Trojan => ShareTrojan(item),
|
||||
EConfigType.VLESS => ShareVLESS(item),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
return url;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -278,7 +268,6 @@ namespace v2rayN.Handler
|
|||
/// <summary>
|
||||
/// 从剪贴板导入URL
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="msg"></param>
|
||||
/// <returns></returns>
|
||||
public static ProfileItem ImportFromClipboardConfig(string clipboardData, out string msg)
|
||||
|
@ -636,7 +625,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})$");
|
||||
@"^(?<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)
|
||||
{
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
<value>配置格式不正确</value>
|
||||
</data>
|
||||
<data name="CustomServerTips" xml:space="preserve">
|
||||
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手工修改监听端口。</value>
|
||||
<value>注意,自定义配置完全依赖您自己的配置,不能使用所有设置功能。如需使用系统代理请手动修改监听端口。</value>
|
||||
</data>
|
||||
<data name="Downloading" xml:space="preserve">
|
||||
<value>下载开始...</value>
|
||||
|
@ -148,7 +148,7 @@
|
|||
<value>生成默认配置文件失败</value>
|
||||
</data>
|
||||
<data name="FailedGetDefaultConfiguration" xml:space="preserve">
|
||||
<value>取得默认配置失败</value>
|
||||
<value>获取默认配置失败</value>
|
||||
</data>
|
||||
<data name="FailedImportedCustomServer" xml:space="preserve">
|
||||
<value>导入自定义配置服务器失败</value>
|
||||
|
|
|
@ -10,8 +10,7 @@ namespace v2rayN.Tool
|
|||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write))
|
||||
fs.Write(content, 0, content.Length);
|
||||
File.WriteAllBytes(fileName, content);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -25,20 +24,9 @@ namespace v2rayN.Tool
|
|||
{
|
||||
try
|
||||
{
|
||||
// Because the uncompressed size of the file is unknown,
|
||||
// we are using an arbitrary buffer size.
|
||||
byte[] buffer = new byte[4096];
|
||||
int n;
|
||||
|
||||
using (FileStream fs = File.Create(fileName))
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(content),
|
||||
CompressionMode.Decompress, false))
|
||||
{
|
||||
while ((n = input.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
fs.Write(buffer, 0, n);
|
||||
}
|
||||
}
|
||||
using FileStream fs = File.Create(fileName);
|
||||
using GZipStream input = new(new MemoryStream(content), CompressionMode.Decompress, false);
|
||||
input.CopyTo(fs);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -55,24 +43,21 @@ namespace v2rayN.Tool
|
|||
{
|
||||
try
|
||||
{
|
||||
using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||
using (StreamReader sr = new StreamReader(fs, encoding))
|
||||
{
|
||||
using FileStream fs = new(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
using StreamReader sr = new(fs, encoding);
|
||||
return sr.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
throw ex;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public static bool ZipExtractToFile(string fileName, string toPath, string ignoredName)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (ZipArchive archive = ZipFile.OpenRead(fileName))
|
||||
{
|
||||
using ZipArchive archive = ZipFile.OpenRead(fileName);
|
||||
foreach (ZipArchiveEntry entry in archive.Entries)
|
||||
{
|
||||
if (entry.Length == 0)
|
||||
|
@ -93,7 +78,6 @@ namespace v2rayN.Tool
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
|
|
|
@ -48,12 +48,10 @@ namespace v2rayN
|
|||
try
|
||||
{
|
||||
Assembly assembly = Assembly.GetExecutingAssembly();
|
||||
using (Stream stream = assembly.GetManifestResourceStream(res))
|
||||
using (StreamReader reader = new StreamReader(stream))
|
||||
{
|
||||
using Stream stream = assembly.GetManifestResourceStream(res);
|
||||
using StreamReader reader = new(stream);
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveLog(ex.Message, ex);
|
||||
|
@ -76,11 +74,9 @@ namespace v2rayN
|
|||
{
|
||||
return result;
|
||||
}
|
||||
using (StreamReader reader = new StreamReader(res))
|
||||
{
|
||||
using StreamReader reader = new(res);
|
||||
result = reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveLog(ex.Message, ex);
|
||||
|
@ -116,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
|
||||
|
@ -145,13 +141,12 @@ 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
|
||||
{
|
||||
using (StreamWriter file = File.CreateText(filePath))
|
||||
{
|
||||
using StreamWriter file = File.CreateText(filePath);
|
||||
JsonSerializer serializer;
|
||||
if (nullValue)
|
||||
{
|
||||
|
@ -163,7 +158,6 @@ namespace v2rayN
|
|||
}
|
||||
|
||||
serializer.Serialize(file, obj);
|
||||
}
|
||||
result = 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -206,7 +200,7 @@ namespace v2rayN
|
|||
}
|
||||
if (wrap)
|
||||
{
|
||||
return string.Join("," + Environment.NewLine, lst.ToArray());
|
||||
return string.Join("," + Environment.NewLine, lst);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -229,7 +223,7 @@ namespace v2rayN
|
|||
try
|
||||
{
|
||||
str = str.Replace(Environment.NewLine, "");
|
||||
return new List<string>(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
|
||||
return new List<string>(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -248,8 +242,9 @@ namespace v2rayN
|
|||
try
|
||||
{
|
||||
str = str.Replace(Environment.NewLine, "");
|
||||
List<string> list = new List<string>(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
|
||||
return list.OrderBy(x => x).ToList();
|
||||
List<string> list = new(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||
list.Sort();
|
||||
return list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -341,7 +336,7 @@ namespace v2rayN
|
|||
{
|
||||
try
|
||||
{
|
||||
return (obj == null ? string.Empty : obj.ToString());
|
||||
return obj?.ToString() ?? string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -418,10 +413,9 @@ namespace v2rayN
|
|||
|
||||
public static string GetMD5(string str)
|
||||
{
|
||||
var md5 = MD5.Create();
|
||||
byte[] byteOld = Encoding.UTF8.GetBytes(str);
|
||||
byte[] byteNew = md5.ComputeHash(byteOld);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
byte[] byteNew = MD5.HashData(byteOld);
|
||||
StringBuilder sb = new(32);
|
||||
foreach (byte b in byteNew)
|
||||
{
|
||||
sb.Append(b.ToString("x2"));
|
||||
|
@ -444,7 +438,7 @@ namespace v2rayN
|
|||
}
|
||||
try
|
||||
{
|
||||
Uri uri = new Uri(url);
|
||||
Uri uri = new(url);
|
||||
if (uri.Host == uri.IdnHost)
|
||||
{
|
||||
return url;
|
||||
|
@ -572,18 +566,14 @@ namespace v2rayN
|
|||
|
||||
public static bool IsIpv6(string ip)
|
||||
{
|
||||
IPAddress address;
|
||||
if (IPAddress.TryParse(ip, out address))
|
||||
if (IPAddress.TryParse(ip, out IPAddress? address))
|
||||
{
|
||||
switch (address.AddressFamily)
|
||||
return address.AddressFamily switch
|
||||
{
|
||||
case AddressFamily.InterNetwork:
|
||||
return false;
|
||||
case AddressFamily.InterNetworkV6:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
AddressFamily.InterNetwork => false,
|
||||
AddressFamily.InterNetworkV6 => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -688,11 +678,11 @@ namespace v2rayN
|
|||
|
||||
public static string RegReadValue(string path, string name, string def)
|
||||
{
|
||||
RegistryKey regKey = null;
|
||||
RegistryKey? regKey = null;
|
||||
try
|
||||
{
|
||||
regKey = Registry.CurrentUser.OpenSubKey(path, false);
|
||||
string value = regKey?.GetValue(name) as string;
|
||||
string? value = regKey?.GetValue(name) as string;
|
||||
if (IsNullOrEmpty(value))
|
||||
{
|
||||
return def;
|
||||
|
@ -715,7 +705,7 @@ namespace v2rayN
|
|||
|
||||
public static void RegWriteValue(string path, string name, object value)
|
||||
{
|
||||
RegistryKey regKey = null;
|
||||
RegistryKey? regKey = null;
|
||||
try
|
||||
{
|
||||
regKey = Registry.CurrentUser.CreateSubKey(path);
|
||||
|
@ -747,15 +737,13 @@ 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;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Auto Start via TaskService
|
||||
|
@ -775,8 +763,7 @@ namespace v2rayN
|
|||
string taskDescription = description;
|
||||
string deamonFileName = fileName;
|
||||
|
||||
using (var taskService = new TaskService())
|
||||
{
|
||||
using var taskService = new TaskService();
|
||||
var tasks = taskService.RootFolder.GetTasks(new Regex(TaskName));
|
||||
foreach (var t in tasks)
|
||||
{
|
||||
|
@ -800,7 +787,6 @@ namespace v2rayN
|
|||
|
||||
taskService.RootFolder.RegisterTaskDefinition(TaskName, task);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -908,16 +894,13 @@ namespace v2rayN
|
|||
public static T DeepCopy<T>(T obj)
|
||||
{
|
||||
object retval;
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
BinaryFormatter bf = new BinaryFormatter();
|
||||
//序列化成流
|
||||
bf.Serialize(ms, obj);
|
||||
ms.Seek(0, SeekOrigin.Begin);
|
||||
//反序列化成对象
|
||||
retval = bf.Deserialize(ms);
|
||||
ms.Close();
|
||||
}
|
||||
return (T)retval;
|
||||
}
|
||||
|
||||
|
@ -1075,14 +1058,11 @@ namespace v2rayN
|
|||
|
||||
public static string UnGzip(byte[] buf)
|
||||
{
|
||||
MemoryStream sb = new MemoryStream();
|
||||
using (GZipStream input = new GZipStream(new MemoryStream(buf),
|
||||
CompressionMode.Decompress,
|
||||
false))
|
||||
{
|
||||
using MemoryStream sb = new();
|
||||
using GZipStream input = new(new MemoryStream(buf), CompressionMode.Decompress, false);
|
||||
input.CopyTo(sb);
|
||||
}
|
||||
return Encoding.UTF8.GetString(sb.ToArray());
|
||||
sb.Position = 0;
|
||||
return new StreamReader(sb, Encoding.UTF8).ReadToEnd();
|
||||
}
|
||||
|
||||
public static string GetBackupPath(string filename)
|
||||
|
@ -1198,9 +1178,8 @@ namespace v2rayN
|
|||
{
|
||||
foreach (Screen screen in Screen.AllScreens)
|
||||
{
|
||||
using (Bitmap fullImage = new Bitmap(screen.Bounds.Width,
|
||||
screen.Bounds.Height))
|
||||
{
|
||||
using Bitmap fullImage = new Bitmap(screen.Bounds.Width,
|
||||
screen.Bounds.Height);
|
||||
using (Graphics g = Graphics.FromImage(fullImage))
|
||||
{
|
||||
g.CopyFromScreen(screen.Bounds.X,
|
||||
|
@ -1237,7 +1216,6 @@ namespace v2rayN
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SaveLog(ex.Message, ex);
|
||||
|
|
Loading…
Reference in New Issue