Compare commits

...

11 Commits
5.12 ... 5.14

Author SHA1 Message Date
2dust
73c79ca7bf Update AssemblyInfo.cs 2022-04-12 16:58:31 +08:00
2dust
978975ee2d update package 2022-04-12 16:58:09 +08:00
2dust
d7dc0dff50 Adjusting the tray server display 2022-04-12 14:49:57 +08:00
2dust
a3aa6c045f Improve speed test 2022-04-12 13:38:42 +08:00
2dust
785ebc49fc fix clash port 2022-04-12 13:38:10 +08:00
2dust
fde1c98ddd add group sort 2022-04-12 13:37:41 +08:00
2dust
024040163a Update AssemblyInfo.cs 2022-04-11 19:16:52 +08:00
2dust
e95b5e04c0 remove expired tls 2022-04-11 19:16:35 +08:00
2dust
815826c856 Refactor download/update/speedtest 2022-04-11 15:26:32 +08:00
2dust
1c5cc190c5 modify res 2022-04-11 15:24:59 +08:00
2dust
50b109ca71 Auto update subscription 2022-04-11 15:24:24 +08:00
27 changed files with 2453 additions and 2884 deletions

View File

@@ -0,0 +1,235 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
namespace v2rayN.Base
{
/// <summary>
/// </summary>
public class HttpClientHelper
{
private static HttpClientHelper httpClientHelper = null;
private HttpClient httpClient;
/// <summary>
/// </summary>
private HttpClientHelper() { }
/// <summary>
/// </summary>
/// <returns></returns>
public static HttpClientHelper GetInstance()
{
if (httpClientHelper != null)
{
return httpClientHelper;
}
else
{
HttpClientHelper httpClientHelper = new HttpClientHelper();
HttpClientHandler handler = new HttpClientHandler() { UseCookies = false };
httpClientHelper.httpClient = new HttpClient(handler);
return httpClientHelper;
}
}
public async Task<string> GetAsync(string url)
{
if (string.IsNullOrEmpty(url))
{
return null;
}
try
{
HttpResponseMessage response = await httpClient.GetAsync(url);
return await response.Content.ReadAsStringAsync();
}
catch
{
}
return null;
}
public async Task<string> GetAsync(HttpClient client, string url)
{
if (string.IsNullOrEmpty(url))
{
return null;
}
try
{
var cts = new CancellationTokenSource();
cts.CancelAfter(5000);
HttpResponseMessage response = await client.GetAsync(url, cts.Token);
return await response.Content.ReadAsStringAsync();
}
catch (Exception ex)
{
Utils.SaveLog("GetAsync", ex);
}
return null;
}
public async Task PutAsync(string url, Dictionary<string, string> headers)
{
var myContent = Utils.ToJson(headers);
var buffer = System.Text.Encoding.UTF8.GetBytes(myContent);
var byteContent = new ByteArrayContent(buffer);
byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");
var result = await httpClient.PutAsync(url, byteContent);
}
public async Task DownloadFileAsync(HttpClient client, string url, string fileName, IProgress<double> progress, CancellationToken token)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException("url");
}
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentNullException("fileName");
}
if (File.Exists(fileName))
{
File.Delete(fileName);
}
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
if (!response.IsSuccessStatusCode)
{
throw new Exception(string.Format("The request returned with HTTP status code {0}", response.StatusCode));
}
var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
var canReportProgress = total != -1 && progress != null;
using (var stream = await response.Content.ReadAsStreamAsync())
{
using (var file = File.Create(fileName))
{
var totalRead = 0L;
var buffer = new byte[1024 * 1024];
var isMoreToRead = true;
var progressPercentage = 0;
do
{
token.ThrowIfCancellationRequested();
var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
if (read == 0)
{
isMoreToRead = false;
}
else
{
var data = new byte[read];
buffer.ToList().CopyTo(0, data, 0, read);
// TODO: put here the code to write the file to disk
file.Write(data, 0, read);
totalRead += read;
if (canReportProgress)
{
var percent = Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
if (progressPercentage != percent && percent % 10 == 0)
{
progressPercentage = percent;
progress.Report(percent);
}
}
}
} while (isMoreToRead);
file.Close();
if (canReportProgress)
{
progress.Report(101);
}
}
}
}
public async Task DownloadDataAsync4Speed(HttpClient client, string url, IProgress<double> progress, CancellationToken token)
{
if (string.IsNullOrEmpty(url))
{
throw new ArgumentNullException("url");
}
var response = await client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead, token);
if (!response.IsSuccessStatusCode)
{
throw new Exception(string.Format("The request returned with HTTP status code {0}", response.StatusCode));
}
var total = response.Content.Headers.ContentLength.HasValue ? response.Content.Headers.ContentLength.Value : -1L;
var canReportProgress = total != -1 && progress != null;
using (var stream = await response.Content.ReadAsStreamAsync())
{
var totalRead = 0L;
var buffer = new byte[1024 * 64];
var isMoreToRead = true;
var progressPercentage = 0;
DateTime totalDatetime = DateTime.Now;
do
{
if (token.IsCancellationRequested)
{
if (totalRead > 0)
{
return;
}
else
{
token.ThrowIfCancellationRequested();
}
}
var read = await stream.ReadAsync(buffer, 0, buffer.Length, token);
if (read == 0)
{
isMoreToRead = false;
}
else
{
var data = new byte[read];
buffer.ToList().CopyTo(0, data, 0, read);
// TODO:
totalRead += read;
if (canReportProgress)
{
TimeSpan ts = (DateTime.Now - totalDatetime);
var speed = totalRead * 1d / ts.TotalMilliseconds / 1000;
var percent = Convert.ToInt32((totalRead * 1d) / (total * 1d) * 100);
if (progressPercentage != percent)
{
progressPercentage = percent;
progress.Report(speed);
}
}
}
} while (isMoreToRead);
}
}
}
}

View File

@@ -1,37 +0,0 @@
using System;
using System.Net;
namespace v2rayN.Base
{
class WebClientEx : WebClient
{
public int Timeout
{
get; set;
}
public WebClientEx(int timeout = 3000)
{
Timeout = timeout;
}
protected override WebRequest GetWebRequest(Uri address)
{
HttpWebRequest request;
request = (HttpWebRequest)base.GetWebRequest(address);
request.Timeout = Timeout;
request.ReadWriteTimeout = Timeout;
//request.AllowAutoRedirect = false;
//request.AllowWriteStreamBuffering = true;
request.ServicePoint.BindIPEndPointDelegate = (servicePoint, remoteEndPoint, retryCount) =>
{
if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
return new IPEndPoint(IPAddress.IPv6Any, 0);
else
return new IPEndPoint(IPAddress.Any, 0);
};
return request;
}
}
}

View File

@@ -33,15 +33,20 @@
this.btnRemove = new System.Windows.Forms.Button();
this.txtRemarks = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.numSort = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.grbMain.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numSort)).BeginInit();
this.SuspendLayout();
//
// grbMain
//
resources.ApplyResources(this.grbMain, "grbMain");
this.grbMain.Controls.Add(this.label1);
this.grbMain.Controls.Add(this.numSort);
this.grbMain.Controls.Add(this.btnRemove);
this.grbMain.Controls.Add(this.txtRemarks);
this.grbMain.Controls.Add(this.label2);
resources.ApplyResources(this.grbMain, "grbMain");
this.grbMain.Name = "grbMain";
this.grbMain.TabStop = false;
//
@@ -63,6 +68,17 @@
resources.ApplyResources(this.label2, "label2");
this.label2.Name = "label2";
//
// numSort
//
resources.ApplyResources(this.numSort, "numSort");
this.numSort.Name = "numSort";
this.numSort.Leave += new System.EventHandler(this.txtRemarks_Leave);
//
// label1
//
resources.ApplyResources(this.label1, "label1");
this.label1.Name = "label1";
//
// GroupSettingControl
//
resources.ApplyResources(this, "$this");
@@ -72,6 +88,7 @@
this.Load += new System.EventHandler(this.GroupSettingControl_Load);
this.grbMain.ResumeLayout(false);
this.grbMain.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numSort)).EndInit();
this.ResumeLayout(false);
}
@@ -82,5 +99,7 @@
private System.Windows.Forms.TextBox txtRemarks;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Button btnRemove;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.NumericUpDown numSort;
}
}

View File

@@ -32,6 +32,7 @@ namespace v2rayN.Forms
if (groupItem != null)
{
txtRemarks.Text = groupItem.remarks.ToString();
numSort.Value = groupItem.sort;
}
}
private void EndBindingSub()
@@ -39,6 +40,7 @@ namespace v2rayN.Forms
if (groupItem != null)
{
groupItem.remarks = txtRemarks.Text.TrimEx();
groupItem.sort = Convert.ToInt32(numSort.Value);
}
}
private void txtRemarks_Leave(object sender, EventArgs e)

View File

