Compare commits

..

9 Commits
6.50 ... 6.51

Author SHA1 Message Date
2dust
cfe8fcd28d up 6.51 2024-07-12 14:23:29 +08:00
2dust
9f4718af70 Code clean
Add allowInsecure to Share
2024-07-11 14:42:01 +08:00
2dust
39faccfd0b Bug fix 2024-07-10 17:32:26 +08:00
2dust
7545763dae Default domain strategy for resolving the outbound domain names -- singbox 2024-07-08 18:45:29 +08:00
2dust
c2928be35d Log messages are not displayed when in the background 2024-07-08 17:16:49 +08:00
2dust
449bb40d48 sing-box prioritizes the use of local srs 2024-07-08 14:20:41 +08:00
2dust
4caf1a1e63 Improve and refactor the code 2024-07-08 09:52:11 +08:00
2dust
01b205e6f1 Adjust information DispatcherPriority 2024-07-07 21:11:04 +08:00
2dust
160d3843a6 Bug fix 2024-07-05 15:28:28 +08:00
30 changed files with 181 additions and 238 deletions

View File

@@ -1,10 +1,38 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using static v2rayN.Handler.ProxySetting.InternetConnectionOption; using static v2rayN.Common.ProxySetting.InternetConnectionOption;
namespace v2rayN.Handler namespace v2rayN.Common
{ {
internal class ProxySetting internal class ProxySetting
{ {
private const string _regPath = @"Software\Microsoft\Windows\CurrentVersion\Internet Settings";
private static bool SetProxyFallback(string? strProxy, string? exceptions, int type)
{
if (type == 1)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyServer", string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", string.Empty);
}
if (type == 2)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 1);
Utils.RegWriteValue(_regPath, "ProxyServer", strProxy ?? string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", exceptions ?? string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", string.Empty);
}
else if (type == 4)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyServer", string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", strProxy ?? string.Empty);
}
return true;
}
/// <summary> /// <summary>
// set to use no proxy // set to use no proxy
/// </summary> /// </summary>
@@ -43,6 +71,7 @@ namespace v2rayN.Handler
} }
catch (Exception ex) catch (Exception ex)
{ {
SetProxyFallback(strProxy, exceptions, type);
Logging.SaveLog(ex.Message, ex); Logging.SaveLog(ex.Message, ex);
return false; return false;
} }
@@ -102,25 +131,25 @@ namespace v2rayN.Handler
} }
else else
{ {
list.szConnection = IntPtr.Zero; list.szConnection = nint.Zero;
} }
list.dwOptionCount = options.Length; list.dwOptionCount = options.Length;
list.dwOptionError = 0; list.dwOptionError = 0;
int optSize = Marshal.SizeOf(typeof(InternetConnectionOption)); int optSize = Marshal.SizeOf(typeof(InternetConnectionOption));
// make a pointer out of all that ... // make a pointer out of all that ...
IntPtr optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4 nint optionsPtr = Marshal.AllocCoTaskMem(optSize * options.Length); // !! remember to deallocate memory 4
// copy the array over into that spot in memory ... // copy the array over into that spot in memory ...
for (int i = 0; i < options.Length; ++i) for (int i = 0; i < options.Length; ++i)
{ {
if (Environment.Is64BitOperatingSystem) if (Environment.Is64BitOperatingSystem)
{ {
IntPtr opt = new(optionsPtr.ToInt64() + (i * optSize)); nint opt = new(optionsPtr.ToInt64() + i * optSize);
Marshal.StructureToPtr(options[i], opt, false); Marshal.StructureToPtr(options[i], opt, false);
} }
else else
{ {
IntPtr opt = new(optionsPtr.ToInt32() + (i * optSize)); nint opt = new(optionsPtr.ToInt32() + i * optSize);
Marshal.StructureToPtr(options[i], opt, false); Marshal.StructureToPtr(options[i], opt, false);
} }
} }
@@ -128,11 +157,11 @@ 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(list.dwSize); // !! remember to deallocate memory 5 nint ipcoListPtr = Marshal.AllocCoTaskMem(list.dwSize); // !! remember to deallocate memory 5
Marshal.StructureToPtr(list, ipcoListPtr, false); Marshal.StructureToPtr(list, ipcoListPtr, false);
// and finally, call the API method! // and finally, call the API method!
bool isSuccess = NativeMethods.InternetSetOption(IntPtr.Zero, bool isSuccess = NativeMethods.InternetSetOption(nint.Zero,
InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION, InternetOption.INTERNET_OPTION_PER_CONNECTION_OPTION,
ipcoListPtr, list.dwSize); ipcoListPtr, list.dwSize);
int returnvalue = 0; // ERROR_SUCCESS int returnvalue = 0; // ERROR_SUCCESS
@@ -143,12 +172,12 @@ namespace v2rayN.Handler
else else
{ {
// Notify the system that the registry settings have been changed and cause them to be refreshed // Notify the system that the registry settings have been changed and cause them to be refreshed
NativeMethods.InternetSetOption(IntPtr.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0); NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_SETTINGS_CHANGED, nint.Zero, 0);
NativeMethods.InternetSetOption(IntPtr.Zero, InternetOption.INTERNET_OPTION_REFRESH, IntPtr.Zero, 0); NativeMethods.InternetSetOption(nint.Zero, InternetOption.INTERNET_OPTION_REFRESH, nint.Zero, 0);
} }
// FREE the data ASAP // FREE the data ASAP
if (list.szConnection != IntPtr.Zero) Marshal.FreeHGlobal(list.szConnection); // release mem 3 if (list.szConnection != nint.Zero) Marshal.FreeHGlobal(list.szConnection); // release mem 3
if (optionCount > 1) if (optionCount > 1)
{ {
Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1 Marshal.FreeHGlobal(options[1].m_Value.m_StringPtr); // release mem 1
@@ -212,12 +241,12 @@ namespace v2rayN.Handler
public struct InternetPerConnOptionList public struct InternetPerConnOptionList
{ {
public int dwSize; // size of the INTERNET_PER_CONN_OPTION_LIST struct public int dwSize; // size of the INTERNET_PER_CONN_OPTION_LIST struct
public IntPtr szConnection; // connection name to set/query options public nint szConnection; // connection name to set/query options
public int dwOptionCount; // number of options to set/query public int dwOptionCount; // number of options to set/query
public int dwOptionError; // on error, which option failed public int dwOptionError; // on error, which option failed
//[MarshalAs(UnmanagedType.)] //[MarshalAs(UnmanagedType.)]
public IntPtr options; public nint options;
}; };
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -244,7 +273,7 @@ namespace v2rayN.Handler
public int m_Int; public int m_Int;
[FieldOffset(0)] [FieldOffset(0)]
public IntPtr m_StringPtr; public nint m_StringPtr;
} }
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
@@ -316,7 +345,7 @@ namespace v2rayN.Handler
{ {
[DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)] [DllImport("WinInet.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)] [return: MarshalAs(UnmanagedType.Bool)]
public static extern bool InternetSetOption(IntPtr hInternet, InternetOption dwOption, IntPtr lpBuffer, int dwBufferLength); public static extern bool InternetSetOption(nint hInternet, InternetOption dwOption, nint lpBuffer, int dwBufferLength);
[DllImport("Rasapi32.dll", CharSet = CharSet.Auto)] [DllImport("Rasapi32.dll", CharSet = CharSet.Auto)]
public static extern uint RasEnumEntries( public static extern uint RasEnumEntries(

View File

@@ -1,9 +1,4 @@
using System; using YamlDotNet.Serialization;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YamlDotNet.Serialization;
using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization.NamingConventions;
namespace v2rayN.Common namespace v2rayN.Common

View File

@@ -11,7 +11,7 @@ namespace v2rayN.Converters
if (delay <= 0) if (delay <= 0)
return new SolidColorBrush(Colors.Red); return new SolidColorBrush(Colors.Red);
if (delay <= 200) if (delay <= 500)
return new SolidColorBrush(Colors.Green); return new SolidColorBrush(Colors.Green);
else else
return new SolidColorBrush(Colors.IndianRed); return new SolidColorBrush(Colors.IndianRed);

View File

@@ -172,6 +172,7 @@ namespace v2rayN
public static readonly List<string> AllowInsecure = new() { "true", "false", "" }; public static readonly List<string> AllowInsecure = new() { "true", "false", "" };
public static readonly List<string> DomainStrategy4Freedoms = new() { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" }; public static readonly List<string> DomainStrategy4Freedoms = new() { "AsIs", "UseIP", "UseIPv4", "UseIPv6", "" };
public static readonly List<string> SingboxDomainStrategy4Out = new() { "ipv4_only", "prefer_ipv4", "prefer_ipv6", "ipv6_only", "" };
public static readonly List<string> Languages = new() { "zh-Hans", "zh-Hant", "en", "fa-Ir", "ru" }; public static readonly List<string> Languages = new() { "zh-Hans", "zh-Hant", "en", "fa-Ir", "ru" };
public static readonly List<string> Alpns = new() { "h3", "h2", "http/1.1", "h3,h2,http/1.1", "h3,h2", "h2,http/1.1", "" }; public static readonly List<string> Alpns = new() { "h3", "h2", "http/1.1", "h3,h2,http/1.1", "h3,h2", "h2,http/1.1", "" };
public static readonly List<string> LogLevels = new() { "debug", "info", "warning", "error", "none" }; public static readonly List<string> LogLevels = new() { "debug", "info", "warning", "error", "none" };

View File

@@ -1,4 +1,5 @@
using System.Data; using System.Data;
using System.IO;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using v2rayN.Enums; using v2rayN.Enums;
@@ -825,7 +826,7 @@ namespace v2rayN.Handler.CoreConfig
} }
singboxConfig.dns = dns4Sbox; singboxConfig.dns = dns4Sbox;
GenDnsDomains(node, singboxConfig); GenDnsDomains(node, singboxConfig, item?.domainStrategy4Freedom);
} }
catch (Exception ex) catch (Exception ex)
{ {
@@ -834,7 +835,7 @@ namespace v2rayN.Handler.CoreConfig
return 0; return 0;
} }
private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig) private int GenDnsDomains(ProfileItem? node, SingboxConfig singboxConfig, string? strategy)
{ {
var dns4Sbox = singboxConfig.dns ?? new(); var dns4Sbox = singboxConfig.dns ?? new();
dns4Sbox.servers ??= []; dns4Sbox.servers ??= [];
@@ -846,7 +847,7 @@ namespace v2rayN.Handler.CoreConfig
tag = tag, tag = tag,
address = "223.5.5.5", address = "223.5.5.5",
detour = Global.DirectTag, detour = Global.DirectTag,
//strategy = strategy strategy = Utils.IsNullOrEmpty(strategy) ? null : strategy,
}); });
var lstDomain = singboxConfig.outbounds var lstDomain = singboxConfig.outbounds
@@ -966,28 +967,42 @@ namespace v2rayN.Handler.CoreConfig
} }
} }
//Local srs files address
var localSrss = Utils.GetBinPath("srss");
//Add ruleset srs //Add ruleset srs
singboxConfig.route.rule_set = []; singboxConfig.route.rule_set = [];
foreach (var item in new HashSet<string>(ruleSets)) foreach (var item in new HashSet<string>(ruleSets))
{ {
if (Utils.IsNullOrEmpty(item)) { continue; } if (Utils.IsNullOrEmpty(item)) { continue; }
var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item)); var customRuleset = customRulesets.FirstOrDefault(t => t.tag != null && t.tag.Equals(item));
if (customRuleset != null) if (customRuleset is null)
{ {
singboxConfig.route.rule_set.Add(customRuleset); var pathSrs = Path.Combine(localSrss, $"{item}.srs");
if (File.Exists(pathSrs))
{
customRuleset = new()
{
type = "local",
format = "binary",
tag = item,
path = pathSrs
};
} }
else else
{ {
singboxConfig.route.rule_set.Add(new() customRuleset = new()
{ {
type = "remote", type = "remote",
format = "binary", format = "binary",
tag = item, tag = item,
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item), url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item),
download_detour = Global.ProxyTag download_detour = Global.ProxyTag
}); };
} }
} }
singboxConfig.route.rule_set.Add(customRuleset);
}
return 0; return 0;
} }
@@ -1129,7 +1144,7 @@ namespace v2rayN.Handler.CoreConfig
singboxConfig.route.rules.Add(rule); singboxConfig.route.rules.Add(rule);
} }
GenDnsDomains(null, singboxConfig); GenDnsDomains(null, singboxConfig, null);
//var dnsServer = singboxConfig.dns?.servers.FirstOrDefault(); //var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
//if (dnsServer != null) //if (dnsServer != null)
//{ //{

