From fde1c98dddb663499f1df8dab1127dc9dea19d82 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Tue, 12 Apr 2022 13:37:41 +0800 Subject: [PATCH] add group sort --- .../Forms/GroupSettingControl.Designer.cs | 21 +- v2rayN/v2rayN/Forms/GroupSettingControl.cs | 2 + v2rayN/v2rayN/Forms/GroupSettingControl.resx | 203 +++++++++++------- .../Forms/GroupSettingControl.zh-Hans.resx | 3 + v2rayN/v2rayN/Forms/MainForm.cs | 27 ++- v2rayN/v2rayN/Mode/Config.cs | 34 ++- 6 files changed, 193 insertions(+), 97 deletions(-) diff --git a/v2rayN/v2rayN/Forms/GroupSettingControl.Designer.cs b/v2rayN/v2rayN/Forms/GroupSettingControl.Designer.cs index 239057e5..9dfcc635 100644 --- a/v2rayN/v2rayN/Forms/GroupSettingControl.Designer.cs +++ b/v2rayN/v2rayN/Forms/GroupSettingControl.Designer.cs @@ -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; } } diff --git a/v2rayN/v2rayN/Forms/GroupSettingControl.cs b/v2rayN/v2rayN/Forms/GroupSettingControl.cs index ac10087a..a3fcbf27 100644 --- a/v2rayN/v2rayN/Forms/GroupSettingControl.cs +++ b/v2rayN/v2rayN/Forms/GroupSettingControl.cs @@ -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) diff --git a/v2rayN/v2rayN/Forms/GroupSettingControl.resx b/v2rayN/v2rayN/Forms/GroupSettingControl.resx index c8761f6e..75f7057e 100644 --- a/v2rayN/v2rayN/Forms/GroupSettingControl.resx +++ b/v2rayN/v2rayN/Forms/GroupSettingControl.resx @@ -118,126 +118,177 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 10 + + True + + + + NoControl - - 6, 12 + + 12, 61 - + + 71, 12 + + + 26 + + + Sort number + + + label1 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grbMain + + 0 - - 292, 21 + + 127, 57 + + + 120, 21 + + + 25 + + + numSort + + + System.Windows.Forms.NumericUpDown, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grbMain + + + 1 + + + NoControl 525, 21 - - 127, 21 - - - grbMain - - - 12, 25 + + 75, 23 24 - - System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Remove - - GroupSettingControl - - - grbMain + + btnRemove System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + grbMain - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + 2 + + 127, 21 + + + 292, 21 + + + 1 + + + txtRemarks + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grbMain + + + 3 + + + True + + + NoControl + + + 12, 25 + + + 47, 12 + + + 10 + + + Remarks + label2 - - 75, 23 + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + grbMain + + + 4 + + + Fill 0, 0 - 619, 61 + 619, 91 - - Remarks - - - grbMain + + 10 Group details - - - NoControl - - - 1 - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - 47, 12 - - - txtRemarks - - - 0 - - - btnRemove - - - Fill - - - 10 - - - True - - - NoControl + + grbMain System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 1 - $this - - 619, 61 - - - Remove + + 0 True + + 6, 12 + + + 619, 91 + + + GroupSettingControl + + + System.Windows.Forms.UserControl, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/GroupSettingControl.zh-Hans.resx b/v2rayN/v2rayN/Forms/GroupSettingControl.zh-Hans.resx index c68bf863..34dd0092 100644 --- a/v2rayN/v2rayN/Forms/GroupSettingControl.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/GroupSettingControl.zh-Hans.resx @@ -130,4 +130,7 @@ 分组详情 + + 排序编号 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/MainForm.cs b/v2rayN/v2rayN/Forms/MainForm.cs index cee1f2aa..c62c5956 100644 --- a/v2rayN/v2rayN/Forms/MainForm.cs +++ b/v2rayN/v2rayN/Forms/MainForm.cs @@ -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) @@ -472,7 +472,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 +539,15 @@ namespace v2rayN.Forms #endregion #region v2ray 操作 - /// /// 载入V2ray /// async Task LoadV2ray() { - tsbReload.Enabled = false; + this.BeginInvoke(new Action(() => + { + tsbReload.Enabled = false; + })); if (Global.reloadV2ray) { @@ -562,7 +564,10 @@ namespace v2rayN.Forms ChangePACButtonStatus(config.sysProxyType); - tsbReload.Enabled = true; + this.BeginInvoke(new Action(() => + { + tsbReload.Enabled = true; + })); } /// @@ -881,9 +886,9 @@ namespace v2rayN.Forms var fm = new GlobalHotkeySettingForm(); if (fm.ShowDialog() == DialogResult.OK) { - RefreshRoutingsMenu(); - RefreshServers(); - _ = LoadV2ray(); + //RefreshRoutingsMenu(); + //RefreshServers(); + //_ = LoadV2ray(); } } @@ -1259,13 +1264,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 diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index 40236fcf..e99e7be3 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -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 GetAlpn() { @@ -578,9 +590,9 @@ namespace v2rayN.Mode public bool sniffingEnabled { get; set; } = true; public bool allowLANConn { get; set; } - + public string user { get; set; } - + public string pass { get; set; } } @@ -763,6 +775,10 @@ namespace v2rayN.Mode { get; set; } + public int sort + { + get; set; + } }