From f74071691f1dc4e31c86eaac307fd628f32b6f4e Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 5 Aug 2022 20:52:08 +0800 Subject: [PATCH] Update current group subscription --- v2rayN/v2rayN/Forms/MainForm.Designer.cs | 20 +- v2rayN/v2rayN/Forms/MainForm.cs | 41 ++- v2rayN/v2rayN/Forms/MainForm.resx | 338 ++++++++++++---------- v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx | 6 + v2rayN/v2rayN/Handler/MainFormHandler.cs | 2 +- v2rayN/v2rayN/Handler/UpdateHandle.cs | 11 +- 6 files changed, 242 insertions(+), 176 deletions(-) diff --git a/v2rayN/v2rayN/Forms/MainForm.Designer.cs b/v2rayN/v2rayN/Forms/MainForm.Designer.cs index f0fe26dc..218a8fe3 100644 --- a/v2rayN/v2rayN/Forms/MainForm.Designer.cs +++ b/v2rayN/v2rayN/Forms/MainForm.Designer.cs @@ -128,6 +128,8 @@ this.tsbPromotion = new System.Windows.Forms.ToolStripButton(); this.toolStripSeparator11 = new System.Windows.Forms.ToolStripSeparator(); this.tsbClose = new System.Windows.Forms.ToolStripButton(); + this.tsbSubGroupUpdate = new System.Windows.Forms.ToolStripMenuItem(); + this.tsbSubGroupUpdateViaProxy = new System.Windows.Forms.ToolStripMenuItem(); ((System.ComponentModel.ISupportInitialize)(this.scServers)).BeginInit(); this.scServers.Panel1.SuspendLayout(); this.scServers.Panel2.SuspendLayout(); @@ -612,7 +614,9 @@ this.tsbSub.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.tsbSubSetting, this.tsbSubUpdate, - this.tsbSubUpdateViaProxy}); + this.tsbSubUpdateViaProxy, + this.tsbSubGroupUpdate, + this.tsbSubGroupUpdateViaProxy}); this.tsbSub.Image = global::v2rayN.Properties.Resources.sub; resources.ApplyResources(this.tsbSub, "tsbSub"); this.tsbSub.Name = "tsbSub"; @@ -848,6 +852,18 @@ this.tsbClose.Name = "tsbClose"; this.tsbClose.Click += new System.EventHandler(this.tsbClose_Click); // + // tsbSubGroupUpdate + // + this.tsbSubGroupUpdate.Name = "tsbSubGroupUpdate"; + resources.ApplyResources(this.tsbSubGroupUpdate, "tsbSubGroupUpdate"); + this.tsbSubGroupUpdate.Click += new System.EventHandler(this.tsbSubGroupUpdate_Click); + // + // tsbSubGroupUpdateViaProxy + // + this.tsbSubGroupUpdateViaProxy.Name = "tsbSubGroupUpdateViaProxy"; + resources.ApplyResources(this.tsbSubGroupUpdateViaProxy, "tsbSubGroupUpdateViaProxy"); + this.tsbSubGroupUpdateViaProxy.Click += new System.EventHandler(this.tsbSubGroupUpdateViaProxy_Click); + // // MainForm // resources.ApplyResources(this, "$this"); @@ -981,6 +997,8 @@ private System.Windows.Forms.ToolStripSeparator toolStripSeparator16; private System.Windows.Forms.ToolStripMenuItem menuSortServerResult; private System.Windows.Forms.ToolStripMenuItem tsbCheckUpdateSagerNetCore; + private System.Windows.Forms.ToolStripMenuItem tsbSubGroupUpdate; + private System.Windows.Forms.ToolStripMenuItem tsbSubGroupUpdateViaProxy; } } diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index 83100854..e9edeb65 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -20,7 +20,7 @@ namespace v2rayN.Forms private List lstSelecteds = new List(); private StatisticsHandler statistics; private List lstVmess; - private string groupId = string.Empty; + private string _groupId = string.Empty; private string serverFilter = string.Empty; #region Window 事件 @@ -226,13 +226,17 @@ namespace v2rayN.Forms private void RefreshServers() { lstVmess = config.vmess - .Where(it => Utils.IsNullOrEmpty(groupId) || it.groupId == groupId) + .Where(it => Utils.IsNullOrEmpty(_groupId) || it.groupId == _groupId) .Where(it => Utils.IsNullOrEmpty(serverFilter) || it.remarks.Contains(serverFilter)) .OrderBy(it => it.sort) .ToList(); ConfigHandler.SetDefaultServer(config, lstVmess); - RefreshServersView(); + BeginInvoke(new Action(() => + { + RefreshServersView(); + })); + RefreshServersMenu(); } @@ -491,9 +495,9 @@ namespace v2rayN.Forms { return; } - groupId = string.Empty; + _groupId = string.Empty; //groupId = tabGroup.TabPages[tabGroup.SelectedIndex].Name; - groupId = tabGroup.SelectedTab.Name; + _groupId = tabGroup.SelectedTab.Name; RefreshServers(); @@ -604,7 +608,7 @@ namespace v2rayN.Forms fm = new AddServerForm(); } fm.vmessItem = index >= 0 ? lstVmess[index] : null; - fm.groupId = groupId; + fm.groupId = _groupId; fm.eConfigType = configType; if (fm.ShowDialog() == DialogResult.OK) { @@ -1026,7 +1030,7 @@ namespace v2rayN.Forms private void menuAddServers_Click(object sender, EventArgs e) { string clipboardData = Utils.GetClipboardData(); - int ret = ConfigHandler.AddBatchServers(ref config, clipboardData, "", groupId); + int ret = ConfigHandler.AddBatchServers(ref config, clipboardData, "", _groupId); if (ret > 0) { RefreshServers(); @@ -1056,7 +1060,7 @@ namespace v2rayN.Forms } else { - int ret = ConfigHandler.AddBatchServers(ref config, result, "", groupId); + int ret = ConfigHandler.AddBatchServers(ref config, result, "", _groupId); if (ret > 0) { RefreshServers(); @@ -1067,11 +1071,11 @@ namespace v2rayN.Forms private void menuUpdateSubscriptions_Click(object sender, EventArgs e) { - UpdateSubscriptionProcess(false); + UpdateSubscriptionProcess("", false); } private void menuUpdateSubViaProxy_Click(object sender, EventArgs e) { - UpdateSubscriptionProcess(true); + UpdateSubscriptionProcess("", true); } private void tsbBackupGuiNConfig_Click(object sender, EventArgs e) @@ -1458,18 +1462,18 @@ namespace v2rayN.Forms private void tsbSubUpdate_Click(object sender, EventArgs e) { - UpdateSubscriptionProcess(false); + UpdateSubscriptionProcess("", false); } private void tsbSubUpdateViaProxy_Click(object sender, EventArgs e) { - UpdateSubscriptionProcess(true); + UpdateSubscriptionProcess("", true); } /// /// the subscription update process /// - private void UpdateSubscriptionProcess(bool blProxy) + private void UpdateSubscriptionProcess(string groupId, bool blProxy) { void _updateUI(bool success, string msg) { @@ -1487,7 +1491,7 @@ namespace v2rayN.Forms } }; - (new UpdateHandle()).UpdateSubscriptionProcess(config, blProxy, _updateUI); + (new UpdateHandle()).UpdateSubscriptionProcess(config, groupId, blProxy, _updateUI); } private void tsbQRCodeSwitch_CheckedChanged(object sender, EventArgs e) @@ -1577,5 +1581,14 @@ namespace v2rayN.Forms } #endregion + private void tsbSubGroupUpdate_Click(object sender, EventArgs e) + { + UpdateSubscriptionProcess(_groupId, true); + } + + private void tsbSubGroupUpdateViaProxy_Click(object sender, EventArgs e) + { + UpdateSubscriptionProcess(_groupId, true); + } } } diff --git a/v2rayN/v2rayN/Forms/MainForm.resx b/v2rayN/v2rayN/Forms/MainForm.resx index 2d512adb..e13b36cd 100644 --- a/v2rayN/v2rayN/Forms/MainForm.resx +++ b/v2rayN/v2rayN/Forms/MainForm.resx @@ -218,30 +218,6 @@ Move to Group - - 192, 22 - - - Move to top (T) - - - 192, 22 - - - Up (U) - - - 192, 22 - - - Down (D) - - - 192, 22 - - - Move to bottom (B) - 355, 22 @@ -339,7 +315,7 @@ ImageAboveText - 356, 644 + 356, 622 cmsLv @@ -488,6 +464,30 @@ 0 + + 192, 22 + + + Move to top (T) + + + 192, 22 + + + Up (U) + + + 192, 22 + + + Down (D) + + + 192, 22 + + + Move to bottom (B) + Fill @@ -599,6 +599,27 @@ NoControl + + 278, 192 + + + cmsMain + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + v2rayN + + + True + + + 277, 22 + + + System proxy + 243, 22 @@ -617,12 +638,6 @@ Do not change system proxy - - 277, 22 - - - System proxy - 277, 22 @@ -671,21 +686,6 @@ Exit - - 278, 192 - - - cmsMain - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - v2rayN - - - True - Top @@ -717,23 +717,35 @@ 6, 56 - 277, 22 + 317, 22 Settings - 277, 22 + 317, 22 Update subscription without proxy - 277, 22 + 317, 22 Update subscription with proxy + + 317, 22 + + + Update group subscription without proxy + + + 317, 22 + + + Update group subscription with proxy + Magenta @@ -764,39 +776,6 @@ 6, 56 - - 195, 22 - - - OptionSetting - - - 195, 22 - - - RoutingSetting - - - 195, 22 - - - GlobalHotkeySetting - - - 195, 22 - - - GroupSetting - - - 192, 6 - - - 195, 22 - - - BackupGuiConfig - Magenta @@ -830,51 +809,6 @@ 6, 56 - - 219, 22 - - - v2rayN (this software) - - - 219, 22 - - - Update v2fly Core - - - 219, 22 - - - 219, 22 - - - Update Xray Core - - - 216, 6 - - - 219, 22 - - - Update clash Core - - - 219, 22 - - - Update Clash.Meta Core - - - 216, 6 - - - 219, 22 - - - Update Geo files - Magenta @@ -890,33 +824,6 @@ 6, 56 - - 187, 22 - - - v2rayN Project - - - 187, 22 - - - V2Ray Website - - - 184, 6 - - - 187, 22 - - - Language-[English] - - - 187, 22 - - - 语言-[中文简体] - Magenta @@ -977,6 +884,114 @@ 4 + + 195, 22 + + + OptionSetting + + + 195, 22 + + + RoutingSetting + + + 195, 22 + + + GlobalHotkeySetting + + + 195, 22 + + + GroupSetting + + + 192, 6 + + + 195, 22 + + + BackupGuiConfig + + + 219, 22 + + + v2rayN (this software) + + + 219, 22 + + + Update v2fly Core + + + 219, 22 + + + Update SagerNet Core + + + 219, 22 + + + Update Xray Core + + + 216, 6 + + + 219, 22 + + + Update clash Core + + + 219, 22 + + + Update Clash.Meta Core + + + 216, 6 + + + 219, 22 + + + Update Geo files + + + 187, 22 + + + v2rayN Project + + + 187, 22 + + + V2Ray Website + + + 184, 6 + + + 187, 22 + + + Language-[English] + + + 187, 22 + + + 语言-[中文简体] + True @@ -1517,13 +1532,22 @@ System.Windows.Forms.ToolStripButton, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + tsbSubGroupUpdate + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + tsbSubGroupUpdateViaProxy + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + MainForm v2rayN.Forms.BaseForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - Update SagerNet Core - \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx index e1a374e3..40bf1982 100644 --- a/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/MainForm.zh-Hans.resx @@ -573,4 +573,10 @@ SagerNet-Core + + 更新当前分组订阅(不通过代理) + + + 更新当前分组订阅(通过代理) + \ No newline at end of file diff --git a/v2rayN/v2rayN/Handler/MainFormHandler.cs b/v2rayN/v2rayN/Handler/MainFormHandler.cs index 975de934..e67909ba 100644 --- a/v2rayN/v2rayN/Handler/MainFormHandler.cs +++ b/v2rayN/v2rayN/Handler/MainFormHandler.cs @@ -254,7 +254,7 @@ namespace v2rayN.Handler { if ((dtNow - autoUpdateSubTime).Hours % config.autoUpdateSubInterval == 0) { - updateHandle.UpdateSubscriptionProcess(config, true, (bool success, string msg) => + updateHandle.UpdateSubscriptionProcess(config, "", true, (bool success, string msg) => { update(success, msg); if (success) diff --git a/v2rayN/v2rayN/Handler/UpdateHandle.cs b/v2rayN/v2rayN/Handler/UpdateHandle.cs index 90408c25..d521742e 100644 --- a/v2rayN/v2rayN/Handler/UpdateHandle.cs +++ b/v2rayN/v2rayN/Handler/UpdateHandle.cs @@ -159,7 +159,7 @@ namespace v2rayN.Handler } - public void UpdateSubscriptionProcess(Config config, bool blProxy, Action update) + public void UpdateSubscriptionProcess(Config config, string groupId, bool blProxy, Action update) { _config = config; _updateFunc = update; @@ -190,10 +190,15 @@ namespace v2rayN.Handler { continue; } + if (!Utils.IsNullOrEmpty(groupId) && item.groupId != groupId) + { + continue; + } + string id = item.id.TrimEx(); string url = item.url.TrimEx(); string userAgent = item.userAgent.TrimEx(); - string groupId = item.groupId.TrimEx(); + //string groupId = item.groupId.TrimEx(); string hashCode = $"{item.remarks}->"; if (Utils.IsNullOrEmpty(id) || Utils.IsNullOrEmpty(url)) { @@ -226,7 +231,7 @@ namespace v2rayN.Handler _updateFunc(false, $"{hashCode}{result}"); } - int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId); + int ret = ConfigHandler.AddBatchServers(ref config, result, id, item.groupId.TrimEx()); _updateFunc(false, ret > 0 ? $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}"