Add custom configuration to start socks service

This commit is contained in:
2dust 2022-07-28 21:05:22 +08:00
parent 50e55761ab
commit 5198f30363
7 changed files with 606 additions and 437 deletions

View file

@ -31,6 +31,9 @@
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddServer2Form)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddServer2Form));
this.btnClose = new System.Windows.Forms.Button(); this.btnClose = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox(); 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.btnEdit = new System.Windows.Forms.Button();
this.cmbCoreType = new System.Windows.Forms.ComboBox(); this.cmbCoreType = new System.Windows.Forms.ComboBox();
this.labCoreType = new System.Windows.Forms.Label(); this.labCoreType = new System.Windows.Forms.Label();
@ -49,14 +52,18 @@
// //
// btnClose // btnClose
// //
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
resources.ApplyResources(this.btnClose, "btnClose"); resources.ApplyResources(this.btnClose, "btnClose");
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Name = "btnClose"; this.btnClose.Name = "btnClose";
this.btnClose.UseVisualStyleBackColor = true; this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click); this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
// //
// groupBox1 // 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.btnEdit);
this.groupBox1.Controls.Add(this.cmbCoreType); this.groupBox1.Controls.Add(this.cmbCoreType);
this.groupBox1.Controls.Add(this.labCoreType); this.groupBox1.Controls.Add(this.labCoreType);
@ -66,10 +73,24 @@
this.groupBox1.Controls.Add(this.txtRemarks); this.groupBox1.Controls.Add(this.txtRemarks);
this.groupBox1.Controls.Add(this.label6); this.groupBox1.Controls.Add(this.label6);
this.groupBox1.Controls.Add(this.label1); this.groupBox1.Controls.Add(this.label1);
resources.ApplyResources(this.groupBox1, "groupBox1");
this.groupBox1.Name = "groupBox1"; this.groupBox1.Name = "groupBox1";
this.groupBox1.TabStop = false; 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 // btnEdit
// //
resources.ApplyResources(this.btnEdit, "btnEdit"); resources.ApplyResources(this.btnEdit, "btnEdit");
@ -79,9 +100,9 @@
// //
// cmbCoreType // cmbCoreType
// //
resources.ApplyResources(this.cmbCoreType, "cmbCoreType");
this.cmbCoreType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.cmbCoreType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cmbCoreType.FormattingEnabled = true; this.cmbCoreType.FormattingEnabled = true;
resources.ApplyResources(this.cmbCoreType, "cmbCoreType");
this.cmbCoreType.Name = "cmbCoreType"; this.cmbCoreType.Name = "cmbCoreType";
// //
// labCoreType // labCoreType
@ -123,9 +144,9 @@
// //
// panel2 // panel2
// //
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Controls.Add(this.btnClose); this.panel2.Controls.Add(this.btnClose);
this.panel2.Controls.Add(this.btnOK); this.panel2.Controls.Add(this.btnOK);
resources.ApplyResources(this.panel2, "panel2");
this.panel2.Name = "panel2"; this.panel2.Name = "panel2";
// //
// btnOK // btnOK
@ -174,5 +195,8 @@
private System.Windows.Forms.ComboBox cmbCoreType; private System.Windows.Forms.ComboBox cmbCoreType;
private System.Windows.Forms.Label labCoreType; private System.Windows.Forms.Label labCoreType;
private System.Windows.Forms.Button btnEdit; private System.Windows.Forms.Button btnEdit;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txtPreSocksPort;
private System.Windows.Forms.Label label3;
} }
} }

View file

