mirror of
				https://github.com/2dust/v2rayN.git
				synced 2025-10-31 12:32:53 +00:00 
			
		
		
		
	Merge pull request #2415 from EdiWang/master
C# language usage improvements
This commit is contained in:
		
						commit
						28b2e1a405
					
				
					 30 changed files with 247 additions and 341 deletions
				
			
		|  | @ -16,37 +16,37 @@ namespace v2rayN.Base | ||||||
|             UpdateStyles(); |             UpdateStyles(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         public void RegisterDragEvent(Action<int, int> _update) |         public void RegisterDragEvent(Action<int, int> update) | ||||||
|         { |         { | ||||||
|             _updateFunc = _update; |             _updateFunc = update; | ||||||
|             this.AllowDrop = true; |             AllowDrop = true; | ||||||
| 
 | 
 | ||||||
|             this.ItemDrag += new ItemDragEventHandler(this.lv_ItemDrag); |             ItemDrag += lv_ItemDrag; | ||||||
|             this.DragDrop += new DragEventHandler(this.lv_DragDrop); |             DragDrop += lv_DragDrop; | ||||||
|             this.DragEnter += new DragEventHandler(this.lv_DragEnter); |             DragEnter += lv_DragEnter; | ||||||
|             this.DragOver += new DragEventHandler(this.lv_DragOver); |             DragOver += lv_DragOver; | ||||||
|             this.DragLeave += new EventHandler(this.lv_DragLeave); |             DragLeave += lv_DragLeave; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void lv_DragDrop(object sender, DragEventArgs e) |         private void lv_DragDrop(object sender, DragEventArgs e) | ||||||
|         { |         { | ||||||
|             int targetIndex = this.InsertionMark.Index; |             int targetIndex = InsertionMark.Index; | ||||||
|             if (targetIndex == -1) |             if (targetIndex == -1) | ||||||
|             { |             { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             if (this.InsertionMark.AppearsAfterItem) |             if (InsertionMark.AppearsAfterItem) | ||||||
|             { |             { | ||||||
|                 targetIndex++; |                 targetIndex++; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|             if (this.SelectedIndices.Count <= 0) |             if (SelectedIndices.Count <= 0) | ||||||
|             { |             { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             _updateFunc(this.SelectedIndices[0], targetIndex); |             _updateFunc(SelectedIndices[0], targetIndex); | ||||||
| 
 | 
 | ||||||
|             //ListViewItem draggedItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); |             //ListViewItem draggedItem = (ListViewItem)e.Data.GetData(typeof(ListViewItem)); | ||||||
|             //this.BeginUpdate(); |             //this.BeginUpdate(); | ||||||
|  | @ -63,35 +63,35 @@ namespace v2rayN.Base | ||||||
| 
 | 
 | ||||||
|         private void lv_DragLeave(object sender, EventArgs e) |         private void lv_DragLeave(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.InsertionMark.Index = -1; |             InsertionMark.Index = -1; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void lv_DragOver(object sender, DragEventArgs e) |         private void lv_DragOver(object sender, DragEventArgs e) | ||||||
|         { |         { | ||||||
|             Point targetPoint = this.PointToClient(new Point(e.X, e.Y)); |             Point targetPoint = PointToClient(new Point(e.X, e.Y)); | ||||||
|             int targetIndex = this.InsertionMark.NearestIndex(targetPoint); |             int targetIndex = InsertionMark.NearestIndex(targetPoint); | ||||||
| 
 | 
 | ||||||
|             if (targetIndex > -1) |             if (targetIndex > -1) | ||||||
|             { |             { | ||||||
|                 Rectangle itemBounds = this.GetItemRect(targetIndex); |                 Rectangle itemBounds = GetItemRect(targetIndex); | ||||||
|                 this.EnsureVisible(targetIndex); |                 EnsureVisible(targetIndex); | ||||||
| 
 | 
 | ||||||
|                 if (targetPoint.Y > itemBounds.Top + (itemBounds.Height / 2)) |                 if (targetPoint.Y > itemBounds.Top + (itemBounds.Height / 2)) | ||||||
|                 { |                 { | ||||||
|                     this.InsertionMark.AppearsAfterItem = true; |                     InsertionMark.AppearsAfterItem = true; | ||||||
|                 } |                 } | ||||||
|                 else |                 else | ||||||
|                 { |                 { | ||||||
|                     this.InsertionMark.AppearsAfterItem = false; |                     InsertionMark.AppearsAfterItem = false; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|             this.InsertionMark.Index = targetIndex; |             InsertionMark.Index = targetIndex; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void lv_ItemDrag(object sender, ItemDragEventArgs e) |         private void lv_ItemDrag(object sender, ItemDragEventArgs e) | ||||||
|         { |         { | ||||||
|             this.DoDragDrop(e.Item, DragDropEffects.Move); |             DoDragDrop(e.Item, DragDropEffects.Move); | ||||||
|             this.InsertionMark.Index = -1; |             InsertionMark.Index = -1; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | @ -32,8 +32,10 @@ namespace v2rayN.Forms | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 vmessItem = new VmessItem(); |                 vmessItem = new VmessItem | ||||||
|                 vmessItem.groupId = groupId; |                 { | ||||||
|  |                     groupId = groupId | ||||||
|  |                 }; | ||||||
|                 ClearServer(); |                 ClearServer(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -46,14 +48,7 @@ namespace v2rayN.Forms | ||||||
|             txtRemarks.Text = vmessItem.remarks; |             txtRemarks.Text = vmessItem.remarks; | ||||||
|             txtAddress.Text = vmessItem.address; |             txtAddress.Text = vmessItem.address; | ||||||
| 
 | 
 | ||||||
|             if (vmessItem.coreType == null) |             cmbCoreType.Text = vmessItem.coreType == null ? string.Empty : vmessItem.coreType.ToString(); | ||||||
|             { |  | ||||||
|                 cmbCoreType.Text = string.Empty; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 cmbCoreType.Text = vmessItem.coreType.ToString(); |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -90,7 +85,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (ConfigHandler.EditCustomServer(ref config, vmessItem) == 0) |             if (ConfigHandler.EditCustomServer(ref config, vmessItem) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -100,14 +95,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             if (Utils.IsNullOrEmpty(vmessItem.indexId)) |             DialogResult = Utils.IsNullOrEmpty(vmessItem.indexId) ? DialogResult.Cancel : DialogResult.OK; | ||||||
|             { |  | ||||||
|                 this.DialogResult = DialogResult.Cancel; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 this.DialogResult = DialogResult.OK; |  | ||||||
|             } |  | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnBrowse_Click(object sender, EventArgs e) |         private void btnBrowse_Click(object sender, EventArgs e) | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void AddServerForm_Load(object sender, EventArgs e) |         private void AddServerForm_Load(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.Text = (eConfigType).ToString(); |             Text = (eConfigType).ToString(); | ||||||
|              |              | ||||||
|             cmbCoreType.Items.AddRange(Global.coreTypes.ToArray()); |             cmbCoreType.Items.AddRange(Global.coreTypes.ToArray()); | ||||||
|             cmbCoreType.Items.Add(string.Empty); |             cmbCoreType.Items.Add(string.Empty); | ||||||
|  | @ -41,7 +41,7 @@ namespace v2rayN.Forms | ||||||
|                     panSocks.Dock = DockStyle.Fill; |                     panSocks.Dock = DockStyle.Fill; | ||||||
|                     panSocks.Visible = true; |                     panSocks.Visible = true; | ||||||
|                     panTran.Visible = false; |                     panTran.Visible = false; | ||||||
|                     this.Height = this.Height - panTran.Height; |                     Height = Height - panTran.Height; | ||||||
|                     break; |                     break; | ||||||
|                 case EConfigType.VLESS: |                 case EConfigType.VLESS: | ||||||
|                     panVless.Dock = DockStyle.Fill; |                     panVless.Dock = DockStyle.Fill; | ||||||
|  | @ -65,8 +65,10 @@ namespace v2rayN.Forms | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 vmessItem = new VmessItem(); |                 vmessItem = new VmessItem | ||||||
|                 vmessItem.groupId = groupId; |                 { | ||||||
|  |                     groupId = groupId | ||||||
|  |                 }; | ||||||
|                 ClearServer(); |                 ClearServer(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -106,14 +108,7 @@ namespace v2rayN.Forms | ||||||
|                     break; |                     break; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (vmessItem.coreType == null) |             cmbCoreType.Text = vmessItem.coreType == null ? string.Empty : vmessItem.coreType.ToString(); | ||||||
|             { |  | ||||||
|                 cmbCoreType.Text = string.Empty; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 cmbCoreType.Text = vmessItem.coreType.ToString(); |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             transportControl.BindingServer(vmessItem); |             transportControl.BindingServer(vmessItem); | ||||||
|         } |         } | ||||||
|  | @ -267,7 +262,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (ret == 0) |             if (ret == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -284,7 +279,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -21,11 +21,11 @@ namespace v2rayN.Forms | ||||||
|                 string file = Utils.GetPath(Global.CustomIconName); |                 string file = Utils.GetPath(Global.CustomIconName); | ||||||
|                 if (System.IO.File.Exists(file)) |                 if (System.IO.File.Exists(file)) | ||||||
|                 { |                 { | ||||||
|                     this.Icon = new System.Drawing.Icon(file); |                     Icon = new System.Drawing.Icon(file); | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 this.Icon = Properties.Resources.NotifyIcon1; |                 Icon = Properties.Resources.NotifyIcon1; | ||||||
|             } |             } | ||||||
|             catch (Exception e) |             catch (Exception e) | ||||||
|             { |             { | ||||||
|  |  | ||||||
|  | @ -101,7 +101,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (ConfigHandler.SaveConfig(ref config, false) == 0) |             if (ConfigHandler.SaveConfig(ref config, false) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -111,7 +111,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnReset_Click(object sender, EventArgs e) |         private void btnReset_Click(object sender, EventArgs e) | ||||||
|  |  | ||||||
|  | @ -23,7 +23,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void GroupSettingControl_Load(object sender, EventArgs e) |         private void GroupSettingControl_Load(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.Height = grbMain.Height; |             Height = grbMain.Height; | ||||||
|             BindingSub(); |             BindingSub(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -70,7 +70,7 @@ namespace v2rayN.Forms | ||||||
|         {             |         {             | ||||||
|             if (ConfigHandler.SaveGroupItem(ref config) == 0) |             if (ConfigHandler.SaveGroupItem(ref config) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -80,7 +80,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnAdd_Click(object sender, EventArgs e) |         private void btnAdd_Click(object sender, EventArgs e) | ||||||
|  |  | ||||||
|  | @ -18,8 +18,8 @@ namespace v2rayN.Forms | ||||||
|     { |     { | ||||||
|         private V2rayHandler v2rayHandler; |         private V2rayHandler v2rayHandler; | ||||||
|         private List<VmessItem> lstSelecteds = new List<VmessItem>(); |         private List<VmessItem> lstSelecteds = new List<VmessItem>(); | ||||||
|         private StatisticsHandler statistics = null; |         private StatisticsHandler statistics; | ||||||
|         private List<VmessItem> lstVmess = null; |         private List<VmessItem> lstVmess; | ||||||
|         private string groupId = string.Empty; |         private string groupId = string.Empty; | ||||||
|         private string serverFilter = string.Empty; |         private string serverFilter = string.Empty; | ||||||
| 
 | 
 | ||||||
|  | @ -28,10 +28,10 @@ namespace v2rayN.Forms | ||||||
|         public MainForm() |         public MainForm() | ||||||
|         { |         { | ||||||
|             InitializeComponent(); |             InitializeComponent(); | ||||||
|             this.ShowInTaskbar = false; |             ShowInTaskbar = false; | ||||||
|             this.WindowState = FormWindowState.Minimized; |             WindowState = FormWindowState.Minimized; | ||||||
|             HideForm(); |             HideForm(); | ||||||
|             this.Text = Utils.GetVersion(); |             Text = Utils.GetVersion(); | ||||||
|             Global.processJob = new Job(); |             Global.processJob = new Job(); | ||||||
| 
 | 
 | ||||||
|             Application.ApplicationExit += (sender, args) => |             Application.ApplicationExit += (sender, args) => | ||||||
|  | @ -154,12 +154,12 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (!config.uiItem.mainLocation.IsEmpty) |             if (!config.uiItem.mainLocation.IsEmpty) | ||||||
|             { |             { | ||||||
|                 this.Location = config.uiItem.mainLocation; |                 Location = config.uiItem.mainLocation; | ||||||
|             } |             } | ||||||
|             if (!config.uiItem.mainSize.IsEmpty) |             if (!config.uiItem.mainSize.IsEmpty) | ||||||
|             { |             { | ||||||
|                 this.Width = config.uiItem.mainSize.Width; |                 Width = config.uiItem.mainSize.Width; | ||||||
|                 this.Height = config.uiItem.mainSize.Height; |                 Height = config.uiItem.mainSize.Height; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -172,9 +172,9 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void StorageUI() |         private void StorageUI() | ||||||
|         { |         { | ||||||
|             config.uiItem.mainLocation = this.Location; |             config.uiItem.mainLocation = Location; | ||||||
| 
 | 
 | ||||||
|             config.uiItem.mainSize = new Size(this.Width, this.Height); |             config.uiItem.mainSize = new Size(Width, Height); | ||||||
| 
 | 
 | ||||||
|             for (int k = 0; k < lvServers.Columns.Count; k++) |             for (int k = 0; k < lvServers.Columns.Count; k++) | ||||||
|             { |             { | ||||||
|  | @ -187,7 +187,7 @@ namespace v2rayN.Forms | ||||||
|             switch (Utils.ToInt(e.Name)) |             switch (Utils.ToInt(e.Name)) | ||||||
|             { |             { | ||||||
|                 case (int)EGlobalHotkey.ShowForm: |                 case (int)EGlobalHotkey.ShowForm: | ||||||
|                     if (this.ShowInTaskbar) HideForm(); else ShowForm(); |                     if (ShowInTaskbar) HideForm(); else ShowForm(); | ||||||
|                     break; |                     break; | ||||||
|                 case (int)EGlobalHotkey.SystemProxyClear: |                 case (int)EGlobalHotkey.SystemProxyClear: | ||||||
|                     SetListenerType(ESysProxyType.ForcedClear); |                     SetListenerType(ESysProxyType.ForcedClear); | ||||||
|  | @ -212,8 +212,8 @@ namespace v2rayN.Forms | ||||||
|         private void RefreshServers() |         private void RefreshServers() | ||||||
|         { |         { | ||||||
|             lstVmess = config.vmess |             lstVmess = config.vmess | ||||||
|                 .Where(it => Utils.IsNullOrEmpty(groupId) ? true : it.groupId == groupId) |                 .Where(it => Utils.IsNullOrEmpty(groupId) || it.groupId == groupId) | ||||||
|                 .Where(it => Utils.IsNullOrEmpty(serverFilter) ? true : it.remarks.Contains(serverFilter)) |                 .Where(it => Utils.IsNullOrEmpty(serverFilter) || it.remarks.Contains(serverFilter)) | ||||||
|                 .OrderBy(it => it.sort) |                 .OrderBy(it => it.sort) | ||||||
|                 .ToList(); |                 .ToList(); | ||||||
| 
 | 
 | ||||||
|  | @ -371,7 +371,7 @@ namespace v2rayN.Forms | ||||||
|                 { |                 { | ||||||
|                     ts.Checked = true; |                     ts.Checked = true; | ||||||
|                 } |                 } | ||||||
|                 ts.Click += new EventHandler(ts_Click); |                 ts.Click += ts_Click; | ||||||
|                 lst.Add(ts); |                 lst.Add(ts); | ||||||
|             } |             } | ||||||
|             menuServers.DropDownItems.AddRange(lst.ToArray()); |             menuServers.DropDownItems.AddRange(lst.ToArray()); | ||||||
|  | @ -415,7 +415,7 @@ namespace v2rayN.Forms | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 var tag = lvServers.Columns[e.Column].Tag?.ToString(); |                 var tag = lvServers.Columns[e.Column].Tag?.ToString(); | ||||||
|                 bool asc = Utils.IsNullOrEmpty(tag) ? true : !Convert.ToBoolean(tag); |                 bool asc = Utils.IsNullOrEmpty(tag) || !Convert.ToBoolean(tag); | ||||||
|                 if (ConfigHandler.SortServers(ref config, ref lstVmess, (EServerColName)e.Column, asc) != 0) |                 if (ConfigHandler.SortServers(ref config, ref lstVmess, (EServerColName)e.Column, asc) != 0) | ||||||
|                 { |                 { | ||||||
|                     return; |                     return; | ||||||
|  | @ -465,7 +465,7 @@ namespace v2rayN.Forms | ||||||
|                 { |                 { | ||||||
|                     Tag = item.id, |                     Tag = item.id, | ||||||
|                 }; |                 }; | ||||||
|                 ts.Click += new EventHandler(ts_Group_Click); |                 ts.Click += ts_Group_Click; | ||||||
|                 lst.Add(ts); |                 lst.Add(ts); | ||||||
|             } |             } | ||||||
|             menuMoveToGroup.DropDownItems.AddRange(lst.ToArray()); |             menuMoveToGroup.DropDownItems.AddRange(lst.ToArray()); | ||||||
|  | @ -516,7 +516,7 @@ namespace v2rayN.Forms | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         async Task LoadV2ray() |         async Task LoadV2ray() | ||||||
|         { |         { | ||||||
|             this.BeginInvoke(new Action(() => |             BeginInvoke(new Action(() => | ||||||
|             { |             { | ||||||
|                 tsbReload.Enabled = false; |                 tsbReload.Enabled = false; | ||||||
|             })); |             })); | ||||||
|  | @ -536,7 +536,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             ChangePACButtonStatus(config.sysProxyType); |             ChangePACButtonStatus(config.sysProxyType); | ||||||
| 
 | 
 | ||||||
|             this.BeginInvoke(new Action(() => |             BeginInvoke(new Action(() => | ||||||
|             { |             { | ||||||
|                 tsbReload.Enabled = true; |                 tsbReload.Enabled = true; | ||||||
|             })); |             })); | ||||||
|  | @ -1085,8 +1085,8 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void menuExit_Click(object sender, EventArgs e) |         private void menuExit_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.Visible = false; |             Visible = false; | ||||||
|             this.Close(); |             Close(); | ||||||
| 
 | 
 | ||||||
|             Application.Exit(); |             Application.Exit(); | ||||||
|         } |         } | ||||||
|  | @ -1094,13 +1094,13 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void ShowForm() |         private void ShowForm() | ||||||
|         { |         { | ||||||
|             this.Show(); |             Show(); | ||||||
|             if (this.WindowState == FormWindowState.Minimized) |             if (WindowState == FormWindowState.Minimized) | ||||||
|             { |             { | ||||||
|                 this.WindowState = FormWindowState.Normal; |                 WindowState = FormWindowState.Normal; | ||||||
|             } |             } | ||||||
|             this.Activate(); |             Activate(); | ||||||
|             this.ShowInTaskbar = true; |             ShowInTaskbar = true; | ||||||
|             //this.notifyIcon1.Visible = false; |             //this.notifyIcon1.Visible = false; | ||||||
|             mainMsgControl.ScrollToCaret(); |             mainMsgControl.ScrollToCaret(); | ||||||
| 
 | 
 | ||||||
|  | @ -1117,10 +1117,10 @@ namespace v2rayN.Forms | ||||||
|         private void HideForm() |         private void HideForm() | ||||||
|         { |         { | ||||||
|             //this.WindowState = FormWindowState.Minimized; |             //this.WindowState = FormWindowState.Minimized; | ||||||
|             this.Hide(); |             Hide(); | ||||||
|             //this.notifyMain.Icon = this.Icon; |             //this.notifyMain.Icon = this.Icon; | ||||||
|             this.notifyMain.Visible = true; |             notifyMain.Visible = true; | ||||||
|             this.ShowInTaskbar = false; |             ShowInTaskbar = false; | ||||||
| 
 | 
 | ||||||
|             SetVisibleCore(false); |             SetVisibleCore(false); | ||||||
|         } |         } | ||||||
|  | @ -1293,9 +1293,9 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             mainMsgControl.DisplayToolStatus(config); |             mainMsgControl.DisplayToolStatus(config); | ||||||
| 
 | 
 | ||||||
|             this.BeginInvoke(new Action(() => |             BeginInvoke(new Action(() => | ||||||
|             { |             { | ||||||
|                 notifyMain.Icon = this.Icon = MainFormHandler.Instance.GetNotifyIcon(config, this.Icon); |                 notifyMain.Icon = Icon = MainFormHandler.Instance.GetNotifyIcon(config, Icon); | ||||||
|             })); |             })); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -1487,7 +1487,7 @@ namespace v2rayN.Forms | ||||||
|                     ts.Checked = true; |                     ts.Checked = true; | ||||||
|                     mainMsgControl.SetToolSslInfo("routing", item.remarks); |                     mainMsgControl.SetToolSslInfo("routing", item.remarks); | ||||||
|                 } |                 } | ||||||
|                 ts.Click += new EventHandler(ts_Routing_Click); |                 ts.Click += ts_Routing_Click; | ||||||
|                 lst.Add(ts); |                 lst.Add(ts); | ||||||
|             } |             } | ||||||
|             menuRoutings.DropDownItems.AddRange(lst.ToArray()); |             menuRoutings.DropDownItems.AddRange(lst.ToArray()); | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ namespace v2rayN.Forms | ||||||
| { | { | ||||||
|     public partial class MainMsgControl : UserControl |     public partial class MainMsgControl : UserControl | ||||||
|     { |     { | ||||||
|         private string MsgFilter = string.Empty; |         private string _msgFilter = string.Empty; | ||||||
|         delegate void AppendTextDelegate(string text); |         delegate void AppendTextDelegate(string text); | ||||||
| 
 | 
 | ||||||
|         public MainMsgControl() |         public MainMsgControl() | ||||||
|  | @ -33,15 +33,15 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         public void AppendText(string text) |         public void AppendText(string text) | ||||||
|         { |         { | ||||||
|             if (this.txtMsgBox.InvokeRequired) |             if (txtMsgBox.InvokeRequired) | ||||||
|             { |             { | ||||||
|                 Invoke(new AppendTextDelegate(AppendText), new object[] { text }); |                 Invoke(new AppendTextDelegate(AppendText), text); | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 if (!Utils.IsNullOrEmpty(MsgFilter)) |                 if (!Utils.IsNullOrEmpty(_msgFilter)) | ||||||
|                 { |                 { | ||||||
|                     if (!Regex.IsMatch(text, MsgFilter)) |                     if (!Regex.IsMatch(text, _msgFilter)) | ||||||
|                     { |                     { | ||||||
|                         return; |                         return; | ||||||
|                     } |                     } | ||||||
|  | @ -61,10 +61,10 @@ namespace v2rayN.Forms | ||||||
|             { |             { | ||||||
|                 ClearMsg(); |                 ClearMsg(); | ||||||
|             } |             } | ||||||
|             this.txtMsgBox.AppendText(msg); |             txtMsgBox.AppendText(msg); | ||||||
|             if (!msg.EndsWith(Environment.NewLine)) |             if (!msg.EndsWith(Environment.NewLine)) | ||||||
|             { |             { | ||||||
|                 this.txtMsgBox.AppendText(Environment.NewLine); |                 txtMsgBox.AppendText(Environment.NewLine); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -124,7 +124,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         public void ScrollToCaret() |         public void ScrollToCaret() | ||||||
|         { |         { | ||||||
|             this.txtMsgBox.ScrollToCaret(); |             txtMsgBox.ScrollToCaret(); | ||||||
|         } |         } | ||||||
|         #endregion |         #endregion | ||||||
| 
 | 
 | ||||||
|  | @ -132,24 +132,24 @@ namespace v2rayN.Forms | ||||||
|         #region MsgBoxMenu |         #region MsgBoxMenu | ||||||
|         private void menuMsgBoxSelectAll_Click(object sender, EventArgs e) |         private void menuMsgBoxSelectAll_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.txtMsgBox.Focus(); |             txtMsgBox.Focus(); | ||||||
|             this.txtMsgBox.SelectAll(); |             txtMsgBox.SelectAll(); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void menuMsgBoxCopy_Click(object sender, EventArgs e) |         private void menuMsgBoxCopy_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             var data = this.txtMsgBox.SelectedText.TrimEx(); |             var data = txtMsgBox.SelectedText.TrimEx(); | ||||||
|             Utils.SetClipboardData(data); |             Utils.SetClipboardData(data); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void menuMsgBoxCopyAll_Click(object sender, EventArgs e) |         private void menuMsgBoxCopyAll_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             var data = this.txtMsgBox.Text; |             var data = txtMsgBox.Text; | ||||||
|             Utils.SetClipboardData(data); |             Utils.SetClipboardData(data); | ||||||
|         } |         } | ||||||
|         private void menuMsgBoxClear_Click(object sender, EventArgs e) |         private void menuMsgBoxClear_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.txtMsgBox.Clear(); |             txtMsgBox.Clear(); | ||||||
|         } |         } | ||||||
|         private void menuMsgBoxAddRoutingRule_Click(object sender, EventArgs e) |         private void menuMsgBoxAddRoutingRule_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|  | @ -182,12 +182,12 @@ namespace v2rayN.Forms | ||||||
|         private void menuMsgBoxFilter_Click(object sender, EventArgs e) |         private void menuMsgBoxFilter_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             var fm = new MsgFilterSetForm(); |             var fm = new MsgFilterSetForm(); | ||||||
|             fm.MsgFilter = MsgFilter; |             fm.MsgFilter = _msgFilter; | ||||||
|             fm.ShowDefFilter = true; |             fm.ShowDefFilter = true; | ||||||
|             if (fm.ShowDialog() == DialogResult.OK) |             if (fm.ShowDialog() == DialogResult.OK) | ||||||
|             { |             { | ||||||
|                 MsgFilter = fm.MsgFilter; |                 _msgFilter = fm.MsgFilter; | ||||||
|                 gbMsgTitle.Text = string.Format(ResUI.MsgInformationTitle, MsgFilter); |                 gbMsgTitle.Text = string.Format(ResUI.MsgInformationTitle, _msgFilter); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -30,12 +30,12 @@ namespace v2rayN.Forms | ||||||
|         private void btnOK_Click(object sender, EventArgs e) |         private void btnOK_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             MsgFilter = txtMsgFilter.Text; |             MsgFilter = txtMsgFilter.Text; | ||||||
|             this.DialogResult = DialogResult.OK; |             DialogResult = DialogResult.OK; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnFilderProxy_Click(object sender, EventArgs e) |         private void btnFilderProxy_Click(object sender, EventArgs e) | ||||||
|  | @ -51,7 +51,7 @@ namespace v2rayN.Forms | ||||||
|         private void btnClear_Click(object sender, EventArgs e) |         private void btnClear_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             MsgFilter = string.Empty; |             MsgFilter = string.Empty; | ||||||
|             this.DialogResult = DialogResult.OK; |             DialogResult = DialogResult.OK; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -177,7 +177,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (ConfigHandler.SaveConfig(ref config) == 0) |             if (ConfigHandler.SaveConfig(ref config) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -335,7 +335,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -115,34 +115,28 @@ namespace v2rayN.Forms | ||||||
|         private void btnOK_Click(object sender, EventArgs e) |         private void btnOK_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             EndBindingData(); |             EndBindingData(); | ||||||
|             var hasRule = false; | 
 | ||||||
|             if (rulesItem.domain != null && rulesItem.domain.Count > 0) |             bool hasRule =  | ||||||
|             { |                 rulesItem.domain != null  | ||||||
|                 hasRule = true; |                 && rulesItem.domain.Count > 0  | ||||||
|             } |                 || rulesItem.ip != null  | ||||||
|             if (rulesItem.ip != null && rulesItem.ip.Count > 0) |                 && rulesItem.ip.Count > 0  | ||||||
|             { |                 || rulesItem.protocol != null  | ||||||
|                 hasRule = true; |                 && rulesItem.protocol.Count > 0  | ||||||
|             } |                 || !Utils.IsNullOrEmpty(rulesItem.port); | ||||||
|             if (rulesItem.protocol != null && rulesItem.protocol.Count > 0) | 
 | ||||||
|             { |  | ||||||
|                 hasRule = true; |  | ||||||
|             } |  | ||||||
|             if (!Utils.IsNullOrEmpty(rulesItem.port)) |  | ||||||
|             { |  | ||||||
|                 hasRule = true; |  | ||||||
|             } |  | ||||||
|             if (!hasRule) |             if (!hasRule) | ||||||
|             { |             { | ||||||
|                 UI.ShowWarning(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP")); |                 UI.ShowWarning(string.Format(ResUI.RoutingRuleDetailRequiredTips, "Port/Protocol/Domain/IP")); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             this.DialogResult = DialogResult.OK; | 
 | ||||||
|  |             DialogResult = DialogResult.OK; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -15,9 +15,9 @@ namespace v2rayN.Forms | ||||||
|         { |         { | ||||||
|             get; set; |             get; set; | ||||||
|         } |         } | ||||||
|         protected RoutingItem routingItem = null; |         protected RoutingItem routingItem; | ||||||
| 
 | 
 | ||||||
|         private List<int> lvSelecteds = new List<int>(); |         private readonly List<int> lvSelecteds = new List<int>(); | ||||||
|         public RoutingRuleSettingForm() |         public RoutingRuleSettingForm() | ||||||
|         { |         { | ||||||
|             InitializeComponent(); |             InitializeComponent(); | ||||||
|  | @ -25,14 +25,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void RoutingRuleSettingForm_Load(object sender, EventArgs e) |         private void RoutingRuleSettingForm_Load(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             if (EditIndex >= 0) |             routingItem = EditIndex >= 0 ? config.routings[EditIndex] : new RoutingItem(); | ||||||
|             { |  | ||||||
|                 routingItem = config.routings[EditIndex]; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 routingItem = new RoutingItem(); |  | ||||||
|             } |  | ||||||
|             if (routingItem.rules == null) |             if (routingItem.rules == null) | ||||||
|             { |             { | ||||||
|                 routingItem.rules = new List<RulesItem>(); |                 routingItem.rules = new List<RulesItem>(); | ||||||
|  | @ -86,10 +79,8 @@ namespace v2rayN.Forms | ||||||
|             lvRoutings.BeginUpdate(); |             lvRoutings.BeginUpdate(); | ||||||
|             lvRoutings.Items.Clear(); |             lvRoutings.Items.Clear(); | ||||||
| 
 | 
 | ||||||
|             for (int k = 0; k < routingItem.rules.Count; k++) |             foreach (var item in routingItem.rules) | ||||||
|             { |             { | ||||||
|                 var item = routingItem.rules[k]; |  | ||||||
| 
 |  | ||||||
|                 ListViewItem lvItem = new ListViewItem(""); |                 ListViewItem lvItem = new ListViewItem(""); | ||||||
|                 Utils.AddSubItem(lvItem, "outboundTag", item.outboundTag); |                 Utils.AddSubItem(lvItem, "outboundTag", item.outboundTag); | ||||||
|                 Utils.AddSubItem(lvItem, "port", item.port); |                 Utils.AddSubItem(lvItem, "port", item.port); | ||||||
|  | @ -112,7 +103,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (ConfigHandler.AddRoutingItem(ref config, routingItem, EditIndex) == 0) |             if (ConfigHandler.AddRoutingItem(ref config, routingItem, EditIndex) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -122,7 +113,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
|         private void btnBrowse_Click(object sender, EventArgs e) |         private void btnBrowse_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -10,8 +10,8 @@ namespace v2rayN.Forms | ||||||
| { | { | ||||||
|     public partial class RoutingSettingForm : BaseForm |     public partial class RoutingSettingForm : BaseForm | ||||||
|     { |     { | ||||||
|         private List<int> lvSelecteds = new List<int>(); |         private readonly List<int> _lvSelecteds = new List<int>(); | ||||||
|         private RoutingItem lockedItem; |         private RoutingItem _lockedItem; | ||||||
|         public RoutingSettingForm() |         public RoutingSettingForm() | ||||||
|         { |         { | ||||||
|             InitializeComponent(); |             InitializeComponent(); | ||||||
|  | @ -58,7 +58,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|             if (ConfigHandler.SaveRouting(ref config) == 0) |             if (ConfigHandler.SaveRouting(ref config) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -68,7 +68,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
|         private void chkenableRoutingAdvanced_CheckedChanged_1(object sender, EventArgs e) |         private void chkenableRoutingAdvanced_CheckedChanged_1(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|  | @ -78,20 +78,20 @@ namespace v2rayN.Forms | ||||||
|         { |         { | ||||||
|             if (chkenableRoutingAdvanced.Checked) |             if (chkenableRoutingAdvanced.Checked) | ||||||
|             { |             { | ||||||
|                 this.tabPageProxy.Parent = null; |                 tabPageProxy.Parent = null; | ||||||
|                 this.tabPageDirect.Parent = null; |                 tabPageDirect.Parent = null; | ||||||
|                 this.tabPageBlock.Parent = null; |                 tabPageBlock.Parent = null; | ||||||
|                 this.tabPageRuleList.Parent = tabNormal; |                 tabPageRuleList.Parent = tabNormal; | ||||||
|                 MenuItemBasic.Enabled = false; |                 MenuItemBasic.Enabled = false; | ||||||
|                 MenuItemAdvanced.Enabled = true; |                 MenuItemAdvanced.Enabled = true; | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 this.tabPageProxy.Parent = tabNormal; |                 tabPageProxy.Parent = tabNormal; | ||||||
|                 this.tabPageDirect.Parent = tabNormal; |                 tabPageDirect.Parent = tabNormal; | ||||||
|                 this.tabPageBlock.Parent = tabNormal; |                 tabPageBlock.Parent = tabNormal; | ||||||
|                 this.tabPageRuleList.Parent = null; |                 tabPageRuleList.Parent = null; | ||||||
|                 MenuItemBasic.Enabled = true; |                 MenuItemBasic.Enabled = true; | ||||||
|                 MenuItemAdvanced.Enabled = false; |                 MenuItemAdvanced.Enabled = false; | ||||||
|             } |             } | ||||||
|  | @ -102,31 +102,31 @@ namespace v2rayN.Forms | ||||||
|         #region locked |         #region locked | ||||||
|         private void BindingLockedData() |         private void BindingLockedData() | ||||||
|         { |         { | ||||||
|             lockedItem = ConfigHandler.GetLockedRoutingItem(ref config); |             _lockedItem = ConfigHandler.GetLockedRoutingItem(ref config); | ||||||
|             if (lockedItem != null) |             if (_lockedItem != null) | ||||||
|             { |             { | ||||||
|                 txtProxyDomain.Text = Utils.List2String(lockedItem.rules[0].domain, true); |                 txtProxyDomain.Text = Utils.List2String(_lockedItem.rules[0].domain, true); | ||||||
|                 txtProxyIp.Text = Utils.List2String(lockedItem.rules[0].ip, true); |                 txtProxyIp.Text = Utils.List2String(_lockedItem.rules[0].ip, true); | ||||||
| 
 | 
 | ||||||
|                 txtDirectDomain.Text = Utils.List2String(lockedItem.rules[1].domain, true); |                 txtDirectDomain.Text = Utils.List2String(_lockedItem.rules[1].domain, true); | ||||||
|                 txtDirectIp.Text = Utils.List2String(lockedItem.rules[1].ip, true); |                 txtDirectIp.Text = Utils.List2String(_lockedItem.rules[1].ip, true); | ||||||
| 
 | 
 | ||||||
|                 txtBlockDomain.Text = Utils.List2String(lockedItem.rules[2].domain, true); |                 txtBlockDomain.Text = Utils.List2String(_lockedItem.rules[2].domain, true); | ||||||
|                 txtBlockIp.Text = Utils.List2String(lockedItem.rules[2].ip, true); |                 txtBlockIp.Text = Utils.List2String(_lockedItem.rules[2].ip, true); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         private void EndBindingLockedData() |         private void EndBindingLockedData() | ||||||
|         { |         { | ||||||
|             if (lockedItem != null) |             if (_lockedItem != null) | ||||||
|             { |             { | ||||||
|                 lockedItem.rules[0].domain = Utils.String2List(txtProxyDomain.Text.TrimEx()); |                 _lockedItem.rules[0].domain = Utils.String2List(txtProxyDomain.Text.TrimEx()); | ||||||
|                 lockedItem.rules[0].ip = Utils.String2List(txtProxyIp.Text.TrimEx()); |                 _lockedItem.rules[0].ip = Utils.String2List(txtProxyIp.Text.TrimEx()); | ||||||
| 
 | 
 | ||||||
|                 lockedItem.rules[1].domain = Utils.String2List(txtDirectDomain.Text.TrimEx()); |                 _lockedItem.rules[1].domain = Utils.String2List(txtDirectDomain.Text.TrimEx()); | ||||||
|                 lockedItem.rules[1].ip = Utils.String2List(txtDirectIp.Text.TrimEx()); |                 _lockedItem.rules[1].ip = Utils.String2List(txtDirectIp.Text.TrimEx()); | ||||||
| 
 | 
 | ||||||
|                 lockedItem.rules[2].domain = Utils.String2List(txtBlockDomain.Text.TrimEx()); |                 _lockedItem.rules[2].domain = Utils.String2List(txtBlockDomain.Text.TrimEx()); | ||||||
|                 lockedItem.rules[2].ip = Utils.String2List(txtBlockIp.Text.TrimEx()); |                 _lockedItem.rules[2].ip = Utils.String2List(txtBlockIp.Text.TrimEx()); | ||||||
| 
 | 
 | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | @ -207,7 +207,7 @@ namespace v2rayN.Forms | ||||||
|         private int GetLvSelectedIndex() |         private int GetLvSelectedIndex() | ||||||
|         { |         { | ||||||
|             int index = -1; |             int index = -1; | ||||||
|             lvSelecteds.Clear(); |             _lvSelecteds.Clear(); | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 if (lvRoutings.SelectedIndices.Count <= 0) |                 if (lvRoutings.SelectedIndices.Count <= 0) | ||||||
|  | @ -219,7 +219,7 @@ namespace v2rayN.Forms | ||||||
|                 index = lvRoutings.SelectedIndices[0]; |                 index = lvRoutings.SelectedIndices[0]; | ||||||
|                 foreach (int i in lvRoutings.SelectedIndices) |                 foreach (int i in lvRoutings.SelectedIndices) | ||||||
|                 { |                 { | ||||||
|                     lvSelecteds.Add(i); |                     _lvSelecteds.Add(i); | ||||||
|                 } |                 } | ||||||
|                 return index; |                 return index; | ||||||
|             } |             } | ||||||
|  | @ -264,7 +264,7 @@ namespace v2rayN.Forms | ||||||
|             { |             { | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|             for (int k = lvSelecteds.Count - 1; k >= 0; k--) |             for (int k = _lvSelecteds.Count - 1; k >= 0; k--) | ||||||
|             { |             { | ||||||
|                 config.routings.RemoveAt(index); |                 config.routings.RemoveAt(index); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -9,7 +9,7 @@ namespace v2rayN.Forms | ||||||
|     public partial class ServerTransportControl : UserControl |     public partial class ServerTransportControl : UserControl | ||||||
|     { |     { | ||||||
|         public bool AllowXtls { get; set; } |         public bool AllowXtls { get; set; } | ||||||
|         private VmessItem vmessItem = null; |         private VmessItem vmessItem; | ||||||
| 
 | 
 | ||||||
|         public ServerTransportControl() |         public ServerTransportControl() | ||||||
|         { |         { | ||||||
|  |  | ||||||
|  | @ -26,7 +26,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void SubSettingControl_Load(object sender, EventArgs e) |         private void SubSettingControl_Load(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.Height = grbMain.Height; |             Height = grbMain.Height; | ||||||
| 
 | 
 | ||||||
|             groupItem = LazyConfig.Instance.GetConfig().groupItem; |             groupItem = LazyConfig.Instance.GetConfig().groupItem; | ||||||
| 
 | 
 | ||||||
|  | @ -90,7 +90,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnShare_Click(object sender, EventArgs e) |         private void btnShare_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             if (this.Height <= grbMain.Height) |             if (Height <= grbMain.Height) | ||||||
|             { |             { | ||||||
|                 if (Utils.IsNullOrEmpty(subItem.url)) |                 if (Utils.IsNullOrEmpty(subItem.url)) | ||||||
|                 { |                 { | ||||||
|  | @ -98,11 +98,11 @@ namespace v2rayN.Forms | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|                 picQRCode.Image = QRCodeHelper.GetQRCode(subItem.url); |                 picQRCode.Image = QRCodeHelper.GetQRCode(subItem.url); | ||||||
|                 this.Height = grbMain.Height + 200; |                 Height = grbMain.Height + 200; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|                 this.Height = grbMain.Height; |                 Height = grbMain.Height; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -71,7 +71,7 @@ namespace v2rayN.Forms | ||||||
|         { |         { | ||||||
|             if (ConfigHandler.SaveSubItem(ref config) == 0) |             if (ConfigHandler.SaveSubItem(ref config) == 0) | ||||||
|             { |             { | ||||||
|                 this.DialogResult = DialogResult.OK; |                 DialogResult = DialogResult.OK; | ||||||
|             } |             } | ||||||
|             else |             else | ||||||
|             { |             { | ||||||
|  | @ -81,7 +81,7 @@ namespace v2rayN.Forms | ||||||
| 
 | 
 | ||||||
|         private void btnClose_Click(object sender, EventArgs e) |         private void btnClose_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|             this.DialogResult = DialogResult.Cancel; |             DialogResult = DialogResult.Cancel; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void btnAdd_Click(object sender, EventArgs e) |         private void btnAdd_Click(object sender, EventArgs e) | ||||||
|  |  | ||||||
|  | @ -304,7 +304,7 @@ namespace v2rayN.Handler | ||||||
|             { |             { | ||||||
|                 VmessItem vmessItem = Utils.DeepCopy(item); |                 VmessItem vmessItem = Utils.DeepCopy(item); | ||||||
|                 vmessItem.indexId = string.Empty; |                 vmessItem.indexId = string.Empty; | ||||||
|                 vmessItem.remarks = string.Format("{0}-clone", item.remarks); |                 vmessItem.remarks = $"{item.remarks}-clone"; | ||||||
| 
 | 
 | ||||||
|                 if (vmessItem.configType == EConfigType.Custom) |                 if (vmessItem.configType == EConfigType.Custom) | ||||||
|                 { |                 { | ||||||
|  | @ -469,7 +469,7 @@ namespace v2rayN.Handler | ||||||
|                 return -1; |                 return -1; | ||||||
|             } |             } | ||||||
|             var ext = Path.GetExtension(fileName); |             var ext = Path.GetExtension(fileName); | ||||||
|             string newFileName = string.Format("{0}{1}", Utils.GetGUID(), ext); |             string newFileName = $"{Utils.GetGUID()}{ext}"; | ||||||
|             //newFileName = Path.Combine(Utils.GetTempPath(), newFileName); |             //newFileName = Path.Combine(Utils.GetTempPath(), newFileName); | ||||||
| 
 | 
 | ||||||
|             try |             try | ||||||
|  | @ -489,7 +489,7 @@ namespace v2rayN.Handler | ||||||
|             vmessItem.configType = EConfigType.Custom; |             vmessItem.configType = EConfigType.Custom; | ||||||
|             if (Utils.IsNullOrEmpty(vmessItem.remarks)) |             if (Utils.IsNullOrEmpty(vmessItem.remarks)) | ||||||
|             { |             { | ||||||
|                 vmessItem.remarks = string.Format("import custom@{0}", DateTime.Now.ToShortDateString()); |                 vmessItem.remarks = $"import custom@{DateTime.Now.ToShortDateString()}"; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -814,7 +814,7 @@ namespace v2rayN.Handler | ||||||
|                 && o.path == n.path |                 && o.path == n.path | ||||||
|                 && o.streamSecurity == n.streamSecurity |                 && o.streamSecurity == n.streamSecurity | ||||||
|                 && o.flow == n.flow |                 && o.flow == n.flow | ||||||
|                 && (remarks ? o.remarks == n.remarks : true); |                 && (!remarks || o.remarks == n.remarks); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private static int RemoveVmessItem(Config config, int index) |         private static int RemoveVmessItem(Config config, int index) | ||||||
|  | @ -1051,7 +1051,7 @@ namespace v2rayN.Handler | ||||||
|             if (lstSsServer == null || lstSsServer.Count <= 0) |             if (lstSsServer == null || lstSsServer.Count <= 0) | ||||||
|             { |             { | ||||||
|                 var ssSIP008 = Utils.FromJson<SsSIP008>(clipboardData); |                 var ssSIP008 = Utils.FromJson<SsSIP008>(clipboardData); | ||||||
|                 if (ssSIP008 != null && ssSIP008.servers != null && ssSIP008.servers.Count > 0) |                 if (ssSIP008?.servers != null && ssSIP008.servers.Count > 0) | ||||||
|                 { |                 { | ||||||
|                     lstSsServer = ssSIP008.servers; |                     lstSsServer = ssSIP008.servers; | ||||||
|                 } |                 } | ||||||
|  | @ -1154,12 +1154,9 @@ namespace v2rayN.Handler | ||||||
|                 return -1; |                 return -1; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             foreach (SubItem item in config.subItem) |             foreach (var item in config.subItem.Where(item => Utils.IsNullOrEmpty(item.id))) | ||||||
|             { |             { | ||||||
|                 if (Utils.IsNullOrEmpty(item.id)) |                 item.id = Utils.GetGUID(false); | ||||||
|                 { |  | ||||||
|                     item.id = Utils.GetGUID(false); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             ToJsonFile(config); |             ToJsonFile(config); | ||||||
|  | @ -1203,12 +1200,9 @@ namespace v2rayN.Handler | ||||||
|                 return -1; |                 return -1; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             foreach (GroupItem item in config.groupItem) |             foreach (var item in config.groupItem.Where(item => Utils.IsNullOrEmpty(item.id))) | ||||||
|             { |             { | ||||||
|                 if (Utils.IsNullOrEmpty(item.id)) |                 item.id = Utils.GetGUID(false); | ||||||
|                 { |  | ||||||
|                     item.id = Utils.GetGUID(false); |  | ||||||
|                 } |  | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             ToJsonFile(config); |             ToJsonFile(config); | ||||||
|  |  | ||||||
|  | @ -29,8 +29,8 @@ namespace v2rayN.Handler | ||||||
| 
 | 
 | ||||||
|             public ResultEventArgs(bool success, string msg) |             public ResultEventArgs(bool success, string msg) | ||||||
|             { |             { | ||||||
|                 this.Success = success; |                 Success = success; | ||||||
|                 this.Msg = msg; |                 Msg = msg; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -51,7 +51,7 @@ namespace v2rayN.Handler | ||||||
|                 { |                 { | ||||||
|                     if (UpdateCompleted != null) |                     if (UpdateCompleted != null) | ||||||
|                     { |                     { | ||||||
|                         string msg = string.Format("{0} M/s", value).PadLeft(9, ' '); |                         string msg = $"{value} M/s".PadLeft(9, ' '); | ||||||
|                         UpdateCompleted(this, new ResultEventArgs(false, msg)); |                         UpdateCompleted(this, new ResultEventArgs(false, msg)); | ||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|  | @ -88,7 +88,7 @@ namespace v2rayN.Handler | ||||||
|                 { |                 { | ||||||
|                     if (UpdateCompleted != null) |                     if (UpdateCompleted != null) | ||||||
|                     { |                     { | ||||||
|                         string msg = string.Format("...{0}%", value); |                         string msg = $"...{value}%"; | ||||||
|                         UpdateCompleted(this, new ResultEventArgs(value > 100 ? true : false, msg)); |                         UpdateCompleted(this, new ResultEventArgs(value > 100 ? true : false, msg)); | ||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|  |  | ||||||
|  | @ -11,10 +11,8 @@ namespace v2rayN.Handler | ||||||
|         private Config _config; |         private Config _config; | ||||||
|         private List<CoreInfo> coreInfos; |         private List<CoreInfo> coreInfos; | ||||||
| 
 | 
 | ||||||
|         public static LazyConfig Instance |         public static LazyConfig Instance => _instance.Value; | ||||||
|         { | 
 | ||||||
|             get { return _instance.Value; } |  | ||||||
|         } |  | ||||||
|         public void SetConfig(ref Config config) |         public void SetConfig(ref Config config) | ||||||
|         { |         { | ||||||
|             _config = config; |             _config = config; | ||||||
|  |  | ||||||
|  | @ -24,10 +24,8 @@ namespace v2rayN.Handler | ||||||
|         //private List<int> _selecteds; |         //private List<int> _selecteds; | ||||||
|         //private Thread _workThread; |         //private Thread _workThread; | ||||||
|         //Action<int, string> _updateFunc; |         //Action<int, string> _updateFunc; | ||||||
|         public static MainFormHandler Instance |         public static MainFormHandler Instance => instance.Value; | ||||||
|         { | 
 | ||||||
|             get { return instance.Value; } |  | ||||||
|         } |  | ||||||
|         public Icon GetNotifyIcon(Config config, Icon def) |         public Icon GetNotifyIcon(Config config, Icon def) | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|  | @ -84,7 +82,7 @@ namespace v2rayN.Handler | ||||||
|                 int index = (int)config.sysProxyType; |                 int index = (int)config.sysProxyType; | ||||||
|                 if (index > 0) |                 if (index > 0) | ||||||
|                 { |                 { | ||||||
|                     color = (new Color[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1]; |                     color = (new[] { Color.Red, Color.Purple, Color.DarkGreen, Color.Orange, Color.DarkSlateBlue, Color.RoyalBlue })[index - 1]; | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 int width = 128; |                 int width = 128; | ||||||
|  |  | ||||||
|  | @ -81,7 +81,7 @@ namespace v2rayN.Handler | ||||||
| 
 | 
 | ||||||
|             url = Utils.ToJson(vmessQRCode); |             url = Utils.ToJson(vmessQRCode); | ||||||
|             url = Utils.Base64Encode(url); |             url = Utils.Base64Encode(url); | ||||||
|             url = string.Format("{0}{1}", Global.vmessProtocol, url); |             url = $"{Global.vmessProtocol}{url}"; | ||||||
| 
 | 
 | ||||||
|             return url; |             return url; | ||||||
|         } |         } | ||||||
|  | @ -104,7 +104,7 @@ namespace v2rayN.Handler | ||||||
|             //new Sip002 |             //new Sip002 | ||||||
|             var pw = Utils.Base64Encode($"{item.security}:{item.id}"); |             var pw = Utils.Base64Encode($"{item.security}:{item.id}"); | ||||||
|             url = $"{pw}@{GetIpv6(item.address)}:{ item.port}"; |             url = $"{pw}@{GetIpv6(item.address)}:{ item.port}"; | ||||||
|             url = string.Format("{0}{1}{2}", Global.ssProtocol, url, remark); |             url = $"{Global.ssProtocol}{url}{remark}"; | ||||||
|             return url; |             return url; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -125,7 +125,7 @@ namespace v2rayN.Handler | ||||||
|             //new |             //new | ||||||
|             var pw = Utils.Base64Encode($"{item.security}:{item.id}"); |             var pw = Utils.Base64Encode($"{item.security}:{item.id}"); | ||||||
|             url = $"{pw}@{GetIpv6(item.address)}:{ item.port}"; |             url = $"{pw}@{GetIpv6(item.address)}:{ item.port}"; | ||||||
|             url = string.Format("{0}{1}{2}", Global.socksProtocol, url, remark); |             url = $"{Global.socksProtocol}{url}{remark}"; | ||||||
|             return url; |             return url; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -145,7 +145,7 @@ namespace v2rayN.Handler | ||||||
|             item.id, |             item.id, | ||||||
|             GetIpv6(item.address), |             GetIpv6(item.address), | ||||||
|             item.port); |             item.port); | ||||||
|             url = string.Format("{0}{1}{2}{3}", Global.trojanProtocol, url, query, remark); |             url = $"{Global.trojanProtocol}{url}{query}{remark}"; | ||||||
|             return url; |             return url; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -173,7 +173,7 @@ namespace v2rayN.Handler | ||||||
|             item.id, |             item.id, | ||||||
|             GetIpv6(item.address), |             GetIpv6(item.address), | ||||||
|             item.port); |             item.port); | ||||||
|             url = string.Format("{0}{1}{2}{3}", Global.vlessProtocol, url, query, remark); |             url = $"{Global.vlessProtocol}{url}{query}{remark}"; | ||||||
|             return url; |             return url; | ||||||
|         } |         } | ||||||
|         private static string GetIpv6(string address) |         private static string GetIpv6(string address) | ||||||
|  | @ -207,40 +207,20 @@ namespace v2rayN.Handler | ||||||
|             { |             { | ||||||
|                 dicQuery.Add("alpn", Utils.UrlEncode(Utils.List2String(item.alpn))); |                 dicQuery.Add("alpn", Utils.UrlEncode(Utils.List2String(item.alpn))); | ||||||
|             } |             } | ||||||
|             if (!Utils.IsNullOrEmpty(item.network)) | 
 | ||||||
|             { |             dicQuery.Add("type", !Utils.IsNullOrEmpty(item.network) ? item.network : "tcp"); | ||||||
|                 dicQuery.Add("type", item.network); |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 dicQuery.Add("type", "tcp"); |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             switch (item.network) |             switch (item.network) | ||||||
|             { |             { | ||||||
|                 case "tcp": |                 case "tcp": | ||||||
|                     if (!Utils.IsNullOrEmpty(item.headerType)) |                     dicQuery.Add("headerType", !Utils.IsNullOrEmpty(item.headerType) ? item.headerType : "none"); | ||||||
|                     { |  | ||||||
|                         dicQuery.Add("headerType", item.headerType); |  | ||||||
|                     } |  | ||||||
|                     else |  | ||||||
|                     { |  | ||||||
|                         dicQuery.Add("headerType", "none"); |  | ||||||
|                     } |  | ||||||
|                     if (!Utils.IsNullOrEmpty(item.requestHost)) |                     if (!Utils.IsNullOrEmpty(item.requestHost)) | ||||||
|                     { |                     { | ||||||
|                         dicQuery.Add("host", Utils.UrlEncode(item.requestHost)); |                         dicQuery.Add("host", Utils.UrlEncode(item.requestHost)); | ||||||
|                     } |                     } | ||||||
|                     break; |                     break; | ||||||
|                 case "kcp": |                 case "kcp": | ||||||
|                     if (!Utils.IsNullOrEmpty(item.headerType)) |                     dicQuery.Add("headerType", !Utils.IsNullOrEmpty(item.headerType) ? item.headerType : "none"); | ||||||
|                     { |  | ||||||
|                         dicQuery.Add("headerType", item.headerType); |  | ||||||
|                     } |  | ||||||
|                     else |  | ||||||
|                     { |  | ||||||
|                         dicQuery.Add("headerType", "none"); |  | ||||||
|                     } |  | ||||||
|                     if (!Utils.IsNullOrEmpty(item.path)) |                     if (!Utils.IsNullOrEmpty(item.path)) | ||||||
|                     { |                     { | ||||||
|                         dicQuery.Add("seed", Utils.UrlEncode(item.path)); |                         dicQuery.Add("seed", Utils.UrlEncode(item.path)); | ||||||
|  | @ -272,14 +252,7 @@ namespace v2rayN.Handler | ||||||
|                     break; |                     break; | ||||||
| 
 | 
 | ||||||
|                 case "quic": |                 case "quic": | ||||||
|                     if (!Utils.IsNullOrEmpty(item.headerType)) |                     dicQuery.Add("headerType", !Utils.IsNullOrEmpty(item.headerType) ? item.headerType : "none"); | ||||||
|                     { |  | ||||||
|                         dicQuery.Add("headerType", item.headerType); |  | ||||||
|                     } |  | ||||||
|                     else |  | ||||||
|                     { |  | ||||||
|                         dicQuery.Add("headerType", "none"); |  | ||||||
|                     } |  | ||||||
|                     dicQuery.Add("quicSecurity", Utils.UrlEncode(item.requestHost)); |                     dicQuery.Add("quicSecurity", Utils.UrlEncode(item.requestHost)); | ||||||
|                     dicQuery.Add("key", Utils.UrlEncode(item.path)); |                     dicQuery.Add("key", Utils.UrlEncode(item.path)); | ||||||
|                     break; |                     break; | ||||||
|  | @ -341,11 +314,7 @@ namespace v2rayN.Handler | ||||||
|                 { |                 { | ||||||
|                     msg = ResUI.ConfigurationFormatIncorrect; |                     msg = ResUI.ConfigurationFormatIncorrect; | ||||||
| 
 | 
 | ||||||
|                     vmessItem = ResolveSSLegacy(result); |                     vmessItem = ResolveSSLegacy(result) ?? ResolveSip002(result); | ||||||
|                     if (vmessItem == null) |  | ||||||
|                     { |  | ||||||
|                         vmessItem = ResolveSip002(result); |  | ||||||
|                     } |  | ||||||
|                     if (vmessItem == null) |                     if (vmessItem == null) | ||||||
|                     { |                     { | ||||||
|                         return null; |                         return null; | ||||||
|  | @ -361,11 +330,7 @@ namespace v2rayN.Handler | ||||||
|                 { |                 { | ||||||
|                     msg = ResUI.ConfigurationFormatIncorrect; |                     msg = ResUI.ConfigurationFormatIncorrect; | ||||||
| 
 | 
 | ||||||
|                     vmessItem = ResolveSocksNew(result); |                     vmessItem = ResolveSocksNew(result) ?? ResolveSocks(result); | ||||||
|                     if (vmessItem == null) |  | ||||||
|                     { |  | ||||||
|                         vmessItem = ResolveSocks(result); |  | ||||||
|                     } |  | ||||||
|                     if (vmessItem == null) |                     if (vmessItem == null) | ||||||
|                     { |                     { | ||||||
|                         return null; |                         return null; | ||||||
|  | @ -407,9 +372,11 @@ namespace v2rayN.Handler | ||||||
|         private static VmessItem ResolveVmess(string result, out string msg) |         private static VmessItem ResolveVmess(string result, out string msg) | ||||||
|         { |         { | ||||||
|             msg = string.Empty; |             msg = string.Empty; | ||||||
|             VmessItem vmessItem = new VmessItem(); |             var vmessItem = new VmessItem | ||||||
|  |             { | ||||||
|  |                 configType = EConfigType.Vmess | ||||||
|  |             }; | ||||||
| 
 | 
 | ||||||
|             vmessItem.configType = EConfigType.Vmess; |  | ||||||
|             result = result.Substring(Global.vmessProtocol.Length); |             result = result.Substring(Global.vmessProtocol.Length); | ||||||
|             result = Utils.Base64Decode(result); |             result = Utils.Base64Decode(result); | ||||||
| 
 | 
 | ||||||
|  | @ -432,14 +399,7 @@ namespace v2rayN.Handler | ||||||
|             vmessItem.alterId = Utils.ToInt(vmessQRCode.aid); |             vmessItem.alterId = Utils.ToInt(vmessQRCode.aid); | ||||||
|             vmessItem.security = Utils.ToString(vmessQRCode.scy); |             vmessItem.security = Utils.ToString(vmessQRCode.scy); | ||||||
| 
 | 
 | ||||||
|             if (!Utils.IsNullOrEmpty(vmessQRCode.scy)) |             vmessItem.security = !Utils.IsNullOrEmpty(vmessQRCode.scy) ? vmessQRCode.scy : Global.DefaultSecurity; | ||||||
|             { |  | ||||||
|                 vmessItem.security = vmessQRCode.scy; |  | ||||||
|             } |  | ||||||
|             else |  | ||||||
|             { |  | ||||||
|                 vmessItem.security = Global.DefaultSecurity; |  | ||||||
|             } |  | ||||||
|             if (!Utils.IsNullOrEmpty(vmessQRCode.net)) |             if (!Utils.IsNullOrEmpty(vmessQRCode.net)) | ||||||
|             { |             { | ||||||
|                 vmessItem.network = vmessQRCode.net; |                 vmessItem.network = vmessQRCode.net; | ||||||
|  | @ -598,7 +558,7 @@ namespace v2rayN.Handler | ||||||
|             //2022-blake3 |             //2022-blake3 | ||||||
|             if (rawUserInfo.Contains(":")) |             if (rawUserInfo.Contains(":")) | ||||||
|             { |             { | ||||||
|                 string[] userInfoParts = rawUserInfo.Split(new char[] { ':' }, 2); |                 string[] userInfoParts = rawUserInfo.Split(new[] { ':' }, 2); | ||||||
|                 if (userInfoParts.Length != 2) |                 if (userInfoParts.Length != 2) | ||||||
|                 { |                 { | ||||||
|                     return null; |                     return null; | ||||||
|  | @ -610,7 +570,7 @@ namespace v2rayN.Handler | ||||||
|             { |             { | ||||||
|                 // parse base64 UserInfo |                 // parse base64 UserInfo | ||||||
|                 string userInfo = Utils.Base64Decode(rawUserInfo); |                 string userInfo = Utils.Base64Decode(rawUserInfo); | ||||||
|                 string[] userInfoParts = userInfo.Split(new char[] { ':' }, 2); |                 string[] userInfoParts = userInfo.Split(new[] { ':' }, 2); | ||||||
|                 if (userInfoParts.Length != 2) |                 if (userInfoParts.Length != 2) | ||||||
|                 { |                 { | ||||||
|                     return null; |                     return null; | ||||||
|  | @ -668,8 +628,10 @@ namespace v2rayN.Handler | ||||||
| 
 | 
 | ||||||
|         private static VmessItem ResolveSocks(string result) |         private static VmessItem ResolveSocks(string result) | ||||||
|         { |         { | ||||||
|             VmessItem vmessItem = new VmessItem(); |             VmessItem vmessItem = new VmessItem | ||||||
|             vmessItem.configType = EConfigType.Socks; |             { | ||||||
|  |                 configType = EConfigType.Socks | ||||||
|  |             }; | ||||||
|             result = result.Substring(Global.socksProtocol.Length); |             result = result.Substring(Global.socksProtocol.Length); | ||||||
|             //remark |             //remark | ||||||
|             int indexRemark = result.IndexOf("#"); |             int indexRemark = result.IndexOf("#"); | ||||||
|  | @ -733,7 +695,7 @@ namespace v2rayN.Handler | ||||||
|             // parse base64 UserInfo |             // parse base64 UserInfo | ||||||
|             string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped); |             string rawUserInfo = parsedUrl.GetComponents(UriComponents.UserInfo, UriFormat.Unescaped); | ||||||
|             string userInfo = Utils.Base64Decode(rawUserInfo); |             string userInfo = Utils.Base64Decode(rawUserInfo); | ||||||
|             string[] userInfoParts = userInfo.Split(new char[] { ':' }, 2); |             string[] userInfoParts = userInfo.Split(new[] { ':' }, 2); | ||||||
|             if (userInfoParts.Length == 2) |             if (userInfoParts.Length == 2) | ||||||
|             { |             { | ||||||
|                 server.security = userInfoParts[0]; |                 server.security = userInfoParts[0]; | ||||||
|  |  | ||||||
|  | @ -1,6 +1,7 @@ | ||||||
| using System; | using System; | ||||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||||
| using System.Diagnostics; | using System.Diagnostics; | ||||||
|  | using System.Linq; | ||||||
| using System.Net; | using System.Net; | ||||||
| using System.Net.Sockets; | using System.Net.Sockets; | ||||||
| using System.Threading; | using System.Threading; | ||||||
|  | @ -43,19 +44,19 @@ namespace v2rayN.Handler | ||||||
| 
 | 
 | ||||||
|             if (actionType == ESpeedActionType.Ping) |             if (actionType == ESpeedActionType.Ping) | ||||||
|             { |             { | ||||||
|                 Task.Run(() => RunPing()); |                 Task.Run(RunPing); | ||||||
|             } |             } | ||||||
|             else if (actionType == ESpeedActionType.Tcping) |             else if (actionType == ESpeedActionType.Tcping) | ||||||
|             { |             { | ||||||
|                 Task.Run(() => RunTcping()); |                 Task.Run(RunTcping); | ||||||
|             } |             } | ||||||
|             else if (actionType == ESpeedActionType.Realping) |             else if (actionType == ESpeedActionType.Realping) | ||||||
|             { |             { | ||||||
|                 Task.Run(() => RunRealPing()); |                 Task.Run(RunRealPing); | ||||||
|             } |             } | ||||||
|             else if (actionType == ESpeedActionType.Speedtest) |             else if (actionType == ESpeedActionType.Speedtest) | ||||||
|             { |             { | ||||||
|                 Task.Run(() => RunSpeedTestAsync()); |                 Task.Run(RunSpeedTestAsync); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -63,12 +64,8 @@ namespace v2rayN.Handler | ||||||
|         { |         { | ||||||
|             try |             try | ||||||
|             { |             { | ||||||
|                 foreach (var it in _selecteds) |                 foreach (var it in _selecteds.Where(it => it.configType != EConfigType.Custom)) | ||||||
|                 { |                 { | ||||||
|                     if (it.configType == EConfigType.Custom) |  | ||||||
|                     { |  | ||||||
|                         continue; |  | ||||||
|                     } |  | ||||||
|                     try |                     try | ||||||
|                     { |                     { | ||||||
|                         Task.Run(() => updateFun(it)); |                         Task.Run(() => updateFun(it)); | ||||||
|  | @ -252,7 +249,7 @@ namespace v2rayN.Handler | ||||||
|             { |             { | ||||||
|                 return "Timeout"; |                 return "Timeout"; | ||||||
|             } |             } | ||||||
|             return string.Format("{0}{1}", time, unit).PadLeft(8, ' '); |             return $"{time}{unit}".PadLeft(8, ' '); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -31,13 +31,7 @@ namespace v2rayN.Handler | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|         public List<ServerStatItem> Statistic |         public List<ServerStatItem> Statistic => serverStatistics_.server; | ||||||
|         { |  | ||||||
|             get |  | ||||||
|             { |  | ||||||
|                 return serverStatistics_.server; |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
| 
 | 
 | ||||||
|         public StatisticsHandler(Mode.Config config, Action<ulong, ulong, List<ServerStatItem>> update) |         public StatisticsHandler(Mode.Config config, Action<ulong, ulong, List<ServerStatItem>> update) | ||||||
|         { |         { | ||||||
|  | @ -68,7 +62,7 @@ namespace v2rayN.Handler | ||||||
| 
 | 
 | ||||||
|             GrpcInit(); |             GrpcInit(); | ||||||
| 
 | 
 | ||||||
|             Task.Run(() => Run()); |             Task.Run(Run); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         private void GrpcInit() |         private void GrpcInit() | ||||||
|  |  | ||||||
|  | @ -26,8 +26,8 @@ namespace v2rayN.Handler | ||||||
| 
 | 
 | ||||||
|             public ResultEventArgs(bool success, string msg) |             public ResultEventArgs(bool success, string msg) | ||||||
|             { |             { | ||||||
|                 this.Success = success; |                 Success = success; | ||||||
|                 this.Msg = msg; |                 Msg = msg; | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  | @ -209,16 +209,12 @@ namespace v2rayN.Handler | ||||||
|                     else |                     else | ||||||
|                     { |                     { | ||||||
|                         int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId); |                         int ret = ConfigHandler.AddBatchServers(ref config, result, id, groupId); | ||||||
|                         if (ret > 0) |                         _updateFunc(false, | ||||||
|                         { |                             ret > 0 | ||||||
|                             _updateFunc(false, $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}"); |                                 ? $"{hashCode}{ResUI.MsgUpdateSubscriptionEnd}" | ||||||
|                         } |                                 : $"{hashCode}{ResUI.MsgFailedImportSubscription}"); | ||||||
|                         else |  | ||||||
|                         { |  | ||||||
|                             _updateFunc(false, $"{hashCode}{ResUI.MsgFailedImportSubscription}"); |  | ||||||
|                         } |  | ||||||
|                     } |                     } | ||||||
|                     _updateFunc(false, $"-------------------------------------------------------"); |                     _updateFunc(false, "-------------------------------------------------------"); | ||||||
|                 } |                 } | ||||||
|                 //restore system proxy |                 //restore system proxy | ||||||
|                 if (bSysProxyType) |                 if (bSysProxyType) | ||||||
|  | @ -331,7 +327,7 @@ namespace v2rayN.Handler | ||||||
|                 string filePath = string.Empty; |                 string filePath = string.Empty; | ||||||
|                 foreach (string name in coreInfo.coreExes) |                 foreach (string name in coreInfo.coreExes) | ||||||
|                 { |                 { | ||||||
|                     string vName = string.Format("{0}.exe", name); |                     string vName = $"{name}.exe"; | ||||||
|                     vName = Utils.GetPath(vName); |                     vName = Utils.GetPath(vName); | ||||||
|                     if (File.Exists(vName)) |                     if (File.Exists(vName)) | ||||||
|                     { |                     { | ||||||
|  |  | ||||||
|  | @ -427,14 +427,7 @@ namespace v2rayN.Handler | ||||||
|                     serversItem.address = node.address; |                     serversItem.address = node.address; | ||||||
|                     serversItem.port = node.port; |                     serversItem.port = node.port; | ||||||
|                     serversItem.password = node.id; |                     serversItem.password = node.id; | ||||||
|                     if (LazyConfig.Instance.GetShadowsocksSecuritys().Contains(node.security)) |                     serversItem.method = LazyConfig.Instance.GetShadowsocksSecuritys().Contains(node.security) ? node.security : "none"; | ||||||
|                     { |  | ||||||
|                         serversItem.method = node.security; |  | ||||||
|                     } |  | ||||||
|                     else |  | ||||||
|                     { |  | ||||||
|                         serversItem.method = "none"; |  | ||||||
|                     } |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|                     serversItem.ota = false; |                     serversItem.ota = false; | ||||||
|  | @ -761,10 +754,12 @@ namespace v2rayN.Handler | ||||||
|                         } |                         } | ||||||
|                         break; |                         break; | ||||||
|                     case "grpc": |                     case "grpc": | ||||||
|                         var grpcSettings = new GrpcSettings(); |                         var grpcSettings = new GrpcSettings | ||||||
|  |                         { | ||||||
|  |                             serviceName = node.path, | ||||||
|  |                             multiMode = (node.headerType == Global.GrpcmultiMode) | ||||||
|  |                         }; | ||||||
| 
 | 
 | ||||||
|                         grpcSettings.serviceName = node.path; |  | ||||||
|                         grpcSettings.multiMode = (node.headerType == Global.GrpcmultiMode ? true : false); |  | ||||||
|                         streamSettings.grpcSettings = grpcSettings; |                         streamSettings.grpcSettings = grpcSettings; | ||||||
|                         break; |                         break; | ||||||
|                     default: |                     default: | ||||||
|  | @ -785,7 +780,7 @@ namespace v2rayN.Handler | ||||||
|                                 string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); |                                 string request = Utils.GetEmbedText(Global.v2raySampleHttprequestFileName); | ||||||
|                                 string[] arrHost = host.Split(','); |                                 string[] arrHost = host.Split(','); | ||||||
|                                 string host2 = string.Join("\",\"", arrHost); |                                 string host2 = string.Join("\",\"", arrHost); | ||||||
|                                 request = request.Replace("$requestHost$", string.Format("\"{0}\"", host2)); |                                 request = request.Replace("$requestHost$", $"\"{host2}\""); | ||||||
|                                 //request = request.Replace("$requestHost$", string.Format("\"{0}\"", config.requestHost())); |                                 //request = request.Replace("$requestHost$", string.Format("\"{0}\"", config.requestHost())); | ||||||
| 
 | 
 | ||||||
|                                 //填入自定义Path |                                 //填入自定义Path | ||||||
|  | @ -795,7 +790,7 @@ namespace v2rayN.Handler | ||||||
|                                     string[] arrPath = node.path.Split(','); |                                     string[] arrPath = node.path.Split(','); | ||||||
|                                     pathHttp = string.Join("\",\"", arrPath); |                                     pathHttp = string.Join("\",\"", arrPath); | ||||||
|                                 } |                                 } | ||||||
|                                 request = request.Replace("$requestPath$", string.Format("\"{0}\"", pathHttp)); |                                 request = request.Replace("$requestPath$", $"\"{pathHttp}\""); | ||||||
|                                 tcpSettings.header.request = Utils.FromJson<object>(request); |                                 tcpSettings.header.request = Utils.FromJson<object>(request); | ||||||
|                             } |                             } | ||||||
|                             else if (iobound.Equals("in")) |                             else if (iobound.Equals("in")) | ||||||
|  | @ -882,7 +877,7 @@ namespace v2rayN.Handler | ||||||
|                 policyObj.system = policySystemSetting; |                 policyObj.system = policySystemSetting; | ||||||
|                 v2rayConfig.policy = policyObj; |                 v2rayConfig.policy = policyObj; | ||||||
| 
 | 
 | ||||||
|                 if (!v2rayConfig.inbounds.Exists(item => { return item.tag == tag; })) |                 if (!v2rayConfig.inbounds.Exists(item => item.tag == tag)) | ||||||
|                 { |                 { | ||||||
|                     Inbounds apiInbound = new Inbounds(); |                     Inbounds apiInbound = new Inbounds(); | ||||||
|                     Inboundsettings apiInboundSettings = new Inboundsettings(); |                     Inboundsettings apiInboundSettings = new Inboundsettings(); | ||||||
|  | @ -895,7 +890,7 @@ namespace v2rayN.Handler | ||||||
|                     v2rayConfig.inbounds.Add(apiInbound); |                     v2rayConfig.inbounds.Add(apiInbound); | ||||||
|                 } |                 } | ||||||
| 
 | 
 | ||||||
|                 if (!v2rayConfig.routing.rules.Exists(item => { return item.outboundTag == tag; })) |                 if (!v2rayConfig.routing.rules.Exists(item => item.outboundTag == tag)) | ||||||
|                 { |                 { | ||||||
|                     RulesItem apiRoutingRule = new RulesItem |                     RulesItem apiRoutingRule = new RulesItem | ||||||
|                     { |                     { | ||||||
|  | @ -1171,7 +1166,7 @@ namespace v2rayN.Handler | ||||||
|                 vmessItem.port = outbound.settings.vnext[0].port; |                 vmessItem.port = outbound.settings.vnext[0].port; | ||||||
|                 vmessItem.id = outbound.settings.vnext[0].users[0].id; |                 vmessItem.id = outbound.settings.vnext[0].users[0].id; | ||||||
|                 vmessItem.alterId = outbound.settings.vnext[0].users[0].alterId; |                 vmessItem.alterId = outbound.settings.vnext[0].users[0].alterId; | ||||||
|                 vmessItem.remarks = string.Format("import@{0}", DateTime.Now.ToShortDateString()); |                 vmessItem.remarks = $"import@{DateTime.Now.ToShortDateString()}"; | ||||||
| 
 | 
 | ||||||
|                 //tcp or kcp |                 //tcp or kcp | ||||||
|                 if (outbound.streamSettings != null |                 if (outbound.streamSettings != null | ||||||
|  | @ -1316,7 +1311,7 @@ namespace v2rayN.Handler | ||||||
|                 vmessItem.id = inbound.settings.clients[0].id; |                 vmessItem.id = inbound.settings.clients[0].id; | ||||||
|                 vmessItem.alterId = inbound.settings.clients[0].alterId; |                 vmessItem.alterId = inbound.settings.clients[0].alterId; | ||||||
| 
 | 
 | ||||||
|                 vmessItem.remarks = string.Format("import@{0}", DateTime.Now.ToShortDateString()); |                 vmessItem.remarks = $"import@{DateTime.Now.ToShortDateString()}"; | ||||||
| 
 | 
 | ||||||
|                 //tcp or kcp |                 //tcp or kcp | ||||||
|                 if (inbound.streamSettings != null |                 if (inbound.streamSettings != null | ||||||
|  |  | ||||||
|  | @ -175,7 +175,7 @@ namespace v2rayN.Handler | ||||||
|             string fileName = string.Empty; |             string fileName = string.Empty; | ||||||
|             foreach (string name in lstCoreTemp) |             foreach (string name in lstCoreTemp) | ||||||
|             { |             { | ||||||
|                 string vName = string.Format("{0}.exe", name); |                 string vName = $"{name}.exe"; | ||||||
|                 vName = Utils.GetPath(vName); |                 vName = Utils.GetPath(vName); | ||||||
|                 if (File.Exists(vName)) |                 if (File.Exists(vName)) | ||||||
|                 { |                 { | ||||||
|  | @ -217,14 +217,14 @@ namespace v2rayN.Handler | ||||||
|                         StandardOutputEncoding = Encoding.UTF8 |                         StandardOutputEncoding = Encoding.UTF8 | ||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|                 p.OutputDataReceived += new DataReceivedEventHandler((sender, e) => |                 p.OutputDataReceived += (sender, e) => | ||||||
|                 { |                 { | ||||||
|                     if (!String.IsNullOrEmpty(e.Data)) |                     if (!String.IsNullOrEmpty(e.Data)) | ||||||
|                     { |                     { | ||||||
|                         string msg = e.Data + Environment.NewLine; |                         string msg = e.Data + Environment.NewLine; | ||||||
|                         ShowMsg(false, msg); |                         ShowMsg(false, msg); | ||||||
|                     } |                     } | ||||||
|                 }); |                 }; | ||||||
|                 p.Start(); |                 p.Start(); | ||||||
|                 p.PriorityClass = ProcessPriorityClass.High; |                 p.PriorityClass = ProcessPriorityClass.High; | ||||||
|                 p.BeginOutputReadLine(); |                 p.BeginOutputReadLine(); | ||||||
|  | @ -272,14 +272,14 @@ namespace v2rayN.Handler | ||||||
|                         StandardOutputEncoding = Encoding.UTF8 |                         StandardOutputEncoding = Encoding.UTF8 | ||||||
|                     } |                     } | ||||||
|                 }; |                 }; | ||||||
|                 p.OutputDataReceived += new DataReceivedEventHandler((sender, e) => |                 p.OutputDataReceived += (sender, e) => | ||||||
|                 { |                 { | ||||||
|                     if (!String.IsNullOrEmpty(e.Data)) |                     if (!String.IsNullOrEmpty(e.Data)) | ||||||
|                     { |                     { | ||||||
|                         string msg = e.Data + Environment.NewLine; |                         string msg = e.Data + Environment.NewLine; | ||||||
|                         ShowMsg(false, msg); |                         ShowMsg(false, msg); | ||||||
|                     } |                     } | ||||||
|                 }); |                 }; | ||||||
|                 p.Start(); |                 p.Start(); | ||||||
|                 p.BeginOutputReadLine(); |                 p.BeginOutputReadLine(); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -25,8 +25,8 @@ namespace v2rayN | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); |             Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); | ||||||
|             Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException); |             Application.ThreadException += Application_ThreadException; | ||||||
|             AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |             AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|             //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; |             //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; | ||||||
|  |  | ||||||
|  | @ -13,23 +13,27 @@ namespace v2rayN.Tool | ||||||
|     { |     { | ||||||
|         public static void Setup() |         public static void Setup() | ||||||
|         { |         { | ||||||
|             Hierarchy hierarchy = (Hierarchy)LogManager.GetRepository(); |             var hierarchy = (Hierarchy)LogManager.GetRepository(); | ||||||
| 
 | 
 | ||||||
|             PatternLayout patternLayout = new PatternLayout(); |             var patternLayout = new PatternLayout | ||||||
|             patternLayout.ConversionPattern = "%date [%thread] %-5level %logger - %message%newline"; |             { | ||||||
|  |                 ConversionPattern = "%date [%thread] %-5level %logger - %message%newline" | ||||||
|  |             }; | ||||||
|             patternLayout.ActivateOptions(); |             patternLayout.ActivateOptions(); | ||||||
| 
 | 
 | ||||||
|             RollingFileAppender roller = new RollingFileAppender(); |             var roller = new RollingFileAppender | ||||||
|             roller.AppendToFile = true; |             { | ||||||
|             roller.RollingStyle = RollingFileAppender.RollingMode.Date; |                 AppendToFile = true, | ||||||
|             roller.DatePattern = "yyyy-MM-dd'.txt'"; |                 RollingStyle = RollingFileAppender.RollingMode.Date, | ||||||
|             roller.File = Utils.GetPath(@"guiLogs\"); |                 DatePattern = "yyyy-MM-dd'.txt'", | ||||||
|             roller.Layout = patternLayout; |                 File = Utils.GetPath(@"guiLogs\"), | ||||||
|             roller.StaticLogFileName = false; |                 Layout = patternLayout, | ||||||
|  |                 StaticLogFileName = false | ||||||
|  |             }; | ||||||
|             roller.ActivateOptions(); |             roller.ActivateOptions(); | ||||||
|             hierarchy.Root.AddAppender(roller); |             hierarchy.Root.AddAppender(roller); | ||||||
| 
 | 
 | ||||||
|             MemoryAppender memory = new MemoryAppender(); |             var memory = new MemoryAppender(); | ||||||
|             memory.ActivateOptions(); |             memory.ActivateOptions(); | ||||||
|             hierarchy.Root.AddAppender(memory); |             hierarchy.Root.AddAppender(memory); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -951,7 +951,7 @@ namespace v2rayN | ||||||
| 
 | 
 | ||||||
|         public static string GetDownloadFileName(string url) |         public static string GetDownloadFileName(string url) | ||||||
|         { |         { | ||||||
|             var fileName = System.IO.Path.GetFileName(url); |             var fileName = Path.GetFileName(url); | ||||||
|             fileName += "_temp"; |             fileName += "_temp"; | ||||||
| 
 | 
 | ||||||
|             return fileName; |             return fileName; | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue
	
	 2dust
						2dust