mirror of https://github.com/2dust/v2rayN
性能优化
parent
fc137f9b1c
commit
a23cb95a10
|
@ -6,13 +6,9 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
internal class DownloaderHelper
|
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 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))
|
if (string.IsNullOrEmpty(url))
|
||||||
|
@ -44,7 +40,6 @@ namespace v2rayN.Base
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
string text = string.Empty;
|
|
||||||
using var downloader = new DownloadService(downloadOpt);
|
using var downloader = new DownloadService(downloadOpt);
|
||||||
downloader.DownloadFileCompleted += (sender, value) =>
|
downloader.DownloadFileCompleted += (sender, value) =>
|
||||||
{
|
{
|
||||||
|
@ -55,11 +50,10 @@ namespace v2rayN.Base
|
||||||
};
|
};
|
||||||
using var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
|
using var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
|
||||||
using StreamReader reader = new(stream);
|
using StreamReader reader = new(stream);
|
||||||
text = reader.ReadToEnd();
|
|
||||||
|
|
||||||
downloadOpt = null;
|
downloadOpt = null;
|
||||||
|
|
||||||
return text;
|
return reader.ReadToEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,11 +126,11 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(url))
|
if (string.IsNullOrEmpty(url))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("url");
|
throw new ArgumentNullException(nameof(url));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("fileName");
|
throw new ArgumentNullException(nameof(fileName));
|
||||||
}
|
}
|
||||||
if (File.Exists(fileName))
|
if (File.Exists(fileName))
|
||||||
{
|
{
|
||||||
|
|
|
@ -268,7 +268,6 @@ namespace v2rayN.Handler
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 从剪贴板导入URL
|
/// 从剪贴板导入URL
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileName"></param>
|
|
||||||
/// <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)
|
||||||
|
@ -626,7 +625,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})$");
|
@"^(?<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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -10,8 +10,7 @@ namespace v2rayN.Tool
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using FileStream fs = new(fileName, FileMode.Create, FileAccess.Write);
|
File.WriteAllBytes(fileName, content);
|
||||||
fs.Write(content);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -51,7 +50,7 @@ namespace v2rayN.Tool
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Utils.SaveLog(ex.Message, ex);
|
Utils.SaveLog(ex.Message, ex);
|
||||||
throw ex;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static bool ZipExtractToFile(string fileName, string toPath, string ignoredName)
|
public static bool ZipExtractToFile(string fileName, string toPath, string ignoredName)
|
||||||
|
|
|
@ -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
|
||||||
|
@ -200,11 +200,11 @@ namespace v2rayN
|
||||||
}
|
}
|
||||||
if (wrap)
|
if (wrap)
|
||||||
{
|
{
|
||||||
return string.Join("," + Environment.NewLine, lst.ToArray());
|
return string.Join("," + Environment.NewLine, lst);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return string.Join(",", lst.ToArray());
|
return string.Join(",", lst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -223,7 +223,7 @@ namespace v2rayN
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
str = str.Replace(Environment.NewLine, "");
|
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)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -242,8 +242,9 @@ namespace v2rayN
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
str = str.Replace(Environment.NewLine, "");
|
str = str.Replace(Environment.NewLine, "");
|
||||||
List<string> list = new(str.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries));
|
List<string> list = new(str.Split(',', StringSplitOptions.RemoveEmptyEntries));
|
||||||
return list.OrderBy(x => x).ToList();
|
list.Sort();
|
||||||
|
return list;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue