diff --git a/v2rayN/v2rayN/Forms/AddServer2Form.Designer.cs b/v2rayN/v2rayN/Forms/AddServer2Form.Designer.cs index 25f8d715..cff9eca2 100644 --- a/v2rayN/v2rayN/Forms/AddServer2Form.Designer.cs +++ b/v2rayN/v2rayN/Forms/AddServer2Form.Designer.cs @@ -31,6 +31,9 @@ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddServer2Form)); this.btnClose = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.label3 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.txtPreSocksPort = new System.Windows.Forms.TextBox(); this.btnEdit = new System.Windows.Forms.Button(); this.cmbCoreType = new System.Windows.Forms.ComboBox(); this.labCoreType = new System.Windows.Forms.Label(); @@ -49,14 +52,18 @@ // // btnClose // - this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; resources.ApplyResources(this.btnClose, "btnClose"); + this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.btnClose.Name = "btnClose"; this.btnClose.UseVisualStyleBackColor = true; this.btnClose.Click += new System.EventHandler(this.btnClose_Click); // // groupBox1 // + resources.ApplyResources(this.groupBox1, "groupBox1"); + this.groupBox1.Controls.Add(this.label3); + this.groupBox1.Controls.Add(this.label2); + this.groupBox1.Controls.Add(this.txtPreSocksPort); this.groupBox1.Controls.Add(this.btnEdit); this.groupBox1.Controls.Add(this.cmbCoreType); this.groupBox1.Controls.Add(this.labCoreType); @@ -66,10 +73,24 @@ this.groupBox1.Controls.Add(this.txtRemarks); this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.label1); - resources.ApplyResources(this.groupBox1, "groupBox1"); this.groupBox1.Name = "groupBox1"; this.groupBox1.TabStop = false; // + // label3 + // + resources.ApplyResources(this.label3, "label3"); + this.label3.Name = "label3"; + // + // label2 + // + resources.ApplyResources(this.label2, "label2"); + this.label2.Name = "label2"; + // + // txtPreSocksPort + // + resources.ApplyResources(this.txtPreSocksPort, "txtPreSocksPort"); + this.txtPreSocksPort.Name = "txtPreSocksPort"; + // // btnEdit // resources.ApplyResources(this.btnEdit, "btnEdit"); @@ -79,9 +100,9 @@ // // cmbCoreType // + resources.ApplyResources(this.cmbCoreType, "cmbCoreType"); this.cmbCoreType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbCoreType.FormattingEnabled = true; - resources.ApplyResources(this.cmbCoreType, "cmbCoreType"); this.cmbCoreType.Name = "cmbCoreType"; // // labCoreType @@ -123,9 +144,9 @@ // // panel2 // + resources.ApplyResources(this.panel2, "panel2"); this.panel2.Controls.Add(this.btnClose); this.panel2.Controls.Add(this.btnOK); - resources.ApplyResources(this.panel2, "panel2"); this.panel2.Name = "panel2"; // // btnOK @@ -174,5 +195,8 @@ private System.Windows.Forms.ComboBox cmbCoreType; private System.Windows.Forms.Label labCoreType; private System.Windows.Forms.Button btnEdit; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.TextBox txtPreSocksPort; + private System.Windows.Forms.Label label3; } } \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/AddServer2Form.cs b/v2rayN/v2rayN/Forms/AddServer2Form.cs index f54c1257..68fbdcd9 100644 --- a/v2rayN/v2rayN/Forms/AddServer2Form.cs +++ b/v2rayN/v2rayN/Forms/AddServer2Form.cs @@ -19,7 +19,7 @@ namespace v2rayN.Forms private void AddServer2Form_Load(object sender, EventArgs e) { - List coreTypes = new List (); + List coreTypes = new List(); foreach (ECoreType it in Enum.GetValues(typeof(ECoreType))) { if (it == ECoreType.v2rayN) @@ -27,7 +27,7 @@ namespace v2rayN.Forms coreTypes.Add(it.ToString()); } - cmbCoreType.Items.AddRange(coreTypes.ToArray()); + cmbCoreType.Items.AddRange(coreTypes.ToArray()); cmbCoreType.Items.Add(string.Empty); txtAddress.ReadOnly = true; @@ -52,6 +52,7 @@ namespace v2rayN.Forms { txtRemarks.Text = vmessItem.remarks; txtAddress.Text = vmessItem.address; + txtPreSocksPort.Text = vmessItem.preSocksPort.ToString(); cmbCoreType.Text = vmessItem.coreType == null ? string.Empty : vmessItem.coreType.ToString(); } @@ -79,6 +80,8 @@ namespace v2rayN.Forms return; } vmessItem.remarks = remarks; + vmessItem.preSocksPort = Utils.ToInt(txtPreSocksPort.Text); + if (Utils.IsNullOrEmpty(cmbCoreType.Text)) { vmessItem.coreType = null; diff --git a/v2rayN/v2rayN/Forms/AddServer2Form.resx b/v2rayN/v2rayN/Forms/AddServer2Form.resx index 23a0a255..0935b393 100644 --- a/v2rayN/v2rayN/Forms/AddServer2Form.resx +++ b/v2rayN/v2rayN/Forms/AddServer2Form.resx @@ -118,390 +118,456 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 113, 12 + + + 370, 41 + + + label6 + + + + True + + + panel2 + + + 11 + + + 59, 12 + + + System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Bottom + + + panel1 + + + 3 + + + * After setting this value, an socks service will be started using V2ray to provide functions such as speed display + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 5 + + + NoControl + + + 75, 23 + + + groupBox1 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Fill + + + 127, 157 + + + 127, 62 + + + 8 + + + True + + + Custom configuration server + + + 127, 110 + + + NoControl + + + 11 + + + 357, 17 + + + System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 46 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 0 + + + 432, 37 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 2 + 450, 17 - + + 43 + + + 1 + + + txtPreSocksPort + + + label1 + + + 611, 60 + + + 0, 0 + + + 45 + + + groupBox1 + + + True + + + 22 + + 75, 23 - - - 4 + + 208, 110 - - &Cancel + + &Edit - - btnClose + + 2 - + + panel2 + + + 5 + + + Alias (remarks) + + + 313, 21 + + + groupBox1 + + + NoControl + + + 41 + + + 12, 62 + + + groupBox1 + + + 1 + + + AddServer2Form + + + 446, 26 + + + groupBox1 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + labCoreType + + + 0 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + btnOK + + + $this + + + 89, 12 + + + 89, 20 + + + $this + + + groupBox1 + + + 42 + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 panel2 - - 0 + + 89, 21 - - - NoControl + + 611, 10 - - 208, 110 - - - 75, 23 - - - 43 - - - &Edit - - - btnEdit - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 0 - - - 127, 157 - - - 89, 20 - - - 41 - - - cmbCoreType - - - System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 1 - - - True - - - NoControl - - - 12, 161 - - - 59, 12 - - - 42 + + 0, 10 Core Type - - labCoreType + + 127, 195 - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 2 - - - NoControl - - - 127, 110 - - + 75, 23 - - 40 - - - &Browse - - - btnBrowse - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - + groupBox1 - 3 - - - 127, 62 - - - True - - - 432, 37 - - - 23 - - - txtAddress - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 4 - - - True - - - 446, 26 - - - 113, 12 - - - 22 - - - * Fill in manually - - - label13 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 5 - - - 127, 23 - - - 313, 21 - - - 11 - - - txtRemarks - - - System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - 6 - - True + + btnEdit - - 12, 27 + + &OK - - 95, 12 + + btnClose - - 10 - - - Alias (remarks) - - - label6 - - - System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - groupBox1 - - - 7 - - - True - - - 12, 62 - - - 47, 12 + + $this 0 - - Address + + 229, 189 - - label1 + + 44 - + + True + + + groupBox1 + + + 12, 161 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 23 + + + System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 6 + + + 1 + + + 7 + + + cmbCoreType + + + &Browse + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 groupBox1 - - 8 + + v2rayN.Forms.BaseServerForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - - Fill + + label3 - - 0, 10 - - - 611, 189 - - - 3 - - - Server - - - groupBox1 - - - System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 0 - - - btnOK - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 1 - - - Bottom - - - 0, 199 - - - 611, 60 - - - 7 - - - panel2 + + Pre-Socks Port System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - $this - - - 1 - - - 357, 17 - - - 75, 23 - - - 5 - - - &OK - - - btnOK - - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - panel2 - - - 1 - Top - - 0, 0 + + 0, 259 - - 611, 10 + + 7 - - 6 + + NoControl - - panel1 + + groupBox1 - - System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 47, 12 - - $this + + True - - 2 + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 6, 12 + + + Address + + + 3 + + + 127, 23 + + + 95, 12 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + 4 + + + * Fill in manually + + + label2 + + + groupBox1 + + + 12, 199 + + + 611, 319 + + + btnBrowse + + + 611, 249 + + + 40 + + + 10 + + + 75, 23 + + + 0 + + + label13 + + + &Cancel + + + NoControl + + + 4 + + + 9 + + + groupBox1 + + + txtAddress + + + groupBox1 + + + System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Server + + + txtRemarks + + + 10 + + + 12, 27 + + + True + + + System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 True - - 6, 12 - - - 611, 259 - - - Custom configuration server - - - AddServer2Form - - - v2rayN.Forms.BaseServerForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null - \ No newline at end of file diff --git a/v2rayN/v2rayN/Forms/AddServer2Form.zh-Hans.resx b/v2rayN/v2rayN/Forms/AddServer2Form.zh-Hans.resx index 45296254..ba37ebc6 100644 --- a/v2rayN/v2rayN/Forms/AddServer2Form.zh-Hans.resx +++ b/v2rayN/v2rayN/Forms/AddServer2Form.zh-Hans.resx @@ -117,34 +117,56 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - 自定义配置 - - - 浏览(&B) - 取消(&C) - - 编辑(&E) - - - 确定(&O) - 服务器 + + + 337, 41 + + + * 自定义配置的Socks端口值,可不设置;当设置此值后,将使用V2ray-core额外启动一个前置Socks服务,提供分流和速度显示等功能 + + + 59, 12 + + + Socks端口 + + + 编辑(&E) + + + 53, 12 + Core类型 - - 地址(address) + + 浏览(&B) *手填,方便识别管理 + + 83, 12 + 别名(remarks) + + 83, 12 + + + 地址(address) + + + 确定(&O) + + + 自定义配置 + \ No newline at end of file diff --git a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs index 54f8c725..97f5abf5 100644 --- a/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayConfigHandler.cs @@ -27,8 +27,9 @@ namespace v2rayN.Handler /// /// /// - public static int GenerateClientConfig(VmessItem node, string fileName, bool blExport, out string msg) + public static int GenerateClientConfig(VmessItem node, string fileName, out string msg, out string content) { + content = string.Empty; try { if (node == null) @@ -42,47 +43,22 @@ namespace v2rayN.Handler { return GenerateClientCustomConfig(node, fileName, out msg); } - - //取得默认配置 - string result = Utils.GetEmbedText(SampleClient); - if (Utils.IsNullOrEmpty(result)) + else { - msg = ResUI.FailedGetDefaultConfiguration; - return -1; + V2rayConfig v2rayConfig = null; + if (GenerateClientConfigContent(node, false, ref v2rayConfig, out msg) != 0) + { + return -1; + } + if (Utils.IsNullOrEmpty(fileName)) + { + content = Utils.ToJson(v2rayConfig); + } + else + { + Utils.ToJsonFile(v2rayConfig, fileName, false); + } } - - //转成Json - V2rayConfig v2rayConfig = Utils.FromJson(result); - if (v2rayConfig == null) - { - msg = ResUI.FailedGenDefaultConfiguration; - return -1; - } - - var config = LazyConfig.Instance.GetConfig(); - - //开始修改配置 - log(config, ref v2rayConfig, blExport); - - //本地端口 - inbound(config, ref v2rayConfig); - - //路由 - routing(config, ref v2rayConfig); - - //outbound - outbound(node, ref v2rayConfig); - - //dns - dns(config, ref v2rayConfig); - - // TODO: 统计配置 - statistic(config, ref v2rayConfig); - - Utils.ToJsonFile(v2rayConfig, fileName, false); - - //msg = string.Format(ResUI.SuccessfulConfiguration, $"[{config.GetGroupRemarks(node.groupId)}] {node.GetSummary()}"); - msg = string.Format(ResUI.SuccessfulConfiguration, ""); } catch (Exception ex) { @@ -93,6 +69,8 @@ namespace v2rayN.Handler return 0; } + + /// /// 日志 /// @@ -964,34 +942,38 @@ namespace v2rayN.Handler } //overwrite port - var fileContent = File.ReadAllLines(fileName).ToList(); - var coreType = LazyConfig.Instance.GetCoreType(node, node.configType); - switch (coreType) + if (node.preSocksPort <= 0) { - case ECoreType.v2fly: - case ECoreType.Xray: - break; - case ECoreType.clash: - case ECoreType.clash_meta: - //remove the original - var indexPort = fileContent.FindIndex(t => t.Contains("port:")); - if (indexPort >= 0) - { - fileContent.RemoveAt(indexPort); - } - indexPort = fileContent.FindIndex(t => t.Contains("socks-port:")); - if (indexPort >= 0) - { - fileContent.RemoveAt(indexPort); - } + var fileContent = File.ReadAllLines(fileName).ToList(); + var coreType = LazyConfig.Instance.GetCoreType(node, node.configType); + switch (coreType) + { + case ECoreType.v2fly: + case ECoreType.Xray: + break; + case ECoreType.clash: + case ECoreType.clash_meta: + //remove the original + var indexPort = fileContent.FindIndex(t => t.Contains("port:")); + if (indexPort >= 0) + { + fileContent.RemoveAt(indexPort); + } + indexPort = fileContent.FindIndex(t => t.Contains("socks-port:")); + if (indexPort >= 0) + { + fileContent.RemoveAt(indexPort); + } - fileContent.Add($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp)}"); - fileContent.Add($"socks-port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundSocks)}"); - break; + fileContent.Add($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp)}"); + fileContent.Add($"socks-port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundSocks)}"); + break; + } + File.WriteAllLines(fileName, fileContent); } - File.WriteAllLines(fileName, fileContent); - msg = string.Format(ResUI.SuccessfulConfiguration, $"[{LazyConfig.Instance.GetConfig().GetGroupRemarks(node.groupId)}] {node.GetSummary()}"); + //msg = string.Format(ResUI.SuccessfulConfiguration, $"[{LazyConfig.Instance.GetConfig().GetGroupRemarks(node.groupId)}] {node.GetSummary()}"); + msg = string.Format(ResUI.SuccessfulConfiguration, ""); } catch (Exception ex) { @@ -1002,6 +984,66 @@ namespace v2rayN.Handler return 0; } + public static int GenerateClientConfigContent(VmessItem node, bool blExport, ref V2rayConfig v2rayConfig, out string msg) + { + try + { + if (node == null) + { + msg = ResUI.CheckServerSettings; + return -1; + } + + msg = ResUI.InitialConfiguration; + + //取得默认配置 + string result = Utils.GetEmbedText(SampleClient); + if (Utils.IsNullOrEmpty(result)) + { + msg = ResUI.FailedGetDefaultConfiguration; + return -1; + } + + //转成Json + v2rayConfig = Utils.FromJson(result); + if (v2rayConfig == null) + { + msg = ResUI.FailedGenDefaultConfiguration; + return -1; + } + + var config = LazyConfig.Instance.GetConfig(); + + //开始修改配置 + log(config, ref v2rayConfig, blExport); + + //本地端口 + inbound(config, ref v2rayConfig); + + //路由 + routing(config, ref v2rayConfig); + + //outbound + outbound(node, ref v2rayConfig); + + //dns + dns(config, ref v2rayConfig); + + //stat + statistic(config, ref v2rayConfig); + + //msg = string.Format(ResUI.SuccessfulConfiguration, $"[{config.GetGroupRemarks(node.groupId)}] {node.GetSummary()}"); + msg = string.Format(ResUI.SuccessfulConfiguration, ""); + } + catch (Exception ex) + { + Utils.SaveLog("GenerateClientConfig", ex); + msg = ResUI.FailedGenDefaultConfiguration; + return -1; + } + return 0; + } + #endregion #region 生成服务端端配置 @@ -1442,7 +1484,12 @@ namespace v2rayN.Handler /// public static int Export2ClientConfig(VmessItem node, string fileName, out string msg) { - return GenerateClientConfig(node, fileName, true, out msg); + V2rayConfig v2rayConfig = null; + if (GenerateClientConfigContent(node, true, ref v2rayConfig, out msg) != 0) + { + return -1; + } + return Utils.ToJsonFile(v2rayConfig, fileName, false); } /// diff --git a/v2rayN/v2rayN/Handler/V2rayHandler.cs b/v2rayN/v2rayN/Handler/V2rayHandler.cs index c7e23dbd..d5a0800c 100644 --- a/v2rayN/v2rayN/Handler/V2rayHandler.cs +++ b/v2rayN/v2rayN/Handler/V2rayHandler.cs @@ -24,7 +24,7 @@ namespace v2rayN.Handler private static string v2rayConfigRes = Global.v2rayConfigFileName; private CoreInfo coreInfo; public event ProcessDelegate ProcessEvent; - //private int processId = 0; + private int processId = 0; private Process _process; public V2rayHandler() @@ -51,7 +51,7 @@ namespace v2rayN.Handler return; } string fileName = Utils.GetPath(v2rayConfigRes); - if (V2rayConfigHandler.GenerateClientConfig(item, fileName, false, out string msg) != 0) + if (V2rayConfigHandler.GenerateClientConfig(item, fileName, out string msg, out string content) != 0) { ShowMsg(false, msg); } @@ -61,6 +61,21 @@ namespace v2rayN.Handler ShowMsg(true, $"[{config.GetGroupRemarks(item.groupId)}] {item.GetSummary()}"); V2rayRestart(); } + + //start a socks service + if (item.configType == EConfigType.Custom && item.preSocksPort > 0) + { + var itemSocks = new VmessItem() + { + configType = EConfigType.Socks, + address = Global.Loopback, + port = item.preSocksPort + }; + if (V2rayConfigHandler.GenerateClientConfig(itemSocks, null, out string msg2, out string configStr) == 0) + { + processId = V2rayStartNew(configStr); + } + } } } @@ -128,27 +143,12 @@ namespace v2rayN.Handler } } - //bool blExist = true; - //if (processId > 0) - //{ - // Process p1 = Process.GetProcessById(processId); - // if (p1 != null) - // { - // p1.Kill(); - // blExist = false; - // } - //} - //if (blExist) - //{ - // foreach (string vName in lstV2ray) - // { - // Process[] killPro = Process.GetProcessesByName(vName); - // foreach (Process p in killPro) - // { - // p.Kill(); - // } - // } - //} + if (processId > 0) + { + V2rayStopPid(processId); + processId = 0; + } + } catch (Exception ex) { @@ -215,7 +215,8 @@ namespace v2rayN.Handler RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, - StandardOutputEncoding = Encoding.UTF8 + StandardOutputEncoding = Encoding.UTF8, + StandardErrorEncoding = Encoding.UTF8 } }; p.OutputDataReceived += (sender, e) => @@ -229,7 +230,6 @@ namespace v2rayN.Handler p.Start(); p.PriorityClass = ProcessPriorityClass.High; p.BeginOutputReadLine(); - //processId = p.Id; _process = p; if (p.WaitForExit(1000)) @@ -270,7 +270,8 @@ namespace v2rayN.Handler RedirectStandardOutput = true, RedirectStandardError = true, CreateNoWindow = true, - StandardOutputEncoding = Encoding.UTF8 + StandardOutputEncoding = Encoding.UTF8, + StandardErrorEncoding = Encoding.UTF8 } }; p.OutputDataReceived += (sender, e) => diff --git a/v2rayN/v2rayN/Mode/Config.cs b/v2rayN/v2rayN/Mode/Config.cs index 02d5c4ab..b498ef18 100644 --- a/v2rayN/v2rayN/Mode/Config.cs +++ b/v2rayN/v2rayN/Mode/Config.cs @@ -561,10 +561,16 @@ namespace v2rayN.Mode { get; set; } = string.Empty; + public ECoreType? coreType { get; set; } + + public int preSocksPort + { + get; set; + } } [Serializable]