@@ -118,126 +118,177 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="grbMain.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
<data name="label1.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="label1.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 12</value>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 61</value>
</data>
<data name="&gt;&gt;grbMain.ZOrder" xml:space="preserve">
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>71, 12</value>
</data>
<data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>26</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>Sort number</value>
</data>
<data name="&gt;&gt;label1.Name" xml:space="preserve">
<value>label1</value>
</data>
<data name="&gt;&gt;label1.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;label1.Parent" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="txtRemarks.Size" type="System.Drawing.Size, System.Drawing">
<value>292, 21</value>
<data name="numSort.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 57</value>
</data>
<data name="numSort.Size" type="System.Drawing.Size, System.Drawing">
<value>120, 21</value>
</data>
<data name="numSort.TabIndex" type="System.Int32, mscorlib">
<value>25</value>
</data>
<data name="&gt;&gt;numSort.Name" xml:space="preserve">
<value>numSort</value>
</data>
<data name="&gt;&gt;numSort.Type" xml:space="preserve">
<value>System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;numSort.Parent" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="&gt;&gt;numSort.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="btnRemove.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="btnRemove.Location" type="System.Drawing.Point, System.Drawing">
<value>525, 21</value>
</data>
<data name="txtRemarks.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 21</value>
</data>
<data name="&gt;&gt;btnRemove.Parent" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 25</value>
<data name="btnRemove.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
</data>
<data name="btnRemove.TabIndex" type="System.Int32, mscorlib">
<value>24</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
<data name="btnRemove.Text" xml:space="preserve">
<value>Remove</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>GroupSettingControl</value>
</data>
<data name="&gt;&gt;label2.Parent" xml:space="preserve">
<value>grbMain</value>
<data name="&gt;&gt;btnRemove.Name" xml:space="preserve">
<value>btnRemove</value>
</data>
<data name="&gt;&gt;btnRemove.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;grbMain.Name" xml:space="preserve">
<data name="&gt;&gt;btnRemove.Parent" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="&gt;&gt;label2.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<data name="&gt;&gt;btnRemove.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="txtRemarks.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 21</value>
</data>
<data name="txtRemarks.Size" type="System.Drawing.Size, System.Drawing">
<value>292, 21</value>
</data>
<data name="txtRemarks.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="&gt;&gt;txtRemarks.Name" xml:space="preserve">
<value>txtRemarks</value>
</data>
<data name="&gt;&gt;txtRemarks.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;txtRemarks.Parent" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="&gt;&gt;txtRemarks.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="label2.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="label2.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 25</value>
</data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>47, 12</value>
</data>
<data name="label2.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
</data>
<data name="label2.Text" xml:space="preserve">
<value>Remarks</value>
</data>
<data name="&gt;&gt;label2.Name" xml:space="preserve">
<value>label2</value>
</data>
<data name="btnRemove.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
<data name="&gt;&gt;label2.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;label2.Parent" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="grbMain.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="grbMain.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
<data name="grbMain.Size" type="System.Drawing.Size, System.Drawing">
<value>619, 61</value>
<value>619, 91</value>
</data>
<data name="label2.Text" xml:space="preserve">
<value>Remarks</value>
</data>
<data name="&gt;&gt;txtRemarks.Parent" xml:space="preserve">
<value>grbMain</value>
<data name="grbMain.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
</data>
<data name="grbMain.Text" xml:space="preserve">
<value>Group details</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="label2.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="txtRemarks.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
</data>
<data name="&gt;&gt;txtRemarks.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>47, 12</value>
</data>
<data name="&gt;&gt;txtRemarks.Name" xml:space="preserve">
<value>txtRemarks</value>
</data>
<data name="&gt;&gt;btnRemove.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="&gt;&gt;btnRemove.Name" xml:space="preserve">
<value>btnRemove</value>
</data>
<data name="grbMain.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="label2.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
</data>
<data name="label2.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="btnRemove.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
<data name="&gt;&gt;grbMain.Name" xml:space="preserve">
<value>grbMain</value>
</data>
<data name="&gt;&gt;grbMain.Type" xml:space="preserve">
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;txtRemarks.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="&gt;&gt;grbMain.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="$this.Size" type="System.Drawing.Size, System.Drawing">
<value>619, 61</value>
</data>
<data name="btnRemove.Text" xml:space="preserve">
<value>Remove</value>
<data name="&gt;&gt;grbMain.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 12</value>
</data>
<data name="$this.Size" type="System.Drawing.Size, System.Drawing">
<value>619, 91</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>GroupSettingControl</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
</root>

View File

@@ -130,4 +130,7 @@
<data name="grbMain.Text" xml:space="preserve">
<value>分组详情</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>排序编号</value>
</data>
</root>

View File

@@ -94,7 +94,6 @@
this.menuKeepNothing = new System.Windows.Forms.ToolStripMenuItem();
this.menuRoutings = new System.Windows.Forms.ToolStripMenuItem();
this.menuServers = new System.Windows.Forms.ToolStripMenuItem();
this.menuServers2 = new System.Windows.Forms.ToolStripComboBox();
this.toolStripSeparator13 = new System.Windows.Forms.ToolStripSeparator();
this.menuAddServers2 = new System.Windows.Forms.ToolStripMenuItem();
this.menuScanScreen2 = new System.Windows.Forms.ToolStripMenuItem();
@@ -126,8 +125,7 @@
this.tsbCheckUpdateCore = new System.Windows.Forms.ToolStripMenuItem();
this.tsbCheckUpdateXrayCore = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator15 = new System.Windows.Forms.ToolStripSeparator();
this.tsbCheckUpdateGeoSite = new System.Windows.Forms.ToolStripMenuItem();
this.tsbCheckUpdateGeoIP = new System.Windows.Forms.ToolStripMenuItem();
this.tsbCheckUpdateGeo = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator10 = new System.Windows.Forms.ToolStripSeparator();
this.tsbHelp = new System.Windows.Forms.ToolStripDropDownButton();
this.tsbAbout = new System.Windows.Forms.ToolStripMenuItem();
@@ -586,7 +584,6 @@
this.menuSysAgentMode,
this.menuRoutings,
this.menuServers,
this.menuServers2,
this.toolStripSeparator13,
this.menuAddServers2,
this.menuScanScreen2,
@@ -636,14 +633,6 @@
this.menuServers.Name = "menuServers";
resources.ApplyResources(this.menuServers, "menuServers");
//
// menuServers2
//
this.menuServers2.BackColor = System.Drawing.SystemColors.Window;
this.menuServers2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.menuServers2.DropDownWidth = 500;
resources.ApplyResources(this.menuServers2, "menuServers2");
this.menuServers2.Name = "menuServers2";
//
// toolStripSeparator13
//
this.toolStripSeparator13.Name = "toolStripSeparator13";
@@ -831,8 +820,7 @@
this.tsbCheckUpdateCore,
this.tsbCheckUpdateXrayCore,
this.toolStripSeparator15,
this.tsbCheckUpdateGeoSite,
this.tsbCheckUpdateGeoIP});
this.tsbCheckUpdateGeo});
this.tsbCheckUpdate.Image = global::v2rayN.Properties.Resources.checkupdate;
resources.ApplyResources(this.tsbCheckUpdate, "tsbCheckUpdate");
this.tsbCheckUpdate.Name = "tsbCheckUpdate";
@@ -860,17 +848,11 @@
this.toolStripSeparator15.Name = "toolStripSeparator15";
resources.ApplyResources(this.toolStripSeparator15, "toolStripSeparator15");
//
// tsbCheckUpdateGeoSite
// tsbCheckUpdateGeo
//
this.tsbCheckUpdateGeoSite.Name = "tsbCheckUpdateGeoSite";
resources.ApplyResources(this.tsbCheckUpdateGeoSite, "tsbCheckUpdateGeoSite");
this.tsbCheckUpdateGeoSite.Click += new System.EventHandler(this.tsbCheckUpdateGeoSite_Click);
//
// tsbCheckUpdateGeoIP
//
this.tsbCheckUpdateGeoIP.Name = "tsbCheckUpdateGeoIP";
resources.ApplyResources(this.tsbCheckUpdateGeoIP, "tsbCheckUpdateGeoIP");
this.tsbCheckUpdateGeoIP.Click += new System.EventHandler(this.tsbCheckUpdateGeoIP_Click);
this.tsbCheckUpdateGeo.Name = "tsbCheckUpdateGeo";
resources.ApplyResources(this.tsbCheckUpdateGeo, "tsbCheckUpdateGeo");
this.tsbCheckUpdateGeo.Click += new System.EventHandler(this.tsbCheckUpdateGeo_Click);
//
// toolStripSeparator10
//
@@ -1071,14 +1053,12 @@
private System.Windows.Forms.ToolStripSeparator toolStripSeparator14;
private System.Windows.Forms.ToolStripMenuItem tsbBackupGuiNConfig;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator15;
private System.Windows.Forms.ToolStripMenuItem tsbCheckUpdateGeoSite;
private System.Windows.Forms.ToolStripMenuItem tsbCheckUpdateGeoIP;
private System.Windows.Forms.ToolStripMenuItem tsbCheckUpdateGeo;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.ToolStripMenuItem menuMsgBoxFilter;
private System.Windows.Forms.ToolStripStatusLabel toolSslInboundInfo;
private System.Windows.Forms.ToolStripStatusLabel toolSslRoutingRule;
private System.Windows.Forms.ToolStripStatusLabel toolSslBlank2;
private System.Windows.Forms.ToolStripComboBox menuServers2;
private System.Windows.Forms.ToolStripMenuItem tsbSubUpdateViaProxy;
private System.Windows.Forms.ToolStripMenuItem menuUpdateSubViaProxy;
private System.Windows.Forms.ToolStripMenuItem menuMsgBoxClear;

View File

@@ -83,12 +83,12 @@ namespace v2rayN.Forms
RefreshRoutingsMenu();
RestoreUI();
_ = LoadV2ray();
HideForm();
MainFormHandler.Instance.UpdateTask(config, UpdateTaskHandler);
MainFormHandler.Instance.RegisterGlobalHotkey(config, OnHotkeyHandler, UpdateTaskHandler);
_ = LoadV2ray();
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
@@ -347,31 +347,13 @@ namespace v2rayN.Forms
private void RefreshServersMenu()
{
menuServers.DropDownItems.Clear();
menuServers2.SelectedIndexChanged -= MenuServers2_SelectedIndexChanged;
menuServers2.Items.Clear();
menuServers.Visible = false;
menuServers2.Visible = false;
if (lstVmess.Count > 20)
if (lstVmess.Count > 30)
{
for (int k = 0; k < lstVmess.Count; k++)
{
VmessItem item = lstVmess[k];
string name = item.GetSummary();
menuServers.DropDownItems.Add(new ToolStripMenuItem(ResUI.TooManyServersTip));
return;
}
if (config.IsActiveNode(item))
{
name = $"√ {name}";
}
menuServers2.Items.Add(name);
}
menuServers2.SelectedIndex = lstVmess.FindIndex(it => it.indexId == config.indexId);
menuServers2.SelectedIndexChanged += MenuServers2_SelectedIndexChanged;
menuServers2.Visible = true;
}
else
{
List<ToolStripMenuItem> lst = new List<ToolStripMenuItem>();
for (int k = 0; k < lstVmess.Count; k++)
{
@@ -392,12 +374,6 @@ namespace v2rayN.Forms
menuServers.DropDownItems.AddRange(lst.ToArray());
menuServers.Visible = true;
}
}
private void MenuServers2_SelectedIndexChanged(object sender, EventArgs e)
{
SetDefaultServer(((ToolStripComboBox)sender).SelectedIndex);
}
private void ts_Click(object sender, EventArgs e)
{
@@ -472,7 +448,7 @@ namespace v2rayN.Forms
tabPage.Name = "";
tabGroup.TabPages.Add(tabPage);
foreach (var item in config.groupItem)
foreach (var item in config.groupItem.OrderBy(t => t.sort))
{
var tabPage2 = new TabPage($" {item.remarks} ");
tabPage2.Name = item.id;
@@ -539,13 +515,15 @@ namespace v2rayN.Forms
#endregion
#region v2ray
/// <summary>
/// 载入V2ray
/// </summary>
async Task LoadV2ray()
{
this.BeginInvoke(new Action(() =>
{
tsbReload.Enabled = false;
}));
if (Global.reloadV2ray)
{
@@ -562,7 +540,10 @@ namespace v2rayN.Forms
ChangePACButtonStatus(config.sysProxyType);
this.BeginInvoke(new Action(() =>
{
tsbReload.Enabled = true;
}));
}
/// <summary>
@@ -781,13 +762,12 @@ namespace v2rayN.Forms
{
if (GetLvSelectedIndex() < 0) return;
ClearTestResult();
SpeedtestHandler statistics = new SpeedtestHandler(ref config, v2rayHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
SpeedtestHandler statistics = new SpeedtestHandler(config, v2rayHandler, lstSelecteds, actionType, UpdateSpeedtestHandler);
}
private void tsbTestMe_Click(object sender, EventArgs e)
{
SpeedtestHandler statistics = new SpeedtestHandler(ref config);
string result = statistics.RunAvailabilityCheck() + "ms";
string result = (new DownloadHandle()).RunAvailabilityCheck(null) + "ms";
AppendText(false, string.Format(ResUI.TestMeOutput, result));
}
@@ -882,9 +862,9 @@ namespace v2rayN.Forms
var fm = new GlobalHotkeySettingForm();
if (fm.ShowDialog() == DialogResult.OK)
{
RefreshRoutingsMenu();
RefreshServers();
_ = LoadV2ray();
//RefreshRoutingsMenu();
//RefreshServers();
//_ = LoadV2ray();
}
}
@@ -1197,6 +1177,10 @@ namespace v2rayN.Forms
lstVmess[k].testResult = txt;
lvServers.Items[k].SubItems["testResult"].Text = txt;
}
else
{
AppendText(false, txt);
}
}
private void SetTestResult(int k, string txt)
{
@@ -1256,13 +1240,13 @@ namespace v2rayN.Forms
}
}
private void UpdateTaskHandler(bool success, string msg)
private async void UpdateTaskHandler(bool success, string msg)
{
AppendText(false, msg);
if (success)
{
Global.reloadV2ray = true;
_ = LoadV2ray();
await LoadV2ray();
}
}
#endregion
@@ -1418,31 +1402,16 @@ namespace v2rayN.Forms
(new UpdateHandle()).CheckUpdateCore(type, config, _updateUI);
}
private void tsbCheckUpdateGeoSite_Click(object sender, EventArgs e)
private void tsbCheckUpdateGeo_Click(object sender, EventArgs e)
{
(new UpdateHandle()).UpdateGeoFile("geosite", config, (bool success, string msg) =>
Task.Run(() =>
{
AppendText(false, msg);
if (success)
{
Global.reloadV2ray = true;
_ = LoadV2ray();
}
var updateHandle = new UpdateHandle();
updateHandle.UpdateGeoFile("geosite", config, UpdateTaskHandler);
updateHandle.UpdateGeoFile("geoip", config, UpdateTaskHandler);
});
}
private void tsbCheckUpdateGeoIP_Click(object sender, EventArgs e)
{
(new UpdateHandle()).UpdateGeoFile("geoip", config, (bool success, string msg) =>
{
AppendText(false, msg);
if (success)
{
Global.reloadV2ray = true;
_ = LoadV2ray();
}
});
}
#endregion
#region Help

View File

@@ -321,7 +321,7 @@
<value>ImageAboveText</value>
</data>
<data name="cmsLv.Size" type="System.Drawing.Size, System.Drawing">
<value>356, 666</value>
<value>356, 644</value>
</data>
<data name="&gt;&gt;cmsLv.Name" xml:space="preserve">
<value>cmsLv</value>
@@ -750,73 +750,61 @@
<value>Do not change system proxy</value>
</data>
<data name="menuSysAgentMode.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuSysAgentMode.Text" xml:space="preserve">
<value>System proxy</value>
</data>
<data name="menuRoutings.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuRoutings.Text" xml:space="preserve">
<value>Routing</value>
</data>
<data name="menuServers.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuServers.Text" xml:space="preserve">
<value>Server</value>
</data>
<data name="menuServers2.FlatStyle" type="System.Windows.Forms.FlatStyle, System.Windows.Forms">
<value>Standard</value>
</data>
<data name="menuServers2.MaxDropDownItems" type="System.Int32, mscorlib">
<value>50</value>
</data>
<data name="menuServers2.Size" type="System.Drawing.Size, System.Drawing">
<value>200, 25</value>
</data>
<data name="menuServers2.ToolTipText" xml:space="preserve">
<value>Server</value>
</data>
<data name="toolStripSeparator13.Size" type="System.Drawing.Size, System.Drawing">
<value>261, 6</value>
<value>274, 6</value>
</data>
<data name="menuAddServers2.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuAddServers2.Text" xml:space="preserve">
<value>Import bulk URL from clipboard</value>
</data>
<data name="menuScanScreen2.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuScanScreen2.Text" xml:space="preserve">
<value>Scan QR code on the screen</value>
</data>
<data name="menuUpdateSubscriptions.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuUpdateSubscriptions.Text" xml:space="preserve">
<value>Update subscription without proxy</value>
</data>
<data name="menuUpdateSubViaProxy.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuUpdateSubViaProxy.Text" xml:space="preserve">
<value>Update subscriptions via proxy</value>
</data>
<data name="toolStripSeparator2.Size" type="System.Drawing.Size, System.Drawing">
<value>261, 6</value>
<value>274, 6</value>
</data>
<data name="menuExit.Size" type="System.Drawing.Size, System.Drawing">
<value>264, 22</value>
<value>277, 22</value>
</data>
<data name="menuExit.Text" xml:space="preserve">
<value>Exit</value>
</data>
<data name="cmsMain.Size" type="System.Drawing.Size, System.Drawing">
<value>265, 221</value>
<value>278, 192</value>
</data>
<data name="&gt;&gt;cmsMain.Name" xml:space="preserve">
<value>cmsMain</value>
@@ -861,19 +849,19 @@
<value>6, 56</value>
</data>
<data name="tsbSubSetting.Size" type="System.Drawing.Size, System.Drawing">
<value>182, 22</value>
<value>277, 22</value>
</data>
<data name="tsbSubSetting.Text" xml:space="preserve">
<value>Settings</value>
</data>
<data name="tsbSubUpdate.Size" type="System.Drawing.Size, System.Drawing">
<value>182, 22</value>
<value>277, 22</value>
</data>
<data name="tsbSubUpdate.Text" xml:space="preserve">
<value>Update subscription without proxy</value>
</data>
<data name="tsbSubUpdateViaProxy.Size" type="System.Drawing.Size, System.Drawing">
<value>182, 22</value>
<value>277, 22</value>
</data>
<data name="tsbSubUpdateViaProxy.Text" xml:space="preserve">
<value>Update subscription with proxy</value>
@@ -995,17 +983,11 @@
<data name="toolStripSeparator15.Size" type="System.Drawing.Size, System.Drawing">
<value>200, 6</value>
</data>
<data name="tsbCheckUpdateGeoSite.Size" type="System.Drawing.Size, System.Drawing">
<data name="tsbCheckUpdateGeo.Size" type="System.Drawing.Size, System.Drawing">
<value>203, 22</value>
</data>
<data name="tsbCheckUpdateGeoSite.Text" xml:space="preserve">
<value>Update GeoSite</value>
</data>
<data name="tsbCheckUpdateGeoIP.Size" type="System.Drawing.Size, System.Drawing">
<value>203, 22</value>
</data>
<data name="tsbCheckUpdateGeoIP.Text" xml:space="preserve">
<value>Update GeoIP</value>
<data name="tsbCheckUpdateGeo.Text" xml:space="preserve">
<value>Update Geo files</value>
</data>
<data name="tsbCheckUpdate.ImageTransparentColor" type="System.Drawing.Color, System.Drawing">
<value>Magenta</value>
@@ -1439,12 +1421,6 @@
<data name="&gt;&gt;menuServers.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;menuServers2.Name" xml:space="preserve">
<value>menuServers2</value>
</data>
<data name="&gt;&gt;menuServers2.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripSeparator13.Name" xml:space="preserve">
<value>toolStripSeparator13</value>
</data>
@@ -1619,16 +1595,10 @@
<data name="&gt;&gt;toolStripSeparator15.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripSeparator, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tsbCheckUpdateGeoSite.Name" xml:space="preserve">
<value>tsbCheckUpdateGeoSite</value>
<data name="&gt;&gt;tsbCheckUpdateGeo.Name" xml:space="preserve">
<value>tsbCheckUpdateGeo</value>
</data>
<data name="&gt;&gt;tsbCheckUpdateGeoSite.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;tsbCheckUpdateGeoIP.Name" xml:space="preserve">
<value>tsbCheckUpdateGeoIP</value>
</data>
<data name="&gt;&gt;tsbCheckUpdateGeoIP.Type" xml:space="preserve">
<data name="&gt;&gt;tsbCheckUpdateGeo.Type" xml:space="preserve">
<value>System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;toolStripSeparator10.Name" xml:space="preserve">

View File

@@ -114,33 +114,34 @@
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
resources.ApplyResources(this.btnClose, "btnClose");
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Name = "btnClose";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// tabControl1
//
resources.ApplyResources(this.tabControl1, "tabControl1");
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Controls.Add(this.tabPage6);
this.tabControl1.Controls.Add(this.tabPage7);
this.tabControl1.Controls.Add(this.tabPageCoreType);
this.tabControl1.Controls.Add(this.tabPage3);
resources.ApplyResources(this.tabControl1, "tabControl1");
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.groupBox1);
resources.ApplyResources(this.tabPage1, "tabPage1");
this.tabPage1.Controls.Add(this.groupBox1);
this.tabPage1.Name = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// groupBox1
//
resources.ApplyResources(this.groupBox1, "groupBox1");
this.groupBox1.Controls.Add(this.label16);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.txtpass);
@@ -157,7 +158,6 @@
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Controls.Add(this.txtlocalPort);
this.groupBox1.Controls.Add(this.label2);
resources.ApplyResources(this.groupBox1, "groupBox1");
this.groupBox1.Name = "groupBox1";
this.groupBox1.TabStop = false;
//
@@ -207,8 +207,8 @@
//
// cmbprotocol
//
this.cmbprotocol.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
resources.ApplyResources(this.cmbprotocol, "cmbprotocol");
this.cmbprotocol.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbprotocol.FormattingEnabled = true;
this.cmbprotocol.Items.AddRange(new object[] {
resources.GetString("cmbprotocol.Items"),
@@ -234,6 +234,7 @@
//
// cmbloglevel
//
resources.ApplyResources(this.cmbloglevel, "cmbloglevel");
this.cmbloglevel.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbloglevel.FormattingEnabled = true;
this.cmbloglevel.Items.AddRange(new object[] {
@@ -242,7 +243,6 @@
resources.GetString("cmbloglevel.Items2"),
resources.GetString("cmbloglevel.Items3"),
resources.GetString("cmbloglevel.Items4")});
resources.ApplyResources(this.cmbloglevel, "cmbloglevel");
this.cmbloglevel.Name = "cmbloglevel";
//
// label5
@@ -262,10 +262,10 @@
//
// tabPage2
//
resources.ApplyResources(this.tabPage2, "tabPage2");
this.tabPage2.Controls.Add(this.linkDnsObjectDoc);
this.tabPage2.Controls.Add(this.txtremoteDNS);
this.tabPage2.Controls.Add(this.label14);
resources.ApplyResources(this.tabPage2, "tabPage2");
this.tabPage2.Name = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
@@ -288,6 +288,7 @@
//
// tabPage6
//
resources.ApplyResources(this.tabPage6, "tabPage6");
this.tabPage6.Controls.Add(this.chkKcpcongestion);
this.tabPage6.Controls.Add(this.txtKcpwriteBufferSize);
this.tabPage6.Controls.Add(this.label10);
@@ -301,7 +302,6 @@
this.tabPage6.Controls.Add(this.label7);
this.tabPage6.Controls.Add(this.txtKcpmtu);
this.tabPage6.Controls.Add(this.label6);
resources.ApplyResources(this.tabPage6, "tabPage6");
this.tabPage6.Name = "tabPage6";
this.tabPage6.UseVisualStyleBackColor = true;
//
@@ -373,6 +373,7 @@
//
// tabPage7
//
resources.ApplyResources(this.tabPage7, "tabPage7");
this.tabPage7.Controls.Add(this.chkEnableSecurityProtocolTls13);
this.tabPage7.Controls.Add(this.chkEnableAutoAdjustMainLvColWidth);
this.tabPage7.Controls.Add(this.btnSetLoopback);
@@ -384,7 +385,6 @@
this.tabPage7.Controls.Add(this.lbFreshrate);
this.tabPage7.Controls.Add(this.chkEnableStatistics);
this.tabPage7.Controls.Add(this.chkAutoRun);
resources.ApplyResources(this.tabPage7, "tabPage7");
this.tabPage7.Name = "tabPage7";
this.tabPage7.UseVisualStyleBackColor = true;
//
@@ -431,9 +431,9 @@
//
// cbFreshrate
//
resources.ApplyResources(this.cbFreshrate, "cbFreshrate");
this.cbFreshrate.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cbFreshrate.FormattingEnabled = true;
resources.ApplyResources(this.cbFreshrate, "cbFreshrate");
this.cbFreshrate.Name = "cbFreshrate";
//
// lbFreshrate
@@ -455,6 +455,7 @@
//
// tabPageCoreType
//
resources.ApplyResources(this.tabPageCoreType, "tabPageCoreType");
this.tabPageCoreType.Controls.Add(this.cmbCoreType6);
this.tabPageCoreType.Controls.Add(this.labCoreType6);
this.tabPageCoreType.Controls.Add(this.cmbCoreType5);
@@ -467,15 +468,14 @@
this.tabPageCoreType.Controls.Add(this.labCoreType2);
this.tabPageCoreType.Controls.Add(this.cmbCoreType1);
this.tabPageCoreType.Controls.Add(this.labCoreType1);
resources.ApplyResources(this.tabPageCoreType, "tabPageCoreType");
this.tabPageCoreType.Name = "tabPageCoreType";
this.tabPageCoreType.UseVisualStyleBackColor = true;
//
// cmbCoreType6
//
resources.ApplyResources(this.cmbCoreType6, "cmbCoreType6");
this.cmbCoreType6.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType6.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType6, "cmbCoreType6");
this.cmbCoreType6.Name = "cmbCoreType6";
//
// labCoreType6
@@ -485,9 +485,9 @@
//
// cmbCoreType5
//
resources.ApplyResources(this.cmbCoreType5, "cmbCoreType5");
this.cmbCoreType5.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType5.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType5, "cmbCoreType5");
this.cmbCoreType5.Name = "cmbCoreType5";
//
// labCoreType5
@@ -497,9 +497,9 @@
//
// cmbCoreType4
//
resources.ApplyResources(this.cmbCoreType4, "cmbCoreType4");
this.cmbCoreType4.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType4.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType4, "cmbCoreType4");
this.cmbCoreType4.Name = "cmbCoreType4";
//
// labCoreType4
@@ -509,9 +509,9 @@
//
// cmbCoreType3
//
resources.ApplyResources(this.cmbCoreType3, "cmbCoreType3");
this.cmbCoreType3.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType3.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType3, "cmbCoreType3");
this.cmbCoreType3.Name = "cmbCoreType3";
//
// labCoreType3
@@ -521,9 +521,9 @@
//
// cmbCoreType2
//
resources.ApplyResources(this.cmbCoreType2, "cmbCoreType2");
this.cmbCoreType2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType2.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType2, "cmbCoreType2");
this.cmbCoreType2.Name = "cmbCoreType2";
//
// labCoreType2
@@ -533,9 +533,9 @@
//
// cmbCoreType1
//
resources.ApplyResources(this.cmbCoreType1, "cmbCoreType1");
this.cmbCoreType1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType1.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType1, "cmbCoreType1");
this.cmbCoreType1.Name = "cmbCoreType1";
//
// labCoreType1
@@ -545,17 +545,17 @@
//
// tabPage3
//
this.tabPage3.Controls.Add(this.groupBox2);
resources.ApplyResources(this.tabPage3, "tabPage3");
this.tabPage3.Controls.Add(this.groupBox2);
this.tabPage3.Name = "tabPage3";
this.tabPage3.UseVisualStyleBackColor = true;
//
// groupBox2
//
resources.ApplyResources(this.groupBox2, "groupBox2");
this.groupBox2.Controls.Add(this.label13);
this.groupBox2.Controls.Add(this.label12);
this.groupBox2.Controls.Add(this.txtsystemProxyExceptions);
resources.ApplyResources(this.groupBox2, "groupBox2");
this.groupBox2.Name = "groupBox2";
this.groupBox2.TabStop = false;
//
@@ -576,9 +576,9 @@
//
// panel2
//
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Controls.Add(this.btnClose);
this.panel2.Controls.Add(this.btnOK);
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Name = "panel2";
//
// btnOK

File diff suppressed because it is too large Load Diff

View File

@@ -121,6 +121,18 @@
<value>取消(&amp;C)</value>
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="tabControl1.Size" type="System.Drawing.Size, System.Drawing">
<value>662, 469</value>
</data>
<data name="tabPage1.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage1.Text" xml:space="preserve">
<value> Core:基础设置 </value>
</data>
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
<value>648, 437</value>
</data>
<data name="label16.Size" type="System.Drawing.Size, System.Drawing">
<value>53, 12</value>
</data>
@@ -145,15 +157,6 @@
<data name="chkdefAllowInsecure.Text" xml:space="preserve">
<value>传输层安全选tls时默认跳过证书验证(allowInsecure)</value>
</data>
<data name="chksniffingEnabled2.Location" type="System.Drawing.Point, System.Drawing">
<value>468, 117</value>
</data>
<data name="chksniffingEnabled2.Size" type="System.Drawing.Size, System.Drawing">
<value>96, 16</value>
</data>
<data name="chksniffingEnabled2.Text" xml:space="preserve">
<value>开启流量探测</value>
</data>
<data name="chkAllowLANConn.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 16</value>
</data>
@@ -175,39 +178,6 @@
<data name="chkmuxEnabled.Text" xml:space="preserve">
<value>开启Mux多路复用</value>
</data>
<data name="chkAllowIn2.Location" type="System.Drawing.Point, System.Drawing">
<value>15, 120</value>
</data>
<data name="chkAllowIn2.Size" type="System.Drawing.Size, System.Drawing">
<value>102, 16</value>
</data>
<data name="chkAllowIn2.Text" xml:space="preserve">
<value>本地监听端口2</value>
</data>
<data name="chkudpEnabled2.Location" type="System.Drawing.Point, System.Drawing">
<value>369, 119</value>
</data>
<data name="chkudpEnabled2.Size" type="System.Drawing.Size, System.Drawing">
<value>66, 16</value>
</data>
<data name="chkudpEnabled2.Text" xml:space="preserve">
<value>开启UDP</value>
</data>
<data name="cmbprotocol2.Location" type="System.Drawing.Point, System.Drawing">
<value>257, 117</value>
</data>
<data name="label3.Location" type="System.Drawing.Point, System.Drawing">
<value>206, 121</value>
</data>
<data name="label3.Size" type="System.Drawing.Size, System.Drawing">
<value>29, 12</value>
</data>
<data name="label3.Text" xml:space="preserve">
<value>协议</value>
</data>
<data name="txtlocalPort2.Location" type="System.Drawing.Point, System.Drawing">
<value>124, 117</value>
</data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>219, 29</value>
</data>
@@ -250,14 +220,11 @@
<data name="label2.Text" xml:space="preserve">
<value>本地监听端口</value>
</data>
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
<value>648, 437</value>
</data>
<data name="tabPage1.Size" type="System.Drawing.Size, System.Drawing">
<data name="tabPage2.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage1.Text" xml:space="preserve">
<value> Core:基础设置 </value>
<data name="tabPage2.Text" xml:space="preserve">
<value> Core:DNS设置 </value>
</data>
<data name="linkDnsObjectDoc.Size" type="System.Drawing.Size, System.Drawing">
<value>161, 12</value>
@@ -271,18 +238,18 @@
<data name="label14.Text" xml:space="preserve">
<value>自定义DNS(可多个,用逗号(,)隔开)</value>
</data>
<data name="tabPage2.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage2.Text" xml:space="preserve">
<value> Core:DNS设置 </value>
</data>
<data name="tabPage6.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage6.Text" xml:space="preserve">
<value> Core:KCP设置 </value>
</data>
<data name="tabPage7.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage7.Text" xml:space="preserve">
<value> v2rayN设置 </value>
</data>
<data name="chkEnableSecurityProtocolTls13.Text" xml:space="preserve">
<value>启用安全协议TLS v1.3 (订阅/检查更新/测速)</value>
</data>
@@ -296,13 +263,13 @@
<value>解除Windows10 UWP应用回环代理限制</value>
</data>
<data name="txtautoUpdateInterval.Location" type="System.Drawing.Point, System.Drawing">
<value>255, 156</value>
<value>274, 134</value>
</data>
<data name="label15.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 12</value>
<value>227, 12</value>
</data>
<data name="label15.Text" xml:space="preserve">
<value>自动更新Geo文件的间隔(单位小时)</value>
<value>自动更新订阅和Geo文件的间隔(单位小时)</value>
</data>
<data name="chkIgnoreGeoUpdateCore.Size" type="System.Drawing.Size, System.Drawing">
<value>150, 16</value>
@@ -334,18 +301,24 @@
<data name="chkAutoRun.Text" xml:space="preserve">
<value>开机自动启动(可能会不成功)</value>
</data>
<data name="tabPage7.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage7.Text" xml:space="preserve">
<value> v2rayN设置 </value>
</data>
<data name="tabPageCoreType.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPageCoreType.Text" xml:space="preserve">
<value> Core类型设置 </value>
</data>
<data name="tabPage3.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage3.Text" xml:space="preserve">
<value> 系统代理设置 </value>
</data>
<data name="groupBox2.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="groupBox2.Text" xml:space="preserve">
<value>例外</value>
</data>
<data name="label13.Size" type="System.Drawing.Size, System.Drawing">
<value>95, 12</value>
</data>
@@ -358,30 +331,15 @@
<data name="label12.Text" xml:space="preserve">
<value>对于下列字符开头的地址不使用代理服务器:</value>
</data>
<data name="groupBox2.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="groupBox2.Text" xml:space="preserve">
<value>例外</value>
</data>
<data name="tabPage3.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="tabPage3.Text" xml:space="preserve">
<value> 系统代理设置 </value>
</data>
<data name="tabControl1.Size" type="System.Drawing.Size, System.Drawing">
<value>662, 469</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>确定(&amp;O)</value>
</data>
<data name="panel2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 479</value>
</data>
<data name="panel2.Size" type="System.Drawing.Size, System.Drawing">
<value>662, 60</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>确定(&amp;O)</value>
</data>
<data name="panel1.Size" type="System.Drawing.Size, System.Drawing">
<value>662, 10</value>
</data>

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using v2rayN.Base;
using v2rayN.Handler;
@@ -345,13 +346,17 @@ namespace v2rayN.Forms
UI.Show(ResUI.MsgNeedUrl);
return;
}
Task.Run(async () =>
{
DownloadHandle downloadHandle = new DownloadHandle();
string clipboardData = downloadHandle.WebDownloadStringSync(url);
if (AddBatchRoutingRules(ref routingItem, clipboardData) == 0)
string result = await downloadHandle.DownloadStringAsync(url, false, "");
if (AddBatchRoutingRules(ref routingItem, result) == 0)
{
RefreshRoutingsView();
UI.Show(ResUI.OperationSuccess);
}
});
}
private int AddBatchRoutingRules(ref RoutingItem routingItem, string clipboardData)
{
@@ -363,8 +368,6 @@ namespace v2rayN.Forms
return ConfigHandler.AddBatchRoutingRules(ref routingItem, clipboardData, blReplace);
}
#endregion
}

View File

@@ -1,7 +1,12 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using v2rayN.Base;
using v2rayN.Resx;
@@ -29,32 +34,71 @@ namespace v2rayN.Handler
}
}
private int progressPercentage = -1;
private long totalBytesToReceive = 0;
private DateTime totalDatetime = new DateTime();
private int DownloadTimeout = -1;
public WebClientEx DownloadFileAsync(string url, WebProxy webProxy, int downloadTimeout)
public async Task<int> DownloadDataAsync(string url, WebProxy webProxy, int downloadTimeout)
{
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Speedtesting));
var client = new HttpClient(new WebRequestHandler()
{
Proxy = webProxy
});
var progress = new Progress<double>();
progress.ProgressChanged += (sender, value) =>
{
if (UpdateCompleted != null)
{
string msg = string.Format("{0} M/s", value.ToString("#0.0")).PadLeft(9, ' ');
UpdateCompleted(this, new ResultEventArgs(false, msg));
}
};
var cancellationToken = new CancellationTokenSource();
cancellationToken.CancelAfter(downloadTimeout * 1000);
await HttpClientHelper.GetInstance().DownloadDataAsync4Speed(client,
url,
progress,
cancellationToken.Token);
}
catch (Exception ex)
{
//Utils.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex));
}
return 0;
}
public void DownloadFileAsync(string url, bool blProxy, int downloadTimeout)
{
WebClientEx ws = new WebClientEx();
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Downloading));
progressPercentage = -1;
totalBytesToReceive = 0;
//WebClientEx ws = new WebClientEx();
DownloadTimeout = downloadTimeout;
if (webProxy != null)
var client = new HttpClient(new WebRequestHandler()
{
ws.Proxy = webProxy;// new WebProxy(Global.Loopback, Global.httpPort);
}
Proxy = GetWebProxy(blProxy)
});
ws.DownloadFileCompleted += ws_DownloadFileCompleted;
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(Utils.GetDownloadFileName(url)));
var progress = new Progress<double>();
progress.ProgressChanged += (sender, value) =>
{
if (UpdateCompleted != null)
{
string msg = string.Format("...{0}%", value);
UpdateCompleted(this, new ResultEventArgs(value > 100 ? true : false, msg));
}
};
var cancellationToken = new CancellationTokenSource();
_ = HttpClientHelper.GetInstance().DownloadFileAsync(client,
url,
Utils.GetPath(Utils.GetDownloadFileName(url)),
progress,
cancellationToken.Token);
}
catch (Exception ex)
{
@@ -62,70 +106,27 @@ namespace v2rayN.Handler
Error?.Invoke(this, new ErrorEventArgs(ex));
}
return ws;
}
void ws_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
public async Task<string> UrlRedirectAsync(string url, bool blProxy)
{
if (UpdateCompleted != null)
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
WebRequestHandler webRequestHandler = new WebRequestHandler
{
if (totalBytesToReceive == 0)
{
totalDatetime = DateTime.Now;
totalBytesToReceive = e.BytesReceived;
return;
}
totalBytesToReceive = e.BytesReceived;
AllowAutoRedirect = false,
Proxy = GetWebProxy(blProxy)
};
HttpClient client = new HttpClient(webRequestHandler);
if (DownloadTimeout != -1)
HttpResponseMessage response = await client.GetAsync(url);
if (response.StatusCode.ToString() == "Redirect")
{
if ((DateTime.Now - totalDatetime).TotalSeconds > DownloadTimeout)
{
((WebClientEx)sender).CancelAsync();
}
}
if (progressPercentage != e.ProgressPercentage && e.ProgressPercentage % 10 == 0)
{
progressPercentage = e.ProgressPercentage;
string msg = string.Format("...{0}%", e.ProgressPercentage);
UpdateCompleted(this, new ResultEventArgs(false, msg));
}
}
}
void ws_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
try
{
if (UpdateCompleted != null)
{
if (e.Cancelled)
{
((WebClientEx)sender).Dispose();
TimeSpan ts = (DateTime.Now - totalDatetime);
string speed = string.Format("{0} M/s", (totalBytesToReceive / ts.TotalMilliseconds / 1000).ToString("#0.0"));
UpdateCompleted(this, new ResultEventArgs(true, speed.PadLeft(8, ' ')));
return;
}
if (e.Error == null
|| Utils.IsNullOrEmpty(e.Error.ToString()))
{
((WebClientEx)sender).Dispose();
TimeSpan ts = (DateTime.Now - totalDatetime);
string speed = string.Format("{0} M/s", (totalBytesToReceive / ts.TotalMilliseconds / 1000).ToString("#0.0"));
UpdateCompleted(this, new ResultEventArgs(true, speed.PadLeft(8, ' ')));
return response.Headers.Location.ToString();
}
else
{
throw e.Error;
}
}
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex));
Utils.SaveLog("StatusCode error: " + url);
return null;
}
}
@@ -133,111 +134,117 @@ namespace v2rayN.Handler
/// DownloadString
/// </summary>
/// <param name="url"></param>
public void WebDownloadString(string url, WebProxy webProxy, string userAgent)
public async Task<string> DownloadStringAsync(string url, bool blProxy, string userAgent)
{
string source = string.Empty;
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
WebClientEx ws = new WebClientEx();
ws.Encoding = Encoding.UTF8;
if (webProxy != null)
var client = new HttpClient(new WebRequestHandler()
{
ws.Proxy = webProxy;
}
Proxy = GetWebProxy(blProxy)
});
if (Utils.IsNullOrEmpty(userAgent))
{
userAgent = $"{Utils.GetVersion(false)}";
}
ws.Headers.Add("user-agent", userAgent);
client.DefaultRequestHeaders.UserAgent.TryParseAdd(userAgent);
Uri uri = new Uri(url);
//Authorization Header
if (!Utils.IsNullOrEmpty(uri.UserInfo))
{
ws.Headers.Add(HttpRequestHeader.Authorization, "Basic " + Utils.Base64Encode(uri.UserInfo));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
}
ws.DownloadStringCompleted += Ws_DownloadStringCompleted;
ws.DownloadStringAsync(uri);
var result = await HttpClientHelper.GetInstance().GetAsync(client, url);
return result;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
}
return null;
}
private void Ws_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
public int RunAvailabilityCheck(WebProxy webProxy)
{
try
{
if (e.Error == null
|| Utils.IsNullOrEmpty(e.Error.ToString()))
if (webProxy == null)
{
string source = e.Result;
UpdateCompleted?.Invoke(this, new ResultEventArgs(true, source));
}
else
{
throw e.Error;
}
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
Error?.Invoke(this, new ErrorEventArgs(ex));
}
var httpPort = LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp2);
webProxy = new WebProxy(Global.Loopback, httpPort);
}
public string WebDownloadStringSync(string url)
Task<int> t = Task.Run(() =>
{
string source = string.Empty;
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
WebClientEx ws = new WebClientEx();
ws.Encoding = Encoding.UTF8;
return ws.DownloadString(new Uri(url));
string status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out int responseTime);
bool noError = Utils.IsNullOrEmpty(status);
return noError ? responseTime : -1;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return string.Empty;
return -1;
}
});
return t.Result;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return -1;
}
}
public WebClientEx DownloadDataAsync(string url, WebProxy webProxy, int downloadTimeout)
public string GetRealPingTime(string url, WebProxy webProxy, out int responseTime)
{
WebClientEx ws = new WebClientEx();
string msg = string.Empty;
responseTime = -1;
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
UpdateCompleted?.Invoke(this, new ResultEventArgs(false, ResUI.Downloading));
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.Timeout = 5000;
myHttpWebRequest.Proxy = webProxy;
progressPercentage = -1;
totalBytesToReceive = 0;
Stopwatch timer = new Stopwatch();
timer.Start();
DownloadTimeout = downloadTimeout;
if (webProxy != null)
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode != HttpStatusCode.OK
&& myHttpWebResponse.StatusCode != HttpStatusCode.NoContent)
{
ws.Proxy = webProxy;
msg = myHttpWebResponse.StatusDescription;
}
timer.Stop();
responseTime = timer.Elapsed.Milliseconds;
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
ws.DownloadDataCompleted += ws_DownloadFileCompleted;
ws.DownloadDataAsync(new Uri(url));
myHttpWebResponse.Close();
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
msg = ex.Message;
}
return msg;
}
Error?.Invoke(this, new ErrorEventArgs(ex));
private WebProxy GetWebProxy(bool blProxy)
{
if (!blProxy)
{
return null;
}
return ws;
var httpPort = LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp2);
var webProxy = new WebProxy(Global.Loopback, httpPort);
if (RunAvailabilityCheck(webProxy) > 0)
{
return webProxy;
}
return null;
}
}
}

View File

@@ -71,8 +71,8 @@ namespace v2rayN.Handler
coreType = ECoreType.v2fly,
coreExes = new List<string> { "wv2ray", "v2ray" },
arguments = "",
coreUrl = Global.v2flyCoreUrl
coreUrl = Global.v2flyCoreUrl,
match = "V2Ray"
});
coreInfos.Add(new CoreInfo
@@ -80,7 +80,8 @@ namespace v2rayN.Handler
coreType = ECoreType.Xray,
coreExes = new List<string> { "xray" },
arguments = "",
coreUrl = Global.xrayCoreUrl
coreUrl = Global.xrayCoreUrl,
match = "Xray"
});
coreInfos.Add(new CoreInfo

View File

@@ -218,6 +218,15 @@ namespace v2rayN.Handler
}
Utils.SaveLog("UpdateTaskRun");
updateHandle.UpdateSubscriptionProcess(config, true, (bool success, string msg) =>
{
update(success, msg);
if (success)
Utils.SaveLog("subscription" + msg);
});
Thread.Sleep(60000);
updateHandle.UpdateGeoFile("geosite", config, (bool success, string msg) =>
{
update(false, msg);
@@ -225,8 +234,6 @@ namespace v2rayN.Handler
Utils.SaveLog("geosite" + msg);
});
Thread.Sleep(60000);
updateHandle.UpdateGeoFile("geoip", config, (bool success, string msg) =>
{
update(false, msg);

View File

@@ -17,12 +17,12 @@ namespace v2rayN.Handler
private List<ServerTestItem> _selecteds;
Action<string, string> _updateFunc;
public SpeedtestHandler(ref Config config)
public SpeedtestHandler(Config config)
{
_config = config;
}
public SpeedtestHandler(ref Config config, V2rayHandler v2rayHandler, List<VmessItem> selecteds, ESpeedActionType actionType, Action<string, string> update)
public SpeedtestHandler(Config config, V2rayHandler v2rayHandler, List<VmessItem> selecteds, ESpeedActionType actionType, Action<string, string> update)
{
_config = config;
_v2rayHandler = v2rayHandler;
@@ -55,7 +55,7 @@ namespace v2rayN.Handler
}
else if (actionType == ESpeedActionType.Speedtest)
{
Task.Run(() => RunSpeedTest());
Task.Run(() => RunSpeedTestAsync());
}
}
@@ -71,7 +71,7 @@ namespace v2rayN.Handler
}
try
{
updateFun(it);
Task.Run(() => updateFun(it));
}
catch (Exception ex)
{
@@ -122,6 +122,7 @@ namespace v2rayN.Handler
return;
}
DownloadHandle downloadHandle = new DownloadHandle();
//Thread.Sleep(5000);
List<Task> tasks = new List<Task>();
foreach (var it in _selecteds)
@@ -140,7 +141,7 @@ namespace v2rayN.Handler
{
WebProxy webProxy = new WebProxy(Global.Loopback, it.port);
int responseTime = -1;
string status = GetRealPingTime(_config.constItem.speedPingTestUrl, webProxy, out responseTime);
string status = downloadHandle.GetRealPingTime(_config.constItem.speedPingTestUrl, webProxy, out responseTime);
string output = Utils.IsNullOrEmpty(status) ? FormatOut(responseTime, "ms") : status;
_config.GetVmessItem(it.indexId)?.SetTestResult(output);
@@ -165,38 +166,7 @@ namespace v2rayN.Handler
}
}
public int RunAvailabilityCheck() // alias: isLive
{
try
{
int httpPort = _config.GetLocalPort(Global.InboundHttp2);
Task<int> t = Task.Run(() =>
{
try
{
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
int responseTime = -1;
string status = GetRealPingTime(Global.SpeedPingTestUrl, webProxy, out responseTime);
bool noError = Utils.IsNullOrEmpty(status);
return noError ? responseTime : -1;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return -1;
}
});
return t.Result;
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
return -1;
}
}
private void RunSpeedTest()
private async Task RunSpeedTestAsync()
{
string testIndexId = string.Empty;
int pid = -1;
@@ -220,7 +190,7 @@ namespace v2rayN.Handler
_updateFunc(testIndexId, args.GetException().Message);
};
var timeout = 10;
var timeout = 8;
foreach (var it in _selecteds)
{
if (!it.allowTest)
@@ -235,15 +205,9 @@ namespace v2rayN.Handler
if (_config.FindIndexId(it.indexId) < 0) continue;
WebProxy webProxy = new WebProxy(Global.Loopback, it.port);
var ws = downloadHandle2.DownloadDataAsync(url, webProxy, timeout - 2);
Thread.Sleep(1000 * timeout);
ws.CancelAsync();
ws.Dispose();
Thread.Sleep(1000 * 2);
await downloadHandle2.DownloadDataAsync(url, webProxy, timeout);
}
if (pid > 0) _v2rayHandler.V2rayStopPid(pid);
}
@@ -282,37 +246,6 @@ namespace v2rayN.Handler
return responseTime;
}
private string GetRealPingTime(string url, WebProxy webProxy, out int responseTime)
{
string msg = string.Empty;
responseTime = -1;
try
{
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create(url);
myHttpWebRequest.Timeout = 5000;
myHttpWebRequest.Proxy = webProxy;//new WebProxy(Global.Loopback, Global.httpPort);
Stopwatch timer = new Stopwatch();
timer.Start();
HttpWebResponse myHttpWebResponse = (HttpWebResponse)myHttpWebRequest.GetResponse();
if (myHttpWebResponse.StatusCode != HttpStatusCode.OK
&& myHttpWebResponse.StatusCode != HttpStatusCode.NoContent)
{
msg = myHttpWebResponse.StatusDescription;
}
timer.Stop();
responseTime = timer.Elapsed.Milliseconds;
myHttpWebResponse.Close();
}
catch (Exception ex)
{
Utils.SaveLog(ex.Message, ex);
msg = ex.Message;
}
return msg;
}
private string FormatOut(object time, string unit)
{
if (time.ToString().Equals("-1"))

View File

@@ -1,10 +1,9 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using v2rayN.Base;
using v2rayN.Mode;
@@ -177,67 +176,49 @@ namespace v2rayN.Handler
return;
}
for (int k = 1; k <= config.subItem.Count; k++)
Task.Run(async () =>
{
string id = config.subItem[k - 1].id.TrimEx();
string url = config.subItem[k - 1].url.TrimEx();
string userAgent = config.subItem[k - 1].userAgent.TrimEx();
string groupId = config.subItem[k - 1].groupId.TrimEx();
string hashCode = $"{k}){config.subItem[k - 1].remarks}->";
if (config.subItem[k - 1].enabled == false)
foreach (var item in config.subItem)
{
if (item.enabled == false)
{
continue;
}
string id = item.id.TrimEx();
string url = item.url.TrimEx();
string userAgent = item.userAgent.TrimEx();
string groupId = item.groupId.TrimEx();
string hashCode = $"{item.remarks}->";
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url))
{
_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
//_updateFunc(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
continue;
}
DownloadHandle downloadHandle3 = new DownloadHandle();
downloadHandle3.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
_updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
var result = await (new DownloadHandle()).DownloadStringAsync(url, blProxy, userAgent);
_updateFunc(false, $"{hashCode}{ResUI.MsgGetSubscriptionSuccessfully}");
//string result = Utils.Base64Decode(args.Msg);
string result = args.Msg;
if (Utils.IsNullOrEmpty(result))
{
_updateFunc(false, $"{hashCode}{ResUI.MsgSubscriptionDecodingFailed}");
return;
}
//ConfigHandler.RemoveServerViaSubid(ref config, id);
//_updateFunc(false, $"{hashCode}{ResUI.MsgClearSubscription")}");
// RefreshServers();
else
{
int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId);
if (ret > 0)
{
// RefreshServers();
_updateFunc(false, $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}");
}
else
{
_updateFunc(false, $"{hashCode}{ResUI.MsgFailedImportSubscription}");
}
_updateFunc(true, $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}");
}
else
{
_updateFunc(false, args.Msg);
_updateFunc(false, $"-------------------------------------------------------");
}
};
downloadHandle3.Error += (sender2, args) =>
{
_updateFunc(false, args.GetException().Message);
};
WebProxy webProxy = blProxy ? new WebProxy(Global.Loopback, _config.GetLocalPort(Global.InboundHttp2)) : null;
downloadHandle3.WebDownloadString(url, webProxy, userAgent);
_updateFunc(false, $"{hashCode}{ResUI.MsgStartGettingSubscriptions}");
}
_updateFunc(true, $"{ResUI.MsgUpdateSubscriptionEnd}");
});
}
@@ -269,7 +250,7 @@ namespace v2rayN.Handler
File.Delete(targetPath);
}
File.Move(fileName, targetPath);
_updateFunc(true, "");
//_updateFunc(true, "");
}
}
catch (Exception ex)
@@ -287,8 +268,8 @@ namespace v2rayN.Handler
_updateFunc(false, args.GetException().Message);
};
}
askToDownload(downloadHandle, url, false);
}
#region private
@@ -297,19 +278,6 @@ namespace v2rayN.Handler
{
try
{
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
WebRequestHandler webRequestHandler = new WebRequestHandler
{
AllowAutoRedirect = false
};
if (httpProxyTest() > 0)
{
int httpPort = _config.GetLocalPort(Global.InboundHttp2);
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
webRequestHandler.Proxy = webProxy;
}
HttpClient httpClient = new HttpClient(webRequestHandler);
string url;
if (type == ECoreType.v2fly)
{
@@ -327,10 +295,11 @@ namespace v2rayN.Handler
{
throw new ArgumentException("Type");
}
HttpResponseMessage response = await httpClient.GetAsync(url);
if (response.StatusCode.ToString() == "Redirect")
var result = await (new DownloadHandle()).UrlRedirectAsync(url, true);
if (!Utils.IsNullOrEmpty(result))
{
responseHandler(type, response.Headers.Location.ToString());
responseHandler(type, result);
}
else
{
@@ -352,19 +321,20 @@ namespace v2rayN.Handler
{
try
{
var core = string.Empty;
var match = string.Empty;
if (type == ECoreType.v2fly)
var coreInfo = LazyConfig.Instance.GetCoreInfo(type);
string filePath = string.Empty;
foreach (string name in coreInfo.coreExes)
{
core = "v2ray.exe";
match = "V2Ray";
}
else if (type == ECoreType.Xray)
string vName = string.Format("{0}.exe", name);
vName = Utils.GetPath(vName);
if (File.Exists(vName))
{
core = "xray.exe";
match = "Xray";
filePath = vName;
break;
}
string filePath = Utils.GetPath(core);
}
if (!File.Exists(filePath))
{
string msg = string.Format(ResUI.NotFoundCore, @"");
@@ -383,7 +353,7 @@ namespace v2rayN.Handler
p.Start();
p.WaitForExit(5000);
string echo = p.StandardOutput.ReadToEnd();
string version = Regex.Match(echo, $"{match} ([0-9.]+) \\(").Groups[1].Value;
string version = Regex.Match(echo, $"{coreInfo.match} ([0-9.]+) \\(").Groups[1].Value;
return version;
}
catch (Exception ex)
@@ -458,23 +428,8 @@ namespace v2rayN.Handler
}
if (blDownload)
{
if (httpProxyTest() > 0)
{
int httpPort = _config.GetLocalPort(Global.InboundHttp2);
WebProxy webProxy = new WebProxy(Global.Loopback, httpPort);
downloadHandle.DownloadFileAsync(url, webProxy, 600);
downloadHandle.DownloadFileAsync(url, true, 600);
}
else
{
downloadHandle.DownloadFileAsync(url, null, 600);
}
}
}
private int httpProxyTest()
{
SpeedtestHandler statistics = new SpeedtestHandler(ref _config);
return statistics.RunAvailabilityCheck();
}
#endregion
}

View File

@@ -957,7 +957,7 @@ namespace v2rayN.Handler
case ECoreType.Xray:
break;
case ECoreType.clash:
fileContent.Add($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp)}");
fileContent.Add($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp2)}");
fileContent.Add($"socks-port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundSocks)}");
break;
}

View File

@@ -341,19 +341,31 @@ namespace v2rayN.Mode
{
return subRemarks;
}
foreach (SubItem sub in config.subItem)
{
if (sub.id.EndsWith(subid))
{
return sub.remarks;
}
}
if (subid.Length <= 4)
{
return subid;
}
var sub = config.subItem.FirstOrDefault(t => t.id == subid);
if (sub != null)
{
return sub.remarks;
}
return subid.Substring(0, 4);
}
public string GetGroupRemarks(Config config)
{
string subRemarks = string.Empty;
if (Utils.IsNullOrEmpty(groupId))
{
return subRemarks;
}
var group = config.groupItem.FirstOrDefault(t => t.id == groupId);
if (group != null)
{
return group.remarks;
}
return groupId.Substring(0, 4);
}
public List<string> GetAlpn()
{
@@ -763,6 +775,10 @@ namespace v2rayN.Mode
{
get; set;
}
public int sort
{
get; set;
}
}

View File

@@ -13,5 +13,7 @@ namespace v2rayN.Mode
public string arguments { get; set; }
public string coreUrl { get; set; }
public string match { get; set; }
}
}

View File

@@ -32,4 +32,4 @@ using System.Runtime.InteropServices;
// 方法是按如下所示使用“*”:
//[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyVersion("1.0.0")]
[assembly: AssemblyFileVersion("5.12")]
[assembly: AssemblyFileVersion("5.14")]