@ -19,7 +19,7 @@ namespace v2rayN.Forms
private void AddServer2Form_Load(object sender, EventArgs e) private void AddServer2Form_Load(object sender, EventArgs e)
{ {
List<string> coreTypes = new List<string> (); List<string> coreTypes = new List<string>();
foreach (ECoreType it in Enum.GetValues(typeof(ECoreType))) foreach (ECoreType it in Enum.GetValues(typeof(ECoreType)))
{ {
if (it == ECoreType.v2rayN) if (it == ECoreType.v2rayN)
@ -27,7 +27,7 @@ namespace v2rayN.Forms
coreTypes.Add(it.ToString()); coreTypes.Add(it.ToString());
} }
cmbCoreType.Items.AddRange(coreTypes.ToArray()); cmbCoreType.Items.AddRange(coreTypes.ToArray());
cmbCoreType.Items.Add(string.Empty); cmbCoreType.Items.Add(string.Empty);
txtAddress.ReadOnly = true; txtAddress.ReadOnly = true;
@ -52,6 +52,7 @@ namespace v2rayN.Forms
{ {
txtRemarks.Text = vmessItem.remarks; txtRemarks.Text = vmessItem.remarks;
txtAddress.Text = vmessItem.address; txtAddress.Text = vmessItem.address;
txtPreSocksPort.Text = vmessItem.preSocksPort.ToString();
cmbCoreType.Text = vmessItem.coreType == null ? string.Empty : vmessItem.coreType.ToString(); cmbCoreType.Text = vmessItem.coreType == null ? string.Empty : vmessItem.coreType.ToString();
} }
@ -79,6 +80,8 @@ namespace v2rayN.Forms
return; return;
} }
vmessItem.remarks = remarks; vmessItem.remarks = remarks;
vmessItem.preSocksPort = Utils.ToInt(txtPreSocksPort.Text);
if (Utils.IsNullOrEmpty(cmbCoreType.Text)) if (Utils.IsNullOrEmpty(cmbCoreType.Text))
{ {
vmessItem.coreType = null; vmessItem.coreType = null;

View file

@ -118,390 +118,456 @@
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> <assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="label13.Size" type="System.Drawing.Size, System.Drawing">
<value>113, 12</value>
</data>
<data name="label3.Size" type="System.Drawing.Size, System.Drawing">
<value>370, 41</value>
</data>
<data name="&gt;&gt;label6.Name" xml:space="preserve">
<value>label6</value>
</data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="label6.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="&gt;&gt;panel2.Name" xml:space="preserve">
<value>panel2</value>
</data>
<data name="txtRemarks.TabIndex" type="System.Int32, mscorlib">
<value>11</value>
</data>
<data name="labCoreType.Size" type="System.Drawing.Size, System.Drawing">
<value>59, 12</value>
</data>
<data name="&gt;&gt;cmbCoreType.Type" xml:space="preserve">
<value>System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="panel2.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Bottom</value>
</data>
<data name="&gt;&gt;panel1.Name" xml:space="preserve">
<value>panel1</value>
</data>
<data name="groupBox1.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="label3.Text" xml:space="preserve">
<value>* After setting this value, an socks service will be started using V2ray to provide functions such as speed display</value>
</data>
<data name="&gt;&gt;label1.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;labCoreType.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="labCoreType.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="btnBrowse.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
</data>
<data name="&gt;&gt;label6.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;label2.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="groupBox1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="cmbCoreType.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 157</value>
</data>
<data name="txtAddress.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 62</value>
</data>
<data name="&gt;&gt;label13.ZOrder" xml:space="preserve">
<value>8</value>
</data>
<data name="labCoreType.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>Custom configuration server</value>
</data>
<data name="btnBrowse.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 110</value>
</data>
<data name="label3.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve">
<value>11</value>
</data>
<data name="btnOK.Location" type="System.Drawing.Point, System.Drawing">
<value>357, 17</value>
</data>
<data name="&gt;&gt;panel1.Type" xml:space="preserve">
<value>System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="label3.TabIndex" type="System.Int32, mscorlib">
<value>46</value>
</data>
<data name="&gt;&gt;btnBrowse.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnClose.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="txtAddress.Size" type="System.Drawing.Size, System.Drawing">
<value>432, 37</value>
</data>
<data name="&gt;&gt;labCoreType.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;txtPreSocksPort.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="btnClose.Location" type="System.Drawing.Point, System.Drawing"> <data name="btnClose.Location" type="System.Drawing.Point, System.Drawing">
<value>450, 17</value> <value>450, 17</value>
</data> </data>
<data name="btnClose.Size" type="System.Drawing.Size, System.Drawing"> <data name="btnEdit.TabIndex" type="System.Int32, mscorlib">
<value>43</value>
</data>
<data name="&gt;&gt;label2.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="&gt;&gt;txtPreSocksPort.Name" xml:space="preserve">
<value>txtPreSocksPort</value>
</data>
<data name="&gt;&gt;label1.Name" xml:space="preserve">
<value>label1</value>
</data>
<data name="panel2.Size" type="System.Drawing.Size, System.Drawing">
<value>611, 60</value>
</data>
<data name="panel1.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value>
</data>
<data name="txtPreSocksPort.TabIndex" type="System.Int32, mscorlib">
<value>45</value>
</data>
<data name="&gt;&gt;txtRemarks.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="label2.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="label13.TabIndex" type="System.Int32, mscorlib">
<value>22</value>
</data>
<data name="btnOK.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value> <value>75, 23</value>
</data> </data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <data name="btnEdit.Location" type="System.Drawing.Point, System.Drawing">
<data name="btnClose.TabIndex" type="System.Int32, mscorlib"> <value>208, 110</value>
<value>4</value>
</data> </data>
<data name="btnClose.Text" xml:space="preserve"> <data name="btnEdit.Text" xml:space="preserve">
<value>&amp;Cancel</value> <value>&amp;Edit</value>
</data> </data>
<data name="&gt;&gt;btnClose.Name" xml:space="preserve"> <data name="&gt;&gt;panel1.ZOrder" xml:space="preserve">
<value>btnClose</value> <value>2</value>
</data> </data>
<data name="&gt;&gt;btnClose.Type" xml:space="preserve"> <data name="&gt;&gt;btnOK.Parent" xml:space="preserve">
<value>panel2</value>
</data>
<data name="btnOK.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="label6.Text" xml:space="preserve">
<value>Alias (remarks)</value>
</data>
<data name="txtRemarks.Size" type="System.Drawing.Size, System.Drawing">
<value>313, 21</value>
</data>
<data name="&gt;&gt;label13.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="btnBrowse.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="cmbCoreType.TabIndex" type="System.Int32, mscorlib">
<value>41</value>
</data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 62</value>
</data>
<data name="&gt;&gt;groupBox1.Name" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;btnOK.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>AddServer2Form</value>
</data>
<data name="label13.Location" type="System.Drawing.Point, System.Drawing">
<value>446, 26</value>
</data>
<data name="&gt;&gt;btnBrowse.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;txtAddress.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;labCoreType.Name" xml:space="preserve">
<value>labCoreType</value>
</data>
<data name="&gt;&gt;groupBox1.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="&gt;&gt;btnOK.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnOK.Name" xml:space="preserve">
<value>btnOK</value>
</data>
<data name="&gt;&gt;groupBox1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>89, 12</value>
</data>
<data name="cmbCoreType.Size" type="System.Drawing.Size, System.Drawing">
<value>89, 20</value>
</data>
<data name="&gt;&gt;panel1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;label2.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="labCoreType.TabIndex" type="System.Int32, mscorlib">
<value>42</value>
</data>
<data name="&gt;&gt;btnEdit.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="&gt;&gt;btnClose.Parent" xml:space="preserve"> <data name="&gt;&gt;btnClose.Parent" xml:space="preserve">
<value>panel2</value> <value>panel2</value>
</data> </data>
<data name="&gt;&gt;btnClose.ZOrder" xml:space="preserve"> <data name="txtPreSocksPort.Size" type="System.Drawing.Size, System.Drawing">
<value>0</value> <value>89, 21</value>
</data> </data>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <data name="panel1.Size" type="System.Drawing.Size, System.Drawing">
<data name="btnEdit.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms"> <value>611, 10</value>
<value>NoControl</value>
</data> </data>
<data name="btnEdit.Location" type="System.Drawing.Point, System.Drawing"> <data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing">
<value>208, 110</value> <value>0, 10</value>
</data>
<data name="btnEdit.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
</data>
<data name="btnEdit.TabIndex" type="System.Int32, mscorlib">
<value>43</value>
</data>
<data name="btnEdit.Text" xml:space="preserve">
<value>&amp;Edit</value>
</data>
<data name="&gt;&gt;btnEdit.Name" xml:space="preserve">
<value>btnEdit</value>
</data>
<data name="&gt;&gt;btnEdit.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnEdit.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;btnEdit.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="cmbCoreType.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 157</value>
</data>
<data name="cmbCoreType.Size" type="System.Drawing.Size, System.Drawing">
<value>89, 20</value>
</data>
<data name="cmbCoreType.TabIndex" type="System.Int32, mscorlib">
<value>41</value>
</data>
<data name="&gt;&gt;cmbCoreType.Name" xml:space="preserve">
<value>cmbCoreType</value>
</data>
<data name="&gt;&gt;cmbCoreType.Type" xml:space="preserve">
<value>System.Windows.Forms.ComboBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cmbCoreType.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;cmbCoreType.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="labCoreType.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="labCoreType.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="labCoreType.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 161</value>
</data>
<data name="labCoreType.Size" type="System.Drawing.Size, System.Drawing">
<value>59, 12</value>
</data>
<data name="labCoreType.TabIndex" type="System.Int32, mscorlib">
<value>42</value>
</data> </data>
<data name="labCoreType.Text" xml:space="preserve"> <data name="labCoreType.Text" xml:space="preserve">
<value>Core Type</value> <value>Core Type</value>
</data> </data>
<data name="&gt;&gt;labCoreType.Name" xml:space="preserve"> <data name="txtPreSocksPort.Location" type="System.Drawing.Point, System.Drawing">
<value>labCoreType</value> <value>127, 195</value>
</data> </data>
<data name="&gt;&gt;labCoreType.Type" xml:space="preserve"> <data name="btnEdit.Size" type="System.Drawing.Size, System.Drawing">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;labCoreType.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;labCoreType.ZOrder" xml:space="preserve">
<value>2</value>
</data>
<data name="btnBrowse.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="btnBrowse.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 110</value>
</data>
<data name="btnBrowse.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value> <value>75, 23</value>
</data> </data>
<data name="btnBrowse.TabIndex" type="System.Int32, mscorlib"> <data name="&gt;&gt;cmbCoreType.Parent" xml:space="preserve">
<value>40</value>
</data>
<data name="btnBrowse.Text" xml:space="preserve">
<value>&amp;Browse</value>
</data>
<data name="&gt;&gt;btnBrowse.Name" xml:space="preserve">
<value>btnBrowse</value>
</data>
<data name="&gt;&gt;btnBrowse.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnBrowse.Parent" xml:space="preserve">
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;btnBrowse.ZOrder" xml:space="preserve"> <data name="&gt;&gt;btnBrowse.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="txtAddress.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 62</value>
</data>
<data name="txtAddress.Multiline" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="txtAddress.Size" type="System.Drawing.Size, System.Drawing">
<value>432, 37</value>
</data>
<data name="txtAddress.TabIndex" type="System.Int32, mscorlib">
<value>23</value>
</data>
<data name="&gt;&gt;txtAddress.Name" xml:space="preserve">
<value>txtAddress</value>
</data>
<data name="&gt;&gt;txtAddress.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;txtAddress.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;txtAddress.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="label13.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="label13.Location" type="System.Drawing.Point, System.Drawing">
<value>446, 26</value>
</data>
<data name="label13.Size" type="System.Drawing.Size, System.Drawing">
<value>113, 12</value>
</data>
<data name="label13.TabIndex" type="System.Int32, mscorlib">
<value>22</value>
</data>
<data name="label13.Text" xml:space="preserve">
<value>* Fill in manually</value>
</data>
<data name="&gt;&gt;label13.Name" xml:space="preserve">
<value>label13</value>
</data>
<data name="&gt;&gt;label13.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;label13.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;label13.ZOrder" xml:space="preserve">
<value>5</value>
</data>
<data name="txtRemarks.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 23</value>
</data>
<data name="txtRemarks.Size" type="System.Drawing.Size, System.Drawing">
<value>313, 21</value>
</data>
<data name="txtRemarks.TabIndex" type="System.Int32, mscorlib">
<value>11</value>
</data>
<data name="&gt;&gt;txtRemarks.Name" xml:space="preserve">
<value>txtRemarks</value>
</data>
<data name="&gt;&gt;txtRemarks.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;txtRemarks.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;txtRemarks.ZOrder" xml:space="preserve">
<value>6</value> <value>6</value>
</data> </data>
<data name="label6.AutoSize" type="System.Boolean, mscorlib"> <data name="&gt;&gt;btnEdit.Name" xml:space="preserve">
<value>True</value> <value>btnEdit</value>
</data> </data>
<data name="label6.Location" type="System.Drawing.Point, System.Drawing"> <data name="btnOK.Text" xml:space="preserve">
<value>12, 27</value> <value>&amp;OK</value>
</data> </data>
<data name="label6.Size" type="System.Drawing.Size, System.Drawing"> <data name="&gt;&gt;btnClose.Name" xml:space="preserve">
<value>95, 12</value> <value>btnClose</value>
</data> </data>
<data name="label6.TabIndex" type="System.Int32, mscorlib"> <data name="&gt;&gt;panel2.Parent" xml:space="preserve">
<value>10</value> <value>$this</value>
</data>
<data name="label6.Text" xml:space="preserve">
<value>Alias (remarks)</value>
</data>
<data name="&gt;&gt;label6.Name" xml:space="preserve">
<value>label6</value>
</data>
<data name="&gt;&gt;label6.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;label6.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;label6.ZOrder" xml:space="preserve">
<value>7</value>
</data>
<data name="label1.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="label1.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 62</value>
</data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>47, 12</value>
</data> </data>
<data name="label1.TabIndex" type="System.Int32, mscorlib"> <data name="label1.TabIndex" type="System.Int32, mscorlib">
<value>0</value> <value>0</value>
</data> </data>
<data name="label1.Text" xml:space="preserve"> <data name="label3.Location" type="System.Drawing.Point, System.Drawing">
<value>Address</value> <value>229, 189</value>
</data> </data>
<data name="&gt;&gt;label1.Name" xml:space="preserve"> <data name="label2.TabIndex" type="System.Int32, mscorlib">
<value>label1</value> <value>44</value>
</data> </data>
<data name="&gt;&gt;label1.Type" xml:space="preserve"> <data name="txtAddress.Multiline" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="&gt;&gt;label3.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="labCoreType.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 161</value>
</data>
<data name="&gt;&gt;label13.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="txtAddress.TabIndex" type="System.Int32, mscorlib">
<value>23</value>
</data>
<data name="&gt;&gt;btnClose.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="panel1.TabIndex" type="System.Int32, mscorlib">
<value>6</value>
</data>
<data name="&gt;&gt;panel2.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="panel2.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
</data>
<data name="&gt;&gt;cmbCoreType.Name" xml:space="preserve">
<value>cmbCoreType</value>
</data>
<data name="btnBrowse.Text" xml:space="preserve">
<value>&amp;Browse</value>
</data>
<data name="&gt;&gt;label6.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="&gt;&gt;label1.Parent" xml:space="preserve"> <data name="&gt;&gt;label1.Parent" xml:space="preserve">
<value>groupBox1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;label1.ZOrder" xml:space="preserve"> <data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>8</value> <value>v2rayN.Forms.BaseServerForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data> </data>
<data name="groupBox1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms"> <data name="&gt;&gt;label3.Name" xml:space="preserve">
<value>Fill</value> <value>label3</value>
</data> </data>
<data name="groupBox1.Location" type="System.Drawing.Point, System.Drawing"> <data name="label2.Text" xml:space="preserve">
<value>0, 10</value> <value>Pre-Socks Port</value>
</data>
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
<value>611, 189</value>
</data>
<data name="groupBox1.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
</data>
<data name="groupBox1.Text" xml:space="preserve">
<value>Server</value>
</data>
<data name="&gt;&gt;groupBox1.Name" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;groupBox1.Type" xml:space="preserve">
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;groupBox1.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;groupBox1.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="&gt;&gt;btnOK.Name" xml:space="preserve">
<value>btnOK</value>
</data>
<data name="&gt;&gt;btnOK.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnOK.Parent" xml:space="preserve">
<value>panel2</value>
</data>
<data name="&gt;&gt;btnOK.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="panel2.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Bottom</value>
</data>
<data name="panel2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 199</value>
</data>
<data name="panel2.Size" type="System.Drawing.Size, System.Drawing">
<value>611, 60</value>
</data>
<data name="panel2.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
</data>
<data name="&gt;&gt;panel2.Name" xml:space="preserve">
<value>panel2</value>
</data> </data>
<data name="&gt;&gt;panel2.Type" xml:space="preserve"> <data name="&gt;&gt;panel2.Type" xml:space="preserve">
<value>System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="&gt;&gt;panel2.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;panel2.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="btnOK.Location" type="System.Drawing.Point, System.Drawing">
<value>357, 17</value>
</data>
<data name="btnOK.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
</data>
<data name="btnOK.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>&amp;OK</value>
</data>
<data name="&gt;&gt;btnOK.Name" xml:space="preserve">
<value>btnOK</value>
</data>
<data name="&gt;&gt;btnOK.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;btnOK.Parent" xml:space="preserve">
<value>panel2</value>
</data>
<data name="&gt;&gt;btnOK.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="panel1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms"> <data name="panel1.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Top</value> <value>Top</value>
</data> </data>
<data name="panel1.Location" type="System.Drawing.Point, System.Drawing"> <data name="panel2.Location" type="System.Drawing.Point, System.Drawing">
<value>0, 0</value> <value>0, 259</value>
</data> </data>
<data name="panel1.Size" type="System.Drawing.Size, System.Drawing"> <data name="&gt;&gt;txtAddress.ZOrder" xml:space="preserve">
<value>611, 10</value> <value>7</value>
</data> </data>
<data name="panel1.TabIndex" type="System.Int32, mscorlib"> <data name="btnEdit.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>6</value> <value>NoControl</value>
</data> </data>
<data name="&gt;&gt;panel1.Name" xml:space="preserve"> <data name="&gt;&gt;labCoreType.Parent" xml:space="preserve">
<value>panel1</value> <value>groupBox1</value>
</data> </data>
<data name="&gt;&gt;panel1.Type" xml:space="preserve"> <data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>System.Windows.Forms.Panel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>47, 12</value>
</data> </data>
<data name="&gt;&gt;panel1.Parent" xml:space="preserve"> <data name="label13.AutoSize" type="System.Boolean, mscorlib">
<value>$this</value> <value>True</value>
</data> </data>
<data name="&gt;&gt;panel1.ZOrder" xml:space="preserve"> <data name="&gt;&gt;txtPreSocksPort.Type" xml:space="preserve">
<value>2</value> <value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 12</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>Address</value>
</data>
<data name="&gt;&gt;btnEdit.ZOrder" xml:space="preserve">
<value>3</value>
</data>
<data name="txtRemarks.Location" type="System.Drawing.Point, System.Drawing">
<value>127, 23</value>
</data>
<data name="label6.Size" type="System.Drawing.Size, System.Drawing">
<value>95, 12</value>
</data>
<data name="&gt;&gt;label3.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cmbCoreType.ZOrder" xml:space="preserve">
<value>4</value>
</data>
<data name="label13.Text" xml:space="preserve">
<value>* Fill in manually</value>
</data>
<data name="&gt;&gt;label2.Name" xml:space="preserve">
<value>label2</value>
</data>
<data name="&gt;&gt;txtPreSocksPort.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="label2.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 199</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>611, 319</value>
</data>
<data name="&gt;&gt;btnBrowse.Name" xml:space="preserve">
<value>btnBrowse</value>
</data>
<data name="groupBox1.Size" type="System.Drawing.Size, System.Drawing">
<value>611, 249</value>
</data>
<data name="btnBrowse.TabIndex" type="System.Int32, mscorlib">
<value>40</value>
</data>
<data name="&gt;&gt;label6.ZOrder" xml:space="preserve">
<value>10</value>
</data>
<data name="btnClose.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
</data>
<data name="&gt;&gt;label3.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="&gt;&gt;label13.Name" xml:space="preserve">
<value>label13</value>
</data>
<data name="btnClose.Text" xml:space="preserve">
<value>&amp;Cancel</value>
</data>
<data name="label2.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="btnClose.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="&gt;&gt;txtRemarks.ZOrder" xml:space="preserve">
<value>9</value>
</data>
<data name="&gt;&gt;btnEdit.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;txtAddress.Name" xml:space="preserve">
<value>txtAddress</value>
</data>
<data name="&gt;&gt;txtAddress.Parent" xml:space="preserve">
<value>groupBox1</value>
</data>
<data name="&gt;&gt;txtRemarks.Type" xml:space="preserve">
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="groupBox1.Text" xml:space="preserve">
<value>Server</value>
</data>
<data name="&gt;&gt;txtRemarks.Name" xml:space="preserve">
<value>txtRemarks</value>
</data>
<data name="label6.TabIndex" type="System.Int32, mscorlib">
<value>10</value>
</data>
<data name="label6.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 27</value>
</data>
<data name="label1.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="&gt;&gt;groupBox1.Type" xml:space="preserve">
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 12</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>611, 259</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>Custom configuration server</value>
</data>
<data name="&gt;&gt;$this.Name" xml:space="preserve">
<value>AddServer2Form</value>
</data>
<data name="&gt;&gt;$this.Type" xml:space="preserve">
<value>v2rayN.Forms.BaseServerForm, v2rayN, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null</value>
</data>
</root> </root>

View file

@ -117,34 +117,56 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<data name="$this.Text" xml:space="preserve">
<value>自定义配置</value>
</data>
<data name="btnBrowse.Text" xml:space="preserve">
<value>浏览(&amp;B)</value>
</data>
<data name="btnClose.Text" xml:space="preserve"> <data name="btnClose.Text" xml:space="preserve">
<value>取消(&amp;C)</value> <value>取消(&amp;C)</value>
</data> </data>
<data name="btnEdit.Text" xml:space="preserve">
<value>编辑(&amp;E)</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>确定(&amp;O)</value>
</data>
<data name="groupBox1.Text" xml:space="preserve"> <data name="groupBox1.Text" xml:space="preserve">
<value>服务器</value> <value>服务器</value>
</data> </data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="label3.Size" type="System.Drawing.Size, System.Drawing">
<value>337, 41</value>
</data>
<data name="label3.Text" xml:space="preserve">
<value>* 自定义配置的Socks端口值可不设置当设置此值后将使用V2ray-core额外启动一个前置Socks服务提供分流和速度显示等功能</value>
</data>
<data name="label2.Size" type="System.Drawing.Size, System.Drawing">
<value>59, 12</value>
</data>
<data name="label2.Text" xml:space="preserve">
<value>Socks端口</value>
</data>
<data name="btnEdit.Text" xml:space="preserve">
<value>编辑(&amp;E)</value>
</data>
<data name="labCoreType.Size" type="System.Drawing.Size, System.Drawing">
<value>53, 12</value>
</data>
<data name="labCoreType.Text" xml:space="preserve"> <data name="labCoreType.Text" xml:space="preserve">
<value>Core类型</value> <value>Core类型</value>
</data> </data>
<data name="label1.Text" xml:space="preserve"> <data name="btnBrowse.Text" xml:space="preserve">
<value>地址(address)</value> <value>浏览(&amp;B)</value>
</data> </data>
<data name="label13.Text" xml:space="preserve"> <data name="label13.Text" xml:space="preserve">
<value>*手填,方便识别管理</value> <value>*手填,方便识别管理</value>
</data> </data>
<data name="label6.Size" type="System.Drawing.Size, System.Drawing">
<value>83, 12</value>
</data>
<data name="label6.Text" xml:space="preserve"> <data name="label6.Text" xml:space="preserve">
<value>别名(remarks)</value> <value>别名(remarks)</value>
</data> </data>
<data name="label1.Size" type="System.Drawing.Size, System.Drawing">
<value>83, 12</value>
</data>
<data name="label1.Text" xml:space="preserve">
<value>地址(address)</value>
</data>
<data name="btnOK.Text" xml:space="preserve">
<value>确定(&amp;O)</value>
</data>
<data name="$this.Text" xml:space="preserve">
<value>自定义配置</value>
</data>
</root> </root>

View file

@ -27,8 +27,9 @@ namespace v2rayN.Handler
/// <param name="fileName"></param> /// <param name="fileName"></param>
/// <param name="msg"></param> /// <param name="msg"></param>
/// <returns></returns> /// <returns></returns>
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 try
{ {
if (node == null) if (node == null)
@ -42,47 +43,22 @@ namespace v2rayN.Handler
{ {
return GenerateClientCustomConfig(node, fileName, out msg); return GenerateClientCustomConfig(node, fileName, out msg);
} }
else
//取得默认配置
string result = Utils.GetEmbedText(SampleClient);
if (Utils.IsNullOrEmpty(result))
{ {
msg = ResUI.FailedGetDefaultConfiguration; V2rayConfig v2rayConfig = null;
return -1; 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<V2rayConfig>(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) catch (Exception ex)
{ {
@ -93,6 +69,8 @@ namespace v2rayN.Handler
return 0; return 0;
} }
/// <summary> /// <summary>
/// 日志 /// 日志
/// </summary> /// </summary>
@ -964,34 +942,38 @@ namespace v2rayN.Handler
} }
//overwrite port //overwrite port
var fileContent = File.ReadAllLines(fileName).ToList(); if (node.preSocksPort <= 0)
var coreType = LazyConfig.Instance.GetCoreType(node, node.configType);
switch (coreType)
{ {
case ECoreType.v2fly: var fileContent = File.ReadAllLines(fileName).ToList();
case ECoreType.Xray: var coreType = LazyConfig.Instance.GetCoreType(node, node.configType);
break; switch (coreType)
case ECoreType.clash: {
case ECoreType.clash_meta: case ECoreType.v2fly:
//remove the original case ECoreType.Xray:
var indexPort = fileContent.FindIndex(t => t.Contains("port:")); break;
if (indexPort >= 0) case ECoreType.clash:
{ case ECoreType.clash_meta:
fileContent.RemoveAt(indexPort); //remove the original
} var indexPort = fileContent.FindIndex(t => t.Contains("port:"));
indexPort = fileContent.FindIndex(t => t.Contains("socks-port:")); if (indexPort >= 0)
if (indexPort >= 0) {
{ fileContent.RemoveAt(indexPort);
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($"port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundHttp)}");
fileContent.Add($"socks-port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundSocks)}"); fileContent.Add($"socks-port: {LazyConfig.Instance.GetConfig().GetLocalPort(Global.InboundSocks)}");
break; 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) catch (Exception ex)
{ {
@ -1002,6 +984,66 @@ namespace v2rayN.Handler
return 0; 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<V2rayConfig>(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 #endregion
#region #region
@ -1442,7 +1484,12 @@ namespace v2rayN.Handler
/// <returns></returns> /// <returns></returns>
public static int Export2ClientConfig(VmessItem node, string fileName, out string msg) 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);
} }
/// <summary> /// <summary>

View file

@ -24,7 +24,7 @@ namespace v2rayN.Handler
private static string v2rayConfigRes = Global.v2rayConfigFileName; private static string v2rayConfigRes = Global.v2rayConfigFileName;
private CoreInfo coreInfo; private CoreInfo coreInfo;
public event ProcessDelegate ProcessEvent; public event ProcessDelegate ProcessEvent;
//private int processId = 0; private int processId = 0;
private Process _process; private Process _process;
public V2rayHandler() public V2rayHandler()
@ -51,7 +51,7 @@ namespace v2rayN.Handler
return; return;
} }
string fileName = Utils.GetPath(v2rayConfigRes); 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); ShowMsg(false, msg);
} }
@ -61,6 +61,21 @@ namespace v2rayN.Handler
ShowMsg(true, $"[{config.GetGroupRemarks(item.groupId)}] {item.GetSummary()}"); ShowMsg(true, $"[{config.GetGroupRemarks(item.groupId)}] {item.GetSummary()}");
V2rayRestart(); 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)
//if (processId > 0) {
//{ V2rayStopPid(processId);
// Process p1 = Process.GetProcessById(processId); processId = 0;
// 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();
// }
// }
//}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -215,7 +215,8 @@ namespace v2rayN.Handler
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true, RedirectStandardError = true,
CreateNoWindow = true, CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8 StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8
} }
}; };
p.OutputDataReceived += (sender, e) => p.OutputDataReceived += (sender, e) =>
@ -229,7 +230,6 @@ namespace v2rayN.Handler
p.Start(); p.Start();
p.PriorityClass = ProcessPriorityClass.High; p.PriorityClass = ProcessPriorityClass.High;
p.BeginOutputReadLine(); p.BeginOutputReadLine();
//processId = p.Id;
_process = p; _process = p;
if (p.WaitForExit(1000)) if (p.WaitForExit(1000))
@ -270,7 +270,8 @@ namespace v2rayN.Handler
RedirectStandardOutput = true, RedirectStandardOutput = true,
RedirectStandardError = true, RedirectStandardError = true,
CreateNoWindow = true, CreateNoWindow = true,
StandardOutputEncoding = Encoding.UTF8 StandardOutputEncoding = Encoding.UTF8,
StandardErrorEncoding = Encoding.UTF8
} }
}; };
p.OutputDataReceived += (sender, e) => p.OutputDataReceived += (sender, e) =>

View file

@ -561,10 +561,16 @@ namespace v2rayN.Mode
{ {
get; set; get; set;
} = string.Empty; } = string.Empty;
public ECoreType? coreType public ECoreType? coreType
{ {
get; set; get; set;
} }
public int preSocksPort
{
get; set;
}
} }
[Serializable] [Serializable]