修复进程编辑模式文件名会被更改,添加编辑模式不可用提醒,抽取进程模式编辑右键菜单

This commit is contained in:
ChsBuffer
2020-08-13 01:06:55 +08:00
parent c490e9f802
commit a2838b8217
5 changed files with 85 additions and 52 deletions

View File

@@ -334,23 +334,28 @@ namespace Netch.Forms
private void EditModePictureBox_Click(object sender, EventArgs e)
{
// 当前ModeComboBox中至少有一项
if (ModeComboBox.Items.Count > 0 && ModeComboBox.SelectedIndex != -1)
{
SaveConfigs();
var selectedMode = (Models.Mode) ModeComboBox.SelectedItem;
// 只允许修改进程加速的模式
if (selectedMode.Type == 0)
{
//Process.Start(Environment.CurrentDirectory + "\\mode\\" + selectedMode.FileName + ".txt");
var process = new Process(selectedMode);
process.Text = "Edit Process Mode";
process.Show();
Hide();
}
}
else
if (ModeComboBox.Items.Count <= 0 || ModeComboBox.SelectedIndex == -1)
{
MessageBoxX.Show(i18N.Translate("Please select a mode first"));
return;
}
SaveConfigs();
var selectedMode = (Models.Mode) ModeComboBox.SelectedItem;
switch (selectedMode.Type)
{
case 0:
{
var process = new Process(selectedMode);
process.Show();
Hide();
break;
}
default:
{
MessageBoxX.Show($"Current not support editing {selectedMode.TypeToString()} Mode");
break;
}
}
}

View File

@@ -31,6 +31,7 @@ namespace Netch.Forms.Mode
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Process));
this.ConfigurationGroupBox = new System.Windows.Forms.GroupBox();
this.UseCustomFilenameBox = new System.Windows.Forms.CheckBox();
@@ -43,9 +44,12 @@ namespace Netch.Forms.Mode
this.RuleListBox = new System.Windows.Forms.ListBox();
this.RemarkTextBox = new System.Windows.Forms.TextBox();
this.RemarkLabel = new System.Windows.Forms.Label();
this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
this.ControlButton = new System.Windows.Forms.Button();
this.DeleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.ConfigurationGroupBox.SuspendLayout();
this.ProcessGroupBox.SuspendLayout();
this.contextMenuStrip.SuspendLayout();
this.SuspendLayout();
//
// ConfigurationGroupBox
@@ -156,6 +160,12 @@ namespace Netch.Forms.Mode
this.RemarkLabel.TabIndex = 0;
this.RemarkLabel.Text = "Remark";
//
// contextMenuStrip
//
this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {this.DeleteToolStripMenuItem});
this.contextMenuStrip.Name = "contextMenuStrip";
this.contextMenuStrip.Size = new System.Drawing.Size(153, 48);
//
// ControlButton
//
this.ControlButton.Location = new System.Drawing.Point(277, 362);
@@ -166,6 +176,13 @@ namespace Netch.Forms.Mode
this.ControlButton.UseVisualStyleBackColor = true;
this.ControlButton.Click += new System.EventHandler(this.ControlButton_Click);
//
// DeleteToolStripMenuItem
//
this.DeleteToolStripMenuItem.Name = "DeleteToolStripMenuItem";
this.DeleteToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.DeleteToolStripMenuItem.Text = "Delete";
this.DeleteToolStripMenuItem.Click += new System.EventHandler(this.deleteRule_Click);
//
// Process
//
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F);
@@ -187,11 +204,14 @@ namespace Netch.Forms.Mode
this.ConfigurationGroupBox.PerformLayout();
this.ProcessGroupBox.ResumeLayout(false);
this.ProcessGroupBox.PerformLayout();
this.contextMenuStrip.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
private System.Windows.Forms.ToolStripMenuItem DeleteToolStripMenuItem;
private System.Windows.Forms.GroupBox ConfigurationGroupBox;
private System.Windows.Forms.Label RemarkLabel;
private System.Windows.Forms.GroupBox ProcessGroupBox;

View File

