mirror of https://github.com/2dust/v2rayN
简化代码
parent
b84bad4e1a
commit
6a89be2e89
|
@ -26,9 +26,9 @@ namespace v2rayN.Base
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
HttpClientHelper httpClientHelper = new HttpClientHelper();
|
HttpClientHelper httpClientHelper = new();
|
||||||
|
|
||||||
HttpClientHandler handler = new HttpClientHandler() { UseCookies = false };
|
HttpClientHandler handler = new() { UseCookies = false };
|
||||||
httpClientHelper.httpClient = new HttpClient(handler);
|
httpClientHelper.httpClient = new HttpClient(handler);
|
||||||
return httpClientHelper;
|
return httpClientHelper;
|
||||||
}
|
}
|
||||||
|
@ -71,11 +71,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))
|
||||||
{
|
{
|
||||||
|
@ -89,10 +89,10 @@ namespace v2rayN.Base
|
||||||
throw new Exception(string.Format("{0}", response.StatusCode));
|
throw new Exception(string.Format("{0}", response.StatusCode));
|
||||||
}
|
}
|
||||||
|
|
||||||
var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
|
var total = response.Content.Headers.ContentLength ?? -1L;
|
||||||
var canReportProgress = total != -1 && progress != null;
|
var canReportProgress = total != -1 && progress != null;
|
||||||
|
|
||||||
using var stream = await response.Content.ReadAsStreamAsync();
|
using var stream = await response.Content.ReadAsStreamAsync(token);
|
||||||
using var file = File.Create(fileName);
|
using var file = File.Create(fileName);
|
||||||
var totalRead = 0L;
|
var totalRead = 0L;
|
||||||
var buffer = new byte[1024 * 1024];
|
var buffer = new byte[1024 * 1024];
|
||||||
|
@ -103,7 +103,7 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
token.ThrowIfCancellationRequested();
|
token.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
|
var read = await stream.ReadAsync(buffer, token);
|
||||||
|
|
||||||
if (read == 0)
|
if (read == 0)
|
||||||
{
|
{
|
||||||
|
@ -176,7 +176,7 @@ namespace v2rayN.Base
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
|
var read = await stream.ReadAsync(buffer, token);
|
||||||
|
|
||||||
if (read == 0)
|
if (read == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
public sealed class SqliteHelper
|
public sealed class SqliteHelper
|
||||||
{
|
{
|
||||||
private static readonly Lazy<SqliteHelper> _instance = new Lazy<SqliteHelper>(() => new());
|
private static readonly Lazy<SqliteHelper> _instance = new(() => new());
|
||||||
public static SqliteHelper Instance => _instance.Value;
|
public static SqliteHelper Instance => _instance.Value;
|
||||||
private string _connstr;
|
private string _connstr;
|
||||||
public SQLiteConnection _db;
|
public SQLiteConnection _db;
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace v2rayN.Converters
|
||||||
return new SolidColorBrush(Colors.IndianRed);
|
return new SolidColorBrush(Colors.IndianRed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
public object? ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,7 @@ namespace v2rayN.Converters
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
if (MyFont is null)
|
MyFont ??= new FontFamily("Microsoft YaHei");
|
||||||
{
|
|
||||||
MyFont = new FontFamily("Microsoft YaHei");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -80,26 +80,26 @@
|
||||||
public const string SpeedUnit = "";
|
public const string SpeedUnit = "";
|
||||||
public const int MinFontSize = 10;
|
public const int MinFontSize = 10;
|
||||||
|
|
||||||
public static readonly List<string> IEProxyProtocols = new List<string> {
|
public static readonly List<string> IEProxyProtocols = new() {
|
||||||
"{ip}:{http_port}",
|
"{ip}:{http_port}",
|
||||||
"socks={ip}:{socks_port}",
|
"socks={ip}:{socks_port}",
|
||||||
"http={ip}:{http_port};https={ip}:{http_port};ftp={ip}:{http_port};socks={ip}:{socks_port}",
|
"http={ip}:{http_port};https={ip}:{http_port};ftp={ip}:{http_port};socks={ip}:{socks_port}",
|
||||||
"http=http://{ip}:{http_port};https=http://{ip}:{http_port}",
|
"http=http://{ip}:{http_port};https=http://{ip}:{http_port}",
|
||||||
""
|
""
|
||||||
};
|
};
|
||||||
public static readonly List<string> vmessSecuritys = new List<string> { "aes-128-gcm", "chacha20-poly1305", "auto", "none", "zero" };
|
public static readonly List<string> vmessSecuritys = new() { "aes-128-gcm", "chacha20-poly1305", "auto", "none", "zero" };
|
||||||
public static readonly List<string> ssSecuritys = new List<string> { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "none", "plain" };
|
public static readonly List<string> ssSecuritys = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "none", "plain" };
|
||||||
public static readonly List<string> ssSecuritysInSagerNet = new List<string> { "none", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "rc4", "rc4-md5", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-cfb8", "aes-192-cfb8", "aes-256-cfb8", "aes-128-ofb", "aes-192-ofb", "aes-256-ofb", "bf-cfb", "cast5-cfb", "des-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "camellia-128-cfb8", "camellia-192-cfb8", "camellia-256-cfb8", "salsa20", "chacha20", "chacha20-ietf", "xchacha20" };
|
public static readonly List<string> ssSecuritysInSagerNet = new() { "none", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "rc4", "rc4-md5", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "aes-128-cfb8", "aes-192-cfb8", "aes-256-cfb8", "aes-128-ofb", "aes-192-ofb", "aes-256-ofb", "bf-cfb", "cast5-cfb", "des-cfb", "idea-cfb", "rc2-cfb", "seed-cfb", "camellia-128-cfb", "camellia-192-cfb", "camellia-256-cfb", "camellia-128-cfb8", "camellia-192-cfb8", "camellia-256-cfb8", "salsa20", "chacha20", "chacha20-ietf", "xchacha20" };
|
||||||
public static readonly List<string> ssSecuritysInXray = new List<string> { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "xchacha20-poly1305", "xchacha20-ietf-poly1305", "none", "plain", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305" };
|
public static readonly List<string> ssSecuritysInXray = new() { "aes-256-gcm", "aes-128-gcm", "chacha20-poly1305", "chacha20-ietf-poly1305", "xchacha20-poly1305", "xchacha20-ietf-poly1305", "none", "plain", "2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305" };
|
||||||
public static readonly List<string> xtlsFlows = new List<string> { "", "xtls-rprx-origin", "xtls-rprx-origin-udp443", "xtls-rprx-direct", "xtls-rprx-direct-udp443", "xtls-rprx-vision", "xtls-rprx-vision-udp443" };
|
public static readonly List<string> xtlsFlows = new() { "", "xtls-rprx-origin", "xtls-rprx-origin-udp443", "xtls-rprx-direct", "xtls-rprx-direct-udp443", "xtls-rprx-vision", "xtls-rprx-vision-udp443" };
|
||||||
public static readonly List<string> networks = new List<string> { "tcp", "kcp", "ws", "h2", "quic", "grpc" };
|
public static readonly List<string> networks = new() { "tcp", "kcp", "ws", "h2", "quic", "grpc" };
|
||||||
public static readonly List<string> kcpHeaderTypes = new List<string> { "srtp", "utp", "wechat-video", "dtls", "wireguard" };
|
public static readonly List<string> kcpHeaderTypes = new() { "srtp", "utp", "wechat-video", "dtls", "wireguard" };
|
||||||
public static readonly List<string> coreTypes = new List<string> { "v2fly", "SagerNet", "Xray", "v2fly_v5" };
|
public static readonly List<string> coreTypes = new() { "v2fly", "SagerNet", "Xray", "v2fly_v5" };
|
||||||
public static readonly List<string> domainStrategys = new List<string> { "AsIs", "IPIfNonMatch", "IPOnDemand" };
|
public static readonly List<string> domainStrategys = new() { "AsIs", "IPIfNonMatch", "IPOnDemand" };
|
||||||
public static readonly List<string> domainMatchers = new List<string> { "linear", "mph", "" };
|
public static readonly List<string> domainMatchers = new() { "linear", "mph", "" };
|
||||||
public static readonly List<string> fingerprints = new List<string> { "chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random", "randomized", "" };
|
public static readonly List<string> fingerprints = new() { "chrome", "firefox", "safari", "ios", "android", "edge", "360", "qq", "random", "randomized", "" };
|
||||||
public static readonly List<string> userAgent = new List<string> { "chrome", "firefox", "safari", "edge", "none" };
|
public static readonly List<string> userAgent = new() { "chrome", "firefox", "safari", "edge", "none" };
|
||||||
public static readonly Dictionary<string, string> userAgentTxt = new Dictionary<string, string>
|
public static readonly Dictionary<string, string> userAgentTxt = new()
|
||||||
{
|
{
|
||||||
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },
|
{"chrome","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" },
|
||||||
{"firefox","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0" },
|
{"firefox","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0" },
|
||||||
|
@ -107,17 +107,17 @@
|
||||||
{"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" },
|
{"edge","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70" },
|
||||||
{"none",""}
|
{"none",""}
|
||||||
};
|
};
|
||||||
public static readonly List<string> allowInsecures = new List<string> { "true", "false", "" };
|
public static readonly List<string> allowInsecures = new() { "true", "false", "" };
|
||||||
public static readonly List<string> domainStrategy4Freedoms = new List<string> { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" };
|
public static readonly List<string> domainStrategy4Freedoms = new() { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" };
|
||||||
public static readonly List<string> Languages = new List<string> { "zh-Hans", "en", "fa-Ir", "ru" };
|
public static readonly List<string> Languages = new() { "zh-Hans", "en", "fa-Ir", "ru" };
|
||||||
public static readonly List<string> alpns = new List<string> { "h2", "http/1.1", "h2,http/1.1", "" };
|
public static readonly List<string> alpns = new() { "h2", "http/1.1", "h2,http/1.1", "" };
|
||||||
public static readonly List<string> LogLevel = new List<string> { "debug", "info", "warning", "error", "none" };
|
public static readonly List<string> LogLevel = new() { "debug", "info", "warning", "error", "none" };
|
||||||
public static readonly List<string> InboundTags = new List<string> { "socks", "http", "socks2", "http2" };
|
public static readonly List<string> InboundTags = new() { "socks", "http", "socks2", "http2" };
|
||||||
public static readonly List<string> Protocols = new List<string> { "http", "tls", "bittorrent" };
|
public static readonly List<string> Protocols = new() { "http", "tls", "bittorrent" };
|
||||||
public static readonly List<string> TunMtus = new List<string> { "9000", "1500" };
|
public static readonly List<string> TunMtus = new() { "9000", "1500" };
|
||||||
public static readonly List<string> TunStacks = new List<string> { "gvisor", "system" };
|
public static readonly List<string> TunStacks = new() { "gvisor", "system" };
|
||||||
public static readonly List<string> PresetMsgFilters = new List<string> { "proxy", "direct", "block", "" };
|
public static readonly List<string> PresetMsgFilters = new() { "proxy", "direct", "block", "" };
|
||||||
public static readonly List<string> SpeedTestUrls = new List<string> { @"http://cachefly.cachefly.net/100mb.test", @"http://cachefly.cachefly.net/10mb.test" };
|
public static readonly List<string> SpeedTestUrls = new() { @"http://cachefly.cachefly.net/100mb.test", @"http://cachefly.cachefly.net/10mb.test" };
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ namespace v2rayN.Handler
|
||||||
class ConfigHandler
|
class ConfigHandler
|
||||||
{
|
{
|
||||||
private static string configRes = Global.ConfigFileName;
|
private static string configRes = Global.ConfigFileName;
|
||||||
private static readonly object objLock = new object();
|
private static readonly object objLock = new();
|
||||||
|
|
||||||
#region ConfigHandler
|
#region ConfigHandler
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ namespace v2rayN.Handler
|
||||||
if (config.inbound == null)
|
if (config.inbound == null)
|
||||||
{
|
{
|
||||||
config.inbound = new List<InItem>();
|
config.inbound = new List<InItem>();
|
||||||
InItem inItem = new InItem
|
InItem inItem = new()
|
||||||
{
|
{
|
||||||
protocol = Global.InboundSocks,
|
protocol = Global.InboundSocks,
|
||||||
localPort = 10808,
|
localPort = 10808,
|
||||||
|
@ -190,7 +190,7 @@ namespace v2rayN.Handler
|
||||||
config.speedTestItem.speedPingTestUrl = Global.SpeedPingTestUrl;
|
config.speedTestItem.speedPingTestUrl = Global.SpeedPingTestUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.guiItem.statisticsFreshRate > 100 || config.guiItem.statisticsFreshRate < 1)
|
if (config.guiItem.statisticsFreshRate is > 100 or < 1)
|
||||||
{
|
{
|
||||||
config.guiItem.statisticsFreshRate = 1;
|
config.guiItem.statisticsFreshRate = 1;
|
||||||
}
|
}
|
||||||
|
@ -548,7 +548,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
sort = ProfileExHandler.Instance.GetSort(lstProfile[lstProfile.Count - 1].indexId) + 1;
|
sort = ProfileExHandler.Instance.GetSort(lstProfile[^1].indexId) + 1;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -810,7 +810,7 @@ namespace v2rayN.Handler
|
||||||
List<ProfileItem> source = lstProfile;
|
List<ProfileItem> source = lstProfile;
|
||||||
bool keepOlder = config.guiItem.keepOlderDedupl;
|
bool keepOlder = config.guiItem.keepOlderDedupl;
|
||||||
|
|
||||||
List<ProfileItem> list = new List<ProfileItem>();
|
List<ProfileItem> list = new();
|
||||||
if (!keepOlder) source.Reverse(); // Remove the early items first
|
if (!keepOlder) source.Reverse(); // Remove the early items first
|
||||||
|
|
||||||
foreach (ProfileItem item in source)
|
foreach (ProfileItem item in source)
|
||||||
|
@ -1221,7 +1221,7 @@ namespace v2rayN.Handler
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SubItem subItem = new SubItem
|
SubItem subItem = new()
|
||||||
{
|
{
|
||||||
id = string.Empty,
|
id = string.Empty,
|
||||||
remarks = "import_sub",
|
remarks = "import_sub",
|
||||||
|
|
|
@ -90,8 +90,8 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
var dtNow = DateTime.Now;
|
var dtNow = DateTime.Now;
|
||||||
v2rayConfig.log.loglevel = config.coreBasicItem.loglevel;
|
v2rayConfig.log.loglevel = config.coreBasicItem.loglevel;
|
||||||
v2rayConfig.log.access = Utils.GetLogPath($"Vaccess_{dtNow.ToString("yyyy-MM-dd")}.txt");
|
v2rayConfig.log.access = Utils.GetLogPath($"Vaccess_{dtNow:yyyy-MM-dd}.txt");
|
||||||
v2rayConfig.log.error = Utils.GetLogPath($"Verror_{dtNow.ToString("yyyy-MM-dd")}.txt");
|
v2rayConfig.log.error = Utils.GetLogPath($"Verror_{dtNow:yyyy-MM-dd}.txt");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -405,7 +405,7 @@ namespace v2rayN.Handler
|
||||||
if (!Utils.IsNullOrEmpty(node.security)
|
if (!Utils.IsNullOrEmpty(node.security)
|
||||||
&& !Utils.IsNullOrEmpty(node.id))
|
&& !Utils.IsNullOrEmpty(node.id))
|
||||||
{
|
{
|
||||||
SocksUsersItem socksUsersItem = new SocksUsersItem
|
SocksUsersItem socksUsersItem = new()
|
||||||
{
|
{
|
||||||
user = node.security,
|
user = node.security,
|
||||||
pass = node.id,
|
pass = node.id,
|
||||||
|
@ -565,7 +565,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
streamSettings.security = node.streamSecurity;
|
streamSettings.security = node.streamSecurity;
|
||||||
|
|
||||||
TlsSettings tlsSettings = new TlsSettings
|
TlsSettings tlsSettings = new()
|
||||||
{
|
{
|
||||||
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
|
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
|
||||||
alpn = node.GetAlpn(),
|
alpn = node.GetAlpn(),
|
||||||
|
@ -587,7 +587,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
streamSettings.security = node.streamSecurity;
|
streamSettings.security = node.streamSecurity;
|
||||||
|
|
||||||
TlsSettings xtlsSettings = new TlsSettings
|
TlsSettings xtlsSettings = new()
|
||||||
{
|
{
|
||||||
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
|
allowInsecure = Utils.ToBool(node.allowInsecure.IsNullOrEmpty() ? config.coreBasicItem.defAllowInsecure.ToString().ToLower() : node.allowInsecure),
|
||||||
alpn = node.GetAlpn(),
|
alpn = node.GetAlpn(),
|
||||||
|
@ -608,7 +608,7 @@ namespace v2rayN.Handler
|
||||||
switch (node.GetNetwork())
|
switch (node.GetNetwork())
|
||||||
{
|
{
|
||||||
case "kcp":
|
case "kcp":
|
||||||
KcpSettings kcpSettings = new KcpSettings
|
KcpSettings kcpSettings = new()
|
||||||
{
|
{
|
||||||
mtu = config.kcpItem.mtu,
|
mtu = config.kcpItem.mtu,
|
||||||
tti = config.kcpItem.tti
|
tti = config.kcpItem.tti
|
||||||
|
@ -644,12 +644,8 @@ namespace v2rayN.Handler
|
||||||
break;
|
break;
|
||||||
//ws
|
//ws
|
||||||
case "ws":
|
case "ws":
|
||||||
WsSettings wsSettings = new WsSettings
|
WsSettings wsSettings = new();
|
||||||
{
|
wsSettings.headers = new Headers();
|
||||||
};
|
|
||||||
wsSettings.headers = new Headers
|
|
||||||
{
|
|
||||||
};
|
|
||||||
string path = node.path;
|
string path = node.path;
|
||||||
if (!string.IsNullOrWhiteSpace(host))
|
if (!string.IsNullOrWhiteSpace(host))
|
||||||
{
|
{
|
||||||
|
@ -675,7 +671,7 @@ namespace v2rayN.Handler
|
||||||
break;
|
break;
|
||||||
//h2
|
//h2
|
||||||
case "h2":
|
case "h2":
|
||||||
HttpSettings httpSettings = new HttpSettings();
|
HttpSettings httpSettings = new();
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(host))
|
if (!string.IsNullOrWhiteSpace(host))
|
||||||
{
|
{
|
||||||
|
@ -691,7 +687,7 @@ namespace v2rayN.Handler
|
||||||
break;
|
break;
|
||||||
//quic
|
//quic
|
||||||
case "quic":
|
case "quic":
|
||||||
QuicSettings quicsettings = new QuicSettings
|
QuicSettings quicsettings = new()
|
||||||
{
|
{
|
||||||
security = host,
|
security = host,
|
||||||
key = node.path,
|
key = node.path,
|
||||||
|
@ -714,7 +710,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "grpc":
|
case "grpc":
|
||||||
var grpcSettings = new GrpcSettings
|
GrpcSettings grpcSettings = new()
|
||||||
{
|
{
|
||||||
serviceName = node.path,
|
serviceName = node.path,
|
||||||
multiMode = (node.headerType == Global.GrpcmultiMode),
|
multiMode = (node.headerType == Global.GrpcmultiMode),
|
||||||
|
@ -730,7 +726,7 @@ namespace v2rayN.Handler
|
||||||
//tcp
|
//tcp
|
||||||
if (node.headerType.Equals(Global.TcpHeaderHttp))
|
if (node.headerType.Equals(Global.TcpHeaderHttp))
|
||||||
{
|
{
|
||||||
TcpSettings tcpSettings = new TcpSettings
|
TcpSettings tcpSettings = new()
|
||||||
{
|
{
|
||||||
header = new Header
|
header = new Header
|
||||||
{
|
{
|
||||||
|
@ -799,7 +795,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
List<string> servers = new List<string>();
|
List<string> servers = new();
|
||||||
|
|
||||||
string[] arrDNS = config.remoteDNS.Split(',');
|
string[] arrDNS = config.remoteDNS.Split(',');
|
||||||
foreach (string str in arrDNS)
|
foreach (string str in arrDNS)
|
||||||
|
@ -828,9 +824,9 @@ namespace v2rayN.Handler
|
||||||
if (config.guiItem.enableStatistics)
|
if (config.guiItem.enableStatistics)
|
||||||
{
|
{
|
||||||
string tag = Global.InboundAPITagName;
|
string tag = Global.InboundAPITagName;
|
||||||
API apiObj = new API();
|
API apiObj = new();
|
||||||
Policy policyObj = new Policy();
|
Policy policyObj = new();
|
||||||
SystemPolicy policySystemSetting = new SystemPolicy();
|
SystemPolicy policySystemSetting = new();
|
||||||
|
|
||||||
string[] services = { "StatsService" };
|
string[] services = { "StatsService" };
|
||||||
|
|
||||||
|
@ -847,8 +843,8 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
if (!v2rayConfig.inbounds.Exists(item => item.tag == tag))
|
if (!v2rayConfig.inbounds.Exists(item => item.tag == tag))
|
||||||
{
|
{
|
||||||
Inbounds apiInbound = new Inbounds();
|
Inbounds apiInbound = new();
|
||||||
Inboundsettings apiInboundSettings = new Inboundsettings();
|
Inboundsettings apiInboundSettings = new();
|
||||||
apiInbound.tag = tag;
|
apiInbound.tag = tag;
|
||||||
apiInbound.listen = Global.Loopback;
|
apiInbound.listen = Global.Loopback;
|
||||||
apiInbound.port = Global.statePort;
|
apiInbound.port = Global.statePort;
|
||||||
|
@ -860,7 +856,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
if (!v2rayConfig.routing.rules.Exists(item => item.outboundTag == tag))
|
if (!v2rayConfig.routing.rules.Exists(item => item.outboundTag == tag))
|
||||||
{
|
{
|
||||||
RulesItem apiRoutingRule = new RulesItem
|
RulesItem apiRoutingRule = new()
|
||||||
{
|
{
|
||||||
inboundTag = new List<string> { tag },
|
inboundTag = new List<string> { tag },
|
||||||
outboundTag = tag,
|
outboundTag = tag,
|
||||||
|
@ -1126,7 +1122,7 @@ namespace v2rayN.Handler
|
||||||
public static ProfileItem? ImportFromClientConfig(string fileName, out string msg)
|
public static ProfileItem? ImportFromClientConfig(string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = string.Empty;
|
||||||
ProfileItem profileItem = new ProfileItem();
|
ProfileItem profileItem = new();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1265,7 +1261,7 @@ namespace v2rayN.Handler
|
||||||
public static ProfileItem? ImportFromServerConfig(string fileName, out string msg)
|
public static ProfileItem? ImportFromServerConfig(string fileName, out string msg)
|
||||||
{
|
{
|
||||||
msg = string.Empty;
|
msg = string.Empty;
|
||||||
ProfileItem profileItem = new ProfileItem();
|
ProfileItem profileItem = new();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1446,8 +1442,8 @@ namespace v2rayN.Handler
|
||||||
msg = ResUI.FailedGenDefaultConfiguration;
|
msg = ResUI.FailedGenDefaultConfiguration;
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
List<IPEndPoint> lstIpEndPoints = new List<IPEndPoint>();
|
List<IPEndPoint> lstIpEndPoints = new();
|
||||||
List<TcpConnectionInformation> lstTcpConns = new List<TcpConnectionInformation>();
|
List<TcpConnectionInformation> lstTcpConns = new();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
lstIpEndPoints.AddRange(IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners());
|
||||||
|
@ -1477,7 +1473,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (it.configType == EConfigType.VMess || it.configType == EConfigType.VLESS)
|
if (it.configType is EConfigType.VMess or EConfigType.VLESS)
|
||||||
{
|
{
|
||||||
var item2 = LazyConfig.Instance.GetProfileItem(it.indexId);
|
var item2 = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||||
if (item2 is null || Utils.IsNullOrEmpty(item2.id) || !Utils.IsGuidByParse(item2.id))
|
if (item2 is null || Utils.IsNullOrEmpty(item2.id) || !Utils.IsGuidByParse(item2.id))
|
||||||
|
@ -1513,7 +1509,7 @@ namespace v2rayN.Handler
|
||||||
it.allowTest = true;
|
it.allowTest = true;
|
||||||
|
|
||||||
//inbound
|
//inbound
|
||||||
Inbounds inbound = new Inbounds
|
Inbounds inbound = new()
|
||||||
{
|
{
|
||||||
listen = Global.Loopback,
|
listen = Global.Loopback,
|
||||||
port = port,
|
port = port,
|
||||||
|
@ -1540,7 +1536,7 @@ namespace v2rayN.Handler
|
||||||
v2rayConfig.outbounds.Add(v2rayConfigCopy.outbounds[0]);
|
v2rayConfig.outbounds.Add(v2rayConfigCopy.outbounds[0]);
|
||||||
|
|
||||||
//rule
|
//rule
|
||||||
RulesItem rule = new RulesItem
|
RulesItem rule = new()
|
||||||
{
|
{
|
||||||
inboundTag = new List<string> { inbound.tag },
|
inboundTag = new List<string> { inbound.tag },
|
||||||
outboundTag = v2rayConfigCopy.outbounds[0].tag,
|
outboundTag = v2rayConfigCopy.outbounds[0].tag,
|
||||||
|
|
|
@ -173,8 +173,8 @@ namespace v2rayN.Handler
|
||||||
string fileName = CoreFindexe(_coreInfo);
|
string fileName = CoreFindexe(_coreInfo);
|
||||||
if (fileName == "") return;
|
if (fileName == "") return;
|
||||||
|
|
||||||
var displayLog = node.configType == EConfigType.Custom ? node.displayLog : true;
|
var displayLog = node.configType != EConfigType.Custom || node.displayLog;
|
||||||
Process p = new Process
|
Process p = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
|
@ -232,7 +232,7 @@ namespace v2rayN.Handler
|
||||||
string fileName = CoreFindexe(coreInfo);
|
string fileName = CoreFindexe(coreInfo);
|
||||||
if (fileName == "") return -1;
|
if (fileName == "") return -1;
|
||||||
|
|
||||||
Process p = new Process
|
Process p = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,7 +76,7 @@ namespace v2rayN.Handler
|
||||||
if (UpdateCompleted != null)
|
if (UpdateCompleted != null)
|
||||||
{
|
{
|
||||||
string msg = $"...{value}%";
|
string msg = $"...{value}%";
|
||||||
UpdateCompleted(this, new ResultEventArgs(value > 100 ? true : false, msg));
|
UpdateCompleted(this, new ResultEventArgs(value > 100, msg));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ namespace v2rayN.Handler
|
||||||
AllowAutoRedirect = false,
|
AllowAutoRedirect = false,
|
||||||
Proxy = GetWebProxy(blProxy)
|
Proxy = GetWebProxy(blProxy)
|
||||||
};
|
};
|
||||||
HttpClient client = new HttpClient(webRequestHandler);
|
HttpClient client = new(webRequestHandler);
|
||||||
|
|
||||||
HttpResponseMessage response = await client.GetAsync(url);
|
HttpResponseMessage response = await client.GetAsync(url);
|
||||||
if (response.StatusCode.ToString() == "Redirect")
|
if (response.StatusCode.ToString() == "Redirect")
|
||||||
|
@ -203,7 +203,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
client.DefaultRequestHeaders.UserAgent.TryParseAdd(userAgent);
|
client.DefaultRequestHeaders.UserAgent.TryParseAdd(userAgent);
|
||||||
|
|
||||||
Uri uri = new Uri(url);
|
Uri uri = new(url);
|
||||||
//Authorization Header
|
//Authorization Header
|
||||||
if (!Utils.IsNullOrEmpty(uri.UserInfo))
|
if (!Utils.IsNullOrEmpty(uri.UserInfo))
|
||||||
{
|
{
|
||||||
|
@ -300,12 +300,11 @@ namespace v2rayN.Handler
|
||||||
myHttpWebRequest.Timeout = downloadTimeout * 1000;
|
myHttpWebRequest.Timeout = downloadTimeout * 1000;
|
||||||
myHttpWebRequest.Proxy = webProxy;
|
myHttpWebRequest.Proxy = webProxy;
|
||||||
|
|
||||||
Stopwatch timer = new Stopwatch();
|
Stopwatch timer = new();
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
|
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
|
||||||
if (myHttpWebResponse.StatusCode != HttpStatusCode.OK
|
if (myHttpWebResponse.StatusCode is not HttpStatusCode.OK and not HttpStatusCode.NoContent)
|
||||||
&& myHttpWebResponse.StatusCode != HttpStatusCode.NoContent)
|
|
||||||
{
|
{
|
||||||
msg = myHttpWebResponse.StatusDescription;
|
msg = myHttpWebResponse.StatusDescription;
|
||||||
}
|
}
|
||||||
|
@ -343,7 +342,7 @@ namespace v2rayN.Handler
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IPAddress ipa = IPAddress.Parse(ip);
|
IPAddress ipa = IPAddress.Parse(ip);
|
||||||
IPEndPoint point = new IPEndPoint(ipa, port);
|
IPEndPoint point = new(ipa, port);
|
||||||
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||||
sock.Connect(point);
|
sock.Connect(point);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
public sealed class LazyConfig
|
public sealed class LazyConfig
|
||||||
{
|
{
|
||||||
private static readonly Lazy<LazyConfig> _instance = new Lazy<LazyConfig>(() => new());
|
private static readonly Lazy<LazyConfig> _instance = new(() => new());
|
||||||
private Config _config;
|
private Config _config;
|
||||||
private List<CoreInfo> coreInfos;
|
private List<CoreInfo> coreInfos;
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
private void InitCoreInfo()
|
private void InitCoreInfo()
|
||||||
{
|
{
|
||||||
coreInfos = new List<CoreInfo>();
|
coreInfos = new(16);
|
||||||
|
|
||||||
coreInfos.Add(new CoreInfo
|
coreInfos.Add(new CoreInfo
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,7 +12,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
public sealed class MainFormHandler
|
public sealed class MainFormHandler
|
||||||
{
|
{
|
||||||
private static readonly Lazy<MainFormHandler> instance = new Lazy<MainFormHandler>(() => new MainFormHandler());
|
private static readonly Lazy<MainFormHandler> instance = new(() => new());
|
||||||
//Action<bool, string> _updateUI;
|
//Action<bool, string> _updateUI;
|
||||||
|
|
||||||
//private DownloadHandle downloadHandle2;
|
//private DownloadHandle downloadHandle2;
|
||||||
|
@ -42,19 +42,14 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return new Icon(fileName);
|
return new Icon(fileName);
|
||||||
}
|
}
|
||||||
switch (index)
|
return index switch
|
||||||
{
|
{
|
||||||
case 0:
|
0 => Properties.Resources.NotifyIcon1,
|
||||||
return Properties.Resources.NotifyIcon1;
|
1 => Properties.Resources.NotifyIcon2,
|
||||||
case 1:
|
2 => Properties.Resources.NotifyIcon3,
|
||||||
return Properties.Resources.NotifyIcon2;
|
3 => Properties.Resources.NotifyIcon2,
|
||||||
case 2:
|
_ => Properties.Resources.NotifyIcon1, // default
|
||||||
return Properties.Resources.NotifyIcon3;
|
};
|
||||||
case 3:
|
|
||||||
return Properties.Resources.NotifyIcon2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Properties.Resources.NotifyIcon1;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -107,9 +102,9 @@ namespace v2rayN.Handler
|
||||||
int width = 128;
|
int width = 128;
|
||||||
int height = 128;
|
int height = 128;
|
||||||
|
|
||||||
Bitmap bitmap = new Bitmap(width, height);
|
Bitmap bitmap = new(width, height);
|
||||||
Graphics graphics = Graphics.FromImage(bitmap);
|
Graphics graphics = Graphics.FromImage(bitmap);
|
||||||
SolidBrush drawBrush = new SolidBrush(color);
|
SolidBrush drawBrush = new(color);
|
||||||
|
|
||||||
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
|
||||||
//graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
|
//graphics.FillRectangle(drawBrush, new Rectangle(0, 0, width, height));
|
||||||
|
@ -143,7 +138,7 @@ namespace v2rayN.Handler
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveFileDialog fileDialog = new SaveFileDialog
|
SaveFileDialog fileDialog = new()
|
||||||
{
|
{
|
||||||
Filter = "Config|*.json",
|
Filter = "Config|*.json",
|
||||||
FilterIndex = 2,
|
FilterIndex = 2,
|
||||||
|
@ -176,14 +171,13 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (item.configType != EConfigType.VMess
|
if (item.configType is not EConfigType.VMess and not EConfigType.VLESS)
|
||||||
&& item.configType != EConfigType.VLESS)
|
|
||||||
{
|
{
|
||||||
UI.Show(ResUI.NonVmessService);
|
UI.Show(ResUI.NonVmessService);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SaveFileDialog fileDialog = new SaveFileDialog
|
SaveFileDialog fileDialog = new()
|
||||||
{
|
{
|
||||||
Filter = "Config|*.json",
|
Filter = "Config|*.json",
|
||||||
FilterIndex = 2,
|
FilterIndex = 2,
|
||||||
|
@ -212,14 +206,14 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public void BackupGuiNConfig(Config config, bool auto = false)
|
public void BackupGuiNConfig(Config config, bool auto = false)
|
||||||
{
|
{
|
||||||
string fileName = $"guiNConfig_{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss_fff")}.json";
|
string fileName = $"guiNConfig_{DateTime.Now:yyyy_MM_dd_HH_mm_ss_fff}.json";
|
||||||
if (auto)
|
if (auto)
|
||||||
{
|
{
|
||||||
fileName = Utils.GetBackupPath(fileName);
|
fileName = Utils.GetBackupPath(fileName);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SaveFileDialog fileDialog = new SaveFileDialog
|
SaveFileDialog fileDialog = new()
|
||||||
{
|
{
|
||||||
FileName = fileName,
|
FileName = fileName,
|
||||||
Filter = "guiNConfig|*.json",
|
Filter = "guiNConfig|*.json",
|
||||||
|
@ -254,7 +248,7 @@ namespace v2rayN.Handler
|
||||||
public bool RestoreGuiNConfig(ref Config config)
|
public bool RestoreGuiNConfig(ref Config config)
|
||||||
{
|
{
|
||||||
var fileContent = string.Empty;
|
var fileContent = string.Empty;
|
||||||
using (OpenFileDialog fileDialog = new OpenFileDialog())
|
using (OpenFileDialog fileDialog = new())
|
||||||
{
|
{
|
||||||
fileDialog.InitialDirectory = Utils.GetBackupPath("");
|
fileDialog.InitialDirectory = Utils.GetBackupPath("");
|
||||||
fileDialog.Filter = "guiNConfig|*.json|All|*.*";
|
fileDialog.Filter = "guiNConfig|*.json|All|*.*";
|
||||||
|
@ -381,12 +375,12 @@ namespace v2rayN.Handler
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
HotkeyManager.Current.AddOrReplace(((int)item.eGlobalHotkey).ToString(), gesture, handler);
|
HotkeyManager.Current.AddOrReplace(((int)item.eGlobalHotkey).ToString(), gesture, handler);
|
||||||
var msg = string.Format(ResUI.RegisterGlobalHotkeySuccessfully, $"{item.eGlobalHotkey.ToString()}");
|
var msg = string.Format(ResUI.RegisterGlobalHotkeySuccessfully, $"{item.eGlobalHotkey}");
|
||||||
update(false, msg);
|
update(false, msg);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var msg = string.Format(ResUI.RegisterGlobalHotkeyFailed, $"{item.eGlobalHotkey.ToString()}", ex.Message);
|
var msg = string.Format(ResUI.RegisterGlobalHotkeyFailed, $"{item.eGlobalHotkey}", ex.Message);
|
||||||
update(false, msg);
|
update(false, msg);
|
||||||
Utils.SaveLog(msg);
|
Utils.SaveLog(msg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
class ProfileExHandler
|
class ProfileExHandler
|
||||||
{
|
{
|
||||||
private static readonly Lazy<ProfileExHandler> _instance = new Lazy<ProfileExHandler>(() => new());
|
private static readonly Lazy<ProfileExHandler> _instance = new(() => new());
|
||||||
private List<ProfileExItem> _lstProfileEx;
|
private List<ProfileExItem> _lstProfileEx;
|
||||||
public List<ProfileExItem> ProfileExs => _lstProfileEx;
|
public List<ProfileExItem> ProfileExs => _lstProfileEx;
|
||||||
public static ProfileExHandler Instance => _instance.Value;
|
public static ProfileExHandler Instance => _instance.Value;
|
||||||
|
|
|
@ -12,14 +12,14 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
public static bool SetProxy(string? strProxy, string? exceptions, int type)
|
public static bool SetProxy(string? strProxy, string? exceptions, int type)
|
||||||
{
|
{
|
||||||
InternetPerConnOptionList list = new InternetPerConnOptionList();
|
InternetPerConnOptionList list = new();
|
||||||
|
|
||||||
int optionCount = 1;
|
int optionCount = 1;
|
||||||
if (type == 1)
|
if (type == 1)
|
||||||
{
|
{
|
||||||
optionCount = 1;
|
optionCount = 1;
|
||||||
}
|
}
|
||||||
else if (type == 2 || type == 4)
|
else if (type is 2 or 4)
|
||||||
{
|
{
|
||||||
optionCount = Utils.IsNullOrEmpty(exceptions) ? 2 : 3;
|
optionCount = Utils.IsNullOrEmpty(exceptions) ? 2 : 3;
|
||||||
}
|
}
|
||||||
|
@ -71,12 +71,12 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
if (Environment.Is64BitOperatingSystem)
|
if (Environment.Is64BitOperatingSystem)
|
||||||
{
|
{
|
||||||
IntPtr opt = new IntPtr(optionsPtr.ToInt64() + (i * optSize));
|
IntPtr opt = new(optionsPtr.ToInt64() + (i * optSize));
|
||||||
Marshal.StructureToPtr(options[i], opt, false);
|
Marshal.StructureToPtr(options[i], opt, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
IntPtr opt = new IntPtr(optionsPtr.ToInt32() + (i * optSize));
|
IntPtr opt = new(optionsPtr.ToInt32() + (i * optSize));
|
||||||
Marshal.StructureToPtr(options[i], opt, false);
|
Marshal.StructureToPtr(options[i], opt, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ namespace v2rayN.Handler
|
||||||
list.options = optionsPtr;
|
list.options = optionsPtr;
|
||||||
|
|
||||||
// and then make a pointer out of the whole list
|
// and then make a pointer out of the whole list
|
||||||
IntPtr ipcoListPtr = Marshal.AllocCoTaskMem((int)list.dwSize);
|
IntPtr ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize);
|
||||||
Marshal.StructureToPtr(list, ipcoListPtr, false);
|
Marshal.StructureToPtr(list, ipcoListPtr, false);
|
||||||
|
|
||||||
// and finally, call the API method!
|
// and finally, call the API method!
|
||||||
|
@ -200,7 +200,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//获得代理的IP和端口
|
//获得代理的IP和端口
|
||||||
public static string GetProxyProxyServer()
|
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();
|
string ProxyServer = rk.GetValue("ProxyServer").ToString();
|
||||||
|
|
|
@ -13,9 +13,9 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
QRCodeGenerator qrGenerator = new();
|
||||||
QRCodeData qrCodeData = qrGenerator.CreateQrCode(strContent, QRCodeGenerator.ECCLevel.H);
|
QRCodeData qrCodeData = qrGenerator.CreateQrCode(strContent, QRCodeGenerator.ECCLevel.H);
|
||||||
XamlQRCode qrCode = new XamlQRCode(qrCodeData);
|
XamlQRCode qrCode = new(qrCodeData);
|
||||||
DrawingImage qrCodeAsXaml = qrCode.GetGraphic(40);
|
DrawingImage qrCodeAsXaml = qrCode.GetGraphic(40);
|
||||||
return qrCodeAsXaml;
|
return qrCodeAsXaml;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
string url = string.Empty;
|
string url = string.Empty;
|
||||||
|
|
||||||
VmessQRCode vmessQRCode = new VmessQRCode
|
VmessQRCode vmessQRCode = new()
|
||||||
{
|
{
|
||||||
v = item.configVersion.ToString(),
|
v = item.configVersion.ToString(),
|
||||||
ps = item.remarks.TrimEx(), //备注也许很长 ;
|
ps = item.remarks.TrimEx(), //备注也许很长 ;
|
||||||
|
@ -250,7 +250,7 @@ namespace v2rayN.Handler
|
||||||
if (!Utils.IsNullOrEmpty(item.path))
|
if (!Utils.IsNullOrEmpty(item.path))
|
||||||
{
|
{
|
||||||
dicQuery.Add("serviceName", Utils.UrlEncode(item.path));
|
dicQuery.Add("serviceName", Utils.UrlEncode(item.path));
|
||||||
if (item.headerType == Global.GrpcgunMode || item.headerType == Global.GrpcmultiMode)
|
if (item.headerType is Global.GrpcgunMode or Global.GrpcmultiMode)
|
||||||
{
|
{
|
||||||
dicQuery.Add("mode", Utils.UrlEncode(item.headerType));
|
dicQuery.Add("mode", Utils.UrlEncode(item.headerType));
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,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;
|
msg = string.Empty;
|
||||||
ProfileItem profileItem = new ProfileItem();
|
ProfileItem profileItem = new();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -365,7 +365,7 @@ namespace v2rayN.Handler
|
||||||
configType = EConfigType.VMess
|
configType = EConfigType.VMess
|
||||||
};
|
};
|
||||||
|
|
||||||
result = result.Substring(Global.vmessProtocol.Length);
|
result = result[Global.vmessProtocol.Length..];
|
||||||
result = Utils.Base64Decode(result);
|
result = Utils.Base64Decode(result);
|
||||||
|
|
||||||
//转成Json
|
//转成Json
|
||||||
|
@ -409,7 +409,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
private static ProfileItem? ResolveVmess4Kitsunebi(string result)
|
private static ProfileItem? ResolveVmess4Kitsunebi(string result)
|
||||||
{
|
{
|
||||||
ProfileItem profileItem = new ProfileItem
|
ProfileItem profileItem = new()
|
||||||
{
|
{
|
||||||
configType = EConfigType.VMess
|
configType = EConfigType.VMess
|
||||||
};
|
};
|
||||||
|
@ -428,7 +428,7 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
string[] arr21 = arr1[0].Split(':');
|
string[] arr21 = arr1[0].Split(':');
|
||||||
string[] arr22 = arr1[1].Split(':');
|
string[] arr22 = arr1[1].Split(':');
|
||||||
if (arr21.Length != 2 || arr21.Length != 2)
|
if (arr21.Length != 2 || arr22.Length != 2)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -447,13 +447,13 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
private static ProfileItem? ResolveStdVmess(string result)
|
private static ProfileItem? ResolveStdVmess(string result)
|
||||||
{
|
{
|
||||||
ProfileItem i = new ProfileItem
|
ProfileItem i = new()
|
||||||
{
|
{
|
||||||
configType = EConfigType.VMess,
|
configType = EConfigType.VMess,
|
||||||
security = "auto"
|
security = "auto"
|
||||||
};
|
};
|
||||||
|
|
||||||
Uri u = new Uri(result);
|
Uri u = new(result);
|
||||||
|
|
||||||
i.address = u.IdnHost;
|
i.address = u.IdnHost;
|
||||||
i.port = u.Port;
|
i.port = u.Port;
|
||||||
|
@ -537,7 +537,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ProfileItem server = new ProfileItem
|
ProfileItem server = new()
|
||||||
{
|
{
|
||||||
remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),
|
remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),
|
||||||
address = parsedUrl.IdnHost,
|
address = parsedUrl.IdnHost,
|
||||||
|
@ -589,8 +589,8 @@ namespace v2rayN.Handler
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static readonly Regex UrlFinder = new Regex(@"ss://(?<base64>[A-Za-z0-9+-/=_]+)(?:#(?<tag>\S+))?", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
private static readonly Regex UrlFinder = new(@"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 readonly Regex DetailsParser = new(@"^((?<method>.+?):(?<password>.*)@(?<hostname>.+?):(?<port>\d+?))$", RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||||
|
|
||||||
private static ProfileItem? ResolveSSLegacy(string result)
|
private static ProfileItem? ResolveSSLegacy(string result)
|
||||||
{
|
{
|
||||||
|
@ -598,7 +598,7 @@ namespace v2rayN.Handler
|
||||||
if (!match.Success)
|
if (!match.Success)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
ProfileItem server = new ProfileItem();
|
ProfileItem server = new();
|
||||||
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
var base64 = match.Groups["base64"].Value.TrimEnd('/');
|
||||||
var tag = match.Groups["tag"].Value;
|
var tag = match.Groups["tag"].Value;
|
||||||
if (!Utils.IsNullOrEmpty(tag))
|
if (!Utils.IsNullOrEmpty(tag))
|
||||||
|
@ -624,16 +624,16 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static readonly Regex StdVmessUserInfo = new Regex(
|
private static readonly Regex StdVmessUserInfo = new(
|
||||||
@"^(?<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);
|
@"^(?<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
|
ProfileItem profileItem = new()
|
||||||
{
|
{
|
||||||
configType = EConfigType.Socks
|
configType = EConfigType.Socks
|
||||||
};
|
};
|
||||||
result = result.Substring(Global.socksProtocol.Length);
|
result = result[Global.socksProtocol.Length..];
|
||||||
//remark
|
//remark
|
||||||
int indexRemark = result.IndexOf("#");
|
int indexRemark = result.IndexOf("#");
|
||||||
if (indexRemark > 0)
|
if (indexRemark > 0)
|
||||||
|
@ -643,7 +643,7 @@ namespace v2rayN.Handler
|
||||||
profileItem.remarks = Utils.UrlDecode(result.Substring(indexRemark + 1, result.Length - indexRemark - 1));
|
profileItem.remarks = Utils.UrlDecode(result.Substring(indexRemark + 1, result.Length - indexRemark - 1));
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
result = result.Substring(0, indexRemark);
|
result = result[..indexRemark];
|
||||||
}
|
}
|
||||||
//part decode
|
//part decode
|
||||||
int indexS = result.IndexOf("@");
|
int indexS = result.IndexOf("@");
|
||||||
|
@ -667,8 +667,8 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
profileItem.address = arr1[1].Substring(0, indexPort);
|
profileItem.address = arr1[1][..indexPort];
|
||||||
profileItem.port = Utils.ToInt(arr1[1].Substring(indexPort + 1, arr1[1].Length - (indexPort + 1)));
|
profileItem.port = Utils.ToInt(arr1[1][(indexPort + 1)..]);
|
||||||
profileItem.security = arr21[0];
|
profileItem.security = arr21[0];
|
||||||
profileItem.id = arr21[1];
|
profileItem.id = arr21[1];
|
||||||
|
|
||||||
|
@ -686,7 +686,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ProfileItem server = new ProfileItem
|
ProfileItem server = new()
|
||||||
{
|
{
|
||||||
remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),
|
remarks = parsedUrl.GetComponents(UriComponents.Fragment, UriFormat.Unescaped),
|
||||||
address = parsedUrl.IdnHost,
|
address = parsedUrl.IdnHost,
|
||||||
|
@ -708,12 +708,12 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
private static ProfileItem ResolveTrojan(string result)
|
private static ProfileItem ResolveTrojan(string result)
|
||||||
{
|
{
|
||||||
ProfileItem item = new ProfileItem
|
ProfileItem item = new()
|
||||||
{
|
{
|
||||||
configType = EConfigType.Trojan
|
configType = EConfigType.Trojan
|
||||||
};
|
};
|
||||||
|
|
||||||
Uri url = new Uri(result);
|
Uri url = new(result);
|
||||||
|
|
||||||
item.address = url.IdnHost;
|
item.address = url.IdnHost;
|
||||||
item.port = url.Port;
|
item.port = url.Port;
|
||||||
|
@ -727,13 +727,13 @@ namespace v2rayN.Handler
|
||||||
}
|
}
|
||||||
private static ProfileItem ResolveStdVLESS(string result)
|
private static ProfileItem ResolveStdVLESS(string result)
|
||||||
{
|
{
|
||||||
ProfileItem item = new ProfileItem
|
ProfileItem item = new()
|
||||||
{
|
{
|
||||||
configType = EConfigType.VLESS,
|
configType = EConfigType.VLESS,
|
||||||
security = "none"
|
security = "none"
|
||||||
};
|
};
|
||||||
|
|
||||||
Uri url = new Uri(result);
|
Uri url = new(result);
|
||||||
|
|
||||||
item.address = url.IdnHost;
|
item.address = url.IdnHost;
|
||||||
item.port = url.Port;
|
item.port = url.Port;
|
||||||
|
|
|
@ -150,7 +150,7 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new DownloadHandle();
|
||||||
//Thread.Sleep(5000);
|
//Thread.Sleep(5000);
|
||||||
List<Task> tasks = new List<Task>();
|
List<Task> tasks = new();
|
||||||
foreach (var it in _selecteds)
|
foreach (var it in _selecteds)
|
||||||
{
|
{
|
||||||
if (!it.allowTest)
|
if (!it.allowTest)
|
||||||
|
@ -166,7 +166,7 @@ namespace v2rayN.Handler
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
WebProxy webProxy = new WebProxy(Global.Loopback, it.port);
|
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||||
string output = GetRealPingTime(downloadHandle, webProxy);
|
string output = GetRealPingTime(downloadHandle, webProxy);
|
||||||
|
|
||||||
await ProfileExHandler.Instance.SetTestDelay(it.indexId, output);
|
await ProfileExHandler.Instance.SetTestDelay(it.indexId, output);
|
||||||
|
@ -214,7 +214,7 @@ namespace v2rayN.Handler
|
||||||
string url = _config.speedTestItem.speedTestUrl;
|
string url = _config.speedTestItem.speedTestUrl;
|
||||||
var timeout = _config.speedTestItem.speedTestTimeout;
|
var timeout = _config.speedTestItem.speedTestTimeout;
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new();
|
||||||
|
|
||||||
foreach (var it in _selecteds)
|
foreach (var it in _selecteds)
|
||||||
{
|
{
|
||||||
|
@ -236,7 +236,7 @@ namespace v2rayN.Handler
|
||||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||||
if (item is null) continue;
|
if (item is null) continue;
|
||||||
|
|
||||||
WebProxy webProxy = new WebProxy(Global.Loopback, it.port);
|
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||||
|
|
||||||
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>
|
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>
|
||||||
{
|
{
|
||||||
|
@ -270,7 +270,7 @@ namespace v2rayN.Handler
|
||||||
string url = _config.speedTestItem.speedTestUrl;
|
string url = _config.speedTestItem.speedTestUrl;
|
||||||
var timeout = _config.speedTestItem.speedTestTimeout;
|
var timeout = _config.speedTestItem.speedTestTimeout;
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new();
|
||||||
|
|
||||||
foreach (var it in _selecteds)
|
foreach (var it in _selecteds)
|
||||||
{
|
{
|
||||||
|
@ -287,7 +287,7 @@ namespace v2rayN.Handler
|
||||||
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
var item = LazyConfig.Instance.GetProfileItem(it.indexId);
|
||||||
if (item is null) continue;
|
if (item is null) continue;
|
||||||
|
|
||||||
WebProxy webProxy = new WebProxy(Global.Loopback, it.port);
|
WebProxy webProxy = new(Global.Loopback, it.port);
|
||||||
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>
|
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, async (bool success, string msg) =>
|
||||||
{
|
{
|
||||||
decimal.TryParse(msg, out decimal dec);
|
decimal.TryParse(msg, out decimal dec);
|
||||||
|
@ -338,11 +338,11 @@ namespace v2rayN.Handler
|
||||||
ipAddress = ipHostInfo.AddressList[0];
|
ipAddress = ipHostInfo.AddressList[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
Stopwatch timer = new Stopwatch();
|
Stopwatch timer = new();
|
||||||
timer.Start();
|
timer.Start();
|
||||||
|
|
||||||
IPEndPoint endPoint = new IPEndPoint(ipAddress, port);
|
IPEndPoint endPoint = new(ipAddress, port);
|
||||||
Socket clientSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
|
||||||
|
|
||||||
IAsyncResult result = clientSocket.BeginConnect(endPoint, null, null);
|
IAsyncResult result = clientSocket.BeginConnect(endPoint, null, null);
|
||||||
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
|
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
|
||||||
|
@ -351,7 +351,6 @@ namespace v2rayN.Handler
|
||||||
|
|
||||||
timer.Stop();
|
timer.Stop();
|
||||||
responseTime = timer.Elapsed.Milliseconds;
|
responseTime = timer.Elapsed.Milliseconds;
|
||||||
clientSocket.Close();
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -373,7 +372,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
int timeout = 30;
|
int timeout = 30;
|
||||||
int echoNum = 2;
|
int echoNum = 2;
|
||||||
Ping pingSender = new Ping();
|
using Ping pingSender = new();
|
||||||
for (int i = 0; i < echoNum; i++)
|
for (int i = 0; i < echoNum; i++)
|
||||||
{
|
{
|
||||||
PingReply reply = pingSender.Send(host, timeout);
|
PingReply reply = pingSender.Send(host, timeout);
|
||||||
|
|
|
@ -229,7 +229,7 @@ namespace v2rayN.Handler
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// TCP stack please do me a favor
|
// TCP stack please do me a favor
|
||||||
TcpListener l = new TcpListener(IPAddress.Loopback, 0);
|
TcpListener l = new(IPAddress.Loopback, 0);
|
||||||
l.Start();
|
l.Start();
|
||||||
int port = ((IPEndPoint)l.LocalEndpoint).Port;
|
int port = ((IPEndPoint)l.LocalEndpoint).Port;
|
||||||
l.Stop();
|
l.Stop();
|
||||||
|
|
|
@ -154,85 +154,82 @@ namespace v2rayN.Handler
|
||||||
// using event to avoid hanging when redirect standard output/error
|
// using event to avoid hanging when redirect standard output/error
|
||||||
// ref: https://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why
|
// ref: https://stackoverflow.com/questions/139593/processstartinfo-hanging-on-waitforexit-why
|
||||||
// and http://blog.csdn.net/zhangweixing0/article/details/7356841
|
// and http://blog.csdn.net/zhangweixing0/article/details/7356841
|
||||||
using (AutoResetEvent outputWaitHandle = new AutoResetEvent(false))
|
using AutoResetEvent outputWaitHandle = new(false);
|
||||||
using (AutoResetEvent errorWaitHandle = new AutoResetEvent(false))
|
using AutoResetEvent errorWaitHandle = new(false);
|
||||||
|
using Process process = new();
|
||||||
|
|
||||||
|
// Configure the process using the StartInfo properties.
|
||||||
|
process.StartInfo.FileName = Utils.GetTempPath("sysproxy.exe");
|
||||||
|
process.StartInfo.Arguments = arguments;
|
||||||
|
process.StartInfo.WorkingDirectory = Utils.GetTempPath();
|
||||||
|
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||||
|
process.StartInfo.UseShellExecute = false;
|
||||||
|
process.StartInfo.RedirectStandardError = true;
|
||||||
|
process.StartInfo.RedirectStandardOutput = true;
|
||||||
|
|
||||||
|
// Need to provide encoding info, or output/error strings we got will be wrong.
|
||||||
|
process.StartInfo.StandardOutputEncoding = Encoding.Unicode;
|
||||||
|
process.StartInfo.StandardErrorEncoding = Encoding.Unicode;
|
||||||
|
|
||||||
|
process.StartInfo.CreateNoWindow = true;
|
||||||
|
|
||||||
|
StringBuilder output = new(1024);
|
||||||
|
StringBuilder error = new(1024);
|
||||||
|
|
||||||
|
process.OutputDataReceived += (sender, e) =>
|
||||||
{
|
{
|
||||||
using (Process process = new Process())
|
if (e.Data == null)
|
||||||
{
|
{
|
||||||
// Configure the process using the StartInfo properties.
|
outputWaitHandle.Set();
|
||||||
process.StartInfo.FileName = Utils.GetTempPath("sysproxy.exe");
|
|
||||||
process.StartInfo.Arguments = arguments;
|
|
||||||
process.StartInfo.WorkingDirectory = Utils.GetTempPath();
|
|
||||||
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
|
||||||
process.StartInfo.UseShellExecute = false;
|
|
||||||
process.StartInfo.RedirectStandardError = true;
|
|
||||||
process.StartInfo.RedirectStandardOutput = true;
|
|
||||||
|
|
||||||
// Need to provide encoding info, or output/error strings we got will be wrong.
|
|
||||||
process.StartInfo.StandardOutputEncoding = Encoding.Unicode;
|
|
||||||
process.StartInfo.StandardErrorEncoding = Encoding.Unicode;
|
|
||||||
|
|
||||||
process.StartInfo.CreateNoWindow = true;
|
|
||||||
|
|
||||||
StringBuilder output = new StringBuilder(1024);
|
|
||||||
StringBuilder error = new StringBuilder(1024);
|
|
||||||
|
|
||||||
process.OutputDataReceived += (sender, e) =>
|
|
||||||
{
|
|
||||||
if (e.Data == null)
|
|
||||||
{
|
|
||||||
outputWaitHandle.Set();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
output.AppendLine(e.Data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
process.ErrorDataReceived += (sender, e) =>
|
|
||||||
{
|
|
||||||
if (e.Data == null)
|
|
||||||
{
|
|
||||||
errorWaitHandle.Set();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
error.AppendLine(e.Data);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
try
|
|
||||||
{
|
|
||||||
process.Start();
|
|
||||||
|
|
||||||
process.BeginErrorReadLine();
|
|
||||||
process.BeginOutputReadLine();
|
|
||||||
|
|
||||||
process.WaitForExit();
|
|
||||||
}
|
|
||||||
catch (System.ComponentModel.Win32Exception e)
|
|
||||||
{
|
|
||||||
|
|
||||||
// log the arguments
|
|
||||||
throw new Exception(process.StartInfo.Arguments);
|
|
||||||
}
|
|
||||||
string stderr = error.ToString();
|
|
||||||
string stdout = output.ToString();
|
|
||||||
|
|
||||||
int exitCode = process.ExitCode;
|
|
||||||
if (exitCode != (int)RET_ERRORS.RET_NO_ERROR)
|
|
||||||
{
|
|
||||||
throw new Exception(stderr);
|
|
||||||
}
|
|
||||||
|
|
||||||
//if (arguments == "query")
|
|
||||||
//{
|
|
||||||
// if (stdout.IsNullOrWhiteSpace() || stdout.IsNullOrEmpty())
|
|
||||||
// {
|
|
||||||
// throw new Exception("failed to query wininet settings");
|
|
||||||
// }
|
|
||||||
// _queryStr = stdout;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output.AppendLine(e.Data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
process.ErrorDataReceived += (sender, e) =>
|
||||||
|
{
|
||||||
|
if (e.Data == null)
|
||||||
|
{
|
||||||
|
errorWaitHandle.Set();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
error.AppendLine(e.Data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try
|
||||||
|
{
|
||||||
|
process.Start();
|
||||||
|
|
||||||
|
process.BeginErrorReadLine();
|
||||||
|
process.BeginOutputReadLine();
|
||||||
|
|
||||||
|
process.WaitForExit();
|
||||||
}
|
}
|
||||||
|
catch (System.ComponentModel.Win32Exception e)
|
||||||
|
{
|
||||||
|
|
||||||
|
// log the arguments
|
||||||
|
throw new Exception(process.StartInfo.Arguments);
|
||||||
|
}
|
||||||
|
string stderr = error.ToString();
|
||||||
|
string stdout = output.ToString();
|
||||||
|
|
||||||
|
int exitCode = process.ExitCode;
|
||||||
|
if (exitCode != (int)RET_ERRORS.RET_NO_ERROR)
|
||||||
|
{
|
||||||
|
throw new Exception(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
//if (arguments == "query")
|
||||||
|
//{
|
||||||
|
// if (stdout.IsNullOrWhiteSpace() || stdout.IsNullOrEmpty())
|
||||||
|
// {
|
||||||
|
// throw new Exception("failed to query wininet settings");
|
||||||
|
// }
|
||||||
|
// _queryStr = stdout;
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ namespace v2rayN.Base
|
||||||
{
|
{
|
||||||
public sealed class TunHandler
|
public sealed class TunHandler
|
||||||
{
|
{
|
||||||
private static readonly Lazy<TunHandler> _instance = new Lazy<TunHandler>(() => new());
|
private static readonly Lazy<TunHandler> _instance = new(() => new());
|
||||||
public static TunHandler Instance => _instance.Value;
|
public static TunHandler Instance => _instance.Value;
|
||||||
private string _tunConfigName = "tunConfig.json";
|
private string _tunConfigName = "tunConfig.json";
|
||||||
private static Config _config;
|
private static Config _config;
|
||||||
|
@ -108,7 +108,7 @@ namespace v2rayN.Base
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var dtNow = DateTime.Now;
|
var dtNow = DateTime.Now;
|
||||||
var log_output = $"\"output\": \"{Utils.GetLogPath($"singbox_{dtNow.ToString("yyyy-MM-dd")}.txt")}\", ";
|
var log_output = $"\"output\": \"{Utils.GetLogPath($"singbox_{dtNow:yyyy-MM-dd}.txt")}\", ";
|
||||||
configStr = configStr.Replace("$log_output$", $"{log_output.Replace(@"\", @"\\")}");
|
configStr = configStr.Replace("$log_output$", $"{log_output.Replace(@"\", @"\\")}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,8 +116,8 @@ namespace v2rayN.Base
|
||||||
configStr = configStr.Replace("$socksPort$", $"{_socksPort}");
|
configStr = configStr.Replace("$socksPort$", $"{_socksPort}");
|
||||||
|
|
||||||
//exe
|
//exe
|
||||||
List<string> lstDnsExe = new List<string>();
|
List<string> lstDnsExe = new();
|
||||||
List<string> lstDirectExe = new List<string>();
|
List<string> lstDirectExe = new();
|
||||||
var coreInfos = LazyConfig.Instance.GetCoreInfos();
|
var coreInfos = LazyConfig.Instance.GetCoreInfos();
|
||||||
foreach (var it in coreInfos)
|
foreach (var it in coreInfos)
|
||||||
{
|
{
|
||||||
|
@ -240,7 +240,7 @@ namespace v2rayN.Base
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var showWindow = _config.tunModeItem.showWindow;
|
var showWindow = _config.tunModeItem.showWindow;
|
||||||
Process p = new Process
|
Process p = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace v2rayN.Handler
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
var url = string.Empty;
|
var url = string.Empty;
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new();
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
||||||
|
@ -46,7 +46,7 @@ namespace v2rayN.Handler
|
||||||
{
|
{
|
||||||
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
string fileName = Utils.GetTempPath(Utils.GetDownloadFileName(url));
|
||||||
fileName = Utils.UrlEncode(fileName);
|
fileName = Utils.UrlEncode(fileName);
|
||||||
Process process = new Process
|
Process process = new()
|
||||||
{
|
{
|
||||||
StartInfo = new ProcessStartInfo
|
StartInfo = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
|
@ -101,7 +101,7 @@ namespace v2rayN.Handler
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
var url = string.Empty;
|
var url = string.Empty;
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new();
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
||||||
|
@ -253,7 +253,7 @@ namespace v2rayN.Handler
|
||||||
_updateFunc = update;
|
_updateFunc = update;
|
||||||
var url = string.Format(Global.geoUrl, geoName);
|
var url = string.Format(Global.geoUrl, geoName);
|
||||||
|
|
||||||
DownloadHandle downloadHandle = new DownloadHandle();
|
DownloadHandle downloadHandle = new();
|
||||||
downloadHandle.UpdateCompleted += (sender2, args) =>
|
downloadHandle.UpdateCompleted += (sender2, args) =>
|
||||||
{
|
{
|
||||||
if (args.Success)
|
if (args.Success)
|
||||||
|
@ -360,7 +360,7 @@ namespace v2rayN.Handler
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
Process p = new Process();
|
using Process p = new();
|
||||||
p.StartInfo.FileName = filePath;
|
p.StartInfo.FileName = filePath;
|
||||||
p.StartInfo.Arguments = coreInfo.versionArg;
|
p.StartInfo.Arguments = coreInfo.versionArg;
|
||||||
p.StartInfo.WorkingDirectory = Utils.StartupPath();
|
p.StartInfo.WorkingDirectory = Utils.StartupPath();
|
||||||
|
|
|
@ -16,12 +16,12 @@ namespace v2rayN
|
||||||
{
|
{
|
||||||
handle = CreateJobObject(IntPtr.Zero, null);
|
handle = CreateJobObject(IntPtr.Zero, null);
|
||||||
IntPtr extendedInfoPtr = IntPtr.Zero;
|
IntPtr extendedInfoPtr = IntPtr.Zero;
|
||||||
JOBOBJECT_BASIC_LIMIT_INFORMATION info = new JOBOBJECT_BASIC_LIMIT_INFORMATION
|
JOBOBJECT_BASIC_LIMIT_INFORMATION info = new()
|
||||||
{
|
{
|
||||||
LimitFlags = 0x2000
|
LimitFlags = 0x2000
|
||||||
};
|
};
|
||||||
|
|
||||||
JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new JOBOBJECT_EXTENDED_LIMIT_INFORMATION
|
JOBOBJECT_EXTENDED_LIMIT_INFORMATION extendedInfo = new()
|
||||||
{
|
{
|
||||||
BasicLimitInformation = info
|
BasicLimitInformation = info
|
||||||
};
|
};
|
||||||
|
@ -100,7 +100,7 @@ namespace v2rayN
|
||||||
#region Interop
|
#region Interop
|
||||||
|
|
||||||
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
|
||||||
private static extern IntPtr CreateJobObject(IntPtr a, string lpName);
|
private static extern IntPtr CreateJobObject(IntPtr a, string? lpName);
|
||||||
|
|
||||||
[DllImport("kernel32.dll", SetLastError = true)]
|
[DllImport("kernel32.dll", SetLastError = true)]
|
||||||
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
|
private static extern bool SetInformationJobObject(IntPtr hJob, JobObjectInfoType infoType, IntPtr lpJobObjectInfo, UInt32 cbJobObjectInfoLength);
|
||||||
|
|
|
@ -9,8 +9,8 @@ namespace v2rayN.Tool
|
||||||
{
|
{
|
||||||
public static void Setup()
|
public static void Setup()
|
||||||
{
|
{
|
||||||
LoggingConfiguration config = new LoggingConfiguration();
|
LoggingConfiguration config = new();
|
||||||
FileTarget fileTarget = new FileTarget();
|
FileTarget fileTarget = new();
|
||||||
config.AddTarget("file", fileTarget);
|
config.AddTarget("file", fileTarget);
|
||||||
fileTarget.Layout = "${longdate}-${level:uppercase=true} ${message}";
|
fileTarget.Layout = "${longdate}-${level:uppercase=true} ${message}";
|
||||||
fileTarget.FileName = Utils.GetLogPath("${shortdate}.txt");
|
fileTarget.FileName = Utils.GetLogPath("${shortdate}.txt");
|
||||||
|
|
|
@ -106,7 +106,7 @@ namespace v2rayN.ViewModels
|
||||||
{
|
{
|
||||||
UI.Show(ResUI.CustomServerTips);
|
UI.Show(ResUI.CustomServerTips);
|
||||||
|
|
||||||
OpenFileDialog fileDialog = new OpenFileDialog
|
OpenFileDialog fileDialog = new()
|
||||||
{
|
{
|
||||||
Multiselect = false,
|
Multiselect = false,
|
||||||
Filter = "Config|*.json|YAML|*.yaml;*.yml|All|*.*"
|
Filter = "Config|*.json|YAML|*.yaml;*.yml|All|*.*"
|
||||||
|
@ -121,10 +121,7 @@ namespace v2rayN.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var item = LazyConfig.Instance.GetProfileItem(SelectedSource.indexId);
|
var item = LazyConfig.Instance.GetProfileItem(SelectedSource.indexId);
|
||||||
if (item is null)
|
item ??= SelectedSource;
|
||||||
{
|
|
||||||
item = SelectedSource;
|
|
||||||
}
|
|
||||||
item.address = fileName;
|
item.address = fileName;
|
||||||
if (ConfigHandler.AddCustomServer(ref _config, item, false) == 0)
|
if (ConfigHandler.AddCustomServer(ref _config, item, false) == 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -37,7 +37,7 @@ namespace v2rayN.ViewModels
|
||||||
private string _serverFilter = string.Empty;
|
private string _serverFilter = string.Empty;
|
||||||
private static Config _config;
|
private static Config _config;
|
||||||
private NoticeHandler? _noticeHandler;
|
private NoticeHandler? _noticeHandler;
|
||||||
private readonly PaletteHelper _paletteHelper = new PaletteHelper();
|
private readonly PaletteHelper _paletteHelper = new();
|
||||||
private Dictionary<int, bool> _dicHeaderSort = new();
|
private Dictionary<int, bool> _dicHeaderSort = new();
|
||||||
private Action<string> _updateView;
|
private Action<string> _updateView;
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ namespace v2rayN.ViewModels
|
||||||
SystemProxySelected = (int)_config.sysProxyType;
|
SystemProxySelected = (int)_config.sysProxyType;
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
x => x.SystemProxySelected,
|
x => x.SystemProxySelected,
|
||||||
y => y != null && y >= 0)
|
y => y >= 0)
|
||||||
.Subscribe(c => DoSystemProxySelected(c));
|
.Subscribe(c => DoSystemProxySelected(c));
|
||||||
|
|
||||||
this.WhenAnyValue(
|
this.WhenAnyValue(
|
||||||
|
@ -820,7 +820,7 @@ namespace v2rayN.ViewModels
|
||||||
private int GetProfileItems(out List<ProfileItem> lstSelecteds)
|
private int GetProfileItems(out List<ProfileItem> lstSelecteds)
|
||||||
{
|
{
|
||||||
lstSelecteds = new List<ProfileItem>();
|
lstSelecteds = new List<ProfileItem>();
|
||||||
if (SelectedProfiles == null || SelectedProfiles.Count() <= 0)
|
if (SelectedProfiles == null || SelectedProfiles.Count <= 0)
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1169,7 +1169,7 @@ namespace v2rayN.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
foreach (var it in lstSelecteds)
|
foreach (var it in lstSelecteds)
|
||||||
{
|
{
|
||||||
string url = ShareHandler.GetShareUrl(it);
|
string url = ShareHandler.GetShareUrl(it);
|
||||||
|
@ -1194,10 +1194,10 @@ namespace v2rayN.ViewModels
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
foreach (var it in lstSelecteds)
|
foreach (var it in lstSelecteds)
|
||||||
{
|
{
|
||||||
string url = ShareHandler.GetShareUrl(it);
|
string? url = ShareHandler.GetShareUrl(it);
|
||||||
if (Utils.IsNullOrEmpty(url))
|
if (Utils.IsNullOrEmpty(url))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
|
@ -1268,7 +1268,7 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
private void ImportOldGuiConfig()
|
private void ImportOldGuiConfig()
|
||||||
{
|
{
|
||||||
OpenFileDialog fileDialog = new OpenFileDialog
|
OpenFileDialog fileDialog = new()
|
||||||
{
|
{
|
||||||
Multiselect = false,
|
Multiselect = false,
|
||||||
Filter = "guiNConfig|*.json|All|*.*"
|
Filter = "guiNConfig|*.json|All|*.*"
|
||||||
|
@ -1532,7 +1532,7 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
public void ShowHideWindow(bool? blShow)
|
public void ShowHideWindow(bool? blShow)
|
||||||
{
|
{
|
||||||
var bl = blShow.HasValue ? blShow.Value : !Global.ShowInTaskbar;
|
var bl = blShow ?? !Global.ShowInTaskbar;
|
||||||
if (bl)
|
if (bl)
|
||||||
{
|
{
|
||||||
//Application.Current.MainWindow.ShowInTaskbar = true;
|
//Application.Current.MainWindow.ShowInTaskbar = true;
|
||||||
|
@ -1651,7 +1651,7 @@ namespace v2rayN.ViewModels
|
||||||
|
|
||||||
public void InboundDisplayStaus()
|
public void InboundDisplayStaus()
|
||||||
{
|
{
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new();
|
||||||
sb.Append($"[{Global.InboundSocks}:{LazyConfig.Instance.GetLocalPort(Global.InboundSocks)}]");
|
sb.Append($"[{Global.InboundSocks}:{LazyConfig.Instance.GetLocalPort(Global.InboundSocks)}]");
|
||||||
sb.Append(" | ");
|
sb.Append(" | ");
|
||||||
//if (_config.sysProxyType == ESysProxyType.ForcedChange)
|
//if (_config.sysProxyType == ESysProxyType.ForcedChange)
|
||||||
|
@ -1662,21 +1662,21 @@ namespace v2rayN.ViewModels
|
||||||
//{
|
//{
|
||||||
sb.Append($"[{Global.InboundHttp}:{LazyConfig.Instance.GetLocalPort(Global.InboundHttp)}]");
|
sb.Append($"[{Global.InboundHttp}:{LazyConfig.Instance.GetLocalPort(Global.InboundHttp)}]");
|
||||||
//}
|
//}
|
||||||
InboundDisplay = $"{ResUI.LabLocal}:{sb.ToString()}";
|
InboundDisplay = $"{ResUI.LabLocal}:{sb}";
|
||||||
|
|
||||||
if (_config.inbound[0].allowLANConn)
|
if (_config.inbound[0].allowLANConn)
|
||||||
{
|
{
|
||||||
if (_config.inbound[0].newPort4LAN)
|
if (_config.inbound[0].newPort4LAN)
|
||||||
{
|
{
|
||||||
StringBuilder sb2 = new StringBuilder();
|
StringBuilder sb2 = new();
|
||||||
sb2.Append($"[{Global.InboundSocks}:{LazyConfig.Instance.GetLocalPort(Global.InboundSocks2)}]");
|
sb2.Append($"[{Global.InboundSocks}:{LazyConfig.Instance.GetLocalPort(Global.InboundSocks2)}]");
|
||||||
sb2.Append(" | ");
|
sb2.Append(" | ");
|
||||||
sb2.Append($"[{Global.InboundHttp}:{LazyConfig.Instance.GetLocalPort(Global.InboundHttp2)}]");
|
sb2.Append($"[{Global.InboundHttp}:{LazyConfig.Instance.GetLocalPort(Global.InboundHttp2)}]");
|
||||||
InboundLanDisplay = $"{ResUI.LabLAN}:{sb2.ToString()}";
|
InboundLanDisplay = $"{ResUI.LabLAN}:{sb2}";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
InboundLanDisplay = $"{ResUI.LabLAN}:{sb.ToString()}";
|
InboundLanDisplay = $"{ResUI.LabLAN}:{sb}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1713,10 +1713,10 @@ namespace v2rayN.ViewModels
|
||||||
.Delay(TimeSpan.FromSeconds(1))
|
.Delay(TimeSpan.FromSeconds(1))
|
||||||
.Subscribe(x =>
|
.Subscribe(x =>
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke((Action)(() =>
|
Application.Current.Dispatcher.Invoke(() =>
|
||||||
{
|
{
|
||||||
ShowHideWindow(false);
|
ShowHideWindow(false);
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue