add auto update geo task

pull/1857/head 4.22
2dust 2021-10-10 20:16:30 +08:00
parent a29b744526
commit 933d3c2678
12 changed files with 518 additions and 433 deletions

View File

@ -51,6 +51,7 @@ namespace v2rayN.Forms
{
statistics = new StatisticsHandler(config, UpdateStatisticsHandler);
}
MainFormHandler.Instance.UpdateTask(config, UpdateTaskHandler);
}
private void MainForm_VisibleChanged(object sender, EventArgs e)
@ -962,7 +963,10 @@ namespace v2rayN.Forms
/// </summary>
private void ClearMsg()
{
this.txtMsgBox.Clear();
txtMsgBox.Invoke((Action)delegate
{
txtMsgBox.Clear();
});
}
/// <summary>
@ -1085,6 +1089,15 @@ namespace v2rayN.Forms
}
}
private void UpdateTaskHandler(bool success, string msg)
{
AppendText(false, msg);
if (success)
{
Global.reloadV2ray = true;
LoadV2ray();
}
}
#endregion
#region 移动服务器
@ -1213,8 +1226,7 @@ namespace v2rayN.Forms
{
CloseV2ray();
string fileName = Global.DownloadFileName;
fileName = Utils.GetPath(fileName);
string fileName = Utils.GetPath(Utils.GetDownloadFileName(msg));
FileManager.ZipExtractToFile(fileName, config.ignoreGeoUpdateCore ? "geo" : "");
AppendText(false, UIRes.I18N("MsgUpdateV2rayCoreSuccessfullyMore"));

View File

@ -69,6 +69,8 @@
this.txtKcpmtu = new System.Windows.Forms.TextBox();
this.label6 = new System.Windows.Forms.Label();
this.tabPage7 = new System.Windows.Forms.TabPage();
this.txtautoUpdateInterval = new System.Windows.Forms.TextBox();
this.label15 = new System.Windows.Forms.Label();
this.chkIgnoreGeoUpdateCore = new System.Windows.Forms.CheckBox();
this.cmbCoreType = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label();
@ -372,6 +374,8 @@
// tabPage7
//
resources.ApplyResources(this.tabPage7, "tabPage7");
this.tabPage7.Controls.Add(this.txtautoUpdateInterval);
this.tabPage7.Controls.Add(this.label15);
this.tabPage7.Controls.Add(this.chkIgnoreGeoUpdateCore);
this.tabPage7.Controls.Add(this.cmbCoreType);
this.tabPage7.Controls.Add(this.label4);
@ -384,6 +388,16 @@
this.tabPage7.Name = "tabPage7";
this.tabPage7.UseVisualStyleBackColor = true;
//
// txtautoUpdateInterval
//
resources.ApplyResources(this.txtautoUpdateInterval, "txtautoUpdateInterval");
this.txtautoUpdateInterval.Name = "txtautoUpdateInterval";
//
// label15
//
resources.ApplyResources(this.label15, "label15");
this.label15.Name = "label15";
//
// chkIgnoreGeoUpdateCore
//
resources.ApplyResources(this.chkIgnoreGeoUpdateCore, "chkIgnoreGeoUpdateCore");
@ -579,5 +593,7 @@
private System.Windows.Forms.Label label12;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label13;
private System.Windows.Forms.TextBox txtautoUpdateInterval;
private System.Windows.Forms.Label label15;
}
}

View File

