性能优化

pull/3305/head
小仙女 2023-02-17 15:17:01 +08:00
parent fc137f9b1c
commit a23cb95a10
4 changed files with 15 additions and 22 deletions

View File

@ -6,13 +6,9 @@ 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)
{
if (string.IsNullOrEmpty(url))
@ -44,7 +40,6 @@ namespace v2rayN.Base
}
};
string text = string.Empty;
using var downloader = new DownloadService(downloadOpt);
downloader.DownloadFileCompleted += (sender, value) =>
{
@ -55,11 +50,10 @@ namespace v2rayN.Base
};
using var stream = await downloader.DownloadFileTaskAsync(address: url, cancellationToken: cancellationToken.Token);
using StreamReader reader = new(stream);
text = reader.ReadToEnd();
downloadOpt = null;
return text;
return reader.ReadToEnd();
}
@ -132,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))
{

View File

@ -268,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)
@ -626,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)
{

View File

@ -10,8 +10,7 @@ namespace v2rayN.Tool
{
try
{
using FileStream fs = new(fileName, FileMode.Create, FileAccess.Write);
fs.Write(content);
File.WriteAllBytes(fileName, content);
return true;
}
catch (Exception ex)
@ -51,7 +50,7 @@ namespace v2rayN.Tool
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
throw ex;
throw;
}
}
public static bool ZipExtractToFile(string fileName, string toPath, string ignoredName)

View File

@ -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
@ -200,11 +200,11 @@ namespace v2rayN
}
if (wrap)
{
return string.Join("," + Environment.NewLine, lst.ToArray());
return string.Join("," + Environment.NewLine, lst);
}
else
{
return string.Join(",", lst.ToArray());
return string.Join(",", lst);
}
}
catch (Exception ex)
@ -223,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)
{
@ -242,8 +242,9 @@ namespace v2rayN
try
{
str = str.Replace(Environment.NewLine, "");
List<string> list = new(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)
{