View File

@@ -619,7 +619,7 @@ namespace v2rayN.Resx {
}
/// <summary>
/// 查找类似 Failed to get subscription content 的本地化字符串。
/// 查找类似 Invalid subscription content 的本地化字符串。
/// </summary>
internal static string MsgSubscriptionDecodingFailed {
get {
@@ -879,6 +879,15 @@ namespace v2rayN.Resx {
}
}
/// <summary>
/// 查找类似 Speed Test... 的本地化字符串。
/// </summary>
internal static string Speedtesting {
get {
return ResourceManager.GetString("Speedtesting", resourceCulture);
}
}
/// <summary>
/// 查找类似 PAC failed to start. Run it with Admin right. 的本地化字符串。
/// </summary>
@@ -952,6 +961,15 @@ namespace v2rayN.Resx {
}
}
/// <summary>
/// 查找类似 Too many servers, please open the main interface 的本地化字符串。
/// </summary>
internal static string TooManyServersTip {
get {
return ResourceManager.GetString("TooManyServersTip", resourceCulture);
}
}
/// <summary>
/// 查找类似 *tcp camouflage type 的本地化字符串。
/// </summary>

View File

@@ -268,7 +268,7 @@
<value>Start updating PAC...</value>
</data>
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
<value>Failed to get subscription content</value>
<value>Invalid subscription content</value>
</data>
<data name="MsgUnpacking" xml:space="preserve">
<value>is unpacking...</value>
@@ -457,4 +457,10 @@
<data name="SystemProxy" xml:space="preserve">
<value>System proxy</value>
</data>
<data name="Speedtesting" xml:space="preserve">
<value>Speed Test...</value>
</data>
<data name="TooManyServersTip" xml:space="preserve">
<value>Too many servers, please open the main interface</value>
</data>
</root>

View File

@@ -268,7 +268,7 @@
<value>开始更新 PAC...</value>
</data>
<data name="MsgSubscriptionDecodingFailed" xml:space="preserve">
<value>订阅内容获取失败</value>
<value>无效的订阅内容</value>
</data>
<data name="MsgUnpacking" xml:space="preserve">
<value>正在解压......</value>
@@ -457,4 +457,10 @@
<data name="SystemProxy" xml:space="preserve">
<value>系统代理</value>
</data>
<data name="Speedtesting" xml:space="preserve">
<value>测速中...</value>
</data>
<data name="TooManyServersTip" xml:space="preserve">
<value>服务器太多,请打开主界面操作</value>
</data>
</root>

View File

@@ -753,16 +753,11 @@ namespace v2rayN
{
if (enableSecurityProtocolTls13)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12
| SecurityProtocolType.Tls13;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12 | SecurityProtocolType.Tls13;
}
else
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls12;
ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;
}
ServicePointManager.DefaultConnectionLimit = 256;
}

View File

@@ -99,6 +99,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Base\HttpClientHelper.cs" />
<Compile Include="Base\ListViewFlickerFree.cs">
<SubType>Component</SubType>
</Compile>
@@ -195,9 +196,6 @@
<Compile Include="Handler\StatisticsHandler.cs" />
<Compile Include="Handler\DownloadHandle.cs" />
<Compile Include="Handler\ProxySetting.cs" />
<Compile Include="Base\WebClientEx.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Handler\SysProxyHandle.cs" />
<Compile Include="Mode\ESpeedActionType.cs" />
<Compile Include="Mode\EGlobalHotkey.cs" />
@@ -474,13 +472,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Google.Protobuf">
<Version>3.19.4</Version>
<Version>3.20.0</Version>
</PackageReference>
<PackageReference Include="Grpc.Core">
<Version>2.44.0</Version>
<Version>2.45.0</Version>
</PackageReference>
<PackageReference Include="Grpc.Tools">
<Version>2.44.0</Version>
<Version>2.45.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>