@ -123,6 +123,7 @@ namespace v2rayN.Forms
chkIgnoreGeoUpdateCore.Checked = config.ignoreGeoUpdateCore;
cmbCoreType.SelectedIndex = (int)config.coreType;
txtautoUpdateInterval.Text = config.autoUpdateInterval.ToString();
}
private void btnOK_Click(object sender, EventArgs e)
{
@ -290,6 +291,7 @@ namespace v2rayN.Forms
config.ignoreGeoUpdateCore = chkIgnoreGeoUpdateCore.Checked;
config.coreType = (ECoreType)cmbCoreType.SelectedIndex;
config.autoUpdateInterval = Utils.ToInt(txtautoUpdateInterval.Text);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -139,30 +139,63 @@
<data name="tabPage6.Text" xml:space="preserve">
<value> Core:KCP设置 </value>
</data>
<data name="txtautoUpdateInterval.Location" type="System.Drawing.Point, System.Drawing">
<value>255, 156</value>
</data>
<data name="label15.Size" type="System.Drawing.Size, System.Drawing">
<value>191, 12</value>
</data>
<data name="label15.Text" xml:space="preserve">
<value>自动更新Geo文件的间隔(单位分钟)</value>
</data>
<data name="chkIgnoreGeoUpdateCore.Size" type="System.Drawing.Size, System.Drawing">
<value>150, 16</value>
</data>
<data name="chkIgnoreGeoUpdateCore.Text" xml:space="preserve">
<value>更新Core时忽略Geo文件</value>
</data>
<data name="label4.Size" type="System.Drawing.Size, System.Drawing">
<value>53, 12</value>
</data>
<data name="label4.Text" xml:space="preserve">
<value>Core类型</value>
</data>
<data name="chkKeepOlderDedupl.Size" type="System.Drawing.Size, System.Drawing">
<value>156, 16</value>
</data>
<data name="chkKeepOlderDedupl.Text" xml:space="preserve">
<value>去重时保留序号较小的项</value>
</data>
<data name="lbFreshrate.Size" type="System.Drawing.Size, System.Drawing">
<value>77, 12</value>
</data>
<data name="lbFreshrate.Text" xml:space="preserve">
<value>统计刷新频率</value>
</data>
<data name="chkEnableStatistics.Size" type="System.Drawing.Size, System.Drawing">
<value>372, 16</value>
</data>
<data name="chkEnableStatistics.Text" xml:space="preserve">
<value>启用统计(实时网速显示和使用流量显示需要重启v2rayN客户端)</value>
</data>
<data name="chkAllowLANConn.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 16</value>
</data>
<data name="chkAllowLANConn.Text" xml:space="preserve">
<value>允许来自局域网的连接</value>
</data>
<data name="chkAutoRun.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 16</value>
</data>
<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="label13.Size" type="System.Drawing.Size, System.Drawing">
<value>95, 12</value>
</data>
<data name="label13.Text" xml:space="preserve">
<value>使用分号(;)分隔</value>
</data>
<data name="label12.Size" type="System.Drawing.Size, System.Drawing">
<value>239, 12</value>
</data>
<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>
@ -259,47 +292,23 @@
<data name="label14.Text" xml:space="preserve">
<value>自定义DNS(可多个,用逗号(,)隔开)</value>
</data>
<data name="chkIgnoreGeoUpdateCore.Size" type="System.Drawing.Size, System.Drawing">
<value>150, 16</value>
<data name="groupBox2.Size" type="System.Drawing.Size, System.Drawing">
<value>654, 443</value>
</data>
<data name="chkIgnoreGeoUpdateCore.Text" xml:space="preserve">
<value>更新Core时忽略Geo文件</value>
<data name="groupBox2.Text" xml:space="preserve">
<value>例外</value>
</data>
<data name="label4.Size" type="System.Drawing.Size, System.Drawing">
<value>53, 12</value>
<data name="label13.Size" type="System.Drawing.Size, System.Drawing">
<value>95, 12</value>
</data>
<data name="label4.Text" xml:space="preserve">
<value>Core类型</value>
<data name="label13.Text" xml:space="preserve">
<value>使用分号(;)分隔</value>
</data>
<data name="chkKeepOlderDedupl.Size" type="System.Drawing.Size, System.Drawing">
<value>156, 16</value>
<data name="label12.Size" type="System.Drawing.Size, System.Drawing">
<value>239, 12</value>
</data>
<data name="chkKeepOlderDedupl.Text" xml:space="preserve">
<value>去重时保留序号较小的项</value>
</data>
<data name="lbFreshrate.Size" type="System.Drawing.Size, System.Drawing">
<value>77, 12</value>
</data>
<data name="lbFreshrate.Text" xml:space="preserve">
<value>统计刷新频率</value>
</data>
<data name="chkEnableStatistics.Size" type="System.Drawing.Size, System.Drawing">
<value>372, 16</value>
</data>
<data name="chkEnableStatistics.Text" xml:space="preserve">
<value>启用统计(实时网速显示和使用流量显示需要重启v2rayN客户端)</value>
</data>
<data name="chkAllowLANConn.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 16</value>
</data>
<data name="chkAllowLANConn.Text" xml:space="preserve">
<value>允许来自局域网的连接</value>
</data>
<data name="chkAutoRun.Size" type="System.Drawing.Size, System.Drawing">
<value>180, 16</value>
</data>
<data name="chkAutoRun.Text" xml:space="preserve">
<value>开机自动启动(可能会不成功)</value>
<data name="label12.Text" xml:space="preserve">
<value>对于下列字符开头的地址不使用代理服务器:</value>
</data>
<data name="panel2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 479</value>

View File

@ -7,7 +7,7 @@ namespace v2rayN
{
#region 常量
public const string DownloadFileName = "v2ray-windows.zip";
//public const string DownloadFileName = "v2ray-windows.zip";
public const string v2rayWebsiteUrl = @"https://www.v2fly.org/";
public const string AboutUrl = @"https://github.com/2dust/v2rayN";
public const string UpdateUrl = AboutUrl + @"/releases";

View File

@ -52,7 +52,7 @@ namespace v2rayN.Handler
ws.DownloadFileCompleted += ws_DownloadFileCompleted;
ws.DownloadProgressChanged += ws_DownloadProgressChanged;
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(Global.DownloadFileName));
ws.DownloadFileAsync(new Uri(url), Utils.GetPath(Utils.GetDownloadFileName(url)));
}
catch (Exception ex)
{

View File

@ -1,5 +1,7 @@
using System;
using System.Drawing;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using v2rayN.Base;
using v2rayN.Mode;
@ -9,7 +11,7 @@ namespace v2rayN.Handler
class MainFormHandler
{
private static MainFormHandler instance;
Action<bool, string> updateUI;
Action<bool, string> _updateUI;
//private DownloadHandle downloadHandle2;
//private Config _config;
@ -166,77 +168,6 @@ namespace v2rayN.Handler
return counter;
}
public void UpdateSubscriptionProcess(Config config, Action<bool, string> update)
{
updateUI = update;
updateUI(false, UIRes.I18N("MsgUpdateSubscriptionStart"));
if (config.subItem == null || config.subItem.Count <= 0)
{
updateUI(false, UIRes.I18N("MsgNoValidSubscription"));
return;
}
for (int k = 1; k <= config.subItem.Count; k++)
{
string id = config.subItem[k - 1].id.TrimEx();
string url = config.subItem[k - 1].url.TrimEx();
string hashCode = $"{k}->";
if (config.subItem[k - 1].enabled == false)
{
continue;
}
if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url))
{
updateUI(false, $"{hashCode}{UIRes.I18N("MsgNoValidSubscription")}");
continue;
}
DownloadHandle downloadHandle3 = new DownloadHandle();
downloadHandle3.UpdateCompleted += (sender2, args) =>
{
if (args.Success)
{
updateUI(false, $"{hashCode}{UIRes.I18N("MsgGetSubscriptionSuccessfully")}");
string result = Utils.Base64Decode(args.Msg);
if (Utils.IsNullOrEmpty(result))
{
updateUI(false, $"{hashCode}{UIRes.I18N("MsgSubscriptionDecodingFailed")}");
return;
}
ConfigHandler.RemoveServerViaSubid(ref config, id);
updateUI(false, $"{hashCode}{UIRes.I18N("MsgClearSubscription")}");
// RefreshServers();
int ret = MainFormHandler.Instance.AddBatchServers(config, result, id);
if (ret > 0)
{
// RefreshServers();
}
else
{
updateUI(false, $"{hashCode}{UIRes.I18N("MsgFailedImportSubscription")}");
}
updateUI(true, $"{hashCode}{UIRes.I18N("MsgUpdateSubscriptionEnd")}");
}
else
{
updateUI(false, args.Msg);
}
};
downloadHandle3.Error += (sender2, args) =>
{
updateUI(false, args.GetException().Message);
};
downloadHandle3.WebDownloadString(url);
updateUI(false, $"{hashCode}{UIRes.I18N("MsgStartGettingSubscriptions")}");
}
}
public void BackupGuiNConfig(Config config, bool auto = false)
{
string fileName = string.Empty;
@ -277,5 +208,42 @@ namespace v2rayN.Handler
}
}
public void UpdateTask(Config config, Action<bool, string> update)
{
_updateUI = update;
Task.Run(() => UpdateTaskRun(config));
}
private void UpdateTaskRun(Config config)
{
var updateHandle = new UpdateHandle();
while (true)
{
Utils.SaveLog("UpdateTaskRun");
Thread.Sleep(60000);
if (config.autoUpdateInterval <= 0)
{
continue;
}
updateHandle.UpdateGeoFile("geosite", config, (bool success, string msg) =>
{
_updateUI(false, msg);
if (success)
Utils.SaveLog("geosite" + msg);
});
Thread.Sleep(60000);
updateHandle.UpdateGeoFile("geoip", config, (bool success, string msg) =>
{
_updateUI(false, msg);
if (success)
Utils.SaveLog("geoip" + msg);
});
Thread.Sleep(60000 * config.autoUpdateInterval);
}
}
}
}
}

