mirror of
https://github.com/2dust/v2rayN.git
synced 2025-08-29 14:26:20 +00:00
Merge branch '2dust:master' into master
This commit is contained in:
commit
9fe1ccb83a
9 changed files with 128 additions and 100 deletions
|
@ -1,6 +1,13 @@
|
|||
using QRCoder;
|
||||
using QRCoder.Xaml;
|
||||
using System.Drawing;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
using ZXing.Windows.Compatibility;
|
||||
using ZXing;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
@ -28,5 +35,70 @@ namespace v2rayN
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ScanScreen(float dpiX, float dpiY)
|
||||
{
|
||||
try
|
||||
{
|
||||
var left = (int)(SystemParameters.WorkArea.Left);
|
||||
var top = (int)(SystemParameters.WorkArea.Top);
|
||||
var width = (int)(SystemParameters.WorkArea.Width / dpiX);
|
||||
var height = (int)(SystemParameters.WorkArea.Height / dpiY);
|
||||
|
||||
using Bitmap fullImage = new Bitmap(width, height);
|
||||
using (Graphics g = Graphics.FromImage(fullImage))
|
||||
{
|
||||
g.CopyFromScreen(left, top, 0, 0, fullImage.Size, CopyPixelOperation.SourceCopy);
|
||||
}
|
||||
int maxTry = 10;
|
||||
for (int i = 0; i < maxTry; i++)
|
||||
{
|
||||
int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
|
||||
int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry);
|
||||
Rectangle cropRect = new(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
|
||||
Bitmap target = new(width, height);
|
||||
|
||||
double imageScale = (double)width / (double)cropRect.Width;
|
||||
using (Graphics g = Graphics.FromImage(target))
|
||||
{
|
||||
g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
|
||||
cropRect,
|
||||
GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
BitmapLuminanceSource source = new(target);
|
||||
QRCodeReader reader = new();
|
||||
|
||||
BinaryBitmap bitmap = new(new HybridBinarizer(source));
|
||||
var result = reader.decode(bitmap);
|
||||
if (result != null)
|
||||
{
|
||||
return result.Text;
|
||||
}
|
||||
else
|
||||
{
|
||||
BinaryBitmap bitmap2 = new(new HybridBinarizer(source.invert()));
|
||||
var result2 = reader.decode(bitmap2);
|
||||
if (result2 != null)
|
||||
{
|
||||
return result2.Text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(ex.Message, ex);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static Tuple<float, float> GetDpiXY(Window window)
|
||||
{
|
||||
IntPtr hWnd = new WindowInteropHelper(window).EnsureHandle();
|
||||
Graphics g = Graphics.FromHwnd(hWnd);
|
||||
|
||||
return new(96 / g.DpiX, 96 / g.DpiY);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,10 +18,6 @@ using System.Windows;
|
|||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using ZXing;
|
||||
using ZXing.Common;
|
||||
using ZXing.QrCode;
|
||||
using ZXing.Windows.Compatibility;
|
||||
|
||||
namespace v2rayN
|
||||
{
|
||||
|
@ -481,7 +477,7 @@ namespace v2rayN
|
|||
/// 验证Domain地址是否合法
|
||||
/// </summary>
|
||||
/// <param name="domain"></param>
|
||||
public static bool IsDomain(string domain)
|
||||
public static bool IsDomain(string? domain)
|
||||
{
|
||||
//如果为空
|
||||
if (IsNullOrEmpty(domain))
|
||||
|
@ -950,66 +946,6 @@ namespace v2rayN
|
|||
|
||||
#endregion TempPath
|
||||
|
||||
#region scan screen
|
||||
|
||||
public static string ScanScreen(float dpiX, float dpiY)
|
||||
{
|
||||
try
|
||||
{
|
||||
var left = (int)(SystemParameters.WorkArea.Left);
|
||||
var top = (int)(SystemParameters.WorkArea.Top);
|
||||
var width = (int)(SystemParameters.WorkArea.Width / dpiX);
|
||||
var height = (int)(SystemParameters.WorkArea.Height / dpiY);
|
||||
|
||||
using Bitmap fullImage = new Bitmap(width, height);
|
||||
using (Graphics g = Graphics.FromImage(fullImage))
|
||||
{
|
||||
g.CopyFromScreen(left, top, 0, 0, fullImage.Size, CopyPixelOperation.SourceCopy);
|
||||
}
|
||||
int maxTry = 10;
|
||||
for (int i = 0; i < maxTry; i++)
|
||||
{
|
||||
int marginLeft = (int)((double)fullImage.Width * i / 2.5 / maxTry);
|
||||
int marginTop = (int)((double)fullImage.Height * i / 2.5 / maxTry);
|
||||
Rectangle cropRect = new(marginLeft, marginTop, fullImage.Width - marginLeft * 2, fullImage.Height - marginTop * 2);
|
||||
Bitmap target = new(width, height);
|
||||
|
||||
double imageScale = (double)width / (double)cropRect.Width;
|
||||
using (Graphics g = Graphics.FromImage(target))
|
||||
{
|
||||
g.DrawImage(fullImage, new Rectangle(0, 0, target.Width, target.Height),
|
||||
cropRect,
|
||||
GraphicsUnit.Pixel);
|
||||
}
|
||||
|
||||
BitmapLuminanceSource source = new(target);
|
||||
BinaryBitmap bitmap = new(new HybridBinarizer(source));
|
||||
QRCodeReader reader = new();
|
||||
Result result = reader.decode(bitmap);
|
||||
if (result != null)
|
||||
{
|
||||
string ret = result.Text;
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.SaveLog(ex.Message, ex);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
public static Tuple<float, float> GetDpiXY(Window window)
|
||||
{
|
||||
IntPtr hWnd = new WindowInteropHelper(window).EnsureHandle();
|
||||
Graphics g = Graphics.FromHwnd(hWnd);
|
||||
|
||||
return new(96 / g.DpiX, 96 / g.DpiY);
|
||||
}
|
||||
|
||||
#endregion scan screen
|
||||
|
||||
#region 开机自动启动等
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -810,24 +810,9 @@ namespace v2rayN.Handler
|
|||
{
|
||||
return 0;
|
||||
}
|
||||
//Add the dns of the remote server domain
|
||||
if (dns4Sbox.rules is null)
|
||||
{
|
||||
dns4Sbox.rules = new();
|
||||
}
|
||||
dns4Sbox.servers.Add(new()
|
||||
{
|
||||
tag = "local_local",
|
||||
address = "223.5.5.5",
|
||||
detour = Global.DirectTag,
|
||||
});
|
||||
dns4Sbox.rules.Add(new()
|
||||
{
|
||||
server = "local_local",
|
||||
outbound = "any"
|
||||
});
|
||||
|
||||
singboxConfig.dns = dns4Sbox;
|
||||
|
||||
GenDnsDomains(singboxConfig);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
@ -836,6 +821,35 @@ namespace v2rayN.Handler
|
|||
return 0;
|
||||
}
|
||||
|
||||
private int GenDnsDomains(SingboxConfig singboxConfig)
|
||||
{
|
||||
var dns4Sbox = singboxConfig.dns ?? new();
|
||||
dns4Sbox.servers ??= [];
|
||||
dns4Sbox.rules ??= [];
|
||||
|
||||
var lstDomain = singboxConfig.outbounds
|
||||
.Where(t => !Utils.IsNullOrEmpty(t.server) && Utils.IsDomain(t.server))
|
||||
.Select(t => t.server)
|
||||
.ToList();
|
||||
if (lstDomain != null && lstDomain.Count > 0)
|
||||
{
|
||||
var tag = "local_local";
|
||||
dns4Sbox.servers.Insert(0, new()
|
||||
{
|
||||
tag = tag,
|
||||
address = "223.5.5.5",
|
||||
detour = Global.DirectTag,
|
||||
});
|
||||
dns4Sbox.rules.Insert(0, new()
|
||||
{
|
||||
server = tag,
|
||||
domain = lstDomain
|
||||
});
|
||||
}
|
||||
singboxConfig.dns = dns4Sbox;
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int GenExperimental(SingboxConfig singboxConfig)
|
||||
{
|
||||
if (_config.guiItem.enableStatistics)
|
||||
|
@ -1076,18 +1090,18 @@ namespace v2rayN.Handler
|
|||
singboxConfig.route.rules.Add(rule);
|
||||
}
|
||||
|
||||
GenDns(new(), singboxConfig);
|
||||
var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
|
||||
if (dnsServer != null)
|
||||
{
|
||||
dnsServer.detour = singboxConfig.route.rules.LastOrDefault()?.outbound;
|
||||
}
|
||||
var dnsRule = singboxConfig.dns?.rules.Where(t => t.outbound != null).FirstOrDefault();
|
||||
if (dnsRule != null)
|
||||
{
|
||||
singboxConfig.dns.rules = [];
|
||||
singboxConfig.dns.rules.Add(dnsRule);
|
||||
}
|
||||
GenDnsDomains(singboxConfig);
|
||||
//var dnsServer = singboxConfig.dns?.servers.FirstOrDefault();
|
||||
//if (dnsServer != null)
|
||||
//{
|
||||
// dnsServer.detour = singboxConfig.route.rules.LastOrDefault()?.outbound;
|
||||
//}
|
||||
//var dnsRule = singboxConfig.dns?.rules.Where(t => t.outbound != null).FirstOrDefault();
|
||||
//if (dnsRule != null)
|
||||
//{
|
||||
// singboxConfig.dns.rules = [];
|
||||
// singboxConfig.dns.rules.Add(dnsRule);
|
||||
//}
|
||||
|
||||
//msg = string.Format(ResUI.SuccessfulConfiguration"), node.getSummary());
|
||||
return 0;
|
||||
|
|
|
@ -95,7 +95,7 @@
|
|||
{
|
||||
public string type { get; set; }
|
||||
public string tag { get; set; }
|
||||
public string server { get; set; }
|
||||
public string? server { get; set; }
|
||||
public int? server_port { get; set; }
|
||||
public string uuid { get; set; }
|
||||
public string security { get; set; }
|
||||
|
|
|
@ -30,5 +30,6 @@
|
|||
],
|
||||
"server": "block"
|
||||
}
|
||||
]
|
||||
],
|
||||
"final": "local"
|
||||
}
|
|
@ -30,5 +30,6 @@
|
|||
],
|
||||
"server": "block"
|
||||
}
|
||||
]
|
||||
],
|
||||
"final": "local"
|
||||
}
|
|
@ -1026,10 +1026,10 @@ namespace v2rayN.ViewModels
|
|||
{
|
||||
ShowHideWindow(false);
|
||||
|
||||
var dpiXY = Utils.GetDpiXY(Application.Current.MainWindow);
|
||||
var dpiXY = QRCodeHelper.GetDpiXY(Application.Current.MainWindow);
|
||||
string result = await Task.Run(() =>
|
||||
{
|
||||
return Utils.ScanScreen(dpiXY.Item1, dpiXY.Item2);
|
||||
return QRCodeHelper.ScanScreen(dpiXY.Item1, dpiXY.Item2);
|
||||
});
|
||||
|
||||
ShowHideWindow(true);
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
|
||||
<materialDesign:DialogHost
|
||||
Identifier="RootDialog"
|
||||
materialDesign:TransitionAssist.DisableTransitions="True"
|
||||
SnackbarMessageQueue="{Binding ElementName=MainSnackbar, Path=MessageQueue}"
|
||||
Style="{StaticResource MaterialDesignEmbeddedDialogHost}">
|
||||
<Grid>
|
||||
|
|
|
@ -23,7 +23,10 @@
|
|||
TextOptions.TextRenderingMode="Auto"
|
||||
WindowStartupLocation="CenterScreen"
|
||||
mc:Ignorable="d">
|
||||
<materialDesign:DialogHost Identifier="SubDialog" Style="{StaticResource MaterialDesignEmbeddedDialogHost}">
|
||||
<materialDesign:DialogHost
|
||||
materialDesign:TransitionAssist.DisableTransitions="True"
|
||||
Identifier="SubDialog"
|
||||
Style="{StaticResource MaterialDesignEmbeddedDialogHost}">
|
||||
<DockPanel>
|
||||
<ToolBarTray DockPanel.Dock="Top">
|
||||
<ToolBar
|
||||
|
|
Loading…
Reference in a new issue