View File

@@ -286,8 +286,6 @@ namespace v2rayN.Handler
int responseTime = -1; int responseTime = -1;
try try
{ {
Stopwatch timer = Stopwatch.StartNew();
using var cts = new CancellationTokenSource(); using var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(downloadTimeout)); cts.CancelAfter(TimeSpan.FromSeconds(downloadTimeout));
using var client = new HttpClient(new SocketsHttpHandler() using var client = new HttpClient(new SocketsHttpHandler()
@@ -295,9 +293,13 @@ namespace v2rayN.Handler
Proxy = webProxy, Proxy = webProxy,
UseProxy = webProxy != null UseProxy = webProxy != null
}); });
var timer = Stopwatch.StartNew();
await client.GetAsync(url, cts.Token); await client.GetAsync(url, cts.Token);
responseTime = timer.Elapsed.Milliseconds; timer.Stop();
responseTime = (int)timer.Elapsed.TotalMilliseconds;
} }
catch //(Exception ex) catch //(Exception ex)
{ {

View File

@@ -59,6 +59,10 @@ namespace v2rayN.Handler.Fmt
{ {
dicQuery.Add("spx", Utils.UrlEncode(item.spiderX)); dicQuery.Add("spx", Utils.UrlEncode(item.spiderX));
} }
if (item.allowInsecure.Equals("true"))
{
dicQuery.Add("allowInsecure", "1");
}
dicQuery.Add("type", !Utils.IsNullOrEmpty(item.network) ? item.network : nameof(ETransport.tcp)); dicQuery.Add("type", !Utils.IsNullOrEmpty(item.network) ? item.network : nameof(ETransport.tcp));
@@ -137,6 +141,7 @@ namespace v2rayN.Handler.Fmt
item.publicKey = Utils.UrlDecode(query["pbk"] ?? ""); item.publicKey = Utils.UrlDecode(query["pbk"] ?? "");
item.shortId = Utils.UrlDecode(query["sid"] ?? ""); item.shortId = Utils.UrlDecode(query["sid"] ?? "");
item.spiderX = Utils.UrlDecode(query["spx"] ?? ""); item.spiderX = Utils.UrlDecode(query["spx"] ?? "");
item.allowInsecure = (query["allowInsecure"] ?? "") == "1" ? "true" : "";
item.network = query["type"] ?? nameof(ETransport.tcp); item.network = query["type"] ?? nameof(ETransport.tcp);
switch (item.network) switch (item.network)

View File

@@ -1,5 +1,4 @@
using System.Text.RegularExpressions; using v2rayN.Enums;
using v2rayN.Enums;
using v2rayN.Models; using v2rayN.Models;
using v2rayN.Resx; using v2rayN.Resx;
@@ -7,17 +6,13 @@ namespace v2rayN.Handler.Fmt
{ {
internal class VmessFmt : BaseFmt internal class VmessFmt : BaseFmt
{ {
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);
public static ProfileItem? Resolve(string str, out string msg) public static ProfileItem? Resolve(string str, out string msg)
{ {
msg = ResUI.ConfigurationFormatIncorrect; msg = ResUI.ConfigurationFormatIncorrect;
ProfileItem? item; ProfileItem? item;
int indexSplit = str.IndexOf("?"); if (str.IndexOf('?') > 0 && str.IndexOf('&') > 0)
if (indexSplit > 0)
{ {
item = ResolveStdVmess(str) ?? ResolveVmess4Kitsunebi(str); item = ResolveStdVmess(str);
} }
else else
{ {
@@ -107,7 +102,7 @@ namespace v2rayN.Handler.Fmt
return item; return item;
} }
private static ProfileItem? ResolveStdVmess(string result) public static ProfileItem? ResolveStdVmess(string str)
{ {
ProfileItem item = new() ProfileItem item = new()
{ {
@@ -115,113 +110,15 @@ namespace v2rayN.Handler.Fmt
security = "auto" security = "auto"
}; };
Uri u = new(result); Uri url = new(str);
item.address = u.IdnHost; item.address = url.IdnHost;
item.port = u.Port; item.port = url.Port;
item.remarks = u.GetComponents(UriComponents.Fragment, UriFormat.Unescaped); item.remarks = url.GetComponents(UriComponents.Fragment, UriFormat.Unescaped);
var query = Utils.ParseQueryString(u.Query); item.id = Utils.UrlDecode(url.UserInfo);
var m = StdVmessUserInfo.Match(u.UserInfo); var query = Utils.ParseQueryString(url.Query);
if (!m.Success) return null; ResolveStdTransport(query, ref item);
item.id = m.Groups["id"].Value;
if (m.Groups["streamSecurity"].Success)
{
item.streamSecurity = m.Groups["streamSecurity"].Value;
}
switch (item.streamSecurity)
{
case Global.StreamSecurity:
break;
default:
if (!Utils.IsNullOrEmpty(item.streamSecurity))
return null;
break;
}
item.network = m.Groups["network"].Value;
switch (item.network)
{
case nameof(ETransport.tcp):
string t1 = query["type"] ?? Global.None;
item.headerType = t1;
break;
case nameof(ETransport.kcp):
item.headerType = query["type"] ?? Global.None;
break;
case nameof(ETransport.ws):
case nameof(ETransport.httpupgrade):
case nameof(ETransport.splithttp):
string p1 = query["path"] ?? "/";
string h1 = query["host"] ?? "";
item.requestHost = Utils.UrlDecode(h1);
item.path = p1;
break;
case nameof(ETransport.http):
case nameof(ETransport.h2):
item.network = nameof(ETransport.h2);
string p2 = query["path"] ?? "/";
string h2 = query["host"] ?? "";
item.requestHost = Utils.UrlDecode(h2);
item.path = p2;
break;
case nameof(ETransport.quic):
string s = query["security"] ?? Global.None;
string k = query["key"] ?? "";
string t3 = query["type"] ?? Global.None;
item.headerType = t3;
item.requestHost = Utils.UrlDecode(s);
item.path = k;
break;
default:
return null;
}
return item;
}
private static ProfileItem? ResolveVmess4Kitsunebi(string result)
{
ProfileItem item = new()
{
configType = EConfigType.VMess
};
result = result[Global.ProtocolShares[EConfigType.VMess].Length..];
int indexSplit = result.IndexOf("?");
if (indexSplit > 0)
{
result = result[..indexSplit];
}
result = Utils.Base64Decode(result);
string[] arr1 = result.Split('@');
if (arr1.Length != 2)
{
return null;
}
string[] arr21 = arr1[0].Split(':');
string[] arr22 = arr1[1].Split(':');
if (arr21.Length != 2 || arr22.Length != 2)
{
return null;
}
item.address = arr22[0];
item.port = Utils.ToInt(arr22[1]);
item.security = arr21[0];
item.id = arr21[1];
item.network = Global.DefaultNetwork;
item.headerType = Global.None;
item.remarks = "Alien";
return item; return item;
} }

View File

@@ -377,19 +377,18 @@ namespace v2rayN.Handler
ipAddress = ipHostInfo.AddressList[0]; ipAddress = ipHostInfo.AddressList[0];
} }
Stopwatch timer = new(); var timer = Stopwatch.StartNew();
timer.Start();
IPEndPoint endPoint = new(ipAddress, port); IPEndPoint endPoint = new(ipAddress, port);
using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp); using Socket clientSocket = new(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
IAsyncResult result = clientSocket.BeginConnect(endPoint, null, null); var result = clientSocket.BeginConnect(endPoint, null, null);
if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5))) if (!result.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(5)))
throw new TimeoutException("connect timeout (5s): " + url); throw new TimeoutException("connect timeout (5s): " + url);
clientSocket.EndConnect(result); clientSocket.EndConnect(result);
timer.Stop(); timer.Stop();
responseTime = timer.Elapsed.Milliseconds; responseTime = (int)timer.Elapsed.TotalMilliseconds;
} }
catch (Exception ex) catch (Exception ex)
{ {

View File

@@ -1,6 +1,6 @@
using v2rayN.Models; using v2rayN.Models;
namespace v2rayN.Handler namespace v2rayN.Handler.Statistics
{ {
internal class StatisticsHandler internal class StatisticsHandler
{ {

View File

@@ -3,7 +3,7 @@ using System.Text;
using v2rayN.Enums; using v2rayN.Enums;
using v2rayN.Models; using v2rayN.Models;
namespace v2rayN.Handler namespace v2rayN.Handler.Statistics
{ {
internal class StatisticsSingbox internal class StatisticsSingbox
{ {

View File

@@ -4,7 +4,7 @@ using ProtosLib.Statistics;
using v2rayN.Enums; using v2rayN.Enums;
using v2rayN.Models; using v2rayN.Models;
namespace v2rayN.Handler namespace v2rayN.Handler.Statistics
{ {
internal class StatisticsV2ray internal class StatisticsV2ray
{ {

View File

@@ -1,4 +1,5 @@
using PacLib; using PacLib;
using v2rayN.Common;
using v2rayN.Enums; using v2rayN.Enums;
using v2rayN.Models; using v2rayN.Models;
@@ -42,17 +43,11 @@ namespace v2rayN.Handler
.Replace("{http_port}", port.ToString()) .Replace("{http_port}", port.ToString())
.Replace("{socks_port}", portSocks.ToString()); .Replace("{socks_port}", portSocks.ToString());
} }
if (!ProxySetting.SetProxy(strProxy, strExceptions, 2)) ProxySetting.SetProxy(strProxy, strExceptions, 2);
{
SetProxy(strProxy, strExceptions, 2);
}
} }
else if (type == ESysProxyType.ForcedClear) else if (type == ESysProxyType.ForcedClear)
{ {
if (!ProxySetting.UnsetProxy()) ProxySetting.UnsetProxy();
{
UnsetProxy();
}
} }
else if (type == ESysProxyType.Unchanged) else if (type == ESysProxyType.Unchanged)
{ {
@@ -61,10 +56,7 @@ namespace v2rayN.Handler
{ {
PacHandler.Start(Utils.GetConfigPath(), port, portPac); PacHandler.Start(Utils.GetConfigPath(), port, portPac);
var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}"; var strProxy = $"{Global.HttpProtocol}{Global.Loopback}:{portPac}/pac?t={DateTime.Now.Ticks}";
if (!ProxySetting.SetProxy(strProxy, "", 4)) ProxySetting.SetProxy(strProxy, "", 4);
{
SetProxy(strProxy, "", 4);
}
} }
if (type != ESysProxyType.Pac) if (type != ESysProxyType.Pac)
@@ -81,38 +73,7 @@ namespace v2rayN.Handler
public static void ResetIEProxy4WindowsShutDown() public static void ResetIEProxy4WindowsShutDown()
{ {
SetProxy(null, null, 1); ProxySetting.UnsetProxy();
}
private static void UnsetProxy()
{
SetProxy(null, null, 1);
}
private static bool SetProxy(string? strProxy, string? exceptions, int type)
{
if (type == 1)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyServer", string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", string.Empty);
}
if (type == 2)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 1);
Utils.RegWriteValue(_regPath, "ProxyServer", strProxy ?? string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", exceptions ?? string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", string.Empty);
}
else if (type == 4)
{
Utils.RegWriteValue(_regPath, "ProxyEnable", 0);
Utils.RegWriteValue(_regPath, "ProxyServer", string.Empty);
Utils.RegWriteValue(_regPath, "ProxyOverride", string.Empty);
Utils.RegWriteValue(_regPath, "AutoConfigURL", strProxy ?? string.Empty);
}
return true;
} }
} }
} }

View File

@@ -1,6 +1,4 @@
 using static v2rayN.Models.ClashProxies;
using static v2rayN.Models.ClashProxies;
namespace v2rayN.Models namespace v2rayN.Models
{ {

View File

@@ -169,7 +169,7 @@ namespace v2rayN.Models
public string stack { get; set; } public string stack { get; set; }
public int mtu { get; set; } public int mtu { get; set; }
public bool enableExInbound { get; set; } public bool enableExInbound { get; set; }
public bool enableIPv6Address { get; set; } = true; public bool enableIPv6Address { get; set; }
} }
[Serializable] [Serializable]

View File

@@ -2734,6 +2734,15 @@ namespace v2rayN.Resx {
} }
} }
/// <summary>
/// 查找类似 Default domain strategy for outbound 的本地化字符串。
/// </summary>
public static string TbSettingsDomainStrategy4Out {
get {
return ResourceManager.GetString("TbSettingsDomainStrategy4Out", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Double-click server make active 的本地化字符串。 /// 查找类似 Double-click server make active 的本地化字符串。
/// </summary> /// </summary>

View File

@@ -1297,4 +1297,7 @@
<data name="menuProxiesSelectActivity" xml:space="preserve"> <data name="menuProxiesSelectActivity" xml:space="preserve">
<value>Select active node (Enter)</value> <value>Select active node (Enter)</value>
</data> </data>
<data name="TbSettingsDomainStrategy4Out" xml:space="preserve">
<value>Default domain strategy for outbound</value>
</data>
</root> </root>

View File

@@ -1294,4 +1294,7 @@
<data name="menuProxiesSelectActivity" xml:space="preserve"> <data name="menuProxiesSelectActivity" xml:space="preserve">
<value>设为活动节点 (Enter)</value> <value>设为活动节点 (Enter)</value>
</data> </data>
<data name="TbSettingsDomainStrategy4Out" xml:space="preserve">
<value>Outbound默认解析策略</value>
</data>
</root> </root>

View File

@@ -337,7 +337,7 @@ namespace v2rayN.ViewModels
private ProxiesItem? TryGetProxy(string name) private ProxiesItem? TryGetProxy(string name)
{ {
if(proxies is null) if (proxies is null)
return null; return null;
proxies.TryGetValue(name, out ProxiesItem proxy2); proxies.TryGetValue(name, out ProxiesItem proxy2);
if (proxy2 != null) if (proxy2 != null)

View File

@@ -21,6 +21,7 @@ namespace v2rayN.ViewModels
[Reactive] public string normalDNS { get; set; } [Reactive] public string normalDNS { get; set; }
[Reactive] public string normalDNS2 { get; set; } [Reactive] public string normalDNS2 { get; set; }
[Reactive] public string tunDNS2 { get; set; } [Reactive] public string tunDNS2 { get; set; }
[Reactive] public string domainStrategy4Freedom2 { get; set; }
public ReactiveCommand<Unit, Unit> SaveCmd { get; } public ReactiveCommand<Unit, Unit> SaveCmd { get; }
public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; } public ReactiveCommand<Unit, Unit> ImportDefConfig4V2rayCmd { get; }
@@ -34,12 +35,13 @@ namespace v2rayN.ViewModels
var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray); var item = LazyConfig.Instance.GetDNSItem(ECoreType.Xray);
useSystemHosts = item.useSystemHosts; useSystemHosts = item.useSystemHosts;
domainStrategy4Freedom = item?.domainStrategy4Freedom!; domainStrategy4Freedom = item?.domainStrategy4Freedom ?? string.Empty;
normalDNS = item?.normalDNS!; normalDNS = item?.normalDNS ?? string.Empty;
var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
normalDNS2 = item2?.normalDNS!; normalDNS2 = item2?.normalDNS ?? string.Empty;
tunDNS2 = item2?.tunDNS!; tunDNS2 = item2?.tunDNS ?? string.Empty;
domainStrategy4Freedom2 = item2?.domainStrategy4Freedom ?? string.Empty;
SaveCmd = ReactiveCommand.Create(() => SaveCmd = ReactiveCommand.Create(() =>
{ {
@@ -105,6 +107,7 @@ namespace v2rayN.ViewModels
var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box); var item2 = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2)); item2.normalDNS = JsonUtils.Serialize(JsonUtils.ParseJson(normalDNS2));
item2.tunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2)); item2.tunDNS = JsonUtils.Serialize(JsonUtils.ParseJson(tunDNS2));
item2.domainStrategy4Freedom = domainStrategy4Freedom2;
ConfigHandler.SaveDNSItems(_config, item2); ConfigHandler.SaveDNSItems(_config, item2);
_noticeHandler?.Enqueue(ResUI.OperationSuccess); _noticeHandler?.Enqueue(ResUI.OperationSuccess);

View File

@@ -17,6 +17,7 @@ using System.Windows.Media;
using v2rayN.Enums; using v2rayN.Enums;
using v2rayN.Handler; using v2rayN.Handler;
using v2rayN.Handler.Fmt; using v2rayN.Handler.Fmt;
using v2rayN.Handler.Statistics;
using v2rayN.Models; using v2rayN.Models;
using v2rayN.Resx; using v2rayN.Resx;
using v2rayN.Views; using v2rayN.Views;
@@ -150,6 +151,7 @@ namespace v2rayN.ViewModels
//CheckUpdate //CheckUpdate
public ReactiveCommand<Unit, Unit> CheckUpdateNCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateNCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateXrayCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateXrayCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateClashMetaCoreCmd { get; }
public ReactiveCommand<Unit, Unit> CheckUpdateSingBoxCoreCmd { get; } public ReactiveCommand<Unit, Unit> CheckUpdateSingBoxCoreCmd { get; }
@@ -612,6 +614,10 @@ namespace v2rayN.ViewModels
private void UpdateHandler(bool notify, string msg) private void UpdateHandler(bool notify, string msg)
{ {
if (!_showInTaskbar)
{
return;
}
_noticeHandler?.SendMessage(msg); _noticeHandler?.SendMessage(msg);
if (notify) if (notify)
{ {
@@ -1514,11 +1520,11 @@ namespace v2rayN.ViewModels
{ {
BlReloadEnabled = true; BlReloadEnabled = true;
ShowCalshUI = (_config.runningCoreType is ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo); ShowCalshUI = (_config.runningCoreType is ECoreType.clash or ECoreType.clash_meta or ECoreType.mihomo);
if (ShowCalshUI) { if (ShowCalshUI)
{
Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload(); Locator.Current.GetService<ClashProxiesViewModel>()?.ProxiesReload();
} }
})); }));
}); });
} }