@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
@@ -34,6 +33,7 @@ namespace Netch.Forms.Mode
mode.Rule.ForEach(i => RuleListBox.Items.Add(i));
EditMode = true;
RemarkTextBox.TextChanged -= RemarkTextBox_TextChanged;
FilenameTextBox.Enabled = false;
FilenameLabel.Enabled = false;
UseCustomFilenameBox.Enabled = false;
@@ -109,6 +109,7 @@ namespace Netch.Forms.Mode
AddButton.Text = i18N.Translate(AddButton.Text);
ScanButton.Text = i18N.Translate(ScanButton.Text);
ControlButton.Text = i18N.Translate(ControlButton.Text);
DeleteToolStripMenuItem.Text = i18N.Translate(DeleteToolStripMenuItem.Text);
FilenameTextBox.Enabled = false;
FilenameLabel.Enabled = false;
@@ -129,10 +130,7 @@ namespace Netch.Forms.Mode
return;
if (e.Button == MouseButtons.Right)
{
var strip = new ContextMenuStrip();
strip.Items.Add(i18N.Translate("Delete"));
strip.Items[0].Click += deleteRule_Click;
strip.Show(RuleListBox, e.Location); //鼠标右键按下弹出菜单
contextMenuStrip.Show(RuleListBox, e.Location);
}
}

View File

@@ -117,6 +117,9 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View File

@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
namespace Netch.Models
{
@@ -20,9 +21,9 @@ namespace Netch.Models
/// 0. Socks5 + 进程加速<para />
/// 1. Socks5 + TUN/TAP 规则内 IP CIDR 加速<para />
/// 2. Socks5 + TUN/TAP 全局,绕过规则内 IP CIDR<para />
/// 3. Socks5 + HTTP 代理(自动设置到系统代理)<para />
/// 4. Socks5 代理(不自动设置到系统代理)<para />
/// 5. Socks5 + HTTP 代理(不自动设置到系统代理)<para />
/// 3. Socks5 + HTTP 代理(设置到系统代理)<para />
/// 4. Socks5 代理(不设置到系统代理)<para />
/// 5. Socks5 + HTTP 代理(不设置到系统代理)<para />
/// </summary>
public int Type = 0;
@@ -34,7 +35,7 @@ namespace Netch.Models
/// <summary>
/// 规则
/// </summary>
public List<string> Rule = new List<string>();
public readonly List<string> Rule = new List<string>();
/// <summary>
/// 获取备注
@@ -42,7 +43,7 @@ namespace Netch.Models
/// <returns>备注</returns>
public override string ToString()
{
return string.Format("[{0}] {1}", Type + 1, Remark);
return $"[{Type + 1}] {Remark}";
}
/// <summary>
@@ -51,38 +52,30 @@ namespace Netch.Models
/// <returns>模式文件字符串</returns>
public string ToFileString()
{
string FileString;
string fileString;
// 进程模式
if (Type == 0)
switch (Type)
{
FileString = $"# {Remark}\r\n";
case 0:
// 进程模式
fileString = $"# {Remark}";
break;
case 1:
// TUN/TAP 规则内 IP CIDR无 Bypass China 设置
fileString = $"# {Remark}, {Type}, 0";
break;
default:
fileString = $"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}";
break;
}
// TUN/TAP 规则内 IP CIDR无 Bypass China 设置
else if (Type == 1)
{
FileString = $"# {Remark}, {Type}, 0\r\n";
}
fileString += Global.EOF;
// TUN/TAP 全局,绕过规则内 IP CIDR
// HTTP 代理(自动设置到系统代理)
// Socks5 代理(不自动设置到系统代理)
// Socks5 + HTTP 代理(不自动设置到系统代理)
else
{
FileString = $"# {Remark}, {Type}, {(BypassChina ? 1 : 0)}\r\n";
}
fileString = Rule.Aggregate(fileString, (current, item) => $"{current}{item}{Global.EOF}");
// 去除最后的行尾符
fileString = fileString.Substring(0, fileString.Length - 2);
foreach (var item in Rule)
{
FileString = $"{FileString}{item}\r\n";
}
// 去除最后两个多余回车符和换行符
FileString = FileString.Substring(0, FileString.Length - 2);
return FileString;
return fileString;
}
/// <summary>
@@ -131,5 +124,19 @@ namespace Netch.Models
}
}
}
public string TypeToString()
{
return Type switch
{
0 => "Process",
1 => "TUNTAP",
2 => "TUNTAP",
3 => "SYSTEM",
4 => "S5",
5 => "S5+HTTP",
_ => "ERROR",
};
}
}
}
}