View File

@ -41,8 +41,9 @@ namespace v2rayN.Handler
{
_config = config;
_updateFunc = update;
var url = string.Empty;
DownloadHandle downloadHandle = null;
DownloadHandle downloadHandle = null;
if (downloadHandle == null)
{
downloadHandle = new DownloadHandle();
@ -55,7 +56,7 @@ namespace v2rayN.Handler
try
{
string fileName = Utils.GetPath(Global.DownloadFileName);
string fileName = Utils.GetPath(Utils.GetDownloadFileName(url));
fileName = Utils.UrlEncode(fileName);
Process process = new Process
{
@ -93,8 +94,8 @@ namespace v2rayN.Handler
{
_updateFunc(false, string.Format(UIRes.I18N("MsgParsingSuccessfully"), "v2rayN"));
string url = args.Msg;
askToDownload(downloadHandle, url);
url = args.Msg;
askToDownload(downloadHandle, url, true);
}
else
{
@ -110,6 +111,7 @@ namespace v2rayN.Handler
{
_config = config;
_updateFunc = update;
var url = string.Empty;
DownloadHandle downloadHandle = null;
if (downloadHandle == null)
@ -124,7 +126,7 @@ namespace v2rayN.Handler
try
{
_updateFunc(true, "");
_updateFunc(true, url);
}
catch (Exception ex)
{
@ -147,8 +149,8 @@ namespace v2rayN.Handler
if (args.Success)
{
_updateFunc(false, string.Format(UIRes.I18N("MsgParsingSuccessfully"), "Core"));
string url = args.Msg;
askToDownload(downloadHandle, url);
url = args.Msg;
askToDownload(downloadHandle, url, true);
}
else
{
@ -236,6 +238,7 @@ namespace v2rayN.Handler
{
_config = config;
_updateFunc = update;
var url = string.Format(geoUrl, geoName);
DownloadHandle downloadHandle = null;
if (downloadHandle == null)
@ -250,7 +253,7 @@ namespace v2rayN.Handler
try
{
string fileName = Utils.GetPath(Global.DownloadFileName);
string fileName = Utils.GetPath(Utils.GetDownloadFileName(url));
if (File.Exists(fileName))
{
string targetPath = Utils.GetPath($"{geoName}.dat");
@ -278,8 +281,7 @@ namespace v2rayN.Handler
};
}
var url = string.Format(geoUrl, geoName);
askToDownload(downloadHandle, url);
askToDownload(downloadHandle, url, false);
}
#region private
@ -433,9 +435,21 @@ namespace v2rayN.Handler
}
}
private void askToDownload(DownloadHandle downloadHandle, string url)
private void askToDownload(DownloadHandle downloadHandle, string url, bool blAsk)
{
if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.Yes)
bool blDownload = false;
if (blAsk)
{
if (UI.ShowYesNo(string.Format(UIRes.I18N("DownloadYesNo"), url)) == DialogResult.Yes)
{
blDownload = true;
}
}
else
{
blDownload = true;
}
if (blDownload)
{
if (httpProxyTest() > 0)
{

View File

@ -195,6 +195,11 @@ namespace v2rayN.Mode
get; set;
}
public int autoUpdateInterval
{
get; set;
} = 0;
#region 函数
public string address()

View File

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

View File

@ -833,6 +833,14 @@ namespace v2rayN
{
i.SubItems.Add(new ListViewItem.ListViewSubItem() { Name = name, Text = text });
}
public static string GetDownloadFileName(string url)
{
var fileName = System.IO.Path.GetFileName(url);
fileName += "_temp";
return fileName;
}
#endregion
#region TempPath