View File

@@ -1,6 +1,6 @@
using v2rayN.ViewModels;
using ReactiveUI; using ReactiveUI;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using v2rayN.ViewModels;
namespace v2rayN.Views namespace v2rayN.Views
{ {

View File

@@ -1,13 +1,12 @@
<reactiveui:ReactiveUserControl <reactiveui:ReactiveUserControl
x:Class="v2rayN.Views.ClashProxiesView" x:Class="v2rayN.Views.ClashProxiesView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:v2rayN.Views"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net" xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx" xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
d:DesignHeight="450" d:DesignHeight="450"

View File

@@ -1,8 +1,8 @@
using v2rayN.ViewModels;
using ReactiveUI; using ReactiveUI;
using Splat; using Splat;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Windows.Input; using System.Windows.Input;
using v2rayN.ViewModels;
namespace v2rayN.Views namespace v2rayN.Views
{ {

View File

@@ -132,6 +132,19 @@
Style="{StaticResource DefButton}" /> Style="{StaticResource DefButton}" />
</StackPanel> </StackPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
<TextBlock
Margin="{StaticResource SettingItemMargin}"
VerticalAlignment="Center"
Style="{StaticResource ToolbarTextBlock}"
Text="{x:Static resx:ResUI.TbSettingsDomainStrategy4Out}" />
<ComboBox
x:Name="cmbdomainStrategy4Out"
Width="200"
Margin="{StaticResource SettingItemMargin}"
Style="{StaticResource DefComboBox}" />
</StackPanel>
<Grid Margin="{StaticResource SettingItemMargin}"> <Grid Margin="{StaticResource SettingItemMargin}">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" /> <ColumnDefinition Width="1*" />

View File

@@ -34,12 +34,17 @@ namespace v2rayN.Views
{ {
cmbdomainStrategy4Freedom.Items.Add(it); cmbdomainStrategy4Freedom.Items.Add(it);
}); });
Global.SingboxDomainStrategy4Out.ForEach(it =>
{
cmbdomainStrategy4Out.Items.Add(it);
});
this.WhenActivated(disposables => this.WhenActivated(disposables =>
{ {
this.Bind(ViewModel, vm => vm.useSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.useSystemHosts, v => v.togUseSystemHosts.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.domainStrategy4Freedom, v => v.cmbdomainStrategy4Freedom.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.normalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.normalDNS, v => v.txtnormalDNS.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.domainStrategy4Freedom2, v => v.cmbdomainStrategy4Out.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.normalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.normalDNS2, v => v.txtnormalDNS2.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.tunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables); this.Bind(ViewModel, vm => vm.tunDNS2, v => v.txttunDNS2.Text).DisposeWith(disposables);

View File

@@ -31,7 +31,7 @@ namespace v2rayN.Views
private void DelegateAppendText(string msg) private void DelegateAppendText(string msg)
{ {
Dispatcher.BeginInvoke(AppendText, DispatcherPriority.Send, msg); Dispatcher.BeginInvoke(AppendText, DispatcherPriority.ApplicationIdle, msg);
} }
public void AppendText(string msg) public void AppendText(string msg)

View File

@@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow <reactiveui:ReactiveWindow
x:Class="v2rayN.Views.RoutingRuleDetailsWindow" x:Class="v2rayN.Views.RoutingRuleDetailsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net" xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx" xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuRoutingRuleDetailsSetting}" Title="{x:Static resx:ResUI.menuRoutingRuleDetailsSetting}"

View File

@@ -1,12 +1,12 @@
<reactiveui:ReactiveWindow <reactiveui:ReactiveWindow
x:Class="v2rayN.Views.RoutingRuleSettingWindow" x:Class="v2rayN.Views.RoutingRuleSettingWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:reactiveui="http://reactiveui.net" xmlns:reactiveui="http://reactiveui.net"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:conv="clr-namespace:v2rayN.Converters"
xmlns:resx="clr-namespace:v2rayN.Resx" xmlns:resx="clr-namespace:v2rayN.Resx"
xmlns:vms="clr-namespace:v2rayN.ViewModels" xmlns:vms="clr-namespace:v2rayN.ViewModels"
Title="{x:Static resx:ResUI.menuRoutingRuleSetting}" Title="{x:Static resx:ResUI.menuRoutingRuleSetting}"

View File

@@ -10,14 +10,14 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<ApplicationIcon>v2rayN.ico</ApplicationIcon> <ApplicationIcon>v2rayN.ico</ApplicationIcon>
<Copyright>Copyright © 2017-2024 (GPLv3)</Copyright> <Copyright>Copyright © 2017-2024 (GPLv3)</Copyright>
<FileVersion>6.50</FileVersion> <FileVersion>6.51</FileVersion>
<SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion>7.0</SupportedOSPlatformVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Downloader" Version="3.1.2" /> <PackageReference Include="Downloader" Version="3.1.2" />
<PackageReference Include="MaterialDesignThemes" Version="5.1.0" /> <PackageReference Include="MaterialDesignThemes" Version="5.1.0" />
<PackageReference Include="H.NotifyIcon.Wpf" Version="2.0.131" /> <PackageReference Include="H.NotifyIcon.Wpf" Version="2.1.0" />
<PackageReference Include="QRCoder.Xaml" Version="1.6.0" /> <PackageReference Include="QRCoder.Xaml" Version="1.6.0" />
<PackageReference Include="sqlite-net-pcl" Version="1.9.172" /> <PackageReference Include="sqlite-net-pcl" Version="1.9.172" />
<PackageReference Include="TaskScheduler" Version="2.11.0" /> <PackageReference Include="TaskScheduler" Version="2.11.0" />